Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page.cc

Issue 1183513003: Ignore queued Safe Browsing interstitial requests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // MalwareDetails::FinishCollection() by this much time (in 73 // MalwareDetails::FinishCollection() by this much time (in
74 // milliseconds). 74 // milliseconds).
75 const int64 kMalwareDetailsProceedDelayMilliSeconds = 3000; 75 const int64 kMalwareDetailsProceedDelayMilliSeconds = 3000;
76 76
77 // Constants for the Experience Sampling instrumentation. 77 // Constants for the Experience Sampling instrumentation.
78 const char kEventNameMalware[] = "safebrowsing_interstitial_"; 78 const char kEventNameMalware[] = "safebrowsing_interstitial_";
79 const char kEventNameHarmful[] = "harmful_interstitial_"; 79 const char kEventNameHarmful[] = "harmful_interstitial_";
80 const char kEventNamePhishing[] = "phishing_interstitial_"; 80 const char kEventNamePhishing[] = "phishing_interstitial_";
81 const char kEventNameOther[] = "safebrowsing_other_interstitial_"; 81 const char kEventNameOther[] = "safebrowsing_other_interstitial_";
82 82
83 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap>
84 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER;
85
86 } // namespace 83 } // namespace
87 84
88 // static 85 // static
89 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; 86 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL;
90 87
91 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we 88 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we
92 // don't leak it. 89 // don't leak it.
93 class SafeBrowsingBlockingPageFactoryImpl 90 class SafeBrowsingBlockingPageFactoryImpl
94 : public SafeBrowsingBlockingPageFactory { 91 : public SafeBrowsingBlockingPageFactory {
95 public: 92 public:
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 renderer_preferences_util::UpdateFromSystemSettings( 314 renderer_preferences_util::UpdateFromSystemSettings(
318 prefs, profile, web_contents()); 315 prefs, profile, web_contents());
319 } 316 }
320 317
321 void SafeBrowsingBlockingPage::OnProceed() { 318 void SafeBrowsingBlockingPage::OnProceed() {
322 proceeded_ = true; 319 proceeded_ = true;
323 // Send the malware details, if we opted to. 320 // Send the malware details, if we opted to.
324 FinishMalwareDetails(malware_details_proceed_delay_ms_); 321 FinishMalwareDetails(malware_details_proceed_delay_ms_);
325 322
326 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, true); 323 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, true);
327
328 // Check to see if some new notifications of unsafe resources have been
329 // received while we were showing the interstitial.
330 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
331 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents());
332 SafeBrowsingBlockingPage* blocking_page = NULL;
333 if (iter != unsafe_resource_map->end() && !iter->second.empty()) {
334 // Build an interstitial for all the unsafe resources notifications.
335 // Don't show it now as showing an interstitial while an interstitial is
336 // already showing would cause DontProceed() to be invoked.
337 blocking_page = factory_->CreateSafeBrowsingPage(ui_manager_,
338 web_contents(),
339 iter->second);
340 unsafe_resource_map->erase(iter);
341 }
342
343 // Now that this interstitial is gone, we can show the new one.
344 if (blocking_page)
345 blocking_page->Show();
346 } 324 }
347 325
348 content::InterstitialPageDelegate::TypeID 326 content::InterstitialPageDelegate::TypeID
349 SafeBrowsingBlockingPage::GetTypeForTesting() const { 327 SafeBrowsingBlockingPage::GetTypeForTesting() const {
350 return SafeBrowsingBlockingPage::kTypeForTesting; 328 return SafeBrowsingBlockingPage::kTypeForTesting;
351 } 329 }
352 330
353 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const { 331 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const {
354 return is_main_frame_load_blocked_; 332 return is_main_frame_load_blocked_;
355 } 333 }
356 334
357 void SafeBrowsingBlockingPage::OnDontProceed() { 335 void SafeBrowsingBlockingPage::OnDontProceed() {
358 // We could have already called Proceed(), in which case we must not notify 336 // We could have already called Proceed(), in which case we must not notify
359 // the SafeBrowsingUIManager again, as the client has been deleted. 337 // the SafeBrowsingUIManager again, as the client has been deleted.
360 if (proceeded_) 338 if (proceeded_)
361 return; 339 return;
362 340
363 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { 341 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) {
364 metrics_helper()->RecordUserDecision( 342 metrics_helper()->RecordUserDecision(
365 SecurityInterstitialMetricsHelper::DONT_PROCEED); 343 SecurityInterstitialMetricsHelper::DONT_PROCEED);
366 } 344 }
367 345
368 // Send the malware details, if we opted to. 346 // Send the malware details, if we opted to.
369 FinishMalwareDetails(0); // No delay 347 FinishMalwareDetails(0); // No delay
370 348
371 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, false); 349 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, false);
372 350
373 // The user does not want to proceed, clear the queued unsafe resources
374 // notifications we received while the interstitial was showing.
375 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
376 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents());
377 if (iter != unsafe_resource_map->end() && !iter->second.empty()) {
378 NotifySafeBrowsingUIManager(ui_manager_, iter->second, false);
379 unsafe_resource_map->erase(iter);
380 }
381
382 // We don't remove the navigation entry if the tab is being destroyed as this 351 // We don't remove the navigation entry if the tab is being destroyed as this
383 // would trigger a navigation that would cause trouble as the render view host 352 // would trigger a navigation that would cause trouble as the render view host
384 // for the tab has by then already been destroyed. We also don't delete the 353 // for the tab has by then already been destroyed. We also don't delete the
385 // current entry if it has been committed again, which is possible on a page 354 // current entry if it has been committed again, which is possible on a page
386 // that had a subresource warning. 355 // that had a subresource warning.
387 int last_committed_index = 356 int last_committed_index =
388 web_contents()->GetController().GetLastCommittedEntryIndex(); 357 web_contents()->GetController().GetLastCommittedEntryIndex();
389 if (navigation_entry_index_to_remove_ != -1 && 358 if (navigation_entry_index_to_remove_ != -1 &&
390 navigation_entry_index_to_remove_ != last_committed_index && 359 navigation_entry_index_to_remove_ != last_committed_index &&
391 !web_contents()->IsBeingDestroyed()) { 360 !web_contents()->IsBeingDestroyed()) {
(...skipping 28 matching lines...) Expand all
420 SafeBrowsingUIManager* ui_manager, 389 SafeBrowsingUIManager* ui_manager,
421 const UnsafeResourceList& unsafe_resources, 390 const UnsafeResourceList& unsafe_resources,
422 bool proceed) { 391 bool proceed) {
423 BrowserThread::PostTask( 392 BrowserThread::PostTask(
424 BrowserThread::IO, FROM_HERE, 393 BrowserThread::IO, FROM_HERE,
425 base::Bind(&SafeBrowsingUIManager::OnBlockingPageDone, 394 base::Bind(&SafeBrowsingUIManager::OnBlockingPageDone,
426 ui_manager, unsafe_resources, proceed)); 395 ui_manager, unsafe_resources, proceed));
427 } 396 }
428 397
429 // static 398 // static
430 SafeBrowsingBlockingPage::UnsafeResourceMap*
431 SafeBrowsingBlockingPage::GetUnsafeResourcesMap() {
432 return g_unsafe_resource_map.Pointer();
433 }
434
435 // static
436 SafeBrowsingBlockingPage* SafeBrowsingBlockingPage::CreateBlockingPage( 399 SafeBrowsingBlockingPage* SafeBrowsingBlockingPage::CreateBlockingPage(
437 SafeBrowsingUIManager* ui_manager, 400 SafeBrowsingUIManager* ui_manager,
438 WebContents* web_contents, 401 WebContents* web_contents,
439 const UnsafeResource& unsafe_resource) { 402 const UnsafeResource& unsafe_resource) {
440 std::vector<UnsafeResource> resources; 403 std::vector<UnsafeResource> resources;
441 resources.push_back(unsafe_resource); 404 resources.push_back(unsafe_resource);
442 // Set up the factory if this has not been done already (tests do that 405 // Set up the factory if this has not been done already (tests do that
443 // before this method is called). 406 // before this method is called).
444 if (!factory_) 407 if (!factory_)
445 factory_ = g_safe_browsing_blocking_page_factory_impl.Pointer(); 408 factory_ = g_safe_browsing_blocking_page_factory_impl.Pointer();
(...skipping 19 matching lines...) Expand all
465 } 428 }
466 429
467 if (!interstitial) { 430 if (!interstitial) {
468 // There are no interstitial currently showing in that tab, go ahead and 431 // There are no interstitial currently showing in that tab, go ahead and
469 // show this interstitial. 432 // show this interstitial.
470 SafeBrowsingBlockingPage* blocking_page = 433 SafeBrowsingBlockingPage* blocking_page =
471 CreateBlockingPage(ui_manager, web_contents, unsafe_resource); 434 CreateBlockingPage(ui_manager, web_contents, unsafe_resource);
472 blocking_page->Show(); 435 blocking_page->Show();
473 return; 436 return;
474 } 437 }
475
476 // This is an interstitial for a page's resource, let's queue it.
477 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
478 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource);
479 } 438 }
480 439
481 // static 440 // static
482 bool SafeBrowsingBlockingPage::IsMainPageLoadBlocked( 441 bool SafeBrowsingBlockingPage::IsMainPageLoadBlocked(
483 const UnsafeResourceList& unsafe_resources) { 442 const UnsafeResourceList& unsafe_resources) {
484 // Client-side phishing detection interstitials never block the main frame 443 // Client-side phishing detection interstitials never block the main frame
485 // load, since they happen after the page is finished loading. 444 // load, since they happen after the page is finished loading.
486 if (unsafe_resources[0].threat_type == 445 if (unsafe_resources[0].threat_type ==
487 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL) { 446 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL) {
488 return false; 447 return false;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 load_time_data->SetString( 608 load_time_data->SetString(
650 "explanationParagraph", 609 "explanationParagraph",
651 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH, 610 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH,
652 GetFormattedHostName())); 611 GetFormattedHostName()));
653 load_time_data->SetString( 612 load_time_data->SetString(
654 "finalParagraph", 613 "finalParagraph",
655 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); 614 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH));
656 615
657 PopulateExtendedReportingOption(load_time_data); 616 PopulateExtendedReportingOption(load_time_data);
658 } 617 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698