[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 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. | ||||
4 | |||||
5 | #ifndef CHROME_BROWSER_DOM_UI_HTML_DIALOG_UI_H_ | ||||
6 | #define CHROME_BROWSER_DOM_UI_HTML_DIALOG_UI_H_ | ||||
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] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 11 | #include "chrome/browser/dom_ui/dom_ui.h" |
12 | #include "chrome/common/property_bag.h" | ||||
13 | #include "googleurl/src/gurl.h" | ||||
14 | |||||
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 15 | namespace gfx { |
16 | class Size; | ||||
17 | } | ||||
18 | |||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 19 | // Implement this class to receive notifications. |
20 | class HtmlDialogUIDelegate { | ||||
21 | public: | ||||
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame^] | 22 | // Returns true if the contents needs to be run in a modal dialog. |
23 | virtual bool IsDialogModal() const = 0; | ||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 24 | |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame^] | 25 | // Returns the title of the dialog. |
26 | virtual std::wstring GetDialogTitle() const = 0; | ||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 27 | |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame^] | 28 | // Get the HTML file path for the content to load in the dialog. |
29 | virtual GURL GetDialogContentURL() const = 0; | ||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 30 | |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame^] | 31 | // Get DOMMessageHandler objects to handle messages from the HTML/JS page. |
32 | // The handlers are used to send and receive messages from the page while it | ||||
33 | // is still open. Ownership of each handler is taken over by the DOMUI | ||||
34 | // hosting the page. | ||||
35 | virtual void GetDOMMessageHandlers( | ||||
36 | std::vector<DOMMessageHandler*>* handlers) const = 0; | ||||
[email protected] | 2bc2de6 | 2009-06-29 23:37:42 | [diff] [blame] | 37 | |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame^] | 38 | // Get the size of the dialog. |
39 | virtual void GetDialogSize(gfx::Size* size) const = 0; | ||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 40 | |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame^] | 41 | // Gets the JSON string input to use when showing the dialog. |
42 | virtual std::string GetDialogArgs() const = 0; | ||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 43 | |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame^] | 44 | // A callback to notify the delegate that the dialog closed. |
45 | virtual void OnDialogClosed(const std::string& json_retval) = 0; | ||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 46 | |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame^] | 47 | protected: |
48 | ~HtmlDialogUIDelegate() {} | ||||
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 49 | }; |
50 | |||||
51 | // Displays file URL contents inside a modal HTML dialog. | ||||
52 | // | ||||
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 53 | // This application really should not use TabContents + DOMUI. It should instead |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 54 | // just embed a RenderView in a dialog and be done with it. |
55 | // | ||||
56 | // Before loading a URL corresponding to this DOMUI, the caller should set its | ||||
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 57 | // delegate as a property on the TabContents. This DOMUI will pick it up from |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 58 | // there and call it back. This is a bit of a hack to allow the dialog to pass |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 59 | // its delegate to the DOM UI without having nasty accessors on the TabContents. |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 60 | // The correct design using RVH directly would avoid all of this. |
61 | class HtmlDialogUI : public DOMUI { | ||||
62 | public: | ||||
63 | struct HtmlDialogParams { | ||||
64 | // The URL for the content that will be loaded in the dialog. | ||||
65 | GURL url; | ||||
66 | // Width of the dialog. | ||||
67 | int width; | ||||
68 | // Height of the dialog. | ||||
69 | int height; | ||||
70 | // The JSON input to pass to the dialog when showing it. | ||||
71 | std::string json_input; | ||||
72 | }; | ||||
73 | |||||
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 74 | // When created, the property should already be set on the TabContents. |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame^] | 75 | explicit HtmlDialogUI(TabContents* tab_contents); |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 76 | virtual ~HtmlDialogUI(); |
77 | |||||
78 | // Returns the PropertyBag accessor object used to write the delegate pointer | ||||
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 79 | // into the TabContents (see class-level comment above). |
[email protected] | 4acc19a6 | 2009-04-03 03:05:11 | [diff] [blame] | 80 | static PropertyAccessor<HtmlDialogUIDelegate*>& GetPropertyAccessor(); |
81 | |||||
82 | private: | ||||
83 | // DOMUI overrides. | ||||
84 | virtual void RenderViewCreated(RenderViewHost* render_view_host); | ||||
85 | |||||
86 | // JS message handler. | ||||
87 | void OnDialogClosed(const Value* content); | ||||
88 | |||||
89 | DISALLOW_COPY_AND_ASSIGN(HtmlDialogUI); | ||||
90 | }; | ||||
91 | |||||
92 | #endif // CHROME_BROWSER_DOM_UI_HTML_DIALOG_UI_H_ |