[email protected] | 707d6be6 | 2012-01-12 03:56:15 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 20c07f8e | 2012-05-31 08:43:14 | [diff] [blame] | 5 | #ifndef UI_WEB_DIALOGS_WEB_DIALOG_UI_H_ |
6 | #define UI_WEB_DIALOGS_WEB_DIALOG_UI_H_ | ||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 7 | |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame] | 8 | #include <string> |
[email protected] | 2bc2de6 | 2009-06-29 23:37:42 | [diff] [blame] | 9 | #include <vector> |
10 | |||||
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 12 | #include "base/macros.h" |
[email protected] | f3652ff9 | 2013-06-11 13:54:31 | [diff] [blame] | 13 | #include "base/strings/string16.h" |
[email protected] | 6936ace | 2012-01-31 02:48:12 | [diff] [blame] | 14 | #include "content/public/browser/web_contents_delegate.h" |
[email protected] | e14c95912 | 2012-01-13 16:58:25 | [diff] [blame] | 15 | #include "content/public/browser/web_ui_controller.h" |
[email protected] | 707d6be6 | 2012-01-12 03:56:15 | [diff] [blame] | 16 | #include "ui/base/ui_base_types.h" |
[email protected] | 20c07f8e | 2012-05-31 08:43:14 | [diff] [blame] | 17 | #include "ui/web_dialogs/web_dialogs_export.h" |
Kyle Horimoto | 919b252 | 2018-03-13 03:25:45 | [diff] [blame] | 18 | #include "ui/webui/mojo_web_ui_controller.h" |
[email protected] | 15999de | 2013-06-28 12:44:38 | [diff] [blame] | 19 | #include "url/gurl.h" |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 20 | |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 21 | namespace content { |
22 | class WebContents; | ||||
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 23 | } |
24 | |||||
[email protected] | 20c07f8e | 2012-05-31 08:43:14 | [diff] [blame] | 25 | namespace ui { |
26 | |||||
[email protected] | 92149569 | 2012-05-03 03:57:44 | [diff] [blame] | 27 | class WebDialogDelegate; |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 28 | |
Kyle Horimoto | 919b252 | 2018-03-13 03:25:45 | [diff] [blame] | 29 | class 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] | 5835871a | 2012-04-25 21:56:55 | [diff] [blame] | 58 | // Displays file URL contents inside a modal web dialog. |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 59 | // |
[email protected] | 0ec4898e | 2011-12-30 21:09:24 | [diff] [blame] | 60 | // This application really should not use WebContents + WebUI. It should instead |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 61 | // just embed a RenderView in a dialog and be done with it. |
62 | // | ||||
[email protected] | d21cdb1 | 2011-02-10 01:22:32 | [diff] [blame] | 63 | // Before loading a URL corresponding to this WebUI, the caller should set its |
[email protected] | 36a22c4 | 2012-08-23 00:03:11 | [diff] [blame] | 64 | // 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 Horimoto | 919b252 | 2018-03-13 03:25:45 | [diff] [blame] | 69 | class WEB_DIALOGS_EXPORT WebDialogUI : public WebDialogUIBase, |
70 | public content::WebUIController { | ||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 71 | public: |
[email protected] | 36a22c4 | 2012-08-23 00:03:11 | [diff] [blame] | 72 | // When created, the delegate should already be set as user data on the |
73 | // WebContents. | ||||
[email protected] | 5835871a | 2012-04-25 21:56:55 | [diff] [blame] | 74 | explicit WebDialogUI(content::WebUI* web_ui); |
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 75 | ~WebDialogUI() override; |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 76 | |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 77 | private: |
Kyle Horimoto | 919b252 | 2018-03-13 03:25:45 | [diff] [blame] | 78 | // content::WebUIController: |
alexmos | 78d09c90 | 2016-11-17 05:15:13 | [diff] [blame] | 79 | void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 80 | |
[email protected] | 5835871a | 2012-04-25 21:56:55 | [diff] [blame] | 81 | DISALLOW_COPY_AND_ASSIGN(WebDialogUI); |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 82 | }; |
83 | |||||
Kyle Horimoto | 919b252 | 2018-03-13 03:25:45 | [diff] [blame] | 84 | // Displays file URL contents inside a modal web dialog while also enabling |
85 | // Mojo calls to be made from within the dialog. | ||||
Christopher Lam | f82310d | 2018-04-17 05:39:16 | [diff] [blame] | 86 | class WEB_DIALOGS_EXPORT MojoWebDialogUI : public WebDialogUIBase, |
87 | public MojoWebUIController { | ||||
Kyle Horimoto | 919b252 | 2018-03-13 03:25:45 | [diff] [blame] | 88 | public: |
89 | // When created, the delegate should already be set as user data on the | ||||
90 | // WebContents. | ||||
Kyle Horimoto | e413455 | 2018-07-17 00:41:15 | [diff] [blame] | 91 | explicit MojoWebDialogUI(content::WebUI* web_ui); |
92 | ~MojoWebDialogUI() override; | ||||
Kyle Horimoto | 919b252 | 2018-03-13 03:25:45 | [diff] [blame] | 93 | |
94 | private: | ||||
95 | // content::WebUIController: | ||||
Kyle Horimoto | e413455 | 2018-07-17 00:41:15 | [diff] [blame] | 96 | void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; |
Kyle Horimoto | 919b252 | 2018-03-13 03:25:45 | [diff] [blame] | 97 | |
98 | DISALLOW_COPY_AND_ASSIGN(MojoWebDialogUI); | ||||
99 | }; | ||||
100 | |||||
[email protected] | 20c07f8e | 2012-05-31 08:43:14 | [diff] [blame] | 101 | } // namespace ui |
102 | |||||
103 | #endif // UI_WEB_DIALOGS_WEB_DIALOG_UI_H_ |