Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / constrained_web_dialog_ui.h
blob62c9a8b592c71d36f2fed80087a7f9fbd9dee308
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_WEBUI_CONSTRAINED_WEB_DIALOG_UI_H_
6 #define CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_UI_H_
8 #include "base/compiler_specific.h"
9 #include "content/public/browser/web_ui_controller.h"
10 #include "ui/gfx/native_widget_types.h"
12 namespace gfx {
13 class Size;
16 namespace content {
17 class BrowserContext;
18 class RenderViewHost;
19 class WebContents;
22 namespace ui {
23 class WebDialogDelegate;
24 class WebDialogWebContentsDelegate;
27 class ConstrainedWebDialogDelegate {
28 public:
29 virtual const ui::WebDialogDelegate* GetWebDialogDelegate() const = 0;
30 virtual ui::WebDialogDelegate* GetWebDialogDelegate() = 0;
32 // Called when the dialog is being closed in response to a "dialogClose"
33 // message from WebUI.
34 virtual void OnDialogCloseFromWebUI() = 0;
36 // If called, on dialog closure, the dialog will release its WebContents
37 // instead of destroying it. After which point, the caller will own the
38 // released WebContents.
39 virtual void ReleaseWebContentsOnDialogClose() = 0;
41 // Returns the WebContents owned by the constrained window.
42 virtual content::WebContents* GetWebContents() = 0;
44 // Returns the native type used to display the dialog.
45 virtual gfx::NativeWindow GetNativeDialog() = 0;
47 // Returns the minimum size for the dialog.
48 virtual gfx::Size GetMinimumSize() const = 0;
50 // Returns the maximum size for the dialog.
51 virtual gfx::Size GetMaximumSize() const = 0;
53 virtual gfx::Size GetPreferredSize() const = 0;
55 protected:
56 virtual ~ConstrainedWebDialogDelegate() {}
59 // ConstrainedWebDialogUI is a facility to show HTML WebUI content
60 // in a tab-modal constrained dialog. It is implemented as an adapter
61 // between an WebDialogUI object and a web contents modal dialog.
63 // Since the web contents modal dialog requires platform-specific delegate
64 // implementations, this class is just a factory stub.
65 class ConstrainedWebDialogUI : public content::WebUIController {
66 public:
67 explicit ConstrainedWebDialogUI(content::WebUI* web_ui);
68 ~ConstrainedWebDialogUI() override;
70 // WebUIController implementation:
71 void RenderViewCreated(content::RenderViewHost* render_view_host) override;
73 // Sets the delegate on the WebContents.
74 static void SetConstrainedDelegate(content::WebContents* web_contents,
75 ConstrainedWebDialogDelegate* delegate);
77 protected:
78 // Returns the ConstrainedWebDialogDelegate saved with the WebContents.
79 // Returns NULL if no such delegate is set.
80 ConstrainedWebDialogDelegate* GetConstrainedDelegate();
82 private:
83 // JS Message Handler
84 void OnDialogCloseMessage(const base::ListValue* args);
86 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogUI);
89 // Create and show a constrained HTML dialog. The actual object that gets
90 // created is a ConstrainedWebDialogDelegate, which later triggers construction
91 // of a ConstrainedWebDialogUI object.
92 // |browser_context| is used to construct the constrained HTML dialog's
93 // WebContents.
94 // |delegate| controls the behavior of the dialog.
95 // |overshadowed| is the tab being overshadowed by the dialog.
96 ConstrainedWebDialogDelegate* ShowConstrainedWebDialog(
97 content::BrowserContext* browser_context,
98 ui::WebDialogDelegate* delegate,
99 content::WebContents* overshadowed);
101 // Create and show a constrained HTML dialog with auto-resize enabled. The
102 // dialog is shown automatically after document load has completed to avoid UI
103 // jankiness.
104 // |browser_context| is used to construct the dialog's WebContents.
105 // |delegate| controls the behavior of the dialog.
106 // |overshadowed| is the tab being overshadowed by the dialog.
107 // |min_size| is the minimum size of the dialog.
108 // |max_size| is the maximum size of the dialog.
109 ConstrainedWebDialogDelegate* ShowConstrainedWebDialogWithAutoResize(
110 content::BrowserContext* browser_context,
111 ui::WebDialogDelegate* delegate,
112 content::WebContents* overshadowed,
113 const gfx::Size& min_size,
114 const gfx::Size& max_size);
116 #endif // CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_UI_H_