OLD | NEW |
---|---|
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 // Implementation of the SafeBrowsingBlockingPage class. | 5 // Implementation of the SafeBrowsingBlockingPage class. |
6 | 6 |
7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
23 #include "base/values.h" | 23 #include "base/values.h" |
24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
25 #include "chrome/browser/history/history_service_factory.h" | |
26 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/renderer_preferences_util.h" | 26 #include "chrome/browser/renderer_preferences_util.h" |
28 #include "chrome/browser/safe_browsing/malware_details.h" | 27 #include "chrome/browser/safe_browsing/malware_details.h" |
29 #include "chrome/browser/safe_browsing/ui_manager.h" | 28 #include "chrome/browser/safe_browsing/ui_manager.h" |
30 #include "chrome/browser/tab_contents/tab_util.h" | 29 #include "chrome/browser/tab_contents/tab_util.h" |
31 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
33 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
34 #include "chrome/grit/generated_resources.h" | 33 #include "chrome/grit/generated_resources.h" |
35 #include "chrome/grit/locale_settings.h" | 34 #include "chrome/grit/locale_settings.h" |
36 #include "components/google/core/browser/google_util.h" | 35 #include "components/google/core/browser/google_util.h" |
37 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
38 #include "content/public/browser/interstitial_page.h" | 37 #include "content/public/browser/interstitial_page.h" |
39 #include "content/public/browser/navigation_controller.h" | 38 #include "content/public/browser/navigation_controller.h" |
40 #include "content/public/browser/user_metrics.h" | 39 #include "content/public/browser/user_metrics.h" |
41 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
42 #include "content/public/common/renderer_preferences.h" | 41 #include "content/public/common/renderer_preferences.h" |
43 #include "grit/browser_resources.h" | 42 #include "grit/browser_resources.h" |
44 #include "net/base/escape.h" | 43 #include "net/base/escape.h" |
45 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
46 | 45 |
47 #if defined(ENABLE_EXTENSIONS) | |
48 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h" | |
49 #endif | |
50 | |
51 using base::UserMetricsAction; | 46 using base::UserMetricsAction; |
52 using content::BrowserThread; | 47 using content::BrowserThread; |
53 using content::InterstitialPage; | 48 using content::InterstitialPage; |
54 using content::OpenURLParams; | 49 using content::OpenURLParams; |
55 using content::Referrer; | 50 using content::Referrer; |
56 using content::WebContents; | 51 using content::WebContents; |
57 | 52 |
58 #if defined(ENABLE_EXTENSIONS) | |
59 using extensions::ExperienceSamplingEvent; | |
60 #endif | |
61 | |
62 namespace { | 53 namespace { |
63 | 54 |
64 // For malware interstitial pages, we link the problematic URL to Google's | 55 // For malware interstitial pages, we link the problematic URL to Google's |
65 // diagnostic page. | 56 // diagnostic page. |
66 #if defined(GOOGLE_CHROME_BUILD) | 57 #if defined(GOOGLE_CHROME_BUILD) |
67 const char kSbDiagnosticUrl[] = | 58 const char kSbDiagnosticUrl[] = |
68 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie nt=googlechrome"; | 59 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie nt=googlechrome"; |
69 #else | 60 #else |
70 const char kSbDiagnosticUrl[] = | 61 const char kSbDiagnosticUrl[] = |
71 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie nt=chromium"; | 62 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie nt=chromium"; |
(...skipping 23 matching lines...) Expand all Loading... | |
95 const char kProceedCommand[] = "proceed"; | 86 const char kProceedCommand[] = "proceed"; |
96 const char kShowDiagnosticCommand[] = "showDiagnostic"; | 87 const char kShowDiagnosticCommand[] = "showDiagnostic"; |
97 const char kShowPrivacyCommand[] = "showPrivacy"; | 88 const char kShowPrivacyCommand[] = "showPrivacy"; |
98 const char kTakeMeBackCommand[] = "takeMeBack"; | 89 const char kTakeMeBackCommand[] = "takeMeBack"; |
99 | 90 |
100 // Other constants used to communicate with the JavaScript. | 91 // Other constants used to communicate with the JavaScript. |
101 const char kBoxChecked[] = "boxchecked"; | 92 const char kBoxChecked[] = "boxchecked"; |
102 const char kDisplayCheckBox[] = "displaycheckbox"; | 93 const char kDisplayCheckBox[] = "displaycheckbox"; |
103 | 94 |
104 // Constants for the Experience Sampling instrumentation. | 95 // Constants for the Experience Sampling instrumentation. |
105 #if defined(ENABLE_EXTENSIONS) | |
106 const char kEventNameMalware[] = "safebrowsing_interstitial_"; | 96 const char kEventNameMalware[] = "safebrowsing_interstitial_"; |
107 const char kEventNameHarmful[] = "harmful_interstitial_"; | 97 const char kEventNameHarmful[] = "harmful_interstitial_"; |
108 const char kEventNamePhishing[] = "phishing_interstitial_"; | 98 const char kEventNamePhishing[] = "phishing_interstitial_"; |
109 const char kEventNameOther[] = "safebrowsing_other_interstitial_"; | 99 const char kEventNameOther[] = "safebrowsing_other_interstitial_"; |
110 #endif | |
111 | 100 |
112 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> | 101 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> |
113 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; | 102 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; |
114 | 103 |
115 } // namespace | 104 } // namespace |
116 | 105 |
117 // static | 106 // static |
118 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; | 107 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; |
119 | 108 |
120 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we | 109 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we |
(...skipping 30 matching lines...) Expand all Loading... | |
151 SafeBrowsingUIManager* ui_manager, | 140 SafeBrowsingUIManager* ui_manager, |
152 WebContents* web_contents, | 141 WebContents* web_contents, |
153 const UnsafeResourceList& unsafe_resources) | 142 const UnsafeResourceList& unsafe_resources) |
154 : SecurityInterstitialPage(web_contents, unsafe_resources[0].url), | 143 : SecurityInterstitialPage(web_contents, unsafe_resources[0].url), |
155 malware_details_proceed_delay_ms_( | 144 malware_details_proceed_delay_ms_( |
156 kMalwareDetailsProceedDelayMilliSeconds), | 145 kMalwareDetailsProceedDelayMilliSeconds), |
157 ui_manager_(ui_manager), | 146 ui_manager_(ui_manager), |
158 report_loop_(NULL), | 147 report_loop_(NULL), |
159 is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)), | 148 is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)), |
160 unsafe_resources_(unsafe_resources), | 149 unsafe_resources_(unsafe_resources), |
161 proceeded_(false), | 150 proceeded_(false) { |
162 num_visits_(-1) { | |
163 bool malware = false; | 151 bool malware = false; |
164 bool harmful = false; | 152 bool harmful = false; |
165 bool phishing = false; | 153 bool phishing = false; |
166 for (UnsafeResourceList::const_iterator iter = unsafe_resources_.begin(); | 154 for (UnsafeResourceList::const_iterator iter = unsafe_resources_.begin(); |
167 iter != unsafe_resources_.end(); ++iter) { | 155 iter != unsafe_resources_.end(); ++iter) { |
168 const UnsafeResource& resource = *iter; | 156 const UnsafeResource& resource = *iter; |
169 SBThreatType threat_type = resource.threat_type; | 157 SBThreatType threat_type = resource.threat_type; |
170 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || | 158 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || |
171 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { | 159 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { |
172 malware = true; | 160 malware = true; |
173 } else if (threat_type == SB_THREAT_TYPE_URL_UNWANTED) { | 161 } else if (threat_type == SB_THREAT_TYPE_URL_UNWANTED) { |
174 harmful = true; | 162 harmful = true; |
175 } else { | 163 } else { |
176 DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING || | 164 DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING || |
177 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL); | 165 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL); |
178 phishing = true; | 166 phishing = true; |
179 } | 167 } |
180 } | 168 } |
181 DCHECK(phishing || malware || harmful); | 169 DCHECK(phishing || malware || harmful); |
182 if (malware) | 170 if (malware) |
183 interstitial_type_ = TYPE_MALWARE; | 171 interstitial_reason_ = SB_REASON_MALWARE; |
184 else if (harmful) | 172 else if (harmful) |
185 interstitial_type_ = TYPE_HARMFUL; | 173 interstitial_reason_ = SB_REASON_HARMFUL; |
186 else | 174 else |
187 interstitial_type_ = TYPE_PHISHING; | 175 interstitial_reason_ = SB_REASON_PHISHING; |
188 | 176 |
189 RecordUserDecision(SHOW); | 177 uma_helper_.reset(new SecurityInterstitialUmaHelper( |
190 RecordUserInteraction(TOTAL_VISITS); | 178 web_contents, request_url(), |
191 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) | 179 GetHistogramPrefix(), GetSamplingEventName())); |
192 RecordUserDecision(PROCEEDING_DISABLED); | 180 uma_helper_->RecordUserDecision(SecurityInterstitialUmaHelper::SHOW); |
193 | 181 uma_helper_->RecordUserInteraction( |
194 HistoryService* history_service = HistoryServiceFactory::GetForProfile( | 182 SecurityInterstitialUmaHelper::TOTAL_VISITS); |
195 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | 183 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { |
196 ServiceAccessType::EXPLICIT_ACCESS); | 184 uma_helper_->RecordUserDecision( |
197 if (history_service) { | 185 SecurityInterstitialUmaHelper::PROCEEDING_DISABLED); |
198 history_service->GetVisibleVisitCountToHost( | |
199 request_url(), | |
200 base::Bind(&SafeBrowsingBlockingPage::OnGotHistoryCount, | |
201 base::Unretained(this)), | |
202 &request_tracker_); | |
203 } | 186 } |
204 | 187 |
205 if (!is_main_frame_load_blocked_) { | 188 if (!is_main_frame_load_blocked_) { |
206 navigation_entry_index_to_remove_ = | 189 navigation_entry_index_to_remove_ = |
207 web_contents->GetController().GetLastCommittedEntryIndex(); | 190 web_contents->GetController().GetLastCommittedEntryIndex(); |
208 } else { | 191 } else { |
209 navigation_entry_index_to_remove_ = -1; | 192 navigation_entry_index_to_remove_ = -1; |
210 } | 193 } |
211 | 194 |
212 // Start computing malware details. They will be sent only | 195 // Start computing malware details. They will be sent only |
213 // if the user opts-in on the blocking page later. | 196 // if the user opts-in on the blocking page later. |
214 // If there's more than one malicious resources, it means the user | 197 // If there's more than one malicious resources, it means the user |
215 // clicked through the first warning, so we don't prepare additional | 198 // clicked through the first warning, so we don't prepare additional |
216 // reports. | 199 // reports. |
217 if (unsafe_resources.size() == 1 && | 200 if (unsafe_resources.size() == 1 && |
218 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE && | 201 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE && |
219 malware_details_.get() == NULL && CanShowMalwareDetailsOption()) { | 202 malware_details_.get() == NULL && CanShowMalwareDetailsOption()) { |
220 malware_details_ = MalwareDetails::NewMalwareDetails( | 203 malware_details_ = MalwareDetails::NewMalwareDetails( |
221 ui_manager_, web_contents, unsafe_resources[0]); | 204 ui_manager_, web_contents, unsafe_resources[0]); |
222 } | 205 } |
223 | |
224 #if defined(ENABLE_EXTENSIONS) | |
225 // ExperienceSampling: Set up new sampling event for this interstitial. | |
226 // This needs to handle all types of warnings this interstitial can show. | |
227 std::string event_name; | |
228 switch (interstitial_type_) { | |
229 case TYPE_MALWARE: | |
230 event_name = kEventNameMalware; | |
231 break; | |
232 case TYPE_HARMFUL: | |
233 event_name = kEventNameHarmful; | |
234 break; | |
235 case TYPE_PHISHING: | |
236 event_name = kEventNamePhishing; | |
237 break; | |
238 default: | |
239 event_name = kEventNameOther; | |
240 break; | |
241 } | |
242 sampling_event_.reset(new ExperienceSamplingEvent( | |
243 event_name, | |
244 request_url(), | |
245 web_contents->GetLastCommittedURL(), | |
246 web_contents->GetBrowserContext())); | |
247 #endif | |
248 } | 206 } |
249 | 207 |
250 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() { | 208 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() { |
251 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() && | 209 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() && |
252 web_contents()->GetURL().SchemeIs(url::kHttpScheme)); | 210 web_contents()->GetURL().SchemeIs(url::kHttpScheme)); |
253 } | 211 } |
254 | 212 |
255 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { | 213 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { |
256 } | 214 } |
257 | 215 |
258 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { | 216 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { |
259 std::string command(cmd); // Make a local copy so we can modify it. | 217 std::string command(cmd); // Make a local copy so we can modify it. |
260 // The Jasonified response has quotes, remove them. | 218 // The Jasonified response has quotes, remove them. |
261 if (command.length() > 1 && command[0] == '"') { | 219 if (command.length() > 1 && command[0] == '"') { |
262 command = command.substr(1, command.length() - 2); | 220 command = command.substr(1, command.length() - 2); |
263 } | 221 } |
264 if (command == kDoReportCommand) { | 222 if (command == kDoReportCommand) { |
265 SetReportingPreference(true); | 223 SetReportingPreference(true); |
266 return; | 224 return; |
267 } | 225 } |
268 | 226 |
269 if (command == kDontReportCommand) { | 227 if (command == kDontReportCommand) { |
270 SetReportingPreference(false); | 228 SetReportingPreference(false); |
271 return; | 229 return; |
272 } | 230 } |
273 | 231 |
274 if (command == kLearnMoreCommand) { | 232 if (command == kLearnMoreCommand) { |
275 // User pressed "Learn more". | 233 // User pressed "Learn more". |
276 RecordUserInteraction(SHOW_LEARN_MORE); | 234 uma_helper_->RecordUserInteraction( |
277 GURL learn_more_url(interstitial_type_ == TYPE_PHISHING ? | 235 SecurityInterstitialUmaHelper::SHOW_LEARN_MORE); |
278 kLearnMorePhishingUrlV2 : kLearnMoreMalwareUrlV2); | 236 GURL learn_more_url( |
237 interstitial_reason_ == SB_REASON_PHISHING ? | |
238 kLearnMorePhishingUrlV2 : kLearnMoreMalwareUrlV2); | |
279 learn_more_url = google_util::AppendGoogleLocaleParam( | 239 learn_more_url = google_util::AppendGoogleLocaleParam( |
280 learn_more_url, g_browser_process->GetApplicationLocale()); | 240 learn_more_url, g_browser_process->GetApplicationLocale()); |
281 OpenURLParams params(learn_more_url, | 241 OpenURLParams params(learn_more_url, |
282 Referrer(), | 242 Referrer(), |
283 CURRENT_TAB, | 243 CURRENT_TAB, |
284 ui::PAGE_TRANSITION_LINK, | 244 ui::PAGE_TRANSITION_LINK, |
285 false); | 245 false); |
286 web_contents()->OpenURL(params); | 246 web_contents()->OpenURL(params); |
287 return; | 247 return; |
288 } | 248 } |
289 | 249 |
290 if (command == kShowPrivacyCommand) { | 250 if (command == kShowPrivacyCommand) { |
291 // User pressed "Safe Browsing privacy policy". | 251 // User pressed "Safe Browsing privacy policy". |
292 RecordUserInteraction(SHOW_PRIVACY_POLICY); | 252 uma_helper_->RecordUserInteraction( |
253 SecurityInterstitialUmaHelper::SHOW_PRIVACY_POLICY); | |
293 GURL privacy_url( | 254 GURL privacy_url( |
294 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_URL)); | 255 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_URL)); |
295 privacy_url = google_util::AppendGoogleLocaleParam( | 256 privacy_url = google_util::AppendGoogleLocaleParam( |
296 privacy_url, g_browser_process->GetApplicationLocale()); | 257 privacy_url, g_browser_process->GetApplicationLocale()); |
297 OpenURLParams params(privacy_url, | 258 OpenURLParams params(privacy_url, |
298 Referrer(), | 259 Referrer(), |
299 CURRENT_TAB, | 260 CURRENT_TAB, |
300 ui::PAGE_TRANSITION_LINK, | 261 ui::PAGE_TRANSITION_LINK, |
301 false); | 262 false); |
302 web_contents()->OpenURL(params); | 263 web_contents()->OpenURL(params); |
303 return; | 264 return; |
304 } | 265 } |
305 | 266 |
306 bool proceed_blocked = false; | 267 bool proceed_blocked = false; |
307 if (command == kProceedCommand) { | 268 if (command == kProceedCommand) { |
308 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { | 269 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { |
309 proceed_blocked = true; | 270 proceed_blocked = true; |
310 } else { | 271 } else { |
311 RecordUserDecision(PROCEED); | 272 uma_helper_->RecordUserDecision(SecurityInterstitialUmaHelper::PROCEED); |
312 interstitial_page()->Proceed(); | 273 interstitial_page()->Proceed(); |
313 // |this| has been deleted after Proceed() returns. | 274 // |this| has been deleted after Proceed() returns. |
314 return; | 275 return; |
315 } | 276 } |
316 } | 277 } |
317 | 278 |
318 if (command == kTakeMeBackCommand || proceed_blocked) { | 279 if (command == kTakeMeBackCommand || proceed_blocked) { |
319 // Don't record the user action here because there are other ways of | 280 // Don't record the user action here because there are other ways of |
320 // triggering DontProceed, like clicking the back button. | 281 // triggering DontProceed, like clicking the back button. |
321 if (is_main_frame_load_blocked_) { | 282 if (is_main_frame_load_blocked_) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 } | 318 } |
358 | 319 |
359 if (element_index >= unsafe_resources_.size()) { | 320 if (element_index >= unsafe_resources_.size()) { |
360 NOTREACHED(); | 321 NOTREACHED(); |
361 return; | 322 return; |
362 } | 323 } |
363 | 324 |
364 std::string bad_url_spec = unsafe_resources_[element_index].url.spec(); | 325 std::string bad_url_spec = unsafe_resources_[element_index].url.spec(); |
365 if (command == kShowDiagnosticCommand) { | 326 if (command == kShowDiagnosticCommand) { |
366 // We're going to take the user to Google's SafeBrowsing diagnostic page. | 327 // We're going to take the user to Google's SafeBrowsing diagnostic page. |
367 RecordUserInteraction(SHOW_DIAGNOSTIC); | 328 uma_helper_->RecordUserInteraction( |
329 SecurityInterstitialUmaHelper::SHOW_DIAGNOSTIC); | |
368 std::string diagnostic = | 330 std::string diagnostic = |
369 base::StringPrintf(kSbDiagnosticUrl, | 331 base::StringPrintf(kSbDiagnosticUrl, |
370 net::EscapeQueryParamValue(bad_url_spec, true).c_str()); | 332 net::EscapeQueryParamValue(bad_url_spec, true).c_str()); |
371 GURL diagnostic_url(diagnostic); | 333 GURL diagnostic_url(diagnostic); |
372 diagnostic_url = google_util::AppendGoogleLocaleParam( | 334 diagnostic_url = google_util::AppendGoogleLocaleParam( |
373 diagnostic_url, g_browser_process->GetApplicationLocale()); | 335 diagnostic_url, g_browser_process->GetApplicationLocale()); |
374 DCHECK(unsafe_resources_[element_index].threat_type == | 336 DCHECK(unsafe_resources_[element_index].threat_type == |
375 SB_THREAT_TYPE_URL_MALWARE || | 337 SB_THREAT_TYPE_URL_MALWARE || |
376 unsafe_resources_[element_index].threat_type == | 338 unsafe_resources_[element_index].threat_type == |
377 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || | 339 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || |
378 unsafe_resources_[element_index].threat_type == | 340 unsafe_resources_[element_index].threat_type == |
379 SB_THREAT_TYPE_URL_UNWANTED); | 341 SB_THREAT_TYPE_URL_UNWANTED); |
380 OpenURLParams params( | 342 OpenURLParams params( |
381 diagnostic_url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_LINK, | 343 diagnostic_url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_LINK, |
382 false); | 344 false); |
383 web_contents()->OpenURL(params); | 345 web_contents()->OpenURL(params); |
384 return; | 346 return; |
385 } | 347 } |
386 | 348 |
387 if (command == kExpandedSeeMoreCommand) { | 349 if (command == kExpandedSeeMoreCommand) { |
388 RecordUserInteraction(SHOW_ADVANCED); | 350 uma_helper_->RecordUserInteraction( |
351 SecurityInterstitialUmaHelper::SHOW_ADVANCED); | |
389 return; | 352 return; |
390 } | 353 } |
391 | 354 |
392 NOTREACHED() << "Unexpected command: " << command; | 355 NOTREACHED() << "Unexpected command: " << command; |
393 } | 356 } |
394 | 357 |
395 void SafeBrowsingBlockingPage::OverrideRendererPrefs( | 358 void SafeBrowsingBlockingPage::OverrideRendererPrefs( |
396 content::RendererPreferences* prefs) { | 359 content::RendererPreferences* prefs) { |
397 Profile* profile = Profile::FromBrowserContext( | 360 Profile* profile = Profile::FromBrowserContext( |
398 web_contents()->GetBrowserContext()); | 361 web_contents()->GetBrowserContext()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const { | 405 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const { |
443 return is_main_frame_load_blocked_; | 406 return is_main_frame_load_blocked_; |
444 } | 407 } |
445 | 408 |
446 void SafeBrowsingBlockingPage::OnDontProceed() { | 409 void SafeBrowsingBlockingPage::OnDontProceed() { |
447 // We could have already called Proceed(), in which case we must not notify | 410 // We could have already called Proceed(), in which case we must not notify |
448 // the SafeBrowsingUIManager again, as the client has been deleted. | 411 // the SafeBrowsingUIManager again, as the client has been deleted. |
449 if (proceeded_) | 412 if (proceeded_) |
450 return; | 413 return; |
451 | 414 |
452 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) | 415 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { |
453 RecordUserDecision(DONT_PROCEED); | 416 uma_helper_->RecordUserDecision( |
417 SecurityInterstitialUmaHelper::DONT_PROCEED); | |
418 } | |
454 | 419 |
455 // Send the malware details, if we opted to. | 420 // Send the malware details, if we opted to. |
456 FinishMalwareDetails(0); // No delay | 421 FinishMalwareDetails(0); // No delay |
457 | 422 |
458 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, false); | 423 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, false); |
459 | 424 |
460 // The user does not want to proceed, clear the queued unsafe resources | 425 // The user does not want to proceed, clear the queued unsafe resources |
461 // notifications we received while the interstitial was showing. | 426 // notifications we received while the interstitial was showing. |
462 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 427 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
463 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents()); | 428 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents()); |
(...skipping 11 matching lines...) Expand all Loading... | |
475 web_contents()->GetController().GetLastCommittedEntryIndex(); | 440 web_contents()->GetController().GetLastCommittedEntryIndex(); |
476 if (navigation_entry_index_to_remove_ != -1 && | 441 if (navigation_entry_index_to_remove_ != -1 && |
477 navigation_entry_index_to_remove_ != last_committed_index && | 442 navigation_entry_index_to_remove_ != last_committed_index && |
478 !web_contents()->IsBeingDestroyed()) { | 443 !web_contents()->IsBeingDestroyed()) { |
479 CHECK(web_contents()->GetController().RemoveEntryAtIndex( | 444 CHECK(web_contents()->GetController().RemoveEntryAtIndex( |
480 navigation_entry_index_to_remove_)); | 445 navigation_entry_index_to_remove_)); |
481 navigation_entry_index_to_remove_ = -1; | 446 navigation_entry_index_to_remove_ = -1; |
482 } | 447 } |
483 } | 448 } |
484 | 449 |
485 void SafeBrowsingBlockingPage::OnGotHistoryCount(bool success, | |
486 int num_visits, | |
487 base::Time first_visit) { | |
488 if (success) | |
489 num_visits_ = num_visits; | |
490 } | |
491 | |
492 void SafeBrowsingBlockingPage::RecordUserDecision(Decision decision) { | |
493 switch (interstitial_type_) { | |
494 case TYPE_MALWARE: | |
495 UMA_HISTOGRAM_ENUMERATION("interstitial.malware.decision", | |
496 decision, | |
497 MAX_DECISION); | |
498 break; | |
499 case TYPE_HARMFUL: | |
500 UMA_HISTOGRAM_ENUMERATION("interstitial.harmful.decision", | |
501 decision, | |
502 MAX_DECISION); | |
503 break; | |
504 case TYPE_PHISHING: | |
505 UMA_HISTOGRAM_ENUMERATION("interstitial.phishing.decision", | |
506 decision, | |
507 MAX_DECISION); | |
508 break; | |
509 } | |
510 | |
511 #if defined(ENABLE_EXTENSIONS) | |
512 if (sampling_event_.get()) { | |
513 switch (decision) { | |
514 case PROCEED: | |
515 sampling_event_->CreateUserDecisionEvent( | |
516 ExperienceSamplingEvent::kProceed); | |
517 break; | |
518 case DONT_PROCEED: | |
519 sampling_event_->CreateUserDecisionEvent( | |
520 ExperienceSamplingEvent::kDeny); | |
521 break; | |
522 case SHOW: | |
523 case PROCEEDING_DISABLED: | |
524 case MAX_DECISION: | |
525 break; | |
526 } | |
527 } | |
528 #endif | |
529 | |
530 // Record additional information about malware sites that users have | |
531 // visited before. | |
532 if (num_visits_ < 1 || interstitial_type_ != TYPE_MALWARE) | |
533 return; | |
534 if (decision == PROCEED || decision == DONT_PROCEED) { | |
535 UMA_HISTOGRAM_ENUMERATION("interstitial.malware.decision.repeat_visit", | |
536 SHOW, | |
537 MAX_DECISION); | |
538 UMA_HISTOGRAM_ENUMERATION("interstitial.malware.decision.repeat_visit", | |
539 decision, | |
540 MAX_DECISION); | |
541 } | |
542 } | |
543 | |
544 void SafeBrowsingBlockingPage::RecordUserInteraction(Interaction interaction) { | |
545 switch (interstitial_type_) { | |
546 case TYPE_MALWARE: | |
547 UMA_HISTOGRAM_ENUMERATION("interstitial.malware.interaction", | |
548 interaction, | |
549 MAX_INTERACTION); | |
550 break; | |
551 case TYPE_HARMFUL: | |
552 UMA_HISTOGRAM_ENUMERATION("interstitial.harmful.interaction", | |
553 interaction, | |
554 MAX_INTERACTION); | |
555 break; | |
556 case TYPE_PHISHING: | |
557 UMA_HISTOGRAM_ENUMERATION("interstitial.phishing.interaction", | |
558 interaction, | |
559 MAX_INTERACTION); | |
560 break; | |
561 } | |
562 | |
563 #if defined(ENABLE_EXTENSIONS) | |
564 if (!sampling_event_.get()) | |
565 return; | |
566 switch (interaction) { | |
567 case SHOW_LEARN_MORE: | |
568 sampling_event_->set_has_viewed_learn_more(true); | |
569 break; | |
570 case SHOW_ADVANCED: | |
571 sampling_event_->set_has_viewed_details(true); | |
572 break; | |
573 case SHOW_PRIVACY_POLICY: | |
574 case SHOW_DIAGNOSTIC: | |
575 case TOTAL_VISITS: | |
576 case MAX_INTERACTION: | |
577 break; | |
578 } | |
579 #endif | |
580 } | |
581 | |
582 void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) { | 450 void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) { |
583 if (malware_details_.get() == NULL) | 451 if (malware_details_.get() == NULL) |
584 return; // Not all interstitials have malware details (eg phishing). | 452 return; // Not all interstitials have malware details (eg phishing). |
585 DCHECK(interstitial_type_ == TYPE_MALWARE); | 453 DCHECK(interstitial_reason_ == SB_REASON_MALWARE); |
Alexei Svitkine (slow)
2015/01/14 22:12:33
Nit: Can this be a DCHECK_EQ?
felt
2015/01/15 06:47:22
Done.
| |
586 | 454 |
587 const bool enabled = | 455 const bool enabled = |
588 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled); | 456 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled); |
589 UMA_HISTOGRAM_BOOLEAN("SB2.ExtendedReportingIsEnabled", enabled); | 457 UMA_HISTOGRAM_BOOLEAN("SB2.ExtendedReportingIsEnabled", enabled); |
590 if (enabled) { | 458 if (enabled) { |
591 // Finish the malware details collection, send it over. | 459 // Finish the malware details collection, send it over. |
592 BrowserThread::PostDelayedTask( | 460 BrowserThread::PostDelayedTask( |
593 BrowserThread::IO, FROM_HERE, | 461 BrowserThread::IO, FROM_HERE, |
594 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), | 462 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), |
595 base::TimeDelta::FromMilliseconds(delay_ms)); | 463 base::TimeDelta::FromMilliseconds(delay_ms)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 // load, since they happen after the page is finished loading. | 540 // load, since they happen after the page is finished loading. |
673 if (unsafe_resources[0].threat_type == | 541 if (unsafe_resources[0].threat_type == |
674 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL) { | 542 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL) { |
675 return false; | 543 return false; |
676 } | 544 } |
677 | 545 |
678 // Otherwise, check the threat type. | 546 // Otherwise, check the threat type. |
679 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource; | 547 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource; |
680 } | 548 } |
681 | 549 |
550 std::string SafeBrowsingBlockingPage::GetHistogramPrefix() const { | |
551 switch (interstitial_reason_) { | |
552 case SB_REASON_MALWARE: | |
553 return "malware"; | |
554 case SB_REASON_HARMFUL: | |
555 return "harmful"; | |
556 case SB_REASON_PHISHING: | |
557 return "phishing"; | |
558 } | |
559 NOTREACHED(); | |
palmer
2015/01/15 01:09:32
Do you have to return string() here, for non-Debug
felt
2015/01/15 06:47:22
Good question.
| |
560 } | |
561 | |
562 std::string SafeBrowsingBlockingPage::GetSamplingEventName() const { | |
563 switch (interstitial_reason_) { | |
564 case SB_REASON_MALWARE: | |
565 return kEventNameMalware; | |
566 case SB_REASON_HARMFUL: | |
567 return kEventNameHarmful; | |
568 case SB_REASON_PHISHING: | |
569 return kEventNamePhishing; | |
570 default: | |
571 return kEventNameOther; | |
572 } | |
573 NOTREACHED(); | |
574 } | |
575 | |
682 void SafeBrowsingBlockingPage::PopulateInterstitialStrings( | 576 void SafeBrowsingBlockingPage::PopulateInterstitialStrings( |
683 base::DictionaryValue* load_time_data) { | 577 base::DictionaryValue* load_time_data) { |
684 CHECK(load_time_data); | 578 CHECK(load_time_data); |
685 CHECK(!unsafe_resources_.empty()); | 579 CHECK(!unsafe_resources_.empty()); |
686 | 580 |
687 load_time_data->SetString("type", "SAFEBROWSING"); | 581 load_time_data->SetString("type", "SAFEBROWSING"); |
688 load_time_data->SetString( | 582 load_time_data->SetString( |
689 "tabTitle", l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_TITLE)); | 583 "tabTitle", l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_TITLE)); |
690 load_time_data->SetString( | 584 load_time_data->SetString( |
691 "openDetails", | 585 "openDetails", |
692 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_OPEN_DETAILS_BUTTON)); | 586 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_OPEN_DETAILS_BUTTON)); |
693 load_time_data->SetString( | 587 load_time_data->SetString( |
694 "closeDetails", | 588 "closeDetails", |
695 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_CLOSE_DETAILS_BUTTON)); | 589 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_CLOSE_DETAILS_BUTTON)); |
696 load_time_data->SetString( | 590 load_time_data->SetString( |
697 "primaryButtonText", | 591 "primaryButtonText", |
698 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_OVERRIDABLE_SAFETY_BUTTON)); | 592 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_OVERRIDABLE_SAFETY_BUTTON)); |
699 load_time_data->SetBoolean( | 593 load_time_data->SetBoolean( |
700 "overridable", | 594 "overridable", |
701 !IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)); | 595 !IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)); |
702 | 596 |
703 switch (interstitial_type_) { | 597 switch (interstitial_reason_) { |
704 case TYPE_MALWARE: | 598 case SB_REASON_MALWARE: |
705 PopulateMalwareLoadTimeData(load_time_data); | 599 PopulateMalwareLoadTimeData(load_time_data); |
706 break; | 600 break; |
707 case TYPE_HARMFUL: | 601 case SB_REASON_HARMFUL: |
708 PopulateHarmfulLoadTimeData(load_time_data); | 602 PopulateHarmfulLoadTimeData(load_time_data); |
709 break; | 603 break; |
710 case TYPE_PHISHING: | 604 case SB_REASON_PHISHING: |
711 PopulatePhishingLoadTimeData(load_time_data); | 605 PopulatePhishingLoadTimeData(load_time_data); |
712 break; | 606 break; |
713 } | 607 } |
714 } | 608 } |
715 | 609 |
716 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption( | 610 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption( |
717 base::DictionaryValue* load_time_data) { | 611 base::DictionaryValue* load_time_data) { |
718 // Only show checkbox if !(HTTPS || incognito-mode). | 612 // Only show checkbox if !(HTTPS || incognito-mode). |
719 const bool show = CanShowMalwareDetailsOption(); | 613 const bool show = CanShowMalwareDetailsOption(); |
720 load_time_data->SetBoolean(kDisplayCheckBox, show); | 614 load_time_data->SetBoolean(kDisplayCheckBox, show); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
797 load_time_data->SetString( | 691 load_time_data->SetString( |
798 "explanationParagraph", | 692 "explanationParagraph", |
799 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH, | 693 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH, |
800 GetFormattedHostName())); | 694 GetFormattedHostName())); |
801 load_time_data->SetString( | 695 load_time_data->SetString( |
802 "finalParagraph", | 696 "finalParagraph", |
803 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); | 697 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); |
804 | 698 |
805 PopulateExtendedReportingOption(load_time_data); | 699 PopulateExtendedReportingOption(load_time_data); |
806 } | 700 } |
OLD | NEW |