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 "components/web_modal/native_web_contents_modal_dialog.h"
10 #include "content/public/browser/web_ui_controller.h"
11 #include "ui/gfx/native_widget_types.h"
24 class WebDialogDelegate
;
25 class WebDialogWebContentsDelegate
;
28 class ConstrainedWebDialogDelegate
{
30 virtual const ui::WebDialogDelegate
* GetWebDialogDelegate() const = 0;
31 virtual ui::WebDialogDelegate
* GetWebDialogDelegate() = 0;
33 // Called when the dialog is being closed in response to a "dialogClose"
34 // message from WebUI.
35 virtual void OnDialogCloseFromWebUI() = 0;
37 // If called, on dialog closure, the dialog will release its WebContents
38 // instead of destroying it. After which point, the caller will own the
39 // released WebContents.
40 virtual void ReleaseWebContentsOnDialogClose() = 0;
42 // Returns the WebContents owned by the constrained window.
43 virtual content::WebContents
* GetWebContents() = 0;
45 // Returns the native type used to display the dialog.
46 virtual web_modal::NativeWebContentsModalDialog
GetNativeDialog() = 0;
48 // Returns the minimum size for the dialog.
49 virtual gfx::Size
GetMinimumSize() const = 0;
51 // Returns the maximum size for the dialog.
52 virtual gfx::Size
GetMaximumSize() const = 0;
54 virtual gfx::Size
GetPreferredSize() const = 0;
57 virtual ~ConstrainedWebDialogDelegate() {}
60 // ConstrainedWebDialogUI is a facility to show HTML WebUI content
61 // in a tab-modal constrained dialog. It is implemented as an adapter
62 // between an WebDialogUI object and a web contents modal dialog.
64 // Since the web contents modal dialog requires platform-specific delegate
65 // implementations, this class is just a factory stub.
66 class ConstrainedWebDialogUI
: public content::WebUIController
{
68 explicit ConstrainedWebDialogUI(content::WebUI
* web_ui
);
69 ~ConstrainedWebDialogUI() override
;
71 // WebUIController implementation:
72 void RenderViewCreated(content::RenderViewHost
* render_view_host
) override
;
74 // Sets the delegate on the WebContents.
75 static void SetConstrainedDelegate(content::WebContents
* web_contents
,
76 ConstrainedWebDialogDelegate
* delegate
);
79 // Returns the ConstrainedWebDialogDelegate saved with the WebContents.
80 // Returns NULL if no such delegate is set.
81 ConstrainedWebDialogDelegate
* GetConstrainedDelegate();
85 void OnDialogCloseMessage(const base::ListValue
* args
);
87 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogUI
);
90 // Create and show a constrained HTML dialog. The actual object that gets
91 // created is a ConstrainedWebDialogDelegate, which later triggers construction
92 // of a ConstrainedWebDialogUI object.
93 // |browser_context| is used to construct the constrained HTML dialog's
95 // |delegate| controls the behavior of the dialog.
96 // |overshadowed| is the tab being overshadowed by the dialog.
97 ConstrainedWebDialogDelegate
* ShowConstrainedWebDialog(
98 content::BrowserContext
* browser_context
,
99 ui::WebDialogDelegate
* delegate
,
100 content::WebContents
* overshadowed
);
102 // Create and show a constrained HTML dialog with auto-resize enabled. The
103 // dialog is shown automatically with a call to PopupManager->ShowModalDialog()
104 // after document load has completed to avoid UI jankiness.
105 // |browser_context| is used to construct the dialog's WebContents.
106 // |delegate| controls the behavior of the dialog.
107 // |overshadowed| is the tab being overshadowed by the dialog.
108 // |min_size| is the minimum size of the dialog.
109 // |max_size| is the maximum size of the dialog.
110 ConstrainedWebDialogDelegate
* ShowConstrainedWebDialogWithAutoResize(
111 content::BrowserContext
* browser_context
,
112 ui::WebDialogDelegate
* delegate
,
113 content::WebContents
* overshadowed
,
114 const gfx::Size
& min_size
,
115 const gfx::Size
& max_size
);
117 #endif // CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_UI_H_