Bug 1422365 - Introduce nsIClearDataService - part 17 - EME data, r=johannh
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 01 Jun 2018 14:31:16 +0200
changeset 420886 9fa43598c248709f0a1ef6f5702821c034ef3e94
parent 420885 3725c0472caac21e8c6d60a6097c55548e9a9ff7
child 420887 ee1e13b5033892b805946ab20b42b7ea0a0b9aea
push id34083
push userapavel@mozilla.com
push dateSat, 02 Jun 2018 23:03:25 +0000
treeherdermozilla-central@1f62ecdf59b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1422365
milestone62.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 1422365 - Introduce nsIClearDataService - part 17 - EME data, r=johannh
toolkit/components/cleardata/ClearDataService.js
toolkit/components/cleardata/nsIClearDataService.idl
toolkit/forgetaboutsite/ForgetAboutSite.jsm
--- a/toolkit/components/cleardata/ClearDataService.js
+++ b/toolkit/components/cleardata/ClearDataService.js
@@ -585,16 +585,32 @@ const SecuritySettingsCleaner = {
       let sss = Cc["@mozilla.org/ssservice;1"]
                     .getService(Ci.nsISiteSecurityService);
       sss.clearAll();
       aResolve();
     });
   },
 };
 
+const EMECleaner = {
+  deleteByHost(aHost, aOriginAttributes) {
+    return new Promise(aResolve => {
+      let mps = Cc["@mozilla.org/gecko-media-plugin-service;1"]
+                  .getService(Ci.mozIGeckoMediaPluginChromeService);
+      mps.forgetThisSite(aHost, JSON.stringify(aOriginAttributes));
+      aResolve();
+    });
+  },
+
+  deleteAll() {
+    // Not implemented.
+    return Promise.resolve();
+  },
+};
+
 // Here the map of Flags-Cleaner.
 const FLAGS_MAP = [
  { flag: Ci.nsIClearDataService.CLEAR_COOKIES,
    cleaner: CookieCleaner },
 
  { flag: Ci.nsIClearDataService.CLEAR_NETWORK_CACHE,
    cleaner: NetworkCacheCleaner },
 
@@ -640,16 +656,19 @@ const FLAGS_MAP = [
  { flag: Ci.nsIClearDataService.CLEAR_PERMISSIONS,
    cleaner: PermissionsCleaner, },
 
  { flag: Ci.nsIClearDataService.CLEAR_CONTENT_PREFERENCES,
    cleaner: PreferencesCleaner, },
 
  { flag: Ci.nsIClearDataService.CLEAR_SECURITY_SETTINGS,
    cleaner: SecuritySettingsCleaner, },
+
+ { flag: Ci.nsIClearDataService.CLEAR_EME,
+   cleaner: EMECleaner, },
 ];
 
 this.ClearDataService = function() {};
 
 ClearDataService.prototype = Object.freeze({
   classID: Components.ID("{0c06583d-7dd8-4293-b1a5-912205f779aa}"),
   QueryInterface: ChromeUtils.generateQI([Ci.nsIClearDataService]),
   _xpcom_factory: XPCOMUtils.generateSingletonFactory(ClearDataService),
--- a/toolkit/components/cleardata/nsIClearDataService.idl
+++ b/toolkit/components/cleardata/nsIClearDataService.idl
@@ -168,18 +168,22 @@ interface nsIClearDataService : nsISuppo
    */
   const uint32_t CLEAR_CONTENT_PREFERENCES = 1 << 16;
 
   /**
    * Secure site settings
    */
   const uint32_t CLEAR_SECURITY_SETTINGS = 1 << 17;
 
+  /**
+   * Media plugin data
+   */
+  const uint32_t CLEAR_EME = 1 << 18;
+
   /* TODO
-  const uint32_t CLEAR_EME = 1 << 4;
   const uint32_t CLEAR_FORMDATA = 1 << 16;
   */
 
   /**
    * Use this value to delete all the data.
    */
   const uint32_t CLEAR_ALL = 0xFFFF;
 
--- a/toolkit/forgetaboutsite/ForgetAboutSite.jsm
+++ b/toolkit/forgetaboutsite/ForgetAboutSite.jsm
@@ -8,39 +8,36 @@ ChromeUtils.import("resource://gre/modul
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 
 var EXPORTED_SYMBOLS = ["ForgetAboutSite"];
 
 var ForgetAboutSite = {
   async removeDataFromDomain(aDomain) {
     let promises = [];
+    let errorCount = 0;
 
     ["http://", "https://"].forEach(scheme => {
       promises.push(new Promise(resolve => {
         Services.clearData.deleteDataFromHost(aDomain, true /* user request */,
                                               Ci.nsIClearDataService.CLEAR_ALL,
-                                              resolve);
+                                              value => {
+          errorCount += bitCounting(value);
+          resolve();
+        });
       }));
     });
 
-    // EME
-    promises.push((async function() {
-      let mps = Cc["@mozilla.org/gecko-media-plugin-service;1"].
-                getService(Ci.mozIGeckoMediaPluginChromeService);
-      mps.forgetThisSite(aDomain, JSON.stringify({}));
-    })().catch(ex => {
-      throw new Error("Exception thrown while clearing Encrypted Media Extensions: " + ex);
-    }));
+    await Promise.all(promises);
 
-    let ErrorCount = 0;
-    for (let promise of promises) {
-      try {
-        await promise;
-      } catch (ex) {
-        Cu.reportError(ex);
-        ErrorCount++;
-      }
+    if (errorCount !== 0) {
+      throw new Error(`There were a total of ${errorCount} errors during removal`);
     }
-    if (ErrorCount !== 0)
-      throw new Error(`There were a total of ${ErrorCount} errors during removal`);
   }
 };
+
+function bitCounting(value) {
+  // To know more about how to count bits set to 1 in a numeric value, see this
+  // interesting article:
+  // https://blogs.msdn.microsoft.com/jeuge/2005/06/08/bit-fiddling-3/
+  const count = value - ((value >> 1) & 0o33333333333) - ((value >> 2) & 0o11111111111);
+  return ((count + (count >> 3)) & 0o30707070707) % 63;
+}