[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [Git][tpo/applications/mullvad-browser][mullvad-browser-115.9.1esr-13.0-1] 2 commits: fixup! Bug 40926: Implemented the New Identity feature



Title: GitLab

ma1 pushed to branch mullvad-browser-115.9.1esr-13.0-1 at The Tor Project / Applications / Mullvad Browser

Commits:

  • 1d90ed3d
    by hackademix at 2024-04-08T13:31:55+02:00
    fixup! Bug 40926: Implemented the New Identity feature
    
    Bug 42236: Let users decide whether to load their home page on new identity.
    
  • 8e7cdd60
    by hackademix at 2024-04-08T13:31:56+02:00
    fixup! Bug 40926: Implemented the New Identity feature
    
    MB 283: Make new identity homepage check brand-agnostic.
    

2 changed files:

Changes:

  • browser/components/newidentity/content/newidentity.js
    ... ... @@ -10,37 +10,28 @@ XPCOMUtils.defineLazyGetter(this, "NewIdentityStrings", () => {
    10 10
       );
    
    11 11
       const brandShortName = brandBundle.GetStringFromName("brandShortName");
    
    12 12
     
    
    13
    -  let strings = {
    
    14
    -    new_identity: "New Identity",
    
    15
    -    new_identity_sentence_case: "New identity",
    
    16
    -    new_identity_prompt_title: "Reset your identity?",
    
    17
    -    new_identity_prompt: `${brandShortName} will close all windows and tabs. All website sessions will be lost. \nRestart ${brandShortName} now to reset your identity?`,
    
    18
    -    new_identity_restart: `Restart ${brandShortName}`,
    
    19
    -    new_identity_ask_again: "Never ask me again",
    
    20
    -    new_identity_menu_accesskey: "I",
    
    21
    -  };
    
    22
    -  let bundle = null;
    
    13
    +  const fallbackBundle = Services.strings.createBundle(
    
    14
    +    "resource:///chrome/en-US/locale/browser/newIdentity.properties"
    
    15
    +  );
    
    16
    +  const strings = {};
    
    17
    +  const brandedStrings = ["new_identity_prompt", "new_identity_restart"];
    
    18
    +  for (let { key } of fallbackBundle.getSimpleEnumeration()) {
    
    19
    +    strings[key] = fallbackBundle.GetStringFromName(key);
    
    20
    +  }
    
    23 21
       try {
    
    24
    -    bundle = Services.strings.createBundle(
    
    22
    +    const bundle = Services.strings.createBundle(
    
    25 23
           "chrome://browser/locale/newIdentity.properties"
    
    26 24
         );
    
    27
    -  } catch (e) {
    
    28
    -    console.warn("Could not load the New Identity strings");
    
    29
    -  }
    
    30
    -  if (bundle) {
    
    31 25
         for (const key of Object.keys(strings)) {
    
    32 26
           try {
    
    33 27
             strings[key] = bundle.GetStringFromName(key);
    
    34 28
           } catch (e) {}
    
    35 29
         }
    
    36
    -    strings.new_identity_prompt = strings.new_identity_prompt.replaceAll(
    
    37
    -      "%S",
    
    38
    -      brandShortName
    
    39
    -    );
    
    40
    -    strings.new_identity_restart = strings.new_identity_restart.replaceAll(
    
    41
    -      "%S",
    
    42
    -      brandShortName
    
    43
    -    );
    
    30
    +  } catch (e) {
    
    31
    +    console.warn("Could not load localized New Identity strings");
    
    32
    +  }
    
    33
    +  for (let key of brandedStrings) {
    
    34
    +    strings[key] = strings[key].replaceAll("%S", brandShortName);
    
    44 35
       }
    
    45 36
       return strings;
    
    46 37
     });
    
    ... ... @@ -437,10 +428,79 @@ XPCOMUtils.defineLazyGetter(this, "NewIdentityButton", () => {
    437 428
           logger.info("Opening a new window");
    
    438 429
           return new Promise(resolve => {
    
    439 430
             // Open a new window forcing the about:privatebrowsing page (tor-browser#41765)
    
    440
    -        const win = OpenBrowserWindow({private: "no-home"});
    
    431
    +        // unless user explicitly overrides this policy (tor-browser #42236)
    
    432
    +        const homePref = "browser.startup.homepage";
    
    433
    +        const trustedHomePref = "browser.startup.homepage.new_identity";
    
    434
    +        const homeURL = Services.prefs.getStringPref(homePref, "");
    
    435
    +        const defaultHomeURL = Services.prefs
    
    436
    +          .getDefaultBranch("")
    
    437
    +          .getStringPref(homePref, "");
    
    438
    +        const isTrustedHome =
    
    439
    +          homeURL === defaultHomeURL ||
    
    440
    +          homeURL.startsWith("chrome://") || // about:blank and other built-ins
    
    441
    +          homeURL === Services.prefs.getStringPref(trustedHomePref, "");
    
    442
    +        const isCustomHome =
    
    443
    +          Services.prefs.getIntPref("browser.startup.page") === 1;
    
    444
    +        const win = OpenBrowserWindow({
    
    445
    +          private: isCustomHome && isTrustedHome ? "private" : "no-home",
    
    446
    +        });
    
    441 447
             // This mechanism to know when the new window is ready is used by
    
    442 448
             // OpenBrowserWindow itself (see its definition in browser.js).
    
    443
    -        win.addEventListener("MozAfterPaint", () => resolve(), { once: true });
    
    449
    +        win.addEventListener(
    
    450
    +          "MozAfterPaint",
    
    451
    +          () => {
    
    452
    +            resolve();
    
    453
    +            if (isTrustedHome || !isCustomHome) {
    
    454
    +              return;
    
    455
    +            }
    
    456
    +            const tbl = win.TabsProgressListener;
    
    457
    +            const { onLocationChange } = tbl;
    
    458
    +            tbl.onLocationChange = (...args) => {
    
    459
    +              tbl.onLocationChange = onLocationChange;
    
    460
    +              tbl.onLocationChange(...args);
    
    461
    +              let displayAddress;
    
    462
    +              try {
    
    463
    +                const url = new URL(homeURL);
    
    464
    +                displayAddress = url.hostname;
    
    465
    +                if (!displayAddress) {
    
    466
    +                  // no host, use full address and truncate if too long
    
    467
    +                  const MAX_LEN = 32;
    
    468
    +                  displayAddress = url.href;
    
    469
    +                  if (displayAddress.length > MAX_LEN) {
    
    470
    +                    displayAddress = `${displayAddress.substring(0, MAX_LEN)}…`;
    
    471
    +                  }
    
    472
    +                }
    
    473
    +              } catch (e) {
    
    474
    +                // malformed URL, bail out
    
    475
    +                return;
    
    476
    +              }
    
    477
    +              const label =
    
    478
    +                NewIdentityStrings.new_identity_home_notification.replace(
    
    479
    +                  "%S",
    
    480
    +                  displayAddress
    
    481
    +                );
    
    482
    +              const callback = () => {
    
    483
    +                Services.prefs.setStringPref(trustedHomePref, homeURL);
    
    484
    +                win.BrowserHome();
    
    485
    +              };
    
    486
    +              const notificationBox = win.gBrowser.getNotificationBox();
    
    487
    +              notificationBox.appendNotification(
    
    488
    +                "new-identity-safe-home",
    
    489
    +                {
    
    490
    +                  label,
    
    491
    +                  priority: notificationBox.PRIORITY_INFO_MEDIUM,
    
    492
    +                },
    
    493
    +                [
    
    494
    +                  {
    
    495
    +                    label: NewIdentityStrings.new_identity_home_load_button,
    
    496
    +                    callback,
    
    497
    +                  },
    
    498
    +                ]
    
    499
    +              );
    
    500
    +            };
    
    501
    +          },
    
    502
    +          { once: true }
    
    503
    +        );
    
    444 504
           });
    
    445 505
         }
    
    446 506
     
    

  • browser/locales/en-US/chrome/browser/newIdentity.properties
    ... ... @@ -8,3 +8,6 @@ new_identity_restart = Restart %S
    8 8
     new_identity_ask_again = Never ask me again
    
    9 9
     # Shown in the File menu (use Alt to show File, if you do not see)
    
    10 10
     new_identity_menu_accesskey = I
    
    11
    +new_identity_home_notification = Tor Browser blocked your homepage (%S) from loading because it might recognize your previous session.
    
    12
    +# %S is replaced with the custom homepage URL's domain if applicable, or some short-hand of it otherwise
    
    13
    +new_identity_home_load_button  = Load it anyway

  • _______________________________________________
    tor-commits mailing list
    tor-commits@xxxxxxxxxxxxxxxxxxxx
    https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits