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

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

Issue 2040473002: Move {Resolve|Reject}JavascriptCallback helpers in WebUIMessageHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comment. 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/browser/webui/web_ui_message_handler.cc ('k') | no next file » | 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
Charlie Reis 2016/06/06 21:19:52 nit: Javascript
dpapad 2016/06/06 21:28:53 Done.
81 // cr.sendWithPromise(), for the case where the returned promise should be
Charlie Reis 2016/06/06 21:19:52 What is cr?
dpapad 2016/06/06 21:28:53 'cr' is simply a namespace used by cr.js (where th
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
Charlie Reis 2016/06/06 21:19:52 (Same comments)
dpapad 2016/06/06 21:28:53 Done. See previous comment.
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
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_
OLDNEW
« no previous file with comments | « content/browser/webui/web_ui_message_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698