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. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_UI_CAPTIVE_PORTAL_WINDOW_PROXY_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_UI_CAPTIVE_PORTAL_WINDOW_PROXY_H_ 7 8 #include "base/compiler_specific.h" 9 #include "base/memory/scoped_ptr.h" 10 #include "ui/views/widget/widget_observer.h" 11 12 namespace content { 13 class WebContents; 14 } 15 16 namespace views { 17 class Widget; 18 } 19 20 namespace chromeos { 21 22 class CaptivePortalView; 23 24 // Delegate interface for CaptivePortalWindowProxy. 25 class CaptivePortalWindowProxyDelegate { 26 public: 27 // Called when a captive portal is detected. 28 virtual void OnPortalDetected() = 0; 29 30 protected: 31 virtual ~CaptivePortalWindowProxyDelegate() {} 32 }; 33 34 // Proxy which manages showing of the window for CaptivePortal sign-in. 35 class CaptivePortalWindowProxy : public views::WidgetObserver { 36 public: 37 typedef CaptivePortalWindowProxyDelegate Delegate; 38 39 CaptivePortalWindowProxy(Delegate* delegate, 40 content::WebContents* web_contents); 41 virtual ~CaptivePortalWindowProxy(); 42 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(); 49 50 // Forces captive portal window show. 51 void Show(); 52 53 // Closes the window. 54 void Close(); 55 56 // Called by CaptivePortalView when URL loading was redirected from the 57 // original URL. 58 void OnRedirected(); 59 60 // Called by CaptivePortalView when origin URL is loaded without any 61 // redirections. 62 void OnOriginalURLLoaded(); 63 64 // Overridden from views::WidgetObserver: 65 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE; 66 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 67 virtual void OnWidgetDestroyed(views::Widget* widget) OVERRIDE; 68 69 private: 70 friend class CaptivePortalWindowTest; 71 friend class SimpleWebViewDialogTest; 72 73 // Possible transitions between states: 74 // 75 // wp(ShowIfRedirected(), WAITING_FOR_REDIRECTION) = IDLE 76 // wp(Show(), DISPLAYED) = IDLE | WAITING_FOR_REDIRECTION 77 // wp(Close(), IDLE) = WAITING_FOR_REDIRECTION | DISPLAYED 78 // wp(OnRedirected(), DISPLAYED) = WAITING_FOR_REDIRECTION 79 // wp(OnOriginalURLLoaded(), IDLE) = WAITING_FOR_REDIRECTION | DISPLAYED 80 // 81 // where wp(E, S) is a weakest precondition (initial state) such 82 // that after execution of E the system will be surely in the state S. 83 enum State { 84 STATE_IDLE = 0, 85 STATE_WAITING_FOR_REDIRECTION, 86 STATE_DISPLAYED, 87 STATE_UNKNOWN 88 }; 89 90 // Initializes |captive_portal_view_| if it is not initialized and 91 // starts loading Captive Portal redirect URL. 92 void InitCaptivePortalView(); 93 94 // Returns symbolic state name based on internal state. 95 State GetState() const; 96 97 // When |widget| is not NULL and the same as |widget_| stops to observe 98 // notifications from |widget_| and resets it. 99 void DetachFromWidget(views::Widget* widget); 100 101 CaptivePortalView* captive_portal_view_for_testing() { 102 return captive_portal_view_for_testing_; 103 } 104 105 // Not owned by this class. 106 Delegate* delegate_; 107 // Not owned by this class. 108 views::Widget* widget_; 109 scoped_ptr<CaptivePortalView> captive_portal_view_; 110 111 // Not owned by this class. 112 content::WebContents* web_contents_; 113 114 CaptivePortalView* captive_portal_view_for_testing_; 115 116 DISALLOW_COPY_AND_ASSIGN(CaptivePortalWindowProxy); 117 }; 118 119 } // namespace chromeos 120 121 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_UI_CAPTIVE_PORTAL_WINDOW_PROXY_H_ 122