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