Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/captive_portal/captive_portal_tab_helper.h" | 5 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/captive_portal/captive_portal_login_detector.h" | 8 #include "chrome/browser/captive_portal/captive_portal_login_detector.h" |
| 9 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | 9 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
| 10 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" | 10 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "content/public/browser/resource_request_details.h" | 24 #include "content/public/browser/resource_request_details.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
| 27 #include "net/ssl/ssl_info.h" | 27 #include "net/ssl/ssl_info.h" |
| 28 | 28 |
| 29 using captive_portal::CaptivePortalResult; | 29 using captive_portal::CaptivePortalResult; |
| 30 using content::ResourceType; | 30 using content::ResourceType; |
| 31 | 31 |
| 32 DEFINE_WEB_CONTENTS_USER_DATA_KEY(CaptivePortalTabHelper); | 32 DEFINE_WEB_CONTENTS_USER_DATA_KEY(CaptivePortalTabHelper); |
| 33 | 33 |
| 34 // The delay before displaying the SSL interstitial for cert errors. | |
| 35 // - If a "captive portal detected" result arrives in this many seconds, | |
| 36 // a captive portal interstitial is displayed. | |
| 37 // - Otherwise, an SSL interstitial is displayed. | |
| 38 const int kDefaultSSLInterstitialDisplayDelay = 2; | |
| 39 | |
| 34 CaptivePortalTabHelper::CaptivePortalTabHelper( | 40 CaptivePortalTabHelper::CaptivePortalTabHelper( |
| 35 content::WebContents* web_contents) | 41 content::WebContents* web_contents) |
| 36 : content::WebContentsObserver(web_contents), | 42 : content::WebContentsObserver(web_contents), |
| 37 // web_contents is NULL in unit tests. | 43 // web_contents is NULL in unit tests. |
| 38 profile_(web_contents ? Profile::FromBrowserContext( | 44 profile_(web_contents ? Profile::FromBrowserContext( |
| 39 web_contents->GetBrowserContext()) | 45 web_contents->GetBrowserContext()) |
| 40 : NULL), | 46 : NULL), |
| 41 tab_reloader_( | 47 tab_reloader_( |
| 42 new CaptivePortalTabReloader( | 48 new CaptivePortalTabReloader( |
| 43 profile_, | 49 profile_, |
| 44 web_contents, | 50 web_contents, |
| 45 base::Bind(&CaptivePortalTabHelper::OpenLoginTab, | 51 base::Bind(&CaptivePortalTabHelper::OpenLoginTabForWebContents, |
| 46 base::Unretained(this)))), | 52 web_contents, false))), |
| 47 login_detector_(new CaptivePortalLoginDetector(profile_)), | 53 login_detector_(new CaptivePortalLoginDetector(profile_)), |
| 48 web_contents_(web_contents), | 54 web_contents_(web_contents), |
| 49 pending_error_code_(net::OK), | 55 pending_error_code_(net::OK), |
| 56 ssl_error_delay_( | |
| 57 base::TimeDelta::FromSeconds(kDefaultSSLInterstitialDisplayDelay)), | |
|
mmenke
2014/10/30 19:28:01
I don't think this value makes any sense here - th
meacer
2014/11/06 21:21:55
Yes, for example SSLCertErrorLogin will fail if it
mmenke
2014/11/06 22:12:40
I want to play around with this locally to better
| |
| 50 provisional_render_view_host_(NULL) { | 58 provisional_render_view_host_(NULL) { |
| 51 registrar_.Add(this, | 59 registrar_.Add(this, |
| 52 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | 60 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, |
| 53 content::Source<Profile>(profile_)); | 61 content::Source<Profile>(profile_)); |
| 54 registrar_.Add(this, | 62 registrar_.Add(this, |
| 55 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 63 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| 56 content::Source<content::WebContents>(web_contents)); | 64 content::Source<content::WebContents>(web_contents)); |
| 57 } | 65 } |
| 58 | 66 |
| 59 CaptivePortalTabHelper::~CaptivePortalTabHelper() { | 67 CaptivePortalTabHelper::~CaptivePortalTabHelper() { |
| 60 } | 68 } |
| 61 | 69 |
| 70 base::TimeDelta CaptivePortalTabHelper::GetSSLErrorDelay() const { | |
| 71 return ssl_error_delay_; | |
| 72 } | |
| 73 | |
| 74 void CaptivePortalTabHelper::SetSSLErrorDelayForTest( | |
| 75 base::TimeDelta ssl_error_delay) { | |
| 76 ssl_error_delay_ = ssl_error_delay; | |
| 77 } | |
| 78 | |
| 62 void CaptivePortalTabHelper::RenderViewDeleted( | 79 void CaptivePortalTabHelper::RenderViewDeleted( |
| 63 content::RenderViewHost* render_view_host) { | 80 content::RenderViewHost* render_view_host) { |
| 64 // This can happen when a cross-process navigation is aborted, either by | 81 // This can happen when a cross-process navigation is aborted, either by |
| 65 // pressing stop or by starting a new cross-process navigation that can't | 82 // pressing stop or by starting a new cross-process navigation that can't |
| 66 // re-use |provisional_render_view_host_|. May also happen on a crash. | 83 // re-use |provisional_render_view_host_|. May also happen on a crash. |
| 67 if (render_view_host == provisional_render_view_host_) | 84 if (render_view_host == provisional_render_view_host_) |
| 68 OnLoadAborted(); | 85 OnLoadAborted(); |
| 69 } | 86 } |
| 70 | 87 |
| 71 void CaptivePortalTabHelper::DidStartProvisionalLoadForFrame( | 88 void CaptivePortalTabHelper::DidStartProvisionalLoadForFrame( |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 | 245 |
| 229 void CaptivePortalTabHelper::SetTabReloaderForTest( | 246 void CaptivePortalTabHelper::SetTabReloaderForTest( |
| 230 CaptivePortalTabReloader* tab_reloader) { | 247 CaptivePortalTabReloader* tab_reloader) { |
| 231 tab_reloader_.reset(tab_reloader); | 248 tab_reloader_.reset(tab_reloader); |
| 232 } | 249 } |
| 233 | 250 |
| 234 CaptivePortalTabReloader* CaptivePortalTabHelper::GetTabReloaderForTest() { | 251 CaptivePortalTabReloader* CaptivePortalTabHelper::GetTabReloaderForTest() { |
| 235 return tab_reloader_.get(); | 252 return tab_reloader_.get(); |
| 236 } | 253 } |
| 237 | 254 |
| 238 void CaptivePortalTabHelper::OpenLoginTab() { | 255 // static |
| 239 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 256 void CaptivePortalTabHelper::OpenLoginTabForWebContents( |
|
mmenke
2014/10/30 19:28:01
Definition order should match declaration order.
meacer
2014/11/06 21:21:55
Done.
| |
| 257 content::WebContents* web_contents, | |
| 258 bool focus) { | |
| 259 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | |
| 240 | 260 |
| 241 // If the Profile doesn't have a tabbed browser window open, do nothing. | 261 // If the Profile doesn't have a tabbed browser window open, do nothing. |
| 242 if (!browser) | 262 if (!browser) |
| 243 return; | 263 return; |
| 244 | 264 |
| 245 // Check if the Profile's topmost browser window already has a login tab. | 265 // Check if the Profile's topmost browser window already has a login tab. |
| 246 // If so, do nothing. | 266 // If so, do nothing. |
| 247 // TODO(mmenke): Consider focusing that tab, at least if this is the tab | 267 // TODO(mmenke): Consider focusing that tab, at least if this is the tab |
| 248 // helper for the currently active tab for the profile. | 268 // helper for the currently active tab for the profile. |
| 249 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { | 269 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { |
| 250 content::WebContents* web_contents = | 270 content::WebContents* contents = |
| 251 browser->tab_strip_model()->GetWebContentsAt(i); | 271 browser->tab_strip_model()->GetWebContentsAt(i); |
| 252 CaptivePortalTabHelper* captive_portal_tab_helper = | 272 CaptivePortalTabHelper* captive_portal_tab_helper = |
| 253 CaptivePortalTabHelper::FromWebContents(web_contents); | 273 CaptivePortalTabHelper::FromWebContents(contents); |
| 254 if (captive_portal_tab_helper->IsLoginTab()) | 274 if (captive_portal_tab_helper->IsLoginTab()) { |
| 275 if (focus) | |
| 276 browser->tab_strip_model()->ActivateTabAt(i, false); | |
| 255 return; | 277 return; |
| 278 } | |
| 256 } | 279 } |
| 257 | 280 |
| 258 // Otherwise, open a login tab. Only end up here when a captive portal result | 281 // Otherwise, open a login tab. Only end up here when a captive portal result |
| 259 // was received, so it's safe to assume |profile_| has a CaptivePortalService. | 282 // was received, so it's safe to assume profile has a CaptivePortalService. |
| 260 content::WebContents* web_contents = chrome::AddSelectedTabWithURL( | 283 content::WebContents* new_contents = chrome::AddSelectedTabWithURL( |
| 261 browser, | 284 browser, |
| 262 CaptivePortalServiceFactory::GetForProfile(profile_)->test_url(), | 285 CaptivePortalServiceFactory::GetForProfile( |
| 263 ui::PAGE_TRANSITION_TYPED); | 286 browser->profile())->test_url(), |
| 287 ui::PAGE_TRANSITION_TYPED); | |
| 264 CaptivePortalTabHelper* captive_portal_tab_helper = | 288 CaptivePortalTabHelper* captive_portal_tab_helper = |
| 265 CaptivePortalTabHelper::FromWebContents(web_contents); | 289 CaptivePortalTabHelper::FromWebContents(new_contents); |
| 266 captive_portal_tab_helper->SetIsLoginTab(); | 290 captive_portal_tab_helper->SetIsLoginTab(); |
| 267 } | 291 } |
| OLD | NEW |