OLD | NEW |
(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/scoped_ptr.h" |
| 12 #include "base/threading/non_thread_safe.h" |
| 13 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" |
| 14 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" |
| 16 #include "content/public/browser/web_contents_observer.h" |
| 17 |
| 18 class Profile; |
| 19 class TabContentsWrapper; |
| 20 |
| 21 namespace captive_portal { |
| 22 |
| 23 class CaptivePortalLoginDetector; |
| 24 |
| 25 // 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 // that may indicate a captive portal is present, or has been removed / logged |
| 28 // in to, and taking any correcting actions. |
| 29 // |
| 30 // It acts as a WebContentsObserver for its CaptivePortalTabReloader and |
| 31 // 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 // (ProvisionalLoadFail, DidStartProvisionalLoad, DidCommit), which simplifies |
| 34 // the CaptivePortalTabReloader. It is also needed by CaptivePortalTabReloaders |
| 35 // to inform the tab's CaptivePortalLoginDetector when the tab is at a captive |
| 36 // portal's login page. |
| 37 // |
| 38 // TODO(mmenke): Support redirects. Needed for HSTS, which simulates redirects |
| 39 // at the network layer. Also may reduce the number of |
| 40 // unnecessary captive portal checks on high latency connections. |
| 41 // |
| 42 // For the design doc, see: |
| 43 // https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlUdlUdoW9WRaEm
fM/edit |
| 44 class CaptivePortalTabHelper : public content::WebContentsObserver, |
| 45 public content::NotificationObserver, |
| 46 public base::NonThreadSafe { |
| 47 public: |
| 48 CaptivePortalTabHelper(Profile* profile, |
| 49 content::WebContents* web_contents); |
| 50 virtual ~CaptivePortalTabHelper(); |
| 51 |
| 52 // content::WebContentsObserver: |
| 53 virtual void DidStartProvisionalLoadForFrame( |
| 54 int64 frame_id, |
| 55 bool is_main_frame, |
| 56 const GURL& validated_url, |
| 57 bool is_error_page, |
| 58 content::RenderViewHost* render_view_host) OVERRIDE; |
| 59 |
| 60 virtual void DidCommitProvisionalLoadForFrame( |
| 61 int64 frame_id, |
| 62 bool is_main_frame, |
| 63 const GURL& url, |
| 64 content::PageTransition transition_type, |
| 65 content::RenderViewHost* render_view_host) OVERRIDE; |
| 66 |
| 67 virtual void DidFailProvisionalLoad( |
| 68 int64 frame_id, |
| 69 bool is_main_frame, |
| 70 const GURL& validated_url, |
| 71 int error_code, |
| 72 const string16& error_description, |
| 73 content::RenderViewHost* render_view_host) OVERRIDE; |
| 74 |
| 75 virtual void DidStopLoading() OVERRIDE; |
| 76 |
| 77 // content::NotificationObserver: |
| 78 virtual void Observe( |
| 79 int type, |
| 80 const content::NotificationSource& source, |
| 81 const content::NotificationDetails& details) OVERRIDE; |
| 82 |
| 83 // A "Login Tab" is a tab that was originally at a captive portal login |
| 84 // page. This is set to false when a captive portal is no longer detected. |
| 85 bool IsLoginTab() const; |
| 86 |
| 87 // Called to indicate a tab is at, or is navigating to, the captive portal |
| 88 // login page. |
| 89 void SetIsLoginTab(); |
| 90 |
| 91 private: |
| 92 friend class CaptivePortalTabHelperTest; |
| 93 friend class CaptivePortalBrowserTest; |
| 94 |
| 95 // |this| takes ownership of |tab_reloader|. |
| 96 void SetTabReloaderForTest(CaptivePortalTabReloader* tab_reloader); |
| 97 |
| 98 CaptivePortalTabReloader* GetTabReloaderForTest(); |
| 99 |
| 100 // Neither of these will ever be NULL. |
| 101 scoped_ptr<CaptivePortalTabReloader> tab_reloader_; |
| 102 scoped_ptr<CaptivePortalLoginDetector> login_detector_; |
| 103 |
| 104 Profile* profile_; |
| 105 |
| 106 // If a provisional load has failed, and the tab is loading an error page, the |
| 107 // error code associated with the error page we're loading. |
| 108 // net::OK, otherwise. |
| 109 int pending_error_code_; |
| 110 |
| 111 content::NotificationRegistrar registrar_; |
| 112 |
| 113 DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabHelper); |
| 114 }; |
| 115 |
| 116 } // namespace captive_portal |
| 117 |
| 118 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_ |
OLD | NEW |