Bug 1515277 - Separate ClearData flag for Reporting data, r=jkt, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 11 Jan 2019 09:43:58 +0100
changeset 510513 58fad84cc31ae44e802e742ad9f4eac5bb4284bc
parent 510512 baf99d3bdfea3cfb5bed7a6072ca713ecee67066
child 510514 f7ecf49bb4c0b11031475afa4f3b82c47828b2e7
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjkt, smaug
bugs1515277
milestone66.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 1515277 - Separate ClearData flag for Reporting data, r=jkt, r=smaug
dom/reporting/ReportingHeader.cpp
dom/reporting/tests/browser_cleanup.js
toolkit/components/cleardata/ClearDataService.js
toolkit/components/cleardata/nsIClearDataService.idl
--- a/dom/reporting/ReportingHeader.cpp
+++ b/dom/reporting/ReportingHeader.cpp
@@ -20,16 +20,19 @@
 #include "nsIHttpProtocolHandler.h"
 #include "nsIObserverService.h"
 #include "nsIPrincipal.h"
 #include "nsIRandomGenerator.h"
 #include "nsIScriptError.h"
 #include "nsNetUtil.h"
 #include "nsXULAppAPI.h"
 
+#define REPORTING_PURGE_ALL "reporting:purge-all"
+#define REPORTING_PURGE_HOST "reporting:purge-host"
+
 namespace mozilla {
 namespace dom {
 
 namespace {
 
 StaticRefPtr<ReportingHeader> gReporting;
 
 }  // namespace
@@ -46,19 +49,19 @@ StaticRefPtr<ReportingHeader> gReporting
 
   nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
   if (NS_WARN_IF(!obs)) {
     return;
   }
 
   obs->AddObserver(service, NS_HTTP_ON_EXAMINE_RESPONSE_TOPIC, false);
   obs->AddObserver(service, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
-  obs->AddObserver(service, "browser:purge-domain-data", false);
   obs->AddObserver(service, "clear-origin-attributes-data", false);
-  obs->AddObserver(service, "extension:purge-localStorage", false);
+  obs->AddObserver(service, REPORTING_PURGE_HOST, false);
+  obs->AddObserver(service, REPORTING_PURGE_ALL, false);
 
   gReporting = service;
 }
 
 /* static */ void ReportingHeader::Shutdown() {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!gReporting) {
@@ -75,19 +78,19 @@ StaticRefPtr<ReportingHeader> gReporting
 
   nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
   if (NS_WARN_IF(!obs)) {
     return;
   }
 
   obs->RemoveObserver(service, NS_HTTP_ON_EXAMINE_RESPONSE_TOPIC);
   obs->RemoveObserver(service, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
-  obs->RemoveObserver(service, "browser:purge-domain-data");
   obs->RemoveObserver(service, "clear-origin-attributes-data");
-  obs->RemoveObserver(service, "extension:purge-localStorage");
+  obs->RemoveObserver(service, REPORTING_PURGE_HOST);
+  obs->RemoveObserver(service, REPORTING_PURGE_ALL);
 }
 
 ReportingHeader::ReportingHeader() = default;
 ReportingHeader::~ReportingHeader() = default;
 
 NS_IMETHODIMP
 ReportingHeader::Observe(nsISupports* aSubject, const char* aTopic,
                          const char16_t* aData) {
@@ -106,33 +109,33 @@ ReportingHeader::Observe(nsISupports* aS
     if (NS_WARN_IF(!channel)) {
       return NS_OK;
     }
 
     ReportingFromChannel(channel);
     return NS_OK;
   }
 
-  if (!strcmp(aTopic, "browser:purge-domain-data")) {
+  if (!strcmp(aTopic, REPORTING_PURGE_HOST)) {
     RemoveOriginsFromHost(nsDependentString(aData));
     return NS_OK;
   }
 
   if (!strcmp(aTopic, "clear-origin-attributes-data")) {
     OriginAttributesPattern pattern;
     if (!pattern.Init(nsDependentString(aData))) {
       NS_ERROR("Cannot parse origin attributes pattern");
       return NS_ERROR_FAILURE;
     }
 
     RemoveOriginsFromOriginAttributesPattern(pattern);
     return NS_OK;
   }
 
-  if (!strcmp(aTopic, "extension:purge-localStorage")) {
+  if (!strcmp(aTopic, REPORTING_PURGE_ALL)) {
     RemoveOrigins();
     return NS_OK;
   }
 
   return NS_ERROR_FAILURE;
 }
 
 void ReportingHeader::ReportingFromChannel(nsIHttpChannel* aChannel) {
--- a/dom/reporting/tests/browser_cleanup.js
+++ b/dom/reporting/tests/browser_cleanup.js
@@ -62,20 +62,20 @@ add_task(async function() {
   await BrowserTestUtils.browserLoaded(browser);
 
   ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "No data before the test");
 
   await storeReportingHeader(browser);
   ok(ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "We have data");
 
   await new Promise(resolve => {
-    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_DOM_QUOTA, value => resolve());
+    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_REPORTS, value => resolve());
   });
 
-  ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "No data before a quota cleanup");
+  ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "No data before a reports cleanup");
 
   info("Removing the tab");
   BrowserTestUtils.removeTab(tab);
 });
 
 add_task(async function() {
   info("Testing a QuotaManager host cleanup");
 
@@ -86,20 +86,20 @@ add_task(async function() {
   await BrowserTestUtils.browserLoaded(browser);
 
   ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "No data before the test");
 
   await storeReportingHeader(browser);
   ok(ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "We have data");
 
   await new Promise(resolve => {
-    Services.clearData.deleteDataFromHost(TEST_HOST, true, Ci.nsIClearDataService.CLEAR_DOM_QUOTA, value => resolve());
+    Services.clearData.deleteDataFromHost(TEST_HOST, true, Ci.nsIClearDataService.CLEAR_REPORTS, value => resolve());
   });
 
-  ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "No data before a quota cleanup");
+  ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "No data before a reports cleanup");
 
   info("Removing the tab");
   BrowserTestUtils.removeTab(tab);
 });
 
 add_task(async function() {
   info("Testing a 410 endpoint status");
 
--- a/toolkit/components/cleardata/ClearDataService.js
+++ b/toolkit/components/cleardata/ClearDataService.js
@@ -288,18 +288,17 @@ const AppCacheCleaner = {
     return Promise.resolve();
   },
 };
 
 const QuotaCleaner = {
   deleteByPrincipal(aPrincipal) {
     // localStorage: The legacy LocalStorage implementation that will
     // eventually be removed depends on this observer notification to clear by
-    // principal.  Some other subsystems like Reporting headers depend on this
-    // too.
+    // principal.
     Services.obs.notifyObservers(null, "browser:purge-domain-data",
                                  aPrincipal.URI.host);
 
     // ServiceWorkers: they must be removed before cleaning QuotaManager.
     return ServiceWorkerCleanUp.removeFromPrincipal(aPrincipal)
       .then(_ => /* exceptionThrown = */ false, _ => /* exceptionThrown = */ true)
       .then(exceptionThrown => {
         // QuotaManager: In the event of a failure, we call reject to propagate
@@ -417,17 +416,17 @@ const QuotaCleaner = {
 
       promises.push(this.deleteByPrincipal(principal));
     }
 
     return Promise.all(promises);
   },
 
   deleteAll() {
-    // localStorage, Reporting headers, etc.
+    // localStorage
     Services.obs.notifyObservers(null, "extension:purge-localStorage");
 
     // ServiceWorkers
     return ServiceWorkerCleanUp.removeAll()
       .then(_ => /* exceptionThrown = */ false, _ => /* exceptionThrown = */ true)
       .then(exceptionThrown => {
         // QuotaManager: In the event of a failure, we call reject to propagate
         // the error upwards.
@@ -707,16 +706,32 @@ const EMECleaner = {
   },
 
   deleteAll() {
     // Not implemented.
     return Promise.resolve();
   },
 };
 
+const ReportsCleaner = {
+  deleteByHost(aHost, aOriginAttributes) {
+    return new Promise(aResolve => {
+      Services.obs.notifyObservers(null, "reporting:purge-host", aHost);
+      aResolve();
+    });
+  },
+
+  deleteAll() {
+    return new Promise(aResolve => {
+      Services.obs.notifyObservers(null, "reporting:purge-all");
+      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 },
 
@@ -765,16 +780,19 @@ const FLAGS_MAP = [
  { flag: Ci.nsIClearDataService.CLEAR_CONTENT_PREFERENCES,
    cleaner: PreferencesCleaner },
 
  { flag: Ci.nsIClearDataService.CLEAR_SECURITY_SETTINGS,
    cleaner: SecuritySettingsCleaner },
 
  { flag: Ci.nsIClearDataService.CLEAR_EME,
    cleaner: EMECleaner },
+
+ { flag: Ci.nsIClearDataService.CLEAR_REPORTS,
+   cleaner: ReportsCleaner },
 ];
 
 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
@@ -180,16 +180,21 @@ interface nsIClearDataService : nsISuppo
   const uint32_t CLEAR_SECURITY_SETTINGS = 1 << 17;
 
   /**
    * Media plugin data
    */
   const uint32_t CLEAR_EME = 1 << 18;
 
   /**
+   * Reporting API reports.
+   */
+  const uint32_t CLEAR_REPORTS = 1 << 19;
+
+  /**
    * Use this value to delete all the data.
    */
   const uint32_t CLEAR_ALL = 0xFFFFFF;
 
   /**************************************************************************
    * The following flags are helpers: they combine some of the previous flags
    * in a more convenient way.
    */
@@ -197,27 +202,28 @@ interface nsIClearDataService : nsISuppo
   /**
    * Delete all the possible caches.
    */
   const uint32_t CLEAR_ALL_CACHES = CLEAR_NETWORK_CACHE | CLEAR_IMAGE_CACHE;
 
   /**
    * Delete all DOM storages
    */
-  const uint32_t CLEAR_DOM_STORAGES = CLEAR_APPCACHE | CLEAR_DOM_QUOTA | CLEAR_DOM_PUSH_NOTIFICATIONS;
+  const uint32_t CLEAR_DOM_STORAGES = CLEAR_APPCACHE | CLEAR_DOM_QUOTA |
+    CLEAR_DOM_PUSH_NOTIFICATIONS | CLEAR_REPORTS;
 
   /**
    * Helper flag for forget about site
    */
   const uint32_t CLEAR_FORGET_ABOUT_SITE =
     CLEAR_HISTORY | CLEAR_NETWORK_CACHE | CLEAR_IMAGE_CACHE | CLEAR_COOKIES |
     CLEAR_EME | CLEAR_PLUGIN_DATA | CLEAR_DOWNLOADS | CLEAR_PASSWORDS |
     CLEAR_PERMISSIONS | CLEAR_DOM_STORAGES | CLEAR_CONTENT_PREFERENCES |
     CLEAR_PREDICTOR_NETWORK_DATA | CLEAR_DOM_PUSH_NOTIFICATIONS |
-    CLEAR_SECURITY_SETTINGS;
+    CLEAR_SECURITY_SETTINGS | CLEAR_REPORTS;
 };
 
 /**
  * This is a companion interface for
  * nsIClearDataService::deleteDataFromPrincipal().
  */
 [function, scriptable, uuid(e225517b-24c5-498a-b9fb-9993e341a398)]
 interface nsIClearDataCallback : nsISupports