| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_COMMON_DOCUMENT_SUBRESOURCE_FILTER
_H_ | |
| 6 #define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_COMMON_DOCUMENT_SUBRESOURCE_FILTER
_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/callback.h" | |
| 14 #include "base/macros.h" | |
| 15 #include "base/memory/ref_counted.h" | |
| 16 #include "base/memory/weak_ptr.h" | |
| 17 #include "base/time/time.h" | |
| 18 #include "components/subresource_filter/content/common/document_load_statistics.
h" | |
| 19 #include "components/subresource_filter/core/common/activation_level.h" | |
| 20 #include "components/subresource_filter/core/common/activation_state.h" | |
| 21 #include "components/subresource_filter/core/common/indexed_ruleset.h" | |
| 22 #include "components/subresource_filter/core/common/proto/rules.pb.h" | |
| 23 #include "third_party/WebKit/public/platform/WebDocumentSubresourceFilter.h" | |
| 24 #include "url/gurl.h" | |
| 25 #include "url/origin.h" | |
| 26 | |
| 27 namespace subresource_filter { | |
| 28 | |
| 29 class FirstPartyOrigin; | |
| 30 class MemoryMappedRuleset; | |
| 31 | |
| 32 // Computes whether/how subresource filtering should be activated while loading | |
| 33 // |document_url| in a frame, based on the parent document's |activation_state|, | |
| 34 // the |parent_document_origin|, as well as any applicable deactivation rules in | |
| 35 // non-null |ruleset|. | |
| 36 ActivationState ComputeActivationState( | |
| 37 const GURL& document_url, | |
| 38 const url::Origin& parent_document_origin, | |
| 39 const ActivationState& parent_activation_state, | |
| 40 const MemoryMappedRuleset* ruleset); | |
| 41 | |
| 42 // Same as above, but instead of relying on the pre-computed activation state of | |
| 43 // the parent, computes the activation state for a frame from scratch, based on | |
| 44 // the page-level activation options |activation_level| and | |
| 45 // |measure_performance|; as well as any deactivation rules in |ruleset| that | |
| 46 // apply to |ancestor_document_urls|. | |
| 47 // | |
| 48 // TODO(pkalinnikov): Remove this when browser-side navigation is supported. | |
| 49 ActivationState ComputeActivationState( | |
| 50 ActivationLevel activation_level, | |
| 51 bool measure_performance, | |
| 52 const std::vector<GURL>& ancestor_document_urls, | |
| 53 const MemoryMappedRuleset* ruleset); | |
| 54 | |
| 55 // Performs filtering of subresource loads in the scope of a given document. | |
| 56 class DocumentSubresourceFilter | |
| 57 : public blink::WebDocumentSubresourceFilter, | |
| 58 public base::SupportsWeakPtr<DocumentSubresourceFilter> { | |
| 59 public: | |
| 60 // Constructs a new filter that will: | |
| 61 // -- Operate in a manner prescribed in |activation_state|. | |
| 62 // -- Filter subresource loads in the scope of a document loaded from | |
| 63 // |document_origin|. | |
| 64 // -- Hold a reference to and use |ruleset| for its entire lifetime. | |
| 65 // -- Invoke |first_disallowed_load_callback|, if it is non-null, on the | |
| 66 // first disallowed subresource load. | |
| 67 DocumentSubresourceFilter(url::Origin document_origin, | |
| 68 ActivationState activation_state, | |
| 69 scoped_refptr<const MemoryMappedRuleset> ruleset, | |
| 70 base::OnceClosure first_disallowed_load_callback); | |
| 71 | |
| 72 ~DocumentSubresourceFilter() override; | |
| 73 | |
| 74 const DocumentLoadStatistics& statistics() const { return statistics_; } | |
| 75 bool is_performance_measuring_enabled() const { | |
| 76 return activation_state_.measure_performance; | |
| 77 } | |
| 78 | |
| 79 // blink::WebDocumentSubresourceFilter: | |
| 80 LoadPolicy getLoadPolicy(const blink::WebURL& resourceUrl, | |
| 81 blink::WebURLRequest::RequestContext) override; | |
| 82 void reportDisallowedLoad() override; | |
| 83 | |
| 84 LoadPolicy GetLoadPolicyForSubdocument(const GURL& subdocument_url); | |
| 85 | |
| 86 private: | |
| 87 LoadPolicy EvaluateLoadPolicy(const GURL& resource_url, | |
| 88 proto::ElementType element_type); | |
| 89 | |
| 90 const ActivationState activation_state_; | |
| 91 const scoped_refptr<const MemoryMappedRuleset> ruleset_; | |
| 92 const IndexedRulesetMatcher ruleset_matcher_; | |
| 93 | |
| 94 // Equals nullptr iff |activation_state_.filtering_disabled_for_document|. | |
| 95 std::unique_ptr<FirstPartyOrigin> document_origin_; | |
| 96 | |
| 97 base::OnceClosure first_disallowed_load_callback_; | |
| 98 DocumentLoadStatistics statistics_; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(DocumentSubresourceFilter); | |
| 101 }; | |
| 102 | |
| 103 } // namespace subresource_filter | |
| 104 | |
| 105 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_COMMON_DOCUMENT_SUBRESOURCE_FIL
TER_H_ | |
| OLD | NEW |