tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PromptCollection.sys.mjs (1428B)


      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/. */
      4 
      5 import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
      6 
      7 const lazy = {};
      8 
      9 ChromeUtils.defineESModuleGetters(lazy, {
     10  GeckoViewPrompter: "resource://gre/modules/GeckoViewPrompter.sys.mjs",
     11 });
     12 
     13 const { debug, warn } = GeckoViewUtils.initLogging("PromptCollection");
     14 
     15 export class PromptCollection {
     16  confirmRepost(browsingContext) {
     17    const msg = {
     18      type: "repost",
     19    };
     20    const prompter = new lazy.GeckoViewPrompter(browsingContext);
     21    const result = prompter.showPrompt(msg);
     22    return !!result?.allow;
     23  }
     24 
     25  asyncBeforeUnloadCheck(browsingContext) {
     26    return new Promise(resolve => {
     27      const msg = {
     28        type: "beforeUnload",
     29      };
     30      const prompter = new lazy.GeckoViewPrompter(browsingContext);
     31      prompter.asyncShowPrompt(msg, resolve);
     32    }).then(result => !!result?.allow);
     33  }
     34 
     35  confirmFolderUpload(browsingContext, directoryName) {
     36    const msg = {
     37      type: "folderUpload",
     38      directoryName,
     39    };
     40    const prompter = new lazy.GeckoViewPrompter(browsingContext);
     41    const result = prompter.showPrompt(msg);
     42    return !!result?.allow;
     43  }
     44 }
     45 
     46 PromptCollection.prototype.QueryInterface = ChromeUtils.generateQI([
     47  "nsIPromptCollection",
     48 ]);