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_OBSERVER_H_ |
| 6 #define CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_OBSERVER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" |
| 11 #include "content/public/browser/web_contents_observer.h" |
| 12 |
| 13 namespace captive_portal { |
| 14 |
| 15 class CaptivePortalTabHelper; |
| 16 |
| 17 // A WebContentsObserver that simplifies the messages a CaptivePortalTabHelper |
| 18 // receives. It filters non-main-frame resource loads, and treats the commit |
| 19 // of an error page as a single event, rather than as 3 (ProvisionalLoadFail, |
| 20 // DidStartProvisionalLoad, DidCommit). |
| 21 // |
| 22 // TODO(mmenke): Support redirects. Needed for HSTS, which simulates redirects |
| 23 // at the network layer. Also may reduce the number of |
| 24 // unnecessary captive portal checks on high latency connections. |
| 25 class CaptivePortalTabObserver : public content::WebContentsObserver { |
| 26 public: |
| 27 CaptivePortalTabObserver(CaptivePortalTabHelper* tab_helper, |
| 28 content::WebContents* web_contents); |
| 29 virtual ~CaptivePortalTabObserver(); |
| 30 |
| 31 // content::WebContentsObserver: |
| 32 virtual void DidStartProvisionalLoadForFrame( |
| 33 int64 frame_id, |
| 34 bool is_main_frame, |
| 35 const GURL& validated_url, |
| 36 bool is_error_page, |
| 37 content::RenderViewHost* render_view_host) OVERRIDE; |
| 38 |
| 39 virtual void DidCommitProvisionalLoadForFrame( |
| 40 int64 frame_id, |
| 41 bool is_main_frame, |
| 42 const GURL& url, |
| 43 content::PageTransition transition_type, |
| 44 content::RenderViewHost* render_view_host) OVERRIDE; |
| 45 |
| 46 virtual void DidFailProvisionalLoad( |
| 47 int64 frame_id, |
| 48 bool is_main_frame, |
| 49 const GURL& validated_url, |
| 50 int error_code, |
| 51 const string16& error_description, |
| 52 content::RenderViewHost* render_view_host) OVERRIDE; |
| 53 |
| 54 virtual void DidStopLoading() OVERRIDE; |
| 55 |
| 56 content::WebContents* web_contents() const { |
| 57 return content::WebContentsObserver::web_contents(); |
| 58 } |
| 59 |
| 60 private: |
| 61 // The TabHelper messages are passed to. |
| 62 CaptivePortalTabHelper* tab_helper_; |
| 63 |
| 64 // If a provisional load has failed, and the tab is loading an error page, the |
| 65 // error code associated with the error page we're loading. |
| 66 // net::OK, otherwise. |
| 67 int pending_error_code_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabObserver); |
| 70 }; |
| 71 |
| 72 } // namespace captive_portal |
| 73 |
| 74 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_OBSERVER_H_ |
OLD | NEW |