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_LOGIN_WEB_DIALOG_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_WEB_DIALOG_H_ 7 8 #include <string> 9 10 #include "base/compiler_specific.h" 11 #include "content/public/browser/notification_observer.h" 12 #include "content/public/browser/notification_registrar.h" 13 #include "ui/gfx/native_widget_types.h" 14 #include "ui/gfx/size.h" 15 #include "ui/web_dialogs/web_dialog_delegate.h" 16 #include "url/gurl.h" 17 18 namespace chromeos { 19 20 class BubbleFrameView; 21 22 // Launches web dialog during OOBE/Login with specified URL and title. 23 class LoginWebDialog : public ui::WebDialogDelegate, 24 public content::NotificationObserver { 25 public: 26 // Delegate class to get notifications from the dialog. 27 class Delegate { 28 public: 29 // Called when dialog has been closed. 30 virtual void OnDialogClosed(); 31 32 protected: ~Delegate()33 virtual ~Delegate() {} 34 }; 35 36 enum Style { 37 STYLE_GENERIC, // Use generic CreateChromeWindow as a host. 38 STYLE_BUBBLE // Use chromeos::BubbleWindow as a host. 39 }; 40 41 LoginWebDialog(Delegate* delegate, 42 gfx::NativeWindow parent_window, 43 const base::string16& title, 44 const GURL& url, 45 Style style); 46 virtual ~LoginWebDialog(); 47 48 void Show(); 49 50 // Overrides default width/height for dialog. 51 void SetDialogSize(int width, int height); 52 53 // Overrides dialog title. 54 void SetDialogTitle(const base::string16& title); 55 set_url(const GURL & url)56 void set_url(const GURL& url) { url_ = url; } 57 is_open()58 bool is_open() const { return is_open_; } 59 60 protected: 61 // ui::WebDialogDelegate implementation. 62 virtual ui::ModalType GetDialogModalType() const OVERRIDE; 63 virtual base::string16 GetDialogTitle() const OVERRIDE; 64 virtual GURL GetDialogContentURL() const OVERRIDE; 65 virtual void GetWebUIMessageHandlers( 66 std::vector<content::WebUIMessageHandler*>* handlers) const OVERRIDE; 67 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; 68 virtual void GetMinimumDialogSize(gfx::Size* size) const OVERRIDE; 69 virtual std::string GetDialogArgs() const OVERRIDE; 70 // NOTE: This function deletes this object at the end. 71 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; 72 virtual void OnCloseContents( 73 content::WebContents* source, bool* out_close_dialog) OVERRIDE; 74 virtual bool ShouldShowDialogTitle() const OVERRIDE; 75 virtual bool HandleContextMenu( 76 const content::ContextMenuParams& params) OVERRIDE; 77 78 // content::NotificationObserver implementation. 79 virtual void Observe(int type, 80 const content::NotificationSource& source, 81 const content::NotificationDetails& details) OVERRIDE; 82 83 private: 84 // Notifications receiver. 85 Delegate* delegate_; 86 87 gfx::NativeWindow parent_window_; 88 base::string16 title_; 89 GURL url_; 90 Style style_; 91 content::NotificationRegistrar notification_registrar_; 92 bool is_open_; 93 94 // Dialog display size. 95 int width_; 96 int height_; 97 98 DISALLOW_COPY_AND_ASSIGN(LoginWebDialog); 99 }; 100 101 } // namespace chromeos 102 103 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_WEB_DIALOG_H_ 104