| 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_process.h" |
| 18 #include "chrome/browser/browser_thread.h" | 19 #include "chrome/browser/browser_thread.h" |
| 19 #include "chrome/browser/dom_operation_notification_details.h" | 20 #include "chrome/browser/dom_operation_notification_details.h" |
| 20 #include "chrome/browser/dom_ui/new_tab_ui.h" | 21 #include "chrome/browser/dom_ui/new_tab_ui.h" |
| 21 #include "chrome/browser/google/google_util.h" | 22 #include "chrome/browser/google/google_util.h" |
| 22 #include "chrome/browser/metrics/user_metrics.h" | 23 #include "chrome/browser/metrics/user_metrics.h" |
| 23 #include "chrome/browser/prefs/pref_service.h" | 24 #include "chrome/browser/prefs/pref_service.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/safe_browsing/malware_details.h" | 26 #include "chrome/browser/safe_browsing/malware_details.h" |
| 26 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 27 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 27 #include "chrome/browser/tab_contents/navigation_controller.h" | 28 #include "chrome/browser/tab_contents/navigation_controller.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 static const char* const kPLinkHtml = | 66 static const char* const kPLinkHtml = |
| 66 "<a href=\"\" onclick=\"sendCommand('proceed'); return false;\" " | 67 "<a href=\"\" onclick=\"sendCommand('proceed'); return false;\" " |
| 67 "onmousedown=\"return false;\">%s</a>"; | 68 "onmousedown=\"return false;\">%s</a>"; |
| 68 | 69 |
| 69 // The commands returned by the page when the user performs an action. | 70 // The commands returned by the page when the user performs an action. |
| 70 static const char* const kShowDiagnosticCommand = "showDiagnostic"; | 71 static const char* const kShowDiagnosticCommand = "showDiagnostic"; |
| 71 static const char* const kReportErrorCommand = "reportError"; | 72 static const char* const kReportErrorCommand = "reportError"; |
| 72 static const char* const kLearnMoreCommand = "learnMore"; | 73 static const char* const kLearnMoreCommand = "learnMore"; |
| 73 static const char* const kProceedCommand = "proceed"; | 74 static const char* const kProceedCommand = "proceed"; |
| 74 static const char* const kTakeMeBackCommand = "takeMeBack"; | 75 static const char* const kTakeMeBackCommand = "takeMeBack"; |
| 76 static const char* const kDoReportCommand = "doReport"; |
| 77 static const char* const kDontReportCommand = "dontReport"; |
| 78 static const char* const kDisplayCheckBox = "displaycheckbox"; |
| 79 static const char* const kBoxChecked = "boxchecked"; |
| 75 | 80 |
| 76 // static | 81 // static |
| 77 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; | 82 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; |
| 78 | 83 |
| 79 static base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> | 84 static base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> |
| 80 g_unsafe_resource_map(base::LINKER_INITIALIZED); | 85 g_unsafe_resource_map(base::LINKER_INITIALIZED); |
| 81 | 86 |
| 82 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we | 87 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we |
| 83 // don't leak it. | 88 // don't leak it. |
| 84 class SafeBrowsingBlockingPageFactoryImpl | 89 class SafeBrowsingBlockingPageFactoryImpl |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 UTF8ToUTF16(url().host()), | 314 UTF8ToUTF16(url().host()), |
| 310 UTF8ToUTF16(diagnostic_link)); | 315 UTF8ToUTF16(diagnostic_link)); |
| 311 | 316 |
| 312 strings->SetString("description5", description5); | 317 strings->SetString("description5", description5); |
| 313 | 318 |
| 314 strings->SetString("back_button", | 319 strings->SetString("back_button", |
| 315 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); | 320 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); |
| 316 strings->SetString("proceed_link", | 321 strings->SetString("proceed_link", |
| 317 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK)); | 322 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK)); |
| 318 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 323 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
| 324 |
| 325 if (!CanShowMalwareDetailsOption()) { |
| 326 strings->SetBoolean(kDisplayCheckBox, false); |
| 327 return; |
| 328 } |
| 329 |
| 330 // show the checkbox about sending malware report |
| 331 strings->SetBoolean(kDisplayCheckBox, true); |
| 332 strings->SetString("confirm_text", |
| 333 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE)); |
| 334 |
| 335 const PrefService::Preference* pref = |
| 336 tab()->profile()->GetPrefs()->FindPreference( |
| 337 prefs::kSafeBrowsingReportingEnabled); |
| 338 bool value; |
| 339 if (pref && pref->GetValue()->GetAsBoolean(&value) && value) { |
| 340 strings->SetString(kBoxChecked, "yes"); |
| 341 } else { |
| 342 strings->SetString(kBoxChecked, ""); |
| 343 } |
| 319 } | 344 } |
| 320 | 345 |
| 321 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( | 346 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( |
| 322 DictionaryValue* strings) { | 347 DictionaryValue* strings) { |
| 323 std::string proceed_link = StringPrintf(kPLinkHtml, l10n_util::GetStringUTF8( | 348 std::string proceed_link = StringPrintf(kPLinkHtml, l10n_util::GetStringUTF8( |
| 324 IDS_SAFE_BROWSING_PHISHING_PROCEED_LINK).c_str()); | 349 IDS_SAFE_BROWSING_PHISHING_PROCEED_LINK).c_str()); |
| 325 string16 description3 = l10n_util::GetStringFUTF16( | 350 string16 description3 = l10n_util::GetStringFUTF16( |
| 326 IDS_SAFE_BROWSING_PHISHING_DESCRIPTION3, | 351 IDS_SAFE_BROWSING_PHISHING_DESCRIPTION3, |
| 327 UTF8ToUTF16(proceed_link)); | 352 UTF8ToUTF16(proceed_link)); |
| 328 | 353 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 342 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 367 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
| 343 } | 368 } |
| 344 | 369 |
| 345 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { | 370 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { |
| 346 std::string command(cmd); // Make a local copy so we can modify it. | 371 std::string command(cmd); // Make a local copy so we can modify it. |
| 347 // The Jasonified response has quotes, remove them. | 372 // The Jasonified response has quotes, remove them. |
| 348 if (command.length() > 1 && command[0] == '"') { | 373 if (command.length() > 1 && command[0] == '"') { |
| 349 command = command.substr(1, command.length() - 2); | 374 command = command.substr(1, command.length() - 2); |
| 350 } | 375 } |
| 351 | 376 |
| 377 if (command == kDoReportCommand) { |
| 378 SetReportingPreference(true); |
| 379 return; |
| 380 } |
| 381 |
| 382 if (command == kDontReportCommand) { |
| 383 SetReportingPreference(false); |
| 384 return; |
| 385 } |
| 386 |
| 352 if (command == kLearnMoreCommand) { | 387 if (command == kLearnMoreCommand) { |
| 353 // User pressed "Learn more". | 388 // User pressed "Learn more". |
| 354 GURL url; | 389 GURL url; |
| 355 if (unsafe_resources_[0].threat_type == SafeBrowsingService::URL_MALWARE) { | 390 if (unsafe_resources_[0].threat_type == SafeBrowsingService::URL_MALWARE) { |
| 356 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMoreMalwareUrl)); | 391 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMoreMalwareUrl)); |
| 357 } else if (unsafe_resources_[0].threat_type == | 392 } else if (unsafe_resources_[0].threat_type == |
| 358 SafeBrowsingService::URL_PHISHING) { | 393 SafeBrowsingService::URL_PHISHING) { |
| 359 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMorePhishingUrl)); | 394 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMorePhishingUrl)); |
| 360 } else { | 395 } else { |
| 361 NOTREACHED(); | 396 NOTREACHED(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 diagnostic_url = google_util::AppendGoogleLocaleParam(diagnostic_url); | 452 diagnostic_url = google_util::AppendGoogleLocaleParam(diagnostic_url); |
| 418 DCHECK(unsafe_resources_[element_index].threat_type == | 453 DCHECK(unsafe_resources_[element_index].threat_type == |
| 419 SafeBrowsingService::URL_MALWARE); | 454 SafeBrowsingService::URL_MALWARE); |
| 420 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); | 455 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); |
| 421 return; | 456 return; |
| 422 } | 457 } |
| 423 | 458 |
| 424 NOTREACHED() << "Unexpected command: " << command; | 459 NOTREACHED() << "Unexpected command: " << command; |
| 425 } | 460 } |
| 426 | 461 |
| 462 void SafeBrowsingBlockingPage::SetReportingPreference(bool report) { |
| 463 PrefService* pref = tab()->profile()->GetPrefs(); |
| 464 pref->SetBoolean(prefs::kSafeBrowsingReportingEnabled, report); |
| 465 } |
| 466 |
| 427 void SafeBrowsingBlockingPage::Proceed() { | 467 void SafeBrowsingBlockingPage::Proceed() { |
| 428 RecordUserAction(PROCEED); | 468 RecordUserAction(PROCEED); |
| 429 FinishMalwareDetails(); // Send the malware details, if we opted to. | 469 FinishMalwareDetails(); // Send the malware details, if we opted to. |
| 430 | 470 |
| 431 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); | 471 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); |
| 432 | 472 |
| 433 // Check to see if some new notifications of unsafe resources have been | 473 // Check to see if some new notifications of unsafe resources have been |
| 434 // received while we were showing the interstitial. | 474 // received while we were showing the interstitial. |
| 435 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 475 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
| 436 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); | 476 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 644 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
| 605 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); | 645 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); |
| 606 } | 646 } |
| 607 | 647 |
| 608 // static | 648 // static |
| 609 bool SafeBrowsingBlockingPage::IsMainPage( | 649 bool SafeBrowsingBlockingPage::IsMainPage( |
| 610 const UnsafeResourceList& unsafe_resources) { | 650 const UnsafeResourceList& unsafe_resources) { |
| 611 return unsafe_resources.size() == 1 && | 651 return unsafe_resources.size() == 1 && |
| 612 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; | 652 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; |
| 613 } | 653 } |
| OLD | NEW |