Skybound Software is looking to hire experienced C# developers to work on Stylizer and other forthcoming Skybound products. Click here for details.
GeckoFX is an open-source component which makes it easy to embed Mozilla Gecko (Firefox) into any .NET Windows Forms application. Written in clean, fully commented C#, GeckoFX is the perfect replacement for the default Internet Explorer-based WebBrowser control. Download GeckoFX @ Google Code >
GeckoFX is made by Skybound Software, authors of Stylizer—the professional CSS editor with a strong focus on visual control, error-free workflow, and productivity. Learn About Stylizer >
Discuss GeckoFX, the Open-Source Gecko Control for .NET
You are not logged in.
Pages: 1
Topic closed
I've managed to get the password manager working, but... I have to initialize it from a local file. The problem is when the file is opened by the web browser a warning pops up stating:
A script from "file://" is requesting enhanced abilities that are UNSAFE and could be used to compromise your machine or data:
Run or install software on your machine
Allow these abilities only if you trust this source to be free of viruses or malicious programs
...
Then you get the standard 'Allow' 'Deny' buttons and a check box for remembering your choice...
Is there some way, that anyone knows about, to keep this from popping up? Checking the box doesn't work.
Offline
Can you post some code?
Offline
I navigate to a page containing the below code as soon as the application starts..
Maybe you, Andrew, can use this to implement the login manager directly in the Geckofx library...
<html>
<head>
<script type="text/javascript">
function initLManager() {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const cid = "@mozilla.org/login-manager;1";
obj = Components.classes[cid].createInstance(); //;getService() //<This works too in place of //createInstance
obj = obj.QueryInterface(Components.interfaces.nsILoginManager);
} catch (err) {
alert(err);
return;
}
var res = obj.Nothing(window);
}
initLManager();
</script>
</head>
<body>
</body>
</html>
Only drawback to this method is that you shown a warning message when the page is loaded. The warning contains a "Remember this action" checkbox but, it don't work.
I've done a little bit of research on this and found:
To use that, that code must either be a local file, a signed script, or codebase principal support must be enabled (with a pref:user_pref("signed.applets.codebase_principal_support", true);
??Although, this file is being loaded locally and still throwing the warning message??
-EDIT:
PROBLEM SOLVED!
Add these two lines to your user-prefs.js file:
user_pref("capability.principal.myapp.id", "file:///C:/path/to/local/file/named/loginManagerInit.htm");
user_pref("capability.principal.myapp.granted", "UniversalXPConnect");
No more warning message!
More info found here: http://www.mozilla.org/projects/securit … -file.html
Offline
For those of you that haven't yet read this post: THIS IS A HACK, no GeckoFX source code needs to be modified!
This is a simple step-by-step guide to help you get the Mozilla login manager working with your application.
It's taken me several weeks to figure this out and was a pain in the ass the whole time. So, now that I have it fully working in my application, I think I should shared this with everyone else.
Step 1) Create an simple html file to initialize the login manager service. Contents of this file are as follows:
<html>
<head>
<script type="text/javascript">
function initLManager() {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const cid = "@mozilla.org/login-manager;1";
obj = Components.classes[cid].getService();
obj = obj.QueryInterface(Components.interfaces.nsILoginManager);
} catch (err) {
alert(err);
return;
}
var res = obj.Nothing(window);
}
initLManager();
</script>
</head>
<body>
</body>
</html>
You can name this file anything you want.
Step 2)Open All.js (Located in: XULRunner/greprefs directory) and ensure that you have the following preferences, if they are not there then create them:
pref("signon.rememberSignons", true);
pref("signon.expireMasterPassword", false);
pref("signon.SignonFileName", "signons.txt"); // obsolete
pref("signon.SignonFileName2", "signons2.txt"); // obsolete
pref("signon.SignonFileName3", "signons3.txt");
pref("signon.autofillForms", true); //<-- If false, password will be filled in after username field is blurred
pref("signon.debug", false); // logs to Error Console
Step 3)In the same directory as All.js, open or create/open user-prefs.js. Add the following preferences:
//UPDATED: This first preference can be set by code to allow your application to be copied/moved to another directory
//and still maintain the correct path to the initialization file.
//user_pref("capability.principal.myapp.id", "file:///C:/path/to/initializationfile.html");
//This preference MUST be set in user-prefs.js
user_pref("capability.principal.myapp.granted", "UniversalXPConnect");
Step 3)Initializing the login system:
Before you can use the login manager it needs to be initialized. To do this your browser needs to navigate to the init file, that we've created above, so that the login service will 'come to life'. This only needs to be done once per application session. Below is a simple example of doing this:
Imports Skybound.Gecko
Imports System.IO
Imports System
Private Class Form1
Private LoginManagerInitialized as Boolean = False
Private Sub Form1_Load(byVal Sender As System.Object, byVal e As System.EventArgs) Handles MyBase.Load
Xpcom.initialize(Application.StartupPath & "xulrunner")
Dim profilePath As String = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "MyAppNameDefaultProfile"
If (Not Directory.Exists(profilePath) Then
Directory.CreateDirectory(profilePath)
End If
Xpcom.ProfileDirectory = profilePath
Dim tmp As String = Application.StartupPath
Dim appPath As String = tmp.Replace("", "/")
GeckoPreferences.User("capability.principal.myapp.id") = "file:///" & appPath & "/LoginManagerInitialize.html"
initLoginManager()
End Sub
Private Sub initLoginManager()
If (Not LoginManagerInitialized) Then
WebBrowser.Navigate("LoginManagerInitialize.html")
Else
WebBrowser.Navigate("http://somedomain.com")
End If
End Sub
Private Sub WebBrowser_DocumentCompleted(byVal Sender As System.Object, byVal e As System.EventArgs)
Dim b as GeckoWebBrowser = DirectCast(Sender, GeckoWebBrowser)
If (b.URL.AbsoluteURI.EndsWith("LoginManagerInitialize.html")
LoginManagerInitialized = True
''//MODIFICATION: Remove the login manager initialization page from history
WebBrowser.History.Purge(1)
b.Navigate("http://somedomain.com")
End If
End Sub
End Class
I hope everyone can easily follow this post. If you have any questions just ask.
Offline
You can now implement the login manager directly in GeckoFX by modifying nsInterfaces.cs with the following code:
[Guid("9c87a9bd-bf8b-4fae-bdb8-70513b2877df"), ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface nsILoginInfo
{
void init(nsAString aHostname, nsAString aFormSubmitURL, nsAString aHTTPRealm,
nsAString aUsername, nsAString aPassword, nsAString aUsernameField, nsAString aPasswordField);
void matches(nsILoginInfo aLoginInfo, bool aIgnorePassword);
void equals(nsILoginInfo aLoginInfo);
}
[Guid("579f45b7-682f-479f-9085-3f8075488803"), ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface nsILoginManager
{
void AddLogin(nsILoginInfo aLogin);
void RemoveLogin(nsILoginInfo aLogin);
void ModifyLogin(nsILoginInfo oldLogin, nsILoginInfo newLogin);
void RemoveAllLogins();
void GetAllLogins(out uint count, out nsILoginInfo logins);
void GetAllDisabledHosts(out uint count,[MarshalAs(UnmanagedType.LPWStr)] string hostnames);
bool GetLoginSavingEnabled(nsAString aHost);
void SetLoginSavingEnabled(nsAString aHost, bool isEnabled);
void FindLogins(out uint count, nsAString aHostname, nsAString aActionURL, nsAString aHttpRealm,out nsILoginInfo logins);
uint CountLogins(nsAString aHostname, nsAString aActionURL, nsAString aHttpRealm);
nsIAutoCompleteResult AutoCompleteSearch(nsAString aSearchString, nsIAutoCompleteResult aPreviousResult, nsIDOMHTMLInputElement aElement);
}
[Guid("d2fcba9a-3f5c-40fc-a9fc-4adc87dc61ef"), ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface nsIAutoCompleteResult
{
nsAString getSearchString();
ushort getSearchResult();
int getDefaultIndex();
nsAString getErrorDescription();
uint getMatchCount();
nsAString getValueAt(int index);
nsAString getCommentAt(int index);
nsAString getStyleAt(int index);
nsAString getImageAt(int index);
void removeValueAt(int rowIndex, bool removeFromDb);
}
[Guid("a6cf9093-15b3-11d2-932e-00805f8add32"), ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface nsIDOMHTMLInputElement
{
void getDefaultValue(String defaultValue);
void getDefaultChecked(bool defaultChecked);
void getForm(nsIDOMHTMLElement form);
void getAccept(String accept);
void getAccessKey(String accessKey);
void getAlign(String align);
void getAlt(String alt);
void getChecked(bool _checked);
void getDisabled(bool disabled);
void getMaxLength(bool maxLength);
void getName(String name);
void getReadOnly(bool readOnly);
void getSize(ulong size);
void getSrc(String src);
void getTabIndex(long tabIndex);
void getType(String type);
void getUseMap(String useMap);
void getValue(String value);
}
[Guid("a6cf908f-15b3-11d2-932e-00805f8add32"), ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface nsIDOMHTMLFormElement
{
void getElements(nsIDOMHTMLCollection elements);
void getName(String name);
void getAcceptCharset(String acceptCharset);
void getAction(String action);
void getEnctype(String enctype);
void getMethod(String method);
void getTarget(String target);
}Next, in GeckoWebBrowser.cs, add the following:
public void initLoginManager()
{
nsILoginManager LoginManager = Xpcom.GetService<nsILoginManager>("@mozilla.org/login-manager;1");
LoginManager = Xpcom.QueryInterface<nsILoginManager>(LoginManager);
}To initialize the service all you need to do is call: browser.initLoginManager() in your form load event - after creating a valid instance of GeckoWebBrowser.
There may be a bug or two with this implementation as it doesn't seem to work for ALL sites, but for the majority it seems to be Ok...
DISCLAIMER: I'm still working on the issue of it not working on all sites (although, by default it won't work on some sites anyway) so consider this a prototype. If you need it working for everything, right now, continue using the hack.
This post will be modified as I continue to make progress with the above issue.
Last edited by softwerx (November 08, 2008 12:59 AM)
Offline
To simplify this even more you can initialize the login manager globally by adding the following to xpcom.cs, just below:
Initialize(null);
in the
public static void Initialize()
method.
...Providing you have already got the interfaces from above defined in nsInterfaces.cs
nsILoginManager lm = Xpcom.GetService<nsILoginManager>("@mozilla.org/login-manager;1");
lm = Xpcom.QueryInterface<nsILoginManager>(lm);Last edited by softwerx (October 23, 2008 9:37 AM)
Offline
Topic closed
Pages: 1