| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 UI_WEB_DIALOGS_WEB_DIALOG_UI_H_ | 5 #ifndef UI_WEB_DIALOGS_WEB_DIALOG_UI_H_ |
| 6 #define UI_WEB_DIALOGS_WEB_DIALOG_UI_H_ | 6 #define UI_WEB_DIALOGS_WEB_DIALOG_UI_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "content/public/browser/web_contents_delegate.h" | 13 #include "content/public/browser/web_contents_delegate.h" |
| 14 #include "content/public/browser/web_ui_controller.h" | 14 #include "content/public/browser/web_ui_controller.h" |
| 15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 #include "ui/base/ui_base_types.h" | 16 #include "ui/base/ui_base_types.h" |
| 17 #include "ui/web_dialogs/web_dialogs_export.h" | 17 #include "ui/web_dialogs/web_dialogs_export.h" |
| 18 | 18 |
| 19 | |
| 20 namespace base { | |
| 21 class ListValue; | |
| 22 template<class T> class PropertyAccessor; | |
| 23 } | |
| 24 | |
| 25 namespace content { | 19 namespace content { |
| 26 class WebContents; | 20 class WebContents; |
| 27 class WebUIMessageHandler; | 21 class WebUIMessageHandler; |
| 28 struct ContextMenuParams; | 22 struct ContextMenuParams; |
| 29 } | 23 } |
| 30 | 24 |
| 31 namespace gfx { | 25 namespace gfx { |
| 32 class Size; | 26 class Size; |
| 33 } | 27 } |
| 34 | 28 |
| 35 namespace ui { | 29 namespace ui { |
| 36 | 30 |
| 37 class WebDialogDelegate; | 31 class WebDialogDelegate; |
| 38 | 32 |
| 39 // Displays file URL contents inside a modal web dialog. | 33 // Displays file URL contents inside a modal web dialog. |
| 40 // | 34 // |
| 41 // This application really should not use WebContents + WebUI. It should instead | 35 // This application really should not use WebContents + WebUI. It should instead |
| 42 // just embed a RenderView in a dialog and be done with it. | 36 // just embed a RenderView in a dialog and be done with it. |
| 43 // | 37 // |
| 44 // Before loading a URL corresponding to this WebUI, the caller should set its | 38 // Before loading a URL corresponding to this WebUI, the caller should set its |
| 45 // delegate as a property on the WebContents. This WebUI will pick it up from | 39 // delegate as user data on the WebContents by calling SetDelegate(). This WebUI |
| 46 // there and call it back. This is a bit of a hack to allow the dialog to pass | 40 // will pick it up from there and call it back. This is a bit of a hack to allow |
| 47 // its delegate to the Web UI without having nasty accessors on the WebContents. | 41 // the dialog to pass its delegate to the Web UI without having nasty accessors |
| 48 // The correct design using RVH directly would avoid all of this. | 42 // on the WebContents. The correct design using RVH directly would avoid all of |
| 43 // this. |
| 49 class WEB_DIALOGS_EXPORT WebDialogUI : public content::WebUIController { | 44 class WEB_DIALOGS_EXPORT WebDialogUI : public content::WebUIController { |
| 50 public: | 45 public: |
| 51 struct WebDialogParams { | 46 struct WebDialogParams { |
| 52 // The URL for the content that will be loaded in the dialog. | 47 // The URL for the content that will be loaded in the dialog. |
| 53 GURL url; | 48 GURL url; |
| 54 // Width of the dialog. | 49 // Width of the dialog. |
| 55 int width; | 50 int width; |
| 56 // Height of the dialog. | 51 // Height of the dialog. |
| 57 int height; | 52 int height; |
| 58 // The JSON input to pass to the dialog when showing it. | 53 // The JSON input to pass to the dialog when showing it. |
| 59 std::string json_input; | 54 std::string json_input; |
| 60 }; | 55 }; |
| 61 | 56 |
| 62 // When created, the property should already be set on the WebContents. | 57 // When created, the delegate should already be set as user data on the |
| 58 // WebContents. |
| 63 explicit WebDialogUI(content::WebUI* web_ui); | 59 explicit WebDialogUI(content::WebUI* web_ui); |
| 64 virtual ~WebDialogUI(); | 60 virtual ~WebDialogUI(); |
| 65 | 61 |
| 66 // Close the dialog, passing the specified arguments to the close handler. | 62 // Close the dialog, passing the specified arguments to the close handler. |
| 67 void CloseDialog(const base::ListValue* args); | 63 void CloseDialog(const base::ListValue* args); |
| 68 | 64 |
| 69 // Returns the PropertyBag accessor object used to write the delegate pointer | 65 // Sets the delegate on the WebContents. |
| 70 // into the WebContents (see class-level comment above). | 66 static void SetDelegate(content::WebContents* web_contents, |
| 71 static base::PropertyAccessor<WebDialogDelegate*>& GetPropertyAccessor(); | 67 WebDialogDelegate* delegate); |
| 72 | 68 |
| 73 private: | 69 private: |
| 74 // WebUIController | 70 // WebUIController |
| 75 virtual void RenderViewCreated( | 71 virtual void RenderViewCreated( |
| 76 content::RenderViewHost* render_view_host) OVERRIDE; | 72 content::RenderViewHost* render_view_host) OVERRIDE; |
| 77 | 73 |
| 74 // Gets the delegate for the WebContent set with SetDelegate. |
| 75 static WebDialogDelegate* GetDelegate(content::WebContents* web_contents); |
| 76 |
| 78 // JS message handler. | 77 // JS message handler. |
| 79 void OnDialogClosed(const base::ListValue* args); | 78 void OnDialogClosed(const base::ListValue* args); |
| 80 | 79 |
| 81 DISALLOW_COPY_AND_ASSIGN(WebDialogUI); | 80 DISALLOW_COPY_AND_ASSIGN(WebDialogUI); |
| 82 }; | 81 }; |
| 83 | 82 |
| 84 // Displays external URL contents inside a modal web dialog. | 83 // Displays external URL contents inside a modal web dialog. |
| 85 // | 84 // |
| 86 // Intended to be the place to collect the settings and lockdowns | 85 // Intended to be the place to collect the settings and lockdowns |
| 87 // necessary for running external UI components securely (e.g., the | 86 // necessary for running external UI components securely (e.g., the |
| 88 // cloud print dialog). | 87 // cloud print dialog). |
| 89 class WEB_DIALOGS_EXPORT ExternalWebDialogUI : public WebDialogUI { | 88 class WEB_DIALOGS_EXPORT ExternalWebDialogUI : public WebDialogUI { |
| 90 public: | 89 public: |
| 91 explicit ExternalWebDialogUI(content::WebUI* web_ui); | 90 explicit ExternalWebDialogUI(content::WebUI* web_ui); |
| 92 virtual ~ExternalWebDialogUI(); | 91 virtual ~ExternalWebDialogUI(); |
| 93 }; | 92 }; |
| 94 | 93 |
| 95 } // namespace ui | 94 } // namespace ui |
| 96 | 95 |
| 97 #endif // UI_WEB_DIALOGS_WEB_DIALOG_UI_H_ | 96 #endif // UI_WEB_DIALOGS_WEB_DIALOG_UI_H_ |
| OLD | NEW |