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_reloader.h" | 5 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "chrome/browser/captive_portal/captive_portal_service.h" | 10 #include "chrome/browser/captive_portal/captive_portal_service.h" |
11 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | 11 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
12 #include "content/public/browser/interstitial_page.h" | 12 #include "content/public/browser/interstitial_page.h" |
13 #include "content/public/browser/navigation_controller.h" | 13 #include "content/public/browser/navigation_controller.h" |
14 #include "content/public/browser/navigation_entry.h" | 14 #include "content/public/browser/navigation_entry.h" |
15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
17 | 17 |
18 namespace captive_portal { | 18 using captive_portal::CaptivePortalResult; |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // The time to wait for a slow loading SSL page before triggering a captive | 22 // The time to wait for a slow loading SSL page before triggering a captive |
23 // portal check. | 23 // portal check. |
24 const int kDefaultSlowSSLTimeSeconds = 30; | 24 const int kDefaultSlowSSLTimeSeconds = 30; |
25 | 25 |
26 // Returns true if an SSL request resulting in |error| may indicate a captive | 26 // Returns true if an SSL request resulting in |error| may indicate a captive |
27 // portal. | 27 // portal. |
28 bool SslNetErrorMayImplyCaptivePortal(int error) { | 28 bool SslNetErrorMayImplyCaptivePortal(int error) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 return; | 120 return; |
121 // Only start the SSL timer running if no SSL URL has been seen in the current | 121 // Only start the SSL timer running if no SSL URL has been seen in the current |
122 // redirect chain. If we've already successfully downloaded one SSL URL, | 122 // redirect chain. If we've already successfully downloaded one SSL URL, |
123 // assume we're not behind a captive portal. | 123 // assume we're not behind a captive portal. |
124 if (!ssl_url_in_redirect_chain_) | 124 if (!ssl_url_in_redirect_chain_) |
125 SetState(STATE_TIMER_RUNNING); | 125 SetState(STATE_TIMER_RUNNING); |
126 ssl_url_in_redirect_chain_ = true; | 126 ssl_url_in_redirect_chain_ = true; |
127 } | 127 } |
128 | 128 |
129 void CaptivePortalTabReloader::OnCaptivePortalResults( | 129 void CaptivePortalTabReloader::OnCaptivePortalResults( |
130 Result previous_result, | 130 CaptivePortalResult previous_result, |
131 Result result) { | 131 CaptivePortalResult result) { |
132 if (result == RESULT_BEHIND_CAPTIVE_PORTAL) { | 132 if (result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL) { |
133 if (state_ == STATE_MAYBE_BROKEN_BY_PORTAL) { | 133 if (state_ == STATE_MAYBE_BROKEN_BY_PORTAL) { |
134 SetState(STATE_BROKEN_BY_PORTAL); | 134 SetState(STATE_BROKEN_BY_PORTAL); |
135 MaybeOpenCaptivePortalLoginTab(); | 135 MaybeOpenCaptivePortalLoginTab(); |
136 } | 136 } |
137 return; | 137 return; |
138 } | 138 } |
139 | 139 |
140 switch (state_) { | 140 switch (state_) { |
141 case STATE_MAYBE_BROKEN_BY_PORTAL: | 141 case STATE_MAYBE_BROKEN_BY_PORTAL: |
142 case STATE_TIMER_RUNNING: | 142 case STATE_TIMER_RUNNING: |
143 // If the previous result was BEHIND_CAPTIVE_PORTAL, and the state is | 143 // If the previous result was BEHIND_CAPTIVE_PORTAL, and the state is |
144 // either STATE_MAYBE_BROKEN_BY_PORTAL or STATE_TIMER_RUNNING, reload the | 144 // either STATE_MAYBE_BROKEN_BY_PORTAL or STATE_TIMER_RUNNING, reload the |
145 // tab. In the latter case, the tab has yet to commit, but is an SSL | 145 // tab. In the latter case, the tab has yet to commit, but is an SSL |
146 // page, so if the page ends up at an error caused by a captive portal, it | 146 // page, so if the page ends up at an error caused by a captive portal, it |
147 // will be reloaded. If not, the state will just be reset. The helps in | 147 // will be reloaded. If not, the state will just be reset. The helps in |
148 // the case that a user tries to reload a tab, and then quickly logs in. | 148 // the case that a user tries to reload a tab, and then quickly logs in. |
149 if (previous_result == RESULT_BEHIND_CAPTIVE_PORTAL) { | 149 if (previous_result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL) { |
150 SetState(STATE_NEEDS_RELOAD); | 150 SetState(STATE_NEEDS_RELOAD); |
151 return; | 151 return; |
152 } | 152 } |
153 SetState(STATE_NONE); | 153 SetState(STATE_NONE); |
154 return; | 154 return; |
155 | 155 |
156 case STATE_BROKEN_BY_PORTAL: | 156 case STATE_BROKEN_BY_PORTAL: |
157 // Either reload the tab now, if an error page has already been committed | 157 // Either reload the tab now, if an error page has already been committed |
158 // or an interstitial is being displayed, or reload it if and when a | 158 // or an interstitial is being displayed, or reload it if and when a |
159 // timeout commits. | 159 // timeout commits. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 void CaptivePortalTabReloader::MaybeOpenCaptivePortalLoginTab() { | 272 void CaptivePortalTabReloader::MaybeOpenCaptivePortalLoginTab() { |
273 open_login_tab_callback_.Run(); | 273 open_login_tab_callback_.Run(); |
274 } | 274 } |
275 | 275 |
276 void CaptivePortalTabReloader::CheckForCaptivePortal() { | 276 void CaptivePortalTabReloader::CheckForCaptivePortal() { |
277 CaptivePortalService* service = | 277 CaptivePortalService* service = |
278 CaptivePortalServiceFactory::GetForProfile(profile_); | 278 CaptivePortalServiceFactory::GetForProfile(profile_); |
279 if (service) | 279 if (service) |
280 service->DetectCaptivePortal(); | 280 service->DetectCaptivePortal(); |
281 } | 281 } |
282 | |
283 } // namespace captive_portal | |
OLD | NEW |