Home | History | Annotate | Download | only in login
      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.
      4 
      5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_CAPTIVE_PORTAL_WINDOW_PROXY_H_
      6 #define CHROME_BROWSER_CHROMEOS_LOGIN_CAPTIVE_PORTAL_WINDOW_PROXY_H_
      7 
      8 #include "base/compiler_specific.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "ui/gfx/native_widget_types.h"
     11 #include "ui/views/widget/widget_observer.h"
     12 
     13 namespace views {
     14 class Widget;
     15 }
     16 
     17 namespace chromeos {
     18 
     19 class CaptivePortalView;
     20 
     21 // Delegate interface for CaptivePortalWindowProxy.
     22 class CaptivePortalWindowProxyDelegate {
     23  public:
     24   // Called when a captive portal is detected.
     25   virtual void OnPortalDetected() = 0;
     26 
     27  protected:
     28   virtual ~CaptivePortalWindowProxyDelegate() {}
     29 };
     30 
     31 // Proxy which manages showing of the window for CaptivePortal sign-in.
     32 class CaptivePortalWindowProxy : public views::WidgetObserver {
     33  public:
     34   typedef CaptivePortalWindowProxyDelegate Delegate;
     35 
     36   CaptivePortalWindowProxy(Delegate* delegate, gfx::NativeWindow parent);
     37   virtual ~CaptivePortalWindowProxy();
     38 
     39   // Shows captive portal window only after a redirection has happened. So it is
     40   // safe to call this method, when the caller isn't 100% sure that the network
     41   // is in the captive portal state.
     42   // Subsequent call to this method would reuses existing view
     43   // but reloads test page (generate_204).
     44   void ShowIfRedirected();
     45 
     46   // Forces captive portal window show.
     47   void Show();
     48 
     49   // Closes the window.
     50   void Close();
     51 
     52   // Called by CaptivePortalView when URL loading was redirected from the
     53   // original URL.
     54   void OnRedirected();
     55 
     56   // Called by CaptivePortalView when origin URL is loaded without any
     57   // redirections.
     58   void OnOriginalURLLoaded();
     59 
     60   // Overridden from views::WidgetObserver:
     61   virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE;
     62 
     63  private:
     64   friend class CaptivePortalWindowTest;
     65 
     66   // Possible transitions between states:
     67   //
     68   // wp(ShowIfRedirected(), WAITING_FOR_REDIRECTION) = IDLE
     69   // wp(Show(), DISPLAYED) = IDLE | WAITING_FOR_REDIRECTION
     70   // wp(Close(), IDLE) = WAITING_FOR_REDIRECTION | DISPLAYED
     71   // wp(OnRedirected(), DISPLAYED) = WAITING_FOR_REDIRECTION
     72   // wp(OnOriginalURLLoaded(), IDLE) = WAITING_FOR_REDIRECTION | DISPLAYED
     73   //
     74   // where wp(E, S) is a weakest precondition (initial state) such
     75   // that after execution of E the system will be surely in the state S.
     76   enum State {
     77     STATE_IDLE = 0,
     78     STATE_WAITING_FOR_REDIRECTION,
     79     STATE_DISPLAYED,
     80     STATE_UNKNOWN
     81   };
     82 
     83   // Initializes |captive_portal_view_| if it is not initialized and
     84   // starts loading Captive Portal redirect URL.
     85   void InitCaptivePortalView();
     86 
     87   // Returns symbolic state name based on internal state.
     88   State GetState() const;
     89 
     90   Delegate* delegate_;
     91   views::Widget* widget_;
     92   scoped_ptr<CaptivePortalView> captive_portal_view_;
     93   gfx::NativeWindow parent_;
     94 
     95   DISALLOW_COPY_AND_ASSIGN(CaptivePortalWindowProxy);
     96 };
     97 
     98 }  // namespace chromeos
     99 
    100 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_CAPTIVE_PORTAL_WINDOW_PROXY_H_
    101