| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // the renderer. This is asynchronous; there's no way to get the result | 81 // 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 | 82 // of the call, and should be thought of more like sending a message to |
| 83 // the page. | 83 // the page. |
| 84 // All function names in WebUI must consist of only ASCII characters. | 84 // All function names in WebUI must consist of only ASCII characters. |
| 85 // These functions will crash if JavaScript is not currently allowed. | 85 // These functions will crash if JavaScript is not currently allowed. |
| 86 template <typename... Values> | 86 template <typename... Values> |
| 87 void CallJavascriptFunction(const std::string& function_name, | 87 void CallJavascriptFunction(const std::string& function_name, |
| 88 const Values&... values) { | 88 const Values&... values) { |
| 89 CHECK(IsJavascriptAllowed()) << "Cannot CallJavascriptFunction before " | 89 CHECK(IsJavascriptAllowed()) << "Cannot CallJavascriptFunction before " |
| 90 "explicitly allowing JavaScript."; | 90 "explicitly allowing JavaScript."; |
| 91 web_ui()->CallJavascriptFunction(function_name, values...); | 91 |
| 92 // The CHECK above makes this call safe. |
| 93 web_ui()->CallJavascriptFunctionUnsafe(function_name, values...); |
| 92 } | 94 } |
| 93 | 95 |
| 94 // Returns the attached WebUI for this handler. | 96 // Returns the attached WebUI for this handler. |
| 95 WebUI* web_ui() const { return web_ui_; } | 97 WebUI* web_ui() const { return web_ui_; } |
| 96 | 98 |
| 97 // Sets the attached WebUI - exposed to subclasses for testing purposes. | 99 // Sets the attached WebUI - exposed to subclasses for testing purposes. |
| 98 void set_web_ui(WebUI* web_ui) { web_ui_ = web_ui; } | 100 void set_web_ui(WebUI* web_ui) { web_ui_ = web_ui; } |
| 99 | 101 |
| 100 private: | 102 private: |
| 101 // Provide external classes access to web_ui(), set_web_ui(), and | 103 // Provide external classes access to web_ui(), set_web_ui(), and |
| 102 // RenderViewReused. | 104 // RenderViewReused. |
| 103 friend class WebUIImpl; | 105 friend class WebUIImpl; |
| 104 friend class ::WebUIBrowserTest; | 106 friend class ::WebUIBrowserTest; |
| 105 | 107 |
| 106 // Called when a RenderView is reused to display a page (i.e. reload). | 108 // Called when a RenderView is reused to display a page (i.e. reload). |
| 107 void RenderViewReused(); | 109 void RenderViewReused(); |
| 108 | 110 |
| 109 // TODO(dbeam): disallow JavaScript when a renderer process crashes. | 111 // TODO(dbeam): disallow JavaScript when a renderer process crashes. |
| 110 // http://crbug.com/610450 | 112 // http://crbug.com/610450 |
| 111 | 113 |
| 112 // True if the page is for JavaScript calls from this handler. | 114 // True if the page is for JavaScript calls from this handler. |
| 113 bool javascript_allowed_; | 115 bool javascript_allowed_; |
| 114 | 116 |
| 115 WebUI* web_ui_; | 117 WebUI* web_ui_; |
| 116 }; | 118 }; |
| 117 | 119 |
| 118 } // namespace content | 120 } // namespace content |
| 119 | 121 |
| 120 #endif // CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_ | 122 #endif // CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_ |
| OLD | NEW |