Backing out bug 229285 until I can figure out the orange with the -chrome file:///blah scenario.

This commit is contained in:
bsmedberg%covad.net 2004-01-14 15:26:08 +00:00
Родитель 393d60505f
Коммит b791f1c831
9 изменённых файлов: 394 добавлений и 328 удалений

Просмотреть файл

@ -43,7 +43,6 @@
#endif
#include <string.h>
#include "nsArrayEnumerator.h"
#include "nsCOMPtr.h"
#include "nsIChromeRegistry.h"
#include "nsChromeRegistry.h"
@ -147,6 +146,107 @@ 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<nsISimpleEnumerator> mInstallArcs;
nsCOMPtr<nsISimpleEnumerator> mProfileArcs;
nsCOMPtr<nsISimpleEnumerator> 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<nsISupports> supports;
rv = mCurrentArcs->GetNext(getter_AddRefs(supports));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIRDFLiteral> 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<nsIURI> 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),
@ -210,12 +310,7 @@ nsChromeRegistry::~nsChromeRegistry()
}
NS_IMPL_THREADSAFE_ISUPPORTS5(nsChromeRegistry,
nsIChromeRegistry,
nsIXULChromeRegistry,
nsIXULOverlayProvider,
nsIObserver,
nsISupportsWeakReference)
NS_IMPL_THREADSAFE_ISUPPORTS4(nsChromeRegistry, nsIChromeRegistry, nsIXULChromeRegistry, nsIObserver, nsISupportsWeakReference)
////////////////////////////////////////////////////////////////////////////////
// nsIChromeRegistry methods:
@ -999,7 +1094,7 @@ nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL,
nsCAutoString package, provider, remaining;
rv = SplitURL(aChromeURL, package, provider, remaining);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) return rv;
if (!aCreateDS) {
// We are not supposed to create the data source, which means
@ -1009,7 +1104,7 @@ nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL,
nsDependentCString dataSourceStr(kChromeFileName);
nsCOMPtr<nsIRDFDataSource> mainDataSource;
rv = LoadDataSource(dataSourceStr, getter_AddRefs(mainDataSource), aUseProfile, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) return rv;
// Now that we have the appropriate chrome.rdf file, we
// must check the package resource for stylesheets or overlays.
@ -1083,64 +1178,11 @@ nsChromeRegistry::GetStyleSheets(nsIURI *aChromeURL,
return NS_OK;
}
NS_IMETHODIMP nsChromeRegistry::GetOverlaysForURI(nsIURI *aChromeURL, nsISimpleEnumerator **aResult)
NS_IMETHODIMP nsChromeRegistry::GetOverlays(nsIURI *aChromeURL, nsISimpleEnumerator **aResult)
{
return GetDynamicInfo(aChromeURL, PR_TRUE, aResult);
}
nsresult
nsChromeRegistry::GetURIList(nsIRDFDataSource *aSource,
nsIRDFResource *aResource,
nsCOMArray<nsIURI>& aArray)
{
nsresult rv;
nsCOMPtr<nsISimpleEnumerator> arcs;
nsCOMPtr<nsIRDFContainer> 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<nsISupports> supports;
nsCOMPtr<nsIRDFLiteral> value;
nsCOMPtr<nsIURI> 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)
@ -1153,20 +1195,17 @@ nsChromeRegistry::GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay,
return NS_OK;
nsCOMPtr<nsIRDFDataSource> installSource;
rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_FALSE, PR_FALSE,
getter_AddRefs(installSource));
NS_ENSURE_SUCCESS(rv, rv);
rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_FALSE, PR_FALSE, getter_AddRefs(installSource));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFDataSource> profileSource;
if (mProfileInitialized) {
rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_TRUE, PR_FALSE,
getter_AddRefs(profileSource));
NS_ENSURE_SUCCESS(rv, rv);
rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_TRUE, PR_FALSE, getter_AddRefs(profileSource));
if (NS_FAILED(rv)) return rv;
}
nsCAutoString lookup;
rv = aChromeURL->GetSpec(lookup);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) return rv;
// Get the chromeResource from this lookup string
nsCOMPtr<nsIRDFResource> chromeResource;
@ -1176,16 +1215,38 @@ nsChromeRegistry::GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay,
return rv;
}
nsCOMArray<nsIURI> overlayURIs;
nsCOMPtr<nsISimpleEnumerator> installArcs;
nsCOMPtr<nsISimpleEnumerator> profileArcs;
if (installSource) {
GetURIList(installSource, chromeResource, overlayURIs);
}
if (profileSource) {
GetURIList(profileSource, chromeResource, overlayURIs);
if (installSource)
{
nsCOMPtr<nsIRDFContainer> 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;
}
return NS_NewArrayEnumerator(aResult, overlayURIs);
if (profileSource)
{
nsCOMPtr<nsIRDFContainer> 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;
}
nsresult
@ -2678,28 +2739,38 @@ NS_IMETHODIMP nsChromeRegistry::SetAllowOverlaysForPackage(const PRUnichar *aPac
return rv;
}
PRBool nsChromeRegistry::IsOverlayAllowed(nsIURI *aChromeURL)
NS_IMETHODIMP nsChromeRegistry::OverlaysAllowedForPackage(const PRUnichar *aPackageName, PRBool *aRetval)
{
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 rdfpackage( "urn:mozilla:package:" );
rdfpackage.Append(package);
nsCAutoString package( "urn:mozilla:package:" );
package.AppendWithConversion(aPackageName);
// Obtain the package resource.
nsresult rv = NS_OK;
nsCOMPtr<nsIRDFResource> packageResource;
rv = GetResource(rdfpackage, getter_AddRefs(packageResource));
if (NS_FAILED(rv) || !packageResource) {
rv = GetResource(package, getter_AddRefs(packageResource));
if (NS_FAILED(rv)) {
NS_ERROR("Unable to obtain the package resource.");
return PR_FALSE;
return rv;
}
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);
return disabled.IsEmpty();
*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);
}
NS_IMETHODIMP nsChromeRegistry::InstallSkin(const char* aBaseURL, PRBool aUseProfile, PRBool aAllowScripts)

Просмотреть файл

@ -48,8 +48,6 @@ class nsIRDFContainerUtils;
class nsIDOMWindowInternal;
class nsIDocument;
#include "nsIChromeRegistry.h"
#include "nsIXULOverlayProvider.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsICSSStyleSheet.h"
#include "nsIObserver.h"
@ -57,15 +55,13 @@ class nsIDocument;
#include "nsString.h"
#include "nsIZipReader.h"
#include "nsICSSLoader.h"
#include "nsCOMArray.h"
// for component registration
// {47049e42-1d87-482a-984d-56ae185e367a}
// {D8C7D8A2-E84C-11d2-BF87-00105A1B0627}
#define NS_CHROMEREGISTRY_CID \
{ 0x47049e42, 0x1d87, 0x482a, { 0x98, 0x4d, 0x56, 0xae, 0x18, 0x5e, 0x36, 0x7a } }
{ 0xd8c7d8a2, 0xe84c, 0x11d2, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
class nsChromeRegistry : public nsIXULChromeRegistry,
public nsIXULOverlayProvider,
public nsIObserver,
public nsSupportsWeakReference
{
@ -75,7 +71,6 @@ public:
// nsIChromeRegistry methods:
NS_DECL_NSICHROMEREGISTRY
NS_DECL_NSIXULCHROMEREGISTRY
NS_DECL_NSIXULOVERLAYPROVIDER
NS_DECL_NSIOBSERVER
@ -96,11 +91,8 @@ public:
protected:
nsresult GetDynamicDataSource(nsIURI *aChromeURL, PRBool aIsOverlay, PRBool aUseProfile, PRBool aCreateDS, nsIRDFDataSource **aResult);
nsresult GetURIList(nsIRDFDataSource *aDS, nsIRDFResource *aResource, nsCOMArray<nsIURI>& aArray);
nsresult GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay, nsISimpleEnumerator **aResult);
PRBool IsOverlayAllowed(nsIURI *aChromeURI);
nsresult GetResource(const nsACString& aChromeType, nsIRDFResource** aResult);
nsresult UpdateDynamicDataSource(nsIRDFDataSource *aDataSource,

Просмотреть файл

@ -136,6 +136,8 @@ 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();
@ -145,6 +147,8 @@ 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,

Просмотреть файл

@ -35,10 +35,6 @@ XPIDLSRCS = \
$(NULL)
ifdef MOZ_XUL
XPIDLSRCS += \
nsIXULOverlayProvider.idl \
$(NULL)
EXPORTS = \
nsIXULContentSink.h \
nsIXULDocument.h \

Просмотреть файл

@ -1,61 +0,0 @@
/* -*- 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 <bsmedberg@covad.net>
* 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);
};

Просмотреть файл

@ -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,7 +87,6 @@
#include "nsIXULContent.h"
#include "nsIXULContentSink.h"
#include "nsXULContentUtils.h"
#include "nsIXULOverlayProvider.h"
#include "nsIXULPrototypeCache.h"
#include "nsNetUtil.h"
#include "nsParserCIID.h"
@ -698,8 +697,6 @@ 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);
@ -709,51 +706,49 @@ nsXULDocument::EndLoad()
// loading it, and write the prototype.
if (useXULCache && mIsWritingFastLoad &&
mMasterPrototype != mCurrentPrototype &&
isChrome)
IsChromeURI(uri))
gXULCache->WritePrototype(mCurrentPrototype);
if (isChrome) {
nsCOMPtr<nsIXULChromeRegistry> reg =
do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv);
if (NS_FAILED(rv)) return;
nsCOMPtr<nsIXULChromeRegistry> reg =
do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv);
if (NS_FAILED(rv)) return;
nsCOMPtr<nsISupportsArray> sheets;
reg->GetStyleSheets(uri, getter_AddRefs(sheets));
nsCOMPtr<nsISupportsArray> 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<nsICSSStyleSheet> sheet;
PRUint32 count;
sheets->Count(&count);
for (PRUint32 i = 0; i < count; ++i) {
sheet = do_QueryElementAt(sheets, i);
if (sheet) {
nsCOMPtr<nsIURI> sheetURL;
sheet->GetURL(*getter_AddRefs(sheetURL));
// Walk the sheets and add them to the prototype. Also put them
// into the document.
if (sheets) {
nsCOMPtr<nsICSSStyleSheet> sheet;
PRUint32 count;
sheets->Count(&count);
for (PRUint32 i = 0; i < count; ++i) {
sheet = do_QueryElementAt(sheets, i);
if (sheet) {
nsCOMPtr<nsIURI> sheetURL;
sheet->GetURL(*getter_AddRefs(sheetURL));
if (useXULCache && IsChromeURI(sheetURL)) {
mCurrentPrototype->AddStyleSheetReference(sheetURL);
}
AddStyleSheet(sheet, 0);
if (useXULCache && IsChromeURI(sheetURL)) {
mCurrentPrototype->AddStyleSheetReference(sheetURL);
}
AddStyleSheet(sheet, 0);
}
}
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();
}
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;
}
// Now walk the prototype to build content.
rv = PrepareToWalk();
if (NS_FAILED(rv)) return;
ResumeWalk();
}
// Called back from nsXULPrototypeDocument::NotifyLoadDone for each XUL
@ -2785,40 +2780,47 @@ nsresult
nsXULDocument::AddChromeOverlays()
{
nsresult rv;
nsCOMPtr<nsIXULChromeRegistry> reg(do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv));
nsCOMPtr<nsIURI> docUri;
rv = mCurrentPrototype->GetURI(getter_AddRefs(docUri));
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
/* overlays only apply to chrome, skip all content URIs */
if (!IsChromeURI(docUri)) return NS_OK;
nsCOMPtr<nsISimpleEnumerator> oe;
nsCOMPtr<nsIXULOverlayProvider> 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);
{
nsCOMPtr<nsIURI> uri;
rv = mCurrentPrototype->GetURI(getter_AddRefs(uri));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsISimpleEnumerator> overlays;
rv = chromeReg->GetOverlaysForURI(docUri, getter_AddRefs(overlays));
NS_ENSURE_SUCCESS(rv, rv);
reg->GetOverlays(uri, getter_AddRefs(oe));
}
PRBool moreOverlays;
nsCOMPtr<nsISupports> next;
nsCOMPtr<nsIURI> uri;
if (!oe)
return NS_OK;
while (NS_SUCCEEDED(rv = overlays->HasMoreElements(&moreOverlays)) &&
moreOverlays) {
rv = overlays->GetNext(getter_AddRefs(next));
if (NS_FAILED(rv) || !next) continue;
PRBool moreElements;
oe->HasMoreElements(&moreElements);
uri = do_QueryInterface(next);
if (!uri) {
NS_ERROR("Chrome registry handed me a non-nsIURI object!");
continue;
}
while (moreElements) {
nsCOMPtr<nsISupports> next;
oe->GetNext(getter_AddRefs(next));
if (!next)
return NS_OK;
mUnloadedOverlays->AppendElement(uri);
}
nsCOMPtr<nsIURI> 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);
}
return NS_OK;
}

Просмотреть файл

@ -41,7 +41,6 @@ REQUIRES = xpcom \
necko \
layout \
content \
xuldoc \
jar \
$(NULL)

Просмотреть файл

@ -43,7 +43,6 @@
#endif
#include <string.h>
#include "nsArrayEnumerator.h"
#include "nsCOMPtr.h"
#include "nsIChromeRegistry.h"
#include "nsChromeRegistry.h"
@ -147,6 +146,107 @@ 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<nsISimpleEnumerator> mInstallArcs;
nsCOMPtr<nsISimpleEnumerator> mProfileArcs;
nsCOMPtr<nsISimpleEnumerator> 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<nsISupports> supports;
rv = mCurrentArcs->GetNext(getter_AddRefs(supports));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIRDFLiteral> 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<nsIURI> 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),
@ -210,12 +310,7 @@ nsChromeRegistry::~nsChromeRegistry()
}
NS_IMPL_THREADSAFE_ISUPPORTS5(nsChromeRegistry,
nsIChromeRegistry,
nsIXULChromeRegistry,
nsIXULOverlayProvider,
nsIObserver,
nsISupportsWeakReference)
NS_IMPL_THREADSAFE_ISUPPORTS4(nsChromeRegistry, nsIChromeRegistry, nsIXULChromeRegistry, nsIObserver, nsISupportsWeakReference)
////////////////////////////////////////////////////////////////////////////////
// nsIChromeRegistry methods:
@ -999,7 +1094,7 @@ nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL,
nsCAutoString package, provider, remaining;
rv = SplitURL(aChromeURL, package, provider, remaining);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) return rv;
if (!aCreateDS) {
// We are not supposed to create the data source, which means
@ -1009,7 +1104,7 @@ nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL,
nsDependentCString dataSourceStr(kChromeFileName);
nsCOMPtr<nsIRDFDataSource> mainDataSource;
rv = LoadDataSource(dataSourceStr, getter_AddRefs(mainDataSource), aUseProfile, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) return rv;
// Now that we have the appropriate chrome.rdf file, we
// must check the package resource for stylesheets or overlays.
@ -1083,64 +1178,11 @@ nsChromeRegistry::GetStyleSheets(nsIURI *aChromeURL,
return NS_OK;
}
NS_IMETHODIMP nsChromeRegistry::GetOverlaysForURI(nsIURI *aChromeURL, nsISimpleEnumerator **aResult)
NS_IMETHODIMP nsChromeRegistry::GetOverlays(nsIURI *aChromeURL, nsISimpleEnumerator **aResult)
{
return GetDynamicInfo(aChromeURL, PR_TRUE, aResult);
}
nsresult
nsChromeRegistry::GetURIList(nsIRDFDataSource *aSource,
nsIRDFResource *aResource,
nsCOMArray<nsIURI>& aArray)
{
nsresult rv;
nsCOMPtr<nsISimpleEnumerator> arcs;
nsCOMPtr<nsIRDFContainer> 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<nsISupports> supports;
nsCOMPtr<nsIRDFLiteral> value;
nsCOMPtr<nsIURI> 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)
@ -1153,20 +1195,17 @@ nsChromeRegistry::GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay,
return NS_OK;
nsCOMPtr<nsIRDFDataSource> installSource;
rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_FALSE, PR_FALSE,
getter_AddRefs(installSource));
NS_ENSURE_SUCCESS(rv, rv);
rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_FALSE, PR_FALSE, getter_AddRefs(installSource));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFDataSource> profileSource;
if (mProfileInitialized) {
rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_TRUE, PR_FALSE,
getter_AddRefs(profileSource));
NS_ENSURE_SUCCESS(rv, rv);
rv = GetDynamicDataSource(aChromeURL, aIsOverlay, PR_TRUE, PR_FALSE, getter_AddRefs(profileSource));
if (NS_FAILED(rv)) return rv;
}
nsCAutoString lookup;
rv = aChromeURL->GetSpec(lookup);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) return rv;
// Get the chromeResource from this lookup string
nsCOMPtr<nsIRDFResource> chromeResource;
@ -1176,16 +1215,38 @@ nsChromeRegistry::GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay,
return rv;
}
nsCOMArray<nsIURI> overlayURIs;
nsCOMPtr<nsISimpleEnumerator> installArcs;
nsCOMPtr<nsISimpleEnumerator> profileArcs;
if (installSource) {
GetURIList(installSource, chromeResource, overlayURIs);
}
if (profileSource) {
GetURIList(profileSource, chromeResource, overlayURIs);
if (installSource)
{
nsCOMPtr<nsIRDFContainer> 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;
}
return NS_NewArrayEnumerator(aResult, overlayURIs);
if (profileSource)
{
nsCOMPtr<nsIRDFContainer> 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;
}
nsresult
@ -2678,28 +2739,38 @@ NS_IMETHODIMP nsChromeRegistry::SetAllowOverlaysForPackage(const PRUnichar *aPac
return rv;
}
PRBool nsChromeRegistry::IsOverlayAllowed(nsIURI *aChromeURL)
NS_IMETHODIMP nsChromeRegistry::OverlaysAllowedForPackage(const PRUnichar *aPackageName, PRBool *aRetval)
{
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 rdfpackage( "urn:mozilla:package:" );
rdfpackage.Append(package);
nsCAutoString package( "urn:mozilla:package:" );
package.AppendWithConversion(aPackageName);
// Obtain the package resource.
nsresult rv = NS_OK;
nsCOMPtr<nsIRDFResource> packageResource;
rv = GetResource(rdfpackage, getter_AddRefs(packageResource));
if (NS_FAILED(rv) || !packageResource) {
rv = GetResource(package, getter_AddRefs(packageResource));
if (NS_FAILED(rv)) {
NS_ERROR("Unable to obtain the package resource.");
return PR_FALSE;
return rv;
}
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);
return disabled.IsEmpty();
*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);
}
NS_IMETHODIMP nsChromeRegistry::InstallSkin(const char* aBaseURL, PRBool aUseProfile, PRBool aAllowScripts)

Просмотреть файл

@ -48,8 +48,6 @@ class nsIRDFContainerUtils;
class nsIDOMWindowInternal;
class nsIDocument;
#include "nsIChromeRegistry.h"
#include "nsIXULOverlayProvider.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsICSSStyleSheet.h"
#include "nsIObserver.h"
@ -57,7 +55,6 @@ class nsIDocument;
#include "nsString.h"
#include "nsIZipReader.h"
#include "nsICSSLoader.h"
#include "nsCOMArray.h"
// for component registration
// {D8C7D8A2-E84C-11d2-BF87-00105A1B0627}
@ -65,7 +62,6 @@ class nsIDocument;
{ 0xd8c7d8a2, 0xe84c, 0x11d2, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
class nsChromeRegistry : public nsIXULChromeRegistry,
public nsIXULOverlayProvider,
public nsIObserver,
public nsSupportsWeakReference
{
@ -75,7 +71,6 @@ public:
// nsIChromeRegistry methods:
NS_DECL_NSICHROMEREGISTRY
NS_DECL_NSIXULCHROMEREGISTRY
NS_DECL_NSIXULOVERLAYPROVIDER
NS_DECL_NSIOBSERVER
@ -96,11 +91,8 @@ public:
protected:
nsresult GetDynamicDataSource(nsIURI *aChromeURL, PRBool aIsOverlay, PRBool aUseProfile, PRBool aCreateDS, nsIRDFDataSource **aResult);
nsresult GetURIList(nsIRDFDataSource *aDS, nsIRDFResource *aResource, nsCOMArray<nsIURI>& aArray);
nsresult GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay, nsISimpleEnumerator **aResult);
PRBool IsOverlayAllowed(nsIURI *aChromeURI);
nsresult GetResource(const nsACString& aChromeType, nsIRDFResource** aResult);
nsresult UpdateDynamicDataSource(nsIRDFDataSource *aDataSource,