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

ma1 (@ma1) git at gitlab.torproject.org
Mon Apr 8 11:30:02 UTC 2024



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


Commits:
db383978 by hackademix at 2024-04-08T13:29:33+02:00
fixup! Bug 40926: Implemented the New Identity feature

Bug 42236: Let users decide whether to load their home page on new identity.

- - - - -
ed19d5f4 by hackademix at 2024-04-08T13:29:35+02:00
fixup! Bug 40926: Implemented the New Identity feature

MB 283: Make new identity homepage check brand-agnostic.

- - - - -


2 changed files:

- browser/components/newidentity/content/newidentity.js
- browser/locales/en-US/chrome/browser/newIdentity.properties


Changes:

=====================================
browser/components/newidentity/content/newidentity.js
=====================================
@@ -10,37 +10,28 @@ XPCOMUtils.defineLazyGetter(this, "NewIdentityStrings", () => {
   );
   const brandShortName = brandBundle.GetStringFromName("brandShortName");
 
-  let strings = {
-    new_identity: "New Identity",
-    new_identity_sentence_case: "New identity",
-    new_identity_prompt_title: "Reset your identity?",
-    new_identity_prompt: `${brandShortName} will close all windows and tabs. All website sessions will be lost. \nRestart ${brandShortName} now to reset your identity?`,
-    new_identity_restart: `Restart ${brandShortName}`,
-    new_identity_ask_again: "Never ask me again",
-    new_identity_menu_accesskey: "I",
-  };
-  let bundle = null;
+  const fallbackBundle = Services.strings.createBundle(
+    "resource:///chrome/en-US/locale/browser/newIdentity.properties"
+  );
+  const strings = {};
+  const brandedStrings = ["new_identity_prompt", "new_identity_restart"];
+  for (let { key } of fallbackBundle.getSimpleEnumeration()) {
+    strings[key] = fallbackBundle.GetStringFromName(key);
+  }
   try {
-    bundle = Services.strings.createBundle(
+    const bundle = Services.strings.createBundle(
       "chrome://browser/locale/newIdentity.properties"
     );
-  } catch (e) {
-    console.warn("Could not load the New Identity strings");
-  }
-  if (bundle) {
     for (const key of Object.keys(strings)) {
       try {
         strings[key] = bundle.GetStringFromName(key);
       } catch (e) {}
     }
-    strings.new_identity_prompt = strings.new_identity_prompt.replaceAll(
-      "%S",
-      brandShortName
-    );
-    strings.new_identity_restart = strings.new_identity_restart.replaceAll(
-      "%S",
-      brandShortName
-    );
+  } catch (e) {
+    console.warn("Could not load localized New Identity strings");
+  }
+  for (let key of brandedStrings) {
+    strings[key] = strings[key].replaceAll("%S", brandShortName);
   }
   return strings;
 });
@@ -437,10 +428,79 @@ XPCOMUtils.defineLazyGetter(this, "NewIdentityButton", () => {
       logger.info("Opening a new window");
       return new Promise(resolve => {
         // Open a new window forcing the about:privatebrowsing page (tor-browser#41765)
-        const win = OpenBrowserWindow({private: "no-home"});
+        // unless user explicitly overrides this policy (tor-browser #42236)
+        const homePref = "browser.startup.homepage";
+        const trustedHomePref = "browser.startup.homepage.new_identity";
+        const homeURL = Services.prefs.getStringPref(homePref, "");
+        const defaultHomeURL = Services.prefs
+          .getDefaultBranch("")
+          .getStringPref(homePref, "");
+        const isTrustedHome =
+          homeURL === defaultHomeURL ||
+          homeURL.startsWith("chrome://") || // about:blank and other built-ins
+          homeURL === Services.prefs.getStringPref(trustedHomePref, "");
+        const isCustomHome =
+          Services.prefs.getIntPref("browser.startup.page") === 1;
+        const win = OpenBrowserWindow({
+          private: isCustomHome && isTrustedHome ? "private" : "no-home",
+        });
         // 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 });
+        win.addEventListener(
+          "MozAfterPaint",
+          () => {
+            resolve();
+            if (isTrustedHome || !isCustomHome) {
+              return;
+            }
+            const tbl = win.TabsProgressListener;
+            const { onLocationChange } = tbl;
+            tbl.onLocationChange = (...args) => {
+              tbl.onLocationChange = onLocationChange;
+              tbl.onLocationChange(...args);
+              let displayAddress;
+              try {
+                const url = new URL(homeURL);
+                displayAddress = url.hostname;
+                if (!displayAddress) {
+                  // no host, use full address and truncate if too long
+                  const MAX_LEN = 32;
+                  displayAddress = url.href;
+                  if (displayAddress.length > MAX_LEN) {
+                    displayAddress = `${displayAddress.substring(0, MAX_LEN)}…`;
+                  }
+                }
+              } catch (e) {
+                // malformed URL, bail out
+                return;
+              }
+              const label =
+                NewIdentityStrings.new_identity_home_notification.replace(
+                  "%S",
+                  displayAddress
+                );
+              const callback = () => {
+                Services.prefs.setStringPref(trustedHomePref, homeURL);
+                win.BrowserHome();
+              };
+              const notificationBox = win.gBrowser.getNotificationBox();
+              notificationBox.appendNotification(
+                "new-identity-safe-home",
+                {
+                  label,
+                  priority: notificationBox.PRIORITY_INFO_MEDIUM,
+                },
+                [
+                  {
+                    label: NewIdentityStrings.new_identity_home_load_button,
+                    callback,
+                  },
+                ]
+              );
+            };
+          },
+          { once: true }
+        );
       });
     }
 


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



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/4b70c6b02d980a3f6d92975ffb79115d70a8a732...ed19d5f42f92f8a36a842460380065d84abbd836

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/4b70c6b02d980a3f6d92975ffb79115d70a8a732...ed19d5f42f92f8a36a842460380065d84abbd836
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tor-commits/attachments/20240408/3374c486/attachment-0001.htm>


More information about the tor-commits mailing list