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

Side by Side Diff: components/safe_browsing/base_blocking_page.cc

Issue 2898593002: WebView: choose loud vs. quiet interstitial (Closed)
Patch Set: Rebase and fix patch conflict Created 3 years, 7 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #include "components/safe_browsing/base_blocking_page.h" 5 #include "components/safe_browsing/base_blocking_page.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "components/grit/components_resources.h"
12 #include "components/safe_browsing/common/safe_browsing_prefs.h" 13 #include "components/safe_browsing/common/safe_browsing_prefs.h"
13 #include "components/security_interstitials/content/security_interstitial_contro ller_client.h" 14 #include "components/security_interstitials/content/security_interstitial_contro ller_client.h"
14 #include "components/security_interstitials/core/metrics_helper.h" 15 #include "components/security_interstitials/core/metrics_helper.h"
15 #include "components/security_interstitials/core/safe_browsing_loud_error_ui.h" 16 #include "components/security_interstitials/core/safe_browsing_loud_error_ui.h"
17 #include "components/security_interstitials/core/safe_browsing_quiet_error_ui.h"
16 #include "content/public/browser/interstitial_page.h" 18 #include "content/public/browser/interstitial_page.h"
17 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/navigation_entry.h"
18 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
19 21
20 using content::InterstitialPage; 22 using content::InterstitialPage;
21 using content::WebContents; 23 using content::WebContents;
22 using security_interstitials::BaseSafeBrowsingErrorUI; 24 using security_interstitials::BaseSafeBrowsingErrorUI;
23 using security_interstitials::SafeBrowsingLoudErrorUI; 25 using security_interstitials::SafeBrowsingLoudErrorUI;
26 using security_interstitials::SafeBrowsingQuietErrorUI;
24 using security_interstitials::SecurityInterstitialControllerClient; 27 using security_interstitials::SecurityInterstitialControllerClient;
25 28
26 namespace safe_browsing { 29 namespace safe_browsing {
27 30
28 namespace { 31 namespace {
29 32
30 // After a safe browsing interstitial where the user opted-in to the report 33 // After a safe browsing interstitial where the user opted-in to the report
31 // but clicked "proceed anyway", we delay the call to 34 // but clicked "proceed anyway", we delay the call to
32 // ThreatDetails::FinishCollection() by this much time (in 35 // ThreatDetails::FinishCollection() by this much time (in
33 // milliseconds). 36 // milliseconds).
34 const int64_t kThreatDetailsProceedDelayMilliSeconds = 3000; 37 const int64_t kThreatDetailsProceedDelayMilliSeconds = 3000;
35 38
36 base::LazyInstance<BaseBlockingPage::UnsafeResourceMap>::Leaky 39 base::LazyInstance<BaseBlockingPage::UnsafeResourceMap>::Leaky
37 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; 40 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER;
38 41
39 } // namespace 42 } // namespace
40 43
41 BaseBlockingPage::BaseBlockingPage( 44 BaseBlockingPage::BaseBlockingPage(
42 BaseUIManager* ui_manager, 45 BaseUIManager* ui_manager,
43 WebContents* web_contents, 46 WebContents* web_contents,
44 const GURL& main_frame_url, 47 const GURL& main_frame_url,
45 const UnsafeResourceList& unsafe_resources, 48 const UnsafeResourceList& unsafe_resources,
46 std::unique_ptr<SecurityInterstitialControllerClient> controller_client, 49 std::unique_ptr<SecurityInterstitialControllerClient> controller_client,
47 const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions& display_options) 50 const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions& display_options,
51 ErrorUiType error_type)
48 : SecurityInterstitialPage(web_contents, 52 : SecurityInterstitialPage(web_contents,
49 unsafe_resources[0].url, 53 unsafe_resources[0].url,
50 std::move(controller_client)), 54 std::move(controller_client)),
51 ui_manager_(ui_manager), 55 ui_manager_(ui_manager),
52 main_frame_url_(main_frame_url), 56 main_frame_url_(main_frame_url),
53 navigation_entry_index_to_remove_( 57 navigation_entry_index_to_remove_(
54 IsMainPageLoadBlocked(unsafe_resources) 58 IsMainPageLoadBlocked(unsafe_resources)
55 ? -1 59 ? -1
56 : web_contents->GetController().GetLastCommittedEntryIndex()), 60 : web_contents->GetController().GetLastCommittedEntryIndex()),
57 unsafe_resources_(unsafe_resources), 61 unsafe_resources_(unsafe_resources),
58 sb_error_ui_(base::MakeUnique<SafeBrowsingLoudErrorUI>( 62 sb_error_ui_(error_type == ErrorUiType::LOUD
59 unsafe_resources_[0].url, 63 ? static_cast<std::unique_ptr<BaseSafeBrowsingErrorUI>>(
60 main_frame_url_, 64 base::MakeUnique<SafeBrowsingLoudErrorUI>(
61 GetInterstitialReason(unsafe_resources_), 65 unsafe_resources_[0].url,
62 display_options, 66 main_frame_url_,
63 ui_manager->app_locale(), 67 GetInterstitialReason(unsafe_resources_),
64 base::Time::NowFromSystemTime(), 68 display_options,
65 controller())), 69 ui_manager->app_locale(),
70 base::Time::NowFromSystemTime(),
71 controller()))
72 : static_cast<std::unique_ptr<BaseSafeBrowsingErrorUI>>(
73 base::MakeUnique<SafeBrowsingQuietErrorUI>(
74 unsafe_resources_[0].url,
75 main_frame_url_,
76 GetInterstitialReason(unsafe_resources_),
77 display_options,
78 ui_manager->app_locale(),
79 base::Time::NowFromSystemTime(),
80 controller(),
81 error_type == ErrorUiType::QUIET_GIANT))),
66 proceeded_(false), 82 proceeded_(false),
67 threat_details_proceed_delay_ms_(kThreatDetailsProceedDelayMilliSeconds) { 83 threat_details_proceed_delay_ms_(kThreatDetailsProceedDelayMilliSeconds),
68 } 84 error_type_(error_type) {}
sgurun-gerrit only 2017/05/22 21:05:30 errorType sounds like we are dealing with an error
Nate Fischer 2017/05/22 23:13:46 Acknowledged. The member is removed in the latest
69 85
70 BaseBlockingPage::~BaseBlockingPage() {} 86 BaseBlockingPage::~BaseBlockingPage() {}
71 87
72 // static 88 // static
73 const security_interstitials::BaseSafeBrowsingErrorUI::SBErrorDisplayOptions 89 const security_interstitials::BaseSafeBrowsingErrorUI::SBErrorDisplayOptions
74 BaseBlockingPage::CreateDefaultDisplayOptions( 90 BaseBlockingPage::CreateDefaultDisplayOptions(
75 const UnsafeResourceList& unsafe_resources) { 91 const UnsafeResourceList& unsafe_resources) {
76 return BaseSafeBrowsingErrorUI::SBErrorDisplayOptions( 92 return BaseSafeBrowsingErrorUI::SBErrorDisplayOptions(
77 IsMainPageLoadBlocked(unsafe_resources), 93 IsMainPageLoadBlocked(unsafe_resources),
78 false, // kSafeBrowsingExtendedReportingOptInAllowed 94 false, // kSafeBrowsingExtendedReportingOptInAllowed
(...skipping 20 matching lines...) Expand all
99 // There is no interstitial currently showing in that tab, or we are about 115 // There is no interstitial currently showing in that tab, or we are about
100 // to display a new one for the main frame. If there is already an 116 // to display a new one for the main frame. If there is already an
101 // interstitial, showing the new one will automatically hide the old one. 117 // interstitial, showing the new one will automatically hide the old one.
102 content::NavigationEntry* entry = 118 content::NavigationEntry* entry =
103 unsafe_resource.GetNavigationEntryForResource(); 119 unsafe_resource.GetNavigationEntryForResource();
104 const UnsafeResourceList unsafe_resources{unsafe_resource}; 120 const UnsafeResourceList unsafe_resources{unsafe_resource};
105 BaseBlockingPage* blocking_page = new BaseBlockingPage( 121 BaseBlockingPage* blocking_page = new BaseBlockingPage(
106 ui_manager, web_contents, entry ? entry->GetURL() : GURL(), 122 ui_manager, web_contents, entry ? entry->GetURL() : GURL(),
107 unsafe_resources, 123 unsafe_resources,
108 CreateControllerClient(web_contents, unsafe_resources, ui_manager), 124 CreateControllerClient(web_contents, unsafe_resources, ui_manager),
109 CreateDefaultDisplayOptions(unsafe_resources)); 125 CreateDefaultDisplayOptions(unsafe_resources), ErrorUiType::LOUD);
110 blocking_page->Show(); 126 blocking_page->Show();
111 } 127 }
112 } 128 }
113 129
114 // static 130 // static
115 bool BaseBlockingPage::IsMainPageLoadBlocked( 131 bool BaseBlockingPage::IsMainPageLoadBlocked(
116 const UnsafeResourceList& unsafe_resources) { 132 const UnsafeResourceList& unsafe_resources) {
117 // If there is more than one unsafe resource, the main page load must not be 133 // If there is more than one unsafe resource, the main page load must not be
118 // blocked. Otherwise, check if the one resource is. 134 // blocked. Otherwise, check if the one resource is.
119 return unsafe_resources.size() == 1 && 135 return unsafe_resources.size() == 1 &&
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper = 360 std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper =
345 base::MakeUnique<security_interstitials::MetricsHelper>( 361 base::MakeUnique<security_interstitials::MetricsHelper>(
346 unsafe_resources[0].url, GetReportingInfo(unsafe_resources), 362 unsafe_resources[0].url, GetReportingInfo(unsafe_resources),
347 history_service); 363 history_service);
348 364
349 return base::MakeUnique<SecurityInterstitialControllerClient>( 365 return base::MakeUnique<SecurityInterstitialControllerClient>(
350 web_contents, std::move(metrics_helper), nullptr, /* prefs */ 366 web_contents, std::move(metrics_helper), nullptr, /* prefs */
351 ui_manager->app_locale(), ui_manager->default_safe_page()); 367 ui_manager->app_locale(), ui_manager->default_safe_page());
352 } 368 }
353 369
370 int BaseBlockingPage::GetHTMLTemplateId() {
371 return error_type_ == ErrorUiType::LOUD
372 ? IDR_SECURITY_INTERSTITIAL_HTML
373 : IDR_SECURITY_INTERSTITIAL_QUIET_HTML;
374 }
375
354 } // namespace safe_browsing 376 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698