Bug 1238183 - Part 1 - Make the ForgetAboutSite handles userContextId correctly. r=jimm, r=sicking
☠☠ backed out by bd4f86754707 ☠ ☠
authorTim Huang <tihuang@mozilla.com>
Mon, 20 Jun 2016 20:20:00 +0200
changeset 303506 663a083774f4fe879fc4270774205cdde074918a
parent 303505 ebd38bf78b58dd2e2af45a2265d958721a3ae345
child 303507 1207df32d737779bfd78f6c4f374ca6dbaf2685e
push id79110
push usercbook@mozilla.com
push dateMon, 04 Jul 2016 14:21:35 +0000
treeherdermozilla-inbound@066be6391756 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, sicking
bugs1238183
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1238183 - Part 1 - Make the ForgetAboutSite handles userContextId correctly. r=jimm, r=sicking
toolkit/forgetaboutsite/ForgetAboutSite.jsm
--- a/toolkit/forgetaboutsite/ForgetAboutSite.jsm
+++ b/toolkit/forgetaboutsite/ForgetAboutSite.jsm
@@ -7,16 +7,18 @@
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/NetUtil.jsm");
 Components.utils.import("resource://gre/modules/Task.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
                                   "resource://gre/modules/PlacesUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Downloads",
                                   "resource://gre/modules/Downloads.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "ContextualIdentityService",
+                                  "resource:///modules/ContextualIdentityService.jsm");
 
 this.EXPORTED_SYMBOLS = ["ForgetAboutSite"];
 
 /**
  * Returns true if the string passed in is part of the root domain of the
  * current string.  For example, if this is "www.mozilla.org", and we pass in
  * "mozilla.org", this will return true.  It would return false the other way
  * around.
@@ -42,16 +44,24 @@ function hasRootDomain(str, aDomain)
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 this.ForgetAboutSite = {
   removeDataFromDomain: function CRH_removeDataFromDomain(aDomain)
   {
+    // Get all userContextId from the ContextualIdentityService and create
+    // all originAttributes.
+    let oaList = [ {} ]; // init the list with the default originAttributes.
+
+    for (let identity of ContextualIdentityService.getIdentities()) {
+      oaList.push({ userContextId: identity.userContextId});
+    }
+
     PlacesUtils.history.removePagesFromHost(aDomain, true);
 
     // Cache
     let cs = Cc["@mozilla.org/netwerk/cache-storage-service;1"].
              getService(Ci.nsICacheStorageService);
     // NOTE: there is no way to clear just that domain, so we clear out
     //       everything)
     try {
@@ -69,20 +79,23 @@ this.ForgetAboutSite = {
     } catch (ex) {
       Cu.reportError("Exception thrown while clearing the image cache: " +
         ex.toString());
     }
 
     // Cookies
     let cm = Cc["@mozilla.org/cookiemanager;1"].
              getService(Ci.nsICookieManager2);
-    let enumerator = cm.getCookiesFromHost(aDomain, {});
-    while (enumerator.hasMoreElements()) {
-      let cookie = enumerator.getNext().QueryInterface(Ci.nsICookie);
-      cm.remove(cookie.host, cookie.name, cookie.path, false, cookie.originAttributes);
+    let enumerator;
+    for (let originAttributes of oaList) {
+      enumerator = cm.getCookiesFromHost(aDomain, originAttributes);
+      while (enumerator.hasMoreElements()) {
+        let cookie = enumerator.getNext().QueryInterface(Ci.nsICookie);
+        cm.remove(cookie.host, cookie.name, cookie.path, false, cookie.originAttributes);
+      }
     }
 
     // EME
     let mps = Cc["@mozilla.org/gecko-media-plugin-service;1"].
                getService(Ci.mozIGeckoMediaPluginChromeService);
     mps.forgetThisSite(aDomain);
 
     // Plugin data
@@ -159,20 +172,24 @@ this.ForgetAboutSite = {
     // delete data from both HTTP and HTTPS sites
     let caUtils = {};
     let scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                        getService(Ci.mozIJSSubScriptLoader);
     scriptLoader.loadSubScript("chrome://global/content/contentAreaUtils.js",
                                caUtils);
     let httpURI = caUtils.makeURI("http://" + aDomain);
     let httpsURI = caUtils.makeURI("https://" + aDomain);
-    let httpPrincipal = Services.scriptSecurityManager.createCodebasePrincipal(httpURI, {});
-    let httpsPrincipal = Services.scriptSecurityManager.createCodebasePrincipal(httpsURI, {});
-    qms.clearStoragesForPrincipal(httpPrincipal);
-    qms.clearStoragesForPrincipal(httpsPrincipal);
+    for (let originAttributes of oaList) {
+      let httpPrincipal = Services.scriptSecurityManager
+                                  .createCodebasePrincipal(httpURI, originAttributes);
+      let httpsPrincipal = Services.scriptSecurityManager
+                                   .createCodebasePrincipal(httpsURI, originAttributes);
+      qms.clearStoragesForPrincipal(httpPrincipal);
+      qms.clearStoragesForPrincipal(httpsPrincipal);
+    }
 
     function onContentPrefsRemovalFinished() {
       // Everybody else (including extensions)
       Services.obs.notifyObservers(null, "browser:purge-domain-data", aDomain);
     }
 
     // Content Preferences
     let cps2 = Cc["@mozilla.org/content-pref/service;1"].