| 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/api_event_handler.h" | 5 #include "extensions/renderer/api_event_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 APIEventHandler::APIEventHandler( | 109 APIEventHandler::APIEventHandler( |
| 110 const binding::RunJSFunction& call_js, | 110 const binding::RunJSFunction& call_js, |
| 111 const EventListenersChangedMethod& listeners_changed) | 111 const EventListenersChangedMethod& listeners_changed) |
| 112 : call_js_(call_js), listeners_changed_(listeners_changed) {} | 112 : call_js_(call_js), listeners_changed_(listeners_changed) {} |
| 113 APIEventHandler::~APIEventHandler() {} | 113 APIEventHandler::~APIEventHandler() {} |
| 114 | 114 |
| 115 v8::Local<v8::Object> APIEventHandler::CreateEventInstance( | 115 v8::Local<v8::Object> APIEventHandler::CreateEventInstance( |
| 116 const std::string& event_name, | 116 const std::string& event_name, |
| 117 bool supports_filters, | 117 bool supports_filters, |
| 118 int max_listeners, | 118 int max_listeners, |
| 119 bool notify_on_change, |
| 119 v8::Local<v8::Context> context) { | 120 v8::Local<v8::Context> context) { |
| 120 // We need a context scope since gin::CreateHandle only takes the isolate | 121 // We need a context scope since gin::CreateHandle only takes the isolate |
| 121 // and infers the context from that. | 122 // and infers the context from that. |
| 122 // TODO(devlin): This could be avoided if gin::CreateHandle could take a | 123 // TODO(devlin): This could be avoided if gin::CreateHandle could take a |
| 123 // context directly. | 124 // context directly. |
| 124 v8::Context::Scope context_scope(context); | 125 v8::Context::Scope context_scope(context); |
| 125 | 126 |
| 126 APIEventPerContextData* data = GetContextData(context, true); | 127 APIEventPerContextData* data = GetContextData(context, true); |
| 127 DCHECK(data->emitters.find(event_name) == data->emitters.end()); | 128 DCHECK(data->emitters.find(event_name) == data->emitters.end()); |
| 128 | 129 |
| 129 APIEventListeners::ListenersUpdated updated = | 130 APIEventListeners::ListenersUpdated updated = |
| 130 base::Bind(listeners_changed_, event_name); | 131 notify_on_change ? base::Bind(listeners_changed_, event_name) |
| 132 : base::Bind(&DoNothingOnListenersChanged); |
| 131 std::unique_ptr<APIEventListeners> listeners; | 133 std::unique_ptr<APIEventListeners> listeners; |
| 132 if (supports_filters) { | 134 if (supports_filters) { |
| 133 listeners = base::MakeUnique<FilteredEventListeners>( | 135 listeners = base::MakeUnique<FilteredEventListeners>( |
| 134 updated, event_name, max_listeners, &event_filter_); | 136 updated, event_name, max_listeners, &event_filter_); |
| 135 } else { | 137 } else { |
| 136 listeners = | 138 listeners = |
| 137 base::MakeUnique<UnfilteredEventListeners>(updated, max_listeners); | 139 base::MakeUnique<UnfilteredEventListeners>(updated, max_listeners); |
| 138 } | 140 } |
| 139 | 141 |
| 140 gin::Handle<EventEmitter> emitter_handle = gin::CreateHandle( | 142 gin::Handle<EventEmitter> emitter_handle = gin::CreateHandle( |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 auto iter = data->emitters.find(event_name); | 305 auto iter = data->emitters.find(event_name); |
| 304 DCHECK(iter != data->emitters.end()); | 306 DCHECK(iter != data->emitters.end()); |
| 305 EventEmitter* emitter = nullptr; | 307 EventEmitter* emitter = nullptr; |
| 306 gin::Converter<EventEmitter*>::FromV8( | 308 gin::Converter<EventEmitter*>::FromV8( |
| 307 context->GetIsolate(), iter->second.Get(context->GetIsolate()), &emitter); | 309 context->GetIsolate(), iter->second.Get(context->GetIsolate()), &emitter); |
| 308 CHECK(emitter); | 310 CHECK(emitter); |
| 309 return emitter->GetNumListeners(); | 311 return emitter->GetNumListeners(); |
| 310 } | 312 } |
| 311 | 313 |
| 312 } // namespace extensions | 314 } // namespace extensions |
| OLD | NEW |