Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: content/public/browser/web_ui_message_handler.h

Issue 1995113002: Rename WebUI::CallJavascriptFunction to WebUI::CallJavascriptFunctionUnsafe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/public/browser/web_ui.h ('k') | content/public/test/test_web_ui.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_
OLDNEW
« no previous file with comments | « content/public/browser/web_ui.h ('k') | content/public/test/test_web_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698