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" |
11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
15 #include "chrome/browser/ui/browser_tabstrip.h" | 15 #include "chrome/browser/ui/browser_tabstrip.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
20 #include "content/public/browser/notification_types.h" | 20 #include "content/public/browser/notification_types.h" |
21 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
22 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
23 #include "content/public/browser/resource_request_details.h" | 23 #include "content/public/browser/resource_request_details.h" |
24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
25 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
26 #include "net/ssl/ssl_info.h" | 26 #include "net/ssl/ssl_info.h" |
27 | 27 |
28 DEFINE_WEB_CONTENTS_USER_DATA_KEY(captive_portal::CaptivePortalTabHelper); | 28 using captive_portal::CaptivePortalResult; |
29 | 29 |
30 namespace captive_portal { | 30 DEFINE_WEB_CONTENTS_USER_DATA_KEY(CaptivePortalTabHelper); |
31 | 31 |
32 CaptivePortalTabHelper::CaptivePortalTabHelper( | 32 CaptivePortalTabHelper::CaptivePortalTabHelper( |
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( |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 // Only main frame redirects for the provisional RenderViewHost matter. | 203 // Only main frame redirects for the provisional RenderViewHost matter. |
204 if (resource_type != ResourceType::MAIN_FRAME || | 204 if (resource_type != ResourceType::MAIN_FRAME || |
205 !provisional_render_view_host_ || | 205 !provisional_render_view_host_ || |
206 provisional_render_view_host_->GetProcess()->GetID() != child_id) { | 206 provisional_render_view_host_->GetProcess()->GetID() != child_id) { |
207 return; | 207 return; |
208 } | 208 } |
209 | 209 |
210 tab_reloader_->OnRedirect(new_url.SchemeIsSecure()); | 210 tab_reloader_->OnRedirect(new_url.SchemeIsSecure()); |
211 } | 211 } |
212 | 212 |
213 void CaptivePortalTabHelper::OnCaptivePortalResults(Result previous_result, | 213 void CaptivePortalTabHelper::OnCaptivePortalResults( |
214 Result result) { | 214 CaptivePortalResult previous_result, |
| 215 CaptivePortalResult result) { |
215 tab_reloader_->OnCaptivePortalResults(previous_result, result); | 216 tab_reloader_->OnCaptivePortalResults(previous_result, result); |
216 login_detector_->OnCaptivePortalResults(previous_result, result); | 217 login_detector_->OnCaptivePortalResults(previous_result, result); |
217 } | 218 } |
218 | 219 |
219 void CaptivePortalTabHelper::OnLoadAborted() { | 220 void CaptivePortalTabHelper::OnLoadAborted() { |
220 // No further messages for the cancelled navigation will occur. | 221 // No further messages for the cancelled navigation will occur. |
221 provisional_render_view_host_ = NULL; | 222 provisional_render_view_host_ = NULL; |
222 // May have been aborting the load of an error page. | 223 // May have been aborting the load of an error page. |
223 pending_error_code_ = net::OK; | 224 pending_error_code_ = net::OK; |
224 | 225 |
(...skipping 20 matching lines...) Expand all Loading... |
245 if (!browser) | 246 if (!browser) |
246 return; | 247 return; |
247 | 248 |
248 // 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. |
249 // If so, do nothing. | 250 // If so, do nothing. |
250 // 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 |
251 // helper for the currently active tab for the profile. | 252 // helper for the currently active tab for the profile. |
252 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { | 253 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { |
253 content::WebContents* web_contents = | 254 content::WebContents* web_contents = |
254 browser->tab_strip_model()->GetWebContentsAt(i); | 255 browser->tab_strip_model()->GetWebContentsAt(i); |
255 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper = | 256 CaptivePortalTabHelper* captive_portal_tab_helper = |
256 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents); | 257 CaptivePortalTabHelper::FromWebContents(web_contents); |
257 if (captive_portal_tab_helper->IsLoginTab()) | 258 if (captive_portal_tab_helper->IsLoginTab()) |
258 return; | 259 return; |
259 } | 260 } |
260 | 261 |
261 // Otherwise, open a login tab. Only end up here when a captive portal result | 262 // Otherwise, open a login tab. Only end up here when a captive portal result |
262 // was received, so it's safe to assume |profile_| has a CaptivePortalService. | 263 // was received, so it's safe to assume |profile_| has a CaptivePortalService. |
263 content::WebContents* web_contents = chrome::AddSelectedTabWithURL( | 264 content::WebContents* web_contents = chrome::AddSelectedTabWithURL( |
264 browser, | 265 browser, |
265 CaptivePortalServiceFactory::GetForProfile(profile_)->test_url(), | 266 CaptivePortalServiceFactory::GetForProfile(profile_)->test_url(), |
266 content::PAGE_TRANSITION_TYPED); | 267 content::PAGE_TRANSITION_TYPED); |
267 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper = | 268 CaptivePortalTabHelper* captive_portal_tab_helper = |
268 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents); | 269 CaptivePortalTabHelper::FromWebContents(web_contents); |
269 captive_portal_tab_helper->SetIsLoginTab(); | 270 captive_portal_tab_helper->SetIsLoginTab(); |
270 } | 271 } |
271 | |
272 } // namespace captive_portal | |
OLD | NEW |