mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 04:45:45 +00:00
Bug 1207443 - Change browser_parsable_css.js to load stylesheets with chrome privilege. r=Gijs
--HG-- extra : source : 1c67eb89eed64974a955a0bf5def2537fb3d17a6
This commit is contained in:
parent
e35ad56b37
commit
5443426946
@ -65,6 +65,76 @@ function once(target, name) {
|
||||
});
|
||||
}
|
||||
|
||||
function fetchFile(uri) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", uri, true);
|
||||
xhr.onreadystatechange = function() {
|
||||
if (this.readyState != this.DONE) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
resolve(this.responseText);
|
||||
} catch (ex) {
|
||||
ok(false, `Script error reading ${uri}: ${ex}`);
|
||||
resolve("");
|
||||
}
|
||||
};
|
||||
xhr.onerror = error => {
|
||||
ok(false, `XHR error reading ${uri}: ${error}`);
|
||||
resolve("");
|
||||
};
|
||||
xhr.send(null);
|
||||
});
|
||||
}
|
||||
|
||||
var gChromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]
|
||||
.getService(Ci.nsIChromeRegistry);
|
||||
var gChromeMap = new Map();
|
||||
|
||||
function getBaseUriForChromeUri(chromeUri) {
|
||||
let chromeFile = chromeUri + "gobbledygooknonexistentfile.reallynothere";
|
||||
let uri = Services.io.newURI(chromeFile, null, null);
|
||||
let fileUri = gChromeReg.convertChromeURL(uri);
|
||||
return fileUri.resolve(".");
|
||||
}
|
||||
|
||||
function parseManifest(manifestUri) {
|
||||
return fetchFile(manifestUri.spec).then(data => {
|
||||
for (let line of data.split('\n')) {
|
||||
let [type, ...argv] = line.split(/\s+/);
|
||||
let component;
|
||||
if (type == "content" || type == "skin") {
|
||||
[component] = argv;
|
||||
} else {
|
||||
// skip unrelated lines
|
||||
continue;
|
||||
}
|
||||
let chromeUri = `chrome://${component}/${type}/`;
|
||||
gChromeMap.set(getBaseUriForChromeUri(chromeUri), chromeUri);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function convertToChromeUri(fileUri) {
|
||||
let baseUri = fileUri.spec;
|
||||
let path = "";
|
||||
while (true) {
|
||||
let slashPos = baseUri.lastIndexOf("/", baseUri.length - 2);
|
||||
if (slashPos < 0) {
|
||||
info(`File not accessible from chrome protocol: ${fileUri.path}`);
|
||||
return fileUri;
|
||||
}
|
||||
path = baseUri.slice(slashPos + 1) + path;
|
||||
baseUri = baseUri.slice(0, slashPos + 1);
|
||||
if (gChromeMap.has(baseUri)) {
|
||||
let chromeBaseUri = gChromeMap.get(baseUri);
|
||||
let chromeUri = `${chromeBaseUri}${path}`;
|
||||
return Services.io.newURI(chromeUri, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function messageIsCSSError(msg, innerWindowID, outerWindowID) {
|
||||
// Only care about CSS errors generated by our iframe:
|
||||
if ((msg instanceof Ci.nsIScriptError) &&
|
||||
@ -85,15 +155,11 @@ add_task(function checkAllTheCSS() {
|
||||
// This asynchronously produces a list of URLs (sadly, mostly sync on our
|
||||
// test infrastructure because it runs against jarfiles there, and
|
||||
// our zipreader APIs are all sync)
|
||||
let uris = yield generateURIsFromDirTree(appDir, ".css");
|
||||
let uris = yield generateURIsFromDirTree(appDir, [".css", ".manifest"]);
|
||||
|
||||
// Create a clean iframe to load all the files into. This needs to live at a
|
||||
// file or jar URI (depending on whether we're using a packaged build or not)
|
||||
// so that it's allowed to load other same-scheme URIs (i.e. the browser css).
|
||||
let resHandler = Services.io.getProtocolHandler("resource")
|
||||
.QueryInterface(Ci.nsISubstitutingProtocolHandler);
|
||||
let resURI = Services.io.newURI('resource://testing-common/resource_test_file.html', null, null);
|
||||
let testFile = resHandler.resolveURI(resURI);
|
||||
// chrome URI so that it's allowed to load and parse any styles.
|
||||
let testFile = getRootDirectory(gTestPath) + "dummy_page.html";
|
||||
let windowless = Services.appShell.createWindowlessBrowser();
|
||||
let iframe = windowless.document.createElementNS("http://www.w3.org/1999/xhtml", "html:iframe");
|
||||
windowless.document.documentElement.appendChild(iframe);
|
||||
@ -106,6 +172,20 @@ add_task(function checkAllTheCSS() {
|
||||
let innerWindowID = windowUtils.currentInnerWindowID;
|
||||
let outerWindowID = windowUtils.outerWindowID;
|
||||
|
||||
// Parse and remove all manifests from the list.
|
||||
// NOTE that this must be done before filtering out devtools paths
|
||||
// so that all chrome paths can be recorded.
|
||||
let manifestPromises = [];
|
||||
uris = uris.filter(uri => {
|
||||
if (uri.path.endsWith(".manifest")) {
|
||||
manifestPromises.push(parseManifest(uri));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
// Wait for all manifest to be parsed
|
||||
yield Promise.all(manifestPromises);
|
||||
|
||||
// We build a list of promises that get resolved when their respective
|
||||
// files have loaded and produced no errors.
|
||||
let allPromises = [];
|
||||
@ -133,7 +213,8 @@ add_task(function checkAllTheCSS() {
|
||||
linkEl.addEventListener("load", onLoad);
|
||||
linkEl.addEventListener("error", onError);
|
||||
linkEl.setAttribute("type", "text/css");
|
||||
linkEl.setAttribute("href", uri.spec);
|
||||
let chromeUri = convertToChromeUri(uri);
|
||||
linkEl.setAttribute("href", chromeUri.spec);
|
||||
allPromises.push(promiseForThisSpec.promise);
|
||||
doc.head.appendChild(linkEl);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
@import url("chrome://devtools/skin/themes/floating-scrollbars.css");
|
||||
@import url("floating-scrollbars.css");
|
||||
|
||||
scrollbar thumb {
|
||||
background-color: rgba(170,170,170,0.2) !important;
|
||||
|
Loading…
Reference in New Issue
Block a user