diff --git a/mozilla/chrome/src/nsChromeFactory.cpp b/mozilla/chrome/src/nsChromeFactory.cpp index 742306efe44..3f0f089406e 100644 --- a/mozilla/chrome/src/nsChromeFactory.cpp +++ b/mozilla/chrome/src/nsChromeFactory.cpp @@ -44,9 +44,11 @@ #include "nsIChromeRegistry.h" #include "nscore.h" #include "rdf.h" +#include "nsChromeProtocolHandler.h" #include "nsChromeRegistry.h" NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsChromeRegistry, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsChromeProtocolHandler) // The list of components we register static const nsModuleComponentInfo components[] = @@ -57,10 +59,10 @@ static const nsModuleComponentInfo components[] = nsChromeRegistryConstructor }, - { "Chrome Registry", - NS_CHROMEREGISTRY_CID, - NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "chrome", - nsChromeRegistryConstructor + { "Chrome Protocol Handler", + NS_CHROMEPROTOCOLHANDLER_CID, + NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "chrome", + nsChromeProtocolHandlerConstructor } }; diff --git a/mozilla/chrome/src/nsChromeProtocolHandler.cpp b/mozilla/chrome/src/nsChromeProtocolHandler.cpp index e7cdb40986c..0ed910d7086 100644 --- a/mozilla/chrome/src/nsChromeProtocolHandler.cpp +++ b/mozilla/chrome/src/nsChromeProtocolHandler.cpp @@ -21,7 +21,6 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Benjamin Smedberg * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -43,12 +42,13 @@ */ -#include "nsChromeRegistry.h" +#include "nsChromeProtocolHandler.h" #include "nsCOMPtr.h" #include "nsContentCID.h" #include "nsCRT.h" #include "nsEventQueueUtils.h" #include "nsIChannel.h" +#include "nsIChromeRegistry.h" #include "nsIComponentManager.h" #include "nsIEventQueue.h" #include "nsIEventQueueService.h" @@ -80,6 +80,9 @@ static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID); #endif +// This comes from nsChromeRegistry.cpp +extern nsIChromeRegistry* gChromeRegistry; + //---------------------------------------------------------------------- // // A channel that's used for loading cached chrome documents. Since a @@ -419,25 +422,29 @@ nsCachedChromeChannel::DestroyLoadEvent(PLEvent* aEvent) delete aEvent; } +//////////////////////////////////////////////////////////////////////////////// + +NS_IMPL_THREADSAFE_ISUPPORTS2(nsChromeProtocolHandler, nsIProtocolHandler, nsISupportsWeakReference) + //////////////////////////////////////////////////////////////////////////////// // nsIProtocolHandler methods: NS_IMETHODIMP -nsChromeRegistry::GetScheme(nsACString &result) +nsChromeProtocolHandler::GetScheme(nsACString &result) { result.AssignLiteral("chrome"); return NS_OK; } NS_IMETHODIMP -nsChromeRegistry::GetDefaultPort(PRInt32 *result) +nsChromeProtocolHandler::GetDefaultPort(PRInt32 *result) { *result = -1; // no port for chrome: URLs return NS_OK; } NS_IMETHODIMP -nsChromeRegistry::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval) +nsChromeProtocolHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval) { // don't override anything. *_retval = PR_FALSE; @@ -445,17 +452,17 @@ nsChromeRegistry::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval) } NS_IMETHODIMP -nsChromeRegistry::GetProtocolFlags(PRUint32 *result) +nsChromeProtocolHandler::GetProtocolFlags(PRUint32 *result) { *result = URI_STD; return NS_OK; } NS_IMETHODIMP -nsChromeRegistry::NewURI(const nsACString &aSpec, - const char *aCharset, - nsIURI *aBaseURI, - nsIURI **result) +nsChromeProtocolHandler::NewURI(const nsACString &aSpec, + const char *aCharset, + nsIURI *aBaseURI, + nsIURI **result) { NS_PRECONDITION(result, "Null out param"); @@ -482,7 +489,20 @@ nsChromeRegistry::NewURI(const nsACString &aSpec, // "chrome://navigator/content/" and "chrome://navigator/content" // and "chrome://navigator/content/navigator.xul". - rv = Canonify(uri); + // Try the global cache first. + nsCOMPtr reg = gChromeRegistry; + + // If that fails, the service has not been instantiated yet; let's + // do that now. + if (!reg) { + reg = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); + if (NS_FAILED(rv)) + return rv; + } + + NS_ASSERTION(reg, "Must have a chrome registry by now"); + + rv = reg->Canonify(uri); if (NS_FAILED(rv)) return rv; @@ -492,8 +512,8 @@ nsChromeRegistry::NewURI(const nsACString &aSpec, } NS_IMETHODIMP -nsChromeRegistry::NewChannel(nsIURI* aURI, - nsIChannel* *aResult) +nsChromeProtocolHandler::NewChannel(nsIURI* aURI, + nsIChannel* *aResult) { NS_ENSURE_ARG_POINTER(aURI); NS_PRECONDITION(aResult, "Null out param"); @@ -501,16 +521,20 @@ nsChromeRegistry::NewChannel(nsIURI* aURI, #ifdef DEBUG // Check that the uri we got is already canonified nsresult debug_rv; - nsCOMPtr debugClone; - debug_rv = aURI->Clone(getter_AddRefs(debugClone)); + nsCOMPtr debugReg(do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &debug_rv)); if (NS_SUCCEEDED(debug_rv)) { - debug_rv = Canonify(debugClone); + nsCOMPtr debugClone; + debug_rv = aURI->Clone(getter_AddRefs(debugClone)); if (NS_SUCCEEDED(debug_rv)) { - PRBool same; - debug_rv = aURI->Equals(debugClone, &same); + debug_rv = debugReg->Canonify(debugClone); if (NS_SUCCEEDED(debug_rv)) { - NS_ASSERTION(same, "Non-canonified chrome uri passed to nsChromeProtocolHandler::NewChannel!"); + PRBool same; + debug_rv = aURI->Equals(debugClone, &same); + if (NS_SUCCEEDED(debug_rv)) { + NS_ASSERTION(same, "Non-canonified chrome uri passed to nsChromeProtocolHandler::NewChannel!"); + } } + } } #endif @@ -523,7 +547,7 @@ nsChromeRegistry::NewChannel(nsIURI* aURI, // document in the cache. nsCOMPtr cache = do_GetService(kXULPrototypeCacheCID, &rv); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) return rv; nsCOMPtr proto; cache->GetPrototype(aURI, getter_AddRefs(proto)); @@ -548,7 +572,8 @@ nsChromeRegistry::NewChannel(nsIURI* aURI, // ...in which case, we'll create a dummy stream that'll just // load the thing. result = new nsCachedChromeChannel(aURI); - NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY); + if (! result) + return NS_ERROR_OUT_OF_MEMORY; } else #endif @@ -559,8 +584,14 @@ nsChromeRegistry::NewChannel(nsIURI* aURI, //aURI->GetSpec(getter_Copies(oldSpec)); //printf("*************************** %s\n", (const char*)oldSpec); + nsCOMPtr reg = gChromeRegistry; + if (!reg) { + reg = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + } + nsCAutoString spec; - rv = ConvertChromeURL(aURI, spec); + rv = reg->ConvertChromeURL(aURI, spec); if (NS_FAILED(rv)) { #ifdef DEBUG aURI->GetSpec(spec); @@ -570,14 +601,14 @@ nsChromeRegistry::NewChannel(nsIURI* aURI, } nsCOMPtr ioServ(do_GetIOService(&rv)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) return rv; nsCOMPtr chromeURI; rv = ioServ->NewURI(spec, nsnull, nsnull, getter_AddRefs(chromeURI)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) return rv; rv = ioServ->NewChannelFromURI(chromeURI, getter_AddRefs(result)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) return rv; // XXX Will be removed someday when we handle remote chrome. nsCOMPtr fileChan @@ -609,7 +640,7 @@ nsChromeRegistry::NewChannel(nsIURI* aURI, // Make sure that the channel remembers where it was // originally loaded from. rv = result->SetOriginalURI(aURI); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) return rv; // Get a system principal for xul files and set the owner // property of the result @@ -622,11 +653,11 @@ nsChromeRegistry::NewChannel(nsIURI* aURI, { nsCOMPtr securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) return rv; nsCOMPtr principal; rv = securityManager->GetSystemPrincipal(getter_AddRefs(principal)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) return rv; nsCOMPtr owner = do_QueryInterface(principal); result->SetOwner(owner); diff --git a/mozilla/chrome/src/nsChromeProtocolHandler.h b/mozilla/chrome/src/nsChromeProtocolHandler.h new file mode 100644 index 00000000000..6ae1a4d79cc --- /dev/null +++ b/mozilla/chrome/src/nsChromeProtocolHandler.h @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsChromeProtocolHandler_h___ +#define nsChromeProtocolHandler_h___ + +#include "nsIProtocolHandler.h" +#include "nsWeakReference.h" + +#define NS_CHROMEPROTOCOLHANDLER_CID \ +{ /* 61ba33c0-3031-11d3-8cd0-0060b0fc14a3 */ \ + 0x61ba33c0, \ + 0x3031, \ + 0x11d3, \ + {0x8c, 0xd0, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \ +} + +class nsChromeProtocolHandler : public nsIProtocolHandler, public nsSupportsWeakReference +{ +public: + NS_DECL_ISUPPORTS + + // nsIProtocolHandler methods: + NS_DECL_NSIPROTOCOLHANDLER + + // nsChromeProtocolHandler methods: + nsChromeProtocolHandler() {} + ~nsChromeProtocolHandler() {} +}; + +#endif /* nsChromeProtocolHandler_h___ */ diff --git a/mozilla/chrome/src/nsChromeRegistry.cpp b/mozilla/chrome/src/nsChromeRegistry.cpp index 69c8fb8bf3e..c23b8fda555 100644 --- a/mozilla/chrome/src/nsChromeRegistry.cpp +++ b/mozilla/chrome/src/nsChromeRegistry.cpp @@ -122,6 +122,8 @@ static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID); static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID); static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); +nsIChromeRegistry* gChromeRegistry = nsnull; + #define CHROME_URI "http://www.mozilla.org/rdf/chrome#" DEFINE_RDF_VOCAB(CHROME_URI, CHROME, baseURL); @@ -173,6 +175,8 @@ DatasourceEnumerator(nsHashKey *aKey, void *aData, void* closure) nsChromeRegistry::~nsChromeRegistry() { + gChromeRegistry = nsnull; + if (mDataSourceTable) { mDataSourceTable->Enumerate(DatasourceEnumerator, mChromeDataSource); delete mDataSourceTable; @@ -190,11 +194,10 @@ nsChromeRegistry::~nsChromeRegistry() } -NS_IMPL_THREADSAFE_ISUPPORTS6(nsChromeRegistry, +NS_IMPL_THREADSAFE_ISUPPORTS5(nsChromeRegistry, nsIChromeRegistry, nsIXULChromeRegistry, nsIXULOverlayProvider, - nsIProtocolHandler, nsIObserver, nsISupportsWeakReference) @@ -245,6 +248,8 @@ nsChromeRegistry::Init() if (!mSelectedLocales.Init()) return NS_ERROR_FAILURE; if (!mSelectedSkins.Init()) return NS_ERROR_FAILURE; + gChromeRegistry = this; + nsresult rv; rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService), @@ -359,6 +364,8 @@ nsChromeRegistry::Init() } } + CheckForNewChrome(); + return NS_OK; } @@ -2596,11 +2603,7 @@ nsresult nsChromeRegistry::LoadInstallDataSource() NS_ENSURE_SUCCESS(rv, rv); mInstallInitialized = PR_TRUE; - rv = AddToCompositeDataSource(PR_FALSE); - NS_ENSURE_SUCCESS(rv, rv); - - (void) RealCheckForNewChrome(); - return NS_OK; + return AddToCompositeDataSource(PR_FALSE); } nsresult nsChromeRegistry::LoadProfileDataSource() @@ -2612,9 +2615,7 @@ nsresult nsChromeRegistry::LoadProfileDataSource() mProfileInitialized = mInstallInitialized = PR_TRUE; mChromeDataSource = nsnull; rv = AddToCompositeDataSource(PR_TRUE); - NS_ENSURE_SUCCESS(rv, rv); - - (void) RealCheckForNewChrome(); + if (NS_FAILED(rv)) return rv; } nsCOMPtr pref (do_GetService(NS_PREFSERVICE_CONTRACTID)); @@ -2695,18 +2696,9 @@ nsChromeRegistry::CheckForNewChrome() { nsresult rv; - if (mInstallInitialized) { - return RealCheckForNewChrome(); - } - - // LoadInstallDataSource calls RealCheckForNewChrome internally - return LoadInstallDataSource(); -} - -nsresult -nsChromeRegistry::RealCheckForNewChrome() -{ - nsresult rv; + rv = LoadInstallDataSource(); + if (NS_FAILED(rv)) + return rv; nsCOMPtr dirSvc = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv); diff --git a/mozilla/chrome/src/nsChromeRegistry.h b/mozilla/chrome/src/nsChromeRegistry.h index 1320112bc1e..222477cdab1 100644 --- a/mozilla/chrome/src/nsChromeRegistry.h +++ b/mozilla/chrome/src/nsChromeRegistry.h @@ -53,7 +53,6 @@ class nsIProperties; #include "nsIChromeRegistry.h" #include "nsIXULOverlayProvider.h" -#include "nsIProtocolHandler.h" #include "nsIRDFCompositeDataSource.h" #include "nsIObserver.h" #include "nsWeakReference.h" @@ -69,7 +68,6 @@ class nsIProperties; class nsChromeRegistry : public nsIXULChromeRegistry, public nsIXULOverlayProvider, - public nsIProtocolHandler, public nsIObserver, public nsSupportsWeakReference { @@ -81,9 +79,6 @@ public: NS_DECL_NSIXULCHROMEREGISTRY NS_DECL_NSIXULOVERLAYPROVIDER - // nsIProtocolHandler - NS_DECL_NSIPROTOCOLHANDLER - NS_DECL_NSIOBSERVER // nsChromeRegistry methods: @@ -172,7 +167,6 @@ private: nsresult UninstallFromDynamicDataSource(const nsACString& aPackageName, PRBool aIsOverlay, PRBool aUseProfile); - NS_HIDDEN_(nsresult) RealCheckForNewChrome(); NS_HIDDEN_(nsresult) ProcessNewChromeFile(nsILocalFile *aListFile); NS_HIDDEN_(nsresult) ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength);