[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 1 | // Copyright (c) 2011 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] | 265a149 | 2011-02-27 05:58:07 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_UI_WEBUI_HTML_DIALOG_UI_H_ |
6 | #define CHROME_BROWSER_UI_WEBUI_HTML_DIALOG_UI_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 8 | |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame] | 9 | #include <string> |
[email protected] | 2bc2de6 | 2009-06-29 23:37:42 | [diff] [blame] | 10 | #include <vector> |
11 | |||||
[email protected] | bdae5c1 | 2011-08-05 21:49:06 | [diff] [blame] | 12 | #include "base/string16.h" |
[email protected] | 4d241a5 | 2011-06-06 15:32:27 | [diff] [blame] | 13 | #include "chrome/browser/ui/webui/chrome_web_ui.h" |
[email protected] | 15a5fa5 | 2011-03-10 20:16:04 | [diff] [blame] | 14 | #include "content/common/property_bag.h" |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 15 | #include "googleurl/src/gurl.h" |
16 | |||||
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 17 | namespace gfx { |
18 | class Size; | ||||
19 | } | ||||
20 | |||||
[email protected] | 9a80e22 | 2010-11-22 11:27:26 | [diff] [blame] | 21 | struct ContextMenuParams; |
22 | |||||
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 23 | namespace base { |
24 | class ListValue; | ||||
25 | } | ||||
26 | |||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 27 | // Implement this class to receive notifications. |
28 | class HtmlDialogUIDelegate { | ||||
29 | public: | ||||
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame] | 30 | // Returns true if the contents needs to be run in a modal dialog. |
31 | virtual bool IsDialogModal() const = 0; | ||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 32 | |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame] | 33 | // Returns the title of the dialog. |
[email protected] | bdae5c1 | 2011-08-05 21:49:06 | [diff] [blame] | 34 | virtual string16 GetDialogTitle() const = 0; |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 35 | |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame] | 36 | // Get the HTML file path for the content to load in the dialog. |
37 | virtual GURL GetDialogContentURL() const = 0; | ||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 38 | |
[email protected] | 36e1217 | 2011-02-08 23:46:02 | [diff] [blame] | 39 | // Get WebUIMessageHandler objects to handle messages from the HTML/JS page. |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame] | 40 | // The handlers are used to send and receive messages from the page while it |
[email protected] | d21cdb1 | 2011-02-10 01:22:32 | [diff] [blame] | 41 | // is still open. Ownership of each handler is taken over by the WebUI |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame] | 42 | // hosting the page. |
[email protected] | 36e1217 | 2011-02-08 23:46:02 | [diff] [blame] | 43 | virtual void GetWebUIMessageHandlers( |
44 | std::vector<WebUIMessageHandler*>* handlers) const = 0; | ||||
[email protected] | 2bc2de6 | 2009-06-29 23:37:42 | [diff] [blame] | 45 | |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame] | 46 | // Get the size of the dialog. |
47 | virtual void GetDialogSize(gfx::Size* size) const = 0; | ||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 48 | |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame] | 49 | // Gets the JSON string input to use when showing the dialog. |
50 | virtual std::string GetDialogArgs() const = 0; | ||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 51 | |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame] | 52 | // A callback to notify the delegate that the dialog closed. |
[email protected] | 0a0298403 | 2011-09-02 20:35:46 | [diff] [blame] | 53 | // IMPORTANT: Implementations should delete |this| here (unless they've |
54 | // arranged for the delegate to be deleted in some other way, e.g. by | ||||
55 | // registering it as a message handler in the WebUI object). | ||||
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame] | 56 | virtual void OnDialogClosed(const std::string& json_retval) = 0; |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 57 | |
[email protected] | 73852b8f | 2010-05-14 00:38:12 | [diff] [blame] | 58 | // A callback to notify the delegate that the contents have gone |
59 | // away. Only relevant if your dialog hosts code that calls | ||||
60 | // windows.close() and you've allowed that. If the output parameter | ||||
61 | // is set to true, then the dialog is closed. The default is false. | ||||
62 | virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) = 0; | ||||
63 | |||||
[email protected] | ea161da | 2010-11-02 21:57:35 | [diff] [blame] | 64 | // A callback to allow the delegate to dictate that the window should not |
65 | // have a title bar. This is useful when presenting branded interfaces. | ||||
66 | virtual bool ShouldShowDialogTitle() const = 0; | ||||
67 | |||||
[email protected] | 9a80e22 | 2010-11-22 11:27:26 | [diff] [blame] | 68 | // A callback to allow the delegate to inhibit context menu or show |
69 | // customized menu. | ||||
70 | virtual bool HandleContextMenu(const ContextMenuParams& params); | ||||
71 | |||||
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame] | 72 | protected: |
[email protected] | 1bc6c55 | 2010-07-30 20:39:31 | [diff] [blame] | 73 | virtual ~HtmlDialogUIDelegate() {} |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 74 | }; |
75 | |||||
76 | // Displays file URL contents inside a modal HTML dialog. | ||||
77 | // | ||||
[email protected] | d21cdb1 | 2011-02-10 01:22:32 | [diff] [blame] | 78 | // This application really should not use TabContents + WebUI. It should instead |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 79 | // just embed a RenderView in a dialog and be done with it. |
80 | // | ||||
[email protected] | d21cdb1 | 2011-02-10 01:22:32 | [diff] [blame] | 81 | // Before loading a URL corresponding to this WebUI, the caller should set its |
82 | // delegate as a property on the TabContents. This WebUI will pick it up from | ||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 83 | // there and call it back. This is a bit of a hack to allow the dialog to pass |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 84 | // its delegate to the Web UI without having nasty accessors on the TabContents. |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 85 | // The correct design using RVH directly would avoid all of this. |
[email protected] | 4d241a5 | 2011-06-06 15:32:27 | [diff] [blame] | 86 | class HtmlDialogUI : public ChromeWebUI { |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 87 | public: |
88 | struct HtmlDialogParams { | ||||
89 | // The URL for the content that will be loaded in the dialog. | ||||
90 | GURL url; | ||||
91 | // Width of the dialog. | ||||
92 | int width; | ||||
93 | // Height of the dialog. | ||||
94 | int height; | ||||
95 | // The JSON input to pass to the dialog when showing it. | ||||
96 | std::string json_input; | ||||
97 | }; | ||||
98 | |||||
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 99 | // When created, the property should already be set on the TabContents. |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame] | 100 | explicit HtmlDialogUI(TabContents* tab_contents); |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 101 | virtual ~HtmlDialogUI(); |
102 | |||||
[email protected] | 8befa1a | 2011-09-21 02:03:38 | [diff] [blame^] | 103 | // Close the dialog, passing the specified arguments to the close handler. |
104 | void CloseDialog(const base::ListValue* args); | ||||
105 | |||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 106 | // Returns the PropertyBag accessor object used to write the delegate pointer |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 107 | // into the TabContents (see class-level comment above). |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 108 | static PropertyAccessor<HtmlDialogUIDelegate*>& GetPropertyAccessor(); |
109 | |||||
110 | private: | ||||
[email protected] | d21cdb1 | 2011-02-10 01:22:32 | [diff] [blame] | 111 | // WebUI |
[email protected] | 3abbed00 | 2011-08-01 16:02:20 | [diff] [blame] | 112 | virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE; |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 113 | |
114 | // JS message handler. | ||||
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 115 | void OnDialogClosed(const base::ListValue* args); |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 116 | |
117 | DISALLOW_COPY_AND_ASSIGN(HtmlDialogUI); | ||||
118 | }; | ||||
119 | |||||
[email protected] | 73852b8f | 2010-05-14 00:38:12 | [diff] [blame] | 120 | // Displays external URL contents inside a modal HTML dialog. |
121 | // | ||||
122 | // Intended to be the place to collect the settings and lockdowns | ||||
123 | // necessary for running external UI conponents securely (e.g., the | ||||
124 | // cloud print dialog). | ||||
125 | class ExternalHtmlDialogUI : public HtmlDialogUI { | ||||
126 | public: | ||||
127 | explicit ExternalHtmlDialogUI(TabContents* tab_contents); | ||||
128 | virtual ~ExternalHtmlDialogUI(); | ||||
129 | }; | ||||
130 | |||||
[email protected] | 265a149 | 2011-02-27 05:58:07 | [diff] [blame] | 131 | #endif // CHROME_BROWSER_UI_WEBUI_HTML_DIALOG_UI_H_ |