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 } else { |
| 328 // Show the checkbox for sending malware details. |
| 329 strings->SetBoolean(kDisplayCheckBox, true); |
| 330 strings->SetString( |
| 331 "confirm_text", |
| 332 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE)); |
| 333 |
| 334 const PrefService::Preference* pref = |
| 335 tab()->profile()->GetPrefs()->FindPreference( |
| 336 prefs::kSafeBrowsingReportingEnabled); |
| 337 |
| 338 bool value; |
| 339 if (pref && pref->GetValue()->GetAsBoolean(&value) && value) { |
| 340 strings->SetString(kBoxChecked, "yes"); |
| 341 } else { |
| 342 strings->SetString(kBoxChecked, ""); |
| 343 } |
| 344 } |
319 } | 345 } |
320 | 346 |
321 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( | 347 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( |
322 DictionaryValue* strings) { | 348 DictionaryValue* strings) { |
323 std::string proceed_link = StringPrintf(kPLinkHtml, l10n_util::GetStringUTF8( | 349 std::string proceed_link = StringPrintf(kPLinkHtml, l10n_util::GetStringUTF8( |
324 IDS_SAFE_BROWSING_PHISHING_PROCEED_LINK).c_str()); | 350 IDS_SAFE_BROWSING_PHISHING_PROCEED_LINK).c_str()); |
325 string16 description3 = l10n_util::GetStringFUTF16( | 351 string16 description3 = l10n_util::GetStringFUTF16( |
326 IDS_SAFE_BROWSING_PHISHING_DESCRIPTION3, | 352 IDS_SAFE_BROWSING_PHISHING_DESCRIPTION3, |
327 UTF8ToUTF16(proceed_link)); | 353 UTF8ToUTF16(proceed_link)); |
328 | 354 |
(...skipping 13 matching lines...) Expand all Loading... |
342 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 368 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
343 } | 369 } |
344 | 370 |
345 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { | 371 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { |
346 std::string command(cmd); // Make a local copy so we can modify it. | 372 std::string command(cmd); // Make a local copy so we can modify it. |
347 // The Jasonified response has quotes, remove them. | 373 // The Jasonified response has quotes, remove them. |
348 if (command.length() > 1 && command[0] == '"') { | 374 if (command.length() > 1 && command[0] == '"') { |
349 command = command.substr(1, command.length() - 2); | 375 command = command.substr(1, command.length() - 2); |
350 } | 376 } |
351 | 377 |
| 378 if (command == kDoReportCommand) { |
| 379 SetReportingPreference(true); |
| 380 return; |
| 381 } |
| 382 |
| 383 if (command == kDontReportCommand) { |
| 384 SetReportingPreference(false); |
| 385 return; |
| 386 } |
| 387 |
352 if (command == kLearnMoreCommand) { | 388 if (command == kLearnMoreCommand) { |
353 // User pressed "Learn more". | 389 // User pressed "Learn more". |
354 GURL url; | 390 GURL url; |
355 if (unsafe_resources_[0].threat_type == SafeBrowsingService::URL_MALWARE) { | 391 if (unsafe_resources_[0].threat_type == SafeBrowsingService::URL_MALWARE) { |
356 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMoreMalwareUrl)); | 392 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMoreMalwareUrl)); |
357 } else if (unsafe_resources_[0].threat_type == | 393 } else if (unsafe_resources_[0].threat_type == |
358 SafeBrowsingService::URL_PHISHING) { | 394 SafeBrowsingService::URL_PHISHING) { |
359 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMorePhishingUrl)); | 395 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMorePhishingUrl)); |
360 } else { | 396 } else { |
361 NOTREACHED(); | 397 NOTREACHED(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 diagnostic_url = google_util::AppendGoogleLocaleParam(diagnostic_url); | 453 diagnostic_url = google_util::AppendGoogleLocaleParam(diagnostic_url); |
418 DCHECK(unsafe_resources_[element_index].threat_type == | 454 DCHECK(unsafe_resources_[element_index].threat_type == |
419 SafeBrowsingService::URL_MALWARE); | 455 SafeBrowsingService::URL_MALWARE); |
420 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); | 456 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); |
421 return; | 457 return; |
422 } | 458 } |
423 | 459 |
424 NOTREACHED() << "Unexpected command: " << command; | 460 NOTREACHED() << "Unexpected command: " << command; |
425 } | 461 } |
426 | 462 |
| 463 void SafeBrowsingBlockingPage::SetReportingPreference(bool report) { |
| 464 PrefService* pref = tab()->profile()->GetPrefs(); |
| 465 pref->SetBoolean(prefs::kSafeBrowsingReportingEnabled, report); |
| 466 } |
| 467 |
427 void SafeBrowsingBlockingPage::Proceed() { | 468 void SafeBrowsingBlockingPage::Proceed() { |
428 RecordUserAction(PROCEED); | 469 RecordUserAction(PROCEED); |
429 FinishMalwareDetails(); // Send the malware details, if we opted to. | 470 FinishMalwareDetails(); // Send the malware details, if we opted to. |
430 | 471 |
431 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); | 472 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); |
432 | 473 |
433 // Check to see if some new notifications of unsafe resources have been | 474 // Check to see if some new notifications of unsafe resources have been |
434 // received while we were showing the interstitial. | 475 // received while we were showing the interstitial. |
435 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 476 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
436 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); | 477 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(); | 645 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
605 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); | 646 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); |
606 } | 647 } |
607 | 648 |
608 // static | 649 // static |
609 bool SafeBrowsingBlockingPage::IsMainPage( | 650 bool SafeBrowsingBlockingPage::IsMainPage( |
610 const UnsafeResourceList& unsafe_resources) { | 651 const UnsafeResourceList& unsafe_resources) { |
611 return unsafe_resources.size() == 1 && | 652 return unsafe_resources.size() == 1 && |
612 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; | 653 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; |
613 } | 654 } |
OLD | NEW |