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

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

Issue 2924683002: [Extensions Bindings] Avoid passing the event filter to JS (Closed)
Patch Set: remove extra '.' 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
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"
11 #include "extensions/common/extension.h" 11 #include "extensions/common/extension.h"
12 #include "extensions/common/extension_api.h" 12 #include "extensions/common/extension_api.h"
13 #include "extensions/common/extension_urls.h" 13 #include "extensions/common/extension_urls.h"
14 #include "extensions/common/extensions_client.h" 14 #include "extensions/common/extensions_client.h"
15 #include "extensions/common/features/feature.h" 15 #include "extensions/common/features/feature.h"
16 #include "extensions/common/features/feature_provider.h" 16 #include "extensions/common/features/feature_provider.h"
17 #include "extensions/common/manifest_constants.h" 17 #include "extensions/common/manifest_constants.h"
18 #include "extensions/common/manifest_handlers/externally_connectable.h" 18 #include "extensions/common/manifest_handlers/externally_connectable.h"
19 #include "extensions/renderer/binding_generating_native_handler.h" 19 #include "extensions/renderer/binding_generating_native_handler.h"
20 #include "extensions/renderer/event_bindings.h"
20 #include "extensions/renderer/renderer_extension_registry.h" 21 #include "extensions/renderer/renderer_extension_registry.h"
21 #include "extensions/renderer/resource_bundle_source_map.h" 22 #include "extensions/renderer/resource_bundle_source_map.h"
22 #include "extensions/renderer/script_context.h" 23 #include "extensions/renderer/script_context.h"
23 #include "gin/converter.h" 24 #include "gin/converter.h"
24 #include "v8/include/v8.h" 25 #include "v8/include/v8.h"
25 26
26 namespace extensions { 27 namespace extensions {
27 28
28 namespace { 29 namespace {
29 30
30 static const char kEventDispatchFunction[] = "dispatchEvent";
31
32 // Gets |field| from |object| or creates it as an empty object if it doesn't 31 // Gets |field| from |object| or creates it as an empty object if it doesn't
33 // exist. 32 // exist.
34 v8::Local<v8::Object> GetOrCreateObject(const v8::Local<v8::Object>& object, 33 v8::Local<v8::Object> GetOrCreateObject(const v8::Local<v8::Object>& object,
35 const std::string& field, 34 const std::string& field,
36 v8::Isolate* isolate) { 35 v8::Isolate* isolate) {
37 v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, field.c_str()); 36 v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, field.c_str());
38 // If the object has a callback property, it is assumed it is an unavailable 37 // If the object has a callback property, it is assumed it is an unavailable
39 // API, so it is safe to delete. This is checked before GetOrCreateObject is 38 // API, so it is safe to delete. This is checked before GetOrCreateObject is
40 // called. 39 // called.
41 if (object->HasRealNamedCallbackProperty(key)) { 40 if (object->HasRealNamedCallbackProperty(key)) {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 242
244 RequestSender* JsExtensionBindingsSystem::GetRequestSender() { 243 RequestSender* JsExtensionBindingsSystem::GetRequestSender() {
245 return request_sender_.get(); 244 return request_sender_.get();
246 } 245 }
247 246
248 void JsExtensionBindingsSystem::DispatchEventInContext( 247 void JsExtensionBindingsSystem::DispatchEventInContext(
249 const std::string& event_name, 248 const std::string& event_name,
250 const base::ListValue* event_args, 249 const base::ListValue* event_args,
251 const base::DictionaryValue* filtering_info, 250 const base::DictionaryValue* filtering_info,
252 ScriptContext* context) { 251 ScriptContext* context) {
253 v8::HandleScope handle_scope(context->isolate()); 252 EventBindings::DispatchEventInContext(event_name, event_args, filtering_info,
254 v8::Context::Scope context_scope(context->v8_context()); 253 context);
255
256 std::vector<v8::Local<v8::Value>> arguments;
257 arguments.push_back(gin::StringToSymbol(context->isolate(), event_name));
258
259 {
260 std::unique_ptr<content::V8ValueConverter> converter(
261 content::V8ValueConverter::create());
262 arguments.push_back(
263 converter->ToV8Value(event_args, context->v8_context()));
264 if (filtering_info && !filtering_info->empty()) {
265 arguments.push_back(
266 converter->ToV8Value(filtering_info, context->v8_context()));
267 }
268 }
269
270 context->module_system()->CallModuleMethodSafe(
271 kEventBindings, kEventDispatchFunction, arguments.size(),
272 arguments.data());
273 } 254 }
274 255
275 void JsExtensionBindingsSystem::RegisterBinding( 256 void JsExtensionBindingsSystem::RegisterBinding(
276 const std::string& api_name, 257 const std::string& api_name,
277 const std::string& api_bind_name, 258 const std::string& api_bind_name,
278 ScriptContext* context) { 259 ScriptContext* context) {
279 std::string bind_name; 260 std::string bind_name;
280 v8::Local<v8::Object> bind_object = 261 v8::Local<v8::Object> bind_object =
281 GetOrCreateBindObjectIfAvailable(api_bind_name, &bind_name, context); 262 GetOrCreateBindObjectIfAvailable(api_bind_name, &bind_name, context);
282 263
(...skipping 27 matching lines...) Expand all
310 std::unique_ptr<NativeHandler>( 291 std::unique_ptr<NativeHandler>(
311 new BindingGeneratingNativeHandler(context, api_name, "binding"))); 292 new BindingGeneratingNativeHandler(context, api_name, "binding")));
312 module_system->SetNativeLazyField(bind_object, bind_name, api_bind_name, 293 module_system->SetNativeLazyField(bind_object, bind_name, api_bind_name,
313 "binding"); 294 "binding");
314 } else { 295 } else {
315 module_system->SetLazyField(bind_object, bind_name, api_name, "binding"); 296 module_system->SetLazyField(bind_object, bind_name, api_name, "binding");
316 } 297 }
317 } 298 }
318 299
319 } // namespace extensions 300 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698