#include "extensions/browser/api/declarative_net_request/declarative_net_request_api.h"
#include <functional>
#include <iterator>
#include <memory>
#include <optional>
#include <set>
#include <utility>
#include <vector>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/time/time.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/api/declarative_net_request/action_tracker.h"
#include "extensions/browser/api/declarative_net_request/composite_matcher.h"
#include "extensions/browser/api/declarative_net_request/constants.h"
#include "extensions/browser/api/declarative_net_request/file_backed_ruleset_source.h"
#include "extensions/browser/api/declarative_net_request/prefs_helper.h"
#include "extensions/browser/api/declarative_net_request/request_action.h"
#include "extensions/browser/api/declarative_net_request/request_params.h"
#include "extensions/browser/api/declarative_net_request/rules_monitor_service.h"
#include "extensions/browser/api/declarative_net_request/ruleset_manager.h"
#include "extensions/browser/api/declarative_net_request/ruleset_matcher.h"
#include "extensions/browser/api/declarative_net_request/utils.h"
#include "extensions/browser/api/extensions_api_client.h"
#include "extensions/browser/api/web_request/permission_helper.h"
#include "extensions/browser/api/web_request/web_request_permissions.h"
#include "extensions/browser/extension_file_task_runner.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/quota_service.h"
#include "extensions/common/api/declarative_net_request.h"
#include "extensions/common/api/declarative_net_request/constants.h"
#include "extensions/common/api/declarative_net_request/dnr_manifest_data.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/extension_id.h"
namespace extensions {
namespace {
dnr_api;
bool CanCallGetMatchedRules(content::BrowserContext* browser_context,
const Extension* extension,
std::optional<int> tab_id,
std::string* error) { … }
void FilterRules(std::vector<dnr_api::Rule>& rules,
const dnr_api::GetRulesFilter& rule_filter) { … }
bool IsRequestIntercepted(
const std::vector<declarative_net_request::RequestAction>& actions) { … }
uint64_t GetAllowActionPriority(
const std::vector<declarative_net_request::RequestAction>& actions) { … }
}
DeclarativeNetRequestUpdateDynamicRulesFunction::
DeclarativeNetRequestUpdateDynamicRulesFunction() = default;
DeclarativeNetRequestUpdateDynamicRulesFunction::
~DeclarativeNetRequestUpdateDynamicRulesFunction() = default;
ExtensionFunction::ResponseAction
DeclarativeNetRequestUpdateDynamicRulesFunction::Run() { … }
void DeclarativeNetRequestUpdateDynamicRulesFunction::OnDynamicRulesUpdated(
std::optional<std::string> error) { … }
DeclarativeNetRequestGetDynamicRulesFunction::
DeclarativeNetRequestGetDynamicRulesFunction() = default;
DeclarativeNetRequestGetDynamicRulesFunction::
~DeclarativeNetRequestGetDynamicRulesFunction() = default;
ExtensionFunction::ResponseAction
DeclarativeNetRequestGetDynamicRulesFunction::Run() { … }
void DeclarativeNetRequestGetDynamicRulesFunction::OnDynamicRulesFetched(
dnr_api::GetDynamicRules::Params params,
declarative_net_request::ReadJSONRulesResult read_json_result) { … }
DeclarativeNetRequestUpdateSessionRulesFunction::
DeclarativeNetRequestUpdateSessionRulesFunction() = default;
DeclarativeNetRequestUpdateSessionRulesFunction::
~DeclarativeNetRequestUpdateSessionRulesFunction() = default;
ExtensionFunction::ResponseAction
DeclarativeNetRequestUpdateSessionRulesFunction::Run() { … }
void DeclarativeNetRequestUpdateSessionRulesFunction::OnSessionRulesUpdated(
std::optional<std::string> error) { … }
DeclarativeNetRequestGetSessionRulesFunction::
DeclarativeNetRequestGetSessionRulesFunction() = default;
DeclarativeNetRequestGetSessionRulesFunction::
~DeclarativeNetRequestGetSessionRulesFunction() = default;
ExtensionFunction::ResponseAction
DeclarativeNetRequestGetSessionRulesFunction::Run() { … }
DeclarativeNetRequestUpdateEnabledRulesetsFunction::
DeclarativeNetRequestUpdateEnabledRulesetsFunction() = default;
DeclarativeNetRequestUpdateEnabledRulesetsFunction::
~DeclarativeNetRequestUpdateEnabledRulesetsFunction() = default;
ExtensionFunction::ResponseAction
DeclarativeNetRequestUpdateEnabledRulesetsFunction::Run() { … }
void DeclarativeNetRequestUpdateEnabledRulesetsFunction::
OnEnabledStaticRulesetsUpdated(std::optional<std::string> error) { … }
DeclarativeNetRequestGetEnabledRulesetsFunction::
DeclarativeNetRequestGetEnabledRulesetsFunction() = default;
DeclarativeNetRequestGetEnabledRulesetsFunction::
~DeclarativeNetRequestGetEnabledRulesetsFunction() = default;
ExtensionFunction::ResponseAction
DeclarativeNetRequestGetEnabledRulesetsFunction::Run() { … }
DeclarativeNetRequestUpdateStaticRulesFunction::
DeclarativeNetRequestUpdateStaticRulesFunction() = default;
DeclarativeNetRequestUpdateStaticRulesFunction::
~DeclarativeNetRequestUpdateStaticRulesFunction() = default;
ExtensionFunction::ResponseAction
DeclarativeNetRequestUpdateStaticRulesFunction::Run() { … }
void DeclarativeNetRequestUpdateStaticRulesFunction::OnStaticRulesUpdated(
std::optional<std::string> error) { … }
DeclarativeNetRequestGetDisabledRuleIdsFunction::
DeclarativeNetRequestGetDisabledRuleIdsFunction() = default;
DeclarativeNetRequestGetDisabledRuleIdsFunction::
~DeclarativeNetRequestGetDisabledRuleIdsFunction() = default;
ExtensionFunction::ResponseAction
DeclarativeNetRequestGetDisabledRuleIdsFunction::Run() { … }
void DeclarativeNetRequestGetDisabledRuleIdsFunction::OnDisabledRuleIdsRead(
std::vector<int> disabled_rule_ids) { … }
bool
DeclarativeNetRequestGetMatchedRulesFunction::disable_throttling_for_test_ = …;
DeclarativeNetRequestGetMatchedRulesFunction::
DeclarativeNetRequestGetMatchedRulesFunction() = default;
DeclarativeNetRequestGetMatchedRulesFunction::
~DeclarativeNetRequestGetMatchedRulesFunction() = default;
ExtensionFunction::ResponseAction
DeclarativeNetRequestGetMatchedRulesFunction::Run() { … }
void DeclarativeNetRequestGetMatchedRulesFunction::GetQuotaLimitHeuristics(
QuotaLimitHeuristics* heuristics) const { … }
bool DeclarativeNetRequestGetMatchedRulesFunction::ShouldSkipQuotaLimiting()
const { … }
DeclarativeNetRequestSetExtensionActionOptionsFunction::
DeclarativeNetRequestSetExtensionActionOptionsFunction() = default;
DeclarativeNetRequestSetExtensionActionOptionsFunction::
~DeclarativeNetRequestSetExtensionActionOptionsFunction() = default;
ExtensionFunction::ResponseAction
DeclarativeNetRequestSetExtensionActionOptionsFunction::Run() { … }
DeclarativeNetRequestIsRegexSupportedFunction::
DeclarativeNetRequestIsRegexSupportedFunction() = default;
DeclarativeNetRequestIsRegexSupportedFunction::
~DeclarativeNetRequestIsRegexSupportedFunction() = default;
ExtensionFunction::ResponseAction
DeclarativeNetRequestIsRegexSupportedFunction::Run() { … }
DeclarativeNetRequestGetAvailableStaticRuleCountFunction::
DeclarativeNetRequestGetAvailableStaticRuleCountFunction() = default;
DeclarativeNetRequestGetAvailableStaticRuleCountFunction::
~DeclarativeNetRequestGetAvailableStaticRuleCountFunction() = default;
ExtensionFunction::ResponseAction
DeclarativeNetRequestGetAvailableStaticRuleCountFunction::Run() { … }
DeclarativeNetRequestTestMatchOutcomeFunction::
DeclarativeNetRequestTestMatchOutcomeFunction() = default;
DeclarativeNetRequestTestMatchOutcomeFunction::
~DeclarativeNetRequestTestMatchOutcomeFunction() = default;
ExtensionFunction::ResponseAction
DeclarativeNetRequestTestMatchOutcomeFunction::Run() { … }
scoped_refptr<const net::HttpResponseHeaders>
DeclarativeNetRequestTestMatchOutcomeFunction::ParseHeaders(
std::optional<TestResponseHeaders>& test_headers,
std::string& error) const { … }
base::Value::List
DeclarativeNetRequestTestMatchOutcomeFunction::CreateMatchedRulesFromActions(
const std::vector<declarative_net_request::RequestAction>& actions) const { … }
std::vector<declarative_net_request::RequestAction>
DeclarativeNetRequestTestMatchOutcomeFunction::GetActions(
const declarative_net_request::CompositeMatcher& matcher,
const declarative_net_request::RequestParams& params,
declarative_net_request::RulesetMatchingStage stage,
PermissionsData::PageAccess page_access) const { … }
}