From 9242cd362e394f3923d1b9bef45ab1bd86095c9d Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Mon, 24 Jan 2005 13:43:58 +0000 Subject: Work around a mozilla bug by diverting the contract ID of 2005-01-24 Christian Persch * embed/mozilla/EphyBrowser.cpp: * embed/mozilla/MozRegisterComponents.cpp: Work around a mozilla bug by diverting the contract ID of --- embed/mozilla/EphyBrowser.cpp | 46 +++++++++++++++++++++++++++++---- embed/mozilla/MozRegisterComponents.cpp | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 5 deletions(-) (limited to 'embed') diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp index 03076ef21..86d6b6073 100644 --- a/embed/mozilla/EphyBrowser.cpp +++ b/embed/mozilla/EphyBrowser.cpp @@ -188,15 +188,18 @@ EphyFaviconEventListener::HandleEvent(nsIDOMEvent* aDOMEvent) /* disallow subframes to set favicon */ if (domWinAsISupports != topDomWinAsISupports) return NS_OK; - nsCOMPtr doc = do_QueryInterface (domDoc); + nsCOMPtr doc (do_QueryInterface (domDoc)); NS_ENSURE_TRUE (doc, NS_ERROR_FAILURE); nsEmbedString spec; rv = doc->GetDocumentURI (spec); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + nsEmbedCString encoding; + mOwner->GetEncoding (encoding); + nsCOMPtr docUri; - EphyUtils::NewURI (getter_AddRefs(docUri), spec); + EphyUtils::NewURI (getter_AddRefs(docUri), spec, encoding.get()); NS_ENSURE_TRUE (docUri, NS_ERROR_FAILURE); nsEmbedCString faviconUrl; @@ -497,9 +500,42 @@ nsresult EphyBrowser::Init (GtkMozEmbed *mozembed) * but we cannot get to it! * See https://bugzilla.mozilla.org/show_bug.cgi?id=94974 */ - mSecurityInfo = do_CreateInstance(NS_SECURE_BROWSER_UI_CONTRACTID, &rv); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && mSecurityInfo, NS_ERROR_FAILURE); - mSecurityInfo->Init (mDOMWindow); + /* First try GI */ + mSecurityInfo = do_GetInterface (mWebBrowser); + /* Try to instantiate it under the re-registered contract ID */ + if (!mSecurityInfo) + { + /* This will cause all security warning dialogs to be shown + * twice (once by this instance, and another time by nsWebBrowser's + * instance of nsSecurityBrowserUIImpl), but there appears to be + * no other way :-( + */ + mSecurityInfo = do_CreateInstance("@gnome.org/project/epiphany/hacks/secure-browser-ui;1", &rv); + if (NS_SUCCEEDED (rv) && mSecurityInfo) + { + rv = mSecurityInfo->Init (mDOMWindow); + NS_ENSURE_SUCCESS (rv, rv); + } + } + /* Try the original contract ID */ + if (!mSecurityInfo) + { + /* This will cause all security warning dialogs to be shown + * twice (once by this instance, and another time by nsWebBrowser's + * instance of nsSecurityBrowserUIImpl), but there appears to be + * no other way :-( + */ + mSecurityInfo = do_CreateInstance(NS_SECURE_BROWSER_UI_CONTRACTID, &rv); + if (NS_SUCCEEDED (rv) && mSecurityInfo) + { + rv = mSecurityInfo->Init (mDOMWindow); + NS_ENSURE_SUCCESS (rv, rv); + } + } + if (!mSecurityInfo) + { + g_warning ("Failed to instantiate nsISecureBrowserUI!\n"); + } #endif mInitialized = PR_TRUE; diff --git a/embed/mozilla/MozRegisterComponents.cpp b/embed/mozilla/MozRegisterComponents.cpp index 8dd86b6ee..9dba24c9b 100644 --- a/embed/mozilla/MozRegisterComponents.cpp +++ b/embed/mozilla/MozRegisterComponents.cpp @@ -39,6 +39,7 @@ #include "GtkNSSDialogs.h" #include "GtkNSSKeyPairDialogs.h" #include "GtkNSSSecurityWarningDialogs.h" +#include #endif #include @@ -185,6 +186,42 @@ static const nsModuleComponentInfo sAppComps[] = { }, }; +#ifdef HAVE_MOZILLA_PSM +/* 5999dfd3-571f-4fcf-964b-386879f5cded */ +#define NEW_CID { 0x5999dfd3, 0x571f, 0x4fcf, { 0x96, 0x4b, 0x38, 0x68, 0x79, 0xf5, 0xcd, 0xed } } + +static nsresult +reregister_secure_browser_ui (nsIComponentManager *cm, + nsIComponentRegistrar *cr) +{ + NS_ENSURE_ARG (cm); + NS_ENSURE_ARG (cr); + + /* Workaround as a result of: + * https://bugzilla.mozilla.org/show_bug.cgi?id=94974 + * see + * http://bugzilla.gnome.org/show_bug.cgi?id=164670 + */ + + nsresult rv; + nsCOMPtr factory; + rv = cm->GetClassObjectByContractID (NS_SECURE_BROWSER_UI_CONTRACTID, NS_GET_IID(nsIFactory), getter_AddRefs (factory)); + NS_ENSURE_SUCCESS (rv, rv); + + nsCID *cidPtr = nsnull; + rv = cr->ContractIDToCID(NS_SECURE_BROWSER_UI_CONTRACTID, &cidPtr); + NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && cidPtr, rv); + + rv = cr->UnregisterFactory (*cidPtr, factory); + NS_ENSURE_SUCCESS (rv, rv); + + const nsCID new_cid = NEW_CID; + rv = cr->RegisterFactory (new_cid, "Epiphany Secure Browser Class", "@gnome.org/project/epiphany/hacks/secure-browser-ui;1", factory); + nsMemory::Free (cidPtr); + + return rv; +} +#endif /* HAVE_MOZILLA_PSM */ gboolean mozilla_register_components (void) @@ -236,5 +273,14 @@ mozilla_register_components (void) } } +#ifdef HAVE_MOZILLA_PSM + /* Workaround for http://bugzilla.gnome.org/show_bug.cgi?id=164670 */ + rv = reregister_secure_browser_ui (cm, cr); + if (NS_FAILED (rv)) + { + g_warning ("Failed to divert the nsISecureBrowserUI implementation!\n"); + } +#endif /* HAVE_MOZILLA_PSM */ + return ret; } -- cgit v1.2.3