зеркало из https://github.com/mozilla/pjs.git
Bug 564667: Allow bootstrapped add-ons to have chrome URLs. r=dtownsend, sr=bsmedberg
This commit is contained in:
Родитель
d800946662
Коммит
75db19c5a6
Двоичный файл не отображается.
|
@ -0,0 +1,16 @@
|
|||
# Locally defined URLs
|
||||
content test1 test/
|
||||
locale test1 en-US test/
|
||||
skin test1 test test/
|
||||
|
||||
# Test Override
|
||||
content testOverride test/
|
||||
override chrome://testOverride/content file:///test1/override
|
||||
|
||||
|
||||
# Load external manifest
|
||||
manifest loaded.manifest
|
||||
|
||||
# Failure Cases
|
||||
overlay chrome://test1/content/overlay.xul chrome://test1/content/test1.xul
|
||||
style chrome://test1/content/style.xul chrome://test1/content/test1.css
|
|
@ -0,0 +1,2 @@
|
|||
content test2 test/
|
||||
locale test2 en-US test/
|
|
@ -0,0 +1,155 @@
|
|||
/* ***** 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* the Mozilla Foundation.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Hernan Rodriguez Colmeiro <colmeiro@gmail.com>.
|
||||
*
|
||||
* 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 *****
|
||||
*/
|
||||
|
||||
const UNPACKAGED_ADDON = do_get_file("data/test_bug564667");
|
||||
const PACKAGED_ADDON = do_get_file("data/test_bug564667.xpi");
|
||||
|
||||
var gIOS = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
|
||||
var gCR = Cc["@mozilla.org/chrome/chrome-registry;1"].
|
||||
getService(Ci.nsIChromeRegistry).
|
||||
QueryInterface(Ci.nsIXULOverlayProvider);
|
||||
|
||||
/*
|
||||
* Checks that a mapping was added
|
||||
*/
|
||||
function test_mapping(chromeURL, target) {
|
||||
var uri = gIOS.newURI(chromeURL, null, null);
|
||||
|
||||
try {
|
||||
var result = gCR.convertChromeURL(uri);
|
||||
do_check_eq(result.spec, target);
|
||||
}
|
||||
catch (ex) {
|
||||
do_throw(chromeURL + " not Registered");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks that a mapping was removed
|
||||
*/
|
||||
function test_removed_mapping(chromeURL, target) {
|
||||
var uri = gIOS.newURI(chromeURL, null, null);
|
||||
try {
|
||||
var result = gCR.convertChromeURL(uri);
|
||||
do_throw(chromeURL + " not removed");
|
||||
}
|
||||
catch (ex) {
|
||||
// This should throw
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks if any overlay was added after loading
|
||||
* the manifest files
|
||||
*
|
||||
* @param type The type of overlay: overlay|style
|
||||
*/
|
||||
function test_no_overlays(chromeURL, target, type) {
|
||||
var type = type || "overlay";
|
||||
var uri = gIOS.newURI(chromeURL, null, null);
|
||||
var present = false, elem;
|
||||
|
||||
var overlays = (type == "overlay") ?
|
||||
gCR.getXULOverlays(uri) : gCR.getStyleOverlays(uri);
|
||||
|
||||
// We shouldn't be allowed to register overlays nor styles
|
||||
if (overlays.hasMoreElements()) {
|
||||
if (type == "styles")
|
||||
do_throw("Style Registered: " + chromeURL);
|
||||
else
|
||||
do_throw("Overlay Registered: " + chromeURL);
|
||||
}
|
||||
}
|
||||
|
||||
function testManifest(manifestPath, baseURI) {
|
||||
|
||||
// ------------------ Add manifest file ------------------------
|
||||
Components.manager.addBootstrappedManifestLocation(manifestPath);
|
||||
|
||||
// Test Adding Content URL
|
||||
test_mapping("chrome://test1/content", baseURI + "test/test1.xul");
|
||||
|
||||
// Test Adding Locale URL
|
||||
test_mapping("chrome://test1/locale", baseURI + "test/test1.dtd");
|
||||
|
||||
// Test Adding Skin URL
|
||||
test_mapping("chrome://test1/skin", baseURI + "test/test1.css");
|
||||
|
||||
// Test Adding Manifest URL
|
||||
test_mapping("chrome://test2/content", baseURI + "test/test2.xul");
|
||||
test_mapping("chrome://test2/locale", baseURI + "test/test2.dtd");
|
||||
|
||||
// Test Adding Override
|
||||
test_mapping("chrome://testOverride/content", 'file:///test1/override')
|
||||
|
||||
// Test Not-Adding Overlays
|
||||
test_no_overlays("chrome://test1/content/overlay.xul",
|
||||
"chrome://test1/content/test1.xul");
|
||||
|
||||
// Test Not-Adding Styles
|
||||
test_no_overlays("chrome://test1/content/style.xul",
|
||||
"chrome://test1/content/test1.css", "styles");
|
||||
|
||||
|
||||
// ------------------ Remove manifest file ------------------------
|
||||
Components.manager.removeBootstrappedManifestLocation(manifestPath);
|
||||
|
||||
// Test Removing Content URL
|
||||
test_removed_mapping("chrome://test1/content", baseURI + "test/test1.xul");
|
||||
|
||||
// Test Removing Content URL
|
||||
test_removed_mapping("chrome://test1/locale", baseURI + "test/test1.dtd");
|
||||
|
||||
// Test Removing Skin URL
|
||||
test_removed_mapping("chrome://test1/skin", baseURI + "test/test1.css");
|
||||
|
||||
// Test Removing Manifest URL
|
||||
test_removed_mapping("chrome://test2/content", baseURI + "test/test2.xul");
|
||||
test_removed_mapping("chrome://test2/locale", baseURI + "test/test2.dtd");
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
// Test an unpackaged addon
|
||||
testManifest(UNPACKAGED_ADDON, gIOS.newFileURI(UNPACKAGED_ADDON).spec);
|
||||
|
||||
// Test a packaged addon
|
||||
testManifest(PACKAGED_ADDON, "jar:" + gIOS.newFileURI(PACKAGED_ADDON).spec + "!/");
|
||||
}
|
|
@ -10,6 +10,7 @@ tail =
|
|||
[test_bug401153.js]
|
||||
[test_bug415367.js]
|
||||
[test_bug519468.js]
|
||||
[test_bug564667.js]
|
||||
[test_crlf.js]
|
||||
[test_data_protocol_registration.js]
|
||||
[test_no_remote_registration.js]
|
||||
|
|
|
@ -373,7 +373,8 @@ XRE_API(nsresult,
|
|||
enum NSLocationType
|
||||
{
|
||||
NS_COMPONENT_LOCATION,
|
||||
NS_SKIN_LOCATION
|
||||
NS_SKIN_LOCATION,
|
||||
NS_BOOTSTRAPPED_LOCATION
|
||||
};
|
||||
|
||||
XRE_API(nsresult,
|
||||
|
|
|
@ -76,6 +76,8 @@ struct ManifestDirective
|
|||
|
||||
bool ischrome;
|
||||
|
||||
bool allowbootstrap;
|
||||
|
||||
// The platform/contentaccessible flags only apply to content directives.
|
||||
bool contentflags;
|
||||
|
||||
|
@ -92,31 +94,31 @@ struct ManifestDirective
|
|||
bool isContract;
|
||||
};
|
||||
static const ManifestDirective kParsingTable[] = {
|
||||
{ "manifest", 1, false, true, false,
|
||||
{ "manifest", 1, false, true, true, false,
|
||||
&nsComponentManagerImpl::ManifestManifest, NULL },
|
||||
{ "binary-component", 1, true, false, false,
|
||||
{ "binary-component", 1, true, false, false, false,
|
||||
&nsComponentManagerImpl::ManifestBinaryComponent, NULL },
|
||||
{ "interfaces", 1, true, false, false,
|
||||
{ "interfaces", 1, true, false, false, false,
|
||||
&nsComponentManagerImpl::ManifestXPT, NULL },
|
||||
{ "component", 2, true, false, false,
|
||||
{ "component", 2, true, false, false, false,
|
||||
&nsComponentManagerImpl::ManifestComponent, NULL },
|
||||
{ "contract", 2, true, false, false,
|
||||
{ "contract", 2, true, false, false, false,
|
||||
&nsComponentManagerImpl::ManifestContract, NULL, true},
|
||||
{ "category", 3, true, false, false,
|
||||
{ "category", 3, true, false, false, false,
|
||||
&nsComponentManagerImpl::ManifestCategory, NULL },
|
||||
{ "content", 2, true, true, true,
|
||||
{ "content", 2, true, true, true, true,
|
||||
NULL, &nsChromeRegistry::ManifestContent },
|
||||
{ "locale", 3, true, true, false,
|
||||
{ "locale", 3, true, true, true, false,
|
||||
NULL, &nsChromeRegistry::ManifestLocale },
|
||||
{ "skin", 3, false, true, false,
|
||||
{ "skin", 3, false, true, true, false,
|
||||
NULL, &nsChromeRegistry::ManifestSkin },
|
||||
{ "overlay", 2, true, true, false,
|
||||
{ "overlay", 2, true, true, false, false,
|
||||
NULL, &nsChromeRegistry::ManifestOverlay },
|
||||
{ "style", 2, false, true, false,
|
||||
{ "style", 2, false, true, false, false,
|
||||
NULL, &nsChromeRegistry::ManifestStyle },
|
||||
{ "override", 2, true, true, false,
|
||||
{ "override", 2, true, true, true, false,
|
||||
NULL, &nsChromeRegistry::ManifestOverride },
|
||||
{ "resource", 2, true, true, false,
|
||||
{ "resource", 2, true, true, false, false,
|
||||
NULL, &nsChromeRegistry::ManifestResource }
|
||||
};
|
||||
|
||||
|
@ -450,7 +452,7 @@ ParseManifestCommon(NSLocationType aType, nsILocalFile* aFile,
|
|||
rv = xapp->GetVersion(s);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
CopyUTF8toUTF16(s, appVersion);
|
||||
|
||||
|
||||
nsCOMPtr<nsIXULRuntime> xruntime (do_QueryInterface(xapp));
|
||||
if (xruntime) {
|
||||
rv = xruntime->GetOS(s);
|
||||
|
@ -538,13 +540,22 @@ ParseManifestCommon(NSLocationType aType, nsILocalFile* aFile,
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!directive) {
|
||||
LogMessageWithContext(aFile, aPath, line,
|
||||
"Ignoring unrecognized chrome manifest directive '%s'.",
|
||||
token);
|
||||
continue;
|
||||
}
|
||||
if (directive->componentonly && NS_COMPONENT_LOCATION != aType) {
|
||||
|
||||
if (!directive->allowbootstrap && NS_BOOTSTRAPPED_LOCATION == aType) {
|
||||
LogMessageWithContext(aFile, aPath, line,
|
||||
"Bootstrapped manifest not allowed to use '%s' directive.",
|
||||
token);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (directive->componentonly && NS_SKIN_LOCATION == aType) {
|
||||
LogMessageWithContext(aFile, aPath, line,
|
||||
"Skin manifest not allowed to use '%s' directive.",
|
||||
token);
|
||||
|
|
|
@ -89,6 +89,7 @@
|
|||
#include "prio.h"
|
||||
#include "mozilla/FunctionTimer.h"
|
||||
#include "ManifestParser.h"
|
||||
#include "mozilla/Services.h"
|
||||
|
||||
#include "nsManifestLineReader.h"
|
||||
#include "mozilla/GenericFactory.h"
|
||||
|
@ -406,7 +407,7 @@ nsresult nsComponentManagerImpl::Init()
|
|||
nsCOMPtr<nsIZipReader> reader = do_CreateInstance(kZipReaderCID, &rv);
|
||||
rv = reader->Open(l.location);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
RegisterJarManifest(reader, "chrome.manifest", false);
|
||||
RegisterJarManifest(l.type, reader, "chrome.manifest", false);
|
||||
}
|
||||
|
||||
nsCategoryManager::GetSingleton()->SuppressNotifications(false);
|
||||
|
@ -542,7 +543,7 @@ LoadEntry(nsIZipReader* aReader, const char* aName)
|
|||
}
|
||||
|
||||
void
|
||||
nsComponentManagerImpl::RegisterJarManifest(nsIZipReader* aReader,
|
||||
nsComponentManagerImpl::RegisterJarManifest(NSLocationType aType, nsIZipReader* aReader,
|
||||
const char* aPath, bool aChromeOnly)
|
||||
{
|
||||
nsCOMPtr<nsIInputStream> is = LoadEntry(aReader, aPath);
|
||||
|
@ -576,7 +577,7 @@ nsComponentManagerImpl::RegisterJarManifest(nsIZipReader* aReader,
|
|||
|
||||
whole[flen] = '\0';
|
||||
|
||||
ParseManifest(NS_COMPONENT_LOCATION, aReader, aPath,
|
||||
ParseManifest(aType, aReader, aPath,
|
||||
whole, aChromeOnly);
|
||||
}
|
||||
|
||||
|
@ -674,7 +675,7 @@ nsComponentManagerImpl::ManifestManifest(ManifestProcessingContext& cx, int line
|
|||
nsCAutoString manifest(cx.mPath);
|
||||
AppendFileToManifestPath(manifest, file);
|
||||
|
||||
RegisterJarManifest(cx.mReader, manifest.get(), cx.mChromeOnly);
|
||||
RegisterJarManifest(cx.mType, cx.mReader, manifest.get(), cx.mChromeOnly);
|
||||
}
|
||||
else {
|
||||
#ifdef TRANSLATE_SLASHES
|
||||
|
@ -911,7 +912,7 @@ nsComponentManagerImpl::RereadChromeManifests()
|
|||
if (NS_SUCCEEDED(rv))
|
||||
rv = reader->Open(l.location);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
RegisterJarManifest(reader, "chrome.manifest", true);
|
||||
RegisterJarManifest(l.type, reader, "chrome.manifest", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2036,6 +2037,57 @@ XRE_AddStaticComponent(const mozilla::Module* aComponent)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComponentManagerImpl::AddBootstrappedManifestLocation(nsILocalFile* aLocation)
|
||||
{
|
||||
nsString path;
|
||||
nsresult rv = aLocation->GetPath(path);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (Substring(path, path.Length() - 4).Equals(NS_LITERAL_STRING(".xpi"))) {
|
||||
return XRE_AddJarManifestLocation(NS_BOOTSTRAPPED_LOCATION, aLocation);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsILocalFile> manifest =
|
||||
CloneAndAppend(aLocation, NS_LITERAL_CSTRING("chrome.manifest"));
|
||||
return XRE_AddManifestLocation(NS_BOOTSTRAPPED_LOCATION, manifest);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComponentManagerImpl::RemoveBootstrappedManifestLocation(nsILocalFile* aLocation)
|
||||
{
|
||||
nsCOMPtr<nsIChromeRegistry> cr = mozilla::services::GetChromeRegistryService();
|
||||
if (!cr)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
bool isJar = false;
|
||||
nsCOMPtr<nsILocalFile> manifest;
|
||||
nsString path;
|
||||
nsresult rv = aLocation->GetPath(path);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (Substring(path, path.Length() - 4).Equals(NS_LITERAL_STRING(".xpi"))) {
|
||||
isJar = true;
|
||||
manifest = aLocation;
|
||||
} else {
|
||||
manifest = CloneAndAppend(aLocation, NS_LITERAL_CSTRING("chrome.manifest"));
|
||||
}
|
||||
|
||||
nsComponentManagerImpl::ComponentLocation elem = {
|
||||
NS_BOOTSTRAPPED_LOCATION,
|
||||
manifest,
|
||||
isJar
|
||||
};
|
||||
|
||||
// Remove reference.
|
||||
nsComponentManagerImpl::sModuleLocations->RemoveElement(elem, ComponentLocationComparator());
|
||||
|
||||
rv = cr->CheckForNewChrome();
|
||||
return rv;
|
||||
}
|
||||
|
||||
EXPORT_XPCOM_API(nsresult)
|
||||
XRE_AddManifestLocation(NSLocationType aType, nsILocalFile* aLocation)
|
||||
{
|
||||
|
@ -2073,7 +2125,7 @@ XRE_AddJarManifestLocation(NSLocationType aType, nsILocalFile* aLocation)
|
|||
|
||||
rv = reader->Open(c->location);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
nsComponentManagerImpl::gComponentManager->RegisterJarManifest(reader, "chrome.manifest", false);
|
||||
nsComponentManagerImpl::gComponentManager->RegisterJarManifest(aType, reader, "chrome.manifest", false);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -162,6 +162,22 @@ public:
|
|||
bool jar;
|
||||
};
|
||||
|
||||
class ComponentLocationComparator
|
||||
{
|
||||
public:
|
||||
PRBool Equals(const ComponentLocation& a, const ComponentLocation& b) const
|
||||
{
|
||||
if (a.type == b.type && a.jar == b.jar) {
|
||||
PRBool res;
|
||||
nsresult rv = a.location->Equals(b.location, &res);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Error comparing locations");
|
||||
return res;
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
};
|
||||
|
||||
static nsTArray<const mozilla::Module*>* sStaticModules;
|
||||
static nsTArray<ComponentLocation>* sModuleLocations;
|
||||
static nsTArray<ComponentLocation>* sJarModuleLocations;
|
||||
|
@ -240,7 +256,7 @@ public:
|
|||
KnownModule* aModule);
|
||||
void RegisterContractID(const mozilla::Module::ContractIDEntry* aEntry);
|
||||
|
||||
void RegisterJarManifest(nsIZipReader* aReader,
|
||||
void RegisterJarManifest(NSLocationType aType, nsIZipReader* aReader,
|
||||
const char* aPath, bool aChromeOnly);
|
||||
|
||||
void RegisterManifestFile(NSLocationType aType, nsILocalFile* aFile,
|
||||
|
|
|
@ -41,9 +41,10 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsILocalFile;
|
||||
interface nsIFactory;
|
||||
|
||||
[scriptable, uuid(a88e5a60-205a-4bb1-94e1-2628daf51eae)]
|
||||
[scriptable, uuid(1d940426-5fe5-42c3-84ae-a300f2d9ebd5)]
|
||||
interface nsIComponentManager : nsISupports
|
||||
{
|
||||
/**
|
||||
|
@ -99,6 +100,27 @@ interface nsIComponentManager : nsISupports
|
|||
in nsISupports aDelegate,
|
||||
in nsIIDRef aIID,
|
||||
[iid_is(aIID),retval] out nsQIResult result);
|
||||
|
||||
/**
|
||||
* addBootstrappedManifestLocation
|
||||
*
|
||||
* Adds a bootstrapped manifest location on runtime.
|
||||
*
|
||||
* @param aLocation : A directory where chrome.manifest resides,
|
||||
* or an XPI with it on the root.
|
||||
*/
|
||||
void addBootstrappedManifestLocation(in nsILocalFile aLocation);
|
||||
|
||||
/**
|
||||
* removeBootstrappedManifestLocation
|
||||
*
|
||||
* Removes a bootstrapped manifest location on runtime.
|
||||
*
|
||||
* @param aLocation : A directory where chrome.manifest resides,
|
||||
* or an XPI with it on the root.
|
||||
*/
|
||||
void removeBootstrappedManifestLocation(in nsILocalFile aLocation);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче