Bug 1391099: Avoid using checkLoadURIStrWithPrincipal. r?mixedpuppy
checkLoadURIStrWithPrincipal runs URLs through the URI fixup services and
checks against each of the results. This is both expensive and unnecessary for
our purposes.
MozReview-Commit-ID: 4L2Z4KuMZhQ
--- a/toolkit/components/extensions/ExtensionCommon.jsm
+++ b/toolkit/components/extensions/ExtensionCommon.jsm
@@ -280,17 +280,19 @@ class BaseContext {
if (!options.allowInheritsPrincipal) {
flags |= ssm.DISALLOW_INHERIT_PRINCIPAL;
}
if (options.dontReportErrors) {
flags |= ssm.DONT_REPORT_ERRORS;
}
try {
- ssm.checkLoadURIStrWithPrincipal(this.principal, url, flags);
+ ssm.checkLoadURIWithPrincipal(this.principal,
+ Services.io.newURI(url),
+ flags);
} catch (e) {
return false;
}
return true;
}
/**
* Safely call JSON.stringify() on an object that comes from an
--- a/toolkit/components/extensions/ExtensionParent.jsm
+++ b/toolkit/components/extensions/ExtensionParent.jsm
@@ -1321,18 +1321,18 @@ let IconDetails = {
return result;
},
// 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.checkLoadURIStrWithPrincipal(
- principal, url,
+ Services.scriptSecurityManager.checkLoadURIWithPrincipal(
+ principal, Services.io.newURI(url),
Services.scriptSecurityManager.DISALLOW_SCRIPT);
} catch (e) {
throw new ExtensionError(`Illegal URL ${url}`);
}
},
// Returns the appropriate icon URL for the given icons object and the
// screen resolution of the given window.
--- a/toolkit/components/extensions/Schemas.jsm
+++ b/toolkit/components/extensions/Schemas.jsm
@@ -341,18 +341,19 @@ class Context {
* Checks whether `url` may be loaded by the extension in this context.
*
* @param {string} url The URL that the extension wished to load.
* @returns {boolean} Whether the context may load `url`.
*/
checkLoadURL(url) {
let ssm = Services.scriptSecurityManager;
try {
- ssm.checkLoadURIStrWithPrincipal(this.principal, url,
- ssm.DISALLOW_INHERIT_PRINCIPAL);
+ ssm.checkLoadURIWithPrincipal(this.principal,
+ Services.io.newURI(url),
+ ssm.DISALLOW_INHERIT_PRINCIPAL);
} catch (e) {
return false;
}
return true;
}
/**
* Checks whether this context has the given permission.