OLD | NEW |
---|---|
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_BROWSER_CONTENT_SUBRESOURCE_FILTER _DRIVER_FACTORY_H_ | 5 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FILTER _DRIVER_FACTORY_H_ |
6 #define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FILTER _DRIVER_FACTORY_H_ | 6 #define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FILTER _DRIVER_FACTORY_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 24 matching lines...) Expand all Loading... | |
35 enum class ActivationLevel; | 35 enum class ActivationLevel; |
36 enum class ActivationList; | 36 enum class ActivationList; |
37 | 37 |
38 using URLToActivationListsMap = | 38 using URLToActivationListsMap = |
39 std::unordered_map<std::string, std::set<ActivationList>>; | 39 std::unordered_map<std::string, std::set<ActivationList>>; |
40 | 40 |
41 // Controls the activation of subresource filtering for each page load in a | 41 // Controls the activation of subresource filtering for each page load in a |
42 // WebContents and is responsible for sending the activation signal to all the | 42 // WebContents and is responsible for sending the activation signal to all the |
43 // per-frame SubresourceFilterAgents on the renderer side. | 43 // per-frame SubresourceFilterAgents on the renderer side. |
44 class ContentSubresourceFilterDriverFactory | 44 class ContentSubresourceFilterDriverFactory |
45 : public base::SupportsUserData::Data, | 45 : public base::SupportsUserData::Data, |
engedy
2017/05/02 12:24:20
nit: If you are changing this, could you also spru
Charlie Harrison
2017/05/02 16:01:57
Done.
| |
46 public content::WebContentsObserver, | 46 public content::WebContentsObserver, |
47 public ContentSubresourceFilterThrottleManager::Delegate { | 47 public ContentSubresourceFilterThrottleManager::Delegate { |
48 public: | 48 public: |
49 // NOTE: ActivationDecision backs a UMA histogram, so it is append-only. | 49 // NOTE: ActivationDecision backs a UMA histogram, so it is append-only. |
50 enum class ActivationDecision { | 50 enum class ActivationDecision { |
51 // The activation decision is unknown, or not known yet. | 51 // The activation decision is unknown, or not known yet. |
52 UNKNOWN, | 52 UNKNOWN, |
53 | 53 |
54 // Subresource filtering was activated. | 54 // Subresource filtering was activated. |
55 ACTIVATED, | 55 ACTIVATED, |
56 | 56 |
57 // Did not activate because subresource filtering was disabled. | 57 // Did not activate because subresource filtering was disabled. |
58 ACTIVATION_DISABLED, | 58 ACTIVATION_DISABLED, |
59 | 59 |
60 // Did not activate because the main frame document URL had an unsupported | 60 // Did not activate because the main frame document URL had an unsupported |
61 // scheme. | 61 // scheme. |
62 UNSUPPORTED_SCHEME, | 62 UNSUPPORTED_SCHEME, |
63 | 63 |
64 // Did not activate because the main frame document URL was whitelisted. | 64 // Did not activate because the main frame document URL was whitelisted. |
65 URL_WHITELISTED, | 65 URL_WHITELISTED, |
66 | 66 |
67 // Did not activate because the main frame document URL did not match the | 67 // Did not activate because the main frame document URL did not match the |
68 // activation list. | 68 // activation list. |
69 ACTIVATION_LIST_NOT_MATCHED, | 69 ACTIVATION_LIST_NOT_MATCHED, |
70 | 70 |
71 // Max value for enum. | 71 // Max value for enum. |
72 ACTIVATION_DECISION_MAX | 72 ACTIVATION_DECISION_MAX |
73 }; | 73 }; |
74 | 74 |
75 static void CreateForWebContents( | 75 static void CreateForWebContents(content::WebContents* web_contents, |
76 content::WebContents* web_contents, | 76 SubresourceFilterClient* client); |
77 std::unique_ptr<SubresourceFilterClient> client); | |
78 static ContentSubresourceFilterDriverFactory* FromWebContents( | 77 static ContentSubresourceFilterDriverFactory* FromWebContents( |
79 content::WebContents* web_contents); | 78 content::WebContents* web_contents); |
80 | 79 |
81 // Whether the |url|, |referrer|, and |transition| are considered to be | 80 // Whether the |url|, |referrer|, and |transition| are considered to be |
82 // associated with a page reload. | 81 // associated with a page reload. |
83 static bool NavigationIsPageReload(const GURL& url, | 82 static bool NavigationIsPageReload(const GURL& url, |
84 const content::Referrer& referrer, | 83 const content::Referrer& referrer, |
85 ui::PageTransition transition); | 84 ui::PageTransition transition); |
86 | 85 |
87 explicit ContentSubresourceFilterDriverFactory( | 86 explicit ContentSubresourceFilterDriverFactory( |
88 content::WebContents* web_contents, | 87 content::WebContents* web_contents, |
89 std::unique_ptr<SubresourceFilterClient> client); | 88 SubresourceFilterClient* client); |
90 ~ContentSubresourceFilterDriverFactory() override; | 89 ~ContentSubresourceFilterDriverFactory() override; |
91 | 90 |
92 // Called when Safe Browsing detects that the |url| corresponding to the load | 91 // Called when Safe Browsing detects that the |url| corresponding to the load |
93 // of the main frame belongs to the blacklist with |threat_type|. If the | 92 // of the main frame belongs to the blacklist with |threat_type|. If the |
94 // blacklist is the Safe Browsing Social Engineering ads landing, then |url| | 93 // blacklist is the Safe Browsing Social Engineering ads landing, then |url| |
95 // and |redirects| are saved. | 94 // and |redirects| are saved. |
96 void OnMainResourceMatchedSafeBrowsingBlacklist( | 95 void OnMainResourceMatchedSafeBrowsingBlacklist( |
97 const GURL& url, | 96 const GURL& url, |
98 const std::vector<GURL>& redirect_urls, | 97 const std::vector<GURL>& redirect_urls, |
99 safe_browsing::SBThreatType threat_type, | 98 safe_browsing::SBThreatType threat_type, |
(...skipping 12 matching lines...) Expand all Loading... | |
112 void OnFirstSubresourceLoadDisallowed() override; | 111 void OnFirstSubresourceLoadDisallowed() override; |
113 bool ShouldSuppressActivation( | 112 bool ShouldSuppressActivation( |
114 content::NavigationHandle* navigation_handle) override; | 113 content::NavigationHandle* navigation_handle) override; |
115 void WillProcessResponse( | 114 void WillProcessResponse( |
116 content::NavigationHandle* navigation_handle) override; | 115 content::NavigationHandle* navigation_handle) override; |
117 | 116 |
118 ContentSubresourceFilterThrottleManager* throttle_manager() { | 117 ContentSubresourceFilterThrottleManager* throttle_manager() { |
119 return throttle_manager_.get(); | 118 return throttle_manager_.get(); |
120 } | 119 } |
121 | 120 |
122 SubresourceFilterClient* client() { return client_.get(); } | 121 SubresourceFilterClient* client() { return client_; } |
123 | 122 |
124 private: | 123 private: |
125 friend class ContentSubresourceFilterDriverFactoryTest; | 124 friend class ContentSubresourceFilterDriverFactoryTest; |
126 friend class safe_browsing::SafeBrowsingServiceTest; | 125 friend class safe_browsing::SafeBrowsingServiceTest; |
127 | 126 |
128 void ResetActivationState(); | 127 void ResetActivationState(); |
129 | 128 |
130 // content::WebContentsObserver: | 129 // content::WebContentsObserver: |
131 void DidStartNavigation( | 130 void DidStartNavigation( |
132 content::NavigationHandle* navigation_handle) override; | 131 content::NavigationHandle* navigation_handle) override; |
133 void DidRedirectNavigation( | 132 void DidRedirectNavigation( |
134 content::NavigationHandle* navigation_handle) override; | 133 content::NavigationHandle* navigation_handle) override; |
135 | 134 |
136 // Checks base on the value of |url| and current activation scope if | 135 // Checks base on the value of |url| and current activation scope if |
137 // activation signal should be sent. | 136 // activation signal should be sent. |
138 ActivationDecision ComputeActivationDecisionForMainFrameNavigation( | 137 ActivationDecision ComputeActivationDecisionForMainFrameNavigation( |
139 content::NavigationHandle* navigation_handle) const; | 138 content::NavigationHandle* navigation_handle) const; |
140 | 139 |
141 bool DidURLMatchActivationList(const GURL& url, | 140 bool DidURLMatchActivationList(const GURL& url, |
142 ActivationList activation_list) const; | 141 ActivationList activation_list) const; |
143 | 142 |
144 void AddActivationListMatch(const GURL& url, ActivationList match_type); | 143 void AddActivationListMatch(const GURL& url, ActivationList match_type); |
145 int CalculateHitPatternForActivationList( | 144 int CalculateHitPatternForActivationList( |
146 ActivationList activation_list) const; | 145 ActivationList activation_list) const; |
147 void RecordRedirectChainMatchPattern() const; | 146 void RecordRedirectChainMatchPattern() const; |
148 | 147 |
149 void RecordRedirectChainMatchPatternForList( | 148 void RecordRedirectChainMatchPatternForList( |
150 ActivationList activation_list) const; | 149 ActivationList activation_list) const; |
151 | 150 |
152 std::unique_ptr<SubresourceFilterClient> client_; | 151 // Must outlive this class. |
152 SubresourceFilterClient* client_; | |
153 | 153 |
154 std::unique_ptr<ContentSubresourceFilterThrottleManager> throttle_manager_; | 154 std::unique_ptr<ContentSubresourceFilterThrottleManager> throttle_manager_; |
155 | 155 |
156 ActivationLevel activation_level_; | 156 ActivationLevel activation_level_; |
157 ActivationDecision activation_decision_; | 157 ActivationDecision activation_decision_; |
158 bool measure_performance_; | 158 bool measure_performance_; |
159 | 159 |
160 // The URLs in the navigation chain. | 160 // The URLs in the navigation chain. |
161 std::vector<GURL> navigation_chain_; | 161 std::vector<GURL> navigation_chain_; |
162 | 162 |
163 URLToActivationListsMap activation_list_matches_; | 163 URLToActivationListsMap activation_list_matches_; |
164 | 164 |
165 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactory); | 165 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactory); |
166 }; | 166 }; |
167 | 167 |
168 } // namespace subresource_filter | 168 } // namespace subresource_filter |
169 | 169 |
170 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FIL TER_DRIVER_FACTORY_H_ | 170 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FIL TER_DRIVER_FACTORY_H_ |
OLD | NEW |