Bug 1249934 - Avoid CPOWs in GCLI cookie commands. r=jwalker a=ritu
authorJ. Ryan Stinnett <jryans@gmail.com>
Wed, 23 Mar 2016 11:07:24 -0500
changeset 310327 b193dbe56f113d71f5bf44724615f536809ce0c0
parent 310326 9cf1d97ed35bf8494c47dc03b05dc9ef67e4fd68
child 310328 c310d32547b3165c09d21d49cf8c4b76c55aa77f
push id9326
push userkwierso@gmail.com
push dateMon, 28 Mar 2016 23:12:08 +0000
treeherdermozilla-aurora@f0bcd999646e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalker, ritu
bugs1249934
milestone47.0a2
Bug 1249934 - Avoid CPOWs in GCLI cookie commands. r=jwalker a=ritu MozReview-Commit-ID: 3a1PoMDbUYW
devtools/shared/gcli/commands/cookie.js
--- 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,