| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 12 #include "app/resource_bundle.h" | 12 #include "app/resource_bundle.h" |
| 13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/browser_thread.h" | 17 #include "chrome/browser/browser_thread.h" |
| 18 #include "chrome/browser/dom_operation_notification_details.h" | 18 #include "chrome/browser/dom_operation_notification_details.h" |
| 19 #include "chrome/browser/dom_ui/new_tab_ui.h" | 19 #include "chrome/browser/dom_ui/new_tab_ui.h" |
| 20 #include "chrome/browser/google/google_util.h" | 20 #include "chrome/browser/google/google_util.h" |
| 21 #include "chrome/browser/metrics/user_metrics.h" | 21 #include "chrome/browser/metrics/user_metrics.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/profile.h" |
| 24 #include "chrome/browser/safe_browsing/malware_report.h" |
| 22 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 25 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 23 #include "chrome/browser/tab_contents/navigation_controller.h" | 26 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 24 #include "chrome/browser/tab_contents/navigation_entry.h" | 27 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 25 #include "chrome/browser/tab_contents/tab_util.h" | 28 #include "chrome/browser/tab_contents/tab_util.h" |
| 26 #include "chrome/browser/tab_contents/tab_contents.h" | 29 #include "chrome/browser/tab_contents/tab_contents.h" |
| 27 #include "chrome/common/jstemplate_builder.h" | 30 #include "chrome/common/jstemplate_builder.h" |
| 31 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 29 #include "grit/browser_resources.h" | 33 #include "grit/browser_resources.h" |
| 30 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
| 31 #include "grit/locale_settings.h" | 35 #include "grit/locale_settings.h" |
| 32 #include "net/base/escape.h" | 36 #include "net/base/escape.h" |
| 33 | 37 |
| 34 // For malware interstitial pages, we link the problematic URL to Google's | 38 // For malware interstitial pages, we link the problematic URL to Google's |
| 35 // diagnostic page. | 39 // diagnostic page. |
| 36 #if defined(GOOGLE_CHROME_BUILD) | 40 #if defined(GOOGLE_CHROME_BUILD) |
| 37 static const char* const kSbDiagnosticUrl = | 41 static const char* const kSbDiagnosticUrl = |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 98 |
| 95 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( | 99 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( |
| 96 SafeBrowsingService* sb_service, | 100 SafeBrowsingService* sb_service, |
| 97 TabContents* tab_contents, | 101 TabContents* tab_contents, |
| 98 const UnsafeResourceList& unsafe_resources) | 102 const UnsafeResourceList& unsafe_resources) |
| 99 : InterstitialPage(tab_contents, | 103 : InterstitialPage(tab_contents, |
| 100 IsMainPage(unsafe_resources), | 104 IsMainPage(unsafe_resources), |
| 101 unsafe_resources[0].url), | 105 unsafe_resources[0].url), |
| 102 sb_service_(sb_service), | 106 sb_service_(sb_service), |
| 103 is_main_frame_(IsMainPage(unsafe_resources)), | 107 is_main_frame_(IsMainPage(unsafe_resources)), |
| 104 unsafe_resources_(unsafe_resources) { | 108 unsafe_resources_(unsafe_resources), |
| 109 malware_report_(NULL) { |
| 105 RecordUserAction(SHOW); | 110 RecordUserAction(SHOW); |
| 106 if (!is_main_frame_) { | 111 if (!is_main_frame_) { |
| 107 navigation_entry_index_to_remove_ = | 112 navigation_entry_index_to_remove_ = |
| 108 tab()->controller().last_committed_entry_index(); | 113 tab()->controller().last_committed_entry_index(); |
| 109 } else { | 114 } else { |
| 110 navigation_entry_index_to_remove_ = -1; | 115 navigation_entry_index_to_remove_ = -1; |
| 111 } | 116 } |
| 117 |
| 118 // Start computing a detailed malware report. It will be sent only |
| 119 // if the user opts-in on the blocking page later. |
| 120 // If there's more than one malicious resources, it means the user |
| 121 // clicked through the first warning, so we don't prepare additional |
| 122 // reports. |
| 123 if (unsafe_resources.size() == 1 && |
| 124 unsafe_resources[0].threat_type == SafeBrowsingService::URL_MALWARE && |
| 125 malware_report_ == NULL && |
| 126 CanShowMalwareReportOption()) { |
| 127 malware_report_ = new SafeBrowsingMalwareReport(tab(), unsafe_resources[0]); |
| 128 } |
| 129 } |
| 130 |
| 131 bool SafeBrowsingBlockingPage::CanShowMalwareReportOption() { |
| 132 return (!tab()->profile()->IsOffTheRecord() && |
| 133 tab()->GetURL().SchemeIs(chrome::kHttpScheme)); |
| 112 } | 134 } |
| 113 | 135 |
| 114 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { | 136 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { |
| 115 } | 137 } |
| 116 | 138 |
| 117 std::string SafeBrowsingBlockingPage::GetHTMLContents() { | 139 std::string SafeBrowsingBlockingPage::GetHTMLContents() { |
| 118 // Load the HTML page and create the template components. | 140 // Load the HTML page and create the template components. |
| 119 DictionaryValue strings; | 141 DictionaryValue strings; |
| 120 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 142 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 121 std::string html; | 143 std::string html; |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 SafeBrowsingService::URL_MALWARE); | 405 SafeBrowsingService::URL_MALWARE); |
| 384 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); | 406 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); |
| 385 return; | 407 return; |
| 386 } | 408 } |
| 387 | 409 |
| 388 NOTREACHED() << "Unexpected command: " << command; | 410 NOTREACHED() << "Unexpected command: " << command; |
| 389 } | 411 } |
| 390 | 412 |
| 391 void SafeBrowsingBlockingPage::Proceed() { | 413 void SafeBrowsingBlockingPage::Proceed() { |
| 392 RecordUserAction(PROCEED); | 414 RecordUserAction(PROCEED); |
| 415 FinishMalwareReport(); // Send the malware report, if we opted to. |
| 393 | 416 |
| 394 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); | 417 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); |
| 395 | 418 |
| 396 // Check to see if some new notifications of unsafe resources have been | 419 // Check to see if some new notifications of unsafe resources have been |
| 397 // received while we were showing the interstitial. | 420 // received while we were showing the interstitial. |
| 398 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 421 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
| 399 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); | 422 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); |
| 400 SafeBrowsingBlockingPage* blocking_page = NULL; | 423 SafeBrowsingBlockingPage* blocking_page = NULL; |
| 401 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { | 424 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { |
| 402 // Build an interstitial for all the unsafe resources notifications. | 425 // Build an interstitial for all the unsafe resources notifications. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 420 // We could have already called Proceed(), in which case we must not notify | 443 // We could have already called Proceed(), in which case we must not notify |
| 421 // the SafeBrowsingService again, as the client has been deleted. | 444 // the SafeBrowsingService again, as the client has been deleted. |
| 422 if (action_taken() == PROCEED_ACTION) { | 445 if (action_taken() == PROCEED_ACTION) { |
| 423 // We still want to hide the interstitial page. | 446 // We still want to hide the interstitial page. |
| 424 InterstitialPage::DontProceed(); | 447 InterstitialPage::DontProceed(); |
| 425 // We are now deleted. | 448 // We are now deleted. |
| 426 return; | 449 return; |
| 427 } | 450 } |
| 428 | 451 |
| 429 RecordUserAction(DONT_PROCEED); | 452 RecordUserAction(DONT_PROCEED); |
| 453 FinishMalwareReport(); // Send the malware report, if we opted to. |
| 430 | 454 |
| 431 NotifySafeBrowsingService(sb_service_, unsafe_resources_, false); | 455 NotifySafeBrowsingService(sb_service_, unsafe_resources_, false); |
| 432 | 456 |
| 433 // The user does not want to proceed, clear the queued unsafe resources | 457 // The user does not want to proceed, clear the queued unsafe resources |
| 434 // notifications we received while the interstitial was showing. | 458 // notifications we received while the interstitial was showing. |
| 435 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 459 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
| 436 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); | 460 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); |
| 437 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { | 461 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { |
| 438 NotifySafeBrowsingService(sb_service_, iter->second, false); | 462 NotifySafeBrowsingService(sb_service_, iter->second, false); |
| 439 unsafe_resource_map->erase(iter); | 463 unsafe_resource_map->erase(iter); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 case DONT_PROCEED: | 509 case DONT_PROCEED: |
| 486 action.append("DontProceed"); | 510 action.append("DontProceed"); |
| 487 break; | 511 break; |
| 488 default: | 512 default: |
| 489 NOTREACHED() << "Unexpected event: " << event; | 513 NOTREACHED() << "Unexpected event: " << event; |
| 490 } | 514 } |
| 491 | 515 |
| 492 UserMetrics::RecordComputedAction(action); | 516 UserMetrics::RecordComputedAction(action); |
| 493 } | 517 } |
| 494 | 518 |
| 519 void SafeBrowsingBlockingPage::FinishMalwareReport() { |
| 520 if (malware_report_ == NULL) { |
| 521 // Not all interstitials have reports (eg phishing). |
| 522 return; |
| 523 } |
| 524 |
| 525 const PrefService::Preference* pref = |
| 526 tab()->profile()->GetPrefs()->FindPreference( |
| 527 prefs::kSafeBrowsingReportingEnabled); |
| 528 |
| 529 bool value; |
| 530 if (pref && pref->GetValue()->GetAsBoolean(&value) && value) { |
| 531 // Give the report object to the service class, so it can send it. |
| 532 BrowserThread::PostTask( |
| 533 BrowserThread::IO, FROM_HERE, |
| 534 NewRunnableMethod( |
| 535 sb_service_, &SafeBrowsingService::SendMalwareReport, |
| 536 malware_report_)); |
| 537 } |
| 538 } |
| 539 |
| 495 // static | 540 // static |
| 496 void SafeBrowsingBlockingPage::NotifySafeBrowsingService( | 541 void SafeBrowsingBlockingPage::NotifySafeBrowsingService( |
| 497 SafeBrowsingService* sb_service, | 542 SafeBrowsingService* sb_service, |
| 498 const UnsafeResourceList& unsafe_resources, | 543 const UnsafeResourceList& unsafe_resources, |
| 499 bool proceed) { | 544 bool proceed) { |
| 500 BrowserThread::PostTask( | 545 BrowserThread::PostTask( |
| 501 BrowserThread::IO, FROM_HERE, | 546 BrowserThread::IO, FROM_HERE, |
| 502 NewRunnableMethod( | 547 NewRunnableMethod( |
| 503 sb_service, &SafeBrowsingService::OnBlockingPageDone, | 548 sb_service, &SafeBrowsingService::OnBlockingPageDone, |
| 504 unsafe_resources, proceed)); | 549 unsafe_resources, proceed)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 592 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
| 548 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); | 593 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); |
| 549 } | 594 } |
| 550 | 595 |
| 551 // static | 596 // static |
| 552 bool SafeBrowsingBlockingPage::IsMainPage( | 597 bool SafeBrowsingBlockingPage::IsMainPage( |
| 553 const UnsafeResourceList& unsafe_resources) { | 598 const UnsafeResourceList& unsafe_resources) { |
| 554 return unsafe_resources.size() == 1 && | 599 return unsafe_resources.size() == 1 && |
| 555 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; | 600 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; |
| 556 } | 601 } |
| OLD | NEW |