| 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> | |
| 9 #include <memory> | 8 #include <memory> |
| 10 #include <set> | |
| 11 #include <string> | |
| 12 #include <utility> | |
| 13 #include <vector> | |
| 14 | 9 |
| 15 #include "base/macros.h" | 10 #include "base/macros.h" |
| 16 #include "base/time/time.h" | |
| 17 #include "components/safe_browsing_db/util.h" | 11 #include "components/safe_browsing_db/util.h" |
| 18 #include "components/subresource_filter/content/browser/content_subresource_filt
er_throttle_manager.h" | 12 #include "components/subresource_filter/content/browser/content_subresource_filt
er_throttle_manager.h" |
| 19 #include "components/subresource_filter/core/browser/subresource_filter_features
.h" | 13 #include "components/subresource_filter/core/browser/subresource_filter_features
.h" |
| 20 #include "components/subresource_filter/core/common/activation_decision.h" | 14 #include "components/subresource_filter/core/common/activation_decision.h" |
| 21 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 22 #include "content/public/browser/web_contents_user_data.h" | 16 #include "content/public/browser/web_contents_user_data.h" |
| 23 #include "ui/base/page_transition_types.h" | 17 #include "ui/base/page_transition_types.h" |
| 24 #include "url/gurl.h" | 18 |
| 19 namespace base { |
| 20 class GURL; |
| 21 } // namespace base |
| 25 | 22 |
| 26 namespace content { | 23 namespace content { |
| 27 class WebContents; | 24 class WebContents; |
| 28 } // namespace content | 25 } // namespace content |
| 29 | 26 |
| 30 namespace safe_browsing { | 27 namespace safe_browsing { |
| 31 class SafeBrowsingServiceTest; | 28 class SafeBrowsingServiceTest; |
| 32 }; | 29 }; |
| 33 | 30 |
| 34 namespace subresource_filter { | 31 namespace subresource_filter { |
| 35 | 32 |
| 36 class SubresourceFilterClient; | 33 class SubresourceFilterClient; |
| 37 enum class ActivationLevel; | 34 enum class ActivationLevel; |
| 38 enum class ActivationList; | 35 enum class ActivationList; |
| 39 | 36 |
| 40 using URLToActivationListsMap = | |
| 41 std::unordered_map<std::string, std::set<ActivationList>>; | |
| 42 | |
| 43 // Controls the activation of subresource filtering for each page load in a | 37 // Controls the activation of subresource filtering for each page load in a |
| 44 // WebContents and is responsible for sending the activation signal to all the | 38 // WebContents and is responsible for sending the activation signal to all the |
| 45 // per-frame SubresourceFilterAgents on the renderer side. | 39 // per-frame SubresourceFilterAgents on the renderer side. |
| 46 class ContentSubresourceFilterDriverFactory | 40 class ContentSubresourceFilterDriverFactory |
| 47 : public content::WebContentsUserData< | 41 : public content::WebContentsUserData< |
| 48 ContentSubresourceFilterDriverFactory>, | 42 ContentSubresourceFilterDriverFactory>, |
| 49 public content::WebContentsObserver, | 43 public content::WebContentsObserver, |
| 50 public ContentSubresourceFilterThrottleManager::Delegate { | 44 public ContentSubresourceFilterThrottleManager::Delegate { |
| 51 public: | 45 public: |
| 52 static void CreateForWebContents(content::WebContents* web_contents, | 46 static void CreateForWebContents(content::WebContents* web_contents, |
| 53 SubresourceFilterClient* client); | 47 SubresourceFilterClient* client); |
| 54 | 48 |
| 55 // Whether the |url|, |referrer|, and |transition| are considered to be | 49 // Whether the |url|, |referrer|, and |transition| are considered to be |
| 56 // associated with a page reload. | 50 // associated with a page reload. |
| 57 static bool NavigationIsPageReload(const GURL& url, | 51 static bool NavigationIsPageReload(const GURL& url, |
| 58 const content::Referrer& referrer, | 52 const content::Referrer& referrer, |
| 59 ui::PageTransition transition); | 53 ui::PageTransition transition); |
| 60 | 54 |
| 61 explicit ContentSubresourceFilterDriverFactory( | 55 explicit ContentSubresourceFilterDriverFactory( |
| 62 content::WebContents* web_contents, | 56 content::WebContents* web_contents, |
| 63 SubresourceFilterClient* client); | 57 SubresourceFilterClient* client); |
| 64 ~ContentSubresourceFilterDriverFactory() override; | 58 ~ContentSubresourceFilterDriverFactory() override; |
| 65 | 59 |
| 66 // Called when Safe Browsing detects that the |url| corresponding to the load | 60 // Called when the Safe Browsing throttle has computed the threat type and |
| 67 // of the main frame belongs to the blacklist with |threat_type|. If the | 61 // metadata for this navigation. Will be called once per navigation before |
| 68 // blacklist is the Safe Browsing Social Engineering ads landing, then |url| | 62 // the ReadyToCommit stage. |
| 69 // and |redirects| are saved. | 63 void OnSafeBrowsingMatchComputed( |
| 70 void OnMainResourceMatchedSafeBrowsingBlacklist( | 64 content::NavigationHandle* navigation_handle, |
| 71 const GURL& url, | |
| 72 safe_browsing::SBThreatType threat_type, | 65 safe_browsing::SBThreatType threat_type, |
| 73 safe_browsing::ThreatPatternType threat_type_metadata); | 66 safe_browsing::ThreatPatternType threat_type_metadata); |
| 74 | 67 |
| 75 // Reloads the page and inserts the host of its URL to the whitelist. | 68 // Reloads the page and inserts the host of its URL to the whitelist. |
| 76 void OnReloadRequested(); | 69 void OnReloadRequested(); |
| 77 | 70 |
| 78 // Returns the |ActivationDecision| for the current main frame | 71 // Returns the |ActivationDecision| for the current main frame |
| 79 // document. | 72 // document. |
| 80 ActivationDecision GetActivationDecisionForLastCommittedPageLoad() const { | 73 ActivationDecision GetActivationDecisionForLastCommittedPageLoad() const { |
| 81 return activation_decision_; | 74 return activation_decision_; |
| 82 } | 75 } |
| 83 | 76 |
| 84 // ContentSubresourceFilterThrottleManager::Delegate: | 77 // ContentSubresourceFilterThrottleManager::Delegate: |
| 85 void OnFirstSubresourceLoadDisallowed() override; | 78 void OnFirstSubresourceLoadDisallowed() override; |
| 86 void WillProcessResponse( | |
| 87 content::NavigationHandle* navigation_handle) override; | |
| 88 | 79 |
| 89 ContentSubresourceFilterThrottleManager* throttle_manager() { | 80 ContentSubresourceFilterThrottleManager* throttle_manager() { |
| 90 return throttle_manager_.get(); | 81 return throttle_manager_.get(); |
| 91 } | 82 } |
| 92 | 83 |
| 93 SubresourceFilterClient* client() { return client_; } | 84 SubresourceFilterClient* client() { return client_; } |
| 94 | 85 |
| 95 private: | 86 private: |
| 96 friend class ContentSubresourceFilterDriverFactoryTest; | 87 friend class ContentSubresourceFilterDriverFactoryTest; |
| 97 friend class safe_browsing::SafeBrowsingServiceTest; | 88 friend class safe_browsing::SafeBrowsingServiceTest; |
| 98 | 89 |
| 99 // content::WebContentsObserver: | 90 // content::WebContentsObserver: |
| 100 void DidStartNavigation( | 91 void DidStartNavigation( |
| 101 content::NavigationHandle* navigation_handle) override; | 92 content::NavigationHandle* navigation_handle) override; |
| 102 void DidFinishNavigation( | 93 void DidFinishNavigation( |
| 103 content::NavigationHandle* navigation_handle) override; | 94 content::NavigationHandle* navigation_handle) override; |
| 104 | 95 |
| 105 // Checks base on the value of |url| and current activation scope if | 96 // Checks base on the value of |url| and current activation scope if |
| 106 // activation signal should be sent. | 97 // activation signal should be sent. |
| 107 void ComputeActivationForMainFrameNavigation( | 98 void ComputeActivationForMainFrameNavigation( |
| 108 content::NavigationHandle* navigation_handle); | 99 content::NavigationHandle* navigation_handle, |
| 100 ActivationList matched_list); |
| 109 | 101 |
| 110 // Returns whether a main-frame navigation to the given |url| satisfies the | 102 // Returns whether a main-frame navigation to the given |url| satisfies the |
| 111 // activation |conditions| of a given configuration, except for |priority|. | 103 // activation |conditions| of a given configuration, except for |priority|. |
| 112 bool DoesMainFrameURLSatisfyActivationConditions( | 104 bool DoesMainFrameURLSatisfyActivationConditions( |
| 113 const GURL& url, | 105 const GURL& url, |
| 114 const Configuration::ActivationConditions& conditions) const; | 106 const Configuration::ActivationConditions& conditions, |
| 115 | 107 ActivationList matched_list) const; |
| 116 bool DidURLMatchActivationList(const GURL& url, | |
| 117 ActivationList activation_list) const; | |
| 118 | |
| 119 void AddActivationListMatch(const GURL& url, ActivationList match_type); | |
| 120 | 108 |
| 121 // Must outlive this class. | 109 // Must outlive this class. |
| 122 SubresourceFilterClient* client_; | 110 SubresourceFilterClient* client_; |
| 123 | 111 |
| 124 std::unique_ptr<ContentSubresourceFilterThrottleManager> throttle_manager_; | 112 std::unique_ptr<ContentSubresourceFilterThrottleManager> throttle_manager_; |
| 125 | 113 |
| 126 // The activation decision corresponding to the most recently _started_ | 114 // The activation decision corresponding to the most recently _started_ |
| 127 // non-same-document navigation in the main frame. | 115 // non-same-document navigation in the main frame. |
| 128 // | 116 // |
| 129 // The value is reset to ActivationDecision::UNKNOWN at the start of each such | 117 // The value is reset to ActivationDecision::UNKNOWN at the start of each such |
| 130 // navigation, and will not be assigned until the navigation successfully | 118 // navigation, and will not be assigned until the navigation successfully |
| 131 // reaches the WillProcessResponse stage (or successfully finishes if | 119 // reaches the WillProcessResponse stage (or successfully finishes if |
| 132 // throttles are not invoked). This means that after a cancelled or otherwise | 120 // throttles are not invoked). This means that after a cancelled or otherwise |
| 133 // unsuccessful navigation, the value will be left at UNKNOWN indefinitely. | 121 // unsuccessful navigation, the value will be left at UNKNOWN indefinitely. |
| 134 ActivationDecision activation_decision_ = | 122 ActivationDecision activation_decision_ = |
| 135 ActivationDecision::ACTIVATION_DISABLED; | 123 ActivationDecision::ACTIVATION_DISABLED; |
| 136 | 124 |
| 137 // The activation options corresponding to the most recently _committed_ | 125 // The activation options corresponding to the most recently _committed_ |
| 138 // non-same-document navigation in the main frame. | 126 // non-same-document navigation in the main frame. |
| 139 // | 127 // |
| 140 // The value corresponding to the previous such navigation will be retained, | 128 // The value corresponding to the previous such navigation will be retained, |
| 141 // and the new value not assigned until a subsequent navigation successfully | 129 // and the new value not assigned until a subsequent navigation successfully |
| 142 // reaches the WillProcessResponse stage (or successfully finishes if | 130 // reaches the WillProcessResponse stage (or successfully finishes if |
| 143 // throttles are not invoked). | 131 // throttles are not invoked). |
| 144 Configuration::ActivationOptions activation_options_; | 132 Configuration::ActivationOptions activation_options_; |
| 145 | 133 |
| 146 URLToActivationListsMap activation_list_matches_; | |
| 147 | |
| 148 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactory); | 134 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactory); |
| 149 }; | 135 }; |
| 150 | 136 |
| 151 } // namespace subresource_filter | 137 } // namespace subresource_filter |
| 152 | 138 |
| 153 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FIL
TER_DRIVER_FACTORY_H_ | 139 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FIL
TER_DRIVER_FACTORY_H_ |
| OLD | NEW |