Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / captive_portal / captive_portal_tab_helper.h
blob965c994a98a11b3db89379099dca6dbea4f8f7de
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 NavigationHandle;
24 class WebContents;
27 namespace net {
28 class SSLInfo;
31 class CaptivePortalLoginDetector;
32 class CaptivePortalTabReloader;
34 // Along with the classes it owns, responsible for detecting page loads broken
35 // by a captive portal, triggering captive portal checks on navigation events
36 // that may indicate a captive portal is present, or has been removed / logged
37 // in to, and taking any correcting actions.
39 // It acts as a WebContentsObserver for its CaptivePortalLoginDetector and
40 // CaptivePortalTabReloader. It filters out non-main-frame navigations. It is
41 // also needed by CaptivePortalTabReloaders to inform the tab's
42 // CaptivePortalLoginDetector when the tab is at a captive portal's login page.
44 // The TabHelper assumes that a WebContents can only have one main frame
45 // navigation at a time. This assumption can be violated in rare cases, for
46 // example, a same-site navigation interrupted by a cross-process navigation
47 // started from the omnibox, may commit before it can be cancelled. In these
48 // cases, this class may pass incorrect messages to the TabReloader, which
49 // will, at worst, result in not opening up a login tab until a second load
50 // fails or not automatically reloading a tab after logging in.
51 // TODO(clamy): See if this class can be made to handle these edge-cases
52 // following the refactor of navigation signaling to WebContentsObservers.
54 // For the design doc, see:
55 // https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlUdlUdoW9WRaEmfM/edit
56 class CaptivePortalTabHelper
57 : public content::WebContentsObserver,
58 public content::NotificationObserver,
59 public base::NonThreadSafe,
60 public content::WebContentsUserData<CaptivePortalTabHelper> {
61 public:
62 ~CaptivePortalTabHelper() override;
64 // content::WebContentsObserver:
65 void DidStartNavigation(
66 content::NavigationHandle* navigation_handle) override;
67 void DidRedirectNavigation(
68 content::NavigationHandle* navigation_handle) override;
69 void DidCommitNavigation(
70 content::NavigationHandle* navigation_handle) override;
71 void DidFinishNavigation(
72 content::NavigationHandle* navigation_handle) override;
74 // content::NotificationObserver:
75 void Observe(int type,
76 const content::NotificationSource& source,
77 const content::NotificationDetails& details) override;
79 // Called when a certificate interstitial error page is about to be shown.
80 void OnSSLCertError(const net::SSLInfo& ssl_info);
82 // A "Login Tab" is a tab that was originally at a captive portal login
83 // page. This is set to false when a captive portal is no longer detected.
84 bool IsLoginTab() const;
86 // Opens a login tab if the profile's active window doesn't have one already.
87 static void OpenLoginTabForWebContents(content::WebContents* web_contents,
88 bool focus);
90 private:
91 friend class CaptivePortalBrowserTest;
92 friend class CaptivePortalTabHelperTest;
94 friend class content::WebContentsUserData<CaptivePortalTabHelper>;
95 explicit CaptivePortalTabHelper(content::WebContents* web_contents);
97 // Called by Observe in response to the corresponding event.
98 void OnCaptivePortalResults(
99 captive_portal::CaptivePortalResult previous_result,
100 captive_portal::CaptivePortalResult result);
102 // Called to indicate a tab is at, or is navigating to, the captive portal
103 // login page.
104 void SetIsLoginTab();
106 // |this| takes ownership of |tab_reloader|.
107 void SetTabReloaderForTest(CaptivePortalTabReloader* tab_reloader);
109 CaptivePortalTabReloader* GetTabReloaderForTest();
111 Profile* profile_;
113 // The current main frame navigation happening for the WebContents, or
114 // nullptr if there is none. If there are two main frame navigations
115 // happening at once, it's the one that started most recently.
116 content::NavigationHandle* navigation_handle_;
118 // Neither of these will ever be NULL.
119 scoped_ptr<CaptivePortalTabReloader> tab_reloader_;
120 scoped_ptr<CaptivePortalLoginDetector> login_detector_;
122 content::NotificationRegistrar registrar_;
124 DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabHelper);
127 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_TAB_HELPER_H_