extension_dialog.h revision 868fa2fe829687343ffae624259930155e16dbd8
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 virtual bool UseNewStyleForThisDialog() const OVERRIDE; 83 84 // content::NotificationObserver overrides. 85 virtual void Observe(int type, 86 const content::NotificationSource& source, 87 const content::NotificationDetails& details) OVERRIDE; 88 89 protected: 90 virtual ~ExtensionDialog(); 91 92 private: 93 friend class base::RefCounted<ExtensionDialog>; 94 95 // Use Show() to create instances. 96 ExtensionDialog(extensions::ExtensionHost* host, 97 ExtensionDialogObserver* observer); 98 99 static ExtensionDialog* ShowInternal(const GURL& url, 100 ui::BaseWindow* base_window, 101 extensions::ExtensionHost* host, 102 int width, 103 int height, 104 const string16& title, 105 ExtensionDialogObserver* observer); 106 107 static extensions::ExtensionHost* CreateExtensionHost(const GURL& url, 108 Profile* profile); 109 110 void InitWindow(ui::BaseWindow* base_window, int width, int height); 111 112 // Window that holds the extension host view. 113 views::Widget* window_; 114 115 // Window Title 116 string16 window_title_; 117 118 // The contained host for the view. 119 scoped_ptr<extensions::ExtensionHost> extension_host_; 120 121 content::NotificationRegistrar registrar_; 122 123 // The observer of this popup. 124 ExtensionDialogObserver* observer_; 125 126 DISALLOW_COPY_AND_ASSIGN(ExtensionDialog); 127}; 128 129#endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_DIALOG_H_ 130