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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page.h

Issue 2575623002: Componentizing SafeBrowsingBlockingPage Part 1 (Closed)
Patch Set: nits Created 4 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Classes for managing the SafeBrowsing interstitial pages. 5 // Classes for managing the SafeBrowsing interstitial pages.
6 // 6 //
7 // When a user is about to visit a page the SafeBrowsing system has deemed to 7 // When a user is about to visit a page the SafeBrowsing system has deemed to
8 // be malicious, either as malware or a phishing page, we show an interstitial 8 // be malicious, either as malware or a phishing page, we show an interstitial
9 // page with some options (go back, continue) to give the user a chance to avoid 9 // page with some options (go back, continue) to give the user a chance to avoid
10 // the harmful page. 10 // the harmful page.
(...skipping 22 matching lines...) Expand all
33 #include <vector> 33 #include <vector>
34 34
35 #include <stdint.h> 35 #include <stdint.h>
36 36
37 #include "base/gtest_prod_util.h" 37 #include "base/gtest_prod_util.h"
38 #include "base/macros.h" 38 #include "base/macros.h"
39 #include "base/task/cancelable_task_tracker.h" 39 #include "base/task/cancelable_task_tracker.h"
40 #include "chrome/browser/interstitials/chrome_metrics_helper.h" 40 #include "chrome/browser/interstitials/chrome_metrics_helper.h"
41 #include "chrome/browser/interstitials/security_interstitial_page.h" 41 #include "chrome/browser/interstitials/security_interstitial_page.h"
42 #include "chrome/browser/safe_browsing/ui_manager.h" 42 #include "chrome/browser/safe_browsing/ui_manager.h"
43 #include "components/security_interstitials/core/safe_browsing_error_ui.h"
43 #include "content/public/browser/interstitial_page_delegate.h" 44 #include "content/public/browser/interstitial_page_delegate.h"
44 #include "url/gurl.h" 45 #include "url/gurl.h"
45 46
46 namespace safe_browsing { 47 namespace safe_browsing {
47 48
48 class SafeBrowsingBlockingPageFactory; 49 class SafeBrowsingBlockingPageFactory;
49 class ThreatDetails; 50 class ThreatDetails;
50 51
51 class SafeBrowsingBlockingPage : public SecurityInterstitialPage { 52 class SafeBrowsingBlockingPage : public SecurityInterstitialPage {
52 public: 53 public:
53 typedef security_interstitials::UnsafeResource UnsafeResource; 54 typedef security_interstitials::UnsafeResource UnsafeResource;
55 typedef security_interstitials::SafeBrowsingErrorUI SafeBrowsingErrorUI;
54 typedef std::vector<UnsafeResource> UnsafeResourceList; 56 typedef std::vector<UnsafeResource> UnsafeResourceList;
55 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; 57 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap;
56 58
57 // Interstitial type, used in tests. 59 // Interstitial type, used in tests.
58 static content::InterstitialPageDelegate::TypeID kTypeForTesting; 60 static content::InterstitialPageDelegate::TypeID kTypeForTesting;
59 61
60 ~SafeBrowsingBlockingPage() override; 62 ~SafeBrowsingBlockingPage() override;
61 63
62 // Creates a blocking page. Use ShowBlockingPage if you don't need to access 64 // Creates a blocking page. Use ShowBlockingPage if you don't need to access
63 // the blocking page directly. 65 // the blocking page directly.
(...skipping 21 matching lines...) Expand all
85 void OnProceed() override; 87 void OnProceed() override;
86 void OnDontProceed() override; 88 void OnDontProceed() override;
87 void CommandReceived(const std::string& command) override; 89 void CommandReceived(const std::string& command) override;
88 void OverrideRendererPrefs(content::RendererPreferences* prefs) override; 90 void OverrideRendererPrefs(content::RendererPreferences* prefs) override;
89 content::InterstitialPageDelegate::TypeID GetTypeForTesting() const override; 91 content::InterstitialPageDelegate::TypeID GetTypeForTesting() const override;
90 92
91 // Checks the threat type to decide if we should report ThreatDetails. 93 // Checks the threat type to decide if we should report ThreatDetails.
92 static bool ShouldReportThreatDetails(SBThreatType threat_type); 94 static bool ShouldReportThreatDetails(SBThreatType threat_type);
93 95
94 protected: 96 protected:
97 friend class SafeBrowsingBlockingPageFactoryImpl;
95 friend class SafeBrowsingBlockingPageTest; 98 friend class SafeBrowsingBlockingPageTest;
96 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, 99 FRIEND_TEST_ALL_PREFIXES(
97 ProceedThenDontProceed); 100 SafeBrowsingBlockingPageTest,
98 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, 101 ProceedThenDontProceed);
99 MalwareReportsDisabled); 102 FRIEND_TEST_ALL_PREFIXES(
100 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, 103 SafeBrowsingBlockingPageTest,
101 MalwareReportsToggling); 104 MalwareReportsDisabled);
102 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, 105 FRIEND_TEST_ALL_PREFIXES(
103 ExtendedReportingNotShownOnSecurePage); 106 SafeBrowsingBlockingPageTest,
107 MalwareReportsToggling);
108 FRIEND_TEST_ALL_PREFIXES(
109 SafeBrowsingBlockingPageTest,
110 ExtendedReportingNotShownOnSecurePage);
111 FRIEND_TEST_ALL_PREFIXES(
112 SafeBrowsingBlockingPageTest,
113 MalwareReportsTransitionDisabled);
104 FRIEND_TEST_ALL_PREFIXES( 114 FRIEND_TEST_ALL_PREFIXES(
105 SafeBrowsingBlockingPageTest, 115 SafeBrowsingBlockingPageTest,
106 ExtendedReportingNotShownOnSecurePageWithSecureSubresource); 116 ExtendedReportingNotShownOnSecurePageWithSecureSubresource);
107 FRIEND_TEST_ALL_PREFIXES( 117 FRIEND_TEST_ALL_PREFIXES(
108 SafeBrowsingBlockingPageTest, 118 SafeBrowsingBlockingPageTest,
109 ExtendedReportingNotShownOnSecurePageWithInsecureSubresource); 119 ExtendedReportingNotShownOnSecurePageWithInsecureSubresource);
110 FRIEND_TEST_ALL_PREFIXES( 120 FRIEND_TEST_ALL_PREFIXES(
111 SafeBrowsingBlockingPageTest, 121 SafeBrowsingBlockingPageTest,
112 ExtendedReportingOnInsecurePageWithSecureSubresource); 122 ExtendedReportingOnInsecurePageWithSecureSubresource);
113 FRIEND_TEST_ALL_PREFIXES( 123 FRIEND_TEST_ALL_PREFIXES(
(...skipping 12 matching lines...) Expand all
126 bool ShouldCreateNewNavigation() const override; 136 bool ShouldCreateNewNavigation() const override;
127 void PopulateInterstitialStrings( 137 void PopulateInterstitialStrings(
128 base::DictionaryValue* load_time_data) override; 138 base::DictionaryValue* load_time_data) override;
129 139
130 // After a safe browsing interstitial where the user opted-in to the 140 // After a safe browsing interstitial where the user opted-in to the
131 // report but clicked "proceed anyway", we delay the call to 141 // report but clicked "proceed anyway", we delay the call to
132 // ThreatDetails::FinishCollection() by this much time (in 142 // ThreatDetails::FinishCollection() by this much time (in
133 // milliseconds), in order to get data from the blocked resource itself. 143 // milliseconds), in order to get data from the blocked resource itself.
134 int64_t threat_details_proceed_delay_ms_; 144 int64_t threat_details_proceed_delay_ms_;
135 145
136 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest,
137 MalwareReportsTransitionDisabled);
138
139 // Checks if we should even show the threat details option. For example, we 146 // Checks if we should even show the threat details option. For example, we
140 // don't show it in incognito mode. 147 // don't show it in incognito mode.
141 bool CanShowThreatDetailsOption(); 148 bool CanShowThreatDetailsOption();
142 149
143 // Called when the insterstitial is going away. If there is a 150 // Called when the insterstitial is going away. If there is a
144 // pending threat details object, we look at the user's 151 // pending threat details object, we look at the user's
145 // preferences, and if the option to send threat details is 152 // preferences, and if the option to send threat details is
146 // enabled, the report is scheduled to be sent on the |ui_manager_|. 153 // enabled, the report is scheduled to be sent on the |ui_manager_|.
147 void FinishThreatDetails(int64_t delay_ms, bool did_proceed, int num_visits); 154 void FinishThreatDetails(int64_t delay_ms, bool did_proceed, int num_visits);
148 155
149 // A list of SafeBrowsingUIManager::UnsafeResource for a tab that the user 156 // A list of SafeBrowsingUIManager::UnsafeResource for a tab that the user
150 // should be warned about. They are queued when displaying more than one 157 // should be warned about. They are queued when displaying more than one
151 // interstitial at a time. 158 // interstitial at a time.
152 static UnsafeResourceMap* GetUnsafeResourcesMap(); 159 static UnsafeResourceMap* GetUnsafeResourcesMap();
153 160
154 // Returns true if the passed |unsafe_resources| is blocking the load of 161 // Returns true if the passed |unsafe_resources| is blocking the load of
155 // the main page. 162 // the main page.
156 static bool IsMainPageLoadBlocked( 163 static bool IsMainPageLoadBlocked(
157 const UnsafeResourceList& unsafe_resources); 164 const UnsafeResourceList& unsafe_resources);
158 165
159 friend class SafeBrowsingBlockingPageFactoryImpl;
160
161 // For reporting back user actions. 166 // For reporting back user actions.
162 SafeBrowsingUIManager* ui_manager_; 167 SafeBrowsingUIManager* ui_manager_;
163 168
164 // True if the interstitial is blocking the main page because it is on one 169 // For displaying safe browsing interstitial.
165 // of our lists. False if a subresource is being blocked, or in the case of 170 std::unique_ptr<security_interstitials::SafeBrowsingErrorUI> sb_error_ui_;
166 // client-side detection where the interstitial is shown after page load
167 // finishes.
168 bool is_main_frame_load_blocked_;
169 171
170 // The URL of the main frame that caused the warning. 172 // The URL of the main frame that caused the warning.
171 GURL main_frame_url_; 173 GURL main_frame_url_;
172 174
173 // The index of a navigation entry that should be removed when DontProceed() 175 // The index of a navigation entry that should be removed when DontProceed()
174 // is invoked, -1 if not entry should be removed. 176 // is invoked, -1 if not entry should be removed.
175 int navigation_entry_index_to_remove_; 177 int navigation_entry_index_to_remove_;
176 178
177 // The list of unsafe resources this page is warning about. 179 // The list of unsafe resources this page is warning about.
178 UnsafeResourceList unsafe_resources_; 180 UnsafeResourceList unsafe_resources_;
179 181
180 // A ThreatDetails object that we start generating when the 182 // A ThreatDetails object that we start generating when the
181 // blocking page is shown. The object will be sent when the warning 183 // blocking page is shown. The object will be sent when the warning
182 // is gone (if the user enables the feature). 184 // is gone (if the user enables the feature).
183 scoped_refptr<ThreatDetails> threat_details_; 185 scoped_refptr<ThreatDetails> threat_details_;
184 186
185 bool proceeded_; 187 bool proceeded_;
186 188
187 // Which type of Safe Browsing interstitial this is. 189 // Which type of Safe Browsing interstitial this is.
188 enum SBInterstitialReason { 190 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason_;
189 SB_REASON_MALWARE,
190 SB_REASON_HARMFUL,
191 SB_REASON_PHISHING,
192 };
193 SBInterstitialReason interstitial_reason_;
194 191
195 // The factory used to instantiate SafeBrowsingBlockingPage objects. 192 // The factory used to instantiate SafeBrowsingBlockingPage objects.
196 // Useful for tests, so they can provide their own implementation of 193 // Useful for tests, so they can provide their own implementation of
197 // SafeBrowsingBlockingPage. 194 // SafeBrowsingBlockingPage.
198 static SafeBrowsingBlockingPageFactory* factory_; 195 static SafeBrowsingBlockingPageFactory* factory_;
199 196
200 private: 197 private:
201 // Fills the passed dictionary with the values to be passed to the template 198 static std::string GetMetricPrefix(
202 // when creating the HTML. 199 const UnsafeResourceList& unsafe_resources,
203 void PopulateExtendedReportingOption(base::DictionaryValue* load_time_data); 200 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason);
204 void PopulateMalwareLoadTimeData(base::DictionaryValue* load_time_data);
205 void PopulateHarmfulLoadTimeData(base::DictionaryValue* load_time_data);
206 void PopulatePhishingLoadTimeData(base::DictionaryValue* load_time_data);
207
208 static std::string GetMetricPrefix(const UnsafeResourceList& unsafe_resources,
209 SBInterstitialReason interstitial_reason);
210 static std::string GetExtraMetricsSuffix( 201 static std::string GetExtraMetricsSuffix(
211 const UnsafeResourceList& unsafe_resources); 202 const UnsafeResourceList& unsafe_resources);
212 static std::string GetRapporPrefix(SBInterstitialReason interstitial_reason);
213 static std::string GetDeprecatedRapporPrefix(
214 SBInterstitialReason interstitial_reason);
215 static std::string GetSamplingEventName( 203 static std::string GetSamplingEventName(
216 SBInterstitialReason interstitial_reason); 204 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason);
217 205
218 static SBInterstitialReason GetInterstitialReason( 206 static SafeBrowsingErrorUI::SBInterstitialReason GetInterstitialReason(
219 const UnsafeResourceList& unsafe_resources); 207 const UnsafeResourceList& unsafe_resources);
220 208
221 static std::unique_ptr<ChromeMetricsHelper> CreateMetricsHelper( 209 static std::unique_ptr<ChromeMetricsHelper> CreateMetricsHelper(
222 content::WebContents* web_contents, 210 content::WebContents* web_contents,
223 const UnsafeResourceList& unsafe_resources); 211 const UnsafeResourceList& unsafe_resources);
224 212
225 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); 213 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage);
226 }; 214 };
227 215
228 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. 216 // Factory for creating SafeBrowsingBlockingPage. Useful for tests.
229 class SafeBrowsingBlockingPageFactory { 217 class SafeBrowsingBlockingPageFactory {
230 public: 218 public:
231 virtual ~SafeBrowsingBlockingPageFactory() { } 219 virtual ~SafeBrowsingBlockingPageFactory() { }
232 220
233 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( 221 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage(
234 SafeBrowsingUIManager* ui_manager, 222 SafeBrowsingUIManager* ui_manager,
235 content::WebContents* web_contents, 223 content::WebContents* web_contents,
236 const GURL& main_frame_url, 224 const GURL& main_frame_url,
237 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; 225 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0;
238 }; 226 };
239 227
240 } // namespace safe_browsing 228 } // namespace safe_browsing
241 229
242 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ 230 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698