Bug 1398630: Part 6 - Avoid some avoidable uses of nsIURI. r?zombie
MozReview-Commit-ID: 18Wd3buFM38
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -377,17 +377,17 @@ this.ExtensionData = class {
if (!this.uuid) {
this.uuid = UUIDMap.get(this.id);
}
return `moz-extension://${this.uuid}/${path}`;
}
async readDirectory(path) {
if (this.rootURI instanceof Ci.nsIFileURL) {
- let uri = Services.io.newURI(this.rootURI.resolve("./" + path));
+ let uri = Services.io.newURI("./" + path, null, this.rootURI);
let fullPath = uri.QueryInterface(Ci.nsIFileURL).file.path;
let iter = new OS.File.DirectoryIterator(fullPath);
let results = [];
try {
await iter.forEach(entry => {
results.push(entry);
--- a/toolkit/components/extensions/ext-cookies.js
+++ b/toolkit/components/extensions/ext-cookies.js
@@ -167,25 +167,25 @@ const query = function* (detailsIn, prop
if (isPrivate) {
storeId = PRIVATE_STORE;
} else if ("storeId" in details) {
storeId = details.storeId;
}
// We can use getCookiesFromHost for faster searching.
let enumerator;
- let uri;
+ let url;
let originAttributes = {
userContextId,
privateBrowsingId: isPrivate ? 1 : 0,
};
if ("url" in details) {
try {
- uri = Services.io.newURI(details.url).QueryInterface(Ci.nsIURL);
- enumerator = Services.cookies.getCookiesFromHost(uri.host, originAttributes);
+ url = new URL(details.url);
+ enumerator = Services.cookies.getCookiesFromHost(url.host, originAttributes);
} catch (ex) {
// This often happens for about: URLs
return;
}
} else if ("domain" in details) {
enumerator = Services.cookies.getCookiesFromHost(details.domain, originAttributes);
} else {
enumerator = Services.cookies.getCookiesWithOriginAttributes(JSON.stringify(originAttributes));
@@ -206,31 +206,30 @@ const query = function* (detailsIn, prop
// path == cookiePath, but without the redundant string compare.
if (path.length == cookiePath.length) {
return true;
}
// URL path is a substring of the cookie path, so it matches if, and
// only if, the next character is a path delimiter.
- let pathDelimiters = ["/", "?", "#", ";"];
- return pathDelimiters.includes(path[cookiePath.length]);
+ return path[cookiePath.length] === "/";
}
// "Restricts the retrieved cookies to those that would match the given URL."
- if (uri) {
- if (!domainMatches(uri.host)) {
+ if (url) {
+ if (!domainMatches(url.host)) {
return false;
}
- if (cookie.isSecure && uri.scheme != "https") {
+ if (cookie.isSecure && url.protocol != "https:") {
return false;
}
- if (!pathMatches(uri.pathQueryRef)) {
+ if (!pathMatches(url.path)) {
return false;
}
}
if ("name" in details && details.name != cookie.name) {
return false;
}
@@ -285,27 +284,27 @@ this.cookies = class extends ExtensionAP
getAll: function(details) {
let allowed = ["url", "name", "domain", "path", "secure", "session", "storeId"];
let result = Array.from(query(details, allowed, context), convertCookie);
return Promise.resolve(result);
},
set: function(details) {
- let uri = Services.io.newURI(details.url).QueryInterface(Ci.nsIURL);
+ let uri = Services.io.newURI(details.url);
let path;
if (details.path !== null) {
path = details.path;
} else {
// This interface essentially emulates the behavior of the
// Set-Cookie header. In the case of an omitted path, the cookie
// service uses the directory path of the requesting URL, ignoring
// any filename or query parameters.
- path = uri.directory;
+ path = uri.QueryInterface(Ci.nsIURL).directory;
}
let name = details.name !== null ? details.name : "";
let value = details.value !== null ? details.value : "";
let secure = details.secure !== null ? details.secure : false;
let httpOnly = details.httpOnly !== null ? details.httpOnly : false;
let isSession = details.expirationDate === null;
let expiry = isSession ? Number.MAX_SAFE_INTEGER : details.expirationDate;
--- a/toolkit/components/extensions/ext-runtime.js
+++ b/toolkit/components/extensions/ext-runtime.js
@@ -119,22 +119,22 @@ this.runtime = class extends ExtensionAP
setUninstallURL: function(url) {
if (url.length == 0) {
return Promise.resolve();
}
let uri;
try {
- uri = Services.io.newURI(url);
+ uri = new URL(url);
} catch (e) {
return Promise.reject({message: `Invalid URL: ${JSON.stringify(url)}`});
}
- if (uri.scheme != "http" && uri.scheme != "https") {
+ if (uri.protocol != "http:" && uri.protocol != "https:") {
return Promise.reject({message: "url must have the scheme http or https"});
}
extension.uninstallURL = url;
return Promise.resolve();
},
},
};
--- a/toolkit/components/extensions/ext-toolkit.js
+++ b/toolkit/components/extensions/ext-toolkit.js
@@ -10,16 +10,18 @@
getContainerForCookieStoreId: false,
isValidCookieStoreId:false, isContainerCookieStoreId:false,
isDefaultCookieStoreId: false, isPrivateCookieStoreId:false,
EventManager: false, InputEventManager: false */
XPCOMUtils.defineLazyModuleGetter(this, "ContextualIdentityService",
"resource://gre/modules/ContextualIdentityService.jsm");
+Cu.importGlobalProperties(["URL"]);
+
Cu.import("resource://gre/modules/ExtensionCommon.jsm");
global.EventEmitter = ExtensionUtils.EventEmitter;
global.EventManager = ExtensionCommon.EventManager;
global.InputEventManager = class extends EventManager {
constructor(...args) {
super(...args);
this.inputHandling = true;