Chromium Code Reviews| 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 | 248 |
| 249 void APIEventHandler::RegisterArgumentMassager( | 249 void APIEventHandler::RegisterArgumentMassager( |
| 250 v8::Local<v8::Context> context, | 250 v8::Local<v8::Context> context, |
| 251 const std::string& event_name, | 251 const std::string& event_name, |
| 252 v8::Local<v8::Function> massager) { | 252 v8::Local<v8::Function> massager) { |
| 253 APIEventPerContextData* data = GetContextData(context, true); | 253 APIEventPerContextData* data = GetContextData(context, true); |
| 254 DCHECK(data->massagers.find(event_name) == data->massagers.end()); | 254 DCHECK(data->massagers.find(event_name) == data->massagers.end()); |
| 255 data->massagers[event_name].Reset(context->GetIsolate(), massager); | 255 data->massagers[event_name].Reset(context->GetIsolate(), massager); |
| 256 } | 256 } |
| 257 | 257 |
| 258 bool APIEventHandler::HasListenerForEvent(const std::string& event_name, | |
| 259 v8::Local<v8::Context> context) { | |
| 260 APIEventPerContextData* data = GetContextData(context, false); | |
| 261 if (!data) | |
| 262 return false; | |
| 263 | |
| 264 auto iter = data->emitters.find(event_name); | |
| 265 if (iter == data->emitters.end()) | |
| 266 return false; | |
| 267 EventEmitter* emitter = nullptr; | |
| 268 gin::Converter<EventEmitter*>::FromV8( | |
| 269 context->GetIsolate(), iter->second.Get(context->GetIsolate()), &emitter); | |
| 270 CHECK(emitter); | |
| 271 return emitter->GetNumListeners() > 0; | |
|
lazyboy
2017/06/05 18:18:32
Given that we only care about EventEmitter::HasLis
Devlin
2017/06/09 20:18:01
Good thought. Since this patch is already a bit l
lazyboy
2017/06/10 00:09:05
Acknowledged.
| |
| 272 } | |
| 273 | |
| 258 void APIEventHandler::InvalidateContext(v8::Local<v8::Context> context) { | 274 void APIEventHandler::InvalidateContext(v8::Local<v8::Context> context) { |
| 259 gin::PerContextData* per_context_data = gin::PerContextData::From(context); | 275 gin::PerContextData* per_context_data = gin::PerContextData::From(context); |
| 260 DCHECK(per_context_data); | 276 DCHECK(per_context_data); |
| 261 APIEventPerContextData* data = static_cast<APIEventPerContextData*>( | 277 APIEventPerContextData* data = static_cast<APIEventPerContextData*>( |
| 262 per_context_data->GetUserData(kExtensionAPIEventPerContextKey)); | 278 per_context_data->GetUserData(kExtensionAPIEventPerContextKey)); |
| 263 if (!data) | 279 if (!data) |
| 264 return; | 280 return; |
| 265 | 281 |
| 266 v8::Isolate* isolate = context->GetIsolate(); | 282 v8::Isolate* isolate = context->GetIsolate(); |
| 267 v8::HandleScope scope(isolate); | 283 v8::HandleScope scope(isolate); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 auto iter = data->emitters.find(event_name); | 319 auto iter = data->emitters.find(event_name); |
| 304 DCHECK(iter != data->emitters.end()); | 320 DCHECK(iter != data->emitters.end()); |
| 305 EventEmitter* emitter = nullptr; | 321 EventEmitter* emitter = nullptr; |
| 306 gin::Converter<EventEmitter*>::FromV8( | 322 gin::Converter<EventEmitter*>::FromV8( |
| 307 context->GetIsolate(), iter->second.Get(context->GetIsolate()), &emitter); | 323 context->GetIsolate(), iter->second.Get(context->GetIsolate()), &emitter); |
| 308 CHECK(emitter); | 324 CHECK(emitter); |
| 309 return emitter->GetNumListeners(); | 325 return emitter->GetNumListeners(); |
| 310 } | 326 } |
| 311 | 327 |
| 312 } // namespace extensions | 328 } // namespace extensions |
| OLD | NEW |