| 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 CONTENT_PUBLIC_BROWSER_WEB_UI_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_WEB_UI_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_WEB_UI_H_ | 6 #define CONTENT_PUBLIC_BROWSER_WEB_UI_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 typedef base::Callback<void(const base::ListValue*)> MessageCallback; | 84 typedef base::Callback<void(const base::ListValue*)> MessageCallback; |
| 85 virtual void RegisterMessageCallback(const std::string& message, | 85 virtual void RegisterMessageCallback(const std::string& message, |
| 86 const MessageCallback& callback) = 0; | 86 const MessageCallback& callback) = 0; |
| 87 | 87 |
| 88 // This is only needed if an embedder overrides handling of a WebUIMessage and | 88 // This is only needed if an embedder overrides handling of a WebUIMessage and |
| 89 // then later wants to undo that, or to route it to a different WebUI object. | 89 // then later wants to undo that, or to route it to a different WebUI object. |
| 90 virtual void ProcessWebUIMessage(const GURL& source_url, | 90 virtual void ProcessWebUIMessage(const GURL& source_url, |
| 91 const std::string& message, | 91 const std::string& message, |
| 92 const base::ListValue& args) = 0; | 92 const base::ListValue& args) = 0; |
| 93 | 93 |
| 94 // Calling these functions directly is discouraged. It's generally preferred |
| 95 // to call WebUIMessageHandler::CallJavascriptFunction, as that has |
| 96 // lifecycle controls to prevent calling JavaScript before the page is ready. |
| 97 // |
| 94 // Call a Javascript function by sending its name and arguments down to | 98 // Call a Javascript function by sending its name and arguments down to |
| 95 // the renderer. This is asynchronous; there's no way to get the result | 99 // the renderer. This is asynchronous; there's no way to get the result |
| 96 // of the call, and should be thought of more like sending a message to | 100 // of the call, and should be thought of more like sending a message to |
| 97 // the page. | 101 // the page. |
| 102 // |
| 98 // All function names in WebUI must consist of only ASCII characters. | 103 // All function names in WebUI must consist of only ASCII characters. |
| 99 // There are variants for calls with more arguments. | 104 // There are variants for calls with more arguments. |
| 100 virtual void CallJavascriptFunction(const std::string& function_name) = 0; | 105 virtual void CallJavascriptFunction(const std::string& function_name) = 0; |
| 101 virtual void CallJavascriptFunction(const std::string& function_name, | 106 virtual void CallJavascriptFunction(const std::string& function_name, |
| 102 const base::Value& arg) = 0; | 107 const base::Value& arg) = 0; |
| 103 virtual void CallJavascriptFunction(const std::string& function_name, | 108 virtual void CallJavascriptFunction(const std::string& function_name, |
| 104 const base::Value& arg1, | 109 const base::Value& arg1, |
| 105 const base::Value& arg2) = 0; | 110 const base::Value& arg2) = 0; |
| 106 virtual void CallJavascriptFunction(const std::string& function_name, | 111 virtual void CallJavascriptFunction(const std::string& function_name, |
| 107 const base::Value& arg1, | 112 const base::Value& arg1, |
| 108 const base::Value& arg2, | 113 const base::Value& arg2, |
| 109 const base::Value& arg3) = 0; | 114 const base::Value& arg3) = 0; |
| 110 virtual void CallJavascriptFunction(const std::string& function_name, | 115 virtual void CallJavascriptFunction(const std::string& function_name, |
| 111 const base::Value& arg1, | 116 const base::Value& arg1, |
| 112 const base::Value& arg2, | 117 const base::Value& arg2, |
| 113 const base::Value& arg3, | 118 const base::Value& arg3, |
| 114 const base::Value& arg4) = 0; | 119 const base::Value& arg4) = 0; |
| 115 virtual void CallJavascriptFunction( | 120 virtual void CallJavascriptFunction( |
| 116 const std::string& function_name, | 121 const std::string& function_name, |
| 117 const std::vector<const base::Value*>& args) = 0; | 122 const std::vector<const base::Value*>& args) = 0; |
| 118 }; | 123 }; |
| 119 | 124 |
| 120 } // namespace content | 125 } // namespace content |
| 121 | 126 |
| 122 #endif // CONTENT_PUBLIC_BROWSER_WEB_UI_H_ | 127 #endif // CONTENT_PUBLIC_BROWSER_WEB_UI_H_ |
| OLD | NEW |