mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 15:25:52 +00:00
Bug 1391158: Optimize checkLoadURL for the common case of extension URLs. r=mixedpuppy
MozReview-Commit-ID: KGFFcHxQSvZ --HG-- extra : rebase_source : f4b62ad095077a65e11c6b8354ce54fa2d2ff252
This commit is contained in:
parent
041996d10e
commit
e24e9d802d
@ -821,7 +821,8 @@ this.Extension = class extends ExtensionData {
|
||||
|
||||
this.id = addonData.id;
|
||||
this.version = addonData.version;
|
||||
this.baseURI = Services.io.newURI(this.getURL("")).QueryInterface(Ci.nsIURL);
|
||||
this.baseURL = this.getURL("");
|
||||
this.baseURI = Services.io.newURI(this.baseURL).QueryInterface(Ci.nsIURL);
|
||||
this.principal = this.createPrincipal();
|
||||
this.views = new Set();
|
||||
this._backgroundPageFrameLoader = null;
|
||||
@ -943,7 +944,17 @@ this.Extension = class extends ExtensionData {
|
||||
let uri = Services.io.newURI(url);
|
||||
|
||||
let common = this.baseURI.getCommonBaseSpec(uri);
|
||||
return common == this.baseURI.spec;
|
||||
return common == this.baseURL;
|
||||
}
|
||||
|
||||
checkLoadURL(url, options = {}) {
|
||||
// As an optimization, f the URL starts with the extension's base URL,
|
||||
// don't do any further checks. It's always allowed to load it.
|
||||
if (url.startsWith(this.baseURL)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ExtensionUtils.checkLoadURL(url, this.principal, options);
|
||||
}
|
||||
|
||||
async promiseLocales(locale) {
|
||||
|
@ -511,6 +511,7 @@ class BrowserExtensionContent extends EventEmitter {
|
||||
this.localeData = new LocaleData(data.localeData);
|
||||
|
||||
this.manifest = data.manifest;
|
||||
this.baseURL = data.baseURL;
|
||||
this.baseURI = Services.io.newURI(data.baseURL);
|
||||
|
||||
// Only used in addon processes.
|
||||
|
@ -271,27 +271,13 @@ class BaseContext {
|
||||
}
|
||||
|
||||
checkLoadURL(url, options = {}) {
|
||||
let ssm = Services.scriptSecurityManager;
|
||||
|
||||
let flags = ssm.STANDARD;
|
||||
if (!options.allowScript) {
|
||||
flags |= ssm.DISALLOW_SCRIPT;
|
||||
}
|
||||
if (!options.allowInheritsPrincipal) {
|
||||
flags |= ssm.DISALLOW_INHERIT_PRINCIPAL;
|
||||
}
|
||||
if (options.dontReportErrors) {
|
||||
flags |= ssm.DONT_REPORT_ERRORS;
|
||||
// As an optimization, f the URL starts with the extension's base URL,
|
||||
// don't do any further checks. It's always allowed to load it.
|
||||
if (url.startsWith(this.extension.baseURL)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
ssm.checkLoadURIWithPrincipal(this.principal,
|
||||
Services.io.newURI(url),
|
||||
flags);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return ExtensionUtils.checkLoadURL(url, this.principal, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1292,7 +1292,7 @@ let IconDetails = {
|
||||
// relative paths. We currently accept absolute URLs as well,
|
||||
// which means we need to check that the extension is allowed
|
||||
// to load them. This will throw an error if it's not allowed.
|
||||
this._checkURL(url, extension.principal);
|
||||
this._checkURL(url, extension);
|
||||
|
||||
result[size] = url;
|
||||
}
|
||||
@ -1303,8 +1303,8 @@ let IconDetails = {
|
||||
let lightURL = baseURI.resolve(light);
|
||||
let darkURL = baseURI.resolve(dark);
|
||||
|
||||
this._checkURL(lightURL, extension.principal);
|
||||
this._checkURL(darkURL, extension.principal);
|
||||
this._checkURL(lightURL, extension);
|
||||
this._checkURL(darkURL, extension);
|
||||
|
||||
let defaultURL = result[size];
|
||||
result[size] = {
|
||||
@ -1330,12 +1330,8 @@ let IconDetails = {
|
||||
|
||||
// Checks if the extension is allowed to load the given URL with the specified principal.
|
||||
// This will throw an error if the URL is not allowed.
|
||||
_checkURL(url, principal) {
|
||||
try {
|
||||
Services.scriptSecurityManager.checkLoadURIWithPrincipal(
|
||||
principal, Services.io.newURI(url),
|
||||
Services.scriptSecurityManager.DISALLOW_SCRIPT);
|
||||
} catch (e) {
|
||||
_checkURL(url, extension) {
|
||||
if (!extension.checkLoadURL(url, {allowInheritsPrincipal: true})) {
|
||||
throw new ExtensionError(`Illegal URL ${url}`);
|
||||
}
|
||||
},
|
||||
|
@ -652,7 +652,32 @@ class MessageManagerProxy {
|
||||
}
|
||||
}
|
||||
|
||||
function checkLoadURL(url, principal, options) {
|
||||
let ssm = Services.scriptSecurityManager;
|
||||
|
||||
let flags = ssm.STANDARD;
|
||||
if (!options.allowScript) {
|
||||
flags |= ssm.DISALLOW_SCRIPT;
|
||||
}
|
||||
if (!options.allowInheritsPrincipal) {
|
||||
flags |= ssm.DISALLOW_INHERIT_PRINCIPAL;
|
||||
}
|
||||
if (options.dontReportErrors) {
|
||||
flags |= ssm.DONT_REPORT_ERRORS;
|
||||
}
|
||||
|
||||
try {
|
||||
ssm.checkLoadURIWithPrincipal(principal,
|
||||
Services.io.newURI(url),
|
||||
flags);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
this.ExtensionUtils = {
|
||||
checkLoadURL,
|
||||
defineLazyGetter,
|
||||
flushJarCache,
|
||||
getConsole,
|
||||
|
Loading…
Reference in New Issue
Block a user