extension_dialog.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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 14class ExtensionDialogObserver; 15class GURL; 16class Profile; 17 18namespace content { 19class WebContents; 20} 21 22namespace extensions { 23class ExtensionHost; 24} 25 26namespace ui { 27class 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. 33class 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 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 // Closes the ExtensionDialog. 58 void Close(); 59 60 // Focus to the render view if possible. 61 void MaybeFocusRenderView(); 62 63 // Sets the window title. 64 void set_title(const string16& title) { window_title_ = title; } 65 66 // Sets minimum contents size in pixels and makes the window resizable. 67 void SetMinimumContentsSize(int width, int height); 68 69 extensions::ExtensionHost* host() const { return extension_host_.get(); } 70 71 // views::DialogDelegate override. 72 virtual int GetDialogButtons() const OVERRIDE; 73 virtual bool CanResize() const OVERRIDE; 74 virtual ui::ModalType GetModalType() const OVERRIDE; 75 virtual bool ShouldShowWindowTitle() const OVERRIDE; 76 virtual string16 GetWindowTitle() const OVERRIDE; 77 virtual void WindowClosing() OVERRIDE; 78 virtual void DeleteDelegate() OVERRIDE; 79 virtual views::Widget* GetWidget() OVERRIDE; 80 virtual const views::Widget* GetWidget() const OVERRIDE; 81 virtual views::View* GetContentsView() OVERRIDE; 82 83 // content::NotificationObserver overrides. 84 virtual void Observe(int type, 85 const content::NotificationSource& source, 86 const content::NotificationDetails& details) OVERRIDE; 87 88 protected: 89 virtual ~ExtensionDialog(); 90 91 private: 92 friend class base::RefCounted<ExtensionDialog>; 93 94 // Use Show() to create instances. 95 ExtensionDialog(extensions::ExtensionHost* host, 96 ExtensionDialogObserver* observer); 97 98 static ExtensionDialog* ShowInternal(const GURL& url, 99 ui::BaseWindow* base_window, 100 extensions::ExtensionHost* host, 101 int width, 102 int height, 103 const string16& title, 104 ExtensionDialogObserver* observer); 105 106 static extensions::ExtensionHost* CreateExtensionHost(const GURL& url, 107 Profile* profile); 108 109 void InitWindow(ui::BaseWindow* base_window, int width, int height); 110 111 // Window that holds the extension host view. 112 views::Widget* window_; 113 114 // Window Title 115 string16 window_title_; 116 117 // The contained host for the view. 118 scoped_ptr<extensions::ExtensionHost> extension_host_; 119 120 content::NotificationRegistrar registrar_; 121 122 // The observer of this popup. 123 ExtensionDialogObserver* observer_; 124 125 DISALLOW_COPY_AND_ASSIGN(ExtensionDialog); 126}; 127 128#endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_DIALOG_H_ 129