Bug 1551301 - Allow WebExtensions to clear IndexedDB by hostname. r=rpl
authorTom Schuster <evilpies@gmail.com>
Tue, 28 Apr 2020 13:30:09 +0000
changeset 526477 d922e7e833ba6414aa6936f826ba3a44e66c7219
parent 526476 65bec75f5f10ed54f3804f389c0e1edde5f063c2
child 526478 b74a1462f47a2086ce1a88dd910ce70a774cfb2d
push id114286
push userevilpies@gmail.com
push dateTue, 28 Apr 2020 13:52:49 +0000
treeherderautoland@b74a1462f47a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrpl
bugs1551301
milestone77.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 1551301 - Allow WebExtensions to clear IndexedDB by hostname. r=rpl Differential Revision: https://phabricator.services.mozilla.com/D72450
browser/components/extensions/parent/ext-browsingData.js
browser/components/extensions/test/browser/browser_ext_browsingData_indexedDB.js
--- a/browser/components/extensions/parent/ext-browsingData.js
+++ b/browser/components/extensions/parent/ext-browsingData.js
@@ -103,32 +103,35 @@ const clearIndexedDB = async function(op
         let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin(
           item.origin
         );
         if (
           principal.schemeIs("http") ||
           principal.schemeIs("https") ||
           principal.schemeIs("file")
         ) {
-          promises.push(
-            new Promise((resolve, reject) => {
-              let clearRequest = quotaManagerService.clearStoragesForPrincipal(
-                principal,
-                null,
-                "idb"
-              );
-              clearRequest.callback = () => {
-                if (clearRequest.resultCode == Cr.NS_OK) {
-                  resolve();
-                } else {
-                  reject({ message: "Clear indexedDB failed" });
-                }
-              };
-            })
-          );
+          let host = principal.URI.hostPort;
+          if (!options.hostnames || options.hostnames.includes(host)) {
+            promises.push(
+              new Promise((resolve, reject) => {
+                let clearRequest = quotaManagerService.clearStoragesForPrincipal(
+                  principal,
+                  null,
+                  "idb"
+                );
+                clearRequest.callback = () => {
+                  if (clearRequest.resultCode == Cr.NS_OK) {
+                    resolve();
+                  } else {
+                    reject({ message: "Clear indexedDB failed" });
+                  }
+                };
+              })
+            );
+          }
         }
       }
 
       resolve();
     });
   });
 
   return Promise.all(promises);
--- a/browser/components/extensions/test/browser/browser_ext_browsingData_indexedDB.js
+++ b/browser/components/extensions/test/browser/browser_ext_browsingData_indexedDB.js
@@ -4,17 +4,20 @@
 "use strict";
 
 add_task(async function testIndexedDB() {
   function background() {
     const PAGE =
       "/browser/browser/components/extensions/test/browser/file_indexedDB.html";
 
     browser.test.onMessage.addListener(async msg => {
-      await browser.browsingData.remove({}, { indexedDB: true });
+      await browser.browsingData.remove(
+        { hostnames: msg.hostnames },
+        { indexedDB: true }
+      );
       browser.test.sendMessage("indexedDBRemoved");
     });
 
     // Create two tabs.
     browser.tabs.create({ url: `http://mochi.test:8888${PAGE}` });
     browser.tabs.create({ url: `http://example.com${PAGE}` });
   }
 
@@ -74,18 +77,27 @@ add_task(async function testIndexedDB() 
         resolve(origins);
       });
     });
   }
 
   let origins = await getOrigins();
   is(origins.length, 2, "IndexedDB databases have been populated.");
 
-  extension.sendMessage();
-
+  extension.sendMessage({ hostnames: ["example.com"] });
   await extension.awaitMessage("indexedDBRemoved");
 
   origins = await getOrigins();
-  is(origins.length, 0, "IndexedDB data has been removed.");
+  is(origins.length, 1, "IndexedDB data only for only one domain left");
+  ok(
+    origins[0].startsWith("http://mochi.test"),
+    "IndexedDB data for 'example.com' has been removed."
+  );
+
+  extension.sendMessage({});
+  await extension.awaitMessage("indexedDBRemoved");
+
+  origins = await getOrigins();
+  is(origins.length, 0, "All IndexedDB data has been removed.");
 
   await extension.unload();
   await BrowserTestUtils.closeWindow(win);
 });