OLD | NEW |
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/native_extension_bindings_system.h" | 5 #include "extensions/renderer/native_extension_bindings_system.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "content/public/common/content_switches.h" | 9 #include "content/public/common/content_switches.h" |
10 #include "extensions/common/constants.h" | 10 #include "extensions/common/constants.h" |
| 11 #include "extensions/common/event_filtering_info.h" |
11 #include "extensions/common/extension_api.h" | 12 #include "extensions/common/extension_api.h" |
12 #include "extensions/common/extension_messages.h" | 13 #include "extensions/common/extension_messages.h" |
13 #include "extensions/common/features/feature_provider.h" | 14 #include "extensions/common/features/feature_provider.h" |
14 #include "extensions/renderer/api_binding_bridge.h" | 15 #include "extensions/renderer/api_binding_bridge.h" |
15 #include "extensions/renderer/api_binding_hooks.h" | 16 #include "extensions/renderer/api_binding_hooks.h" |
16 #include "extensions/renderer/api_binding_js_util.h" | 17 #include "extensions/renderer/api_binding_js_util.h" |
17 #include "extensions/renderer/chrome_setting.h" | 18 #include "extensions/renderer/chrome_setting.h" |
18 #include "extensions/renderer/module_system.h" | 19 #include "extensions/renderer/module_system.h" |
19 #include "extensions/renderer/script_context.h" | 20 #include "extensions/renderer/script_context.h" |
20 #include "extensions/renderer/script_context_set.h" | 21 #include "extensions/renderer/script_context_set.h" |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 if (!success.IsJust() || !success.FromJust()) { | 440 if (!success.IsJust() || !success.FromJust()) { |
440 LOG(ERROR) << "Failed to create API on Chrome object."; | 441 LOG(ERROR) << "Failed to create API on Chrome object."; |
441 return; | 442 return; |
442 } | 443 } |
443 } | 444 } |
444 } | 445 } |
445 | 446 |
446 void NativeExtensionBindingsSystem::DispatchEventInContext( | 447 void NativeExtensionBindingsSystem::DispatchEventInContext( |
447 const std::string& event_name, | 448 const std::string& event_name, |
448 const base::ListValue* event_args, | 449 const base::ListValue* event_args, |
449 const base::DictionaryValue* filtering_info, | 450 const base::DictionaryValue* filtering_info_dict, |
450 ScriptContext* context) { | 451 ScriptContext* context) { |
451 v8::HandleScope handle_scope(context->isolate()); | 452 v8::HandleScope handle_scope(context->isolate()); |
452 v8::Context::Scope context_scope(context->v8_context()); | 453 v8::Context::Scope context_scope(context->v8_context()); |
453 // TODO(devlin): Take into account |filtering_info|. | 454 EventFilteringInfo filter; |
454 api_system_.FireEventInContext(event_name, context->v8_context(), | 455 if (filtering_info_dict) |
455 *event_args); | 456 filter = EventFilteringInfo(*filtering_info_dict); |
| 457 api_system_.FireEventInContext(event_name, context->v8_context(), *event_args, |
| 458 filter); |
456 } | 459 } |
457 | 460 |
458 void NativeExtensionBindingsSystem::HandleResponse( | 461 void NativeExtensionBindingsSystem::HandleResponse( |
459 int request_id, | 462 int request_id, |
460 bool success, | 463 bool success, |
461 const base::ListValue& response, | 464 const base::ListValue& response, |
462 const std::string& error) { | 465 const std::string& error) { |
463 api_system_.CompleteRequest(request_id, response, error); | 466 api_system_.CompleteRequest(request_id, response, error); |
464 } | 467 } |
465 | 468 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 // TODO(devlin): Make this work in ServiceWorkers. | 630 // TODO(devlin): Make this work in ServiceWorkers. |
628 params.worker_thread_id = -1; | 631 params.worker_thread_id = -1; |
629 params.service_worker_version_id = kInvalidServiceWorkerVersionId; | 632 params.service_worker_version_id = kInvalidServiceWorkerVersionId; |
630 | 633 |
631 send_request_ipc_.Run(script_context, params); | 634 send_request_ipc_.Run(script_context, params); |
632 } | 635 } |
633 | 636 |
634 void NativeExtensionBindingsSystem::OnEventListenerChanged( | 637 void NativeExtensionBindingsSystem::OnEventListenerChanged( |
635 const std::string& event_name, | 638 const std::string& event_name, |
636 binding::EventListenersChanged change, | 639 binding::EventListenersChanged change, |
| 640 const base::DictionaryValue* filter, |
637 v8::Local<v8::Context> context) { | 641 v8::Local<v8::Context> context) { |
638 send_event_listener_ipc_.Run( | 642 send_event_listener_ipc_.Run(change, |
639 change, ScriptContextSet::GetContextByV8Context(context), event_name); | 643 ScriptContextSet::GetContextByV8Context(context), |
| 644 event_name, filter); |
640 } | 645 } |
641 | 646 |
642 void NativeExtensionBindingsSystem::GetJSBindingUtil( | 647 void NativeExtensionBindingsSystem::GetJSBindingUtil( |
643 v8::Local<v8::Context> context, | 648 v8::Local<v8::Context> context, |
644 v8::Local<v8::Value>* binding_util_out) { | 649 v8::Local<v8::Value>* binding_util_out) { |
645 gin::Handle<APIBindingJSUtil> handle = | 650 gin::Handle<APIBindingJSUtil> handle = |
646 gin::CreateHandle(context->GetIsolate(), | 651 gin::CreateHandle(context->GetIsolate(), |
647 new APIBindingJSUtil(api_system_.type_reference_map(), | 652 new APIBindingJSUtil(api_system_.type_reference_map(), |
648 api_system_.request_handler(), | 653 api_system_.request_handler(), |
649 api_system_.event_handler())); | 654 api_system_.event_handler())); |
650 *binding_util_out = handle.ToV8(); | 655 *binding_util_out = handle.ToV8(); |
651 } | 656 } |
652 | 657 |
653 } // namespace extensions | 658 } // namespace extensions |
OLD | NEW |