| 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_MESSAGE_HANDLER_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_ | 6 #define CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // the disallowed state. Subclasses should override this method to register | 70 // the disallowed state. Subclasses should override this method to register |
| 71 // observers that push JavaScript calls to the page. | 71 // observers that push JavaScript calls to the page. |
| 72 virtual void OnJavascriptAllowed() {} | 72 virtual void OnJavascriptAllowed() {} |
| 73 | 73 |
| 74 // Will be called whenever JavaScript from this handler becomes disallowed | 74 // Will be called whenever JavaScript from this handler becomes disallowed |
| 75 // from the allowed state. This will never be called before | 75 // from the allowed state. This will never be called before |
| 76 // OnJavascriptAllowed has been called. Subclasses should override this method | 76 // OnJavascriptAllowed has been called. Subclasses should override this method |
| 77 // to deregister or disabled observers that push JavaScript calls to the page. | 77 // to deregister or disabled observers that push JavaScript calls to the page. |
| 78 virtual void OnJavascriptDisallowed() {} | 78 virtual void OnJavascriptDisallowed() {} |
| 79 | 79 |
| 80 // Helper method for responding to JS requests initiated with |
| 81 // cr.sendWithPromise(), for the case where the returned promise should be |
| 82 // resolved (request succeeded). |
| 83 void ResolveJavascriptCallback(const base::Value& callback_id, |
| 84 const base::Value& response); |
| 85 |
| 86 // Helper method for responding to JS requests initiated with |
| 87 // cr.sendWithPromise(), for the case where the returned promise should be |
| 88 // rejected (request failed). |
| 89 void RejectJavascriptCallback(const base::Value& callback_id, |
| 90 const base::Value& response); |
| 91 |
| 80 // Call a Javascript function by sending its name and arguments down to | 92 // Call a Javascript function by sending its name and arguments down to |
| 81 // the renderer. This is asynchronous; there's no way to get the result | 93 // the renderer. This is asynchronous; there's no way to get the result |
| 82 // of the call, and should be thought of more like sending a message to | 94 // of the call, and should be thought of more like sending a message to |
| 83 // the page. | 95 // the page. |
| 84 // All function names in WebUI must consist of only ASCII characters. | 96 // All function names in WebUI must consist of only ASCII characters. |
| 85 // These functions will crash if JavaScript is not currently allowed. | 97 // These functions will crash if JavaScript is not currently allowed. |
| 86 template <typename... Values> | 98 template <typename... Values> |
| 87 void CallJavascriptFunction(const std::string& function_name, | 99 void CallJavascriptFunction(const std::string& function_name, |
| 88 const Values&... values) { | 100 const Values&... values) { |
| 89 CHECK(IsJavascriptAllowed()) << "Cannot CallJavascriptFunction before " | 101 CHECK(IsJavascriptAllowed()) << "Cannot CallJavascriptFunction before " |
| (...skipping 21 matching lines...) Expand all Loading... |
| 111 | 123 |
| 112 // True if the page is for JavaScript calls from this handler. | 124 // True if the page is for JavaScript calls from this handler. |
| 113 bool javascript_allowed_; | 125 bool javascript_allowed_; |
| 114 | 126 |
| 115 WebUI* web_ui_; | 127 WebUI* web_ui_; |
| 116 }; | 128 }; |
| 117 | 129 |
| 118 } // namespace content | 130 } // namespace content |
| 119 | 131 |
| 120 #endif // CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_ | 132 #endif // CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_ |
| OLD | NEW |