... |
... |
@@ -238,7 +238,7 @@ var initializeNoScriptControl = () => { |
238
|
238
|
} catch (e) {
|
239
|
239
|
logger.error("Could not apply NoScript settings", e);
|
240
|
240
|
// Treat as a custom security level for the rest of the session.
|
241
|
|
- Services.prefs.setBoolPref(kCustomPref, true);
|
|
241
|
+ SecurityLevelPrefs.setCustomAndWarn();
|
242
|
242
|
}
|
243
|
243
|
};
|
244
|
244
|
waitForExtensionMessage(noscriptID, a => a.__meta.name === "started").then(
|
... |
... |
@@ -248,7 +248,7 @@ var initializeNoScriptControl = () => { |
248
|
248
|
} catch (e) {
|
249
|
249
|
logger.exception(e);
|
250
|
250
|
// Treat as a custom security level for the rest of the session.
|
251
|
|
- Services.prefs.setBoolPref(kCustomPref, true);
|
|
251
|
+ SecurityLevelPrefs.setCustomAndWarn();
|
252
|
252
|
}
|
253
|
253
|
};
|
254
|
254
|
|
... |
... |
@@ -401,7 +401,12 @@ var initializeSecurityPrefs = function () { |
401
|
401
|
// particular, for the NoScript addon.
|
402
|
402
|
Services.prefs.setBoolPref(kCustomPref, false);
|
403
|
403
|
Services.prefs.setIntPref(kSliderPref, effectiveIndex);
|
404
|
|
- } else if (!wasCustom && effectiveIndex !== desiredIndex) {
|
|
404
|
+ }
|
|
405
|
+ // Warn the user if they have booted the browser in a custom state, and have
|
|
406
|
+ // not yet acknowledged it in a previous session.
|
|
407
|
+ SecurityLevelPrefs.maybeWarnCustom();
|
|
408
|
+
|
|
409
|
+ if (!wasCustom && effectiveIndex !== desiredIndex) {
|
405
|
410
|
// NOTE: We assume all our controlled preferences require a restart.
|
406
|
411
|
// In practice, only a subset of these preferences may actually require a
|
407
|
412
|
// restart, so we could switch their values. But we treat them all the same
|
... |
... |
@@ -448,7 +453,7 @@ var initializeSecurityPrefs = function () { |
448
|
453
|
// properly applied. See tor-browser#43783.
|
449
|
454
|
// In the case where it does match a pre-set security level, the custom
|
450
|
455
|
// flag will be cleared at the next startup.
|
451
|
|
- Services.prefs.setBoolPref(kCustomPref, true);
|
|
456
|
+ SecurityLevelPrefs.setCustomAndWarn();
|
452
|
457
|
}),
|
453
|
458
|
});
|
454
|
459
|
}
|
... |
... |
@@ -517,12 +522,27 @@ export class SecurityLevel { |
517
|
522
|
}
|
518
|
523
|
|
519
|
524
|
/**
|
520
|
|
- * @typedef {object} SecurityLevelRestartNotificationHandler
|
|
525
|
+ * @callback SecurityLevelTryRestartBrowserCallback
|
|
526
|
+ *
|
|
527
|
+ * @returns {Promise<boolean>} - A promise that resolves when the user has made
|
|
528
|
+ * a decision. Should return `true` when the browser is now restarting.
|
|
529
|
+ */
|
|
530
|
+/**
|
|
531
|
+ * @callback SecurityLevelShowCustomWarningCallback
|
521
|
532
|
*
|
522
|
|
- * An object that can serve the user a restart notification.
|
|
533
|
+ * @param {Function} userDismissedCallback - A callback that should be called
|
|
534
|
+ * if the user has acknowledged and dismissed the notification.
|
|
535
|
+ */
|
|
536
|
+/**
|
|
537
|
+ * @typedef {object} SecurityLevelNotificationHandler
|
523
|
538
|
*
|
524
|
|
- * @property {Function} tryRestartBrowser - The method that should be called to
|
525
|
|
- * ask the user to restart the browser.
|
|
539
|
+ * An object that can serve the user notifications.
|
|
540
|
+ *
|
|
541
|
+ * @property {SecurityLevelTryRestartBrowserCallback} tryRestartBrowser - The
|
|
542
|
+ * method that should be called to ask the user to restart the browser.
|
|
543
|
+ * @property {SecurityLevelShowCustomWarningCallback} showCustomWarning - The
|
|
544
|
+ * method that should be called to let the user know they have a custom
|
|
545
|
+ * security level.
|
526
|
546
|
*/
|
527
|
547
|
|
528
|
548
|
/*
|
... |
... |
@@ -538,6 +558,8 @@ export const SecurityLevelPrefs = { |
538
|
558
|
}),
|
539
|
559
|
security_slider_pref: "browser.security_level.security_slider",
|
540
|
560
|
security_custom_pref: "browser.security_level.security_custom",
|
|
561
|
+ _customWarningDismissedPref:
|
|
562
|
+ "browser.security_level.custom_warning_dismissed",
|
541
|
563
|
|
542
|
564
|
/**
|
543
|
565
|
* The current security level preference.
|
... |
... |
@@ -593,18 +615,18 @@ export const SecurityLevelPrefs = { |
593
|
615
|
},
|
594
|
616
|
|
595
|
617
|
/**
|
596
|
|
- * Whether the browser should be restarted to apply the security level.
|
|
618
|
+ * The external handler that can show a notification to the user, if any.
|
597
|
619
|
*
|
598
|
|
- * @type {boolean}
|
|
620
|
+ * @type {?SecurityLevelNotificationHandler}
|
599
|
621
|
*/
|
600
|
|
- _needRestart: false,
|
|
622
|
+ _notificationHandler: null,
|
601
|
623
|
|
602
|
624
|
/**
|
603
|
|
- * The external handler that can show a notification to the user, if any.
|
|
625
|
+ * The notifications we are waiting for a handler to show.
|
604
|
626
|
*
|
605
|
|
- * @type {?SecurityLevelRestartNotificationHandler}
|
|
627
|
+ * @type {Set}
|
606
|
628
|
*/
|
607
|
|
- _restartNotificationHandler: null,
|
|
629
|
+ _pendingNotifications: {},
|
608
|
630
|
|
609
|
631
|
/**
|
610
|
632
|
* Set the external handler for showing notifications to the user.
|
... |
... |
@@ -612,49 +634,73 @@ export const SecurityLevelPrefs = { |
612
|
634
|
* This should only be called once per session once the handler is ready to
|
613
|
635
|
* show a notification, which may occur immediately during this call.
|
614
|
636
|
*
|
615
|
|
- * @param {SecurityLevelRestartNotificationHandler} handler - The new handler
|
616
|
|
- * to use.
|
|
637
|
+ * @param {SecurityLevelNotificationHandler} handler - The new handler to use.
|
617
|
638
|
*/
|
618
|
|
- setRestartNotificationHandler(handler) {
|
|
639
|
+ setNotificationHandler(handler) {
|
619
|
640
|
logger.info("Restart notification handler is set");
|
620
|
|
- this._restartNotificationHandler = handler;
|
621
|
|
- if (this._needRestart) {
|
622
|
|
- // Show now using the new handler.
|
623
|
|
- this._tryShowRestartNotification();
|
624
|
|
- }
|
|
641
|
+ this._notificationHandler = handler;
|
|
642
|
+ this._tryShowNotifications(this._pendingNotifications);
|
625
|
643
|
},
|
626
|
644
|
|
627
|
645
|
/**
|
628
|
646
|
* A promise for any ongoing notification prompt task.
|
629
|
647
|
*
|
630
|
|
- * @type {Promise}
|
|
648
|
+ * Resolves with whether the browser is restarting.
|
|
649
|
+ *
|
|
650
|
+ * @type {Promise<boolean>}
|
631
|
651
|
*/
|
632
|
652
|
_restartNotificationPromise: null,
|
633
|
653
|
|
634
|
654
|
/**
|
635
|
|
- * Try show a notification to the user.
|
|
655
|
+ * Try show notifications to the user.
|
|
656
|
+ *
|
|
657
|
+ * If no notification handler has been attached yet, this will queue the
|
|
658
|
+ * notification for when it is added, if ever.
|
636
|
659
|
*
|
637
|
|
- * If no notification handler has been attached yet, this will do nothing.
|
|
660
|
+ * @param {object} notifications - The notifications to try and show.
|
|
661
|
+ * @param {boolean} notifications.restart - Whether to show the restart
|
|
662
|
+ * notification.
|
|
663
|
+ * @param {boolean} notifications.custom - Whether to show the custom security
|
|
664
|
+ * level notification.
|
638
|
665
|
*/
|
639
|
|
- async _tryShowRestartNotification() {
|
640
|
|
- if (!this._restartNotificationHandler) {
|
641
|
|
- logger.info("Missing a restart notification handler");
|
|
666
|
+ async _tryShowNotifications(notifications) {
|
|
667
|
+ if (!this._notificationHandler) {
|
|
668
|
+ logger.info("Missing a notification handler", notifications);
|
642
|
669
|
// This may be added later in the session.
|
|
670
|
+ if (notifications.custom) {
|
|
671
|
+ this._pendingNotifications.custom = true;
|
|
672
|
+ }
|
|
673
|
+ if (notifications.restart) {
|
|
674
|
+ this._pendingNotifications.restart = true;
|
|
675
|
+ }
|
643
|
676
|
return;
|
644
|
677
|
}
|
645
|
678
|
|
646
|
|
- const prevPromise = this._restartNotificationPromise;
|
647
|
|
- let resolve;
|
648
|
|
- ({ promise: this._restartNotificationPromise, resolve } =
|
649
|
|
- Promise.withResolvers());
|
650
|
|
- await prevPromise;
|
651
|
|
-
|
652
|
|
- try {
|
653
|
|
- await this._restartNotificationHandler?.tryRestartBrowser();
|
654
|
|
- } finally {
|
655
|
|
- // Allow the notification to be shown again.
|
656
|
|
- resolve();
|
|
679
|
+ let isRestarting = false;
|
|
680
|
+ if (notifications.restart) {
|
|
681
|
+ const prevPromise = this._restartNotificationPromise;
|
|
682
|
+ let resolve;
|
|
683
|
+ ({ promise: this._restartNotificationPromise, resolve } =
|
|
684
|
+ Promise.withResolvers());
|
|
685
|
+ await prevPromise;
|
|
686
|
+
|
|
687
|
+ try {
|
|
688
|
+ isRestarting = await this._notificationHandler?.tryRestartBrowser();
|
|
689
|
+ } finally {
|
|
690
|
+ // Allow the notification to be shown again.
|
|
691
|
+ resolve();
|
|
692
|
+ }
|
|
693
|
+ }
|
|
694
|
+ // NOTE: We wait for the restart notification to resolve before showing the
|
|
695
|
+ // custom warning. We do not show the warning if we are already restarting.
|
|
696
|
+ if (!isRestarting && notifications.custom) {
|
|
697
|
+ this._notificationHandler?.showCustomWarning(() => {
|
|
698
|
+ // User has acknowledged and dismissed the notification.
|
|
699
|
+ Services.prefs.setBoolPref(this._customWarningDismissedPref, true);
|
|
700
|
+ });
|
657
|
701
|
}
|
|
702
|
+
|
|
703
|
+ this._pendingNotifications = {};
|
658
|
704
|
},
|
659
|
705
|
|
660
|
706
|
/**
|
... |
... |
@@ -670,7 +716,6 @@ export const SecurityLevelPrefs = { |
670
|
716
|
// At the next startup, the custom flag may be cleared if the settings are
|
671
|
717
|
// as expected.
|
672
|
718
|
Services.prefs.setBoolPref(kCustomPref, true);
|
673
|
|
- this._needRestart = true;
|
674
|
719
|
|
675
|
720
|
// NOTE: We need to change the controlled security level preferences in
|
676
|
721
|
// response to the desired change in security level. We could either:
|
... |
... |
@@ -696,6 +741,39 @@ export const SecurityLevelPrefs = { |
696
|
741
|
// still be marked as "custom" because:
|
697
|
742
|
// 1. Some preferences require a browser restart to be applied.
|
698
|
743
|
// 2. NoScript has not been updated with the new settings.
|
699
|
|
- this._tryShowRestartNotification();
|
|
744
|
+
|
|
745
|
+ this._tryShowNotifications({ restart: true, custom: true });
|
|
746
|
+ },
|
|
747
|
+
|
|
748
|
+ /**
|
|
749
|
+ * Put the user in the custom security level state and show them a warning
|
|
750
|
+ * about this state.
|
|
751
|
+ */
|
|
752
|
+ setCustomAndWarn() {
|
|
753
|
+ Services.prefs.setBoolPref(kCustomPref, true);
|
|
754
|
+ // NOTE: We clear _customWarningDismissedPref because the entry points
|
|
755
|
+ // for this method imply we should re-warn the user each time.
|
|
756
|
+ Services.prefs.clearUserPref(this._customWarningDismissedPref);
|
|
757
|
+ this._tryShowNotifications({ custom: true });
|
|
758
|
+ },
|
|
759
|
+
|
|
760
|
+ /**
|
|
761
|
+ * If the user is in a custom state, try and notify them of this state.
|
|
762
|
+ */
|
|
763
|
+ maybeWarnCustom() {
|
|
764
|
+ const isCustom = Services.prefs.getBoolPref(kCustomPref, false);
|
|
765
|
+ if (!isCustom) {
|
|
766
|
+ // Clear the dismissed preference so the user will be re-shown the
|
|
767
|
+ // notification when they re-enter the custom state.
|
|
768
|
+ Services.prefs.clearUserPref(this._customWarningDismissedPref);
|
|
769
|
+ return;
|
|
770
|
+ }
|
|
771
|
+ if (Services.prefs.getBoolPref(this._customWarningDismissedPref, false)) {
|
|
772
|
+ // Do not warn the user of the custom state if they have already
|
|
773
|
+ // acknowledged and dismissed this in a previous session.
|
|
774
|
+ return;
|
|
775
|
+ }
|
|
776
|
+
|
|
777
|
+ this._tryShowNotifications({ custom: true });
|
700
|
778
|
},
|
701
|
779
|
}; /* Security Level Prefs */ |