Verified Commit 11ec7a04 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃
Browse files

fixup! Bug 40925: Implemented the Security Level component

Improve the patch to skip DDG redirection for 115.
parent cce05ab5
Loading
Loading
Loading
Loading
+6 −39
Original line number Diff line number Diff line
@@ -2,6 +2,12 @@

/* global AppConstants, Services, openPreferences, XPCOMUtils */

ChromeUtils.defineModuleGetter(
  this,
  "SecurityLevelPrefs",
  "resource://gre/modules/SecurityLevel.jsm"
);

XPCOMUtils.defineLazyGetter(this, "SecurityLevelStrings", () => {
  let strings = {
    // Generic terms
@@ -61,45 +67,6 @@ XPCOMUtils.defineLazyGetter(this, "SecurityLevelStrings", () => {
  return strings;
});

/*
  Security Level Prefs

  Getters and Setters for relevant torbutton prefs
*/
var SecurityLevelPrefs = {
  SecurityLevels: Object.freeze({
    safest: 1,
    safer: 2,
    standard: 4,
  }),
  security_slider_pref: "browser.security_level.security_slider",
  security_custom_pref: "browser.security_level.security_custom",

  get securityLevel() {
    // Set the default return value to 0, which won't match anything in
    // SecurityLevels.
    const val = Services.prefs.getIntPref(this.security_slider_pref, 0);
    return Object.entries(this.SecurityLevels).find(
      entry => entry[1] === val
    )?.[0];
  },

  set securityLevel(level) {
    const val = this.SecurityLevels[level];
    if (val !== undefined) {
      Services.prefs.setIntPref(this.security_slider_pref, val);
    }
  },

  get securityCustom() {
    return Services.prefs.getBoolPref(this.security_custom_pref);
  },

  set securityCustom(val) {
    Services.prefs.setBoolPref(this.security_custom_pref, val);
  },
}; /* Security Level Prefs */

/*
  Security Level Button Code

+8 −8
Original line number Diff line number Diff line
@@ -14,6 +14,12 @@ ChromeUtils.defineESModuleGetters(lazy, {
  SearchUtils: "resource://gre/modules/SearchUtils.sys.mjs",
});

ChromeUtils.defineModuleGetter(
  lazy,
  "SecurityLevelPrefs",
  "resource://gre/modules/SecurityLevel.jsm"
);

const BinaryInputStream = Components.Constructor(
  "@mozilla.org/binaryinputstream;1",
  "nsIBinaryInputStream",
@@ -27,12 +33,6 @@ XPCOMUtils.defineLazyGetter(lazy, "logConsole", () => {
  });
});

XPCOMUtils.defineLazyScriptGetter(
  this,
  "SecurityLevelPrefs",
  "chrome://browser/content/securitylevel/securityLevel.js"
);

const USER_DEFINED = "searchTerms";

// Supported OpenSearch parameters
@@ -444,8 +444,8 @@ export class EngineURL {
      engine &&
      (engine._extensionID === "ddg@search.mozilla.org" ||
        engine._extensionID === "ddg-onion@search.mozilla.org") &&
      this.type === SearchUtils.URL_TYPE.SEARCH &&
      SecurityLevelPrefs?.securityLevel === "safest"
      this.type === lazy.SearchUtils.URL_TYPE.SEARCH &&
      lazy.SecurityLevelPrefs?.securityLevel === "safest"
    ) {
      urlTemplate += "html";
    }
+45 −7
Original line number Diff line number Diff line
"use strict";

var EXPORTED_SYMBOLS = ["SecurityLevel"];
var EXPORTED_SYMBOLS = ["SecurityLevel", "SecurityLevelPrefs"];

const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
  "resource://gre/modules/XPCOMUtils.jsm"
);
const { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm");

const lazy = {};

XPCOMUtils.defineLazyModuleGetters(lazy, {
  ExtensionParent: "resource://gre/modules/ExtensionParent.jsm",
});
ChromeUtils.defineModuleGetter(
  lazy,
  "ExtensionParent",
  "resource://gre/modules/ExtensionParent.jsm"
);

const logger = new ConsoleAPI({
  maxLogLevel: "info",
@@ -443,3 +442,42 @@ class SecurityLevel {
    }
  }
}

/*
  Security Level Prefs

  Getters and Setters for relevant torbutton prefs
*/
const SecurityLevelPrefs = {
  SecurityLevels: Object.freeze({
    safest: 1,
    safer: 2,
    standard: 4,
  }),
  security_slider_pref: "browser.security_level.security_slider",
  security_custom_pref: "browser.security_level.security_custom",

  get securityLevel() {
    // Set the default return value to 0, which won't match anything in
    // SecurityLevels.
    const val = Services.prefs.getIntPref(this.security_slider_pref, 0);
    return Object.entries(this.SecurityLevels).find(
      entry => entry[1] === val
    )?.[0];
  },

  set securityLevel(level) {
    const val = this.SecurityLevels[level];
    if (val !== undefined) {
      Services.prefs.setIntPref(this.security_slider_pref, val);
    }
  },

  get securityCustom() {
    return Services.prefs.getBoolPref(this.security_custom_pref);
  },

  set securityCustom(val) {
    Services.prefs.setBoolPref(this.security_custom_pref, val);
  },
}; /* Security Level Prefs */