From 173d271bc3b30e8e0d5d34b027a16fb79d77ee50 Mon Sep 17 00:00:00 2001 From: "bsmedberg%covad.net" Date: Wed, 14 Jan 2004 18:03:25 +0000 Subject: [PATCH] Re-landing bug 229285 - There was a misplaced close-brace in nsXULDocument.cpp that was causing problems non-chrome XUL documents. --- chrome/src/nsChromeRegistry.cpp | 249 +++++++----------- chrome/src/nsChromeRegistry.h | 12 +- content/base/public/nsIChromeRegistry.idl | 4 - content/xul/document/public/Makefile.in | 4 + .../document/public/nsIXULOverlayProvider.idl | 61 +++++ content/xul/document/src/nsXULDocument.cpp | 122 +++++---- rdf/chrome/build/Makefile.in | 1 + rdf/chrome/src/nsChromeRegistry.cpp | 249 +++++++----------- rdf/chrome/src/nsChromeRegistry.h | 8 + 9 files changed, 322 insertions(+), 388 deletions(-) create mode 100644 content/xul/document/public/nsIXULOverlayProvider.idl diff --git a/chrome/src/nsChromeRegistry.cpp b/chrome/src/nsChromeRegistry.cpp index ff2efc8e203..519621d5e8c 100644 --- a/chrome/src/nsChromeRegistry.cpp +++ b/chrome/src/nsChromeRegistry.cpp @@ -43,6 +43,7 @@ #endif #include +#include "nsArrayEnumerator.h" #include "nsCOMPtr.h" #include "nsIChromeRegistry.h" #include "nsChromeRegistry.h" @@ -146,107 +147,6 @@ DEFINE_RDF_VOCAB(CHROME_URI, CHROME, localeVersion); DEFINE_RDF_VOCAB(CHROME_URI, CHROME, packageVersion); DEFINE_RDF_VOCAB(CHROME_URI, CHROME, disabled); -//////////////////////////////////////////////////////////////////////////////// - -class nsOverlayEnumerator : public nsISimpleEnumerator -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSISIMPLEENUMERATOR - - nsOverlayEnumerator(nsISimpleEnumerator *aInstallArcs, - nsISimpleEnumerator *aProfileArcs); - virtual ~nsOverlayEnumerator(); - -private: - nsCOMPtr mInstallArcs; - nsCOMPtr mProfileArcs; - nsCOMPtr mCurrentArcs; -}; - -NS_IMPL_ISUPPORTS1(nsOverlayEnumerator, nsISimpleEnumerator) - -nsOverlayEnumerator::nsOverlayEnumerator(nsISimpleEnumerator *aInstallArcs, - nsISimpleEnumerator *aProfileArcs) - : mInstallArcs(aInstallArcs), - mProfileArcs(aProfileArcs) -{ -} - -nsOverlayEnumerator::~nsOverlayEnumerator() -{ -} - -NS_IMETHODIMP nsOverlayEnumerator::HasMoreElements(PRBool *aIsTrue) -{ - *aIsTrue = PR_FALSE; - if (!mProfileArcs) { - if (!mInstallArcs) - return NS_OK; // No arcs period. We default to false, - return mInstallArcs->HasMoreElements(aIsTrue); // no profile arcs. use install arcs, - } - - nsresult rv = mProfileArcs->HasMoreElements(aIsTrue); - if (*aIsTrue || !mInstallArcs) - return rv; - - return mInstallArcs->HasMoreElements(aIsTrue); -} - -NS_IMETHODIMP nsOverlayEnumerator::GetNext(nsISupports **aResult) -{ - nsresult rv; - *aResult = nsnull; - - if (!mCurrentArcs) { - // Start with the profile arcs. - mCurrentArcs = mProfileArcs; - if (!mCurrentArcs) { - // No profile arcs, try the install arcs. - mCurrentArcs = mInstallArcs; - if (!mCurrentArcs) - return NS_ERROR_FAILURE; - } - } - else if (mCurrentArcs == mProfileArcs) { - // Check if we have more profile arcs. - PRBool hasMore; - rv = mCurrentArcs->HasMoreElements(&hasMore); - if (NS_FAILED(rv)) - return rv; - - if (!hasMore) { - // No more profile arcs, try the install arcs. - if (!mInstallArcs) - return NS_ERROR_FAILURE; - mCurrentArcs = mInstallArcs; - } - } - - nsCOMPtr supports; - rv = mCurrentArcs->GetNext(getter_AddRefs(supports)); - if (NS_FAILED(rv)) - return rv; - - nsCOMPtr value = do_QueryInterface(supports, &rv); - if (NS_FAILED(rv)) - return NS_OK; - - const PRUnichar* valueStr; - rv = value->GetValueConst(&valueStr); - if (NS_FAILED(rv)) - return rv; - - nsCOMPtr url; - rv = NS_NewURI(getter_AddRefs(url), NS_ConvertUCS2toUTF8(valueStr)); - - if (NS_FAILED(rv)) - return NS_OK; - - return CallQueryInterface(url, aResult); -} - - //////////////////////////////////////////////////////////////////////////////// nsChromeRegistry::nsChromeRegistry() : mRDFService(nsnull), @@ -310,7 +210,12 @@ nsChromeRegistry::~nsChromeRegistry() } -NS_IMPL_THREADSAFE_ISUPPORTS4(nsChromeRegistry, nsIChromeRegistry, nsIXULChromeRegistry, nsIObserver, nsISupportsWeakReference) +NS_IMPL_THREADSAFE_ISUPPORTS5(nsChromeRegistry, + nsIChromeRegistry, + nsIXULChromeRegistry, + nsIXULOverlayProvider, + nsIObserver, + nsISupportsWeakReference) //////////////////////////////////////////////////////////////////////////////// // nsIChromeRegistry methods: @@ -1094,7 +999,7 @@ nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL, nsCAutoString package, provider, remaining; rv = SplitURL(aChromeURL, package, provider, remaining); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!aCreateDS) { // We are not supposed to create the data source, which means @@ -1104,7 +1009,7 @@ nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL, nsDependentCString dataSourceStr(kChromeFileName); nsCOMPtr mainDataSource; rv = LoadDataSource(dataSourceStr, getter_AddRefs(mainDataSource), aUseProfile, nsnull); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // Now that we have the appropriate chrome.rdf file, we // must check the package resource for stylesheets or overlays. @@ -1178,11 +1083,64 @@ nsChromeRegistry::GetStyleSheets(nsIURI *aChromeURL, return NS_OK; } -NS_IMETHODIMP nsChromeRegistry::GetOverlays(nsIURI *aChromeURL, nsISimpleEnumerator **aResult) +NS_IMETHODIMP nsChromeRegistry::GetOverlaysForURI(nsIURI *aChromeURL, nsISimpleEnumerator **aResult) { return GetDynamicInfo(aChromeURL, PR_TRUE, aResult); } +nsresult +nsChromeRegistry::GetURIList(nsIRDFDataSource *aSource, + nsIRDFResource *aResource, + nsCOMArray& aArray) +{ + nsresult rv; + nsCOMPtr arcs; + nsCOMPtr container = + do_CreateInstance("@mozilla.org/rdf/container;1", &rv); + if (NS_FAILED(rv)) goto end_GetURIList; + + rv = container->Init(aSource, aResource); + if (NS_FAILED(rv)) { + rv = NS_OK; + goto end_GetURIList; + } + + rv = container->GetElements(getter_AddRefs(arcs)); + if (NS_FAILED(rv)) goto end_GetURIList; + + { + nsCOMPtr supports; + nsCOMPtr value; + nsCOMPtr uri; + PRBool hasMore; + + while (NS_SUCCEEDED(rv = arcs->HasMoreElements(&hasMore)) && hasMore) { + rv = arcs->GetNext(getter_AddRefs(supports)); + if (NS_FAILED(rv)) break; + + value = do_QueryInterface(supports, &rv); + if (NS_FAILED(rv)) continue; + + const PRUnichar* valueStr; + rv = value->GetValueConst(&valueStr); + if (NS_FAILED(rv)) continue; + + rv = NS_NewURI(getter_AddRefs(uri), NS_ConvertUTF16toUTF8(valueStr)); + if (NS_FAILED(rv)) continue; + + if (IsOverlayAllowed(uri)) { + if (!aArray.AppendObject(uri)) { + rv = NS_ERROR_OUT_OF_MEMORY; + break; + } + } + } + } + +end_GetURIList: + return rv; +} + nsresult nsChromeRegistry::GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay, nsISimpleEnumerator **aResult) @@ -1195,17 +1153,20 @@ nsChromeRegistry::GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay, return NS_OK; nsCOMPtr installSource; - rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_FALSE, PR_FALSE, getter_AddRefs(installSource)); - if (NS_FAILED(rv)) return rv; + rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_FALSE, PR_FALSE, + getter_AddRefs(installSource)); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr profileSource; if (mProfileInitialized) { - rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_TRUE, PR_FALSE, getter_AddRefs(profileSource)); - if (NS_FAILED(rv)) return rv; + rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_TRUE, PR_FALSE, + getter_AddRefs(profileSource)); + NS_ENSURE_SUCCESS(rv, rv); } nsCAutoString lookup; rv = aChromeURL->GetSpec(lookup); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // Get the chromeResource from this lookup string nsCOMPtr chromeResource; @@ -1215,38 +1176,16 @@ nsChromeRegistry::GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay, return rv; } - nsCOMPtr installArcs; - nsCOMPtr profileArcs; + nsCOMArray overlayURIs; - if (installSource) - { - nsCOMPtr container; - rv = nsComponentManager::CreateInstance("@mozilla.org/rdf/container;1", - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); - if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(container->Init(installSource, chromeResource))) - rv = container->GetElements(getter_AddRefs(installArcs)); - if (NS_FAILED(rv)) return rv; + if (installSource) { + GetURIList(installSource, chromeResource, overlayURIs); + } + if (profileSource) { + GetURIList(profileSource, chromeResource, overlayURIs); } - if (profileSource) - { - nsCOMPtr container; - rv = nsComponentManager::CreateInstance("@mozilla.org/rdf/container;1", - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); - if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(container->Init(profileSource, chromeResource))) - rv = container->GetElements(getter_AddRefs(profileArcs)); - if (NS_FAILED(rv)) return rv; - } - - - *aResult = new nsOverlayEnumerator(installArcs, profileArcs); - NS_ADDREF(*aResult); - - return NS_OK; + return NS_NewArrayEnumerator(aResult, overlayURIs); } nsresult @@ -2739,38 +2678,28 @@ NS_IMETHODIMP nsChromeRegistry::SetAllowOverlaysForPackage(const PRUnichar *aPac return rv; } -NS_IMETHODIMP nsChromeRegistry::OverlaysAllowedForPackage(const PRUnichar *aPackageName, PRBool *aRetval) +PRBool nsChromeRegistry::IsOverlayAllowed(nsIURI *aChromeURL) { + nsCAutoString package, provider, file; + nsresult rv = SplitURL(aChromeURL, package, provider, file); + if (NS_FAILED(rv)) return PR_FALSE; + // Get the chrome resource for the package. - nsCAutoString package( "urn:mozilla:package:" ); - package.AppendWithConversion(aPackageName); + nsCAutoString rdfpackage( "urn:mozilla:package:" ); + rdfpackage.Append(package); // Obtain the package resource. - nsresult rv = NS_OK; nsCOMPtr packageResource; - rv = GetResource(package, getter_AddRefs(packageResource)); - if (NS_FAILED(rv)) { + rv = GetResource(rdfpackage, getter_AddRefs(packageResource)); + if (NS_FAILED(rv) || !packageResource) { NS_ERROR("Unable to obtain the package resource."); - return rv; + return PR_FALSE; } - NS_ASSERTION(packageResource, "failed to get packageResource"); // See if the disabled arc is set for the package. nsCAutoString disabled; nsChromeRegistry::FollowArc(mChromeDataSource, disabled, packageResource, mDisabled); - *aRetval = disabled.IsEmpty(); - - return NS_OK; -} - -NS_IMETHODIMP nsChromeRegistry::IsOverlayAllowed(nsIURI *aChromeURL, PRBool *aRetval) -{ - nsCAutoString package, provider, file; - nsresult rv = SplitURL(aChromeURL, package, provider, file); - if (NS_FAILED(rv)) return rv; - - nsAutoString packageStr; packageStr.AssignWithConversion(package.get()); - return OverlaysAllowedForPackage(packageStr.get(), aRetval); + return disabled.IsEmpty(); } NS_IMETHODIMP nsChromeRegistry::InstallSkin(const char* aBaseURL, PRBool aUseProfile, PRBool aAllowScripts) diff --git a/chrome/src/nsChromeRegistry.h b/chrome/src/nsChromeRegistry.h index 2b24e7c1b79..15346ee60ea 100644 --- a/chrome/src/nsChromeRegistry.h +++ b/chrome/src/nsChromeRegistry.h @@ -48,6 +48,8 @@ class nsIRDFContainerUtils; class nsIDOMWindowInternal; class nsIDocument; +#include "nsIChromeRegistry.h" +#include "nsIXULOverlayProvider.h" #include "nsIRDFCompositeDataSource.h" #include "nsICSSStyleSheet.h" #include "nsIObserver.h" @@ -55,13 +57,15 @@ class nsIDocument; #include "nsString.h" #include "nsIZipReader.h" #include "nsICSSLoader.h" +#include "nsCOMArray.h" // for component registration -// {D8C7D8A2-E84C-11d2-BF87-00105A1B0627} +// {47049e42-1d87-482a-984d-56ae185e367a} #define NS_CHROMEREGISTRY_CID \ -{ 0xd8c7d8a2, 0xe84c, 0x11d2, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } } +{ 0x47049e42, 0x1d87, 0x482a, { 0x98, 0x4d, 0x56, 0xae, 0x18, 0x5e, 0x36, 0x7a } } class nsChromeRegistry : public nsIXULChromeRegistry, + public nsIXULOverlayProvider, public nsIObserver, public nsSupportsWeakReference { @@ -71,6 +75,7 @@ public: // nsIChromeRegistry methods: NS_DECL_NSICHROMEREGISTRY NS_DECL_NSIXULCHROMEREGISTRY + NS_DECL_NSIXULOVERLAYPROVIDER NS_DECL_NSIOBSERVER @@ -91,8 +96,11 @@ public: protected: nsresult GetDynamicDataSource(nsIURI *aChromeURL, PRBool aIsOverlay, PRBool aUseProfile, PRBool aCreateDS, nsIRDFDataSource **aResult); + nsresult GetURIList(nsIRDFDataSource *aDS, nsIRDFResource *aResource, nsCOMArray& aArray); nsresult GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay, nsISimpleEnumerator **aResult); + PRBool IsOverlayAllowed(nsIURI *aChromeURI); + nsresult GetResource(const nsACString& aChromeType, nsIRDFResource** aResult); nsresult UpdateDynamicDataSource(nsIRDFDataSource *aDataSource, diff --git a/content/base/public/nsIChromeRegistry.idl b/content/base/public/nsIChromeRegistry.idl index f038a49ecea..c14445d809a 100755 --- a/content/base/public/nsIChromeRegistry.idl +++ b/content/base/public/nsIChromeRegistry.idl @@ -136,8 +136,6 @@ interface nsIXULChromeRegistry : nsIChromeRegistry { ACString getSelectedLocale(in ACString packageName); ACString getSelectedSkin(in ACString packageName); - nsISimpleEnumerator getOverlays(in nsIURI aChromeURL); - /* Should be called when skins change. Reloads only stylesheets. */ void refreshSkins(); @@ -147,8 +145,6 @@ interface nsIXULChromeRegistry : nsIChromeRegistry { You can use these APIs to effectively disable a chrome add-on without uninstalling it. */ void setAllowOverlaysForPackage(in wstring packageName, in boolean allowOverlays); - boolean overlaysAllowedForPackage(in wstring packageName); - boolean isOverlayAllowed(in nsIURI aChromeURL); /* Installation APIs */ void installSkin(in string baseURL, diff --git a/content/xul/document/public/Makefile.in b/content/xul/document/public/Makefile.in index 7e789e2909e..e30b5c991d0 100644 --- a/content/xul/document/public/Makefile.in +++ b/content/xul/document/public/Makefile.in @@ -35,6 +35,10 @@ XPIDLSRCS = \ $(NULL) ifdef MOZ_XUL +XPIDLSRCS += \ + nsIXULOverlayProvider.idl \ + $(NULL) + EXPORTS = \ nsIXULContentSink.h \ nsIXULDocument.h \ diff --git a/content/xul/document/public/nsIXULOverlayProvider.idl b/content/xul/document/public/nsIXULOverlayProvider.idl new file mode 100644 index 00000000000..58b31f15204 --- /dev/null +++ b/content/xul/document/public/nsIXULOverlayProvider.idl @@ -0,0 +1,61 @@ +/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 Gecko XUL engine code. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg + * Portions created by the Initial Developer are Copyright (C) 2003 + * 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 MPL, 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 MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +interface nsISimpleEnumerator; +interface nsIURI; + +/** + * The chrome registry implements this interface to give overlays + * to the gecko XUL engine. + * + * @status UNDER_REVIEW + */ + +[scriptable, uuid(3b1b0a68-261c-44e1-abfe-fc7637b6977a)] +interface nsIXULOverlayProvider : nsISupports +{ + /** + * Method will be called by the gecko XUL engine when loading a chrome + * XUL page. + * + * @param aURI The URI being loaded + * @return An enumerator of nsIURI for the overlays of this URI + */ + nsISimpleEnumerator /*nsIURI*/ getOverlaysForURI(in nsIURI aURI); +}; diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index e6342064b6f..c8b8439efe6 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -68,13 +68,13 @@ #include "nsDOMError.h" #include "nsIBoxObject.h" #include "nsIChromeRegistry.h" -#include "nsIPrincipal.h" #include "nsIContentSink.h" // for NS_CONTENT_ID_COUNTER_BASE #include "nsIScrollableView.h" #include "nsIContentViewer.h" #include "nsGUIEvent.h" #include "nsIDOMXULElement.h" #include "nsIElementFactory.h" +#include "nsIPrincipal.h" #include "nsIPrivateDOMEvent.h" #include "nsIRDFNode.h" #include "nsIRDFRemoteDataSource.h" @@ -87,6 +87,7 @@ #include "nsIXULContent.h" #include "nsIXULContentSink.h" #include "nsXULContentUtils.h" +#include "nsIXULOverlayProvider.h" #include "nsIXULPrototypeCache.h" #include "nsNetUtil.h" #include "nsParserCIID.h" @@ -697,6 +698,8 @@ nsXULDocument::EndLoad() rv = mCurrentPrototype->GetURI(getter_AddRefs(uri)); if (NS_FAILED(rv)) return; + PRBool isChrome = IsChromeURI(uri); + // Remember if the XUL cache is on PRBool useXULCache; gXULCache->GetEnabled(&useXULCache); @@ -706,48 +709,50 @@ nsXULDocument::EndLoad() // loading it, and write the prototype. if (useXULCache && mIsWritingFastLoad && mMasterPrototype != mCurrentPrototype && - IsChromeURI(uri)) + isChrome) gXULCache->WritePrototype(mCurrentPrototype); - nsCOMPtr reg = - do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); - if (NS_FAILED(rv)) return; + if (isChrome) { + nsCOMPtr reg = + do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); + if (NS_FAILED(rv)) return; - nsCOMPtr sheets; - reg->GetStyleSheets(uri, getter_AddRefs(sheets)); + nsCOMPtr sheets; + reg->GetStyleSheets(uri, getter_AddRefs(sheets)); - // Walk the sheets and add them to the prototype. Also put them - // into the document. - if (sheets) { - nsCOMPtr sheet; - PRUint32 count; - sheets->Count(&count); - for (PRUint32 i = 0; i < count; ++i) { - sheet = do_QueryElementAt(sheets, i); - if (sheet) { - nsCOMPtr sheetURL; - sheet->GetURL(*getter_AddRefs(sheetURL)); + // Walk the sheets and add them to the prototype. Also put them + // into the document. + if (sheets) { + nsCOMPtr sheet; + PRUint32 count; + sheets->Count(&count); + for (PRUint32 i = 0; i < count; ++i) { + sheet = do_QueryElementAt(sheets, i); + if (sheet) { + nsCOMPtr sheetURL; + sheet->GetURL(*getter_AddRefs(sheetURL)); - if (useXULCache && IsChromeURI(sheetURL)) { - mCurrentPrototype->AddStyleSheetReference(sheetURL); + if (useXULCache && IsChromeURI(sheetURL)) { + mCurrentPrototype->AddStyleSheetReference(sheetURL); + } + AddStyleSheet(sheet, 0); } - AddStyleSheet(sheet, 0); } } - } - if (useXULCache && IsChromeURI(uri)) { - // If it's a 'chrome:' prototype document, then notify any - // documents that raced to load the prototype, and awaited - // its load completion via proto->AwaitLoadDone(). - rv = mCurrentPrototype->NotifyLoadDone(); - if (NS_FAILED(rv)) return; + if (useXULCache) { + // If it's a 'chrome:' prototype document, then notify any + // documents that raced to load the prototype, and awaited + // its load completion via proto->AwaitLoadDone(). + rv = mCurrentPrototype->NotifyLoadDone(); + if (NS_FAILED(rv)) return; + } } // Now walk the prototype to build content. rv = PrepareToWalk(); if (NS_FAILED(rv)) return; - + ResumeWalk(); } @@ -2780,47 +2785,40 @@ nsresult nsXULDocument::AddChromeOverlays() { nsresult rv; - nsCOMPtr reg(do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return NS_ERROR_FAILURE; + nsCOMPtr docUri; + rv = mCurrentPrototype->GetURI(getter_AddRefs(docUri)); + NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr oe; + /* overlays only apply to chrome, skip all content URIs */ + if (!IsChromeURI(docUri)) return NS_OK; - { - nsCOMPtr uri; - rv = mCurrentPrototype->GetURI(getter_AddRefs(uri)); - if (NS_FAILED(rv)) return rv; + nsCOMPtr chromeReg(do_GetService(NS_CHROMEREGISTRY_CONTRACTID)); + // In embedding situations, the chrome registry may not provide overlays, + // or even exist at all; that's OK. + NS_ENSURE_TRUE(chromeReg, NS_OK); - reg->GetOverlays(uri, getter_AddRefs(oe)); - } + nsCOMPtr overlays; + rv = chromeReg->GetOverlaysForURI(docUri, getter_AddRefs(overlays)); + NS_ENSURE_SUCCESS(rv, rv); - if (!oe) - return NS_OK; + PRBool moreOverlays; + nsCOMPtr next; + nsCOMPtr uri; - PRBool moreElements; - oe->HasMoreElements(&moreElements); + while (NS_SUCCEEDED(rv = overlays->HasMoreElements(&moreOverlays)) && + moreOverlays) { + rv = overlays->GetNext(getter_AddRefs(next)); + if (NS_FAILED(rv) || !next) continue; - while (moreElements) { - nsCOMPtr next; - oe->GetNext(getter_AddRefs(next)); - if (!next) - return NS_OK; + uri = do_QueryInterface(next); + if (!uri) { + NS_ERROR("Chrome registry handed me a non-nsIURI object!"); + continue; + } - nsCOMPtr uri = do_QueryInterface(next); - if (!uri) - return NS_OK; - - // See if this package is enabled/disabled. If it - // is disabled, we shouldn't append this element to - // the unloaded overlay list. - PRBool allowed = PR_TRUE; - reg->IsOverlayAllowed(uri, &allowed); - if (allowed) - mUnloadedOverlays->AppendElement(uri); - - oe->HasMoreElements(&moreElements); - } + mUnloadedOverlays->AppendElement(uri); + } return NS_OK; } diff --git a/rdf/chrome/build/Makefile.in b/rdf/chrome/build/Makefile.in index ecf151576d0..5383b54a449 100644 --- a/rdf/chrome/build/Makefile.in +++ b/rdf/chrome/build/Makefile.in @@ -41,6 +41,7 @@ REQUIRES = xpcom \ necko \ layout \ content \ + xuldoc \ jar \ $(NULL) diff --git a/rdf/chrome/src/nsChromeRegistry.cpp b/rdf/chrome/src/nsChromeRegistry.cpp index be23ef99656..5791f0401f8 100644 --- a/rdf/chrome/src/nsChromeRegistry.cpp +++ b/rdf/chrome/src/nsChromeRegistry.cpp @@ -43,6 +43,7 @@ #endif #include +#include "nsArrayEnumerator.h" #include "nsCOMPtr.h" #include "nsIChromeRegistry.h" #include "nsChromeRegistry.h" @@ -146,107 +147,6 @@ DEFINE_RDF_VOCAB(CHROME_URI, CHROME, localeVersion); DEFINE_RDF_VOCAB(CHROME_URI, CHROME, packageVersion); DEFINE_RDF_VOCAB(CHROME_URI, CHROME, disabled); -//////////////////////////////////////////////////////////////////////////////// - -class nsOverlayEnumerator : public nsISimpleEnumerator -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSISIMPLEENUMERATOR - - nsOverlayEnumerator(nsISimpleEnumerator *aInstallArcs, - nsISimpleEnumerator *aProfileArcs); - virtual ~nsOverlayEnumerator(); - -private: - nsCOMPtr mInstallArcs; - nsCOMPtr mProfileArcs; - nsCOMPtr mCurrentArcs; -}; - -NS_IMPL_ISUPPORTS1(nsOverlayEnumerator, nsISimpleEnumerator) - -nsOverlayEnumerator::nsOverlayEnumerator(nsISimpleEnumerator *aInstallArcs, - nsISimpleEnumerator *aProfileArcs) - : mInstallArcs(aInstallArcs), - mProfileArcs(aProfileArcs) -{ -} - -nsOverlayEnumerator::~nsOverlayEnumerator() -{ -} - -NS_IMETHODIMP nsOverlayEnumerator::HasMoreElements(PRBool *aIsTrue) -{ - *aIsTrue = PR_FALSE; - if (!mProfileArcs) { - if (!mInstallArcs) - return NS_OK; // No arcs period. We default to false, - return mInstallArcs->HasMoreElements(aIsTrue); // no profile arcs. use install arcs, - } - - nsresult rv = mProfileArcs->HasMoreElements(aIsTrue); - if (*aIsTrue || !mInstallArcs) - return rv; - - return mInstallArcs->HasMoreElements(aIsTrue); -} - -NS_IMETHODIMP nsOverlayEnumerator::GetNext(nsISupports **aResult) -{ - nsresult rv; - *aResult = nsnull; - - if (!mCurrentArcs) { - // Start with the profile arcs. - mCurrentArcs = mProfileArcs; - if (!mCurrentArcs) { - // No profile arcs, try the install arcs. - mCurrentArcs = mInstallArcs; - if (!mCurrentArcs) - return NS_ERROR_FAILURE; - } - } - else if (mCurrentArcs == mProfileArcs) { - // Check if we have more profile arcs. - PRBool hasMore; - rv = mCurrentArcs->HasMoreElements(&hasMore); - if (NS_FAILED(rv)) - return rv; - - if (!hasMore) { - // No more profile arcs, try the install arcs. - if (!mInstallArcs) - return NS_ERROR_FAILURE; - mCurrentArcs = mInstallArcs; - } - } - - nsCOMPtr supports; - rv = mCurrentArcs->GetNext(getter_AddRefs(supports)); - if (NS_FAILED(rv)) - return rv; - - nsCOMPtr value = do_QueryInterface(supports, &rv); - if (NS_FAILED(rv)) - return NS_OK; - - const PRUnichar* valueStr; - rv = value->GetValueConst(&valueStr); - if (NS_FAILED(rv)) - return rv; - - nsCOMPtr url; - rv = NS_NewURI(getter_AddRefs(url), NS_ConvertUCS2toUTF8(valueStr)); - - if (NS_FAILED(rv)) - return NS_OK; - - return CallQueryInterface(url, aResult); -} - - //////////////////////////////////////////////////////////////////////////////// nsChromeRegistry::nsChromeRegistry() : mRDFService(nsnull), @@ -310,7 +210,12 @@ nsChromeRegistry::~nsChromeRegistry() } -NS_IMPL_THREADSAFE_ISUPPORTS4(nsChromeRegistry, nsIChromeRegistry, nsIXULChromeRegistry, nsIObserver, nsISupportsWeakReference) +NS_IMPL_THREADSAFE_ISUPPORTS5(nsChromeRegistry, + nsIChromeRegistry, + nsIXULChromeRegistry, + nsIXULOverlayProvider, + nsIObserver, + nsISupportsWeakReference) //////////////////////////////////////////////////////////////////////////////// // nsIChromeRegistry methods: @@ -1094,7 +999,7 @@ nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL, nsCAutoString package, provider, remaining; rv = SplitURL(aChromeURL, package, provider, remaining); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!aCreateDS) { // We are not supposed to create the data source, which means @@ -1104,7 +1009,7 @@ nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL, nsDependentCString dataSourceStr(kChromeFileName); nsCOMPtr mainDataSource; rv = LoadDataSource(dataSourceStr, getter_AddRefs(mainDataSource), aUseProfile, nsnull); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // Now that we have the appropriate chrome.rdf file, we // must check the package resource for stylesheets or overlays. @@ -1178,11 +1083,64 @@ nsChromeRegistry::GetStyleSheets(nsIURI *aChromeURL, return NS_OK; } -NS_IMETHODIMP nsChromeRegistry::GetOverlays(nsIURI *aChromeURL, nsISimpleEnumerator **aResult) +NS_IMETHODIMP nsChromeRegistry::GetOverlaysForURI(nsIURI *aChromeURL, nsISimpleEnumerator **aResult) { return GetDynamicInfo(aChromeURL, PR_TRUE, aResult); } +nsresult +nsChromeRegistry::GetURIList(nsIRDFDataSource *aSource, + nsIRDFResource *aResource, + nsCOMArray& aArray) +{ + nsresult rv; + nsCOMPtr arcs; + nsCOMPtr container = + do_CreateInstance("@mozilla.org/rdf/container;1", &rv); + if (NS_FAILED(rv)) goto end_GetURIList; + + rv = container->Init(aSource, aResource); + if (NS_FAILED(rv)) { + rv = NS_OK; + goto end_GetURIList; + } + + rv = container->GetElements(getter_AddRefs(arcs)); + if (NS_FAILED(rv)) goto end_GetURIList; + + { + nsCOMPtr supports; + nsCOMPtr value; + nsCOMPtr uri; + PRBool hasMore; + + while (NS_SUCCEEDED(rv = arcs->HasMoreElements(&hasMore)) && hasMore) { + rv = arcs->GetNext(getter_AddRefs(supports)); + if (NS_FAILED(rv)) break; + + value = do_QueryInterface(supports, &rv); + if (NS_FAILED(rv)) continue; + + const PRUnichar* valueStr; + rv = value->GetValueConst(&valueStr); + if (NS_FAILED(rv)) continue; + + rv = NS_NewURI(getter_AddRefs(uri), NS_ConvertUTF16toUTF8(valueStr)); + if (NS_FAILED(rv)) continue; + + if (IsOverlayAllowed(uri)) { + if (!aArray.AppendObject(uri)) { + rv = NS_ERROR_OUT_OF_MEMORY; + break; + } + } + } + } + +end_GetURIList: + return rv; +} + nsresult nsChromeRegistry::GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay, nsISimpleEnumerator **aResult) @@ -1195,17 +1153,20 @@ nsChromeRegistry::GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay, return NS_OK; nsCOMPtr installSource; - rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_FALSE, PR_FALSE, getter_AddRefs(installSource)); - if (NS_FAILED(rv)) return rv; + rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_FALSE, PR_FALSE, + getter_AddRefs(installSource)); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr profileSource; if (mProfileInitialized) { - rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_TRUE, PR_FALSE, getter_AddRefs(profileSource)); - if (NS_FAILED(rv)) return rv; + rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_TRUE, PR_FALSE, + getter_AddRefs(profileSource)); + NS_ENSURE_SUCCESS(rv, rv); } nsCAutoString lookup; rv = aChromeURL->GetSpec(lookup); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // Get the chromeResource from this lookup string nsCOMPtr chromeResource; @@ -1215,38 +1176,16 @@ nsChromeRegistry::GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay, return rv; } - nsCOMPtr installArcs; - nsCOMPtr profileArcs; + nsCOMArray overlayURIs; - if (installSource) - { - nsCOMPtr container; - rv = nsComponentManager::CreateInstance("@mozilla.org/rdf/container;1", - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); - if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(container->Init(installSource, chromeResource))) - rv = container->GetElements(getter_AddRefs(installArcs)); - if (NS_FAILED(rv)) return rv; + if (installSource) { + GetURIList(installSource, chromeResource, overlayURIs); + } + if (profileSource) { + GetURIList(profileSource, chromeResource, overlayURIs); } - if (profileSource) - { - nsCOMPtr container; - rv = nsComponentManager::CreateInstance("@mozilla.org/rdf/container;1", - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); - if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(container->Init(profileSource, chromeResource))) - rv = container->GetElements(getter_AddRefs(profileArcs)); - if (NS_FAILED(rv)) return rv; - } - - - *aResult = new nsOverlayEnumerator(installArcs, profileArcs); - NS_ADDREF(*aResult); - - return NS_OK; + return NS_NewArrayEnumerator(aResult, overlayURIs); } nsresult @@ -2739,38 +2678,28 @@ NS_IMETHODIMP nsChromeRegistry::SetAllowOverlaysForPackage(const PRUnichar *aPac return rv; } -NS_IMETHODIMP nsChromeRegistry::OverlaysAllowedForPackage(const PRUnichar *aPackageName, PRBool *aRetval) +PRBool nsChromeRegistry::IsOverlayAllowed(nsIURI *aChromeURL) { + nsCAutoString package, provider, file; + nsresult rv = SplitURL(aChromeURL, package, provider, file); + if (NS_FAILED(rv)) return PR_FALSE; + // Get the chrome resource for the package. - nsCAutoString package( "urn:mozilla:package:" ); - package.AppendWithConversion(aPackageName); + nsCAutoString rdfpackage( "urn:mozilla:package:" ); + rdfpackage.Append(package); // Obtain the package resource. - nsresult rv = NS_OK; nsCOMPtr packageResource; - rv = GetResource(package, getter_AddRefs(packageResource)); - if (NS_FAILED(rv)) { + rv = GetResource(rdfpackage, getter_AddRefs(packageResource)); + if (NS_FAILED(rv) || !packageResource) { NS_ERROR("Unable to obtain the package resource."); - return rv; + return PR_FALSE; } - NS_ASSERTION(packageResource, "failed to get packageResource"); // See if the disabled arc is set for the package. nsCAutoString disabled; nsChromeRegistry::FollowArc(mChromeDataSource, disabled, packageResource, mDisabled); - *aRetval = disabled.IsEmpty(); - - return NS_OK; -} - -NS_IMETHODIMP nsChromeRegistry::IsOverlayAllowed(nsIURI *aChromeURL, PRBool *aRetval) -{ - nsCAutoString package, provider, file; - nsresult rv = SplitURL(aChromeURL, package, provider, file); - if (NS_FAILED(rv)) return rv; - - nsAutoString packageStr; packageStr.AssignWithConversion(package.get()); - return OverlaysAllowedForPackage(packageStr.get(), aRetval); + return disabled.IsEmpty(); } NS_IMETHODIMP nsChromeRegistry::InstallSkin(const char* aBaseURL, PRBool aUseProfile, PRBool aAllowScripts) diff --git a/rdf/chrome/src/nsChromeRegistry.h b/rdf/chrome/src/nsChromeRegistry.h index 2b24e7c1b79..18c1ab21470 100644 --- a/rdf/chrome/src/nsChromeRegistry.h +++ b/rdf/chrome/src/nsChromeRegistry.h @@ -48,6 +48,8 @@ class nsIRDFContainerUtils; class nsIDOMWindowInternal; class nsIDocument; +#include "nsIChromeRegistry.h" +#include "nsIXULOverlayProvider.h" #include "nsIRDFCompositeDataSource.h" #include "nsICSSStyleSheet.h" #include "nsIObserver.h" @@ -55,6 +57,7 @@ class nsIDocument; #include "nsString.h" #include "nsIZipReader.h" #include "nsICSSLoader.h" +#include "nsCOMArray.h" // for component registration // {D8C7D8A2-E84C-11d2-BF87-00105A1B0627} @@ -62,6 +65,7 @@ class nsIDocument; { 0xd8c7d8a2, 0xe84c, 0x11d2, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } } class nsChromeRegistry : public nsIXULChromeRegistry, + public nsIXULOverlayProvider, public nsIObserver, public nsSupportsWeakReference { @@ -71,6 +75,7 @@ public: // nsIChromeRegistry methods: NS_DECL_NSICHROMEREGISTRY NS_DECL_NSIXULCHROMEREGISTRY + NS_DECL_NSIXULOVERLAYPROVIDER NS_DECL_NSIOBSERVER @@ -91,8 +96,11 @@ public: protected: nsresult GetDynamicDataSource(nsIURI *aChromeURL, PRBool aIsOverlay, PRBool aUseProfile, PRBool aCreateDS, nsIRDFDataSource **aResult); + nsresult GetURIList(nsIRDFDataSource *aDS, nsIRDFResource *aResource, nsCOMArray& aArray); nsresult GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay, nsISimpleEnumerator **aResult); + PRBool IsOverlayAllowed(nsIURI *aChromeURI); + nsresult GetResource(const nsACString& aChromeType, nsIRDFResource** aResult); nsresult UpdateDynamicDataSource(nsIRDFDataSource *aDataSource,