blob: 3df3093c5d211aa474f95a8600b252d1f4a0341f [file] [log] [blame]
[email protected]707d6be62012-01-12 03:56:151// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]4acc19a62009-04-03 03:05:112// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]20c07f8e2012-05-31 08:43:145#ifndef UI_WEB_DIALOGS_WEB_DIALOG_UI_H_
6#define UI_WEB_DIALOGS_WEB_DIALOG_UI_H_
[email protected]4acc19a62009-04-03 03:05:117
[email protected]038d52e12009-10-14 16:53:418#include <string>
[email protected]2bc2de62009-06-29 23:37:429#include <vector>
10
[email protected]c63cedf22012-01-17 18:42:2211#include "base/compiler_specific.h"
avi9c81217b2015-12-24 23:40:0512#include "base/macros.h"
[email protected]f3652ff92013-06-11 13:54:3113#include "base/strings/string16.h"
[email protected]6936ace2012-01-31 02:48:1214#include "content/public/browser/web_contents_delegate.h"
[email protected]e14c959122012-01-13 16:58:2515#include "content/public/browser/web_ui_controller.h"
[email protected]707d6be62012-01-12 03:56:1516#include "ui/base/ui_base_types.h"
[email protected]20c07f8e2012-05-31 08:43:1417#include "ui/web_dialogs/web_dialogs_export.h"
Kyle Horimoto919b2522018-03-13 03:25:4518#include "ui/webui/mojo_web_ui_controller.h"
[email protected]15999de2013-06-28 12:44:3819#include "url/gurl.h"
[email protected]4acc19a62009-04-03 03:05:1120
[email protected]a81343d232011-12-27 07:39:2021namespace content {
22class WebContents;
[email protected]f3a1c642011-07-12 19:15:0323}
24
[email protected]20c07f8e2012-05-31 08:43:1425namespace ui {
26
[email protected]921495692012-05-03 03:57:4427class WebDialogDelegate;
[email protected]4acc19a62009-04-03 03:05:1128
Kyle Horimoto919b2522018-03-13 03:25:4529class WEB_DIALOGS_EXPORT WebDialogUIBase {
30 public:
31 // Sets the delegate on the WebContents.
32 static void SetDelegate(content::WebContents* web_contents,
33 WebDialogDelegate* delegate);
34
35 WebDialogUIBase(content::WebUI* web_ui);
36
37 // Close the dialog, passing the specified arguments to the close handler.
38 void CloseDialog(const base::ListValue* args);
39
40 protected:
41 virtual ~WebDialogUIBase();
42
43 // Prepares |render_frame_host| to host a dialog.
44 void HandleRenderFrameCreated(content::RenderFrameHost* render_frame_host);
45
46 private:
47 // Gets the delegate for the WebContent set with SetDelegate.
48 static WebDialogDelegate* GetDelegate(content::WebContents* web_contents);
49
50 // JS message handler.
51 void OnDialogClosed(const base::ListValue* args);
52
53 content::WebUI* web_ui_;
54
55 DISALLOW_COPY_AND_ASSIGN(WebDialogUIBase);
56};
57
[email protected]5835871a2012-04-25 21:56:5558// Displays file URL contents inside a modal web dialog.
[email protected]4acc19a62009-04-03 03:05:1159//
[email protected]0ec4898e2011-12-30 21:09:2460// This application really should not use WebContents + WebUI. It should instead
[email protected]4acc19a62009-04-03 03:05:1161// just embed a RenderView in a dialog and be done with it.
62//
[email protected]d21cdb12011-02-10 01:22:3263// Before loading a URL corresponding to this WebUI, the caller should set its
[email protected]36a22c42012-08-23 00:03:1164// delegate as user data on the WebContents by calling SetDelegate(). This WebUI
65// will pick it up from there and call it back. This is a bit of a hack to allow
66// the dialog to pass its delegate to the Web UI without having nasty accessors
67// on the WebContents. The correct design using RVH directly would avoid all of
68// this.
Kyle Horimoto919b2522018-03-13 03:25:4569class WEB_DIALOGS_EXPORT WebDialogUI : public WebDialogUIBase,
70 public content::WebUIController {
[email protected]4acc19a62009-04-03 03:05:1171 public:
[email protected]36a22c42012-08-23 00:03:1172 // When created, the delegate should already be set as user data on the
73 // WebContents.
[email protected]5835871a2012-04-25 21:56:5574 explicit WebDialogUI(content::WebUI* web_ui);
dcheng08038792014-10-21 10:53:2675 ~WebDialogUI() override;
[email protected]4acc19a62009-04-03 03:05:1176
[email protected]4acc19a62009-04-03 03:05:1177 private:
Kyle Horimoto919b2522018-03-13 03:25:4578 // content::WebUIController:
alexmos78d09c902016-11-17 05:15:1379 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
[email protected]4acc19a62009-04-03 03:05:1180
[email protected]5835871a2012-04-25 21:56:5581 DISALLOW_COPY_AND_ASSIGN(WebDialogUI);
[email protected]4acc19a62009-04-03 03:05:1182};
83
Kyle Horimoto919b2522018-03-13 03:25:4584// Displays file URL contents inside a modal web dialog while also enabling
85// Mojo calls to be made from within the dialog.
Christopher Lamf82310d2018-04-17 05:39:1686class WEB_DIALOGS_EXPORT MojoWebDialogUI : public WebDialogUIBase,
87 public MojoWebUIController {
Kyle Horimoto919b2522018-03-13 03:25:4588 public:
89 // When created, the delegate should already be set as user data on the
90 // WebContents.
Kyle Horimotoe4134552018-07-17 00:41:1591 explicit MojoWebDialogUI(content::WebUI* web_ui);
92 ~MojoWebDialogUI() override;
Kyle Horimoto919b2522018-03-13 03:25:4593
94 private:
95 // content::WebUIController:
Kyle Horimotoe4134552018-07-17 00:41:1596 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
Kyle Horimoto919b2522018-03-13 03:25:4597
98 DISALLOW_COPY_AND_ASSIGN(MojoWebDialogUI);
99};
100
[email protected]20c07f8e2012-05-31 08:43:14101} // namespace ui
102
103#endif // UI_WEB_DIALOGS_WEB_DIALOG_UI_H_