Bug 1422365 - Introduce nsIClearDataService - part 10 - push notification, r=johannh
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 01 Jun 2018 14:30:01 +0200
changeset 420844 876254607268d4f9ff9f3269b143d828a1279d75
parent 420843 470c748aeffea5535d2148c1cad67a5ca448db1b
child 420845 59a46331ca79bc5851fc38c98a7429717fbec69f
push id103898
push useramarchesini@mozilla.com
push dateFri, 01 Jun 2018 12:31:55 +0000
treeherdermozilla-inbound@ee1e13b50338 [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 10 - push notification, r=johannh
browser/modules/Sanitizer.jsm
toolkit/components/cleardata/ClearDataService.js
toolkit/components/cleardata/nsIClearDataService.idl
toolkit/forgetaboutsite/ForgetAboutSite.jsm
--- a/browser/modules/Sanitizer.jsm
+++ b/browser/modules/Sanitizer.jsm
@@ -500,32 +500,17 @@ var Sanitizer = {
           let sss = Cc["@mozilla.org/ssservice;1"]
                       .getService(Ci.nsISiteSecurityService);
           sss.clearAll();
         } catch (ex) {
           seenException = ex;
         }
 
         // Clear all push notification subscriptions
-        try {
-          await new Promise((resolve, reject) => {
-            let push = Cc["@mozilla.org/push/Service;1"]
-                         .getService(Ci.nsIPushService);
-            push.clearForDomain("*", status => {
-              if (Components.isSuccessCode(status)) {
-                resolve();
-              } else {
-                reject(new Error("Error clearing push subscriptions: " +
-                                 status));
-              }
-            });
-          });
-        } catch (ex) {
-          seenException = ex;
-        }
+        await clearData(range, Ci.nsIClearDataService.CLEAR_DOM_PUSH_NOTIFICATIONS);
 
         TelemetryStopwatch.finish("FX_SANITIZE_SITESETTINGS", refObj);
         if (seenException) {
           throw seenException;
         }
       }
     },
 
--- a/toolkit/components/cleardata/ClearDataService.js
+++ b/toolkit/components/cleardata/ClearDataService.js
@@ -394,16 +394,46 @@ const PredictorNetworkCleaner = {
     // domain, so just trash it all
     let np = Cc["@mozilla.org/network/predictor;1"].
              getService(Ci.nsINetworkPredictor);
     np.reset();
     return Promise.resolve();
   },
 };
 
+const PushNotificationsCleaner = {
+  deleteByHost(aHost, aOriginAttributes) {
+    return new Promise((aResolve, aReject) => {
+      let push = Cc["@mozilla.org/push/Service;1"]
+                   .getService(Ci.nsIPushService);
+      push.clearForDomain(aHost, aStatus => {
+        if (!Components.isSuccessCode(aStatus)) {
+          aReject();
+        } else {
+          aResolve();
+        }
+      });
+    });
+  },
+
+  deleteAll() {
+    return new Promise((aResolve, aReject) => {
+      let push = Cc["@mozilla.org/push/Service;1"]
+                   .getService(Ci.nsIPushService);
+      push.clearForDomain("*", aStatus => {
+        if (!Components.isSuccessCode(aStatus)) {
+          aReject();
+        } else {
+          aResolve();
+        }
+      });
+    });
+  },
+};
+
 // Here the map of Flags-Cleaner.
 const FLAGS_MAP = [
  { flag: Ci.nsIClearDataService.CLEAR_COOKIES,
    cleaner: CookieCleaner },
 
  { flag: Ci.nsIClearDataService.CLEAR_NETWORK_CACHE,
    cleaner: NetworkCacheCleaner },
 
@@ -425,16 +455,19 @@ const FLAGS_MAP = [
  { flag: Ci.nsIClearDataService.CLEAR_APPCACHE,
    cleaner: AppCacheCleaner, },
 
  { flag: Ci.nsIClearDataService.CLEAR_DOM_QUOTA,
    cleaner: QuotaCleaner, },
 
  { flag: Ci.nsIClearDataService.CLEAR_PREDICTOR_NETWORK_DATA,
    cleaner: PredictorNetworkCleaner, },
+
+ { flag: Ci.nsIClearDataService.CLEAR_DOM_PUSH_NOTIFICATIONS,
+   cleaner: PushNotificationsCleaner, },
 ];
 
 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
@@ -128,21 +128,25 @@ interface nsIClearDataService : nsISuppo
    */
   const uint32_t CLEAR_DOM_QUOTA = 1 << 8;
 
   /**
    * Predictor network data
    */
   const uint32_t CLEAR_PREDICTOR_NETWORK_DATA = 1 << 9;
 
+  /**
+   * DOM Push notifications
+   */
+  const uint32_t CLEAR_DOM_PUSH_NOTIFICATIONS = 1 << 10;
+
   /* TODO
   const uint32_t CLEAR_EME = 1 << 4;
   const uint32_t CLEAR_PERMISSIONS = 1 << 7;
   const uint32_t CLEAR_CONTENT_PREFERENCES = 1 << 9;
-  const uint32_t CLEAR_DOM_PUSH_NOTIFICATIONS = 1 << 11;
   const uint32_t CLEAR_HSTS = 1 << 12;
   const uint32_t CLEAR_HPKP = 1 << 13;
   const uint32_t CLEAR_HISTORY = 1 << 14;
   const uint32_t CLEAR_SESSION_HISTORY = 1 << 15;
   const uint32_t CLEAR_FORMDATA = 1 << 16;
   const uint32_t CLEAR_AUTH_TOKENS = 1 << 17;
   const uint32_t CLEAR_LOGINS = 1 << 18;
   */
@@ -160,19 +164,19 @@ interface nsIClearDataService : nsISuppo
   /**
    * Delete all the possible caches.
    * TODO: add CLEAR_PREDICTOR_CACHE ?
    */
   const uint32_t CLEAR_ALL_CACHES = CLEAR_NETWORK_CACHE | CLEAR_IMAGE_CACHE;
 
   /**
    * Delete all DOM storages
-   * TODO: add CLEAR_DOM_PUSH_NOTIFICATIONS | CLEAR_FORMDATA | CLEAR_SESSION_HISTORY;
+   * TODO: add CLEAR_FORMDATA | CLEAR_SESSION_HISTORY;
    */
-  const uint32_t CLEAR_DOM_STORAGES = CLEAR_APPCACHE | CLEAR_DOM_QUOTA;
+  const uint32_t CLEAR_DOM_STORAGES = CLEAR_APPCACHE | CLEAR_DOM_QUOTA | CLEAR_DOM_PUSH_NOTIFICATIONS;
 
   /*
   const uint32_t CLEAR_BROWSER_DATA = CLEAR_DOWNLOADS | CLEAR_PASSWORDS | CLEAR_PERMISSIONS | CLEAR_CONTENT_PREFERENCES | CLEAR_HISTORY | CLEAR_LOGINS;
   */
 };
 
 /**
  * This is a companion interface for
--- a/toolkit/forgetaboutsite/ForgetAboutSite.jsm
+++ b/toolkit/forgetaboutsite/ForgetAboutSite.jsm
@@ -88,27 +88,16 @@ var ForgetAboutSite = {
           if (reason === cps2.COMPLETE_ERROR) {
             throw new Error("Exception occured while clearing content preferences");
           }
         },
         handleError() {}
       });
     })());
 
-    // Push notifications.
-    promises.push((async function() {
-      var push = Cc["@mozilla.org/push/Service;1"].
-                 getService(Ci.nsIPushService);
-      push.clearForDomain(aDomain, status => {
-        if (!Components.isSuccessCode(status)) {
-          throw new Error("Exception occured while clearing push notifications: " + status);
-        }
-      });
-    })());
-
     // HSTS and HPKP
     promises.push((async function() {
       let sss = Cc["@mozilla.org/ssservice;1"].
                 getService(Ci.nsISiteSecurityService);
       for (let type of [Ci.nsISiteSecurityService.HEADER_HSTS,
                         Ci.nsISiteSecurityService.HEADER_HPKP]) {
         // Also remove HSTS/HPKP information for subdomains by enumerating the
         // information in the site security service.