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