| 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_process.h" |
| 17 #include "chrome/browser/browser_thread.h" | 18 #include "chrome/browser/browser_thread.h" |
| 18 #include "chrome/browser/dom_operation_notification_details.h" | 19 #include "chrome/browser/dom_operation_notification_details.h" |
| 19 #include "chrome/browser/dom_ui/new_tab_ui.h" | 20 #include "chrome/browser/dom_ui/new_tab_ui.h" |
| 20 #include "chrome/browser/google/google_util.h" | 21 #include "chrome/browser/google/google_util.h" |
| 21 #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/profile.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 22 matching lines...) Expand all Loading... |
| 60 static const wchar_t* const kPLinkHtml = | 64 static const wchar_t* const kPLinkHtml = |
| 61 L"<a href=\"\" onclick=\"sendCommand('proceed'); return false;\" " | 65 L"<a href=\"\" onclick=\"sendCommand('proceed'); return false;\" " |
| 62 L"onmousedown=\"return false;\">%ls</a>"; | 66 L"onmousedown=\"return false;\">%ls</a>"; |
| 63 | 67 |
| 64 // The commands returned by the page when the user performs an action. | 68 // The commands returned by the page when the user performs an action. |
| 65 static const char* const kShowDiagnosticCommand = "showDiagnostic"; | 69 static const char* const kShowDiagnosticCommand = "showDiagnostic"; |
| 66 static const char* const kReportErrorCommand = "reportError"; | 70 static const char* const kReportErrorCommand = "reportError"; |
| 67 static const char* const kLearnMoreCommand = "learnMore"; | 71 static const char* const kLearnMoreCommand = "learnMore"; |
| 68 static const char* const kProceedCommand = "proceed"; | 72 static const char* const kProceedCommand = "proceed"; |
| 69 static const char* const kTakeMeBackCommand = "takeMeBack"; | 73 static const char* const kTakeMeBackCommand = "takeMeBack"; |
| 74 static const char* const kDoReportCommand = "doReport"; |
| 75 static const char* const kDontReportCommand = "dontReport"; |
| 70 | 76 |
| 71 // static | 77 // static |
| 72 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; | 78 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; |
| 73 | 79 |
| 74 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we | 80 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we |
| 75 // don't leak it. | 81 // don't leak it. |
| 76 class SafeBrowsingBlockingPageFactoryImpl | 82 class SafeBrowsingBlockingPageFactoryImpl |
| 77 : public SafeBrowsingBlockingPageFactory { | 83 : public SafeBrowsingBlockingPageFactory { |
| 78 public: | 84 public: |
| 79 SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 85 SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 strings->SetString("description5", WideToUTF16Hack(description5)); | 281 strings->SetString("description5", WideToUTF16Hack(description5)); |
| 276 | 282 |
| 277 strings->SetString("back_button", | 283 strings->SetString("back_button", |
| 278 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); | 284 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); |
| 279 strings->SetString("more_info_button", | 285 strings->SetString("more_info_button", |
| 280 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_MORE_INFO_BUTTON)); | 286 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_MORE_INFO_BUTTON)); |
| 281 strings->SetString("less_info_button", | 287 strings->SetString("less_info_button", |
| 282 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_LESS_INFO_BUTTON)); | 288 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_LESS_INFO_BUTTON)); |
| 283 strings->SetString("proceed_link", | 289 strings->SetString("proceed_link", |
| 284 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK)); | 290 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK)); |
| 291 strings->SetString("confirm_text", |
| 292 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE)); |
| 285 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 293 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
| 294 |
| 295 const PrefService::Preference* pref = |
| 296 tab()->profile()->GetPrefs()->FindPreference( |
| 297 prefs::kSafeBrowsingReportingEnabled); |
| 298 bool value; |
| 299 if (pref && pref->GetValue()->GetAsBoolean(&value) && value) { |
| 300 strings->SetString("boxchecked", "yes"); |
| 301 } else { |
| 302 strings->SetString("boxchecked", ""); |
| 303 } |
| 286 } | 304 } |
| 287 | 305 |
| 288 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( | 306 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( |
| 289 DictionaryValue* strings) { | 307 DictionaryValue* strings) { |
| 290 PopulateStringDictionary( | 308 PopulateStringDictionary( |
| 291 strings, | 309 strings, |
| 292 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_TITLE), | 310 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_TITLE), |
| 293 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_HEADLINE), | 311 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_HEADLINE), |
| 294 l10n_util::GetStringF(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION1, | 312 l10n_util::GetStringF(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION1, |
| 295 UTF8ToWide(url().host())), | 313 UTF8ToWide(url().host())), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 306 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 324 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
| 307 } | 325 } |
| 308 | 326 |
| 309 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { | 327 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { |
| 310 std::string command(cmd); // Make a local copy so we can modify it. | 328 std::string command(cmd); // Make a local copy so we can modify it. |
| 311 // The Jasonified response has quotes, remove them. | 329 // The Jasonified response has quotes, remove them. |
| 312 if (command.length() > 1 && command[0] == '"') { | 330 if (command.length() > 1 && command[0] == '"') { |
| 313 command = command.substr(1, command.length() - 2); | 331 command = command.substr(1, command.length() - 2); |
| 314 } | 332 } |
| 315 | 333 |
| 334 if (command == kDoReportCommand) { |
| 335 SetReportingPreference(true); |
| 336 return; |
| 337 } |
| 338 |
| 339 if (command == kDontReportCommand) { |
| 340 SetReportingPreference(false); |
| 341 return; |
| 342 } |
| 343 |
| 316 if (command == kLearnMoreCommand) { | 344 if (command == kLearnMoreCommand) { |
| 317 // User pressed "Learn more". | 345 // User pressed "Learn more". |
| 318 GURL url; | 346 GURL url; |
| 319 if (unsafe_resources_[0].threat_type == SafeBrowsingService::URL_MALWARE) { | 347 if (unsafe_resources_[0].threat_type == SafeBrowsingService::URL_MALWARE) { |
| 320 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMoreMalwareUrl)); | 348 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMoreMalwareUrl)); |
| 321 } else if (unsafe_resources_[0].threat_type == | 349 } else if (unsafe_resources_[0].threat_type == |
| 322 SafeBrowsingService::URL_PHISHING) { | 350 SafeBrowsingService::URL_PHISHING) { |
| 323 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMorePhishingUrl)); | 351 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMorePhishingUrl)); |
| 324 } else { | 352 } else { |
| 325 NOTREACHED(); | 353 NOTREACHED(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 diagnostic_url = google_util::AppendGoogleLocaleParam(diagnostic_url); | 409 diagnostic_url = google_util::AppendGoogleLocaleParam(diagnostic_url); |
| 382 DCHECK(unsafe_resources_[element_index].threat_type == | 410 DCHECK(unsafe_resources_[element_index].threat_type == |
| 383 SafeBrowsingService::URL_MALWARE); | 411 SafeBrowsingService::URL_MALWARE); |
| 384 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); | 412 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); |
| 385 return; | 413 return; |
| 386 } | 414 } |
| 387 | 415 |
| 388 NOTREACHED() << "Unexpected command: " << command; | 416 NOTREACHED() << "Unexpected command: " << command; |
| 389 } | 417 } |
| 390 | 418 |
| 419 void SafeBrowsingBlockingPage::SetReportingPreference(bool report) { |
| 420 PrefService* pref = tab()->profile()->GetPrefs(); |
| 421 pref->SetBoolean(prefs::kSafeBrowsingReportingEnabled, report); |
| 422 } |
| 423 |
| 391 void SafeBrowsingBlockingPage::Proceed() { | 424 void SafeBrowsingBlockingPage::Proceed() { |
| 392 RecordUserAction(PROCEED); | 425 RecordUserAction(PROCEED); |
| 393 | 426 |
| 394 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); | 427 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); |
| 395 | 428 |
| 396 // Check to see if some new notifications of unsafe resources have been | 429 // Check to see if some new notifications of unsafe resources have been |
| 397 // received while we were showing the interstitial. | 430 // received while we were showing the interstitial. |
| 398 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 431 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
| 399 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); | 432 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); |
| 400 SafeBrowsingBlockingPage* blocking_page = NULL; | 433 SafeBrowsingBlockingPage* blocking_page = NULL; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 580 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
| 548 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); | 581 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); |
| 549 } | 582 } |
| 550 | 583 |
| 551 // static | 584 // static |
| 552 bool SafeBrowsingBlockingPage::IsMainPage( | 585 bool SafeBrowsingBlockingPage::IsMainPage( |
| 553 const UnsafeResourceList& unsafe_resources) { | 586 const UnsafeResourceList& unsafe_resources) { |
| 554 return unsafe_resources.size() == 1 && | 587 return unsafe_resources.size() == 1 && |
| 555 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; | 588 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; |
| 556 } | 589 } |
| OLD | NEW |