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 #ifndef CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_ |
6 #define CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/threading/non_thread_safe.h" | 11 #include "base/threading/non_thread_safe.h" |
12 #include "chrome/browser/captive_portal/captive_portal_service.h" | 12 #include "chrome/browser/captive_portal/captive_portal_service.h" |
13 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
14 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
15 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 16 #include "webkit/glue/resource_type.h" |
16 | 17 |
17 class GURL; | 18 class GURL; |
18 class Profile; | 19 class Profile; |
19 | 20 |
20 namespace captive_portal { | 21 namespace captive_portal { |
21 | 22 |
22 class CaptivePortalLoginDetector; | 23 class CaptivePortalLoginDetector; |
23 class CaptivePortalTabReloader; | 24 class CaptivePortalTabReloader; |
24 | 25 |
25 // Along with the classes it owns, responsible for detecting page loads broken | 26 // Along with the classes it owns, responsible for detecting page loads broken |
26 // by a captive portal, triggering captive portal checks on navigation events | 27 // by a captive portal, triggering captive portal checks on navigation events |
27 // that may indicate a captive portal is present, or has been removed / logged | 28 // that may indicate a captive portal is present, or has been removed / logged |
28 // in to, and taking any correcting actions. | 29 // in to, and taking any correcting actions. |
29 // | 30 // |
30 // It acts as a WebContentsObserver for its CaptivePortalLoginDetector and | 31 // It acts as a WebContentsObserver for its CaptivePortalLoginDetector and |
31 // CaptivePortalTabReloader. It filters out non-main-frame resource loads, and | 32 // CaptivePortalTabReloader. It filters out non-main-frame resource loads, and |
32 // treats the commit of an error page as a single event, rather than as 3 | 33 // treats the commit of an error page as a single event, rather than as 3 |
33 // (ProvisionalLoadFail, DidStartProvisionalLoad, DidCommit), which simplifies | 34 // (ProvisionalLoadFail, DidStartProvisionalLoad, DidCommit), which simplifies |
34 // the CaptivePortalTabReloader. It is also needed by CaptivePortalTabReloaders | 35 // the CaptivePortalTabReloader. It is also needed by CaptivePortalTabReloaders |
35 // to inform the tab's CaptivePortalLoginDetector when the tab is at a captive | 36 // to inform the tab's CaptivePortalLoginDetector when the tab is at a captive |
36 // portal's login page. | 37 // portal's login page. |
37 // | 38 // |
38 // TODO(mmenke): Support redirects. Needed for HSTS, which simulates redirects | 39 // The TabHelper assumes that a WebContents can only have one RenderViewHost |
39 // at the network layer. Also may reduce the number of | 40 // with a provisional load at a time, and tracks only that navigation. This |
40 // unnecessary captive portal checks on high latency connections. | 41 // assumption can be violated in rare cases, for example, a same-site |
| 42 // navigation interrupted by a cross-process navigation started from the |
| 43 // omnibox, may commit before it can be cancelled. In these cases, this class |
| 44 // may pass incorrect messages to the TabReloader, which will, at worst, result |
| 45 // in not opening up a login tab until a second load fails or not automatically |
| 46 // reloading a tab after logging in. |
41 // | 47 // |
42 // For the design doc, see: | 48 // For the design doc, see: |
43 // https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlUdlUdoW9WRaEm
fM/edit | 49 // https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlUdlUdoW9WRaEm
fM/edit |
44 class CaptivePortalTabHelper : public content::WebContentsObserver, | 50 class CaptivePortalTabHelper : public content::WebContentsObserver, |
45 public content::NotificationObserver, | 51 public content::NotificationObserver, |
46 public base::NonThreadSafe { | 52 public base::NonThreadSafe { |
47 public: | 53 public: |
48 CaptivePortalTabHelper(Profile* profile, | 54 CaptivePortalTabHelper(Profile* profile, |
49 content::WebContents* web_contents); | 55 content::WebContents* web_contents); |
50 virtual ~CaptivePortalTabHelper(); | 56 virtual ~CaptivePortalTabHelper(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 89 |
84 // A "Login Tab" is a tab that was originally at a captive portal login | 90 // A "Login Tab" is a tab that was originally at a captive portal login |
85 // page. This is set to false when a captive portal is no longer detected. | 91 // page. This is set to false when a captive portal is no longer detected. |
86 bool IsLoginTab() const; | 92 bool IsLoginTab() const; |
87 | 93 |
88 private: | 94 private: |
89 friend class CaptivePortalBrowserTest; | 95 friend class CaptivePortalBrowserTest; |
90 friend class CaptivePortalTabHelperTest; | 96 friend class CaptivePortalTabHelperTest; |
91 | 97 |
92 // Called by Observe in response to the corresponding event. | 98 // Called by Observe in response to the corresponding event. |
93 void OnRedirect(int64 frame_id, const GURL& new_url); | 99 void OnRedirect(int child_id, |
| 100 ResourceType::Type resource_type, |
| 101 const GURL& new_url); |
94 | 102 |
95 // Called by Observe in response to the corresponding event. | 103 // Called by Observe in response to the corresponding event. |
96 void OnCaptivePortalResults(Result previous_result, Result result); | 104 void OnCaptivePortalResults(Result previous_result, Result result); |
97 | 105 |
| 106 void OnLoadAborted(); |
| 107 |
98 // Called to indicate a tab is at, or is navigating to, the captive portal | 108 // Called to indicate a tab is at, or is navigating to, the captive portal |
99 // login page. | 109 // login page. |
100 void SetIsLoginTab(); | 110 void SetIsLoginTab(); |
101 | 111 |
102 // |this| takes ownership of |tab_reloader|. | 112 // |this| takes ownership of |tab_reloader|. |
103 void SetTabReloaderForTest(CaptivePortalTabReloader* tab_reloader); | 113 void SetTabReloaderForTest(CaptivePortalTabReloader* tab_reloader); |
104 | 114 |
| 115 const content::RenderViewHost* provisional_render_view_host() const { |
| 116 return provisional_render_view_host_; |
| 117 } |
| 118 |
105 CaptivePortalTabReloader* GetTabReloaderForTest(); | 119 CaptivePortalTabReloader* GetTabReloaderForTest(); |
106 | 120 |
107 // Opens a login tab if the profile's active window doesn't have one already. | 121 // Opens a login tab if the profile's active window doesn't have one already. |
108 void OpenLoginTab(); | 122 void OpenLoginTab(); |
109 | 123 |
110 // Neither of these will ever be NULL. | 124 // Neither of these will ever be NULL. |
111 scoped_ptr<CaptivePortalTabReloader> tab_reloader_; | 125 scoped_ptr<CaptivePortalTabReloader> tab_reloader_; |
112 scoped_ptr<CaptivePortalLoginDetector> login_detector_; | 126 scoped_ptr<CaptivePortalLoginDetector> login_detector_; |
113 | 127 |
114 Profile* profile_; | 128 Profile* profile_; |
115 | 129 |
116 // If a provisional load has failed, and the tab is loading an error page, the | 130 // If a provisional load has failed, and the tab is loading an error page, the |
117 // error code associated with the error page we're loading. | 131 // error code associated with the error page we're loading. |
118 // net::OK, otherwise. | 132 // net::OK, otherwise. |
119 int pending_error_code_; | 133 int pending_error_code_; |
120 | 134 |
121 // The ID of the main frame that's currently provisionally loaded, if there is | 135 // The RenderViewHost with a provisional load, if any. Can either be |
122 // one. -1 (unknown/invalid) when there is no such frame, or when an id of | 136 // the currently displayed RenderViewHost or a pending RenderViewHost for |
123 // -1 is passed to DidStartProvisionalLoadForFrame. | 137 // cross-process navitations. NULL when there's currently no provisional |
124 int64 provisional_main_frame_id_; | 138 // load. |
| 139 content::RenderViewHost* provisional_render_view_host_; |
125 | 140 |
126 content::NotificationRegistrar registrar_; | 141 content::NotificationRegistrar registrar_; |
127 | 142 |
128 DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabHelper); | 143 DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabHelper); |
129 }; | 144 }; |
130 | 145 |
131 } // namespace captive_portal | 146 } // namespace captive_portal |
132 | 147 |
133 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_ | 148 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_ |
OLD | NEW |