Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Side by Side Diff: components/subresource_filter/core/common/document_subresource_filter.h

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

Powered by Google App Engine
This is Rietveld 408576698