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> |
11 #include <string> | 11 #include <string> |
12 #include <utility> | 12 #include <unordered_map> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/supports_user_data.h" | 16 #include "base/supports_user_data.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "components/safe_browsing_db/util.h" | 18 #include "components/safe_browsing_db/util.h" |
19 #include "components/subresource_filter/content/browser/content_subresource_filt
er_throttle_manager.h" | 19 #include "components/subresource_filter/content/browser/content_subresource_filt
er_throttle_manager.h" |
| 20 #include "components/subresource_filter/core/common/activation_decision.h" |
20 #include "content/public/browser/web_contents_observer.h" | 21 #include "content/public/browser/web_contents_observer.h" |
21 #include "ui/base/page_transition_types.h" | 22 #include "ui/base/page_transition_types.h" |
22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 class WebContents; | 26 class WebContents; |
26 } // namespace content | 27 } // namespace content |
27 | 28 |
28 namespace safe_browsing { | 29 namespace safe_browsing { |
29 class SafeBrowsingServiceTest; | 30 class SafeBrowsingServiceTest; |
30 }; | 31 }; |
31 | 32 |
32 namespace subresource_filter { | 33 namespace subresource_filter { |
33 | 34 |
34 class SubresourceFilterClient; | 35 class SubresourceFilterClient; |
35 enum class ActivationLevel; | 36 enum class ActivationLevel; |
36 enum class ActivationList; | 37 enum class ActivationList; |
37 | 38 |
38 using URLToActivationListsMap = | 39 using URLToActivationListsMap = |
39 std::unordered_map<std::string, std::set<ActivationList>>; | 40 std::unordered_map<std::string, std::set<ActivationList>>; |
40 | 41 |
41 // Controls the activation of subresource filtering for each page load in a | 42 // 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 | 43 // WebContents and is responsible for sending the activation signal to all the |
43 // per-frame SubresourceFilterAgents on the renderer side. | 44 // per-frame SubresourceFilterAgents on the renderer side. |
44 class ContentSubresourceFilterDriverFactory | 45 class ContentSubresourceFilterDriverFactory |
45 : public base::SupportsUserData::Data, | 46 : public base::SupportsUserData::Data, |
46 public content::WebContentsObserver, | 47 public content::WebContentsObserver, |
47 public ContentSubresourceFilterThrottleManager::Delegate { | 48 public ContentSubresourceFilterThrottleManager::Delegate { |
48 public: | 49 public: |
49 // NOTE: ActivationDecision backs a UMA histogram, so it is append-only. | |
50 enum class ActivationDecision { | |
51 // The activation decision is unknown, or not known yet. | |
52 UNKNOWN, | |
53 | |
54 // Subresource filtering was activated. | |
55 ACTIVATED, | |
56 | |
57 // Did not activate because subresource filtering was disabled. | |
58 ACTIVATION_DISABLED, | |
59 | |
60 // Did not activate because the main frame document URL had an unsupported | |
61 // scheme. | |
62 UNSUPPORTED_SCHEME, | |
63 | |
64 // Did not activate because the main frame document URL was whitelisted. | |
65 URL_WHITELISTED, | |
66 | |
67 // Did not activate because the main frame document URL did not match the | |
68 // activation list. | |
69 ACTIVATION_LIST_NOT_MATCHED, | |
70 | |
71 // Max value for enum. | |
72 ACTIVATION_DECISION_MAX | |
73 }; | |
74 | |
75 static void CreateForWebContents( | 50 static void CreateForWebContents( |
76 content::WebContents* web_contents, | 51 content::WebContents* web_contents, |
77 std::unique_ptr<SubresourceFilterClient> client); | 52 std::unique_ptr<SubresourceFilterClient> client); |
78 static ContentSubresourceFilterDriverFactory* FromWebContents( | 53 static ContentSubresourceFilterDriverFactory* FromWebContents( |
79 content::WebContents* web_contents); | 54 content::WebContents* web_contents); |
80 | 55 |
81 // Whether the |url|, |referrer|, and |transition| are considered to be | 56 // Whether the |url|, |referrer|, and |transition| are considered to be |
82 // associated with a page reload. | 57 // associated with a page reload. |
83 static bool NavigationIsPageReload(const GURL& url, | 58 static bool NavigationIsPageReload(const GURL& url, |
84 const content::Referrer& referrer, | 59 const content::Referrer& referrer, |
(...skipping 10 matching lines...) Expand all Loading... |
95 // and |redirects| are saved. | 70 // and |redirects| are saved. |
96 void OnMainResourceMatchedSafeBrowsingBlacklist( | 71 void OnMainResourceMatchedSafeBrowsingBlacklist( |
97 const GURL& url, | 72 const GURL& url, |
98 const std::vector<GURL>& redirect_urls, | 73 const std::vector<GURL>& redirect_urls, |
99 safe_browsing::SBThreatType threat_type, | 74 safe_browsing::SBThreatType threat_type, |
100 safe_browsing::ThreatPatternType threat_type_metadata); | 75 safe_browsing::ThreatPatternType threat_type_metadata); |
101 | 76 |
102 // Reloads the page and inserts the host of its URL to the whitelist. | 77 // Reloads the page and inserts the host of its URL to the whitelist. |
103 void OnReloadRequested(); | 78 void OnReloadRequested(); |
104 | 79 |
105 // Returns the |ActivationDecision| for the current main frame | |
106 // document. | |
107 ActivationDecision GetActivationDecisionForLastCommittedPageLoad() const { | |
108 return activation_decision_; | |
109 } | |
110 | |
111 // ContentSubresourceFilterThrottleManager::Delegate: | 80 // ContentSubresourceFilterThrottleManager::Delegate: |
112 void OnFirstSubresourceLoadDisallowed() override; | 81 void OnFirstSubresourceLoadDisallowed() override; |
113 bool ShouldSuppressActivation( | 82 bool ShouldSuppressActivation( |
114 content::NavigationHandle* navigation_handle) override; | 83 content::NavigationHandle* navigation_handle) override; |
115 void WillProcessResponse( | 84 void WillProcessResponse( |
116 content::NavigationHandle* navigation_handle) override; | 85 content::NavigationHandle* navigation_handle) override; |
117 | 86 |
118 ContentSubresourceFilterThrottleManager* throttle_manager() { | 87 ContentSubresourceFilterThrottleManager* throttle_manager() const { |
119 return throttle_manager_.get(); | 88 return throttle_manager_.get(); |
120 } | 89 } |
121 | 90 |
122 SubresourceFilterClient* client() { return client_.get(); } | 91 SubresourceFilterClient* client() { return client_.get(); } |
123 | 92 |
124 private: | 93 private: |
125 friend class ContentSubresourceFilterDriverFactoryTest; | 94 friend class ContentSubresourceFilterDriverFactoryTest; |
126 friend class safe_browsing::SafeBrowsingServiceTest; | 95 friend class safe_browsing::SafeBrowsingServiceTest; |
127 | 96 |
128 void ResetActivationState(); | 97 void ResetActivationState(); |
(...skipping 17 matching lines...) Expand all Loading... |
146 ActivationList activation_list) const; | 115 ActivationList activation_list) const; |
147 void RecordRedirectChainMatchPattern() const; | 116 void RecordRedirectChainMatchPattern() const; |
148 | 117 |
149 void RecordRedirectChainMatchPatternForList( | 118 void RecordRedirectChainMatchPatternForList( |
150 ActivationList activation_list) const; | 119 ActivationList activation_list) const; |
151 | 120 |
152 std::unique_ptr<SubresourceFilterClient> client_; | 121 std::unique_ptr<SubresourceFilterClient> client_; |
153 | 122 |
154 std::unique_ptr<ContentSubresourceFilterThrottleManager> throttle_manager_; | 123 std::unique_ptr<ContentSubresourceFilterThrottleManager> throttle_manager_; |
155 | 124 |
156 ActivationLevel activation_level_; | |
157 ActivationDecision activation_decision_; | |
158 bool measure_performance_; | |
159 | |
160 // The URLs in the navigation chain. | 125 // The URLs in the navigation chain. |
161 std::vector<GURL> navigation_chain_; | 126 std::vector<GURL> navigation_chain_; |
162 | 127 |
163 URLToActivationListsMap activation_list_matches_; | 128 URLToActivationListsMap activation_list_matches_; |
164 | 129 |
165 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactory); | 130 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactory); |
166 }; | 131 }; |
167 | 132 |
168 } // namespace subresource_filter | 133 } // namespace subresource_filter |
169 | 134 |
170 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FIL
TER_DRIVER_FACTORY_H_ | 135 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FIL
TER_DRIVER_FACTORY_H_ |
OLD | NEW |