... |
... |
@@ -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
|
|