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

Side by Side Diff: extensions/renderer/js_extension_bindings_system.cc

Issue 2936673004: Revert of [Extensions Bindings] Avoid passing the event filter to JS (Closed)
Patch Set: Created 3 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 | « extensions/renderer/event_bindings.cc ('k') | extensions/renderer/resources/event.js » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "extensions/renderer/js_extension_bindings_system.h" 5 #include "extensions/renderer/js_extension_bindings_system.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "content/public/child/v8_value_converter.h" 9 #include "content/public/child/v8_value_converter.h"
10 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_switches.h"
(...skipping 10 matching lines...) Expand all
21 #include "extensions/renderer/renderer_extension_registry.h" 21 #include "extensions/renderer/renderer_extension_registry.h"
22 #include "extensions/renderer/resource_bundle_source_map.h" 22 #include "extensions/renderer/resource_bundle_source_map.h"
23 #include "extensions/renderer/script_context.h" 23 #include "extensions/renderer/script_context.h"
24 #include "gin/converter.h" 24 #include "gin/converter.h"
25 #include "v8/include/v8.h" 25 #include "v8/include/v8.h"
26 26
27 namespace extensions { 27 namespace extensions {
28 28
29 namespace { 29 namespace {
30 30
31 static const char kEventDispatchFunction[] = "dispatchEvent";
32
31 // Gets |field| from |object| or creates it as an empty object if it doesn't 33 // Gets |field| from |object| or creates it as an empty object if it doesn't
32 // exist. 34 // exist.
33 v8::Local<v8::Object> GetOrCreateObject(const v8::Local<v8::Object>& object, 35 v8::Local<v8::Object> GetOrCreateObject(const v8::Local<v8::Object>& object,
34 const std::string& field, 36 const std::string& field,
35 v8::Isolate* isolate) { 37 v8::Isolate* isolate) {
36 v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, field.c_str()); 38 v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, field.c_str());
37 // If the object has a callback property, it is assumed it is an unavailable 39 // If the object has a callback property, it is assumed it is an unavailable
38 // API, so it is safe to delete. This is checked before GetOrCreateObject is 40 // API, so it is safe to delete. This is checked before GetOrCreateObject is
39 // called. 41 // called.
40 if (object->HasRealNamedCallbackProperty(key)) { 42 if (object->HasRealNamedCallbackProperty(key)) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 245
244 RequestSender* JsExtensionBindingsSystem::GetRequestSender() { 246 RequestSender* JsExtensionBindingsSystem::GetRequestSender() {
245 return request_sender_.get(); 247 return request_sender_.get();
246 } 248 }
247 249
248 void JsExtensionBindingsSystem::DispatchEventInContext( 250 void JsExtensionBindingsSystem::DispatchEventInContext(
249 const std::string& event_name, 251 const std::string& event_name,
250 const base::ListValue* event_args, 252 const base::ListValue* event_args,
251 const base::DictionaryValue* filtering_info, 253 const base::DictionaryValue* filtering_info,
252 ScriptContext* context) { 254 ScriptContext* context) {
253 EventBindings::DispatchEventInContext(event_name, event_args, filtering_info, 255 v8::HandleScope handle_scope(context->isolate());
254 context); 256 v8::Context::Scope context_scope(context->v8_context());
257
258 std::vector<v8::Local<v8::Value>> arguments;
259 arguments.push_back(gin::StringToSymbol(context->isolate(), event_name));
260
261 {
262 std::unique_ptr<content::V8ValueConverter> converter(
263 content::V8ValueConverter::create());
264 arguments.push_back(
265 converter->ToV8Value(event_args, context->v8_context()));
266 if (filtering_info && !filtering_info->empty()) {
267 arguments.push_back(
268 converter->ToV8Value(filtering_info, context->v8_context()));
269 }
270 }
271
272 context->module_system()->CallModuleMethodSafe(
273 kEventBindings, kEventDispatchFunction, arguments.size(),
274 arguments.data());
255 } 275 }
256 276
257 bool JsExtensionBindingsSystem::HasEventListenerInContext( 277 bool JsExtensionBindingsSystem::HasEventListenerInContext(
258 const std::string& event_name, 278 const std::string& event_name,
259 ScriptContext* context) { 279 ScriptContext* context) {
260 return EventBindings::HasListener(context, event_name); 280 return EventBindings::HasListener(context, event_name);
261 } 281 }
262 282
263 void JsExtensionBindingsSystem::RegisterBinding( 283 void JsExtensionBindingsSystem::RegisterBinding(
264 const std::string& api_name, 284 const std::string& api_name,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 std::unique_ptr<NativeHandler>( 318 std::unique_ptr<NativeHandler>(
299 new BindingGeneratingNativeHandler(context, api_name, "binding"))); 319 new BindingGeneratingNativeHandler(context, api_name, "binding")));
300 module_system->SetNativeLazyField(bind_object, bind_name, api_bind_name, 320 module_system->SetNativeLazyField(bind_object, bind_name, api_bind_name,
301 "binding"); 321 "binding");
302 } else { 322 } else {
303 module_system->SetLazyField(bind_object, bind_name, api_name, "binding"); 323 module_system->SetLazyField(bind_object, bind_name, api_name, "binding");
304 } 324 }
305 } 325 }
306 326
307 } // namespace extensions 327 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/event_bindings.cc ('k') | extensions/renderer/resources/event.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698