Bug 1492908 [wpt PR 13122] - Update wpt metadata, a=testonly
[gecko.git] / toolkit / forgetaboutsite / ForgetAboutSite.jsm
blobff9e3741fa8cffad83a18b040067abc2a8e3942b
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 ChromeUtils.import("resource://gre/modules/Services.jsm");
9 var EXPORTED_SYMBOLS = ["ForgetAboutSite"];
11 var ForgetAboutSite = {
12   async removeDataFromDomain(aDomain) {
13     let promises = [];
14     let errorCount = 0;
16     ["http://", "https://"].forEach(scheme => {
17       promises.push(new Promise(resolve => {
18         Services.clearData.deleteDataFromHost(aDomain, true /* user request */,
19                                               Ci.nsIClearDataService.CLEAR_FORGET_ABOUT_SITE,
20                                               value => {
21           errorCount += bitCounting(value);
22           resolve();
23         });
24       }));
25     });
27     await Promise.all(promises);
29     if (errorCount !== 0) {
30       throw new Error(`There were a total of ${errorCount} errors during removal`);
31     }
32   },
35 function bitCounting(value) {
36   // To know more about how to count bits set to 1 in a numeric value, see this
37   // interesting article:
38   // https://blogs.msdn.microsoft.com/jeuge/2005/06/08/bit-fiddling-3/
39   const count = value - ((value >> 1) & 0o33333333333) - ((value >> 2) & 0o11111111111);
40   return ((count + (count >> 3)) & 0o30707070707) % 63;