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