| 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 <utility> |
| 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" | |
| 17 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 18 #include "components/safe_browsing_db/util.h" | 17 #include "components/safe_browsing_db/util.h" |
| 19 #include "components/subresource_filter/content/browser/content_subresource_filt
er_throttle_manager.h" | 18 #include "components/subresource_filter/content/browser/content_subresource_filt
er_throttle_manager.h" |
| 20 #include "content/public/browser/web_contents_observer.h" | 19 #include "content/public/browser/web_contents_observer.h" |
| 20 #include "content/public/browser/web_contents_user_data.h" |
| 21 #include "ui/base/page_transition_types.h" | 21 #include "ui/base/page_transition_types.h" |
| 22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 23 | 23 |
| 24 namespace content { | 24 namespace content { |
| 25 class WebContents; | 25 class WebContents; |
| 26 } // namespace content | 26 } // namespace content |
| 27 | 27 |
| 28 namespace safe_browsing { | 28 namespace safe_browsing { |
| 29 class SafeBrowsingServiceTest; | 29 class SafeBrowsingServiceTest; |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 namespace subresource_filter { | 32 namespace subresource_filter { |
| 33 | 33 |
| 34 class SubresourceFilterClient; | 34 class SubresourceFilterClient; |
| 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 content::WebContentsUserData< |
| 46 ContentSubresourceFilterDriverFactory>, |
| 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 // NOTE: ActivationDecision backs a UMA histogram, so it is append-only. |
| 50 enum class ActivationDecision { | 51 enum class ActivationDecision { |
| 51 // The activation decision is unknown, or not known yet. | 52 // The activation decision is unknown, or not known yet. |
| 52 UNKNOWN, | 53 UNKNOWN, |
| 53 | 54 |
| 54 // Subresource filtering was activated. | 55 // Subresource filtering was activated. |
| 55 ACTIVATED, | 56 ACTIVATED, |
| 56 | 57 |
| 57 // Did not activate because subresource filtering was disabled. | 58 // Did not activate because subresource filtering was disabled. |
| 58 ACTIVATION_DISABLED, | 59 ACTIVATION_DISABLED, |
| 59 | 60 |
| 60 // Did not activate because the main frame document URL had an unsupported | 61 // Did not activate because the main frame document URL had an unsupported |
| 61 // scheme. | 62 // scheme. |
| 62 UNSUPPORTED_SCHEME, | 63 UNSUPPORTED_SCHEME, |
| 63 | 64 |
| 64 // Did not activate because the main frame document URL was whitelisted. | 65 // Did not activate because the main frame document URL was whitelisted. |
| 65 URL_WHITELISTED, | 66 URL_WHITELISTED, |
| 66 | 67 |
| 67 // Did not activate because the main frame document URL did not match the | 68 // Did not activate because the main frame document URL did not match the |
| 68 // activation list. | 69 // activation list. |
| 69 ACTIVATION_LIST_NOT_MATCHED, | 70 ACTIVATION_LIST_NOT_MATCHED, |
| 70 | 71 |
| 71 // Max value for enum. | 72 // Max value for enum. |
| 72 ACTIVATION_DECISION_MAX | 73 ACTIVATION_DECISION_MAX |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 static void CreateForWebContents( | 76 static void CreateForWebContents(content::WebContents* web_contents, |
| 76 content::WebContents* web_contents, | 77 SubresourceFilterClient* client); |
| 77 std::unique_ptr<SubresourceFilterClient> client); | |
| 78 static ContentSubresourceFilterDriverFactory* FromWebContents( | |
| 79 content::WebContents* web_contents); | |
| 80 | 78 |
| 81 // Whether the |url|, |referrer|, and |transition| are considered to be | 79 // Whether the |url|, |referrer|, and |transition| are considered to be |
| 82 // associated with a page reload. | 80 // associated with a page reload. |
| 83 static bool NavigationIsPageReload(const GURL& url, | 81 static bool NavigationIsPageReload(const GURL& url, |
| 84 const content::Referrer& referrer, | 82 const content::Referrer& referrer, |
| 85 ui::PageTransition transition); | 83 ui::PageTransition transition); |
| 86 | 84 |
| 87 explicit ContentSubresourceFilterDriverFactory( | 85 explicit ContentSubresourceFilterDriverFactory( |
| 88 content::WebContents* web_contents, | 86 content::WebContents* web_contents, |
| 89 std::unique_ptr<SubresourceFilterClient> client); | 87 SubresourceFilterClient* client); |
| 90 ~ContentSubresourceFilterDriverFactory() override; | 88 ~ContentSubresourceFilterDriverFactory() override; |
| 91 | 89 |
| 92 // Called when Safe Browsing detects that the |url| corresponding to the load | 90 // 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 | 91 // 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| | 92 // blacklist is the Safe Browsing Social Engineering ads landing, then |url| |
| 95 // and |redirects| are saved. | 93 // and |redirects| are saved. |
| 96 void OnMainResourceMatchedSafeBrowsingBlacklist( | 94 void OnMainResourceMatchedSafeBrowsingBlacklist( |
| 97 const GURL& url, | 95 const GURL& url, |
| 98 const std::vector<GURL>& redirect_urls, | 96 const std::vector<GURL>& redirect_urls, |
| 99 safe_browsing::SBThreatType threat_type, | 97 safe_browsing::SBThreatType threat_type, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 112 void OnFirstSubresourceLoadDisallowed() override; | 110 void OnFirstSubresourceLoadDisallowed() override; |
| 113 bool ShouldSuppressActivation( | 111 bool ShouldSuppressActivation( |
| 114 content::NavigationHandle* navigation_handle) override; | 112 content::NavigationHandle* navigation_handle) override; |
| 115 void WillProcessResponse( | 113 void WillProcessResponse( |
| 116 content::NavigationHandle* navigation_handle) override; | 114 content::NavigationHandle* navigation_handle) override; |
| 117 | 115 |
| 118 ContentSubresourceFilterThrottleManager* throttle_manager() { | 116 ContentSubresourceFilterThrottleManager* throttle_manager() { |
| 119 return throttle_manager_.get(); | 117 return throttle_manager_.get(); |
| 120 } | 118 } |
| 121 | 119 |
| 122 SubresourceFilterClient* client() { return client_.get(); } | 120 SubresourceFilterClient* client() { return client_; } |
| 123 | 121 |
| 124 private: | 122 private: |
| 125 friend class ContentSubresourceFilterDriverFactoryTest; | 123 friend class ContentSubresourceFilterDriverFactoryTest; |
| 126 friend class safe_browsing::SafeBrowsingServiceTest; | 124 friend class safe_browsing::SafeBrowsingServiceTest; |
| 127 | 125 |
| 128 void ResetActivationState(); | 126 void ResetActivationState(); |
| 129 | 127 |
| 130 // content::WebContentsObserver: | 128 // content::WebContentsObserver: |
| 131 void DidStartNavigation( | 129 void DidStartNavigation( |
| 132 content::NavigationHandle* navigation_handle) override; | 130 content::NavigationHandle* navigation_handle) override; |
| 133 void DidRedirectNavigation( | 131 void DidRedirectNavigation( |
| 134 content::NavigationHandle* navigation_handle) override; | 132 content::NavigationHandle* navigation_handle) override; |
| 135 | 133 |
| 136 // Checks base on the value of |url| and current activation scope if | 134 // Checks base on the value of |url| and current activation scope if |
| 137 // activation signal should be sent. | 135 // activation signal should be sent. |
| 138 ActivationDecision ComputeActivationDecisionForMainFrameNavigation( | 136 ActivationDecision ComputeActivationDecisionForMainFrameNavigation( |
| 139 content::NavigationHandle* navigation_handle) const; | 137 content::NavigationHandle* navigation_handle) const; |
| 140 | 138 |
| 141 bool DidURLMatchActivationList(const GURL& url, | 139 bool DidURLMatchActivationList(const GURL& url, |
| 142 ActivationList activation_list) const; | 140 ActivationList activation_list) const; |
| 143 | 141 |
| 144 void AddActivationListMatch(const GURL& url, ActivationList match_type); | 142 void AddActivationListMatch(const GURL& url, ActivationList match_type); |
| 145 int CalculateHitPatternForActivationList( | 143 int CalculateHitPatternForActivationList( |
| 146 ActivationList activation_list) const; | 144 ActivationList activation_list) const; |
| 147 void RecordRedirectChainMatchPattern() const; | 145 void RecordRedirectChainMatchPattern() const; |
| 148 | 146 |
| 149 void RecordRedirectChainMatchPatternForList( | 147 void RecordRedirectChainMatchPatternForList( |
| 150 ActivationList activation_list) const; | 148 ActivationList activation_list) const; |
| 151 | 149 |
| 152 std::unique_ptr<SubresourceFilterClient> client_; | 150 // Must outlive this class. |
| 151 SubresourceFilterClient* client_; |
| 153 | 152 |
| 154 std::unique_ptr<ContentSubresourceFilterThrottleManager> throttle_manager_; | 153 std::unique_ptr<ContentSubresourceFilterThrottleManager> throttle_manager_; |
| 155 | 154 |
| 156 ActivationLevel activation_level_; | 155 ActivationLevel activation_level_; |
| 157 ActivationDecision activation_decision_; | 156 ActivationDecision activation_decision_; |
| 158 bool measure_performance_; | 157 bool measure_performance_; |
| 159 | 158 |
| 160 // The URLs in the navigation chain. | 159 // The URLs in the navigation chain. |
| 161 std::vector<GURL> navigation_chain_; | 160 std::vector<GURL> navigation_chain_; |
| 162 | 161 |
| 163 URLToActivationListsMap activation_list_matches_; | 162 URLToActivationListsMap activation_list_matches_; |
| 164 | 163 |
| 165 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactory); | 164 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactory); |
| 166 }; | 165 }; |
| 167 | 166 |
| 168 } // namespace subresource_filter | 167 } // namespace subresource_filter |
| 169 | 168 |
| 170 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FIL
TER_DRIVER_FACTORY_H_ | 169 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FIL
TER_DRIVER_FACTORY_H_ |
| OLD | NEW |