#include "extensions/browser/api/declarative_net_request/ruleset_matcher_base.h"
#include <string_view>
#include <tuple>
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "components/url_pattern_index/flat/url_pattern_index_generated.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "extensions/browser/api/declarative_net_request/constants.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/utils.h"
#include "extensions/common/api/declarative_net_request.h"
#include "net/base/url_util.h"
#include "url/gurl.h"
namespace extensions::declarative_net_request {
flat_rule;
dnr_api;
namespace {
bool ShouldCollapseResourceType(flat_rule::ElementType type) { … }
bool IsUpgradeableUrl(const GURL& url) { … }
GURL GetUpgradedUrl(const GURL& url) { … }
template <typename T>
bool IsEmpty(const flatbuffers::Vector<T>* vec) { … }
bool GetModifiedQuery(const GURL& url,
const flat::UrlTransform& transform,
std::string* modified_query) { … }
GURL GetTransformedURL(const RequestParams& params,
const flat::UrlTransform& transform) { … }
}
RulesetMatcherBase::RulesetMatcherBase(const ExtensionId& extension_id,
RulesetID ruleset_id)
: … { … }
RulesetMatcherBase::~RulesetMatcherBase() = default;
std::optional<RequestAction> RulesetMatcherBase::GetAction(
const RequestParams& params,
RulesetMatchingStage stage) const { … }
void RulesetMatcherBase::OnRenderFrameCreated(content::RenderFrameHost* host) { … }
void RulesetMatcherBase::OnRenderFrameDeleted(content::RenderFrameHost* host) { … }
void RulesetMatcherBase::OnDidFinishNavigation(
content::NavigationHandle* navigation_handle) { … }
std::optional<RequestAction>
RulesetMatcherBase::GetAllowlistedFrameActionForTesting(
content::RenderFrameHost* host) const { … }
RequestAction RulesetMatcherBase::CreateBlockOrCollapseRequestAction(
const RequestParams& params,
const flat_rule::UrlRule& rule) const { … }
RequestAction RulesetMatcherBase::CreateAllowAction(
const RequestParams& params,
const flat_rule::UrlRule& rule) const { … }
RequestAction RulesetMatcherBase::CreateAllowAllRequestsAction(
const RequestParams& params,
const url_pattern_index::flat::UrlRule& rule) const { … }
std::optional<RequestAction> RulesetMatcherBase::CreateUpgradeAction(
const RequestParams& params,
const url_pattern_index::flat::UrlRule& rule) const { … }
std::optional<RequestAction>
RulesetMatcherBase::CreateRedirectActionFromMetadata(
const RequestParams& params,
const url_pattern_index::flat::UrlRule& rule,
const ExtensionMetadataList& metadata_list) const { … }
std::optional<RequestAction> RulesetMatcherBase::CreateRedirectAction(
const RequestParams& params,
const url_pattern_index::flat::UrlRule& rule,
GURL redirect_url) const { … }
std::vector<RequestAction>
RulesetMatcherBase::GetModifyHeadersActionsFromMetadata(
const RequestParams& params,
const std::vector<const url_pattern_index::flat::UrlRule*>& rules,
const ExtensionMetadataList& metadata_list) const { … }
RequestAction RulesetMatcherBase::CreateRequestAction(
RequestAction::Type type,
const flat_rule::UrlRule& rule) const { … }
std::optional<RequestAction> RulesetMatcherBase::GetAllowlistedFrameAction(
content::GlobalRenderFrameHostId frame_id) const { … }
}