From cce4921f040c9756af1cbc573e1a7efcebe6a02a Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sun, 4 Nov 2007 23:35:28 +0000 Subject: Add remove_all_passwords method to EphyPasswordManager and implement it in Mozilla and XulRunner backends. Bug #476411. svn path=/trunk/; revision=7623 --- embed/ephy-password-manager.c | 13 +++++++++ embed/ephy-password-manager.h | 3 ++ embed/mozilla/mozilla-embed-single.cpp | 40 ++++++++++++++++++++++++++ embed/webkit/webkit-embed-single.cpp | 6 ++++ embed/xulrunner/embed/mozilla-embed-single.cpp | 19 ++++++++++++ 5 files changed, 81 insertions(+) diff --git a/embed/ephy-password-manager.c b/embed/ephy-password-manager.c index c4fb56143..6f1b49520 100644 --- a/embed/ephy-password-manager.c +++ b/embed/ephy-password-manager.c @@ -186,6 +186,19 @@ ephy_password_manager_remove_password (EphyPasswordManager *manager, iface->remove (manager, info); } +/** + * ephy_password_manager_remove_all_passwords: + * @manager: the #EphyPasswordManager + * + * Removes all the password entries from the password database. + **/ +void +ephy_password_manager_remove_all_passwords (EphyPasswordManager *manager) +{ + EphyPasswordManagerIface *iface = EPHY_PASSWORD_MANAGER_GET_IFACE (manager); + iface->remove_all (manager); +} + /** * ephy_password_manager_list_passwords: * @manager: the #EphyPasswordManager diff --git a/embed/ephy-password-manager.h b/embed/ephy-password-manager.h index 7b85a0092..8dd2751af 100644 --- a/embed/ephy-password-manager.h +++ b/embed/ephy-password-manager.h @@ -58,6 +58,7 @@ struct _EphyPasswordManagerIface EphyPasswordInfo *info); void (* remove) (EphyPasswordManager *manager, EphyPasswordInfo *info); + void (* remove_all) (EphyPasswordManager *manager); GList * (* list) (EphyPasswordManager *manager); }; @@ -83,6 +84,8 @@ void ephy_password_manager_add_password (EphyPasswordManager *manager, void ephy_password_manager_remove_password (EphyPasswordManager *manager, EphyPasswordInfo *info); +void ephy_password_manager_remove_all_passwords (EphyPasswordManager *manager); + GList * ephy_password_manager_list_passwords (EphyPasswordManager *manager); G_END_DECLS diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp index 77a982007..1d07ab548 100644 --- a/embed/mozilla/mozilla-embed-single.cpp +++ b/embed/mozilla/mozilla-embed-single.cpp @@ -957,6 +957,45 @@ impl_remove_password (EphyPasswordManager *manager, #endif /* !HAVE_GECKO_1_9 */ } +static void +impl_remove_all_passwords (EphyPasswordManager *manager) +{ +#ifndef HAVE_GECKO_1_9 + nsresult rv; + nsCOMPtr passwordManager = + do_GetService (NS_PASSWORDMANAGER_CONTRACTID); + if (!passwordManager) return; + + nsCOMPtr idnService + (do_GetService ("@mozilla.org/network/idn-service;1")); + NS_ENSURE_TRUE (idnService, ); + + nsCOMPtr passwordEnumerator; + passwordManager->GetEnumerator (getter_AddRefs(passwordEnumerator)); + NS_ENSURE_TRUE (passwordEnumerator, ); + + PRBool enumResult; + for (passwordEnumerator->HasMoreElements(&enumResult) ; + enumResult == PR_TRUE ; + passwordEnumerator->HasMoreElements(&enumResult)) + { + nsCOMPtr nsPassword; + passwordEnumerator->GetNext (getter_AddRefs(nsPassword)); + if (!nsPassword) continue; + + nsCString host; + rv = nsPassword->GetHost (host); + if (NS_FAILED (rv)) continue; + + nsString userName; + rv = nsPassword->GetUser (userName); + if (NS_FAILED (rv)) continue; + + passwordManager->RemoveUser (host, userName); + } +#endif /* !HAVE_GECKO_1_9 */ +} + static void impl_add_password (EphyPasswordManager *manager, EphyPasswordInfo *info) @@ -1337,6 +1376,7 @@ ephy_password_manager_iface_init (EphyPasswordManagerIface *iface) { iface->add = impl_add_password; iface->remove = impl_remove_password; + iface->remove_all = impl_remove_all_passwords; iface->list = impl_list_passwords; } diff --git a/embed/webkit/webkit-embed-single.cpp b/embed/webkit/webkit-embed-single.cpp index 0946472d3..cb4174213 100644 --- a/embed/webkit/webkit-embed-single.cpp +++ b/embed/webkit/webkit-embed-single.cpp @@ -168,6 +168,11 @@ impl_remove_password (EphyPasswordManager *manager, { } +static void +impl_remove_all_passwords (EphyPasswordManager *manager) +{ +} + static void impl_add_password (EphyPasswordManager *manager, EphyPasswordInfo *info) @@ -328,6 +333,7 @@ ephy_password_manager_iface_init (EphyPasswordManagerIface *iface) { iface->add = impl_add_password; iface->remove = impl_remove_password; + iface->remove = impl_remove_all_passwords; iface->list = impl_list_passwords; } diff --git a/embed/xulrunner/embed/mozilla-embed-single.cpp b/embed/xulrunner/embed/mozilla-embed-single.cpp index e2236297c..ab0373085 100644 --- a/embed/xulrunner/embed/mozilla-embed-single.cpp +++ b/embed/xulrunner/embed/mozilla-embed-single.cpp @@ -982,6 +982,25 @@ impl_remove_password (EphyPasswordManager *manager, #endif } +static void +impl_remove_all_passwords (EphyPasswordManager *manager) +{ + nsresult rv; + nsCOMPtr loginManager = + do_GetService (NS_LOGINMANAGER_CONTRACTID); + g_return_val_if_fail (NS_SUCCEEDED (rv), NULL); + if (!loginManager) + return NULL; + + nsCOMPtr idnService + (do_GetService ("@mozilla.org/network/idn-service;1")); + NS_ENSURE_TRUE (idnService, ); + + rv = loginManager->RemoveAllLogins (); + if (NS_FAILED (rv)) + return; +} + static void impl_add_password (EphyPasswordManager *manager, EphyPasswordInfo *info) -- cgit v1.2.3