Skip to content

Commit

Permalink
Bug 1877181 - Add an explicit lazy getter for accessing the allowlist…
Browse files Browse the repository at this point in the history
… in SearchService. r=search-reviewers,mcheang

Differential Revision: https://phabricator.services.mozilla.com/D199903
  • Loading branch information
Standard8 committed Jan 31, 2024
1 parent a9a75b4 commit d324aaa
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions toolkit/components/search/SearchService.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ XPCOMUtils.defineLazyServiceGetter(
"nsIUpdateTimerManager"
);

/**
* A reference to the handler for the default override allowlist.
*
* @type {SearchDefaultOverrideAllowlistHandler}
*/
ChromeUtils.defineLazyGetter(lazy, "defaultOverrideAllowlist", () => {
return new SearchDefaultOverrideAllowlistHandler();
});

// Exported to tests for not splitting ids when building webextension ids.
export const NON_SPLIT_ENGINE_IDS = [
"allegro-pl",
Expand Down Expand Up @@ -506,11 +515,6 @@ export class SearchService {
};
}

if (!this.#defaultOverrideAllowlist) {
this.#defaultOverrideAllowlist =
new SearchDefaultOverrideAllowlistHandler();
}

if (
extension.startupReason === "ADDON_INSTALL" ||
extension.startupReason === "ADDON_ENABLE"
Expand All @@ -523,7 +527,7 @@ export class SearchService {
};
}
if (
!(await this.#defaultOverrideAllowlist.canOverride(
!(await lazy.defaultOverrideAllowlist.canOverride(
extension,
engine._extensionID
))
Expand Down Expand Up @@ -553,7 +557,7 @@ export class SearchService {

if (
engine.getAttr("overriddenBy") == extension.id &&
(await this.#defaultOverrideAllowlist.canOverride(
(await lazy.defaultOverrideAllowlist.canOverride(
extension,
engine._extensionID
))
Expand Down Expand Up @@ -1101,13 +1105,6 @@ export class SearchService {
*/
#startupRemovedExtensions = new Set();

/**
* A reference to the handler for the default override allow list.
*
* @type {SearchDefaultOverrideAllowlistHandler|null}
*/
#defaultOverrideAllowlist = null;

/**
* This map is built lazily after the available search engines change. It
* allows quick parsing of an URL representing a search submission into the
Expand Down

0 comments on commit d324aaa

Please sign in to comment.