Chromium Code Reviews| 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 "chrome/browser/tab_contents/web_contents_user_data.h" | |
| 13 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
| 14 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 15 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
| 16 #include "webkit/glue/resource_type.h" | 17 #include "webkit/glue/resource_type.h" |
| 17 | 18 |
| 18 class GURL; | 19 class GURL; |
| 19 class Profile; | 20 class Profile; |
| 20 | 21 |
| 21 namespace net { | 22 namespace net { |
| 22 class SSLInfo; | 23 class SSLInfo; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 44 // with a provisional load at a time, and tracks only that navigation. This | 45 // with a provisional load at a time, and tracks only that navigation. This |
| 45 // assumption can be violated in rare cases, for example, a same-site | 46 // assumption can be violated in rare cases, for example, a same-site |
| 46 // navigation interrupted by a cross-process navigation started from the | 47 // navigation interrupted by a cross-process navigation started from the |
| 47 // omnibox, may commit before it can be cancelled. In these cases, this class | 48 // omnibox, may commit before it can be cancelled. In these cases, this class |
| 48 // may pass incorrect messages to the TabReloader, which will, at worst, result | 49 // may pass incorrect messages to the TabReloader, which will, at worst, result |
| 49 // in not opening up a login tab until a second load fails or not automatically | 50 // in not opening up a login tab until a second load fails or not automatically |
| 50 // reloading a tab after logging in. | 51 // reloading a tab after logging in. |
| 51 // | 52 // |
| 52 // For the design doc, see: | 53 // For the design doc, see: |
| 53 // https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlUdlUdoW9WRaEm fM/edit | 54 // https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlUdlUdoW9WRaEm fM/edit |
| 54 class CaptivePortalTabHelper : public content::WebContentsObserver, | 55 class CaptivePortalTabHelper |
| 55 public content::NotificationObserver, | 56 : public content::WebContentsObserver, |
| 56 public base::NonThreadSafe { | 57 public content::NotificationObserver, |
| 58 public base::NonThreadSafe, | |
| 59 public WebContentsUserData<CaptivePortalTabHelper> { | |
| 57 public: | 60 public: |
| 58 CaptivePortalTabHelper(Profile* profile, | |
| 59 content::WebContents* web_contents); | |
| 60 virtual ~CaptivePortalTabHelper(); | 61 virtual ~CaptivePortalTabHelper(); |
| 61 | 62 |
| 62 // content::WebContentsObserver: | 63 // content::WebContentsObserver: |
| 63 virtual void DidStartProvisionalLoadForFrame( | 64 virtual void DidStartProvisionalLoadForFrame( |
| 64 int64 frame_id, | 65 int64 frame_id, |
| 65 bool is_main_frame, | 66 bool is_main_frame, |
| 66 const GURL& validated_url, | 67 const GURL& validated_url, |
| 67 bool is_error_page, | 68 bool is_error_page, |
| 68 content::RenderViewHost* render_view_host) OVERRIDE; | 69 content::RenderViewHost* render_view_host) OVERRIDE; |
| 69 | 70 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 92 const content::NotificationDetails& details) OVERRIDE; | 93 const content::NotificationDetails& details) OVERRIDE; |
| 93 | 94 |
| 94 // Called when a certificate interstitial error page is about to be shown. | 95 // Called when a certificate interstitial error page is about to be shown. |
| 95 void OnSSLCertError(const net::SSLInfo& ssl_info); | 96 void OnSSLCertError(const net::SSLInfo& ssl_info); |
| 96 | 97 |
| 97 // A "Login Tab" is a tab that was originally at a captive portal login | 98 // A "Login Tab" is a tab that was originally at a captive portal login |
| 98 // page. This is set to false when a captive portal is no longer detected. | 99 // page. This is set to false when a captive portal is no longer detected. |
| 99 bool IsLoginTab() const; | 100 bool IsLoginTab() const; |
| 100 | 101 |
| 101 private: | 102 private: |
| 103 explicit CaptivePortalTabHelper(content::WebContents* web_contents); | |
|
mmenke
2012/09/19 16:52:21
This should go after the static int, per Google st
| |
| 104 static int kUserDataKey; | |
|
mmenke
2012/09/19 16:52:21
I believe this should go below the friend declarat
| |
| 105 friend class WebContentsUserData<CaptivePortalTabHelper>; | |
| 106 | |
| 102 friend class CaptivePortalBrowserTest; | 107 friend class CaptivePortalBrowserTest; |
| 103 friend class CaptivePortalTabHelperTest; | 108 friend class CaptivePortalTabHelperTest; |
| 104 | 109 |
| 105 // Called by Observe in response to the corresponding event. | 110 // Called by Observe in response to the corresponding event. |
| 106 void OnRedirect(int child_id, | 111 void OnRedirect(int child_id, |
| 107 ResourceType::Type resource_type, | 112 ResourceType::Type resource_type, |
| 108 const GURL& new_url); | 113 const GURL& new_url); |
| 109 | 114 |
| 110 // Called by Observe in response to the corresponding event. | 115 // Called by Observe in response to the corresponding event. |
| 111 void OnCaptivePortalResults(Result previous_result, Result result); | 116 void OnCaptivePortalResults(Result previous_result, Result result); |
| 112 | 117 |
| 113 void OnLoadAborted(); | 118 void OnLoadAborted(); |
| 114 | 119 |
| 115 // Called to indicate a tab is at, or is navigating to, the captive portal | 120 // Called to indicate a tab is at, or is navigating to, the captive portal |
| 116 // login page. | 121 // login page. |
| 117 void SetIsLoginTab(); | 122 void SetIsLoginTab(); |
| 118 | 123 |
| 119 // |this| takes ownership of |tab_reloader|. | 124 // |this| takes ownership of |tab_reloader|. |
| 120 void SetTabReloaderForTest(CaptivePortalTabReloader* tab_reloader); | 125 void SetTabReloaderForTest(CaptivePortalTabReloader* tab_reloader); |
| 121 | 126 |
| 122 const content::RenderViewHost* provisional_render_view_host() const { | 127 const content::RenderViewHost* provisional_render_view_host() const { |
| 123 return provisional_render_view_host_; | 128 return provisional_render_view_host_; |
| 124 } | 129 } |
| 125 | 130 |
| 126 CaptivePortalTabReloader* GetTabReloaderForTest(); | 131 CaptivePortalTabReloader* GetTabReloaderForTest(); |
| 127 | 132 |
| 128 // Opens a login tab if the profile's active window doesn't have one already. | 133 // Opens a login tab if the profile's active window doesn't have one already. |
| 129 void OpenLoginTab(); | 134 void OpenLoginTab(); |
| 130 | 135 |
| 136 Profile* profile_; | |
| 137 | |
| 131 // Neither of these will ever be NULL. | 138 // Neither of these will ever be NULL. |
| 132 scoped_ptr<CaptivePortalTabReloader> tab_reloader_; | 139 scoped_ptr<CaptivePortalTabReloader> tab_reloader_; |
| 133 scoped_ptr<CaptivePortalLoginDetector> login_detector_; | 140 scoped_ptr<CaptivePortalLoginDetector> login_detector_; |
| 134 | 141 |
| 135 Profile* profile_; | |
| 136 | |
| 137 // If a provisional load has failed, and the tab is loading an error page, the | 142 // If a provisional load has failed, and the tab is loading an error page, the |
| 138 // error code associated with the error page we're loading. | 143 // error code associated with the error page we're loading. |
| 139 // net::OK, otherwise. | 144 // net::OK, otherwise. |
| 140 int pending_error_code_; | 145 int pending_error_code_; |
| 141 | 146 |
| 142 // The RenderViewHost with a provisional load, if any. Can either be | 147 // The RenderViewHost with a provisional load, if any. Can either be |
| 143 // the currently displayed RenderViewHost or a pending RenderViewHost for | 148 // the currently displayed RenderViewHost or a pending RenderViewHost for |
| 144 // cross-process navitations. NULL when there's currently no provisional | 149 // cross-process navitations. NULL when there's currently no provisional |
| 145 // load. | 150 // load. |
| 146 content::RenderViewHost* provisional_render_view_host_; | 151 content::RenderViewHost* provisional_render_view_host_; |
| 147 | 152 |
| 148 content::NotificationRegistrar registrar_; | 153 content::NotificationRegistrar registrar_; |
| 149 | 154 |
| 150 DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabHelper); | 155 DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabHelper); |
| 151 }; | 156 }; |
| 152 | 157 |
| 153 } // namespace captive_portal | 158 } // namespace captive_portal |
| 154 | 159 |
| 155 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_ | 160 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_ |
| OLD | NEW |