From a90a5cba08fdf6c0ceb95101c275108a152a3aed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:35:37 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- .../extensions/ExtensionDNRLimits.sys.mjs | 129 ++++++++++++++------- 1 file changed, 85 insertions(+), 44 deletions(-) (limited to 'toolkit/components/extensions/ExtensionDNRLimits.sys.mjs') diff --git a/toolkit/components/extensions/ExtensionDNRLimits.sys.mjs b/toolkit/components/extensions/ExtensionDNRLimits.sys.mjs index ac4cd79c44..12919e4ee1 100644 --- a/toolkit/components/extensions/ExtensionDNRLimits.sys.mjs +++ b/toolkit/components/extensions/ExtensionDNRLimits.sys.mjs @@ -2,58 +2,99 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -// TODO(Bug 1803370): consider allowing changing DNR limits through about:config prefs). +import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs"; -/** - * The minimum number of static rules guaranteed to an extension across its - * enabled static rulesets. Any rules above this limit will count towards the - * global static rule limit. - */ -const GUARANTEED_MINIMUM_STATIC_RULES = 30000; +// TODO(Bug 1803370): allow extension to exceed the GUARANTEED_MINIMUM_STATIC_RULES limit. +// +// The maximum number of static rules exceeding the per-extension +// GUARANTEED_MINIMUM_STATIC_RULES across every extensions. +// +// const MAX_GLOBAL_NUMBER_OF_STATIC_RULES = 300000; -/** - * The maximum number of static Rulesets an extension can specify as part of - * the "rule_resources" manifest key. - * - * NOTE: this limit may be increased in the future, see https://github.com/w3c/webextensions/issues/318 - */ -const MAX_NUMBER_OF_STATIC_RULESETS = 50; +const lazy = {}; -/** - * The maximum number of static Rulesets an extension can enable at any one time. - * - * NOTE: this limit may be increased in the future, see https://github.com/w3c/webextensions/issues/318 - */ -const MAX_NUMBER_OF_ENABLED_STATIC_RULESETS = 10; +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "GUARANTEED_MINIMUM_STATIC_RULES", + "extensions.dnr.guaranteed_minimum_static_rules", + 30000 +); -/** - * The maximum number of dynamic and session rules an extension can add. - * NOTE: in the Firefox we are enforcing this limit to the session and dynamic rules count separately, - * instead of enforcing it to the rules count for both combined as the Chrome implementation does. - * - * NOTE: this limit may be increased in the future, see https://github.com/w3c/webextensions/issues/319 - */ -const MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES = 5000; +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "MAX_NUMBER_OF_STATIC_RULESETS", + "extensions.dnr.max_number_of_static_rulesets", + 100 +); + +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "MAX_NUMBER_OF_ENABLED_STATIC_RULESETS", + "extensions.dnr.max_number_of_enabled_static_rulesets", + 20 +); /** - * The maximum number of regular expression rules that an extension can add. - * Session, dynamic and static rules have their own quota. - * - * TODO bug 1821033: Bump limit after optimizing regexFilter. + * NOTE: this limit may be increased in the future, see + * https://github.com/w3c/webextensions/issues/319 */ -const MAX_NUMBER_OF_REGEX_RULES = 1000; +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES", + "extensions.dnr.max_number_of_dynamic_and_session_rules", + 5000 +); -// TODO(Bug 1803370): allow extension to exceed the GUARANTEED_MINIMUM_STATIC_RULES limit. -// -// The maximum number of static rules exceeding the per-extension -// GUARANTEED_MINIMUM_STATIC_RULES across every extensions. -// -// const MAX_GLOBAL_NUMBER_OF_STATIC_RULES = 300000; +// TODO bug 1821033: Bump limit after optimizing regexFilter. +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "MAX_NUMBER_OF_REGEX_RULES", + "extensions.dnr.max_number_of_regex_rules", + 1000 +); export const ExtensionDNRLimits = { - GUARANTEED_MINIMUM_STATIC_RULES, - MAX_NUMBER_OF_STATIC_RULESETS, - MAX_NUMBER_OF_ENABLED_STATIC_RULESETS, - MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES, - MAX_NUMBER_OF_REGEX_RULES, + /** + * The minimum number of static rules guaranteed to an extension across its + * enabled static rulesets. Any rules above this limit will count towards the + * global static rule limit. + */ + get GUARANTEED_MINIMUM_STATIC_RULES() { + return lazy.GUARANTEED_MINIMUM_STATIC_RULES; + }, + + /** + * The maximum number of static Rulesets an extension can specify as part of + * the "rule_resources" manifest key. + */ + get MAX_NUMBER_OF_STATIC_RULESETS() { + return lazy.MAX_NUMBER_OF_STATIC_RULESETS; + }, + + /** + * The maximum number of static Rulesets an extension can enable at any one + * time. + */ + get MAX_NUMBER_OF_ENABLED_STATIC_RULESETS() { + return lazy.MAX_NUMBER_OF_ENABLED_STATIC_RULESETS; + }, + + /** + * The maximum number of dynamic and session rules an extension can add. + * + * NOTE: in the Firefox we are enforcing this limit to the session and + * dynamic rules count separately, instead of enforcing it to the rules count + * for both combined as the Chrome implementation does. + */ + get MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES() { + return lazy.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES; + }, + + /** + * The maximum number of regular expression rules that an extension can add. + * Session, dynamic and static rules have their own quota. + */ + get MAX_NUMBER_OF_REGEX_RULES() { + return lazy.MAX_NUMBER_OF_REGEX_RULES; + }, }; -- cgit v1.2.3