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/ssl_error_handler.h" | 5 #include "chrome/browser/ssl/ssl_error_handler.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/safe_browsing/ui_manager.h" |
12 #include "chrome/browser/ssl/ssl_blocking_page.h" | 13 #include "chrome/browser/ssl/ssl_blocking_page.h" |
13 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
14 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
16 | 17 |
17 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 18 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
18 #include "chrome/browser/captive_portal/captive_portal_service.h" | 19 #include "chrome/browser/captive_portal/captive_portal_service.h" |
19 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | 20 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
20 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | 21 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
21 #include "chrome/browser/ssl/captive_portal_blocking_page.h" | 22 #include "chrome/browser/ssl/captive_portal_blocking_page.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } // namespace | 83 } // namespace |
83 | 84 |
84 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SSLErrorHandler); | 85 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SSLErrorHandler); |
85 | 86 |
86 void SSLErrorHandler::HandleSSLError( | 87 void SSLErrorHandler::HandleSSLError( |
87 content::WebContents* web_contents, | 88 content::WebContents* web_contents, |
88 int cert_error, | 89 int cert_error, |
89 const net::SSLInfo& ssl_info, | 90 const net::SSLInfo& ssl_info, |
90 const GURL& request_url, | 91 const GURL& request_url, |
91 int options_mask, | 92 int options_mask, |
| 93 SafeBrowsingUIManager* safe_browsing_ui_manager, |
92 const base::Callback<void(bool)>& callback) { | 94 const base::Callback<void(bool)>& callback) { |
93 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 95 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
94 CaptivePortalTabHelper* captive_portal_tab_helper = | 96 CaptivePortalTabHelper* captive_portal_tab_helper = |
95 CaptivePortalTabHelper::FromWebContents(web_contents); | 97 CaptivePortalTabHelper::FromWebContents(web_contents); |
96 if (captive_portal_tab_helper) { | 98 if (captive_portal_tab_helper) { |
97 captive_portal_tab_helper->OnSSLCertError(ssl_info); | 99 captive_portal_tab_helper->OnSSLCertError(ssl_info); |
98 } | 100 } |
99 #endif | 101 #endif |
100 DCHECK(!FromWebContents(web_contents)); | 102 DCHECK(!FromWebContents(web_contents)); |
101 web_contents->SetUserData(UserDataKey(), | 103 web_contents->SetUserData( |
102 new SSLErrorHandler(web_contents, cert_error, | 104 UserDataKey(), |
103 ssl_info, request_url, | 105 new SSLErrorHandler(web_contents, cert_error, ssl_info, request_url, |
104 options_mask, callback)); | 106 options_mask, safe_browsing_ui_manager, callback)); |
105 | 107 |
106 SSLErrorHandler* error_handler = | 108 SSLErrorHandler* error_handler = |
107 SSLErrorHandler::FromWebContents(web_contents); | 109 SSLErrorHandler::FromWebContents(web_contents); |
108 error_handler->StartHandlingError(); | 110 error_handler->StartHandlingError(); |
109 } | 111 } |
110 | 112 |
111 // static | 113 // static |
112 void SSLErrorHandler::SetInterstitialDelayTypeForTest( | 114 void SSLErrorHandler::SetInterstitialDelayTypeForTest( |
113 SSLErrorHandler::InterstitialDelayType delay) { | 115 SSLErrorHandler::InterstitialDelayType delay) { |
114 g_interstitial_delay_type = delay; | 116 g_interstitial_delay_type = delay; |
115 } | 117 } |
116 | 118 |
117 // static | 119 // static |
118 void SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest( | 120 void SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest( |
119 TimerStartedCallback* callback) { | 121 TimerStartedCallback* callback) { |
120 DCHECK(!callback || !callback->is_null()); | 122 DCHECK(!callback || !callback->is_null()); |
121 g_timer_started_callback = callback; | 123 g_timer_started_callback = callback; |
122 } | 124 } |
123 | 125 |
124 SSLErrorHandler::SSLErrorHandler(content::WebContents* web_contents, | 126 SSLErrorHandler::SSLErrorHandler( |
125 int cert_error, | 127 content::WebContents* web_contents, |
126 const net::SSLInfo& ssl_info, | 128 int cert_error, |
127 const GURL& request_url, | 129 const net::SSLInfo& ssl_info, |
128 int options_mask, | 130 const GURL& request_url, |
129 const base::Callback<void(bool)>& callback) | 131 int options_mask, |
| 132 SafeBrowsingUIManager* safe_browsing_ui_manager, |
| 133 const base::Callback<void(bool)>& callback) |
130 : content::WebContentsObserver(web_contents), | 134 : content::WebContentsObserver(web_contents), |
131 web_contents_(web_contents), | 135 web_contents_(web_contents), |
132 cert_error_(cert_error), | 136 cert_error_(cert_error), |
133 ssl_info_(ssl_info), | 137 ssl_info_(ssl_info), |
134 request_url_(request_url), | 138 request_url_(request_url), |
135 options_mask_(options_mask), | 139 options_mask_(options_mask), |
136 callback_(callback) { | 140 callback_(callback), |
| 141 safe_browsing_ui_manager_(safe_browsing_ui_manager) { |
137 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 142 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
138 Profile* profile = Profile::FromBrowserContext( | 143 Profile* profile = Profile::FromBrowserContext( |
139 web_contents->GetBrowserContext()); | 144 web_contents->GetBrowserContext()); |
140 registrar_.Add(this, | 145 registrar_.Add(this, |
141 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | 146 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, |
142 content::Source<Profile>(profile)); | 147 content::Source<Profile>(profile)); |
143 #endif | 148 #endif |
144 } | 149 } |
145 | 150 |
146 SSLErrorHandler::~SSLErrorHandler() { | 151 SSLErrorHandler::~SSLErrorHandler() { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 #endif | 201 #endif |
197 } | 202 } |
198 | 203 |
199 void SSLErrorHandler::ShowSSLInterstitial() { | 204 void SSLErrorHandler::ShowSSLInterstitial() { |
200 // Show SSL blocking page. The interstitial owns the blocking page. | 205 // Show SSL blocking page. The interstitial owns the blocking page. |
201 RecordUMA(SSLBlockingPage::IsOptionsOverridable(options_mask_) ? | 206 RecordUMA(SSLBlockingPage::IsOptionsOverridable(options_mask_) ? |
202 SHOW_SSL_INTERSTITIAL_OVERRIDABLE : | 207 SHOW_SSL_INTERSTITIAL_OVERRIDABLE : |
203 SHOW_SSL_INTERSTITIAL_NONOVERRIDABLE); | 208 SHOW_SSL_INTERSTITIAL_NONOVERRIDABLE); |
204 (new SSLBlockingPage(web_contents_, cert_error_, ssl_info_, request_url_, | 209 (new SSLBlockingPage(web_contents_, cert_error_, ssl_info_, request_url_, |
205 options_mask_, base::Time::NowFromSystemTime(), | 210 options_mask_, base::Time::NowFromSystemTime(), |
206 callback_))->Show(); | 211 safe_browsing_ui_manager_, callback_))->Show(); |
207 // Once an interstitial is displayed, no need to keep the handler around. | 212 // Once an interstitial is displayed, no need to keep the handler around. |
208 // This is the equivalent of "delete this". | 213 // This is the equivalent of "delete this". |
209 web_contents_->RemoveUserData(UserDataKey()); | 214 web_contents_->RemoveUserData(UserDataKey()); |
210 } | 215 } |
211 | 216 |
212 void SSLErrorHandler::Observe( | 217 void SSLErrorHandler::Observe( |
213 int type, | 218 int type, |
214 const content::NotificationSource& source, | 219 const content::NotificationSource& source, |
215 const content::NotificationDetails& details) { | 220 const content::NotificationDetails& details) { |
216 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 221 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
(...skipping 15 matching lines...) Expand all Loading... |
232 void SSLErrorHandler::DidStartNavigationToPendingEntry( | 237 void SSLErrorHandler::DidStartNavigationToPendingEntry( |
233 const GURL& url, | 238 const GURL& url, |
234 content::NavigationController::ReloadType reload_type) { | 239 content::NavigationController::ReloadType reload_type) { |
235 // Need to explicity deny the certificate via the callback, otherwise memory | 240 // Need to explicity deny the certificate via the callback, otherwise memory |
236 // is leaked. | 241 // is leaked. |
237 if (!callback_.is_null()) { | 242 if (!callback_.is_null()) { |
238 base::ResetAndReturn(&callback_).Run(false); | 243 base::ResetAndReturn(&callback_).Run(false); |
239 } | 244 } |
240 web_contents_->RemoveUserData(UserDataKey()); | 245 web_contents_->RemoveUserData(UserDataKey()); |
241 } | 246 } |
OLD | NEW |