#ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_COMPOSITE_MATCHER_H_
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_COMPOSITE_MATCHER_H_
#include <cstdint>
#include <memory>
#include <set>
#include <vector>
#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/ruleset_matcher.h"
#include "extensions/common/permissions/permissions_data.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace content {
class NavigationHandle;
class RenderFrameHost;
}
namespace extensions {
namespace declarative_net_request {
struct RequestAction;
class CompositeMatcher {
public:
struct ActionInfo {
ActionInfo();
ActionInfo(absl::optional<RequestAction> action,
bool notify_request_withheld);
ActionInfo(const ActionInfo&) = delete;
ActionInfo& operator=(const ActionInfo&) = delete;
~ActionInfo();
ActionInfo(ActionInfo&& other);
ActionInfo& operator=(ActionInfo&& other);
absl::optional<RequestAction> action;
bool notify_request_withheld = false;
};
using MatcherList = std::vector<std::unique_ptr<RulesetMatcher>>;
CompositeMatcher(MatcherList matchers, HostPermissionsAlwaysRequired mode);
CompositeMatcher(const CompositeMatcher&) = delete;
CompositeMatcher& operator=(const CompositeMatcher&) = delete;
~CompositeMatcher();
const MatcherList& matchers() const { return matchers_; }
HostPermissionsAlwaysRequired host_permissions_always_required() const {
return host_permissions_always_required_;
}
const RulesetMatcher* GetMatcherWithID(RulesetID id) const;
void AddOrUpdateRuleset(std::unique_ptr<RulesetMatcher> matcher);
void AddOrUpdateRulesets(CompositeMatcher::MatcherList matchers);
void RemoveRulesetsWithIDs(const std::set<RulesetID>& ids);
std::set<RulesetID> ComputeStaticRulesetIDs() const;
ActionInfo GetBeforeRequestAction(
const RequestParams& params,
PermissionsData::PageAccess page_access) const;
std::vector<RequestAction> GetModifyHeadersActions(
const RequestParams& params) const;
bool HasAnyExtraHeadersMatcher() const;
void OnRenderFrameCreated(content::RenderFrameHost* host);
void OnRenderFrameDeleted(content::RenderFrameHost* host);
void OnDidFinishNavigation(content::NavigationHandle* navigation_handle);
private:
void OnMatchersModified();
bool ComputeHasAnyExtraHeadersMatcher() const;
MatcherList matchers_;
mutable absl::optional<bool> has_any_extra_headers_matcher_;
const HostPermissionsAlwaysRequired host_permissions_always_required_;
};
}
}
#endif