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

Side by Side Diff: chrome/browser/captive_portal/captive_portal_tab_helper.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: Add file to fix component build Created 8 years, 7 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_HELPER_H_
6 #define CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_
7 #pragma once
8
9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/non_thread_safe.h"
13 #include "base/time.h"
14 #include "base/timer.h"
15 #include "chrome/browser/captive_portal/captive_portal_tab_observer.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
18 #include "content/public/browser/web_contents_observer.h"
19
20 class Profile;
21 class TabContentsWrapper;
22
23 namespace captive_portal {
24
25 // Keeps track of whether a tab is a login page or has encountered a navigation
26 // error caused by a captive portal. It triggers captive portal checks and
27 // opens tabs at the portal's login page as necessary. All methods may only be
28 // called on the UI thread.
29 //
30 // Only supports SSL main frames which time out in response to captive portals,
31 // since these make for a particularly bad user experience. Non-SSL requests
32 // are intercepted by captive portals, which take users to the login page. SSL
33 // requests, however, are generally silently blackholed. They then take two
34 // minutes to timeout, and will timeout again when refreshed.
35 //
36 // For the design doc, see:
37 // https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlUdlUdoW9WRaEm fM/edit
38 class CaptivePortalTabHelper : public content::NotificationObserver,
cbentzel 2012/05/22 17:54:27 Would it make sense to have different TabHelper's
mmenke 2012/05/22 18:22:36 I've gone back and forth on this more than once.
cbentzel 2012/05/24 12:41:37 I would not have two classes which are directly re
mmenke 2012/05/24 14:19:04 SGTM, will do.
39 public base::NonThreadSafe {
40 public:
41 enum State {
42 STATE_NONE,
43 // The slow load timer is running. Only started on SSL provisional loads.
44 // If the timer triggers before the page has been committed, a captive
45 // portal test will be requested.
46 STATE_TIMER_RUNNING,
47 // The tab may have been broken by a captive portal. A tab switches to
48 // this state either on an ERR_CONNECTION_TIMEOUT of an SSL page or when
49 // an SSL request takes too long to commit. The tab will remain in this
50 // state until the current load succeeds, a new provisional load starts,
51 // or it gets a captive portal result.
52 STATE_MAYBE_BROKEN_BY_PORTAL,
53 // The TabHelper switches to this state from STATE_MAYBE_BROKEN_BY_PORTAL in
54 // response to a RESULT_BEHIND_CAPTIVE_PORTAL. The tab will remain in this
55 // state until a new provisional load starts, the original load successfully
56 // commits, the current load is aborted, or the tab reloads the page in
57 // response to receiving a captive portal result other than
58 // RESULT_BEHIND_CAPTIVE_PORTAL.
59 STATE_BROKEN_BY_PORTAL,
60 // The page may need to be reloaded. The tab will be reloaded if the page
61 // fails the next load with a timeout, or immediately upon switching to this
62 // state, if the page already timed out. If anything else happens
63 // when in this state (Another error, successful navigation, or the original
64 // navigation was aborted), the TabHelper transitions to STATE_NONE without
65 // reloading.
66 STATE_NEEDS_RELOAD,
67 // This tab is, or was, at the captive portal login page. This state is
68 // only cleared once the CaptivePortalService returns something other than
69 // RESULT_BEHIND_CAPTIVE_PORTAL.
70 STATE_CAPTIVE_PORTAL_LOGIN_PAGE,
71 };
72
73 // |profile| and |web_contents| will only be dereferenced in ReloadTab,
74 // MaybeOpenCaptivePortalLoginTab, and CheckForCaptivePortal, so they can
75 // both be NULL in the unit tests, though |profile| will still be used as a
76 // notification source.
77 CaptivePortalTabHelper(Profile* profile, content::WebContents* web_contents);
78
79 virtual ~CaptivePortalTabHelper();
80
81 protected:
82 // The following 4 functions are all invoked by |observer_|.
83
84 // Called when a non-error main frame load starts. Resets current state,
85 // unless this is a login tab. Each load will eventually result in a call to
86 // OnLoadCommitted or OnAbort. The former will be called both on successful
87 // loads and for error pages.
88 virtual void OnLoadStart(bool is_ssl);
89
90 // Called when a page is committed. |net_error| will be net::OK in the case
91 // of a successful load. For an errror page, the entire 3-step process of
92 // getting the error, starting a new provisional load for the error page, and
93 // committing the error page is treated as a single commit.
94 //
95 // The Link Doctor page will typically be one OnLoadCommitted with an error
96 // code, followed by another OnLoadCommitted with net::OK for the Link Doctor
97 // page.
98 virtual void OnLoadCommitted(int net_error);
cbentzel 2012/05/22 17:54:27 Could this use net::Error instead of int?
mmenke 2012/05/22 18:22:36 The WebContentsObserver only declares it as an int
99
100 // This is called when the current provisional load is canceled.
101 // Sets state to STATE_NONE, unless this is a login tab.
102 virtual void OnAbort();
103
104 // Called when the WebContents stops loading. Starts a captive portal check
105 // if this is the login tab.
106 virtual void OnStopLoading();
107
108 // Sets |state_| and takes any action associated with the new state.
109 void SetState(State new_state);
110
111 State state() const { return state_; }
112
113 // Used by unit tests.
114 void set_slow_ssl_load_time(base::TimeDelta slow_ssl_load_time) {
115 slow_ssl_load_time_ = slow_ssl_load_time;
116 }
117
118 // Started whenever an SSL tab starts loading, when the state is switched to
119 // STATE_TIMER_RUNNING. Stopped on any state change, including when a page
120 // commits or there's an error. If the timer triggers, the state switches to
121 // STATE_MAYBE_BROKEN_BY_PORTAL and |this| kicks off a captive portal check.
122 // TODO(mmenke): On redirects, update this timer.
123 base::OneShotTimer<CaptivePortalTabHelper> slow_ssl_load_timer_;
124
125 // Handles messages from the WebContents. Separate class to simplify logic
126 // and testing.
127 CaptivePortalTabObserver observer_;
128
129 private:
130 friend class CaptivePortalBrowserTest;
131 // friend class CaptivePortalTabHelperTest;
132 friend class CaptivePortalTabObserver;
133
134 // content::NotificationObserver:
135 virtual void Observe(
136 int type,
137 const content::NotificationSource& source,
138 const content::NotificationDetails& details) OVERRIDE;
139
140 // Called by a timer when an SSL main frame provisional load is taking a
141 // while to commit.
142 void OnSlowSSLConnect();
143
144 // Reloads the tab if there's no provisional load going on and the current
145 // state is STATE_NEEDS_RELOAD. Not safe to call synchronously when called
146 // by |observer_|, since the WebContents is already taking some action.
147 void ReloadTabIfNeeded();
148
149 // Reloads the tab.
150 virtual void ReloadTab();
151
152 // Opens a login tab in the topmost browser window for the |profile_|, if the
153 // profile has a tabbed browser window and the window doesn't already have a
154 // login tab. Otherwise, does nothing.
155 virtual void MaybeOpenCaptivePortalLoginTab();
156
157 // Tries to get |profile_|'s CaptivePortalService and have it start a captive
158 // portal check.
159 virtual void CheckForCaptivePortal();
160
161 Profile* profile_;
162
163 State state_;
164
165 // Tracks if there's a load going on that can't safely be interrupted. This
166 // is true between the time when a provisional load fails and when an error
167 // page's provisional load starts, so does not perfectly align with the
168 // notion of a provisional load used by the WebContents.
169 bool provisional_main_frame_load_;
170
171 // Time to wait after a provisional HTTPS load before triggering a captive
172 // portal check.
173 base::TimeDelta slow_ssl_load_time_;
174
175 base::WeakPtrFactory<CaptivePortalTabHelper> weak_factory_;
176
177 content::NotificationRegistrar registrar_;
178
179 DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabHelper);
180 };
181
182 } // namespace captive_portal
183
184 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_
OLDNEW
« no previous file with comments | « chrome/browser/captive_portal/captive_portal_service.h ('k') | chrome/browser/captive_portal/captive_portal_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698