diff --git a/mozilla/chrome/public/nsIChromeRegistry.idl b/mozilla/chrome/public/nsIChromeRegistry.idl new file mode 100644 index 00000000000..f61a88decd7 --- /dev/null +++ b/mozilla/chrome/public/nsIChromeRegistry.idl @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Mozilla browser. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1999 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): hyatt and pav :) + */ + +#include "nsISupports.idl" +#include "nsIURL.idl" + +[scriptable, uuid(D8C7D8A1-E84C-11d2-BF87-00105A1B0627)] +interface nsIChromeRegistry : nsISupports +{ + void convertChromeURL(in nsIURI aChromeURL); + long getOverlayCount(in wstring aChromeURL); + wstring getOverlayAt(in wstring aChromeURL, in long aIndex); +}; + + +%{ C++ + +// for component registration +// {D8C7D8A2-E84C-11d2-BF87-00105A1B0627} +#define NS_CHROMEREGISTRY_CID \ +{ 0xd8c7d8a2, 0xe84c, 0x11d2, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } } + +extern nsresult +NS_NewChromeRegistry(nsIChromeRegistry* *aResult); +%} diff --git a/mozilla/chrome/src/nsChromeProtocolHandler.cpp b/mozilla/chrome/src/nsChromeProtocolHandler.cpp index b43ad291c91..14ffda12870 100644 --- a/mozilla/chrome/src/nsChromeProtocolHandler.cpp +++ b/mozilla/chrome/src/nsChromeProtocolHandler.cpp @@ -148,13 +148,6 @@ nsChromeProtocolHandler::NewChannel(const char* verb, nsIURI* uri, NS_WITH_SERVICE(nsIChromeRegistry, reg, kChromeRegistryCID, &rv); if (NS_FAILED(rv)) return rv; - static PRBool inited = PR_FALSE; - if (!inited) { - rv = reg->InitRegistry(); - if (NS_FAILED(rv)) return rv; - inited = PR_TRUE; - } - nsIURI* chromeURI; rv = uri->Clone(&chromeURI); // don't mangle the original if (NS_FAILED(rv)) return rv; diff --git a/mozilla/chrome/src/nsChromeRegistry.cpp b/mozilla/chrome/src/nsChromeRegistry.cpp index 33437f69753..fee6e7b78d5 100644 --- a/mozilla/chrome/src/nsChromeRegistry.cpp +++ b/mozilla/chrome/src/nsChromeRegistry.cpp @@ -67,8 +67,7 @@ public: NS_DECL_ISUPPORTS // nsIChromeRegistry methods: - NS_IMETHOD InitRegistry(); - NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURL); + NS_DECL_NSICHROMEREGISTRY // nsChromeRegistry methods: nsChromeRegistry(); @@ -85,6 +84,7 @@ public: static nsIRDFResource* kCHROME_archive; static nsIRDFResource* kCHROME_name; static nsIRDFResource* kCHROME_displayname; + static nsSupportsHashtable *mDataSourceTable; protected: NS_IMETHOD InitializeDataSource(nsString &aPackage, @@ -94,12 +94,14 @@ protected: nsresult GetChromeResource(nsIRDFDataSource *aDataSource, nsString& aResult, nsIRDFResource* aChromeResource, nsIRDFResource* aProperty); -protected: - nsSupportsHashtable *mDataSourceTable; +private: + NS_IMETHOD LoadDataSource(const nsCAutoString &aFileName, nsIRDFDataSource **aResult); + }; PRUint32 nsChromeRegistry::gRefCnt ; nsIRDFService* nsChromeRegistry::gRDFService = nsnull; +nsSupportsHashtable* nsChromeRegistry::mDataSourceTable = nsnull; nsIRDFResource* nsChromeRegistry::kCHROME_chrome = nsnull; nsIRDFResource* nsChromeRegistry::kCHROME_skin = nsnull; @@ -116,13 +118,48 @@ nsIRDFResource* nsChromeRegistry::kCHROME_displayname = nsnull; nsChromeRegistry::nsChromeRegistry() { NS_INIT_REFCNT(); - mDataSourceTable = nsnull; + + + gRefCnt++; + if (gRefCnt == 1) { + nsresult rv; + rv = nsServiceManager::GetService(kRDFServiceCID, + kIRDFServiceIID, + (nsISupports**)&gRDFService); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); + + // get all the properties we'll need: + rv = gRDFService->GetResource(kURICHROME_chrome, &kCHROME_chrome); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_skin, &kCHROME_skin); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_content); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_locale, &kCHROME_locale); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_base, &kCHROME_base); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_main, &kCHROME_main); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_archive, &kCHROME_archive); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_name, &kCHROME_name); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_displayname, &kCHROME_displayname); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + } } nsChromeRegistry::~nsChromeRegistry() { - delete mDataSourceTable; - --gRefCnt; if (gRefCnt == 0) { @@ -136,6 +173,7 @@ nsChromeRegistry::~nsChromeRegistry() NS_IF_RELEASE(kCHROME_archive); NS_IF_RELEASE(kCHROME_displayname); NS_IF_RELEASE(kCHROME_name); + delete mDataSourceTable; if (gRDFService) { nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); @@ -314,56 +352,43 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL) return NS_OK; } - -NS_IMETHODIMP -nsChromeRegistry::InitRegistry() +NS_IMETHODIMP nsChromeRegistry::GetOverlayCount(const PRUnichar *aChromeURL, PRInt32 *aResult) { - gRefCnt++; - if (gRefCnt == 1) { - nsresult rv; - rv = nsServiceManager::GetService(kRDFServiceCID, - kIRDFServiceIID, - (nsISupports**)&gRDFService); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); - if (NS_FAILED(rv)) return rv; + return NS_OK; +} - // get all the properties we'll need: - rv = gRDFService->GetResource(kURICHROME_chrome, &kCHROME_chrome); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; +NS_IMETHODIMP nsChromeRegistry::GetOverlayAt(const PRUnichar *aChromeURL, PRInt32 aIndex, PRUnichar **aResult) +{ + return NS_OK; +} - rv = gRDFService->GetResource(kURICHROME_skin, &kCHROME_skin); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; +NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCAutoString &aFileName, nsIRDFDataSource **aResult) +{ + nsresult rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID, + nsnull, + NS_GET_IID(nsIRDFDataSource), + (void**) aResult); + if (NS_FAILED(rv)) return rv; - rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_content); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; - rv = gRDFService->GetResource(kURICHROME_locale, &kCHROME_locale); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; + nsCOMPtr remote = do_QueryInterface(*aResult); + if (! remote) + return NS_ERROR_UNEXPECTED; - rv = gRDFService->GetResource(kURICHROME_base, &kCHROME_base); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; - rv = gRDFService->GetResource(kURICHROME_main, &kCHROME_main); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; + rv = remote->Init(aFileName); + if (NS_FAILED(rv)) return rv; - rv = gRDFService->GetResource(kURICHROME_archive, &kCHROME_archive); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; + // We need to read this synchronously. + rv = remote->Refresh(PR_TRUE); + if (NS_FAILED(rv)) return rv; - rv = gRDFService->GetResource(kURICHROME_name, &kCHROME_name); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; - rv = gRDFService->GetResource(kURICHROME_displayname, &kCHROME_displayname); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; - } + if (!mDataSourceTable) + mDataSourceTable = new nsSupportsHashtable; + + nsCOMPtr supports = do_QueryInterface(remote); + mDataSourceTable->Put(&nsStringKey(aFileName), (void*)supports.get()); return NS_OK; } @@ -373,18 +398,20 @@ nsChromeRegistry::InitializeDataSource(nsString &aPackage, nsString &aProvider, nsIRDFDataSource **aResult) { - - nsCAutoString chromeFile; + nsCAutoString chromeFile, overlayFile; // Retrieve the mInner data source. chromeFile = "resource:/chrome/"; chromeFile += aPackage; chromeFile += aProvider; // provider already has a / in the front of it chromeFile += "/"; - chromeFile += "current.rdf"; + overlayFile = chromeFile; + chromeFile += "current.rdf"; + overlayFile += "overlays.rdf"; if (mDataSourceTable) { + // current.rdf and overlays.rdf are loaded in pairs and so if one is loaded, the other should be too. void *data = mDataSourceTable->Get(&nsStringKey(chromeFile)); if (data) { @@ -402,32 +429,12 @@ nsChromeRegistry::InitializeDataSource(nsString &aPackage, } } - nsresult rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID, - nsnull, - NS_GET_IID(nsIRDFDataSource), - (void**) aResult); - if (NS_FAILED(rv)) return rv; + nsCOMPtr overlayDataSource; + LoadDataSource(chromeFile, aResult); + LoadDataSource(overlayFile, getter_AddRefs(overlayDataSource)); - nsCOMPtr remote = do_QueryInterface(*aResult); - if (! remote) - return NS_ERROR_UNEXPECTED; - - - rv = remote->Init(chromeFile); - if (NS_FAILED(rv)) return rv; - - // We need to read this synchronously. - rv = remote->Refresh(PR_TRUE); - if (NS_FAILED(rv)) return rv; - - if (!mDataSourceTable) - mDataSourceTable = new nsSupportsHashtable; - - nsCOMPtr supports = do_QueryInterface(remote); - mDataSourceTable->Put(&nsStringKey(chromeFile), (void*)supports.get()); - - return NS_OK; + return NS_OK; } //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/rdf/chrome/build/makefile.win b/mozilla/rdf/chrome/build/makefile.win index 183fb491c42..f5e6a02f1cd 100644 --- a/mozilla/rdf/chrome/build/makefile.win +++ b/mozilla/rdf/chrome/build/makefile.win @@ -42,5 +42,4 @@ include <$(DEPTH)\config\rules.mak> install:: $(DLL) $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib - $(MAKE_INSTALL) registry.rdf $(DIST)\bin\chrome diff --git a/mozilla/rdf/chrome/public/Makefile.in b/mozilla/rdf/chrome/public/Makefile.in index 17b738ade18..2a6a8b53bd4 100644 --- a/mozilla/rdf/chrome/public/Makefile.in +++ b/mozilla/rdf/chrome/public/Makefile.in @@ -23,8 +23,11 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk MODULE = chrome +XPIDL_MODULE= chrome -EXPORTS = $(srcdir)/nsIChromeRegistry.h +XPIDLSRCS = \ + nsIChromeRegistry.idl \ + $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/rdf/chrome/public/makefile.win b/mozilla/rdf/chrome/public/makefile.win index b6ce81631db..25cdfb647f1 100644 --- a/mozilla/rdf/chrome/public/makefile.win +++ b/mozilla/rdf/chrome/public/makefile.win @@ -17,9 +17,10 @@ DEPTH=..\..\.. MODULE=chrome +XPIDL_MODULE=chrome -EXPORTS = \ - nsIChromeRegistry.h \ +XPIDLSRCS = \ + .\nsIChromeRegistry.idl \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/rdf/chrome/public/nsIChromeRegistry.h b/mozilla/rdf/chrome/public/nsIChromeRegistry.h index 674ab479885..4581d38a4d3 100644 --- a/mozilla/rdf/chrome/public/nsIChromeRegistry.h +++ b/mozilla/rdf/chrome/public/nsIChromeRegistry.h @@ -1,49 +1,54 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. +/* + * DO NOT EDIT. THIS FILE IS GENERATED FROM nsIChromeRegistry.idl */ -#ifndef nsIChromeRegistry_h__ -#define nsIChromeRegistry_h__ +#ifndef __gen_nsIChromeRegistry_h__ +#define __gen_nsIChromeRegistry_h__ #include "nsISupports.h" -#include "nsString.h" +#include "nsIURI.h" +#include "nsrootidl.h" #include "nsIURL.h" -// {D8C7D8A1-E84C-11d2-BF87-00105A1B0627} -#define NS_ICHROMEREGISTRY_IID \ -{ 0xd8c7d8a1, 0xe84c, 0x11d2, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } } +/* starting interface: nsIChromeRegistry */ +#define NS_ICHROMEREGISTRY_IID_STR "d8c7d8a1-e84c-11d2-bf87-00105a1b0627" + +#define NS_ICHROMEREGISTRY_IID \ + {0xd8c7d8a1, 0xe84c, 0x11d2, \ + { 0xbf, 0x87, 0x00, 0x10, 0x5a, 0x1b, 0x06, 0x27 }} class nsIChromeRegistry : public nsISupports { -public: - static const nsIID& GetIID() { static nsIID iid = NS_ICHROMEREGISTRY_IID; return iid; } - - NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURL) = 0; - NS_IMETHOD InitRegistry() = 0; + public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICHROMEREGISTRY_IID) + + /* void convertChromeURL (in nsIURI aChromeURL); */ + NS_IMETHOD ConvertChromeURL(nsIURI *aChromeURL) = 0; + + /* long getOverlayCount (in wstring aChromeURL); */ + NS_IMETHOD GetOverlayCount(const PRUnichar *aChromeURL, PRInt32 *_retval) = 0; + + /* wstring getOverlayAt (in wstring aChromeURL, in long aIndex); */ + NS_IMETHOD GetOverlayAt(const PRUnichar *aChromeURL, PRInt32 aIndex, PRUnichar **_retval) = 0; }; +/* Use this macro when declaring classes that implement this interface. */ +#define NS_DECL_NSICHROMEREGISTRY \ + NS_IMETHOD ConvertChromeURL(nsIURI *aChromeURL); \ + NS_IMETHOD GetOverlayCount(const PRUnichar *aChromeURL, PRInt32 *_retval); \ + NS_IMETHOD GetOverlayAt(const PRUnichar *aChromeURL, PRInt32 aIndex, PRUnichar **_retval); + +/* Use this macro to declare functions that forward the behavior of this interface to another object. */ +#define NS_FORWARD_NSICHROMEREGISTRY(_to) \ + NS_IMETHOD ConvertChromeURL(nsIURI *aChromeURL) { return _to ## ConvertChromeURL(aChromeURL); } \ + NS_IMETHOD GetOverlayCount(const PRUnichar *aChromeURL, PRInt32 *_retval) { return _to ## GetOverlayCount(aChromeURL, _retval); } \ + NS_IMETHOD GetOverlayAt(const PRUnichar *aChromeURL, PRInt32 aIndex, PRUnichar **_retval) { return _to ## GetOverlayAt(aChromeURL, aIndex, _retval); } + // for component registration // {D8C7D8A2-E84C-11d2-BF87-00105A1B0627} #define NS_CHROMEREGISTRY_CID \ { 0xd8c7d8a2, 0xe84c, 0x11d2, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } } - -//////////////////////////////////////////////////////////////////////////////// - extern nsresult NS_NewChromeRegistry(nsIChromeRegistry* *aResult); -#endif // nsIChromeRegistry_h__ +#endif /* __gen_nsIChromeRegistry_h__ */ diff --git a/mozilla/rdf/chrome/public/nsIChromeRegistry.idl b/mozilla/rdf/chrome/public/nsIChromeRegistry.idl new file mode 100644 index 00000000000..f61a88decd7 --- /dev/null +++ b/mozilla/rdf/chrome/public/nsIChromeRegistry.idl @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Mozilla browser. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1999 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): hyatt and pav :) + */ + +#include "nsISupports.idl" +#include "nsIURL.idl" + +[scriptable, uuid(D8C7D8A1-E84C-11d2-BF87-00105A1B0627)] +interface nsIChromeRegistry : nsISupports +{ + void convertChromeURL(in nsIURI aChromeURL); + long getOverlayCount(in wstring aChromeURL); + wstring getOverlayAt(in wstring aChromeURL, in long aIndex); +}; + + +%{ C++ + +// for component registration +// {D8C7D8A2-E84C-11d2-BF87-00105A1B0627} +#define NS_CHROMEREGISTRY_CID \ +{ 0xd8c7d8a2, 0xe84c, 0x11d2, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } } + +extern nsresult +NS_NewChromeRegistry(nsIChromeRegistry* *aResult); +%} diff --git a/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp b/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp index b43ad291c91..14ffda12870 100644 --- a/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp +++ b/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp @@ -148,13 +148,6 @@ nsChromeProtocolHandler::NewChannel(const char* verb, nsIURI* uri, NS_WITH_SERVICE(nsIChromeRegistry, reg, kChromeRegistryCID, &rv); if (NS_FAILED(rv)) return rv; - static PRBool inited = PR_FALSE; - if (!inited) { - rv = reg->InitRegistry(); - if (NS_FAILED(rv)) return rv; - inited = PR_TRUE; - } - nsIURI* chromeURI; rv = uri->Clone(&chromeURI); // don't mangle the original if (NS_FAILED(rv)) return rv; diff --git a/mozilla/rdf/chrome/src/nsChromeRegistry.cpp b/mozilla/rdf/chrome/src/nsChromeRegistry.cpp index 33437f69753..fee6e7b78d5 100644 --- a/mozilla/rdf/chrome/src/nsChromeRegistry.cpp +++ b/mozilla/rdf/chrome/src/nsChromeRegistry.cpp @@ -67,8 +67,7 @@ public: NS_DECL_ISUPPORTS // nsIChromeRegistry methods: - NS_IMETHOD InitRegistry(); - NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURL); + NS_DECL_NSICHROMEREGISTRY // nsChromeRegistry methods: nsChromeRegistry(); @@ -85,6 +84,7 @@ public: static nsIRDFResource* kCHROME_archive; static nsIRDFResource* kCHROME_name; static nsIRDFResource* kCHROME_displayname; + static nsSupportsHashtable *mDataSourceTable; protected: NS_IMETHOD InitializeDataSource(nsString &aPackage, @@ -94,12 +94,14 @@ protected: nsresult GetChromeResource(nsIRDFDataSource *aDataSource, nsString& aResult, nsIRDFResource* aChromeResource, nsIRDFResource* aProperty); -protected: - nsSupportsHashtable *mDataSourceTable; +private: + NS_IMETHOD LoadDataSource(const nsCAutoString &aFileName, nsIRDFDataSource **aResult); + }; PRUint32 nsChromeRegistry::gRefCnt ; nsIRDFService* nsChromeRegistry::gRDFService = nsnull; +nsSupportsHashtable* nsChromeRegistry::mDataSourceTable = nsnull; nsIRDFResource* nsChromeRegistry::kCHROME_chrome = nsnull; nsIRDFResource* nsChromeRegistry::kCHROME_skin = nsnull; @@ -116,13 +118,48 @@ nsIRDFResource* nsChromeRegistry::kCHROME_displayname = nsnull; nsChromeRegistry::nsChromeRegistry() { NS_INIT_REFCNT(); - mDataSourceTable = nsnull; + + + gRefCnt++; + if (gRefCnt == 1) { + nsresult rv; + rv = nsServiceManager::GetService(kRDFServiceCID, + kIRDFServiceIID, + (nsISupports**)&gRDFService); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); + + // get all the properties we'll need: + rv = gRDFService->GetResource(kURICHROME_chrome, &kCHROME_chrome); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_skin, &kCHROME_skin); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_content); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_locale, &kCHROME_locale); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_base, &kCHROME_base); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_main, &kCHROME_main); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_archive, &kCHROME_archive); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_name, &kCHROME_name); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + + rv = gRDFService->GetResource(kURICHROME_displayname, &kCHROME_displayname); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); + } } nsChromeRegistry::~nsChromeRegistry() { - delete mDataSourceTable; - --gRefCnt; if (gRefCnt == 0) { @@ -136,6 +173,7 @@ nsChromeRegistry::~nsChromeRegistry() NS_IF_RELEASE(kCHROME_archive); NS_IF_RELEASE(kCHROME_displayname); NS_IF_RELEASE(kCHROME_name); + delete mDataSourceTable; if (gRDFService) { nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); @@ -314,56 +352,43 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL) return NS_OK; } - -NS_IMETHODIMP -nsChromeRegistry::InitRegistry() +NS_IMETHODIMP nsChromeRegistry::GetOverlayCount(const PRUnichar *aChromeURL, PRInt32 *aResult) { - gRefCnt++; - if (gRefCnt == 1) { - nsresult rv; - rv = nsServiceManager::GetService(kRDFServiceCID, - kIRDFServiceIID, - (nsISupports**)&gRDFService); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); - if (NS_FAILED(rv)) return rv; + return NS_OK; +} - // get all the properties we'll need: - rv = gRDFService->GetResource(kURICHROME_chrome, &kCHROME_chrome); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; +NS_IMETHODIMP nsChromeRegistry::GetOverlayAt(const PRUnichar *aChromeURL, PRInt32 aIndex, PRUnichar **aResult) +{ + return NS_OK; +} - rv = gRDFService->GetResource(kURICHROME_skin, &kCHROME_skin); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; +NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCAutoString &aFileName, nsIRDFDataSource **aResult) +{ + nsresult rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID, + nsnull, + NS_GET_IID(nsIRDFDataSource), + (void**) aResult); + if (NS_FAILED(rv)) return rv; - rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_content); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; - rv = gRDFService->GetResource(kURICHROME_locale, &kCHROME_locale); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; + nsCOMPtr remote = do_QueryInterface(*aResult); + if (! remote) + return NS_ERROR_UNEXPECTED; - rv = gRDFService->GetResource(kURICHROME_base, &kCHROME_base); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; - rv = gRDFService->GetResource(kURICHROME_main, &kCHROME_main); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; + rv = remote->Init(aFileName); + if (NS_FAILED(rv)) return rv; - rv = gRDFService->GetResource(kURICHROME_archive, &kCHROME_archive); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; + // We need to read this synchronously. + rv = remote->Refresh(PR_TRUE); + if (NS_FAILED(rv)) return rv; - rv = gRDFService->GetResource(kURICHROME_name, &kCHROME_name); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; - rv = gRDFService->GetResource(kURICHROME_displayname, &kCHROME_displayname); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); - if (NS_FAILED(rv)) return rv; - } + if (!mDataSourceTable) + mDataSourceTable = new nsSupportsHashtable; + + nsCOMPtr supports = do_QueryInterface(remote); + mDataSourceTable->Put(&nsStringKey(aFileName), (void*)supports.get()); return NS_OK; } @@ -373,18 +398,20 @@ nsChromeRegistry::InitializeDataSource(nsString &aPackage, nsString &aProvider, nsIRDFDataSource **aResult) { - - nsCAutoString chromeFile; + nsCAutoString chromeFile, overlayFile; // Retrieve the mInner data source. chromeFile = "resource:/chrome/"; chromeFile += aPackage; chromeFile += aProvider; // provider already has a / in the front of it chromeFile += "/"; - chromeFile += "current.rdf"; + overlayFile = chromeFile; + chromeFile += "current.rdf"; + overlayFile += "overlays.rdf"; if (mDataSourceTable) { + // current.rdf and overlays.rdf are loaded in pairs and so if one is loaded, the other should be too. void *data = mDataSourceTable->Get(&nsStringKey(chromeFile)); if (data) { @@ -402,32 +429,12 @@ nsChromeRegistry::InitializeDataSource(nsString &aPackage, } } - nsresult rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID, - nsnull, - NS_GET_IID(nsIRDFDataSource), - (void**) aResult); - if (NS_FAILED(rv)) return rv; + nsCOMPtr overlayDataSource; + LoadDataSource(chromeFile, aResult); + LoadDataSource(overlayFile, getter_AddRefs(overlayDataSource)); - nsCOMPtr remote = do_QueryInterface(*aResult); - if (! remote) - return NS_ERROR_UNEXPECTED; - - - rv = remote->Init(chromeFile); - if (NS_FAILED(rv)) return rv; - - // We need to read this synchronously. - rv = remote->Refresh(PR_TRUE); - if (NS_FAILED(rv)) return rv; - - if (!mDataSourceTable) - mDataSourceTable = new nsSupportsHashtable; - - nsCOMPtr supports = do_QueryInterface(remote); - mDataSourceTable->Put(&nsStringKey(chromeFile), (void*)supports.get()); - - return NS_OK; + return NS_OK; } ////////////////////////////////////////////////////////////////////////////////