OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ssl/captive_portal_blocking_page.h" | 5 #include "chrome/browser/ssl/captive_portal_blocking_page.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | 17 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| 18 #include "chrome/browser/interstitials/chrome_controller_client.h" |
| 19 #include "chrome/browser/interstitials/chrome_metrics_helper.h" |
17 #include "chrome/browser/ssl/cert_report_helper.h" | 20 #include "chrome/browser/ssl/cert_report_helper.h" |
18 #include "chrome/browser/ssl/ssl_cert_reporter.h" | 21 #include "chrome/browser/ssl/ssl_cert_reporter.h" |
19 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
20 #include "components/captive_portal/captive_portal_detector.h" | 23 #include "components/captive_portal/captive_portal_detector.h" |
21 #include "components/certificate_reporting/error_reporter.h" | 24 #include "components/certificate_reporting/error_reporter.h" |
22 #include "components/security_interstitials/core/common_string_util.h" | 25 #include "components/security_interstitials/core/common_string_util.h" |
23 #include "components/security_interstitials/core/controller_client.h" | 26 #include "components/security_interstitials/core/controller_client.h" |
24 #include "components/security_interstitials/core/metrics_helper.h" | 27 #include "components/security_interstitials/core/metrics_helper.h" |
25 #include "components/url_formatter/url_formatter.h" | 28 #include "components/url_formatter/url_formatter.h" |
26 #include "components/wifi/wifi_service.h" | 29 #include "components/wifi/wifi_service.h" |
27 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
28 #include "net/base/network_change_notifier.h" | 31 #include "net/base/network_change_notifier.h" |
29 #include "net/base/network_interfaces.h" | 32 #include "net/base/network_interfaces.h" |
30 #include "net/ssl/ssl_info.h" | 33 #include "net/ssl/ssl_info.h" |
31 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
32 | 35 |
33 namespace { | 36 namespace { |
34 | 37 |
| 38 const char kMetricsName[] = "captive_portal"; |
| 39 |
35 // Events for UMA. | 40 // Events for UMA. |
36 enum CaptivePortalBlockingPageEvent { | 41 enum CaptivePortalBlockingPageEvent { |
37 SHOW_ALL, | 42 SHOW_ALL, |
38 OPEN_LOGIN_PAGE, | 43 OPEN_LOGIN_PAGE, |
39 CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT | 44 CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT |
40 }; | 45 }; |
41 | 46 |
42 void RecordUMA(CaptivePortalBlockingPageEvent event) { | 47 void RecordUMA(CaptivePortalBlockingPageEvent event) { |
43 UMA_HISTOGRAM_ENUMERATION("interstitial.captive_portal", event, | 48 UMA_HISTOGRAM_ENUMERATION("interstitial.captive_portal", event, |
44 CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT); | 49 CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT); |
45 } | 50 } |
46 | 51 |
| 52 std::unique_ptr<ChromeMetricsHelper> CreateMetricsHelper( |
| 53 content::WebContents* web_contents, |
| 54 const GURL& request_url) { |
| 55 security_interstitials::MetricsHelper::ReportDetails reporting_info; |
| 56 reporting_info.metric_prefix = kMetricsName; |
| 57 std::unique_ptr<ChromeMetricsHelper> metrics_helper = |
| 58 base::MakeUnique<ChromeMetricsHelper>(web_contents, request_url, |
| 59 reporting_info, kMetricsName); |
| 60 metrics_helper.get()->StartRecordingCaptivePortalMetrics(false); |
| 61 return metrics_helper; |
| 62 } |
| 63 |
47 } // namespace | 64 } // namespace |
48 | 65 |
49 // static | 66 // static |
50 const void* const CaptivePortalBlockingPage::kTypeForTesting = | 67 const void* const CaptivePortalBlockingPage::kTypeForTesting = |
51 &CaptivePortalBlockingPage::kTypeForTesting; | 68 &CaptivePortalBlockingPage::kTypeForTesting; |
52 | 69 |
53 CaptivePortalBlockingPage::CaptivePortalBlockingPage( | 70 CaptivePortalBlockingPage::CaptivePortalBlockingPage( |
54 content::WebContents* web_contents, | 71 content::WebContents* web_contents, |
55 const GURL& request_url, | 72 const GURL& request_url, |
56 const GURL& login_url, | 73 const GURL& login_url, |
57 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, | 74 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, |
58 const net::SSLInfo& ssl_info, | 75 const net::SSLInfo& ssl_info, |
59 const base::Callback<void(content::CertificateRequestResultType)>& callback) | 76 const base::Callback<void(content::CertificateRequestResultType)>& callback) |
60 : SecurityInterstitialPage(web_contents, request_url, nullptr), | 77 : SecurityInterstitialPage(web_contents, |
| 78 request_url, |
| 79 CreateMetricsHelper(web_contents, request_url)), |
61 login_url_(login_url), | 80 login_url_(login_url), |
62 callback_(callback) { | 81 callback_(callback) { |
63 DCHECK(login_url_.is_valid()); | 82 DCHECK(login_url_.is_valid()); |
64 | 83 |
65 if (ssl_cert_reporter) { | 84 if (ssl_cert_reporter) { |
66 cert_report_helper_.reset(new CertReportHelper( | 85 cert_report_helper_.reset(new CertReportHelper( |
67 std::move(ssl_cert_reporter), web_contents, request_url, ssl_info, | 86 std::move(ssl_cert_reporter), web_contents, request_url, ssl_info, |
68 certificate_reporting::ErrorReport::INTERSTITIAL_CAPTIVE_PORTAL, false, | 87 certificate_reporting::ErrorReport::INTERSTITIAL_CAPTIVE_PORTAL, false, |
69 nullptr)); | 88 nullptr)); |
70 } | 89 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 206 |
188 void CaptivePortalBlockingPage::CommandReceived(const std::string& command) { | 207 void CaptivePortalBlockingPage::CommandReceived(const std::string& command) { |
189 if (command == "\"pageLoadComplete\"") { | 208 if (command == "\"pageLoadComplete\"") { |
190 // content::WaitForRenderFrameReady sends this message when the page | 209 // content::WaitForRenderFrameReady sends this message when the page |
191 // load completes. Ignore it. | 210 // load completes. Ignore it. |
192 return; | 211 return; |
193 } | 212 } |
194 int command_num = 0; | 213 int command_num = 0; |
195 bool command_is_num = base::StringToInt(command, &command_num); | 214 bool command_is_num = base::StringToInt(command, &command_num); |
196 DCHECK(command_is_num) << command; | 215 DCHECK(command_is_num) << command; |
197 // Any command other than "open the login page" is ignored. | 216 security_interstitials::SecurityInterstitialCommands cmd = |
198 if (command_num == security_interstitials::CMD_OPEN_LOGIN) { | 217 static_cast<security_interstitials::SecurityInterstitialCommands>( |
199 RecordUMA(OPEN_LOGIN_PAGE); | 218 command_num); |
200 CaptivePortalTabHelper::OpenLoginTabForWebContents(web_contents(), true); | 219 switch (cmd) { |
| 220 case security_interstitials::CMD_OPEN_LOGIN: |
| 221 RecordUMA(OPEN_LOGIN_PAGE); |
| 222 CaptivePortalTabHelper::OpenLoginTabForWebContents(web_contents(), true); |
| 223 break; |
| 224 case security_interstitials::CMD_DO_REPORT: |
| 225 controller()->SetReportingPreference(true); |
| 226 break; |
| 227 case security_interstitials::CMD_DONT_REPORT: |
| 228 controller()->SetReportingPreference(false); |
| 229 break; |
| 230 case security_interstitials::CMD_OPEN_REPORTING_PRIVACY: |
| 231 controller()->OpenExtendedReportingPrivacyPolicy(); |
| 232 break; |
| 233 case security_interstitials::CMD_ERROR: |
| 234 case security_interstitials::CMD_TEXT_FOUND: |
| 235 case security_interstitials::CMD_TEXT_NOT_FOUND: |
| 236 // Commands are for testing. |
| 237 break; |
| 238 default: |
| 239 NOTREACHED() << "Command " << cmd |
| 240 << " isn't handled by the captive portal interstitial."; |
201 } | 241 } |
202 } | 242 } |
203 | 243 |
204 void CaptivePortalBlockingPage::OnProceed() { | 244 void CaptivePortalBlockingPage::OnProceed() { |
205 if (cert_report_helper_) { | 245 NOTREACHED() |
206 // Finish collecting information about invalid certificates, if the | 246 << "Cannot proceed through the error on a captive portal interstitial."; |
207 // user opted in to. | |
208 cert_report_helper_->FinishCertCollection( | |
209 certificate_reporting::ErrorReport::USER_PROCEEDED); | |
210 } | |
211 } | 247 } |
212 | 248 |
213 void CaptivePortalBlockingPage::OnDontProceed() { | 249 void CaptivePortalBlockingPage::OnDontProceed() { |
214 if (cert_report_helper_) { | 250 if (cert_report_helper_) { |
215 // Finish collecting information about invalid certificates, if the | 251 // Finish collecting information about invalid certificates, if the |
216 // user opted in to. | 252 // user opted in to. |
217 cert_report_helper_->FinishCertCollection( | 253 cert_report_helper_->FinishCertCollection( |
218 certificate_reporting::ErrorReport::USER_DID_NOT_PROCEED); | 254 certificate_reporting::ErrorReport::USER_DID_NOT_PROCEED); |
219 } | 255 } |
220 | 256 |
221 // Need to explicity deny the certificate via the callback, otherwise memory | 257 // Need to explicity deny the certificate via the callback, otherwise memory |
222 // is leaked. | 258 // is leaked. |
223 if (!callback_.is_null()) { | 259 if (!callback_.is_null()) { |
224 callback_.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL); | 260 callback_.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL); |
225 callback_.Reset(); | 261 callback_.Reset(); |
226 } | 262 } |
227 } | 263 } |
OLD | NEW |