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

fixup! Bug 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 33853c83
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -60,6 +60,8 @@ ChromeUtils.defineESModuleGetters(lazy, {
  Sanitizer: "resource:///modules/Sanitizer.sys.mjs",
  ScreenshotsUtils: "resource:///modules/ScreenshotsUtils.sys.mjs",
  SearchSERPTelemetry: "resource:///modules/SearchSERPTelemetry.sys.mjs",
  SecurityLevelRestartNotification:
    "resource:///modules/SecurityLevelRestartNotification.sys.mjs",
  SessionStartup: "resource:///modules/sessionstore/SessionStartup.sys.mjs",
  SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
  ShellService: "resource:///modules/ShellService.sys.mjs",
@@ -1814,6 +1816,8 @@ BrowserGlue.prototype = {

    lazy.DoHController.init();

    lazy.SecurityLevelRestartNotification.ready();

    ClipboardPrivacy.startup();

    this._firstWindowTelemetry(aWindow);
+77 −0
Original line number Diff line number Diff line
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";

const lazy = {};

XPCOMUtils.defineLazyModuleGetters(lazy, {
  BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
});

ChromeUtils.defineESModuleGetters(lazy, {
  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
@@ -142,6 +142,7 @@ EXTRA_JS_MODULES += [
    "PingCentre.jsm",
    "ProcessHangMonitor.jsm",
    "Sanitizer.sys.mjs",
    "SecurityLevelRestartNotification.sys.mjs",
    "SelectionChangedMenulist.jsm",
    "SiteDataManager.jsm",
    "SitePermissions.sys.mjs",
+321 −107

File changed.

Preview size limit exceeded, changes collapsed.