Verified Commit b53567eb authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃
Browse files

fixup! Bug 40926: Implemented the New Identity feature

Bug 41711: Wait for the new window when doing new identity
parent 622db29f
Loading
Loading
Loading
Loading
+14 −9
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ XPCOMUtils.defineLazyGetter(this, "NewIdentityButton", () => {
    );
    const consoleOptions = {
      maxLogLevel: "info",
      maxLogLevelPref: "browser.new_identity.log_level",
      prefix: "NewIdentity",
    };
    return new ConsoleAPI(consoleOptions);
@@ -68,12 +69,11 @@ XPCOMUtils.defineLazyGetter(this, "NewIdentityButton", () => {

  class NewIdentityImpl {
    async run() {
      logger.debug("Disabling JS");
      this.disableAllJS();
      await this.clearState();
      this.broadcast();
      this.openNewWindow();
      await this.openNewWindow();
      this.closeOldWindow();
      this.broadcast();
    }

    // Disable JS (as a defense-in-depth measure)
@@ -389,7 +389,7 @@ XPCOMUtils.defineLazyGetter(this, "NewIdentityButton", () => {
      logger.info("Calling the clearDataService");
      const flags =
        Services.clearData.CLEAR_ALL ^ Services.clearData.CLEAR_PASSWORDS;
      return new Promise((resolve, reject) => {
      return new Promise(resolve => {
        Services.clearData.deleteData(flags, {
          onDataDeleted(code) {
            if (code !== Cr.NS_OK) {
@@ -425,11 +425,16 @@ XPCOMUtils.defineLazyGetter(this, "NewIdentityButton", () => {

    openNewWindow() {
      logger.info("Opening a new window");
      return new Promise(resolve => {
        // Open a new window with the default homepage
        // We could pass {private: true} but we do not because we enforce
        // browser.privatebrowsing.autostart = true.
        // What about users that change settings?
      OpenBrowserWindow();
        const win = OpenBrowserWindow();
        // This mechanism to know when the new window is ready is used by
        // OpenBrowserWindow itself (see its definition in browser.js).
        win.addEventListener("MozAfterPaint", () => resolve(), { once: true });
      });
    }

    closeOldWindow() {