Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(895)

Side by Side Diff: chrome/browser/captive_portal/captive_portal_tab_helper.cc

Issue 318213002: Add custom interstitial for captive portals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix build Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 23 matching lines...) Expand all
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::OpenLoginTab,
44 base::Unretained(this)))), 44 base::Unretained(this), 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
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 void CaptivePortalTabHelper::OpenLoginTab(bool focus) {
243 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); 243 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
244 244
245 // If the Profile doesn't have a tabbed browser window open, do nothing. 245 // If the Profile doesn't have a tabbed browser window open, do nothing.
246 if (!browser) 246 if (!browser)
247 return; 247 return;
248 248
249 // Check if the Profile's topmost browser window already has a login tab. 249 // Check if the Profile's topmost browser window already has a login tab.
250 // If so, do nothing. 250 // If so, do nothing.
251 // TODO(mmenke): Consider focusing that tab, at least if this is the tab 251 // TODO(mmenke): Consider focusing that tab, at least if this is the tab
252 // helper for the currently active tab for the profile. 252 // helper for the currently active tab for the profile.
253 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { 253 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
254 content::WebContents* web_contents = 254 content::WebContents* web_contents =
255 browser->tab_strip_model()->GetWebContentsAt(i); 255 browser->tab_strip_model()->GetWebContentsAt(i);
256 CaptivePortalTabHelper* captive_portal_tab_helper = 256 CaptivePortalTabHelper* captive_portal_tab_helper =
257 CaptivePortalTabHelper::FromWebContents(web_contents); 257 CaptivePortalTabHelper::FromWebContents(web_contents);
258 if (captive_portal_tab_helper->IsLoginTab()) 258 if (captive_portal_tab_helper->IsLoginTab()) {
259 if (focus)
260 browser->tab_strip_model()->ActivateTabAt(i, false);
259 return; 261 return;
262 }
260 } 263 }
261 264
262 // Otherwise, open a login tab. Only end up here when a captive portal result 265 // 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. 266 // was received, so it's safe to assume |profile_| has a CaptivePortalService.
264 content::WebContents* web_contents = chrome::AddSelectedTabWithURL( 267 content::WebContents* web_contents = chrome::AddSelectedTabWithURL(
265 browser, 268 browser,
266 CaptivePortalServiceFactory::GetForProfile(profile_)->test_url(), 269 CaptivePortalServiceFactory::GetForProfile(profile_)->test_url(),
267 content::PAGE_TRANSITION_TYPED); 270 content::PAGE_TRANSITION_TYPED);
268 CaptivePortalTabHelper* captive_portal_tab_helper = 271 CaptivePortalTabHelper* captive_portal_tab_helper =
269 CaptivePortalTabHelper::FromWebContents(web_contents); 272 CaptivePortalTabHelper::FromWebContents(web_contents);
270 captive_portal_tab_helper->SetIsLoginTab(); 273 captive_portal_tab_helper->SetIsLoginTab();
274 if (focus) {
275 int index = browser->tab_strip_model()->GetIndexOfWebContents(web_contents);
276 browser->tab_strip_model()->ActivateTabAt(index, false);
277 }
mmenke 2014/06/17 19:17:03 I don't believe this is needed - "AddSelectedTabWi
meacer 2014/06/18 21:23:08 Correct.
271 } 278 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698