| 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_tab_reloader.h" | 9 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" |
| 10 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | 10 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 profile_(web_contents ? Profile::FromBrowserContext( | 36 profile_(web_contents ? Profile::FromBrowserContext( |
| 37 web_contents->GetBrowserContext()) | 37 web_contents->GetBrowserContext()) |
| 38 : NULL), | 38 : NULL), |
| 39 tab_reloader_( | 39 tab_reloader_( |
| 40 new CaptivePortalTabReloader( | 40 new CaptivePortalTabReloader( |
| 41 profile_, | 41 profile_, |
| 42 web_contents, | 42 web_contents, |
| 43 base::Bind(&CaptivePortalTabHelper::OpenLoginTab, | 43 base::Bind(&CaptivePortalTabHelper::OpenLoginTab, |
| 44 base::Unretained(this)))), | 44 base::Unretained(this)))), |
| 45 login_detector_(new CaptivePortalLoginDetector(profile_)), | 45 login_detector_(new CaptivePortalLoginDetector(profile_)), |
| 46 web_contents_(web_contents), |
| 46 pending_error_code_(net::OK), | 47 pending_error_code_(net::OK), |
| 47 provisional_render_view_host_(NULL) { | 48 provisional_render_view_host_(NULL) { |
| 48 registrar_.Add(this, | 49 registrar_.Add(this, |
| 49 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | 50 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, |
| 50 content::Source<Profile>(profile_)); | 51 content::Source<Profile>(profile_)); |
| 51 registrar_.Add(this, | 52 registrar_.Add(this, |
| 52 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 53 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| 53 content::Source<content::WebContents>(web_contents)); | 54 content::Source<content::WebContents>(web_contents)); |
| 54 registrar_.Add(this, | 55 registrar_.Add(this, |
| 55 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, | 56 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 void CaptivePortalTabHelper::SetTabReloaderForTest( | 232 void CaptivePortalTabHelper::SetTabReloaderForTest( |
| 232 CaptivePortalTabReloader* tab_reloader) { | 233 CaptivePortalTabReloader* tab_reloader) { |
| 233 tab_reloader_.reset(tab_reloader); | 234 tab_reloader_.reset(tab_reloader); |
| 234 } | 235 } |
| 235 | 236 |
| 236 CaptivePortalTabReloader* CaptivePortalTabHelper::GetTabReloaderForTest() { | 237 CaptivePortalTabReloader* CaptivePortalTabHelper::GetTabReloaderForTest() { |
| 237 return tab_reloader_.get(); | 238 return tab_reloader_.get(); |
| 238 } | 239 } |
| 239 | 240 |
| 240 void CaptivePortalTabHelper::OpenLoginTab() { | 241 void CaptivePortalTabHelper::OpenLoginTab() { |
| 241 Browser* browser = browser::FindTabbedBrowser(profile_, true); | 242 Browser* browser = browser::FindBrowserWithWebContents(web_contents_); |
| 243 |
| 242 // If the Profile doesn't have a tabbed browser window open, do nothing. | 244 // If the Profile doesn't have a tabbed browser window open, do nothing. |
| 243 if (!browser) | 245 if (!browser) |
| 244 return; | 246 return; |
| 245 | 247 |
| 246 // Check if the Profile's topmost browser window already has a login tab. | 248 // Check if the Profile's topmost browser window already has a login tab. |
| 247 // If so, do nothing. | 249 // If so, do nothing. |
| 248 // TODO(mmenke): Consider focusing that tab, at least if this is the tab | 250 // TODO(mmenke): Consider focusing that tab, at least if this is the tab |
| 249 // helper for the currently active tab for the profile. | 251 // helper for the currently active tab for the profile. |
| 250 for (int i = 0; i < browser->tab_count(); ++i) { | 252 for (int i = 0; i < browser->tab_count(); ++i) { |
| 251 content::WebContents* web_contents = chrome::GetWebContentsAt(browser, i); | 253 content::WebContents* web_contents = chrome::GetWebContentsAt(browser, i); |
| 252 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper = | 254 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper = |
| 253 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents); | 255 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents); |
| 254 if (captive_portal_tab_helper->IsLoginTab()) | 256 if (captive_portal_tab_helper->IsLoginTab()) |
| 255 return; | 257 return; |
| 256 } | 258 } |
| 257 | 259 |
| 258 // Otherwise, open a login tab. Only end up here when a captive portal result | 260 // 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. | 261 // was received, so it's safe to assume |profile_| has a CaptivePortalService. |
| 260 TabContents* tab_contents = chrome::AddSelectedTabWithURL( | 262 TabContents* tab_contents = chrome::AddSelectedTabWithURL( |
| 261 browser, | 263 browser, |
| 262 CaptivePortalServiceFactory::GetForProfile(profile_)->test_url(), | 264 CaptivePortalServiceFactory::GetForProfile(profile_)->test_url(), |
| 263 content::PAGE_TRANSITION_TYPED); | 265 content::PAGE_TRANSITION_TYPED); |
| 264 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper = | 266 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper = |
| 265 captive_portal::CaptivePortalTabHelper::FromWebContents( | 267 captive_portal::CaptivePortalTabHelper::FromWebContents( |
| 266 tab_contents->web_contents()); | 268 tab_contents->web_contents()); |
| 267 captive_portal_tab_helper->SetIsLoginTab(); | 269 captive_portal_tab_helper->SetIsLoginTab(); |
| 268 } | 270 } |
| 269 | 271 |
| 270 } // namespace captive_portal | 272 } // namespace captive_portal |
| OLD | NEW |