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

Unified Diff: content/public/browser/web_ui_message_handler.h

Issue 2890523003: WebUI: Add helper FireWebUIListener method on WebUIMessageHandler. (Closed)
Patch Set: Address comment. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/settings/search_engines_handler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/browser/web_ui_message_handler.h
diff --git a/content/public/browser/web_ui_message_handler.h b/content/public/browser/web_ui_message_handler.h
index c8d3b09fcdd5fbc4bf0aa49dac6a753b336745b1..0582651ce4a716547ac96ed96a7ab273831cede8 100644
--- a/content/public/browser/web_ui_message_handler.h
+++ b/content/public/browser/web_ui_message_handler.h
@@ -10,6 +10,7 @@
#include "base/gtest_prod_util.h"
#include "base/logging.h"
#include "base/strings/string16.h"
+#include "base/values.h"
#include "content/common/content_export.h"
#include "content/public/browser/web_ui.h"
@@ -17,7 +18,6 @@ class WebUIBrowserTest;
namespace base {
class ListValue;
-class Value;
}
namespace content {
@@ -91,6 +91,16 @@ class CONTENT_EXPORT WebUIMessageHandler {
void RejectJavascriptCallback(const base::Value& callback_id,
const base::Value& response);
+ // Helper method for notifying Javascript listeners added with
+ // cr.addWebUIListener() (defined in cr.js).
+ template <typename... Values>
+ void FireWebUIListener(const std::string& event_name,
+ const Values&... values) {
+ // cr.webUIListenerCallback is a global JS function exposed from cr.js.
+ CallJavascriptFunction("cr.webUIListenerCallback", base::Value(event_name),
+ values...);
+ }
+
// Call a Javascript function by sending its name and arguments down to
// the renderer. This is asynchronous; there's no way to get the result
// of the call, and should be thought of more like sending a message to
« no previous file with comments | « chrome/browser/ui/webui/settings/search_engines_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698