Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef UI_WEB_DIALOGS_WEB_DIALOG_UI_H_ | |
| 6 #define UI_WEB_DIALOGS_WEB_DIALOG_UI_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "ui/views/views_export.h" | |
|
mazda
2012/05/03 22:56:22
You need to create "ui/web_dialogs/web_dialogs_exp
| |
| 13 | |
| 14 #include "base/compiler_specific.h" | |
| 15 #include "base/string16.h" | |
| 16 #include "content/public/browser/web_contents_delegate.h" | |
| 17 #include "content/public/browser/web_ui_controller.h" | |
| 18 #include "googleurl/src/gurl.h" | |
| 19 #include "ui/base/ui_base_types.h" | |
| 20 | |
| 21 | |
| 22 namespace base { | |
| 23 class ListValue; | |
| 24 template<class T> class PropertyAccessor; | |
| 25 } | |
| 26 | |
| 27 namespace content { | |
| 28 class WebContents; | |
| 29 class WebUIMessageHandler; | |
| 30 struct ContextMenuParams; | |
| 31 } | |
| 32 | |
| 33 namespace gfx { | |
| 34 class Size; | |
| 35 } | |
| 36 | |
| 37 namespace views { | |
|
mazda
2012/05/03 22:56:22
This should not be in views namespace.
tfarina
2012/05/03 23:17:29
either ui or web_dialogs. My preference is for ui
| |
| 38 // Implement this class to receive notifications. | |
| 39 class VIEWS_EXPORT WebDialogDelegate { | |
|
mazda
2012/05/03 22:56:22
WEB_DIALOGS_EXPORT
tfarina
2012/05/03 22:59:53
And this class should be in its own header file pe
| |
| 40 public: | |
| 41 // Returns true if the contents needs to be run in a modal dialog. | |
| 42 virtual ui::ModalType GetDialogModalType() const = 0; | |
| 43 | |
| 44 // Returns the title of the dialog. | |
| 45 virtual string16 GetDialogTitle() const = 0; | |
| 46 | |
| 47 // Returns the dialog's name identifier. Used to identify this dialog for | |
| 48 // state restoration. | |
| 49 virtual std::string GetDialogName() const; | |
| 50 | |
| 51 // Get the HTML file path for the content to load in the dialog. | |
| 52 virtual GURL GetDialogContentURL() const = 0; | |
| 53 | |
| 54 // Get WebUIMessageHandler objects to handle messages from the HTML/JS page. | |
| 55 // The handlers are used to send and receive messages from the page while it | |
| 56 // is still open. Ownership of each handler is taken over by the WebUI | |
| 57 // hosting the page. | |
| 58 virtual void GetWebUIMessageHandlers( | |
| 59 std::vector<content::WebUIMessageHandler*>* handlers) const = 0; | |
| 60 | |
| 61 // Get the size of the dialog. | |
| 62 virtual void GetDialogSize(gfx::Size* size) const = 0; | |
| 63 | |
| 64 // Get the size of the dialog. | |
| 65 virtual void GetMinimumDialogSize(gfx::Size* size) const; | |
| 66 | |
| 67 // Gets the JSON string input to use when showing the dialog. | |
| 68 virtual std::string GetDialogArgs() const = 0; | |
| 69 | |
| 70 // A callback to notify the delegate that |source|'s loading state has | |
| 71 // changed. | |
| 72 virtual void OnLoadingStateChanged(content::WebContents* source) {} | |
| 73 | |
| 74 // A callback to notify the delegate that the dialog closed. | |
| 75 // IMPORTANT: Implementations should delete |this| here (unless they've | |
| 76 // arranged for the delegate to be deleted in some other way, e.g. by | |
| 77 // registering it as a message handler in the WebUI object). | |
| 78 virtual void OnDialogClosed(const std::string& json_retval) = 0; | |
| 79 | |
| 80 // A callback to notify the delegate that the contents have gone | |
| 81 // away. Only relevant if your dialog hosts code that calls | |
| 82 // windows.close() and you've allowed that. If the output parameter | |
| 83 // is set to true, then the dialog is closed. The default is false. | |
| 84 virtual void OnCloseContents(content::WebContents* source, | |
| 85 bool* out_close_dialog) = 0; | |
| 86 | |
| 87 // A callback to allow the delegate to dictate that the window should not | |
| 88 // have a title bar. This is useful when presenting branded interfaces. | |
| 89 virtual bool ShouldShowDialogTitle() const = 0; | |
| 90 | |
| 91 // A callback to allow the delegate to inhibit context menu or show | |
| 92 // customized menu. | |
| 93 // Returns true iff you do NOT want the standard context menu to be | |
| 94 // shown (because you want to handle it yourself). | |
| 95 virtual bool HandleContextMenu(const content::ContextMenuParams& params); | |
| 96 | |
| 97 // A callback to allow the delegate to open a new URL inside |source|. | |
| 98 // On return |out_new_contents| should contain the WebContents the URL | |
| 99 // is opened in. Return false to use the default handler. | |
| 100 virtual bool HandleOpenURLFromTab(content::WebContents* source, | |
| 101 const content::OpenURLParams& params, | |
| 102 content::WebContents** out_new_contents); | |
| 103 | |
| 104 // A callback to create a new tab with |new_contents|. |source| is the | |
| 105 // WebContent where the operation originated. |disposition| controls how the | |
| 106 // new tab should be opened. |initial_pos| is the position of the window if a | |
| 107 // new window is created. |user_gesture| is true if the operation was started | |
| 108 // by a user gesture. Return false to use the default handler. | |
| 109 virtual bool HandleAddNewContents(content::WebContents* source, | |
| 110 content::WebContents* new_contents, | |
| 111 WindowOpenDisposition disposition, | |
| 112 const gfx::Rect& initial_pos, | |
| 113 bool user_gesture); | |
| 114 | |
| 115 // Stores the dialog bounds. | |
| 116 virtual void StoreDialogSize(const gfx::Size& dialog_size) {} | |
| 117 | |
| 118 protected: | |
| 119 virtual ~WebDialogDelegate() {} | |
| 120 }; | |
| 121 | |
| 122 // Displays file URL contents inside a modal web dialog. | |
| 123 // | |
| 124 // This application really should not use WebContents + WebUI. It should instead | |
| 125 // just embed a RenderView in a dialog and be done with it. | |
| 126 // | |
| 127 // Before loading a URL corresponding to this WebUI, the caller should set its | |
| 128 // delegate as a property on the WebContents. This WebUI will pick it up from | |
| 129 // there and call it back. This is a bit of a hack to allow the dialog to pass | |
| 130 // its delegate to the Web UI without having nasty accessors on the WebContents. | |
| 131 // The correct design using RVH directly would avoid all of this. | |
| 132 class VIEWS_EXPORT WebDialogUI : public content::WebUIController { | |
| 133 public: | |
| 134 struct WebDialogParams { | |
| 135 // The URL for the content that will be loaded in the dialog. | |
| 136 GURL url; | |
| 137 // Width of the dialog. | |
| 138 int width; | |
| 139 // Height of the dialog. | |
| 140 int height; | |
| 141 // The JSON input to pass to the dialog when showing it. | |
| 142 std::string json_input; | |
| 143 }; | |
| 144 | |
| 145 // When created, the property should already be set on the WebContents. | |
| 146 explicit WebDialogUI(content::WebUI* web_ui); | |
| 147 virtual ~WebDialogUI(); | |
| 148 | |
| 149 // Close the dialog, passing the specified arguments to the close handler. | |
| 150 void CloseDialog(const base::ListValue* args); | |
| 151 | |
| 152 // Returns the PropertyBag accessor object used to write the delegate pointer | |
| 153 // into the WebContents (see class-level comment above). | |
| 154 static base::PropertyAccessor<WebDialogDelegate*>& GetPropertyAccessor(); | |
| 155 | |
| 156 private: | |
| 157 // WebUIController | |
| 158 virtual void RenderViewCreated( | |
| 159 content::RenderViewHost* render_view_host) OVERRIDE; | |
| 160 | |
| 161 // JS message handler. | |
| 162 void OnDialogClosed(const base::ListValue* args); | |
| 163 | |
| 164 DISALLOW_COPY_AND_ASSIGN(WebDialogUI); | |
| 165 }; | |
| 166 | |
| 167 } //namespace views | |
| 168 #endif // UI_WEB_DIALOGS_WEB_DIALOG_UI_H_ | |
| OLD | NEW |