Bug 1422365 - Introduce nsIClearDataService - part 18 - custom flags for ForgetAboutSite, r=johannh
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 01 Jun 2018 14:31:26 +0200
changeset 420852 ee1e13b5033892b805946ab20b42b7ea0a0b9aea
parent 420851 9fa43598c248709f0a1ef6f5702821c034ef3e94
child 420853 4f9eec6361279d8657ffc4e6ef5c84e8f5d08c56
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 18 - custom flags for ForgetAboutSite, r=johannh
browser/modules/Sanitizer.jsm
toolkit/components/cleardata/nsIClearDataService.idl
toolkit/components/cleardata/tests/unit/test_basic.js
toolkit/components/cleardata/tests/unit/test_cookies.js
toolkit/components/cleardata/tests/unit/test_downloads.js
toolkit/forgetaboutsite/ForgetAboutSite.jsm
--- a/browser/modules/Sanitizer.jsm
+++ b/browser/modules/Sanitizer.jsm
@@ -760,21 +760,19 @@ async function maybeSanitizeSessionPrinc
     }
   }
 
   return Promise.all(promises);
 }
 
 async function sanitizeSessionPrincipal(principal) {
   await new Promise(resolve => {
-    let service = Cc["@mozilla.org/clear-data-service;1"]
-                    .getService(Ci.nsIClearDataService);
-    service.deleteDataFromPrincipal(principal, true /* user request */,
-                                    Ci.nsIClearDataService.CLEAR_DOM_STORAGES,
-                                    resolve);
+    Services.clearData.deleteDataFromPrincipal(principal, true /* user request */,
+                                               Ci.nsIClearDataService.CLEAR_DOM_STORAGES,
+                                               resolve);
   });
 }
 
 function sanitizeNewTabSegregation() {
   let identity = ContextualIdentityService.getPrivateIdentity("userContextIdInternal.thumbnail");
   if (identity) {
     Services.obs.notifyObservers(null, "clear-origin-attributes-data",
                                  JSON.stringify({ userContextId: identity.userContextId }));
--- a/toolkit/components/cleardata/nsIClearDataService.idl
+++ b/toolkit/components/cleardata/nsIClearDataService.idl
@@ -173,40 +173,45 @@ interface nsIClearDataService : nsISuppo
    */
   const uint32_t CLEAR_SECURITY_SETTINGS = 1 << 17;
 
   /**
    * Media plugin data
    */
   const uint32_t CLEAR_EME = 1 << 18;
 
-  /* TODO
-  const uint32_t CLEAR_FORMDATA = 1 << 16;
-  */
-
   /**
    * Use this value to delete all the data.
    */
-  const uint32_t CLEAR_ALL = 0xFFFF;
+  const uint32_t CLEAR_ALL = 0xFFFFFF;
 
   /**************************************************************************
    * The following flags are helpers: they combine some of the previous flags
    * in a more convenient way.
    */
 
   /**
    * 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
    */
   const uint32_t CLEAR_DOM_STORAGES = CLEAR_APPCACHE | CLEAR_DOM_QUOTA | CLEAR_DOM_PUSH_NOTIFICATIONS;
+
+  /**
+   * 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;
 };
 
 /**
  * This is a companion interface for
  * nsIClearDataService::deleteDataFromPrincipal().
  */
 [function, scriptable, uuid(e225517b-24c5-498a-b9fb-9993e341a398)]
 interface nsIClearDataCallback : nsISupports
--- a/toolkit/components/cleardata/tests/unit/test_basic.js
+++ b/toolkit/components/cleardata/tests/unit/test_basic.js
@@ -2,20 +2,20 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Basic test for nsIClearDataService module.
  */
 
 "use strict";
 
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
 add_task(async function test_basic() {
-  const service = Cc["@mozilla.org/clear-data-service;1"]
-                  .getService(Ci.nsIClearDataService);
-  Assert.ok(!!service);
+  Assert.ok(!!Services.clearData);
 
   await new Promise(aResolve => {
-    service.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => {
+    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => {
       Assert.equal(value, 0);
       aResolve();
     });
   });
 });
--- a/toolkit/components/cleardata/tests/unit/test_cookies.js
+++ b/toolkit/components/cleardata/tests/unit/test_cookies.js
@@ -5,100 +5,88 @@
  * Tests for cookies.
  */
 
 "use strict";
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 add_task(async function test_all_cookies() {
-  const service = Cc["@mozilla.org/clear-data-service;1"]
-                    .getService(Ci.nsIClearDataService);
-  Assert.ok(!!service);
-
   const expiry = Date.now() + 24 * 60 * 60;
   Services.cookies.add("example.net", "path", "name", "value", true /* secure */,
                        true /* http only */, false /* session */,
                        expiry, {});
   Assert.equal(Services.cookies.countCookiesFromHost("example.net"), 1);
 
   await new Promise(aResolve => {
-    service.deleteData(Ci.nsIClearDataService.CLEAR_COOKIES, value => {
+    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_COOKIES, value => {
       Assert.equal(value, 0);
       aResolve();
     });
   });
 
   Assert.equal(Services.cookies.countCookiesFromHost("example.net"), 0);
 });
 
 add_task(async function test_range_cookies() {
-  const service = Cc["@mozilla.org/clear-data-service;1"]
-                    .getService(Ci.nsIClearDataService);
-  Assert.ok(!!service);
-
   const expiry = Date.now() + 24 * 60 * 60;
   Services.cookies.add("example.net", "path", "name", "value", true /* secure */,
                        true /* http only */, false /* session */,
                        expiry, {});
   Assert.equal(Services.cookies.countCookiesFromHost("example.net"), 1);
 
   // The cookie is out of time range here.
   let from = Date.now() + 60 * 60;
   await new Promise(aResolve => {
-    service.deleteDataInTimeRange(from * 1000, expiry * 2000, true /* user request */,
-                                  Ci.nsIClearDataService.CLEAR_COOKIES, value => {
+    Services.clearData.deleteDataInTimeRange(from * 1000, expiry * 2000, true /* user request */,
+                                             Ci.nsIClearDataService.CLEAR_COOKIES, value => {
       Assert.equal(value, 0);
       aResolve();
     });
   });
 
   Assert.equal(Services.cookies.countCookiesFromHost("example.net"), 1);
 
   // Now we delete all.
   from = Date.now() - 60 * 60;
   await new Promise(aResolve => {
-    service.deleteDataInTimeRange(from * 1000, expiry * 2000, true /* user request */,
-                                  Ci.nsIClearDataService.CLEAR_COOKIES, value => {
+    Services.clearData.deleteDataInTimeRange(from * 1000, expiry * 2000, true /* user request */,
+                                             Ci.nsIClearDataService.CLEAR_COOKIES, value => {
       Assert.equal(value, 0);
       aResolve();
     });
   });
 
   Assert.equal(Services.cookies.countCookiesFromHost("example.net"), 0);
 });
 
 add_task(async function test_principal_cookies() {
-  const service = Cc["@mozilla.org/clear-data-service;1"]
-                    .getService(Ci.nsIClearDataService);
-  Assert.ok(!!service);
-
   const expiry = Date.now() + 24 * 60 * 60;
   Services.cookies.add("example.net", "path", "name", "value", true /* secure */,
                        true /* http only */, false /* session */,
                        expiry, {});
   Assert.equal(Services.cookies.countCookiesFromHost("example.net"), 1);
 
   let uri = Services.io.newURI("http://example.com");
   let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
   await new Promise(aResolve => {
-    service.deleteDataFromPrincipal(principal, true /* user request */,
-                                    Ci.nsIClearDataService.CLEAR_COOKIES, value => {
+    Services.clearData.deleteDataFromPrincipal(principal, true /* user request */,
+                                               Ci.nsIClearDataService.CLEAR_COOKIES, value => {
       Assert.equal(value, 0);
       aResolve();
     });
   });
 
   Assert.equal(Services.cookies.countCookiesFromHost("example.net"), 1);
 
   // Now we delete all.
   uri = Services.io.newURI("http://example.net");
   principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
   await new Promise(aResolve => {
-    service.deleteDataFromPrincipal(principal, true /* user request */,
-                                    Ci.nsIClearDataService.CLEAR_COOKIES, value => {
+    Services.clearData.deleteDataFromPrincipal(principal, true /* user request */,
+                                               Ci.nsIClearDataService.CLEAR_COOKIES, value => {
       Assert.equal(value, 0);
       aResolve();
     });
   });
 
   Assert.equal(Services.cookies.countCookiesFromHost("example.net"), 0);
 });
--- a/toolkit/components/cleardata/tests/unit/test_downloads.js
+++ b/toolkit/components/cleardata/tests/unit/test_downloads.js
@@ -33,21 +33,16 @@ async function createDownloadList() {
     downloadList = await Downloads.getList(Downloads.ALL);
   }
 
   return downloadList;
 }
 
 add_task(async function test_all_downloads() {
   const url = createFileURL();
-
-  const service = Cc["@mozilla.org/clear-data-service;1"]
-                    .getService(Ci.nsIClearDataService);
-  Assert.ok(!!service);
-
   const list = await createDownloadList();
 
   // First download.
   let download = await Downloads.createDownload({
     source: { url: url.spec, isPrivate: false },
     target: { path: FileTestUtils.getTempFile(TEST_TARGET_FILE_NAME).path },
   });
   Assert.ok(!!download);
@@ -61,48 +56,42 @@ add_task(async function test_all_downloa
   await download.start();
   Assert.ok(!!download);
   list.add(download);
 
   let items = await list.getAll();
   Assert.equal(items.length, 2);
 
   await new Promise(resolve => {
-    service.deleteData(Ci.nsIClearDataService.CLEAR_DOWNLOADS, value => {
+    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_DOWNLOADS, value => {
       Assert.equal(value, 0);
       resolve();
     });
   });
 
   items = await list.getAll();
 
   // We don't remove the active downloads.
   Assert.equal(items.length, 1);
 
   await download.cancel();
 
   await new Promise(resolve => {
-    service.deleteData(Ci.nsIClearDataService.CLEAR_DOWNLOADS, value => {
+    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_DOWNLOADS, value => {
       Assert.equal(value, 0);
       resolve();
     });
   });
 
   items = await list.getAll();
   Assert.equal(items.length, 0);
 });
 
 add_task(async function test_range_downloads() {
   const url = createFileURL();
-
-  const service = Cc["@mozilla.org/clear-data-service;1"]
-                    .getService(Ci.nsIClearDataService);
-
-  Assert.ok(!!service);
-
   const list = await createDownloadList();
 
   let download = await Downloads.createDownload({
     source: { url: url.spec, isPrivate: false },
     target: { path: FileTestUtils.getTempFile(TEST_TARGET_FILE_NAME).path },
   });
   Assert.ok(!!download);
   list.add(download);
@@ -110,35 +99,30 @@ add_task(async function test_range_downl
   // Start + cancel. I need to have a startTime value.
   await download.start();
   await download.cancel();
 
   let items = await list.getAll();
   Assert.equal(items.length, 1);
 
   await new Promise(resolve => {
-    service.deleteDataInTimeRange(download.startTime.getTime() * 1000,
+    Services.clearData.deleteDataInTimeRange(download.startTime.getTime() * 1000,
                                   download.startTime.getTime() * 1000,
                                   true /* user request */,
                                   Ci.nsIClearDataService.CLEAR_DOWNLOADS, value => {
       Assert.equal(value, 0);
       resolve();
     });
   });
 
   items = await list.getAll();
   Assert.equal(items.length, 0);
 });
 
 add_task(async function test_principal_downloads() {
-  const service = Cc["@mozilla.org/clear-data-service;1"]
-                    .getService(Ci.nsIClearDataService);
-
-  Assert.ok(!!service);
-
   const list = await createDownloadList();
 
   let download = await Downloads.createDownload({
     source: { url: "http://example.net", isPrivate: false },
     target: { path: FileTestUtils.getTempFile(TEST_TARGET_FILE_NAME).path },
   });
   Assert.ok(!!download);
   list.add(download);
@@ -152,29 +136,29 @@ add_task(async function test_principal_d
 
   let items = await list.getAll();
   Assert.equal(items.length, 2);
 
   let uri = Services.io.newURI("http://example.com");
   let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
 
   await new Promise(resolve => {
-    service.deleteDataFromPrincipal(principal,
+    Services.clearData.deleteDataFromPrincipal(principal,
                                     true /* user request */,
                                     Ci.nsIClearDataService.CLEAR_DOWNLOADS, value => {
       Assert.equal(value, 0);
       resolve();
     });
   });
 
   items = await list.getAll();
   Assert.equal(items.length, 1);
 
   await new Promise(resolve => {
-    service.deleteData(Ci.nsIClearDataService.CLEAR_DOWNLOADS, value => {
+    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_DOWNLOADS, value => {
       Assert.equal(value, 0);
       resolve();
     });
   });
 
   items = await list.getAll();
   Assert.equal(items.length, 0);
 });
--- a/toolkit/forgetaboutsite/ForgetAboutSite.jsm
+++ b/toolkit/forgetaboutsite/ForgetAboutSite.jsm
@@ -13,17 +13,17 @@ 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,
+                                              Ci.nsIClearDataService.CLEAR_FORGET_ABOUT_SITE,
                                               value => {
           errorCount += bitCounting(value);
           resolve();
         });
       }));
     });
 
     await Promise.all(promises);