| 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" |
| 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
| 13 #include "chrome/browser/ui/browser_tabstrip.h" | 14 #include "chrome/browser/ui/browser_tabstrip.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
| 17 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 19 #include "content/public/browser/notification_types.h" | 20 #include "content/public/browser/notification_types.h" |
| 20 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
| 21 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
| 22 #include "content/public/browser/resource_request_details.h" | 23 #include "content/public/browser/resource_request_details.h" |
| 23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 24 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 25 #include "net/base/ssl_info.h" | 26 #include "net/base/ssl_info.h" |
| 26 | 27 |
| 27 namespace captive_portal { | 28 namespace captive_portal { |
| 28 | 29 |
| 30 int CaptivePortalTabHelper::kUserDataKey; |
| 31 |
| 29 CaptivePortalTabHelper::CaptivePortalTabHelper( | 32 CaptivePortalTabHelper::CaptivePortalTabHelper( |
| 30 Profile* profile, | |
| 31 content::WebContents* web_contents) | 33 content::WebContents* web_contents) |
| 32 : content::WebContentsObserver(web_contents), | 34 : content::WebContentsObserver(web_contents), |
| 35 // web_contents is NULL in unit tests. |
| 36 profile_(web_contents ? Profile::FromBrowserContext( |
| 37 web_contents->GetBrowserContext()) |
| 38 : NULL), |
| 33 tab_reloader_( | 39 tab_reloader_( |
| 34 new CaptivePortalTabReloader( | 40 new CaptivePortalTabReloader( |
| 35 profile, | 41 profile_, |
| 36 web_contents, | 42 web_contents, |
| 37 base::Bind(&CaptivePortalTabHelper::OpenLoginTab, | 43 base::Bind(&CaptivePortalTabHelper::OpenLoginTab, |
| 38 base::Unretained(this)))), | 44 base::Unretained(this)))), |
| 39 login_detector_(new CaptivePortalLoginDetector(profile)), | 45 login_detector_(new CaptivePortalLoginDetector(profile_)), |
| 40 profile_(profile), | |
| 41 pending_error_code_(net::OK), | 46 pending_error_code_(net::OK), |
| 42 provisional_render_view_host_(NULL) { | 47 provisional_render_view_host_(NULL) { |
| 43 registrar_.Add(this, | 48 registrar_.Add(this, |
| 44 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | 49 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, |
| 45 content::Source<Profile>(profile_)); | 50 content::Source<Profile>(profile_)); |
| 46 registrar_.Add(this, | 51 registrar_.Add(this, |
| 47 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 52 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| 48 content::Source<content::WebContents>(web_contents)); | 53 content::Source<content::WebContents>(web_contents)); |
| 49 registrar_.Add(this, | 54 registrar_.Add(this, |
| 50 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, | 55 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 Browser* browser = browser::FindTabbedBrowser(profile_, true); | 241 Browser* browser = browser::FindTabbedBrowser(profile_, true); |
| 237 // If the Profile doesn't have a tabbed browser window open, do nothing. | 242 // If the Profile doesn't have a tabbed browser window open, do nothing. |
| 238 if (!browser) | 243 if (!browser) |
| 239 return; | 244 return; |
| 240 | 245 |
| 241 // Check if the Profile's topmost browser window already has a login tab. | 246 // Check if the Profile's topmost browser window already has a login tab. |
| 242 // If so, do nothing. | 247 // If so, do nothing. |
| 243 // TODO(mmenke): Consider focusing that tab, at least if this is the tab | 248 // TODO(mmenke): Consider focusing that tab, at least if this is the tab |
| 244 // helper for the currently active tab for the profile. | 249 // helper for the currently active tab for the profile. |
| 245 for (int i = 0; i < browser->tab_count(); ++i) { | 250 for (int i = 0; i < browser->tab_count(); ++i) { |
| 246 TabContents* tab_contents = chrome::GetTabContentsAt(browser, i); | 251 content::WebContents* web_contents = chrome::GetWebContentsAt(browser, i); |
| 247 if (tab_contents->captive_portal_tab_helper()->IsLoginTab()) | 252 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper = |
| 253 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents); |
| 254 if (captive_portal_tab_helper->IsLoginTab()) |
| 248 return; | 255 return; |
| 249 } | 256 } |
| 250 | 257 |
| 251 // Otherwise, open a login tab. Only end up here when a captive portal result | 258 // Otherwise, open a login tab. Only end up here when a captive portal result |
| 252 // was received, so it's safe to assume |profile_| has a CaptivePortalService. | 259 // was received, so it's safe to assume |profile_| has a CaptivePortalService. |
| 253 TabContents* tab_contents = chrome::AddSelectedTabWithURL( | 260 TabContents* tab_contents = chrome::AddSelectedTabWithURL( |
| 254 browser, | 261 browser, |
| 255 CaptivePortalServiceFactory::GetForProfile(profile_)->test_url(), | 262 CaptivePortalServiceFactory::GetForProfile(profile_)->test_url(), |
| 256 content::PAGE_TRANSITION_TYPED); | 263 content::PAGE_TRANSITION_TYPED); |
| 257 tab_contents->captive_portal_tab_helper()->SetIsLoginTab(); | 264 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper = |
| 265 captive_portal::CaptivePortalTabHelper::FromWebContents( |
| 266 tab_contents->web_contents()); |
| 267 captive_portal_tab_helper->SetIsLoginTab(); |
| 258 } | 268 } |
| 259 | 269 |
| 260 } // namespace captive_portal | 270 } // namespace captive_portal |
| OLD | NEW |