1 // Copyright 2014 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_CHROMEOS_LOGIN_UI_CAPTIVE_PORTAL_WINDOW_PROXY_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_UI_CAPTIVE_PORTAL_WINDOW_PROXY_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h"
11 #include "ui/views/widget/widget_observer.h"
23 class CaptivePortalView
;
25 // Delegate interface for CaptivePortalWindowProxy.
26 class CaptivePortalWindowProxyDelegate
{
28 // Called when a captive portal is detected.
29 virtual void OnPortalDetected() = 0;
32 virtual ~CaptivePortalWindowProxyDelegate() {}
35 // Proxy which manages showing of the window for CaptivePortal sign-in.
36 class CaptivePortalWindowProxy
: public views::WidgetObserver
{
38 typedef CaptivePortalWindowProxyDelegate Delegate
;
40 CaptivePortalWindowProxy(Delegate
* delegate
,
41 content::WebContents
* web_contents
);
42 ~CaptivePortalWindowProxy() override
;
44 // Shows captive portal window only after a redirection has happened. So it is
45 // safe to call this method, when the caller isn't 100% sure that the network
46 // is in the captive portal state.
47 // Subsequent call to this method would reuses existing view
48 // but reloads test page (generate_204).
49 void ShowIfRedirected();
51 // Forces captive portal window show.
57 // Called by CaptivePortalView when URL loading was redirected from the
61 // Called by CaptivePortalView when origin URL is loaded without any
63 void OnOriginalURLLoaded();
65 // Overridden from views::WidgetObserver:
66 void OnWidgetClosing(views::Widget
* widget
) override
;
67 void OnWidgetDestroying(views::Widget
* widget
) override
;
68 void OnWidgetDestroyed(views::Widget
* widget
) override
;
71 friend class CaptivePortalWindowTest
;
72 friend class SimpleWebViewDialogTest
;
74 // Possible transitions between states:
76 // wp(ShowIfRedirected(), WAITING_FOR_REDIRECTION) = IDLE
77 // wp(Show(), DISPLAYED) = IDLE | WAITING_FOR_REDIRECTION
78 // wp(Close(), IDLE) = WAITING_FOR_REDIRECTION | DISPLAYED
79 // wp(OnRedirected(), DISPLAYED) = WAITING_FOR_REDIRECTION
80 // wp(OnOriginalURLLoaded(), IDLE) = WAITING_FOR_REDIRECTION | DISPLAYED
82 // where wp(E, S) is a weakest precondition (initial state) such
83 // that after execution of E the system will be surely in the state S.
86 STATE_WAITING_FOR_REDIRECTION
,
91 // Initializes |captive_portal_view_| if it is not initialized and
92 // starts loading Captive Portal redirect URL.
93 void InitCaptivePortalView();
95 // Returns symbolic state name based on internal state.
96 State
GetState() const;
98 // When |widget| is not NULL and the same as |widget_| stops to observe
99 // notifications from |widget_| and resets it.
100 void DetachFromWidget(views::Widget
* widget
);
102 CaptivePortalView
* captive_portal_view_for_testing() {
103 return captive_portal_view_for_testing_
;
106 // Not owned by this class.
108 // Not owned by this class.
109 views::Widget
* widget_
;
110 scoped_ptr
<CaptivePortalView
> captive_portal_view_
;
112 // Not owned by this class.
113 content::WebContents
* web_contents_
;
115 CaptivePortalView
* captive_portal_view_for_testing_
;
117 base::Time started_loading_at_
;
119 DISALLOW_COPY_AND_ASSIGN(CaptivePortalWindowProxy
);
122 } // namespace chromeos
124 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_UI_CAPTIVE_PORTAL_WINDOW_PROXY_H_