galeon r8978 - in trunk: . embed mozilla



Author: philipl
Date: Wed Sep  3 05:00:15 2008
New Revision: 8978
URL: http://svn.gnome.org/viewvc/galeon?rev=8978&view=rev

Log:
2008-09-02  Philip Langdale  <philipl alumni utexas net>

	* configure.in
	* mozilla/mozilla-embed-shell.cpp
	* mozilla/Makefile.am
	* embed/galeon-embed-shell.c
	* embed/galeon-embed-shell.h: Restore password saving
	support with gecko 1.9. Ported from Epiphany.



Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/embed/galeon-embed-shell.c
   trunk/embed/galeon-embed-shell.h
   trunk/mozilla/Makefile.am
   trunk/mozilla/mozilla-embed-shell.cpp

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Wed Sep  3 05:00:15 2008
@@ -754,7 +754,7 @@
 	[AC_DEFINE([HAVE_NSIMUTABLEARRAY_H],[1],
 	[Define if nsIClassInfoImpl.h exists])])
 
-dnl The password manager was removed from the C++ core in 1.9
+dnl The password manager was removed in 1.9
 AC_CHECK_FILE([$MOZILLA_INCLUDE_ROOT/nsIPassword.h],
 	[AC_DEFINE([HAVE_NSIPASSWORD_H],[1],
 	[Define if nsIPassword.h exists])])
@@ -765,6 +765,14 @@
 	[AC_DEFINE([HAVE_NSIPASSWORD_H],[1],
 	[Define if nsIPassword.h exists])])
 
+dnl The Login Manager was addeded to replace it in 1.9
+AC_CHECK_FILE([$MOZILLA_INCLUDE_ROOT/nsILoginManager.h],
+	[AC_DEFINE([HAVE_NSILOGINMANAGER_H],[1],
+	[Define if nsILoginManager.h exists])])
+AC_CHECK_FILE([$MOZILLA_INCLUDE_ROOT/loginmgr/nsILoginManager.h],
+	[AC_DEFINE([HAVE_NSILOGINMANAGER_H],[1],
+	[Define if nsILoginManager.h exists])])
+
 dnl nsIPromptService2 is how http auth is done in 1.9
 AC_CHECK_FILE([$MOZILLA_INCLUDE_ROOT/nsIPromptService2.h],
 	[AC_DEFINE([HAVE_NSIPROMPTSERVICE2_H],[1],

Modified: trunk/embed/galeon-embed-shell.c
==============================================================================
--- trunk/embed/galeon-embed-shell.c	(original)
+++ trunk/embed/galeon-embed-shell.c	Wed Sep  3 05:00:15 2008
@@ -363,6 +363,11 @@
 		PasswordInfo *info = (PasswordInfo *)l->data;
 		g_free (info->host);
 		g_free (info->username);
+		g_free (info->password);
+		g_free (info->httpRealm);
+		g_free (info->formSubmitURL);
+		g_free (info->usernameField);
+		g_free (info->passwordField);
 		g_free (info);
 	}
 

Modified: trunk/embed/galeon-embed-shell.h
==============================================================================
--- trunk/embed/galeon-embed-shell.h	(original)
+++ trunk/embed/galeon-embed-shell.h	Wed Sep  3 05:00:15 2008
@@ -61,6 +61,12 @@
 {
         gchar *host;
         gchar *username;
+
+	gchar *password;
+	gchar *httpRealm;
+	gchar *formSubmitURL;
+	gchar *usernameField;
+	gchar *passwordField;
 } PasswordInfo;
 
 typedef struct

Modified: trunk/mozilla/Makefile.am
==============================================================================
--- trunk/mozilla/Makefile.am	(original)
+++ trunk/mozilla/Makefile.am	Wed Sep  3 05:00:15 2008
@@ -28,6 +28,7 @@
 	-I$(MOZILLA_INCLUDE_ROOT)/jsconsole \
 	-I$(MOZILLA_INCLUDE_ROOT)/layout \
 	-I$(MOZILLA_INCLUDE_ROOT)/locale \
+	-I$(MOZILLA_INCLUDE_ROOT)/loginmgr \
 	-I$(MOZILLA_INCLUDE_ROOT)/mimetype \
 	-I$(MOZILLA_INCLUDE_ROOT)/mozxfer \
 	-I$(MOZILLA_INCLUDE_ROOT)/necko \

Modified: trunk/mozilla/mozilla-embed-shell.cpp
==============================================================================
--- trunk/mozilla/mozilla-embed-shell.cpp	(original)
+++ trunk/mozilla/mozilla-embed-shell.cpp	Wed Sep  3 05:00:15 2008
@@ -71,6 +71,10 @@
 #ifdef HAVE_NSIPASSWORD_H
 #include <nsIPasswordManager.h>
 #include <nsIPassword.h>
+#elif defined(HAVE_NSILOGINMANAGER_H)
+#include <nsILoginInfo.h>
+#include <nsILoginManager.h>
+#include <nsIIDNService.h>
 #endif
 #include <nsICookie.h>
 #include <nsCPasswordManager.h>
@@ -216,6 +220,17 @@
 }
 
 static void
+mozilla_init_login_manager(void)
+{
+#ifdef HAVE_NSILOGINMANAGER_H
+        nsCOMPtr<nsILoginManager> loginManager =
+                        do_GetService (NS_LOGINMANAGER_CONTRACTID);
+	if (!loginManager)
+		g_warning ("Failed to instantiate LoginManager");
+#endif
+}
+
+static void
 mozilla_init_plugin_path ()
 {
 	const char * user_path = g_getenv( "MOZ_PLUGIN_PATH" );
@@ -354,6 +369,7 @@
 	  *lastSlash = '\0';
 
 	gtk_moz_embed_set_path(xpcomLocation);
+	gtk_moz_embed_set_comp_path(SHARE_DIR);
 #endif // XPCOM_GLUE
 #ifdef GALEON_MOZILLA_HOME
 	mozilla_init_home ();
@@ -371,6 +387,8 @@
 
 	/* Fire up the beast */
 	gtk_moz_embed_push_startup ();
+
+	mozilla_init_login_manager();
 }
 
 
@@ -782,6 +800,126 @@
 		passwords = g_list_prepend (passwords, p);
         }       
 	return g_list_reverse (passwords);
+
+#elif defined(HAVE_NSILOGINMANAGER_H)
+	nsresult rv;
+	GList *passwords = NULL;
+	PRUint32 count,i;
+
+	nsCOMPtr<nsILoginManager> loginManager =
+			do_GetService (NS_LOGINMANAGER_CONTRACTID);
+	NS_ENSURE_TRUE (loginManager, NULL);
+
+	nsCOMPtr<nsIIDNService> idnService
+		(do_GetService ("@mozilla.org/network/idn-service;1"));
+	NS_ENSURE_TRUE (idnService, NULL);
+
+	if (type == PASSWORD_REJECT) {
+		PRUnichar **hostnames = nsnull;
+
+		rv = loginManager->GetAllDisabledHosts (&count, &hostnames);
+		NS_ENSURE_SUCCESS(rv, NULL);
+
+		for (i = 0; i < count; i++) {
+			nsCString host;
+			nsString transfer (hostnames[i]);
+			idnService->ConvertACEtoUTF8 (NS_ConvertUTF16toUTF8(transfer), host);
+
+	                PasswordInfo *p = g_new0 (PasswordInfo, 1);
+	                p->host = g_strdup(host.get());
+
+			passwords = g_list_prepend (passwords, p);
+		}
+
+		NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY (count, hostnames);
+	} else {
+		nsILoginInfo **logins = nsnull;
+		nsresult rv;
+
+		rv = loginManager->GetAllLogins (&count, &logins);
+		NS_ENSURE_SUCCESS(rv, NULL);
+
+		for (i=0; i < count; i++) {
+			nsString transfer;
+			nsString unicodeName;
+			rv = logins[i]->GetHostname (transfer);
+			if (NS_FAILED (rv)) continue;
+
+			nsCString host;
+			if (transfer.IsVoid())
+                  	host.SetIsVoid(PR_TRUE);
+                	else
+                  	idnService->ConvertACEtoUTF8 (NS_ConvertUTF16toUTF8(transfer), host);
+
+			rv = logins[i]->GetHttpRealm (unicodeName);
+			if (NS_FAILED (rv)) continue;
+			nsCString httpRealm;
+			if (unicodeName.IsVoid())
+                  	httpRealm.SetIsVoid(PR_TRUE);
+                	else
+                  	NS_UTF16ToCString (unicodeName,
+                                    	NS_CSTRING_ENCODING_UTF8, httpRealm);
+
+			rv = logins[i]->GetUsername (unicodeName);
+			if (NS_FAILED (rv)) continue;
+			nsCString userName;
+			if (unicodeName.IsVoid())
+                  	userName.SetIsVoid(PR_TRUE);
+                	else
+                  	NS_UTF16ToCString (unicodeName,
+                                    	NS_CSTRING_ENCODING_UTF8, userName);
+
+			rv = logins[i]->GetUsernameField (unicodeName);
+			if (NS_FAILED (rv)) continue;
+			nsCString usernameField;
+			if (unicodeName.IsVoid())
+                  	usernameField.SetIsVoid(PR_TRUE);
+                	else
+                  	NS_UTF16ToCString (unicodeName,
+                                    	NS_CSTRING_ENCODING_UTF8, usernameField);
+
+			rv = logins[i]->GetPassword (unicodeName);
+			if (NS_FAILED (rv)) continue;
+			nsCString userPassword;
+			if (unicodeName.IsVoid())
+                  	userPassword.SetIsVoid(PR_TRUE);
+                	else
+                  	NS_UTF16ToCString (unicodeName,
+                                    	NS_CSTRING_ENCODING_UTF8, userPassword);
+
+			rv = logins[i]->GetPasswordField (unicodeName);
+			if (NS_FAILED (rv)) continue;
+			nsCString passwordField;
+			if (unicodeName.IsVoid())
+                  	passwordField.SetIsVoid(PR_TRUE);
+                	else
+                  	NS_UTF16ToCString (unicodeName,
+                                    	NS_CSTRING_ENCODING_UTF8, passwordField);
+
+			rv = logins[i]->GetFormSubmitURL (unicodeName);
+			if (NS_FAILED (rv)) continue;
+			nsCString formSubmitURL;
+			if (unicodeName.IsVoid())
+                  	formSubmitURL.SetIsVoid(PR_TRUE);
+                	else
+                  	NS_UTF16ToCString (unicodeName,
+                                    	NS_CSTRING_ENCODING_UTF8, formSubmitURL);
+
+			PasswordInfo *p = g_new0(PasswordInfo, 1);
+			p->host = host.IsVoid() ? NULL: g_strdup(host.get());
+			p->username = userName.IsVoid() ? NULL: g_strdup(userName.get());
+			p->password = userPassword.IsVoid() ? NULL: g_strdup(userPassword.get());
+			p->httpRealm = httpRealm.IsVoid() ? NULL : g_strdup(httpRealm.get());
+			p->usernameField = usernameField.IsVoid() ? NULL : g_strdup(usernameField.get());
+			p->passwordField = passwordField.IsVoid() ? NULL : g_strdup(passwordField.get());
+			p->formSubmitURL = formSubmitURL.IsVoid() ? NULL : g_strdup(formSubmitURL.get());
+
+			passwords = g_list_prepend (passwords, p);
+		}
+
+		NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY (count, logins);
+	}
+	return passwords;
 #else
 	return NULL;
 #endif
@@ -792,6 +930,7 @@
 		       GList *passwords, 
 		       PasswordType type)
 {
+#ifdef HAVE_NSIPASSWORD_H
 	nsresult result = NS_ERROR_FAILURE;
         nsCOMPtr<nsIPasswordManager> passwordManager =
                         do_GetService(NS_PASSWORDMANAGER_CONTRACTID);
@@ -812,6 +951,93 @@
 
                 if (NS_FAILED(result)) return;
         };
+
+#elif defined (HAVE_NSILOGINMANAGER_H)
+      	nsCOMPtr<nsILoginManager> loginManager =
+		do_GetService (NS_LOGINMANAGER_CONTRACTID);
+	NS_ENSURE_TRUE (loginManager, );
+
+	if (type == PASSWORD_REJECT) {
+	        for (GList *l = passwords; l != NULL; l = l->next)
+        	{
+                	PasswordInfo *info = (PasswordInfo *)l->data;
+
+			nsString host;
+			NS_CStringToUTF16(nsCString(info->host),
+					  NS_CSTRING_ENCODING_UTF8, host);
+			loginManager->SetLoginSavingEnabled(host, TRUE);
+		}
+	} else {
+        	for (GList *l = passwords; l != NULL; l = l->next)
+        	{
+                	PasswordInfo *info = (PasswordInfo *)l->data;
+
+			nsString userName;
+
+	        	if (info->username)
+	          	NS_CStringToUTF16 (nsCString(info->username),
+        	                    	NS_CSTRING_ENCODING_UTF8, userName);
+        		else
+          		userName.SetIsVoid (PR_TRUE);
+
+			nsString host;
+			nsString userNameField;
+			nsString password;
+			nsString passwordField;
+			nsString httpRealm;
+			nsString formSubmitURL;
+
+        		if (info->host)
+          		NS_CStringToUTF16 (nsCString(info->host),
+                            		NS_CSTRING_ENCODING_UTF8, host);
+        		else
+          		host.SetIsVoid (PR_TRUE);
+
+        		if (info->usernameField)
+          		NS_CStringToUTF16 (nsCString(info->usernameField),
+                            		NS_CSTRING_ENCODING_UTF8, userNameField);
+        		else
+          		userNameField.SetIsVoid (PR_TRUE);
+
+        		if (info->httpRealm)
+          		NS_CStringToUTF16 (nsCString(info->httpRealm),
+                            		NS_CSTRING_ENCODING_UTF8, httpRealm);
+        		else
+          		httpRealm.SetIsVoid (PR_TRUE);
+
+        		if (info->password)
+          		NS_CStringToUTF16 (nsCString(info->password),
+                            		NS_CSTRING_ENCODING_UTF8, password);
+        		else
+          		password.SetIsVoid (PR_TRUE);
+
+        		if (info->passwordField)
+          		NS_CStringToUTF16 (nsCString(info->passwordField),
+                            		NS_CSTRING_ENCODING_UTF8, passwordField);
+        		else
+          		passwordField.SetIsVoid (PR_TRUE);
+
+        		if (info->formSubmitURL)
+          		NS_CStringToUTF16 (nsCString(info->formSubmitURL),
+                            		NS_CSTRING_ENCODING_UTF8, formSubmitURL);
+        		else
+          		formSubmitURL.SetIsVoid (PR_TRUE);
+
+			nsCOMPtr<nsILoginInfo> login
+				(do_CreateInstance(NS_LOGININFO_CONTRACTID));
+
+			login->SetUsername(userName);
+			login->SetUsernameField(userNameField);
+			login->SetHostname(host);
+			login->SetHttpRealm(httpRealm);
+			login->SetFormSubmitURL(formSubmitURL);
+			login->SetPassword(password);
+			login->SetPasswordField(passwordField);
+
+			loginManager->RemoveLogin(login);
+		}
+	}
+#endif
 }
 
 static GList *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]