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_CHROMEOS_LOGIN_CAPTIVE_PORTAL_WINDOW_PROXY_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_CAPTIVE_PORTAL_WINDOW_PROXY_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/views/widget/widget_observer.h"
22 class CaptivePortalView
;
24 // Delegate interface for CaptivePortalWindowProxy.
25 class CaptivePortalWindowProxyDelegate
{
27 // Called when a captive portal is detected.
28 virtual void OnPortalDetected() = 0;
31 virtual ~CaptivePortalWindowProxyDelegate() {}
34 // Proxy which manages showing of the window for CaptivePortal sign-in.
35 class CaptivePortalWindowProxy
: public views::WidgetObserver
{
37 typedef CaptivePortalWindowProxyDelegate Delegate
;
39 CaptivePortalWindowProxy(Delegate
* delegate
,
40 content::WebContents
* web_contents
);
41 virtual ~CaptivePortalWindowProxy();
43 // Shows captive portal window only after a redirection has happened. So it is
44 // safe to call this method, when the caller isn't 100% sure that the network
45 // is in the captive portal state.
46 // Subsequent call to this method would reuses existing view
47 // but reloads test page (generate_204).
48 void ShowIfRedirected();
50 // Forces captive portal window show.
56 // Called by CaptivePortalView when URL loading was redirected from the
60 // Called by CaptivePortalView when origin URL is loaded without any
62 void OnOriginalURLLoaded();
64 // Overridden from views::WidgetObserver:
65 virtual void OnWidgetClosing(views::Widget
* widget
) OVERRIDE
;
68 friend class CaptivePortalWindowTest
;
70 // Possible transitions between states:
72 // wp(ShowIfRedirected(), WAITING_FOR_REDIRECTION) = IDLE
73 // wp(Show(), DISPLAYED) = IDLE | WAITING_FOR_REDIRECTION
74 // wp(Close(), IDLE) = WAITING_FOR_REDIRECTION | DISPLAYED
75 // wp(OnRedirected(), DISPLAYED) = WAITING_FOR_REDIRECTION
76 // wp(OnOriginalURLLoaded(), IDLE) = WAITING_FOR_REDIRECTION | DISPLAYED
78 // where wp(E, S) is a weakest precondition (initial state) such
79 // that after execution of E the system will be surely in the state S.
82 STATE_WAITING_FOR_REDIRECTION
,
87 // Initializes |captive_portal_view_| if it is not initialized and
88 // starts loading Captive Portal redirect URL.
89 void InitCaptivePortalView();
91 // Returns symbolic state name based on internal state.
92 State
GetState() const;
94 // Not owned by this class.
96 // Not owned by this class.
97 views::Widget
* widget_
;
98 scoped_ptr
<CaptivePortalView
> captive_portal_view_
;
100 // Not owned by this class.
101 content::WebContents
* web_contents_
;
103 DISALLOW_COPY_AND_ASSIGN(CaptivePortalWindowProxy
);
106 } // namespace chromeos
108 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_CAPTIVE_PORTAL_WINDOW_PROXY_H_