Index: chrome/browser/captive_portal/captive_portal_tab_observer.h |
=================================================================== |
--- chrome/browser/captive_portal/captive_portal_tab_observer.h (revision 0) |
+++ chrome/browser/captive_portal/captive_portal_tab_observer.h (revision 0) |
@@ -0,0 +1,72 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_OBSERVER_H_ |
+#define CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_OBSERVER_H_ |
+#pragma once |
+ |
+#include "base/basictypes.h" |
+#include "base/compiler_specific.h" |
+#include "content/public/browser/web_contents_observer.h" |
+ |
+namespace captive_portal { |
+ |
+class CaptivePortalTabHelper; |
+ |
+// A WebContentsObserver that simplifies the messages a CaptivePortalTabHelper |
+// receives. It filters non-main-frame resource loads, and treats the commit |
+// of an error page as a single event, rather than as 3 (ProvisionalLoadFail, |
+// DidStartProvisionalLoad, DidCommit). |
+// |
+// TODO(mmenke): Support redirects. Probably won't cause us to succussfully |
+// detect captive portals we wouldn't have handled anyways, but |
+// may reduce the number of unnecessary captive portal checks we |
+// run. |
+class CaptivePortalTabObserver : public content::WebContentsObserver { |
+ public: |
+ CaptivePortalTabObserver(CaptivePortalTabHelper* tab_helper, |
+ content::WebContents* web_contents); |
+ virtual ~CaptivePortalTabObserver(); |
+ |
+ // content::WebContentsObserver: |
+ virtual void DidStartProvisionalLoadForFrame( |
+ int64 frame_id, |
+ bool is_main_frame, |
+ const GURL& validated_url, |
+ bool is_error_page, |
+ content::RenderViewHost* render_view_host) OVERRIDE; |
+ |
+ virtual void DidCommitProvisionalLoadForFrame( |
+ int64 frame_id, |
+ bool is_main_frame, |
+ const GURL& url, |
+ content::PageTransition transition_type) OVERRIDE; |
+ |
+ virtual void DidFailProvisionalLoad( |
+ int64 frame_id, |
+ bool is_main_frame, |
+ const GURL& validated_url, |
+ int error_code, |
+ const string16& error_description) OVERRIDE; |
+ |
+ virtual void DidStopLoading() OVERRIDE; |
+ |
+ content::WebContents* web_contents() const { |
+ return content::WebContentsObserver::web_contents(); |
+ } |
+ |
+ private: |
+ // Our owner. |
+ CaptivePortalTabHelper* tab_helper_; |
+ |
+ // If a load has failed, and we're loading an error page, the error code |
+ // associated with the error page we're loading. net::OK, otherwise. |
+ int pending_error_code_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabObserver); |
+}; |
+ |
+} // namespace captive_portal |
+ |
+#endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_OBSERVER_H_ |