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_UI_VIEWS_EXTENSIONS_EXTENSION_DIALOG_H_ 6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_DIALOG_H_ 7 8 #include "base/logging.h" 9 #include "base/memory/ref_counted.h" 10 #include "content/public/browser/notification_observer.h" 11 #include "content/public/browser/notification_registrar.h" 12 #include "ui/views/window/dialog_delegate.h" 13 14 class ExtensionDialogObserver; 15 class GURL; 16 class Profile; 17 18 namespace content { 19 class WebContents; 20 } 21 22 namespace extensions { 23 class ExtensionViewHost; 24 } 25 26 namespace ui { 27 class BaseWindow; 28 } 29 30 // Modal dialog containing contents provided by an extension. 31 // Dialog is automatically centered in the owning window and has fixed size. 32 // For example, used by the Chrome OS file browser. 33 class ExtensionDialog : public views::DialogDelegate, 34 public content::NotificationObserver, 35 public base::RefCounted<ExtensionDialog> { 36 public: 37 // Create and show a dialog with |url| centered over the provided window. 38 // |base_window| is the window to which the pop-up will be attached. 39 // |profile| is the profile that the extension is registered with. 40 // |web_contents| is the tab that spawned the dialog. 41 // |width| and |height| are the size of the dialog in pixels. 42 static ExtensionDialog* Show(const GURL& url, 43 ui::BaseWindow* base_window, 44 Profile* profile, 45 content::WebContents* web_contents, 46 int width, 47 int height, 48 int min_width, 49 int min_height, 50 const base::string16& title, 51 ExtensionDialogObserver* observer); 52 53 // Notifies the dialog that the observer has been destroyed and should not 54 // be sent notifications. 55 void ObserverDestroyed(); 56 57 // Focus to the render view if possible. 58 void MaybeFocusRenderView(); 59 60 // Sets the window title. 61 void set_title(const base::string16& title) { window_title_ = title; } 62 63 // Sets minimum contents size in pixels and makes the window resizable. 64 void SetMinimumContentsSize(int width, int height); 65 66 extensions::ExtensionViewHost* host() const { return host_.get(); } 67 68 // views::DialogDelegate override. 69 virtual int GetDialogButtons() const OVERRIDE; 70 virtual bool CanResize() const OVERRIDE; 71 virtual ui::ModalType GetModalType() const OVERRIDE; 72 virtual bool ShouldShowWindowTitle() const OVERRIDE; 73 virtual base::string16 GetWindowTitle() const OVERRIDE; 74 virtual void WindowClosing() OVERRIDE; 75 virtual void DeleteDelegate() OVERRIDE; 76 virtual views::Widget* GetWidget() OVERRIDE; 77 virtual const views::Widget* GetWidget() const OVERRIDE; 78 virtual views::View* GetContentsView() OVERRIDE; 79 virtual bool UseNewStyleForThisDialog() const OVERRIDE; 80 81 // content::NotificationObserver overrides. 82 virtual void Observe(int type, 83 const content::NotificationSource& source, 84 const content::NotificationDetails& details) OVERRIDE; 85 86 protected: 87 virtual ~ExtensionDialog(); 88 89 private: 90 friend class base::RefCounted<ExtensionDialog>; 91 92 // Use Show() to create instances. 93 ExtensionDialog(extensions::ExtensionViewHost* host, 94 ExtensionDialogObserver* observer); 95 96 void InitWindow(ui::BaseWindow* base_window, int width, int height); 97 98 // Window Title 99 base::string16 window_title_; 100 101 // The contained host for the view. 102 scoped_ptr<extensions::ExtensionViewHost> host_; 103 104 content::NotificationRegistrar registrar_; 105 106 // The observer of this popup. 107 ExtensionDialogObserver* observer_; 108 109 DISALLOW_COPY_AND_ASSIGN(ExtensionDialog); 110 }; 111 112 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_DIALOG_H_ 113