OLD | NEW |
---|---|
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 "android_webview/browser/aw_safe_browsing_blocking_page.h" | 5 #include "android_webview/browser/aw_safe_browsing_blocking_page.h" |
6 | 6 |
7 #include "android_webview/browser/aw_browser_context.h" | 7 #include "android_webview/browser/aw_browser_context.h" |
8 #include "android_webview/browser/aw_safe_browsing_ui_manager.h" | 8 #include "android_webview/browser/aw_safe_browsing_ui_manager.h" |
9 #include "android_webview/browser/net/aw_url_request_context_getter.h" | 9 #include "android_webview/browser/net/aw_url_request_context_getter.h" |
10 #include "components/safe_browsing/browser/threat_details.h" | |
11 #include "components/safe_browsing/triggers/trigger_manager.h" | |
10 #include "components/security_interstitials/content/security_interstitial_contro ller_client.h" | 12 #include "components/security_interstitials/content/security_interstitial_contro ller_client.h" |
11 #include "components/security_interstitials/content/unsafe_resource.h" | 13 #include "components/security_interstitials/content/unsafe_resource.h" |
12 #include "components/security_interstitials/core/base_safe_browsing_error_ui.h" | 14 #include "components/security_interstitials/core/base_safe_browsing_error_ui.h" |
13 #include "components/security_interstitials/core/safe_browsing_quiet_error_ui.h" | 15 #include "components/security_interstitials/core/safe_browsing_quiet_error_ui.h" |
14 #include "content/public/browser/interstitial_page.h" | 16 #include "content/public/browser/interstitial_page.h" |
15 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
16 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
17 | 19 |
18 using content::InterstitialPage; | 20 using content::InterstitialPage; |
19 using content::WebContents; | 21 using content::WebContents; |
20 using security_interstitials::BaseSafeBrowsingErrorUI; | 22 using security_interstitials::BaseSafeBrowsingErrorUI; |
21 using security_interstitials::SafeBrowsingQuietErrorUI; | 23 using security_interstitials::SafeBrowsingQuietErrorUI; |
22 using security_interstitials::SecurityInterstitialControllerClient; | 24 using security_interstitials::SecurityInterstitialControllerClient; |
23 | 25 |
24 namespace android_webview { | 26 namespace android_webview { |
25 | 27 |
26 AwSafeBrowsingBlockingPage::AwSafeBrowsingBlockingPage( | 28 AwSafeBrowsingBlockingPage::AwSafeBrowsingBlockingPage( |
27 AwSafeBrowsingUIManager* ui_manager, | 29 AwSafeBrowsingUIManager* ui_manager, |
28 WebContents* web_contents, | 30 WebContents* web_contents, |
29 const GURL& main_frame_url, | 31 const GURL& main_frame_url, |
30 const UnsafeResourceList& unsafe_resources, | 32 const UnsafeResourceList& unsafe_resources, |
31 std::unique_ptr<SecurityInterstitialControllerClient> controller_client, | 33 std::unique_ptr<SecurityInterstitialControllerClient> controller_client, |
32 const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions& display_options, | 34 const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions& display_options, |
33 ErrorUiType errorUiType) | 35 ErrorUiType errorUiType) |
34 : BaseBlockingPage(ui_manager, | 36 : BaseBlockingPage(ui_manager, |
35 web_contents, | 37 web_contents, |
36 main_frame_url, | 38 main_frame_url, |
37 unsafe_resources, | 39 unsafe_resources, |
38 std::move(controller_client), | 40 std::move(controller_client), |
39 display_options) { | 41 display_options), |
42 threat_details_in_progress_(false) { | |
40 if (errorUiType == ErrorUiType::QUIET_SMALL || | 43 if (errorUiType == ErrorUiType::QUIET_SMALL || |
41 errorUiType == ErrorUiType::QUIET_GIANT) { | 44 errorUiType == ErrorUiType::QUIET_GIANT) { |
42 set_sb_error_ui(base::MakeUnique<SafeBrowsingQuietErrorUI>( | 45 set_sb_error_ui(base::MakeUnique<SafeBrowsingQuietErrorUI>( |
43 unsafe_resources[0].url, main_frame_url, | 46 unsafe_resources[0].url, main_frame_url, |
44 GetInterstitialReason(unsafe_resources), display_options, | 47 GetInterstitialReason(unsafe_resources), display_options, |
45 ui_manager->app_locale(), base::Time::NowFromSystemTime(), controller(), | 48 ui_manager->app_locale(), base::Time::NowFromSystemTime(), controller(), |
46 errorUiType == ErrorUiType::QUIET_GIANT)); | 49 errorUiType == ErrorUiType::QUIET_GIANT)); |
47 } | 50 } |
48 | 51 |
49 // TODO(timvolodine): invoke TriggerManager::StartCollectingThreatDetails(), | 52 if (unsafe_resources.size() == 1 && |
50 // (via AwBrowserContext, e.g. | 53 ShouldReportThreatDetails(unsafe_resources[0].threat_type)) { |
51 // AwBrowserContext::FromWebContents(web_contents)), crbug.com/731747. | 54 AwBrowserContext* aw_browser_context = |
55 AwBrowserContext::FromWebContents(web_contents); | |
56 // TODO(timvolodine): create a proper history service; currently the | |
57 // HistoryServiceFactory lives in the chrome/ layer and relies on Profile | |
58 // which we don't have in Android WebView (crbug.com/731744). | |
59 threat_details_in_progress_ = | |
60 aw_browser_context->GetSafeBrowsingTriggerManager() | |
61 ->StartCollectingThreatDetails( | |
62 safe_browsing::SafeBrowsingTriggerType::SECURITY_INTERSTITIAL, | |
63 web_contents, unsafe_resources[0], | |
64 aw_browser_context->GetAwURLRequestContext(), | |
65 /*history_service*/ nullptr, | |
66 sb_error_ui()->get_error_display_options()); | |
67 } | |
52 } | 68 } |
53 | 69 |
54 // static | 70 // static |
55 void AwSafeBrowsingBlockingPage::ShowBlockingPage( | 71 void AwSafeBrowsingBlockingPage::ShowBlockingPage( |
56 AwSafeBrowsingUIManager* ui_manager, | 72 AwSafeBrowsingUIManager* ui_manager, |
57 const UnsafeResource& unsafe_resource) { | 73 const UnsafeResource& unsafe_resource) { |
58 DVLOG(1) << __func__ << " " << unsafe_resource.url.spec(); | 74 DVLOG(1) << __func__ << " " << unsafe_resource.url.spec(); |
59 WebContents* web_contents = unsafe_resource.web_contents_getter.Run(); | 75 WebContents* web_contents = unsafe_resource.web_contents_getter.Run(); |
60 | 76 |
61 if (InterstitialPage::GetInterstitialPage(web_contents) && | 77 if (InterstitialPage::GetInterstitialPage(web_contents) && |
(...skipping 24 matching lines...) Expand all Loading... | |
86 | 102 |
87 AwSafeBrowsingBlockingPage* blocking_page = new AwSafeBrowsingBlockingPage( | 103 AwSafeBrowsingBlockingPage* blocking_page = new AwSafeBrowsingBlockingPage( |
88 ui_manager, web_contents, entry ? entry->GetURL() : GURL(), | 104 ui_manager, web_contents, entry ? entry->GetURL() : GURL(), |
89 unsafe_resources, | 105 unsafe_resources, |
90 CreateControllerClient(web_contents, unsafe_resources, ui_manager), | 106 CreateControllerClient(web_contents, unsafe_resources, ui_manager), |
91 display_options, errorType); | 107 display_options, errorType); |
92 blocking_page->Show(); | 108 blocking_page->Show(); |
93 } | 109 } |
94 } | 110 } |
95 | 111 |
112 void AwSafeBrowsingBlockingPage::FinishThreatDetails( | |
113 const base::TimeDelta& delay, | |
114 bool did_proceed, | |
115 int num_visits) { | |
116 // Not all interstitials collect threat details (eg., incognito mode). | |
lpz
2017/06/30 14:01:23
is this comment accurate (eg: is there incognito i
timvolodine
2017/06/30 14:15:11
Right, no incognito for webview. I've amended the
| |
117 if (!threat_details_in_progress_) | |
118 return; | |
119 | |
120 // Finish computing threat details. TriggerManager will decide if it is safe | |
121 // to send the report. | |
122 AwBrowserContext* aw_browser_context = | |
123 AwBrowserContext::FromWebContents(web_contents()); | |
124 bool report_sent = | |
125 aw_browser_context->GetSafeBrowsingTriggerManager() | |
126 ->FinishCollectingThreatDetails( | |
127 safe_browsing::SafeBrowsingTriggerType::SECURITY_INTERSTITIAL, | |
128 web_contents(), delay, did_proceed, num_visits, | |
129 sb_error_ui()->get_error_display_options()); | |
130 | |
131 if (report_sent) { | |
132 controller()->metrics_helper()->RecordUserInteraction( | |
133 security_interstitials::MetricsHelper::EXTENDED_REPORTING_IS_ENABLED); | |
134 } | |
135 } | |
136 | |
96 } // namespace android_webview | 137 } // namespace android_webview |
OLD | NEW |