| 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 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 } | 168 } |
| 169 DCHECK(phishing || malware || harmful); | 169 DCHECK(phishing || malware || harmful); |
| 170 if (malware) | 170 if (malware) |
| 171 interstitial_reason_ = SB_REASON_MALWARE; | 171 interstitial_reason_ = SB_REASON_MALWARE; |
| 172 else if (harmful) | 172 else if (harmful) |
| 173 interstitial_reason_ = SB_REASON_HARMFUL; | 173 interstitial_reason_ = SB_REASON_HARMFUL; |
| 174 else | 174 else |
| 175 interstitial_reason_ = SB_REASON_PHISHING; | 175 interstitial_reason_ = SB_REASON_PHISHING; |
| 176 | 176 |
| 177 // This must be done after calculating |interstitial_reason_| above. | 177 // This must be done after calculating |interstitial_reason_| above. |
| 178 uma_helper_.reset(new SecurityInterstitialUmaHelper( | 178 // Use same prefix for UMA as for Rappor. |
| 179 web_contents, request_url(), | 179 metrics_helper_.reset(new SecurityInterstitialMetricsHelper( |
| 180 GetHistogramPrefix(), GetSamplingEventName())); | 180 web_contents, request_url(), GetMetricPrefix(), GetMetricPrefix(), |
| 181 uma_helper_->RecordUserDecision(SecurityInterstitialUmaHelper::SHOW); | 181 SecurityInterstitialMetricsHelper::REPORT_RAPPOR, |
| 182 uma_helper_->RecordUserInteraction( | 182 GetSamplingEventName())); |
| 183 SecurityInterstitialUmaHelper::TOTAL_VISITS); | 183 metrics_helper_->RecordUserDecision(SecurityInterstitialMetricsHelper::SHOW); |
| 184 metrics_helper_->RecordUserInteraction( |
| 185 SecurityInterstitialMetricsHelper::TOTAL_VISITS); |
| 184 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { | 186 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { |
| 185 uma_helper_->RecordUserDecision( | 187 metrics_helper_->RecordUserDecision( |
| 186 SecurityInterstitialUmaHelper::PROCEEDING_DISABLED); | 188 SecurityInterstitialMetricsHelper::PROCEEDING_DISABLED); |
| 187 } | 189 } |
| 188 | 190 |
| 189 if (!is_main_frame_load_blocked_) { | 191 if (!is_main_frame_load_blocked_) { |
| 190 navigation_entry_index_to_remove_ = | 192 navigation_entry_index_to_remove_ = |
| 191 web_contents->GetController().GetLastCommittedEntryIndex(); | 193 web_contents->GetController().GetLastCommittedEntryIndex(); |
| 192 } else { | 194 } else { |
| 193 navigation_entry_index_to_remove_ = -1; | 195 navigation_entry_index_to_remove_ = -1; |
| 194 } | 196 } |
| 195 | 197 |
| 196 // Start computing malware details. They will be sent only | 198 // Start computing malware details. They will be sent only |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 return; | 234 return; |
| 233 } | 235 } |
| 234 | 236 |
| 235 if (command == kDontReportCommand) { | 237 if (command == kDontReportCommand) { |
| 236 SetReportingPreference(false); | 238 SetReportingPreference(false); |
| 237 return; | 239 return; |
| 238 } | 240 } |
| 239 | 241 |
| 240 if (command == kLearnMoreCommand) { | 242 if (command == kLearnMoreCommand) { |
| 241 // User pressed "Learn more". | 243 // User pressed "Learn more". |
| 242 uma_helper_->RecordUserInteraction( | 244 metrics_helper_->RecordUserInteraction( |
| 243 SecurityInterstitialUmaHelper::SHOW_LEARN_MORE); | 245 SecurityInterstitialMetricsHelper::SHOW_LEARN_MORE); |
| 244 GURL learn_more_url( | 246 GURL learn_more_url( |
| 245 interstitial_reason_ == SB_REASON_PHISHING ? | 247 interstitial_reason_ == SB_REASON_PHISHING ? |
| 246 kLearnMorePhishingUrlV2 : kLearnMoreMalwareUrlV2); | 248 kLearnMorePhishingUrlV2 : kLearnMoreMalwareUrlV2); |
| 247 learn_more_url = google_util::AppendGoogleLocaleParam( | 249 learn_more_url = google_util::AppendGoogleLocaleParam( |
| 248 learn_more_url, g_browser_process->GetApplicationLocale()); | 250 learn_more_url, g_browser_process->GetApplicationLocale()); |
| 249 OpenURLParams params(learn_more_url, | 251 OpenURLParams params(learn_more_url, |
| 250 Referrer(), | 252 Referrer(), |
| 251 CURRENT_TAB, | 253 CURRENT_TAB, |
| 252 ui::PAGE_TRANSITION_LINK, | 254 ui::PAGE_TRANSITION_LINK, |
| 253 false); | 255 false); |
| 254 web_contents()->OpenURL(params); | 256 web_contents()->OpenURL(params); |
| 255 return; | 257 return; |
| 256 } | 258 } |
| 257 | 259 |
| 258 if (command == kShowPrivacyCommand) { | 260 if (command == kShowPrivacyCommand) { |
| 259 // User pressed "Safe Browsing privacy policy". | 261 // User pressed "Safe Browsing privacy policy". |
| 260 uma_helper_->RecordUserInteraction( | 262 metrics_helper_->RecordUserInteraction( |
| 261 SecurityInterstitialUmaHelper::SHOW_PRIVACY_POLICY); | 263 SecurityInterstitialMetricsHelper::SHOW_PRIVACY_POLICY); |
| 262 GURL privacy_url( | 264 GURL privacy_url( |
| 263 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_URL)); | 265 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_URL)); |
| 264 privacy_url = google_util::AppendGoogleLocaleParam( | 266 privacy_url = google_util::AppendGoogleLocaleParam( |
| 265 privacy_url, g_browser_process->GetApplicationLocale()); | 267 privacy_url, g_browser_process->GetApplicationLocale()); |
| 266 OpenURLParams params(privacy_url, | 268 OpenURLParams params(privacy_url, |
| 267 Referrer(), | 269 Referrer(), |
| 268 CURRENT_TAB, | 270 CURRENT_TAB, |
| 269 ui::PAGE_TRANSITION_LINK, | 271 ui::PAGE_TRANSITION_LINK, |
| 270 false); | 272 false); |
| 271 web_contents()->OpenURL(params); | 273 web_contents()->OpenURL(params); |
| 272 return; | 274 return; |
| 273 } | 275 } |
| 274 | 276 |
| 275 bool proceed_blocked = false; | 277 bool proceed_blocked = false; |
| 276 if (command == kProceedCommand) { | 278 if (command == kProceedCommand) { |
| 277 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { | 279 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { |
| 278 proceed_blocked = true; | 280 proceed_blocked = true; |
| 279 } else { | 281 } else { |
| 280 uma_helper_->RecordUserDecision(SecurityInterstitialUmaHelper::PROCEED); | 282 metrics_helper_->RecordUserDecision( |
| 283 SecurityInterstitialMetricsHelper::PROCEED); |
| 281 interstitial_page()->Proceed(); | 284 interstitial_page()->Proceed(); |
| 282 // |this| has been deleted after Proceed() returns. | 285 // |this| has been deleted after Proceed() returns. |
| 283 return; | 286 return; |
| 284 } | 287 } |
| 285 } | 288 } |
| 286 | 289 |
| 287 if (command == kTakeMeBackCommand || proceed_blocked) { | 290 if (command == kTakeMeBackCommand || proceed_blocked) { |
| 288 // Don't record the user action here because there are other ways of | 291 // Don't record the user action here because there are other ways of |
| 289 // triggering DontProceed, like clicking the back button. | 292 // triggering DontProceed, like clicking the back button. |
| 290 if (is_main_frame_load_blocked_) { | 293 if (is_main_frame_load_blocked_) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 } | 329 } |
| 327 | 330 |
| 328 if (element_index >= unsafe_resources_.size()) { | 331 if (element_index >= unsafe_resources_.size()) { |
| 329 NOTREACHED(); | 332 NOTREACHED(); |
| 330 return; | 333 return; |
| 331 } | 334 } |
| 332 | 335 |
| 333 std::string bad_url_spec = unsafe_resources_[element_index].url.spec(); | 336 std::string bad_url_spec = unsafe_resources_[element_index].url.spec(); |
| 334 if (command == kShowDiagnosticCommand) { | 337 if (command == kShowDiagnosticCommand) { |
| 335 // We're going to take the user to Google's SafeBrowsing diagnostic page. | 338 // We're going to take the user to Google's SafeBrowsing diagnostic page. |
| 336 uma_helper_->RecordUserInteraction( | 339 metrics_helper_->RecordUserInteraction( |
| 337 SecurityInterstitialUmaHelper::SHOW_DIAGNOSTIC); | 340 SecurityInterstitialMetricsHelper::SHOW_DIAGNOSTIC); |
| 338 std::string diagnostic = | 341 std::string diagnostic = |
| 339 base::StringPrintf(kSbDiagnosticUrl, | 342 base::StringPrintf(kSbDiagnosticUrl, |
| 340 net::EscapeQueryParamValue(bad_url_spec, true).c_str()); | 343 net::EscapeQueryParamValue(bad_url_spec, true).c_str()); |
| 341 GURL diagnostic_url(diagnostic); | 344 GURL diagnostic_url(diagnostic); |
| 342 diagnostic_url = google_util::AppendGoogleLocaleParam( | 345 diagnostic_url = google_util::AppendGoogleLocaleParam( |
| 343 diagnostic_url, g_browser_process->GetApplicationLocale()); | 346 diagnostic_url, g_browser_process->GetApplicationLocale()); |
| 344 DCHECK(unsafe_resources_[element_index].threat_type == | 347 DCHECK(unsafe_resources_[element_index].threat_type == |
| 345 SB_THREAT_TYPE_URL_MALWARE || | 348 SB_THREAT_TYPE_URL_MALWARE || |
| 346 unsafe_resources_[element_index].threat_type == | 349 unsafe_resources_[element_index].threat_type == |
| 347 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || | 350 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || |
| 348 unsafe_resources_[element_index].threat_type == | 351 unsafe_resources_[element_index].threat_type == |
| 349 SB_THREAT_TYPE_URL_UNWANTED); | 352 SB_THREAT_TYPE_URL_UNWANTED); |
| 350 OpenURLParams params( | 353 OpenURLParams params( |
| 351 diagnostic_url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_LINK, | 354 diagnostic_url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_LINK, |
| 352 false); | 355 false); |
| 353 web_contents()->OpenURL(params); | 356 web_contents()->OpenURL(params); |
| 354 return; | 357 return; |
| 355 } | 358 } |
| 356 | 359 |
| 357 if (command == kExpandedSeeMoreCommand) { | 360 if (command == kExpandedSeeMoreCommand) { |
| 358 uma_helper_->RecordUserInteraction( | 361 metrics_helper_->RecordUserInteraction( |
| 359 SecurityInterstitialUmaHelper::SHOW_ADVANCED); | 362 SecurityInterstitialMetricsHelper::SHOW_ADVANCED); |
| 360 return; | 363 return; |
| 361 } | 364 } |
| 362 | 365 |
| 363 NOTREACHED() << "Unexpected command: " << command; | 366 NOTREACHED() << "Unexpected command: " << command; |
| 364 } | 367 } |
| 365 | 368 |
| 366 void SafeBrowsingBlockingPage::OverrideRendererPrefs( | 369 void SafeBrowsingBlockingPage::OverrideRendererPrefs( |
| 367 content::RendererPreferences* prefs) { | 370 content::RendererPreferences* prefs) { |
| 368 Profile* profile = Profile::FromBrowserContext( | 371 Profile* profile = Profile::FromBrowserContext( |
| 369 web_contents()->GetBrowserContext()); | 372 web_contents()->GetBrowserContext()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 return is_main_frame_load_blocked_; | 417 return is_main_frame_load_blocked_; |
| 415 } | 418 } |
| 416 | 419 |
| 417 void SafeBrowsingBlockingPage::OnDontProceed() { | 420 void SafeBrowsingBlockingPage::OnDontProceed() { |
| 418 // We could have already called Proceed(), in which case we must not notify | 421 // We could have already called Proceed(), in which case we must not notify |
| 419 // the SafeBrowsingUIManager again, as the client has been deleted. | 422 // the SafeBrowsingUIManager again, as the client has been deleted. |
| 420 if (proceeded_) | 423 if (proceeded_) |
| 421 return; | 424 return; |
| 422 | 425 |
| 423 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { | 426 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { |
| 424 uma_helper_->RecordUserDecision( | 427 metrics_helper_->RecordUserDecision( |
| 425 SecurityInterstitialUmaHelper::DONT_PROCEED); | 428 SecurityInterstitialMetricsHelper::DONT_PROCEED); |
| 426 } | 429 } |
| 427 | 430 |
| 428 // Send the malware details, if we opted to. | 431 // Send the malware details, if we opted to. |
| 429 FinishMalwareDetails(0); // No delay | 432 FinishMalwareDetails(0); // No delay |
| 430 | 433 |
| 431 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, false); | 434 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, false); |
| 432 | 435 |
| 433 // The user does not want to proceed, clear the queued unsafe resources | 436 // The user does not want to proceed, clear the queued unsafe resources |
| 434 // notifications we received while the interstitial was showing. | 437 // notifications we received while the interstitial was showing. |
| 435 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 438 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 // load, since they happen after the page is finished loading. | 551 // load, since they happen after the page is finished loading. |
| 549 if (unsafe_resources[0].threat_type == | 552 if (unsafe_resources[0].threat_type == |
| 550 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL) { | 553 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL) { |
| 551 return false; | 554 return false; |
| 552 } | 555 } |
| 553 | 556 |
| 554 // Otherwise, check the threat type. | 557 // Otherwise, check the threat type. |
| 555 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource; | 558 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource; |
| 556 } | 559 } |
| 557 | 560 |
| 558 std::string SafeBrowsingBlockingPage::GetHistogramPrefix() const { | 561 std::string SafeBrowsingBlockingPage::GetMetricPrefix() const { |
| 559 switch (interstitial_reason_) { | 562 switch (interstitial_reason_) { |
| 560 case SB_REASON_MALWARE: | 563 case SB_REASON_MALWARE: |
| 561 return "malware"; | 564 return "malware"; |
| 562 case SB_REASON_HARMFUL: | 565 case SB_REASON_HARMFUL: |
| 563 return "harmful"; | 566 return "harmful"; |
| 564 case SB_REASON_PHISHING: | 567 case SB_REASON_PHISHING: |
| 565 return "phishing"; | 568 return "phishing"; |
| 566 } | 569 } |
| 567 NOTREACHED(); | 570 NOTREACHED(); |
| 568 return std::string(); | 571 return std::string(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 load_time_data->SetString( | 702 load_time_data->SetString( |
| 700 "explanationParagraph", | 703 "explanationParagraph", |
| 701 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH, | 704 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH, |
| 702 GetFormattedHostName())); | 705 GetFormattedHostName())); |
| 703 load_time_data->SetString( | 706 load_time_data->SetString( |
| 704 "finalParagraph", | 707 "finalParagraph", |
| 705 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); | 708 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); |
| 706 | 709 |
| 707 PopulateExtendedReportingOption(load_time_data); | 710 PopulateExtendedReportingOption(load_time_data); |
| 708 } | 711 } |
| OLD | NEW |