Bug 1426135 - cache the reset prefs. r?adw
MozReview-Commit-ID: 5W5o4CZZYpk
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -20,16 +20,23 @@ XPCOMUtils.defineLazyModuleGetters(this,
NetUtil: "resource://gre/modules/NetUtil.jsm",
});
XPCOMUtils.defineLazyServiceGetters(this, {
gEnvironment: ["@mozilla.org/process/environment;1", "nsIEnvironment"],
gChromeReg: ["@mozilla.org/chrome/chrome-registry;1", "nsIChromeRegistry"],
});
+const BROWSER_SEARCH_PREF = "browser.search.";
+
+XPCOMUtils.defineLazyPreferenceGetter(this, "resetStatus", BROWSER_SEARCH_PREF + "reset.status", "");
+XPCOMUtils.defineLazyGetter(this, "resetEnabled", () => {
+ return Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF).getBoolPref("reset.enabled");
+});
+
const BinaryInputStream = Components.Constructor(
"@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream", "setInputStream");
Cu.importGlobalProperties(["DOMParser", "XMLHttpRequest"]);
// A text encoder to UTF8, used whenever we commit the cache to disk.
XPCOMUtils.defineLazyGetter(this, "gEncoder",
@@ -120,18 +127,16 @@ const OPENSEARCH_LOCALNAME = "OpenSearch
const MOZSEARCH_NS_10 = "http://www.mozilla.org/2006/browser/search/";
const MOZSEARCH_LOCALNAME = "SearchPlugin";
const URLTYPE_SUGGEST_JSON = "application/x-suggestions+json";
const URLTYPE_SEARCH_HTML = "text/html";
const URLTYPE_OPENSEARCH = "application/opensearchdescription+xml";
-const BROWSER_SEARCH_PREF = "browser.search.";
-
const USER_DEFINED = "searchTerms";
// Custom search parameters
const MOZ_PARAM_LOCALE = "moz:locale";
const MOZ_PARAM_DIST_ID = "moz:distributionID";
const MOZ_PARAM_OFFICIAL = "moz:official";
// Supported OpenSearch parameters
@@ -2324,18 +2329,18 @@ Engine.prototype = {
getSubmission: function SRCH_ENG_getSubmission(aData, aResponseType, aPurpose) {
if (!aResponseType) {
aResponseType = AppConstants.platform == "android" ? this._defaultMobileResponseType :
URLTYPE_SEARCH_HTML;
}
let resetPending;
if (aResponseType == URLTYPE_SEARCH_HTML &&
- ((resetPending = Services.prefs.getCharPref(BROWSER_SEARCH_PREF + "reset.status", "") == "pending") ||
- Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF).getBoolPref("reset.enabled")) &&
+ ((resetPending = resetStatus == "pending") ||
+ resetEnabled) &&
this.name == Services.search.currentEngine.name &&
!this._isDefault &&
this.name != Services.search.originalDefaultEngine.name &&
(resetPending || !this.getAttr("loadPathHash") ||
this.getAttr("loadPathHash") != getVerificationHash(this._loadPath)) &&
!this._isWhiteListed) {
let url = "about:searchreset";
let data = [];