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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_DIALOG_H_
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_DIALOG_H_
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/gfx/native_widget_types.h"
13 #include "ui/views/window/dialog_delegate.h"
15 class ExtensionDialogObserver
;
23 namespace extensions
{
24 class ExtensionViewHost
;
27 // Modal dialog containing contents provided by an extension.
28 // Dialog is automatically centered in the owning window and has fixed size.
29 // For example, used by the Chrome OS file browser.
30 class ExtensionDialog
: public views::DialogDelegate
,
31 public content::NotificationObserver
,
32 public base::RefCounted
<ExtensionDialog
> {
34 // Create and show a dialog with |url| centered over the provided window.
35 // |parent_window| is the parent window to which the pop-up will be attached.
36 // |profile| is the profile that the extension is registered with.
37 // |web_contents| is the tab that spawned the dialog.
38 // |width| and |height| are the size of the dialog in pixels.
39 static ExtensionDialog
* Show(const GURL
& url
,
40 gfx::NativeWindow parent_window
,
42 content::WebContents
* web_contents
,
47 const base::string16
& title
,
48 ExtensionDialogObserver
* observer
);
50 // Notifies the dialog that the observer has been destroyed and should not
51 // be sent notifications.
52 void ObserverDestroyed();
54 // Focus to the render view if possible.
55 void MaybeFocusRenderView();
57 // Sets the window title.
58 void set_title(const base::string16
& title
) { window_title_
= title
; }
60 // Sets minimum contents size in pixels and makes the window resizable.
61 void SetMinimumContentsSize(int width
, int height
);
63 extensions::ExtensionViewHost
* host() const { return host_
.get(); }
65 // views::DialogDelegate override.
66 int GetDialogButtons() const override
;
67 bool CanResize() const override
;
68 ui::ModalType
GetModalType() const override
;
69 bool ShouldShowWindowTitle() const override
;
70 base::string16
GetWindowTitle() const override
;
71 void WindowClosing() override
;
72 void DeleteDelegate() override
;
73 views::Widget
* GetWidget() override
;
74 const views::Widget
* GetWidget() const override
;
75 views::View
* GetContentsView() override
;
76 bool UseNewStyleForThisDialog() const override
;
78 // content::NotificationObserver overrides.
79 void Observe(int type
,
80 const content::NotificationSource
& source
,
81 const content::NotificationDetails
& details
) override
;
84 ~ExtensionDialog() override
;
87 friend class base::RefCounted
<ExtensionDialog
>;
89 // Use Show() to create instances.
90 ExtensionDialog(extensions::ExtensionViewHost
* host
,
91 ExtensionDialogObserver
* observer
);
93 void InitWindow(gfx::NativeWindow parent_window
, int width
, int height
);
96 base::string16 window_title_
;
98 // The contained host for the view.
99 scoped_ptr
<extensions::ExtensionViewHost
> host_
;
101 content::NotificationRegistrar registrar_
;
103 // The observer of this popup.
104 ExtensionDialogObserver
* observer_
;
106 DISALLOW_COPY_AND_ASSIGN(ExtensionDialog
);
109 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_DIALOG_H_