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