Bug 1249934 - Avoid CPOWs in GCLI cookie commands. r=jwalker
MozReview-Commit-ID: 3a1PoMDbUYW
--- a/devtools/shared/gcli/commands/cookie.js
+++ b/devtools/shared/gcli/commands/cookie.js
@@ -13,35 +13,31 @@
* However, server-running commands have no way of accessing the parent process
* for now.
*
* So, because these cookie commands, as of today, only run in the developer
* toolbar (the gcli command bar), and because this toolbar is only available on
* a local Firefox desktop tab (not in webide or the browser toolbox), we can
* make the commands run on the client.
* This way, they'll always run in the parent process.
- *
- * Note that the commands also need access to the content (see
- * context.environment.document) which means that as long as they run on the
- * client, they'll be using CPOWs (when e10s is enabled).
*/
const { Ci, Cc } = require("chrome");
const l10n = require("gcli/l10n");
const URL = require("sdk/url").URL;
XPCOMUtils.defineLazyGetter(this, "cookieMgr", function() {
return Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2);
});
/**
* Check host value and remove port part as it is not used
* for storing cookies.
*
- * Parameter will usually be context.environment.document.location.host
+ * Parameter will usually be `new URL(context.environment.target.url).host`
*/
function sanitizeHost(host) {
if (host == null || host == "") {
throw new Error(l10n.lookup("cookieListOutNonePage"));
}
return host.split(":")[0];
}
@@ -81,18 +77,18 @@ exports.items = [
description: l10n.lookup("cookieListDesc"),
manual: l10n.lookup("cookieListManual"),
returnType: "cookies",
exec: function(args, context) {
if (context.environment.target.isRemote) {
throw new Error("The cookie gcli commands only work in a local tab, " +
"see bug 1221488");
}
- let host = sanitizeHost(context.environment.document.location.host);
-
+ let host = new URL(context.environment.target.url).host;
+ host = sanitizeHost(host);
let enm = cookieMgr.getCookiesFromHost(host);
let cookies = [];
while (enm.hasMoreElements()) {
let cookie = enm.getNext().QueryInterface(Ci.nsICookie);
if (isCookieAtHost(cookie, host)) {
cookies.push({
host: cookie.host,
@@ -123,17 +119,18 @@ exports.items = [
description: l10n.lookup("cookieRemoveKeyDesc"),
}
],
exec: function(args, context) {
if (context.environment.target.isRemote) {
throw new Error("The cookie gcli commands only work in a local tab, " +
"see bug 1221488");
}
- let host = sanitizeHost(context.environment.document.location.host);
+ let host = new URL(context.environment.target.url).host;
+ host = sanitizeHost(host);
let enm = cookieMgr.getCookiesFromHost(host);
while (enm.hasMoreElements()) {
let cookie = enm.getNext().QueryInterface(Ci.nsICookie);
if (isCookieAtHost(cookie, host)) {
if (cookie.name == args.name) {
cookieMgr.remove(cookie.host, cookie.name, cookie.path,
cookie.originAttributes, false);
@@ -263,17 +260,18 @@ exports.items = [
]
}
],
exec: function(args, context) {
if (context.environment.target.isRemote) {
throw new Error("The cookie gcli commands only work in a local tab, " +
"see bug 1221488");
}
- let host = sanitizeHost(context.environment.document.location.host);
+ let host = new URL(context.environment.target.url).host;
+ host = sanitizeHost(host);
let time = Date.parse(args.expires) / 1000;
cookieMgr.add(args.domain ? "." + args.domain : host,
args.path ? args.path : "/",
args.name,
args.value,
args.secure,
args.httpOnly,