| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CONTENT_BROWSER_WEBUI_WEB_UI_H_ | 5 #ifndef CONTENT_BROWSER_WEBUI_WEB_UI_H_ |
| 6 #define CONTENT_BROWSER_WEBUI_WEB_UI_H_ | 6 #define CONTENT_BROWSER_WEBUI_WEB_UI_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // Indicates whether RegisterMessageCallback() will overwrite an existing | 111 // Indicates whether RegisterMessageCallback() will overwrite an existing |
| 112 // message callback mapping. Serves as the hook for test mocks. | 112 // message callback mapping. Serves as the hook for test mocks. |
| 113 bool register_callback_overwrites() const { | 113 bool register_callback_overwrites() const { |
| 114 return register_callback_overwrites_; | 114 return register_callback_overwrites_; |
| 115 } | 115 } |
| 116 | 116 |
| 117 void set_register_callback_overwrites(bool value) { | 117 void set_register_callback_overwrites(bool value) { |
| 118 register_callback_overwrites_ = value; | 118 register_callback_overwrites_ = value; |
| 119 } | 119 } |
| 120 | 120 |
| 121 void set_frame_xpath(const std::string& xpath) { |
| 122 frame_xpath_ = xpath; |
| 123 } |
| 124 |
| 121 // Call a Javascript function by sending its name and arguments down to | 125 // Call a Javascript function by sending its name and arguments down to |
| 122 // the renderer. This is asynchronous; there's no way to get the result | 126 // the renderer. This is asynchronous; there's no way to get the result |
| 123 // of the call, and should be thought of more like sending a message to | 127 // of the call, and should be thought of more like sending a message to |
| 124 // the page. | 128 // the page. |
| 125 // All function names in WebUI must consist of only ASCII characters. | 129 // All function names in WebUI must consist of only ASCII characters. |
| 126 // There are variants for calls with more arguments. | 130 // There are variants for calls with more arguments. |
| 127 void CallJavascriptFunction(const std::string& function_name); | 131 virtual void CallJavascriptFunction(const std::string& function_name); |
| 128 void CallJavascriptFunction(const std::string& function_name, | 132 virtual void CallJavascriptFunction(const std::string& function_name, |
| 129 const base::Value& arg); | 133 const base::Value& arg); |
| 130 void CallJavascriptFunction(const std::string& function_name, | 134 virtual void CallJavascriptFunction(const std::string& function_name, |
| 131 const base::Value& arg1, | 135 const base::Value& arg1, |
| 132 const base::Value& arg2); | 136 const base::Value& arg2); |
| 133 void CallJavascriptFunction(const std::string& function_name, | 137 virtual void CallJavascriptFunction(const std::string& function_name, |
| 134 const base::Value& arg1, | 138 const base::Value& arg1, |
| 135 const base::Value& arg2, | 139 const base::Value& arg2, |
| 136 const base::Value& arg3); | 140 const base::Value& arg3); |
| 137 void CallJavascriptFunction(const std::string& function_name, | 141 virtual void CallJavascriptFunction(const std::string& function_name, |
| 138 const base::Value& arg1, | 142 const base::Value& arg1, |
| 139 const base::Value& arg2, | 143 const base::Value& arg2, |
| 140 const base::Value& arg3, | 144 const base::Value& arg3, |
| 141 const base::Value& arg4); | 145 const base::Value& arg4); |
| 142 void CallJavascriptFunction(const std::string& function_name, | 146 virtual void CallJavascriptFunction(const std::string& function_name, |
| 143 const std::vector<const base::Value*>& args); | 147 const std::vector<const base::Value*>& args); |
| 144 | 148 |
| 145 TabContents* tab_contents() const { return tab_contents_; } | 149 TabContents* tab_contents() const { return tab_contents_; } |
| 146 | 150 |
| 147 // An opaque identifier used to identify a WebUI. This can only be compared to | 151 // An opaque identifier used to identify a WebUI. This can only be compared to |
| 148 // kNoWebUI or other WebUI types. See GetWebUIType. | 152 // kNoWebUI or other WebUI types. See GetWebUIType. |
| 149 typedef void* TypeID; | 153 typedef void* TypeID; |
| 150 | 154 |
| 151 // A special WebUI type that signifies that a given page would not use the | 155 // A special WebUI type that signifies that a given page would not use the |
| 152 // Web UI system. | 156 // Web UI system. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 183 std::vector<WebUIMessageHandler*> handlers_; | 187 std::vector<WebUIMessageHandler*> handlers_; |
| 184 | 188 |
| 185 // Non-owning pointer to the TabContents this WebUI is associated with. | 189 // Non-owning pointer to the TabContents this WebUI is associated with. |
| 186 TabContents* tab_contents_; | 190 TabContents* tab_contents_; |
| 187 | 191 |
| 188 private: | 192 private: |
| 189 // A map of message name -> message handling callback. | 193 // A map of message name -> message handling callback. |
| 190 typedef std::map<std::string, MessageCallback> MessageCallbackMap; | 194 typedef std::map<std::string, MessageCallback> MessageCallbackMap; |
| 191 MessageCallbackMap message_callbacks_; | 195 MessageCallbackMap message_callbacks_; |
| 192 | 196 |
| 197 // The path for the iframe this WebUI is embedded in (empty if not in an |
| 198 // iframe). |
| 199 std::string frame_xpath_; |
| 200 |
| 193 DISALLOW_COPY_AND_ASSIGN(WebUI); | 201 DISALLOW_COPY_AND_ASSIGN(WebUI); |
| 194 }; | 202 }; |
| 195 | 203 |
| 196 // Messages sent from the DOM are forwarded via the WebUI to handler | 204 // Messages sent from the DOM are forwarded via the WebUI to handler |
| 197 // classes. These objects are owned by WebUI and destroyed when the | 205 // classes. These objects are owned by WebUI and destroyed when the |
| 198 // host is destroyed. | 206 // host is destroyed. |
| 199 class CONTENT_EXPORT WebUIMessageHandler { | 207 class CONTENT_EXPORT WebUIMessageHandler { |
| 200 public: | 208 public: |
| 201 WebUIMessageHandler(); | 209 WebUIMessageHandler(); |
| 202 virtual ~WebUIMessageHandler(); | 210 virtual ~WebUIMessageHandler(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 228 // Returns the attached WebUI for this handler. | 236 // Returns the attached WebUI for this handler. |
| 229 WebUI* web_ui() const { return web_ui_; } | 237 WebUI* web_ui() const { return web_ui_; } |
| 230 | 238 |
| 231 WebUI* web_ui_; // TODO(wyck): Make private after merge conflicts go away. | 239 WebUI* web_ui_; // TODO(wyck): Make private after merge conflicts go away. |
| 232 | 240 |
| 233 private: | 241 private: |
| 234 DISALLOW_COPY_AND_ASSIGN(WebUIMessageHandler); | 242 DISALLOW_COPY_AND_ASSIGN(WebUIMessageHandler); |
| 235 }; | 243 }; |
| 236 | 244 |
| 237 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_H_ | 245 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_H_ |
| OLD | NEW |