OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/histogram.h" | |
9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
10 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/dom_operation_notification_details.h" | 12 #include "chrome/browser/dom_operation_notification_details.h" |
12 #include "chrome/browser/dom_ui/new_tab_ui.h" | 13 #include "chrome/browser/dom_ui/new_tab_ui.h" |
13 #include "chrome/browser/google_util.h" | 14 #include "chrome/browser/google_util.h" |
14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
15 #include "chrome/browser/tab_contents/navigation_controller.h" | 16 #include "chrome/browser/tab_contents/navigation_controller.h" |
16 #include "chrome/browser/tab_contents/navigation_entry.h" | 17 #include "chrome/browser/tab_contents/navigation_entry.h" |
17 #include "chrome/browser/tab_contents/tab_util.h" | 18 #include "chrome/browser/tab_contents/tab_util.h" |
18 #include "chrome/browser/tab_contents/web_contents.h" | 19 #include "chrome/browser/tab_contents/web_contents.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
42 L"<a href=\"\" onClick=\"sendCommand('showDiagnostic'); return false;\" " | 43 L"<a href=\"\" onClick=\"sendCommand('showDiagnostic'); return false;\" " |
43 L"onMouseDown=\"return false;\">%ls</a>"; | 44 L"onMouseDown=\"return false;\">%ls</a>"; |
44 | 45 |
45 // The commands returned by the page when the user performs an action. | 46 // The commands returned by the page when the user performs an action. |
46 static const char* const kShowDiagnosticCommand = "showDiagnostic"; | 47 static const char* const kShowDiagnosticCommand = "showDiagnostic"; |
47 static const char* const kReportErrorCommand = "reportError"; | 48 static const char* const kReportErrorCommand = "reportError"; |
48 static const char* const kLearnMoreCommand = "learnMore"; | 49 static const char* const kLearnMoreCommand = "learnMore"; |
49 static const char* const kProceedCommand = "proceed"; | 50 static const char* const kProceedCommand = "proceed"; |
50 static const char* const kTakeMeBackCommand = "takeMeBack"; | 51 static const char* const kTakeMeBackCommand = "takeMeBack"; |
51 | 52 |
53 namespace { | |
54 | |
55 enum SafeBrowsingBlockingPageEvent { | |
56 SHOW, | |
57 PROCEED, | |
58 DONT_PROCEED, | |
59 }; | |
60 | |
61 void RecordSafeBrowsingBlockingPageStats(SafeBrowsingBlockingPageEvent event) { | |
62 static LinearHistogram histogram("interstial.safe_browsing", 0, 2, 4); | |
jar (doing other things)
2009/04/27 00:20:49
Looking at the unit test, and other examples, the
| |
63 histogram.SetFlags(kUmaTargetedHistogramFlag); | |
64 histogram.Add(event); | |
65 } | |
66 | |
67 } // namespace | |
52 // static | 68 // static |
53 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; | 69 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; |
54 | 70 |
55 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we | 71 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we |
56 // don't leak it. | 72 // don't leak it. |
57 class SafeBrowsingBlockingPageFactoryImpl | 73 class SafeBrowsingBlockingPageFactoryImpl |
58 : public SafeBrowsingBlockingPageFactory { | 74 : public SafeBrowsingBlockingPageFactory { |
59 public: | 75 public: |
60 SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 76 SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
61 SafeBrowsingService* service, | 77 SafeBrowsingService* service, |
(...skipping 14 matching lines...) Expand all Loading... | |
76 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( | 92 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( |
77 SafeBrowsingService* sb_service, | 93 SafeBrowsingService* sb_service, |
78 WebContents* web_contents, | 94 WebContents* web_contents, |
79 const UnsafeResourceList& unsafe_resources) | 95 const UnsafeResourceList& unsafe_resources) |
80 : InterstitialPage(web_contents, | 96 : InterstitialPage(web_contents, |
81 IsMainPage(unsafe_resources), | 97 IsMainPage(unsafe_resources), |
82 unsafe_resources[0].url), | 98 unsafe_resources[0].url), |
83 sb_service_(sb_service), | 99 sb_service_(sb_service), |
84 is_main_frame_(IsMainPage(unsafe_resources)), | 100 is_main_frame_(IsMainPage(unsafe_resources)), |
85 unsafe_resources_(unsafe_resources) { | 101 unsafe_resources_(unsafe_resources) { |
102 RecordSafeBrowsingBlockingPageStats(SHOW); | |
86 if (!is_main_frame_) { | 103 if (!is_main_frame_) { |
87 navigation_entry_index_to_remove_ = | 104 navigation_entry_index_to_remove_ = |
88 tab()->controller().last_committed_entry_index(); | 105 tab()->controller().last_committed_entry_index(); |
89 } else { | 106 } else { |
90 navigation_entry_index_to_remove_ = -1; | 107 navigation_entry_index_to_remove_ = -1; |
91 } | 108 } |
92 } | 109 } |
93 | 110 |
94 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { | 111 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { |
95 } | 112 } |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 DCHECK(unsafe_resources_[element_index].threat_type == | 372 DCHECK(unsafe_resources_[element_index].threat_type == |
356 SafeBrowsingService::URL_MALWARE); | 373 SafeBrowsingService::URL_MALWARE); |
357 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); | 374 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); |
358 return; | 375 return; |
359 } | 376 } |
360 | 377 |
361 NOTREACHED() << "Unexpected command: " << command; | 378 NOTREACHED() << "Unexpected command: " << command; |
362 } | 379 } |
363 | 380 |
364 void SafeBrowsingBlockingPage::Proceed() { | 381 void SafeBrowsingBlockingPage::Proceed() { |
382 RecordSafeBrowsingBlockingPageStats(PROCEED); | |
383 | |
365 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); | 384 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); |
366 | 385 |
367 // Check to see if some new notifications of unsafe resources have been | 386 // Check to see if some new notifications of unsafe resources have been |
368 // received while we were showing the interstitial. | 387 // received while we were showing the interstitial. |
369 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 388 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
370 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); | 389 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); |
371 SafeBrowsingBlockingPage* blocking_page = NULL; | 390 SafeBrowsingBlockingPage* blocking_page = NULL; |
372 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { | 391 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { |
373 // Build an interstitial for all the unsafe resources notifications. | 392 // Build an interstitial for all the unsafe resources notifications. |
374 // Don't show it now as showing an interstitial while an interstitial is | 393 // Don't show it now as showing an interstitial while an interstitial is |
375 // already showing would cause DontProceed() to be invoked. | 394 // already showing would cause DontProceed() to be invoked. |
376 blocking_page = factory_->CreateSafeBrowsingPage(sb_service_, tab(), | 395 blocking_page = factory_->CreateSafeBrowsingPage(sb_service_, tab(), |
377 iter->second); | 396 iter->second); |
378 unsafe_resource_map->erase(iter); | 397 unsafe_resource_map->erase(iter); |
379 } | 398 } |
380 | 399 |
381 InterstitialPage::Proceed(); | 400 InterstitialPage::Proceed(); |
382 // We are now deleted. | 401 // We are now deleted. |
383 | 402 |
384 // Now that this interstitial is gone, we can show the new one. | 403 // Now that this interstitial is gone, we can show the new one. |
385 if (blocking_page) | 404 if (blocking_page) |
386 blocking_page->Show(); | 405 blocking_page->Show(); |
387 } | 406 } |
388 | 407 |
389 void SafeBrowsingBlockingPage::DontProceed() { | 408 void SafeBrowsingBlockingPage::DontProceed() { |
409 RecordSafeBrowsingBlockingPageStats(DONT_PROCEED); | |
410 | |
390 NotifySafeBrowsingService(sb_service_, unsafe_resources_, false); | 411 NotifySafeBrowsingService(sb_service_, unsafe_resources_, false); |
391 | 412 |
392 // The user does not want to proceed, clear the queued unsafe resources | 413 // The user does not want to proceed, clear the queued unsafe resources |
393 // notifications we received while the interstitial was showing. | 414 // notifications we received while the interstitial was showing. |
394 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 415 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
395 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); | 416 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); |
396 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { | 417 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { |
397 NotifySafeBrowsingService(sb_service_, iter->second, false); | 418 NotifySafeBrowsingService(sb_service_, iter->second, false); |
398 unsafe_resource_map->erase(iter); | 419 unsafe_resource_map->erase(iter); |
399 } | 420 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 481 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
461 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource); | 482 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource); |
462 } | 483 } |
463 | 484 |
464 // static | 485 // static |
465 bool SafeBrowsingBlockingPage::IsMainPage( | 486 bool SafeBrowsingBlockingPage::IsMainPage( |
466 const UnsafeResourceList& unsafe_resources) { | 487 const UnsafeResourceList& unsafe_resources) { |
467 return unsafe_resources.size() == 1 && | 488 return unsafe_resources.size() == 1 && |
468 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; | 489 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; |
469 } | 490 } |
OLD | NEW |