Verified Commit a00fd3bb authored by henry's avatar henry Committed by ma1
Browse files

fixup! BB 40925: Implemented the Security Level component

TB 43783: Prompt user for a restart if their security level preferences
are not aligned at startup or mid-session.

Also handle failures to apply NoScript settings.
parent aec824b3
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -63,6 +63,8 @@ ChromeUtils.defineESModuleGetters(lazy, {
  ScreenshotsUtils: "resource:///modules/ScreenshotsUtils.sys.mjs",
  SearchSERPTelemetry:
    "moz-src:///browser/components/search/SearchSERPTelemetry.sys.mjs",
  SecurityLevelRestartNotification:
    "resource:///modules/SecurityLevelRestartNotification.sys.mjs",
  SessionStartup: "resource:///modules/sessionstore/SessionStartup.sys.mjs",
  SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
  ShortcutUtils: "resource://gre/modules/ShortcutUtils.sys.mjs",
@@ -994,6 +996,8 @@ BrowserGlue.prototype = {
      lazy.WeaveService.init();
    }

    lazy.SecurityLevelRestartNotification.ready();

    ClipboardPrivacy.startup();

    lazy.BrowserUtils.callModulesFromCategory(
+72 −0
Original line number Diff line number Diff line
const lazy = {};

ChromeUtils.defineESModuleGetters(lazy, {
  BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs",
  SecurityLevelPrefs: "resource://gre/modules/SecurityLevel.sys.mjs",
});

ChromeUtils.defineLazyGetter(lazy, "NotificationStrings", function () {
  return new Localization([
    "branding/brand.ftl",
    "toolkit/global/base-browser.ftl",
  ]);
});

/**
 * Interface for showing the security level restart notification on desktop.
 */
export const SecurityLevelRestartNotification = {
  /**
   * Whether we have already been initialised.
   *
   * @type {boolean}
   */
  _initialized: false,

  /**
   * Called when the UI is ready to show a notification.
   */
  ready() {
    if (this._initialized) {
      return;
    }
    this._initialized = true;
    lazy.SecurityLevelPrefs.setRestartNotificationHandler(this);
  },

  /**
   * Show the restart notification, and perform the restart if the user agrees.
   */
  async tryRestartBrowser() {
    const [titleText, bodyText, primaryButtonText, secondaryButtonText] =
      await lazy.NotificationStrings.formatValues([
        { id: "security-level-restart-prompt-title" },
        { id: "security-level-restart-prompt-body" },
        { id: "security-level-restart-prompt-button-restart" },
        { id: "security-level-restart-prompt-button-ignore" },
      ]);
    const buttonFlags =
      Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0 +
      Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_1;

    const propBag = await Services.prompt.asyncConfirmEx(
      lazy.BrowserWindowTracker.getTopWindow()?.browsingContext ?? null,
      Services.prompt.MODAL_TYPE_INTERNAL_WINDOW,
      titleText,
      bodyText,
      buttonFlags,
      primaryButtonText,
      secondaryButtonText,
      null,
      null,
      null,
      {}
    );

    if (propBag.get("buttonNumClicked") === 0) {
      Services.startup.quit(
        Services.startup.eAttemptQuit | Services.startup.eRestart
      );
    }
  },
};
+1 −0
Original line number Diff line number Diff line
@@ -136,6 +136,7 @@ EXTRA_JS_MODULES += [
    "PopupBlockerObserver.sys.mjs",
    "ProcessHangMonitor.sys.mjs",
    "Sanitizer.sys.mjs",
    "SecurityLevelRestartNotification.sys.mjs",
    "SelectionChangedMenulist.sys.mjs",
    "SharingUtils.sys.mjs",
    "SiteDataManager.sys.mjs",
+320 −107

File changed.

Preview size limit exceeded, changes collapsed.