Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / captive_portal / captive_portal_tab_helper.h
blob815ccb43319bb7c7a30462d8b45fb17794603c81
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.
5 #ifndef CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_
6 #define CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/non_thread_safe.h"
12 #include "chrome/browser/captive_portal/captive_portal_service.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/browser/web_contents_user_data.h"
17 #include "content/public/common/resource_type.h"
19 class GURL;
20 class Profile;
22 namespace content {
23 class WebContents;
26 namespace net {
27 class SSLInfo;
30 class CaptivePortalLoginDetector;
31 class CaptivePortalTabReloader;
33 // Along with the classes it owns, responsible for detecting page loads broken
34 // by a captive portal, triggering captive portal checks on navigation events
35 // that may indicate a captive portal is present, or has been removed / logged
36 // in to, and taking any correcting actions.
38 // It acts as a WebContentsObserver for its CaptivePortalLoginDetector and
39 // CaptivePortalTabReloader. It filters out non-main-frame resource loads, and
40 // treats the commit of an error page as a single event, rather than as 3
41 // (ProvisionalLoadFail, DidStartProvisionalLoad, DidCommit), which simplifies
42 // the CaptivePortalTabReloader. It is also needed by CaptivePortalTabReloaders
43 // to inform the tab's CaptivePortalLoginDetector when the tab is at a captive
44 // portal's login page.
46 // The TabHelper assumes that a WebContents can only have one RenderViewHost
47 // with a provisional load at a time, and tracks only that navigation. This
48 // assumption can be violated in rare cases, for example, a same-site
49 // navigation interrupted by a cross-process navigation started from the
50 // omnibox, may commit before it can be cancelled. In these cases, this class
51 // may pass incorrect messages to the TabReloader, which will, at worst, result
52 // in not opening up a login tab until a second load fails or not automatically
53 // reloading a tab after logging in.
55 // For the design doc, see:
56 // https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlUdlUdoW9WRaEmfM/edit
57 class CaptivePortalTabHelper
58 : public content::WebContentsObserver,
59 public content::NotificationObserver,
60 public base::NonThreadSafe,
61 public content::WebContentsUserData<CaptivePortalTabHelper> {
62 public:
63 ~CaptivePortalTabHelper() override;
65 // content::WebContentsObserver:
66 void RenderViewDeleted(content::RenderViewHost* render_view_host) override;
68 void DidStartProvisionalLoadForFrame(
69 content::RenderFrameHost* render_frame_host,
70 const GURL& validated_url,
71 bool is_error_page,
72 bool is_iframe_srcdoc) override;
74 void DidCommitProvisionalLoadForFrame(
75 content::RenderFrameHost* render_frame_host,
76 const GURL& url,
77 ui::PageTransition transition_type) override;
79 void DidFailProvisionalLoad(content::RenderFrameHost* render_frame_host,
80 const GURL& validated_url,
81 int error_code,
82 const base::string16& error_description) override;
84 void DidStopLoading() override;
86 // content::NotificationObserver:
87 void Observe(int type,
88 const content::NotificationSource& source,
89 const content::NotificationDetails& details) override;
91 // Called when a certificate interstitial error page is about to be shown.
92 void OnSSLCertError(const net::SSLInfo& ssl_info);
94 // A "Login Tab" is a tab that was originally at a captive portal login
95 // page. This is set to false when a captive portal is no longer detected.
96 bool IsLoginTab() const;
98 // Opens a login tab if the profile's active window doesn't have one already.
99 static void OpenLoginTabForWebContents(content::WebContents* web_contents,
100 bool focus);
102 private:
103 friend class CaptivePortalBrowserTest;
104 friend class CaptivePortalTabHelperTest;
106 friend class content::WebContentsUserData<CaptivePortalTabHelper>;
107 explicit CaptivePortalTabHelper(content::WebContents* web_contents);
109 // Called by Observe in response to the corresponding event.
110 void OnRedirect(int child_id,
111 content::ResourceType resource_type,
112 const GURL& new_url);
114 // Called by Observe in response to the corresponding event.
115 void OnCaptivePortalResults(
116 captive_portal::CaptivePortalResult previous_result,
117 captive_portal::CaptivePortalResult result);
119 void OnLoadAborted();
121 // Called to indicate a tab is at, or is navigating to, the captive portal
122 // login page.
123 void SetIsLoginTab();
125 // |this| takes ownership of |tab_reloader|.
126 void SetTabReloaderForTest(CaptivePortalTabReloader* tab_reloader);
128 const content::RenderViewHost* provisional_render_view_host() const {
129 return provisional_render_view_host_;
132 CaptivePortalTabReloader* GetTabReloaderForTest();
134 Profile* profile_;
136 // Neither of these will ever be NULL.
137 scoped_ptr<CaptivePortalTabReloader> tab_reloader_;
138 scoped_ptr<CaptivePortalLoginDetector> login_detector_;
140 content::WebContents* web_contents_;
142 // If a provisional load has failed, and the tab is loading an error page, the
143 // error code associated with the error page we're loading.
144 // net::OK, otherwise.
145 int pending_error_code_;
147 // The RenderViewHost with a provisional load, if any. Can either be
148 // the currently displayed RenderViewHost or a pending RenderViewHost for
149 // cross-process navitations. NULL when there's currently no provisional
150 // load.
151 content::RenderViewHost* provisional_render_view_host_;
153 content::NotificationRegistrar registrar_;
155 DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabHelper);
158 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_