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

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 Android builds Created 5 years, 11 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 24 matching lines...) Expand all
35 content::WebContents* web_contents) 35 content::WebContents* web_contents)
36 : content::WebContentsObserver(web_contents), 36 : content::WebContentsObserver(web_contents),
37 // web_contents is NULL in unit tests. 37 // web_contents is NULL in unit tests.
38 profile_(web_contents ? Profile::FromBrowserContext( 38 profile_(web_contents ? Profile::FromBrowserContext(
39 web_contents->GetBrowserContext()) 39 web_contents->GetBrowserContext())
40 : NULL), 40 : NULL),
41 tab_reloader_( 41 tab_reloader_(
42 new CaptivePortalTabReloader( 42 new CaptivePortalTabReloader(
43 profile_, 43 profile_,
44 web_contents, 44 web_contents,
45 base::Bind(&CaptivePortalTabHelper::OpenLoginTab, 45 base::Bind(&CaptivePortalTabHelper::OpenLoginTabForWebContents,
46 base::Unretained(this)))), 46 web_contents, false))),
47 login_detector_(new CaptivePortalLoginDetector(profile_)), 47 login_detector_(new CaptivePortalLoginDetector(profile_)),
48 web_contents_(web_contents), 48 web_contents_(web_contents),
49 pending_error_code_(net::OK), 49 pending_error_code_(net::OK),
50 provisional_render_view_host_(NULL) { 50 provisional_render_view_host_(NULL) {
51 registrar_.Add(this, 51 registrar_.Add(this,
52 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, 52 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT,
53 content::Source<Profile>(profile_)); 53 content::Source<Profile>(profile_));
54 registrar_.Add(this, 54 registrar_.Add(this,
55 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, 55 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
56 content::Source<content::WebContents>(web_contents)); 56 content::Source<content::WebContents>(web_contents));
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 186 }
187 187
188 void CaptivePortalTabHelper::OnSSLCertError(const net::SSLInfo& ssl_info) { 188 void CaptivePortalTabHelper::OnSSLCertError(const net::SSLInfo& ssl_info) {
189 tab_reloader_->OnSSLCertError(ssl_info); 189 tab_reloader_->OnSSLCertError(ssl_info);
190 } 190 }
191 191
192 bool CaptivePortalTabHelper::IsLoginTab() const { 192 bool CaptivePortalTabHelper::IsLoginTab() const {
193 return login_detector_->is_login_tab(); 193 return login_detector_->is_login_tab();
194 } 194 }
195 195
196 // static
197 void CaptivePortalTabHelper::OpenLoginTabForWebContents(
198 content::WebContents* web_contents,
199 bool focus) {
200 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
201
202 // If the Profile doesn't have a tabbed browser window open, do nothing.
203 if (!browser)
204 return;
205
206 // Check if the Profile's topmost browser window already has a login tab.
207 // If so, do nothing.
208 // TODO(mmenke): Consider focusing that tab, at least if this is the tab
209 // helper for the currently active tab for the profile.
210 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
211 content::WebContents* contents =
212 browser->tab_strip_model()->GetWebContentsAt(i);
213 CaptivePortalTabHelper* captive_portal_tab_helper =
214 CaptivePortalTabHelper::FromWebContents(contents);
215 if (captive_portal_tab_helper->IsLoginTab()) {
216 if (focus)
217 browser->tab_strip_model()->ActivateTabAt(i, false);
218 return;
219 }
220 }
221
222 // Otherwise, open a login tab. Only end up here when a captive portal result
223 // was received, so it's safe to assume profile has a CaptivePortalService.
224 content::WebContents* new_contents = chrome::AddSelectedTabWithURL(
225 browser,
226 CaptivePortalServiceFactory::GetForProfile(
227 browser->profile())->test_url(),
228 ui::PAGE_TRANSITION_TYPED);
229 CaptivePortalTabHelper* captive_portal_tab_helper =
230 CaptivePortalTabHelper::FromWebContents(new_contents);
231 captive_portal_tab_helper->SetIsLoginTab();
232 }
233
196 void CaptivePortalTabHelper::OnRedirect(int child_id, 234 void CaptivePortalTabHelper::OnRedirect(int child_id,
197 ResourceType resource_type, 235 ResourceType resource_type,
198 const GURL& new_url) { 236 const GURL& new_url) {
199 // Only main frame redirects for the provisional RenderViewHost matter. 237 // Only main frame redirects for the provisional RenderViewHost matter.
200 if (resource_type != content::RESOURCE_TYPE_MAIN_FRAME || 238 if (resource_type != content::RESOURCE_TYPE_MAIN_FRAME ||
201 !provisional_render_view_host_ || 239 !provisional_render_view_host_ ||
202 provisional_render_view_host_->GetProcess()->GetID() != child_id) { 240 provisional_render_view_host_->GetProcess()->GetID() != child_id) {
203 return; 241 return;
204 } 242 }
205 243
(...skipping 21 matching lines...) Expand all
227 } 265 }
228 266
229 void CaptivePortalTabHelper::SetTabReloaderForTest( 267 void CaptivePortalTabHelper::SetTabReloaderForTest(
230 CaptivePortalTabReloader* tab_reloader) { 268 CaptivePortalTabReloader* tab_reloader) {
231 tab_reloader_.reset(tab_reloader); 269 tab_reloader_.reset(tab_reloader);
232 } 270 }
233 271
234 CaptivePortalTabReloader* CaptivePortalTabHelper::GetTabReloaderForTest() { 272 CaptivePortalTabReloader* CaptivePortalTabHelper::GetTabReloaderForTest() {
235 return tab_reloader_.get(); 273 return tab_reloader_.get();
236 } 274 }
237
238 void CaptivePortalTabHelper::OpenLoginTab() {
239 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
240
241 // If the Profile doesn't have a tabbed browser window open, do nothing.
242 if (!browser)
243 return;
244
245 // Check if the Profile's topmost browser window already has a login tab.
246 // If so, do nothing.
247 // TODO(mmenke): Consider focusing that tab, at least if this is the tab
248 // helper for the currently active tab for the profile.
249 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
250 content::WebContents* web_contents =
251 browser->tab_strip_model()->GetWebContentsAt(i);
252 CaptivePortalTabHelper* captive_portal_tab_helper =
253 CaptivePortalTabHelper::FromWebContents(web_contents);
254 if (captive_portal_tab_helper->IsLoginTab())
255 return;
256 }
257
258 // 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.
260 content::WebContents* web_contents = chrome::AddSelectedTabWithURL(
261 browser,
262 CaptivePortalServiceFactory::GetForProfile(profile_)->test_url(),
263 ui::PAGE_TRANSITION_TYPED);
264 CaptivePortalTabHelper* captive_portal_tab_helper =
265 CaptivePortalTabHelper::FromWebContents(web_contents);
266 captive_portal_tab_helper->SetIsLoginTab();
267 }
OLDNEW
« no previous file with comments | « chrome/browser/captive_portal/captive_portal_tab_helper.h ('k') | chrome/browser/chrome_content_browser_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698