| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 250 |
| 251 void APIEventHandler::RegisterArgumentMassager( | 251 void APIEventHandler::RegisterArgumentMassager( |
| 252 v8::Local<v8::Context> context, | 252 v8::Local<v8::Context> context, |
| 253 const std::string& event_name, | 253 const std::string& event_name, |
| 254 v8::Local<v8::Function> massager) { | 254 v8::Local<v8::Function> massager) { |
| 255 APIEventPerContextData* data = GetContextData(context, true); | 255 APIEventPerContextData* data = GetContextData(context, true); |
| 256 DCHECK(data->massagers.find(event_name) == data->massagers.end()); | 256 DCHECK(data->massagers.find(event_name) == data->massagers.end()); |
| 257 data->massagers[event_name].Reset(context->GetIsolate(), massager); | 257 data->massagers[event_name].Reset(context->GetIsolate(), massager); |
| 258 } | 258 } |
| 259 | 259 |
| 260 bool APIEventHandler::HasListenerForEvent(const std::string& event_name, |
| 261 v8::Local<v8::Context> context) { |
| 262 APIEventPerContextData* data = GetContextData(context, false); |
| 263 if (!data) |
| 264 return false; |
| 265 |
| 266 auto iter = data->emitters.find(event_name); |
| 267 if (iter == data->emitters.end()) |
| 268 return false; |
| 269 EventEmitter* emitter = nullptr; |
| 270 gin::Converter<EventEmitter*>::FromV8( |
| 271 context->GetIsolate(), iter->second.Get(context->GetIsolate()), &emitter); |
| 272 CHECK(emitter); |
| 273 return emitter->GetNumListeners() > 0; |
| 274 } |
| 275 |
| 260 void APIEventHandler::InvalidateContext(v8::Local<v8::Context> context) { | 276 void APIEventHandler::InvalidateContext(v8::Local<v8::Context> context) { |
| 261 gin::PerContextData* per_context_data = gin::PerContextData::From(context); | 277 gin::PerContextData* per_context_data = gin::PerContextData::From(context); |
| 262 DCHECK(per_context_data); | 278 DCHECK(per_context_data); |
| 263 APIEventPerContextData* data = static_cast<APIEventPerContextData*>( | 279 APIEventPerContextData* data = static_cast<APIEventPerContextData*>( |
| 264 per_context_data->GetUserData(kExtensionAPIEventPerContextKey)); | 280 per_context_data->GetUserData(kExtensionAPIEventPerContextKey)); |
| 265 if (!data) | 281 if (!data) |
| 266 return; | 282 return; |
| 267 | 283 |
| 268 v8::Isolate* isolate = context->GetIsolate(); | 284 v8::Isolate* isolate = context->GetIsolate(); |
| 269 v8::HandleScope scope(isolate); | 285 v8::HandleScope scope(isolate); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 auto iter = data->emitters.find(event_name); | 321 auto iter = data->emitters.find(event_name); |
| 306 DCHECK(iter != data->emitters.end()); | 322 DCHECK(iter != data->emitters.end()); |
| 307 EventEmitter* emitter = nullptr; | 323 EventEmitter* emitter = nullptr; |
| 308 gin::Converter<EventEmitter*>::FromV8( | 324 gin::Converter<EventEmitter*>::FromV8( |
| 309 context->GetIsolate(), iter->second.Get(context->GetIsolate()), &emitter); | 325 context->GetIsolate(), iter->second.Get(context->GetIsolate()), &emitter); |
| 310 CHECK(emitter); | 326 CHECK(emitter); |
| 311 return emitter->GetNumListeners(); | 327 return emitter->GetNumListeners(); |
| 312 } | 328 } |
| 313 | 329 |
| 314 } // namespace extensions | 330 } // namespace extensions |
| OLD | NEW |