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