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

Side by Side Diff: chrome/browser/ssl/ssl_blocking_page.cc

Issue 400323002: Refactor the captive portal code to move from the ssl_blocking_page class to the ssl_error_classific (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 6 years, 5 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 (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 #include "chrome/browser/ssl/ssl_blocking_page.h" 5 #include "chrome/browser/ssl/ssl_blocking_page.h"
6 6
7 #include "base/build_time.h" 7 #include "base/build_time.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/i18n/time_formatting.h" 10 #include "base/i18n/time_formatting.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 DONT_PROCEED_NAME, 109 DONT_PROCEED_NAME,
110 DONT_PROCEED_DATE, 110 DONT_PROCEED_DATE,
111 DONT_PROCEED_AUTHORITY, 111 DONT_PROCEED_AUTHORITY,
112 MORE, 112 MORE,
113 SHOW_UNDERSTAND, // Used by the summer 2013 Finch trial. Deprecated. 113 SHOW_UNDERSTAND, // Used by the summer 2013 Finch trial. Deprecated.
114 SHOW_INTERNAL_HOSTNAME, 114 SHOW_INTERNAL_HOSTNAME,
115 PROCEED_INTERNAL_HOSTNAME, 115 PROCEED_INTERNAL_HOSTNAME,
116 SHOW_NEW_SITE, 116 SHOW_NEW_SITE,
117 PROCEED_NEW_SITE, 117 PROCEED_NEW_SITE,
118 PROCEED_MANUAL_NONOVERRIDABLE, 118 PROCEED_MANUAL_NONOVERRIDABLE,
119 CAPTIVE_PORTAL_DETECTION_ENABLED, 119 DEPRECATED_CAPTIVE_PORTAL_DETECTION_ENABLED, // Captive Portal errors moved
120 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE, 120 DEPRECATED_CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE, // to
121 CAPTIVE_PORTAL_PROBE_COMPLETED, 121 DEPRECATED_CAPTIVE_PORTAL_PROBE_COMPLETED, // ssl_error_classification.
122 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE, 122 DEPRECATED_CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE,
123 CAPTIVE_PORTAL_NO_RESPONSE, 123 DEPRECATED_CAPTIVE_PORTAL_NO_RESPONSE,
124 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE, 124 DEPRECATED_CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE,
125 CAPTIVE_PORTAL_DETECTED, 125 DEPRECATED_CAPTIVE_PORTAL_DETECTED,
126 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE, 126 DEPRECATED_CAPTIVE_PORTAL_DETECTED_OVERRIDABLE,
meacer 2014/07/21 18:45:14 histograms.xml have entries for the deprecated enu
radhikabhar 2014/07/23 21:41:29 Done.
127 UNUSED_BLOCKING_PAGE_EVENT, 127 UNUSED_BLOCKING_PAGE_EVENT,
128 }; 128 };
129 129
130 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) { 130 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) {
131 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl", 131 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl",
132 event, 132 event,
133 UNUSED_BLOCKING_PAGE_EVENT); 133 UNUSED_BLOCKING_PAGE_EVENT);
134 } 134 }
135 135
136 void RecordSSLBlockingPageDetailedStats( 136 void RecordSSLBlockingPageDetailedStats(
137 bool proceed, 137 bool proceed,
138 int cert_error, 138 int cert_error,
139 bool overridable, 139 bool overridable,
140 bool internal, 140 bool internal,
141 int num_visits, 141 int num_visits) {
142 bool captive_portal_detection_enabled,
143 bool captive_portal_probe_completed,
144 bool captive_portal_no_response,
145 bool captive_portal_detected) {
146 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type", 142 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type",
147 SSLErrorInfo::NetErrorToErrorType(cert_error), SSLErrorInfo::END_OF_ENUM); 143 SSLErrorInfo::NetErrorToErrorType(cert_error), SSLErrorInfo::END_OF_ENUM);
148 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
149 if (captive_portal_detection_enabled)
150 RecordSSLBlockingPageEventStats(
151 overridable ?
152 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE :
153 CAPTIVE_PORTAL_DETECTION_ENABLED);
154 if (captive_portal_probe_completed)
155 RecordSSLBlockingPageEventStats(
156 overridable ?
157 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE :
158 CAPTIVE_PORTAL_PROBE_COMPLETED);
159 // Log only one of portal detected and no response results.
160 if (captive_portal_detected)
161 RecordSSLBlockingPageEventStats(
162 overridable ?
163 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE :
164 CAPTIVE_PORTAL_DETECTED);
165 else if (captive_portal_no_response)
166 RecordSSLBlockingPageEventStats(
167 overridable ?
168 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE :
169 CAPTIVE_PORTAL_NO_RESPONSE);
170 #endif
171 if (!overridable) { 144 if (!overridable) {
172 if (proceed) { 145 if (proceed) {
173 RecordSSLBlockingPageEventStats(PROCEED_MANUAL_NONOVERRIDABLE); 146 RecordSSLBlockingPageEventStats(PROCEED_MANUAL_NONOVERRIDABLE);
174 } 147 }
175 // Overridable is false if the user didn't have any option except to turn 148 // Overridable is false if the user didn't have any option except to turn
176 // back. If that's the case, don't record some of the metrics. 149 // back. If that's the case, don't record some of the metrics.
177 return; 150 return;
178 } 151 }
179 if (num_visits == 0) 152 if (num_visits == 0)
180 RecordSSLBlockingPageEventStats(SHOW_NEW_SITE); 153 RecordSSLBlockingPageEventStats(SHOW_NEW_SITE);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 HistoryService* history_service = HistoryServiceFactory::GetForProfile( 228 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
256 profile, Profile::EXPLICIT_ACCESS); 229 profile, Profile::EXPLICIT_ACCESS);
257 if (history_service) { 230 if (history_service) {
258 history_service->GetVisibleVisitCountToHost( 231 history_service->GetVisibleVisitCountToHost(
259 request_url_, 232 request_url_,
260 base::Bind(&SSLBlockingPage::OnGotHistoryCount, 233 base::Bind(&SSLBlockingPage::OnGotHistoryCount,
261 base::Unretained(this)), 234 base::Unretained(this)),
262 &request_tracker_); 235 &request_tracker_);
263 } 236 }
264 } 237 }
238
239 SSLErrorClassification ssl_error_classification(
240 web_contents_,
241 base::Time::NowFromSystemTime(),
242 *ssl_info_.cert.get());
265 if (SSLErrorInfo::NetErrorToErrorType(cert_error_) == 243 if (SSLErrorInfo::NetErrorToErrorType(cert_error_) ==
266 SSLErrorInfo::CERT_DATE_INVALID) { 244 SSLErrorInfo::CERT_DATE_INVALID) {
267 SSLErrorClassification::RecordUMAStatistics(overridable_ && 245 ssl_error_classification.RecordUMAStatistics(
268 !strict_enforcement_); 246 overridable_ && !strict_enforcement_);
269 } 247 }
270 248
271 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 249 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
272 CaptivePortalService* captive_portal_service = 250 CaptivePortalService* captive_portal_service =
273 CaptivePortalServiceFactory::GetForProfile(profile); 251 CaptivePortalServiceFactory::GetForProfile(profile);
274 captive_portal_detection_enabled_ = captive_portal_service ->enabled(); 252 captive_portal_detection_enabled_ = captive_portal_service ->enabled();
275 captive_portal_service ->DetectCaptivePortal(); 253 captive_portal_service ->DetectCaptivePortal();
276 registrar_.Add(this, 254 registrar_.Add(this,
277 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, 255 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT,
278 content::Source<Profile>(profile)); 256 content::Source<Profile>(profile));
257 ssl_error_classification.RecordCaptivePortalUMAStatistics(
258 overridable_ && !strict_enforcement_);
279 #endif 259 #endif
280 260
281 interstitial_page_ = InterstitialPage::Create( 261 interstitial_page_ = InterstitialPage::Create(
282 web_contents_, true, request_url, this); 262 web_contents_, true, request_url, this);
283 interstitial_page_->Show(); 263 interstitial_page_->Show();
284 } 264 }
285 265
286 SSLBlockingPage::~SSLBlockingPage() { 266 SSLBlockingPage::~SSLBlockingPage() {
287 if (!callback_.is_null()) { 267 if (!callback_.is_null()) {
288 RecordSSLBlockingPageDetailedStats(false, 268 RecordSSLBlockingPageDetailedStats(false,
289 cert_error_, 269 cert_error_,
290 overridable_ && !strict_enforcement_, 270 overridable_ && !strict_enforcement_,
291 internal_, 271 internal_,
292 num_visits_, 272 num_visits_);
293 captive_portal_detection_enabled_,
294 captive_portal_probe_completed_,
295 captive_portal_no_response_,
296 captive_portal_detected_);
297 // The page is closed without the user having chosen what to do, default to 273 // The page is closed without the user having chosen what to do, default to
298 // deny. 274 // deny.
299 NotifyDenyCertificate(); 275 NotifyDenyCertificate();
300 } 276 }
301 } 277 }
302 278
303 std::string SSLBlockingPage::GetHTMLContents() { 279 std::string SSLBlockingPage::GetHTMLContents() {
304 if (trial_condition_ == kCondV1 || trial_condition_ == kCondV1LayoutV2Text) 280 if (trial_condition_ == kCondV1 || trial_condition_ == kCondV1LayoutV2Text)
305 return GetHTMLContentsV1(); 281 return GetHTMLContentsV1();
306 return GetHTMLContentsV2(); 282 return GetHTMLContentsV2();
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 Profile* profile = Profile::FromBrowserContext( 603 Profile* profile = Profile::FromBrowserContext(
628 web_contents_->GetBrowserContext()); 604 web_contents_->GetBrowserContext());
629 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); 605 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile);
630 } 606 }
631 607
632 void SSLBlockingPage::OnProceed() { 608 void SSLBlockingPage::OnProceed() {
633 RecordSSLBlockingPageDetailedStats(true, 609 RecordSSLBlockingPageDetailedStats(true,
634 cert_error_, 610 cert_error_,
635 overridable_ && !strict_enforcement_, 611 overridable_ && !strict_enforcement_,
636 internal_, 612 internal_,
637 num_visits_, 613 num_visits_);
638 captive_portal_detection_enabled_,
639 captive_portal_probe_completed_,
640 captive_portal_no_response_,
641 captive_portal_detected_);
642 // Accepting the certificate resumes the loading of the page. 614 // Accepting the certificate resumes the loading of the page.
643 NotifyAllowCertificate(); 615 NotifyAllowCertificate();
644 } 616 }
645 617
646 void SSLBlockingPage::OnDontProceed() { 618 void SSLBlockingPage::OnDontProceed() {
647 RecordSSLBlockingPageDetailedStats(false, 619 RecordSSLBlockingPageDetailedStats(false,
648 cert_error_, 620 cert_error_,
649 overridable_ && !strict_enforcement_, 621 overridable_ && !strict_enforcement_,
650 internal_, 622 internal_,
651 num_visits_, 623 num_visits_);
652 captive_portal_detection_enabled_,
653 captive_portal_probe_completed_,
654 captive_portal_no_response_,
655 captive_portal_detected_);
656 NotifyDenyCertificate(); 624 NotifyDenyCertificate();
657 } 625 }
658 626
659 void SSLBlockingPage::NotifyDenyCertificate() { 627 void SSLBlockingPage::NotifyDenyCertificate() {
660 // It's possible that callback_ may not exist if the user clicks "Proceed" 628 // It's possible that callback_ may not exist if the user clicks "Proceed"
661 // followed by pressing the back button before the interstitial is hidden. 629 // followed by pressing the back button before the interstitial is hidden.
662 // In that case the certificate will still be treated as allowed. 630 // In that case the certificate will still be treated as allowed.
663 if (callback_.is_null()) 631 if (callback_.is_null())
664 return; 632 return;
665 633
(...skipping 27 matching lines...) Expand all
693 661
694 void SSLBlockingPage::OnGotHistoryCount(bool success, 662 void SSLBlockingPage::OnGotHistoryCount(bool success,
695 int num_visits, 663 int num_visits,
696 base::Time first_visit) { 664 base::Time first_visit) {
697 num_visits_ = num_visits; 665 num_visits_ = num_visits;
698 } 666 }
699 667
700 void SSLBlockingPage::Observe( 668 void SSLBlockingPage::Observe(
701 int type, 669 int type,
702 const content::NotificationSource& source, 670 const content::NotificationSource& source,
703 const content::NotificationDetails& details) { 671 const content::NotificationDetails& details) {
meacer 2014/07/21 18:45:15 I don't think this is needed anymore, it just reco
radhikabhar 2014/07/23 21:41:29 Done.
704 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 672 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
705 // When detection is disabled, captive portal service always sends 673 // When detection is disabled, captive portal service always sends
706 // RESULT_INTERNET_CONNECTED. Ignore any probe results in that case. 674 // RESULT_INTERNET_CONNECTED. Ignore any probe results in that case.
707 if (!captive_portal_detection_enabled_) 675 if (!captive_portal_detection_enabled_)
708 return; 676 return;
709 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) { 677 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) {
710 captive_portal_probe_completed_ = true; 678 captive_portal_probe_completed_ = true;
711 CaptivePortalService::Results* results = 679 CaptivePortalService::Results* results =
712 content::Details<CaptivePortalService::Results>( 680 content::Details<CaptivePortalService::Results>(
713 details).ptr(); 681 details).ptr();
714 // If a captive portal was detected at any point when the interstitial was 682 // If a captive portal was detected at any point when the interstitial was
715 // displayed, assume that the interstitial was caused by a captive portal. 683 // displayed, assume that the interstitial was caused by a captive portal.
716 // Example scenario: 684 // Example scenario:
717 // 1- Interstitial displayed and captive portal detected, setting the flag. 685 // 1- Interstitial displayed and captive portal detected, setting the flag.
718 // 2- Captive portal detection automatically opens portal login page. 686 // 2- Captive portal detection automatically opens portal login page.
719 // 3- User logs in on the portal login page. 687 // 3- User logs in on the portal login page.
720 // A notification will be received here for RESULT_INTERNET_CONNECTED. Make 688 // A notification will be received here for RESULT_INTERNET_CONNECTED. Make
721 // sure we don't clear the captive portal flag, since the interstitial was 689 // sure we don't clear the captive portal flag, since the interstitial was
722 // potentially caused by the captive portal. 690 // potentially caused by the captive portal.
723 captive_portal_detected_ = captive_portal_detected_ || 691 captive_portal_detected_ = captive_portal_detected_ ||
724 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); 692 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL);
725 // Also keep track of non-HTTP portals and error cases. 693 // Also keep track of non-HTTP portals and error cases.
726 captive_portal_no_response_ = captive_portal_no_response_ || 694 captive_portal_no_response_ = captive_portal_no_response_ ||
727 (results->result == captive_portal::RESULT_NO_RESPONSE); 695 (results->result == captive_portal::RESULT_NO_RESPONSE);
728 } 696 }
729 #endif 697 #endif
730 } 698 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ssl/ssl_error_classification.h » ('j') | chrome/browser/ssl/ssl_error_classification.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698