Skip to content

Commit

Permalink
Bug 564667: Allow bootstrapped add-ons to have chrome URLs. r=dtownse…
Browse files Browse the repository at this point in the history
…nd, sr=bsmedberg
  • Loading branch information
peregrinogris committed Jul 29, 2011
1 parent 4b76f9f commit a0ef232
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 24 deletions.
Binary file added chrome/test/unit/data/test_bug564667.xpi
Binary file not shown.
16 changes: 16 additions & 0 deletions chrome/test/unit/data/test_bug564667/chrome.manifest
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions chrome/test/unit/data/test_bug564667/loaded.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
content test2 test/
locale test2 en-US test/
155 changes: 155 additions & 0 deletions chrome/test/unit/test_bug564667.js
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>.
*
* 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 + "!/");
}
1 change: 1 addition & 0 deletions chrome/test/unit/xpcshell.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion xpcom/build/nsXULAppAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ XRE_API(nsresult,
enum NSLocationType
{
NS_COMPONENT_LOCATION,
NS_SKIN_LOCATION
NS_SKIN_LOCATION,
NS_BOOTSTRAPPED_LOCATION
};

XRE_API(nsresult,
Expand Down
41 changes: 26 additions & 15 deletions xpcom/components/ManifestParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ struct ManifestDirective

bool ischrome;

bool allowbootstrap;

// The platform/contentaccessible flags only apply to content directives.
bool contentflags;

Expand All @@ -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 }
};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit a0ef232

Please sign in to comment.