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

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

Issue 10837146: Fix how captive portals track which page is loading. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 8 years, 4 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
OLDNEW
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. While
40 // unnecessary captive portal checks on high latency connections. 41 // this may not be perfectly accurate in all cases, it should be good enough.
cbentzel 2012/08/15 17:00:38 Can you be clearer in this comment about a case wh
mmenke 2012/08/16 14:30:03 Done.
41 // 42 //
42 // For the design doc, see: 43 // For the design doc, see:
43 // https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlUdlUdoW9WRaEm fM/edit 44 // https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlUdlUdoW9WRaEm fM/edit
44 class CaptivePortalTabHelper : public content::WebContentsObserver, 45 class CaptivePortalTabHelper : public content::WebContentsObserver,
45 public content::NotificationObserver, 46 public content::NotificationObserver,
46 public base::NonThreadSafe { 47 public base::NonThreadSafe {
47 public: 48 public:
48 CaptivePortalTabHelper(Profile* profile, 49 CaptivePortalTabHelper(Profile* profile,
49 content::WebContents* web_contents); 50 content::WebContents* web_contents);
50 virtual ~CaptivePortalTabHelper(); 51 virtual ~CaptivePortalTabHelper();
(...skipping 27 matching lines...) Expand all
78 // content::NotificationObserver: 79 // content::NotificationObserver:
79 virtual void Observe( 80 virtual void Observe(
80 int type, 81 int type,
81 const content::NotificationSource& source, 82 const content::NotificationSource& source,
82 const content::NotificationDetails& details) OVERRIDE; 83 const content::NotificationDetails& details) OVERRIDE;
83 84
84 // A "Login Tab" is a tab that was originally at a captive portal login 85 // 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. 86 // page. This is set to false when a captive portal is no longer detected.
86 bool IsLoginTab() const; 87 bool IsLoginTab() const;
87 88
88 private: 89 protected:
cbentzel 2012/08/15 17:00:38 Why are these protected instead of private?
mmenke 2012/08/16 14:30:03 Since I had to override GetProvisionalChildID for
89 friend class CaptivePortalBrowserTest;
90 friend class CaptivePortalTabHelperTest;
91
92 // Called by Observe in response to the corresponding event. 90 // Called by Observe in response to the corresponding event.
93 void OnRedirect(int64 frame_id, const GURL& new_url); 91 void OnRedirect(int child_id,
94 92 ResourceType::Type resource_type,
95 // Called by Observe in response to the corresponding event. 93 const GURL& new_url);
96 void OnCaptivePortalResults(Result previous_result, Result result);
97 94
98 // Called to indicate a tab is at, or is navigating to, the captive portal 95 // Called to indicate a tab is at, or is navigating to, the captive portal
99 // login page. 96 // login page.
100 void SetIsLoginTab(); 97 void SetIsLoginTab();
101 98
102 // |this| takes ownership of |tab_reloader|. 99 // |this| takes ownership of |tab_reloader|.
103 void SetTabReloaderForTest(CaptivePortalTabReloader* tab_reloader); 100 void SetTabReloaderForTest(CaptivePortalTabReloader* tab_reloader);
104 101
102 const content::RenderViewHost* provisional_render_view_host() const {
103 return provisional_render_view_host_;
104 }
105
106 private:
107 friend class CaptivePortalBrowserTest;
108
109 // Called by Observe in response to the corresponding event.
110 void OnCaptivePortalResults(Result previous_result, Result result);
111
105 CaptivePortalTabReloader* GetTabReloaderForTest(); 112 CaptivePortalTabReloader* GetTabReloaderForTest();
106 113
107 // Opens a login tab if the profile's active window doesn't have one already. 114 // Opens a login tab if the profile's active window doesn't have one already.
108 void OpenLoginTab(); 115 void OpenLoginTab();
109 116
117 // Returns the child ID of the provisional RenderViewHost's Renderer process.
118 // Returns -1 if there's no such RenderViewHost.
119 virtual int GetProvisionalChildID() const;
120
110 // Neither of these will ever be NULL. 121 // Neither of these will ever be NULL.
111 scoped_ptr<CaptivePortalTabReloader> tab_reloader_; 122 scoped_ptr<CaptivePortalTabReloader> tab_reloader_;
112 scoped_ptr<CaptivePortalLoginDetector> login_detector_; 123 scoped_ptr<CaptivePortalLoginDetector> login_detector_;
113 124
114 Profile* profile_; 125 Profile* profile_;
115 126
116 // If a provisional load has failed, and the tab is loading an error page, the 127 // 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. 128 // error code associated with the error page we're loading.
118 // net::OK, otherwise. 129 // net::OK, otherwise.
119 int pending_error_code_; 130 int pending_error_code_;
120 131
121 // The ID of the main frame that's currently provisionally loaded, if there is 132 // 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 133 // the currently displayed RenderViewHost or a pending RenderViewHost for
123 // -1 is passed to DidStartProvisionalLoadForFrame. 134 // cross-process navitations. NULL when there's currently no provisional
124 int64 provisional_main_frame_id_; 135 // load.
136 content::RenderViewHost* provisional_render_view_host_;
125 137
126 content::NotificationRegistrar registrar_; 138 content::NotificationRegistrar registrar_;
127 139
128 DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabHelper); 140 DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabHelper);
129 }; 141 };
130 142
131 } // namespace captive_portal 143 } // namespace captive_portal
132 144
133 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_ 145 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698