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

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

Issue 318213002: Add custom interstitial for captive portals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Stop the timer at the right place Created 6 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ssl/ssl_error_handler.h"
6
7 #include "base/metrics/histogram.h"
8 #include "base/time/time.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ssl/ssl_blocking_page.h"
11 #include "chrome/common/chrome_version_info.h"
12 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/notification_source.h"
14 #include "content/public/browser/web_contents.h"
15
16 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
17 #include "chrome/browser/captive_portal/captive_portal_service.h"
18 #include "chrome/browser/captive_portal/captive_portal_service_factory.h"
19 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
20 #include "chrome/browser/ssl/captive_portal_blocking_page.h"
21 #endif
22
23 namespace {
24
25 // Events for UMA.
26 enum SSLErrorHandlerEvent {
27 HANDLE_ALL,
28 CAPTIVE_PORTAL_CHECK,
29 SHOW_CAPTIVE_PORTAL_INTERSTITIAL,
30 SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE,
31 SHOW_SSL_INTERSTITIAL,
32 SHOW_SSL_INTERSTITIAL_OVERRIDABLE,
33 SSL_ERROR_HANDLER_EVENT_COUNT
34 };
35
36 void RecordUMA(SSLErrorHandlerEvent event) {
37 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_handler",
38 event,
39 SSL_ERROR_HANDLER_EVENT_COUNT);
40 }
41
42 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
43 bool IsCaptivePortalInterstitialEnabled() {
44 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
45 return channel <= chrome::VersionInfo::CHANNEL_DEV;
46 }
47 #endif
48
49 } // namespace
50
51 SSLErrorHandler::SSLErrorHandler(content::WebContents* web_contents,
52 int cert_error,
53 const net::SSLInfo& ssl_info,
54 const GURL& request_url,
55 const int options_mask,
56 const base::TimeDelta ssl_error_delay,
57 const base::Callback<void(bool)>& callback)
58 : content::WebContentsObserver(web_contents),
59 web_contents_(web_contents),
60 cert_error_(cert_error),
61 ssl_info_(ssl_info),
62 request_url_(request_url),
63 options_mask_(options_mask),
64 callback_(callback),
65 ssl_interstitial_display_delay_(ssl_error_delay) {
66 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
67 Profile* profile = Profile::FromBrowserContext(
68 web_contents_->GetBrowserContext());
69 registrar_.Add(this,
70 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT,
71 content::Source<Profile>(profile));
72 #endif
73 }
74
75 SSLErrorHandler::~SSLErrorHandler() {
76 }
77
78 void SSLErrorHandler::HandleSSLError(
79 content::WebContents* web_contents,
80 int cert_error,
81 const net::SSLInfo& ssl_info,
82 const GURL& request_url,
83 int options_mask,
84 const base::Callback<void(bool)>& callback) {
85 // SSL interstitials aren't delayed if captive portal detection is disabled.
86 base::TimeDelta ssl_error_delay;
87 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
88 CaptivePortalTabHelper* captive_portal_tab_helper =
89 CaptivePortalTabHelper::FromWebContents(web_contents);
90 if (captive_portal_tab_helper) {
91 captive_portal_tab_helper->OnSSLCertError(ssl_info);
92 ssl_error_delay = captive_portal_tab_helper->GetSSLErrorDelay();
mmenke 2014/11/10 17:32:08 I need to spend some time thinking about how to mo
93 }
94 #endif
95 (new SSLErrorHandler(web_contents, cert_error, ssl_info, request_url,
mmenke 2014/11/10 17:32:08 nit: +1 indent
meacer 2014/11/14 00:30:25 Done.
96 options_mask, ssl_error_delay, callback))->Handle();
97 }
98
99 void SSLErrorHandler::Handle() {
100 RecordUMA(HANDLE_ALL);
101
102 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
103 if (IsCaptivePortalInterstitialEnabled()) {
104 CheckForCaptivePortal();
105 timer_.Start(FROM_HERE, ssl_interstitial_display_delay_,
106 base::Bind(&SSLErrorHandler::OnTimerExpired,
107 base::Unretained(this)));
108 return;
109 }
110 #endif
111 // Display an SSL interstitial.
112 ShowSSLInterstitial();
113 }
114
115 void SSLErrorHandler::CheckForCaptivePortal() {
116 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
117 RecordUMA(CAPTIVE_PORTAL_CHECK);
mmenke 2014/11/10 17:32:08 Do we get anything out of this histogram? Basical
meacer 2014/11/14 00:30:25 Mostly convenience. With this one doesn't need to
meacer 2014/11/14 00:31:32 Actually, I'll probably delete this histogram.
118 Profile* profile = Profile::FromBrowserContext(
119 web_contents_->GetBrowserContext());
120 CaptivePortalService* captive_portal_service =
121 CaptivePortalServiceFactory::GetForProfile(profile);
122 captive_portal_service->DetectCaptivePortal();
123 #endif
124 }
125
126 void SSLErrorHandler::ShowCaptivePortalInterstitial() {
127 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
128 // Show captive portal blocking page. The interstitial owns the blocking page.
129 RecordUMA(SSLBlockingPage::IsOverridable(options_mask_) ?
130 SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE :
131 SHOW_CAPTIVE_PORTAL_INTERSTITIAL);
132 (new CaptivePortalBlockingPage(web_contents_, request_url_))->Show();
133 delete this;
134 #else
135 NOTREACHED();
136 #endif
137 }
138
139 void SSLErrorHandler::ShowSSLInterstitial() {
140 // Show SSL blocking page. The interstitial owns the blocking page.
141 RecordUMA(SSLBlockingPage::IsOverridable(options_mask_) ?
142 SHOW_SSL_INTERSTITIAL_OVERRIDABLE :
143 SHOW_SSL_INTERSTITIAL);
144 (new SSLBlockingPage(web_contents_, cert_error_, ssl_info_, request_url_,
145 options_mask_, callback_))->Show();
146 delete this;
147 }
148
149 void SSLErrorHandler::OnTimerExpired() {
150 ShowSSLInterstitial();
151 }
152
153 void SSLErrorHandler::Observe(
154 int type,
155 const content::NotificationSource& source,
156 const content::NotificationDetails& details) {
157 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
158 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) {
159 timer_.Stop();
160 CaptivePortalService::Results* results =
161 content::Details<CaptivePortalService::Results>(details).ptr();
162 if (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL)
163 ShowCaptivePortalInterstitial();
164 else
165 ShowSSLInterstitial();
166 }
167 #endif
168 }
169
170 void SSLErrorHandler::DidStartNavigationToPendingEntry(
171 const GURL& url,
172 content::NavigationController::ReloadType reload_type) {
173 delete this;
174 }
175
176 void SSLErrorHandler::DidStopLoading(
177 content::RenderViewHost* render_view_host) {
178 delete this;
179 }
180
181 void SSLErrorHandler::WebContentsDestroyed() {
182 delete this;
183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698