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

Side by Side Diff: components/subresource_filter/content/browser/content_subresource_filter_driver_factory.h

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

Powered by Google App Engine
This is Rietveld 408576698