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 22 matching lines...) Expand all Loading... | |
33 content::WebContents* web_contents) | 33 content::WebContents* web_contents) |
34 : content::WebContentsObserver(web_contents), | 34 : content::WebContentsObserver(web_contents), |
35 // web_contents is NULL in unit tests. | 35 // web_contents is NULL in unit tests. |
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::OpenLoginTabForWebContents, |
44 base::Unretained(this)))), | 44 web_contents, false))), |
45 login_detector_(new CaptivePortalLoginDetector(profile_)), | 45 login_detector_(new CaptivePortalLoginDetector(profile_)), |
46 web_contents_(web_contents), | 46 web_contents_(web_contents), |
47 pending_error_code_(net::OK), | 47 pending_error_code_(net::OK), |
48 provisional_render_view_host_(NULL) { | 48 provisional_render_view_host_(NULL) { |
49 registrar_.Add(this, | 49 registrar_.Add(this, |
50 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | 50 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, |
51 content::Source<Profile>(profile_)); | 51 content::Source<Profile>(profile_)); |
52 registrar_.Add(this, | 52 registrar_.Add(this, |
53 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 53 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
54 content::Source<content::WebContents>(web_contents)); | 54 content::Source<content::WebContents>(web_contents)); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 | 232 |
233 void CaptivePortalTabHelper::SetTabReloaderForTest( | 233 void CaptivePortalTabHelper::SetTabReloaderForTest( |
234 CaptivePortalTabReloader* tab_reloader) { | 234 CaptivePortalTabReloader* tab_reloader) { |
235 tab_reloader_.reset(tab_reloader); | 235 tab_reloader_.reset(tab_reloader); |
236 } | 236 } |
237 | 237 |
238 CaptivePortalTabReloader* CaptivePortalTabHelper::GetTabReloaderForTest() { | 238 CaptivePortalTabReloader* CaptivePortalTabHelper::GetTabReloaderForTest() { |
239 return tab_reloader_.get(); | 239 return tab_reloader_.get(); |
240 } | 240 } |
241 | 241 |
242 void CaptivePortalTabHelper::OpenLoginTab() { | 242 // static |
243 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 243 void CaptivePortalTabHelper::OpenLoginTabForWebContents( |
244 content::WebContents* web_contents, | |
245 bool focus) { | |
246 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | |
244 | 247 |
245 // If the Profile doesn't have a tabbed browser window open, do nothing. | 248 // If the Profile doesn't have a tabbed browser window open, do nothing. |
246 if (!browser) | 249 if (!browser) |
247 return; | 250 return; |
248 | 251 |
249 // Check if the Profile's topmost browser window already has a login tab. | 252 // Check if the Profile's topmost browser window already has a login tab. |
250 // If so, do nothing. | 253 // If so, do nothing. |
251 // TODO(mmenke): Consider focusing that tab, at least if this is the tab | 254 // TODO(mmenke): Consider focusing that tab, at least if this is the tab |
252 // helper for the currently active tab for the profile. | 255 // helper for the currently active tab for the profile. |
253 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { | 256 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { |
254 content::WebContents* web_contents = | 257 content::WebContents* contents = |
255 browser->tab_strip_model()->GetWebContentsAt(i); | 258 browser->tab_strip_model()->GetWebContentsAt(i); |
256 CaptivePortalTabHelper* captive_portal_tab_helper = | 259 CaptivePortalTabHelper* captive_portal_tab_helper = |
257 CaptivePortalTabHelper::FromWebContents(web_contents); | 260 CaptivePortalTabHelper::FromWebContents(contents); |
258 if (captive_portal_tab_helper->IsLoginTab()) | 261 if (captive_portal_tab_helper->IsLoginTab()) { |
262 if (focus) | |
263 browser->tab_strip_model()->ActivateTabAt(i, false); | |
259 return; | 264 return; |
265 } | |
260 } | 266 } |
261 | 267 |
262 // Otherwise, open a login tab. Only end up here when a captive portal result | 268 // Otherwise, open a login tab. Only end up here when a captive portal result |
263 // was received, so it's safe to assume |profile_| has a CaptivePortalService. | 269 // was received, so it's safe to assume profile has a CaptivePortalService. |
264 content::WebContents* web_contents = chrome::AddSelectedTabWithURL( | 270 content::WebContents* contents = chrome::AddSelectedTabWithURL( |
mmenke
2014/06/24 18:09:26
nit: new_contents or login_web_contents or login_
meacer
2014/10/22 23:04:28
Done.
| |
265 browser, | 271 browser, |
266 CaptivePortalServiceFactory::GetForProfile(profile_)->test_url(), | 272 CaptivePortalServiceFactory::GetForProfile( |
267 content::PAGE_TRANSITION_TYPED); | 273 browser->profile())->test_url(), |
274 content::PAGE_TRANSITION_TYPED); | |
268 CaptivePortalTabHelper* captive_portal_tab_helper = | 275 CaptivePortalTabHelper* captive_portal_tab_helper = |
269 CaptivePortalTabHelper::FromWebContents(web_contents); | 276 CaptivePortalTabHelper::FromWebContents(contents); |
270 captive_portal_tab_helper->SetIsLoginTab(); | 277 captive_portal_tab_helper->SetIsLoginTab(); |
271 } | 278 } |
OLD | NEW |