Home | History | Annotate | Download | only in login
      1 // Copyright (c) 2011 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_LOGIN_HTML_DIALOG_H_
      6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_HTML_DIALOG_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "chrome/browser/ui/webui/html_dialog_ui.h"
     12 #include "content/common/notification_observer.h"
     13 #include "content/common/notification_registrar.h"
     14 #include "ui/gfx/native_widget_types.h"
     15 #include "ui/gfx/size.h"
     16 
     17 namespace chromeos {
     18 
     19 class BubbleFrameView;
     20 
     21 // Launches html dialog during OOBE/Login with specified URL and title.
     22 class LoginHtmlDialog : public HtmlDialogUIDelegate,
     23                         public NotificationObserver {
     24  public:
     25   // Delegate class to get notifications from the dialog.
     26   class Delegate {
     27   public:
     28     virtual ~Delegate() {}
     29 
     30     // Called when dialog has been closed.
     31     virtual void OnDialogClosed() = 0;
     32   };
     33 
     34   enum Style {
     35     STYLE_GENERIC, // Use generic CreateChromeWindow as a host.
     36     STYLE_BUBBLE   // Use chromeos::BubbleWindow as a host.
     37   };
     38 
     39   LoginHtmlDialog(Delegate* delegate,
     40                   gfx::NativeWindow parent_window,
     41                   const std::wstring& title,
     42                   const GURL& url,
     43                   Style style);
     44   ~LoginHtmlDialog();
     45 
     46   // Shows created dialog.
     47   void Show();
     48 
     49   // Overrides default width/height for dialog.
     50   void SetDialogSize(int width, int height);
     51 
     52   void set_url(const GURL& url) { url_ = url; }
     53 
     54   bool is_open() const { return is_open_; }
     55 
     56  protected:
     57   // HtmlDialogUIDelegate implementation.
     58   virtual bool IsDialogModal() const { return true; }
     59   virtual std::wstring GetDialogTitle() const { return title_; }
     60   virtual GURL GetDialogContentURL() const { return url_; }
     61   virtual void GetWebUIMessageHandlers(
     62       std::vector<WebUIMessageHandler*>* handlers) const {}
     63   virtual void GetDialogSize(gfx::Size* size) const;
     64   virtual std::string GetDialogArgs() const { return std::string(); }
     65   virtual void OnDialogClosed(const std::string& json_retval);
     66   virtual void OnCloseContents(TabContents* source, bool* out_close_dialog);
     67   virtual bool ShouldShowDialogTitle() const { return true; }
     68 
     69   // NotificationObserver implementation.
     70   virtual void Observe(NotificationType type,
     71                        const NotificationSource& source,
     72                        const NotificationDetails& details);
     73 
     74  private:
     75   // Notifications receiver.
     76   Delegate* delegate_;
     77 
     78   gfx::NativeWindow parent_window_;
     79   std::wstring title_;
     80   GURL url_;
     81   Style style_;
     82   NotificationRegistrar notification_registrar_;
     83   BubbleFrameView* bubble_frame_view_;
     84   bool is_open_;
     85 
     86   // Dialog display size.
     87   int width_;
     88   int height_;
     89 
     90   DISALLOW_COPY_AND_ASSIGN(LoginHtmlDialog);
     91 };
     92 
     93 }  // namespace chromeos
     94 
     95 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_HTML_DIALOG_H_
     96