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

Side by Side Diff: chrome/browser/captive_portal/captive_portal_tab_reloader.h

Issue 10020051: Open a login tab on captive portal detection on SSL loads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Response to comments Created 8 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_RELOADER_H_
6 #define CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_RELOADER_H_
7 #pragma once
8
9 #include "base/basictypes.h"
10 #include "base/callback_forward.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time.h"
14 #include "base/timer.h"
15 #include "chrome/browser/captive_portal/captive_portal_service.h"
16
17 class Profile;
18 class TabContentsWrapper;
19
20 namespace content {
21 class WebContents;
22 }
23
24 namespace captive_portal {
25
26 // Keeps track of whether a tab has encountered a navigation error caused by a
27 // captive portal. Also triggers captive portal checks when a page load may
28 // have been broken or be taking longer due to a captive portal. All methods
29 // may only be called on the UI thread.
30 //
31 // Only supports SSL main frames which time out in response to captive portals,
32 // since these make for a particularly bad user experience. Non-SSL requests
33 // are intercepted by captive portals, which take users to the login page. SSL
34 // requests, however, are generally silently blackholed. They then take a
35 // while to timeout, and will timeout again when refreshed.
36 class CaptivePortalTabReloader {
37 public:
38 enum State {
39 STATE_NONE,
40 // The slow load timer is running. Only started on SSL provisional loads.
41 // If the timer triggers before the page has been committed, a captive
42 // portal test will be requested.
43 STATE_TIMER_RUNNING,
44 // The tab may have been broken by a captive portal. A tab switches to
45 // this state either on an ERR_CONNECTION_TIMEOUT of an SSL page or when
46 // an SSL request takes too long to commit. The tab will remain in this
47 // state until the current load succeeds, a new provisional load starts,
48 // or it gets a captive portal result.
49 STATE_MAYBE_BROKEN_BY_PORTAL,
50 // The TabHelper switches to this state from STATE_MAYBE_BROKEN_BY_PORTAL in
51 // response to a RESULT_BEHIND_CAPTIVE_PORTAL. The tab will remain in this
52 // state until a new provisional load starts, the original load successfully
53 // commits, the current load is aborted, or the tab reloads the page in
54 // response to receiving a captive portal result other than
55 // RESULT_BEHIND_CAPTIVE_PORTAL.
56 STATE_BROKEN_BY_PORTAL,
57 // The page may need to be reloaded. The tab will be reloaded if the page
58 // fails the next load with a timeout, or immediately upon switching to this
59 // state, if the page already timed out. If anything else happens
60 // when in this state (Another error, successful navigation, or the original
61 // navigation was aborted), the TabHelper transitions to STATE_NONE without
62 // reloading.
63 STATE_NEEDS_RELOAD,
64 };
65
66 // Function to open a login tab, if there isn't one already.
67 typedef base::Callback<void()> OpenLoginTabCallback;
68
69 // |profile| and |web_contents| will only be dereferenced in ReloadTab,
70 // MaybeOpenCaptivePortalLoginTab, and CheckForCaptivePortal, so they can
71 // both be NULL in the unit tests as long as those functions are not called.
72 CaptivePortalTabReloader(Profile* profile,
73 content::WebContents* web_contents,
74 const OpenLoginTabCallback& open_login_tab_callback);
75
76 virtual ~CaptivePortalTabReloader();
77
78 // The following 4 functions are all invoked by the CaptivePortalTabHelper:
79
80 // Called when a non-error main frame load starts. Resets current state,
81 // unless this is a login tab. Each load will eventually result in a call to
82 // OnLoadCommitted or OnAbort. The former will be called both on successful
83 // loads and for error pages.
84 virtual void OnLoadStart(bool is_ssl);
85
86 // Called when a page is committed. |net_error| will be net::OK in the case
87 // of a successful load. For an errror page, the entire 3-step process of
88 // getting the error, starting a new provisional load for the error page, and
89 // committing the error page is treated as a single commit.
90 //
91 // The Link Doctor page will typically be one OnLoadCommitted with an error
92 // code, followed by another OnLoadCommitted with net::OK for the Link Doctor
93 // page.
94 virtual void OnLoadCommitted(int net_error);
95
96 // This is called when the current provisional load is canceled.
97 // Sets state to STATE_NONE, unless this is a login tab.
98 virtual void OnAbort();
99
100 // Called by CaptivePortalTabHelper whenever a captive portal test completes.
101 virtual void OnCaptivePortalResults(Result previous_result, Result result);
102
103 protected:
104 // The following functions are used only when testing:
105
106 State state() const { return state_; }
107
108 void set_slow_ssl_load_time(base::TimeDelta slow_ssl_load_time) {
109 slow_ssl_load_time_ = slow_ssl_load_time;
110 }
111
112 // Started whenever an SSL tab starts loading, when the state is switched to
113 // STATE_TIMER_RUNNING. Stopped on any state change, including when a page
114 // commits or there's an error. If the timer triggers, the state switches to
115 // STATE_MAYBE_BROKEN_BY_PORTAL and |this| kicks off a captive portal check.
116 // TODO(mmenke): On redirects, update this timer.
117 base::OneShotTimer<CaptivePortalTabReloader> slow_ssl_load_timer_;
118
119 private:
120 friend class CaptivePortalBrowserTest;
121
122 // Sets |state_| and takes any action associated with the new state. Also
123 // stops the timer, if needed.
124 void SetState(State new_state);
125
126 // Called by a timer when an SSL main frame provisional load is taking a
127 // while to commit.
128 void OnSlowSSLConnect();
129
130 // Reloads the tab if there's no provisional load going on and the current
131 // state is STATE_NEEDS_RELOAD. Not safe to call synchronously when called
132 // by from a WebContentsObserver function, since the WebContents is currently
133 // performing some action.
134 void ReloadTabIfNeeded();
135
136 // Reloads the tab.
137 virtual void ReloadTab();
138
139 // Opens a login tab in the topmost browser window for the |profile_|, if the
140 // profile has a tabbed browser window and the window doesn't already have a
141 // login tab. Otherwise, does nothing.
142 virtual void MaybeOpenCaptivePortalLoginTab();
143
144 // Tries to get |profile_|'s CaptivePortalService and have it start a captive
145 // portal check.
146 virtual void CheckForCaptivePortal();
147
148 Profile* profile_;
149 content::WebContents* web_contents_;
150
151 State state_;
152
153 // Tracks if there's a load going on that can't safely be interrupted. This
154 // is true between the time when a provisional load fails and when an error
155 // page's provisional load starts, so does not perfectly align with the
156 // notion of a provisional load used by the WebContents.
157 bool provisional_main_frame_load_;
158
159 // Time to wait after a provisional HTTPS load before triggering a captive
160 // portal check.
161 base::TimeDelta slow_ssl_load_time_;
162
163 const OpenLoginTabCallback open_login_tab_callback_;
164
165 base::WeakPtrFactory<CaptivePortalTabReloader> weak_factory_;
166
167 DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabReloader);
168 };
169
170 } // namespace captive_portal
171
172 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_RELOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698