| 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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 // object (including an array), other listeners will see that modification. | 212 // object (including an array), other listeners will see that modification. |
| 213 // TODO(devlin): This is how it's always been, but should it be? | 213 // TODO(devlin): This is how it's always been, but should it be? |
| 214 std::unique_ptr<content::V8ValueConverter> converter( | 214 std::unique_ptr<content::V8ValueConverter> converter( |
| 215 content::V8ValueConverter::create()); | 215 content::V8ValueConverter::create()); |
| 216 | 216 |
| 217 auto massager_iter = data->massagers.find(event_name); | 217 auto massager_iter = data->massagers.find(event_name); |
| 218 if (massager_iter == data->massagers.end()) { | 218 if (massager_iter == data->massagers.end()) { |
| 219 std::vector<v8::Local<v8::Value>> v8_args; | 219 std::vector<v8::Local<v8::Value>> v8_args; |
| 220 v8_args.reserve(args.GetSize()); | 220 v8_args.reserve(args.GetSize()); |
| 221 for (const auto& arg : args) | 221 for (const auto& arg : args) |
| 222 v8_args.push_back(converter->ToV8Value(arg.get(), context)); | 222 v8_args.push_back(converter->ToV8Value(&arg, context)); |
| 223 emitter->Fire(context, &v8_args, &filter); | 223 emitter->Fire(context, &v8_args, &filter); |
| 224 } else { | 224 } else { |
| 225 v8::Isolate* isolate = context->GetIsolate(); | 225 v8::Isolate* isolate = context->GetIsolate(); |
| 226 v8::HandleScope handle_scope(isolate); | 226 v8::HandleScope handle_scope(isolate); |
| 227 v8::Local<v8::Function> massager = massager_iter->second.Get(isolate); | 227 v8::Local<v8::Function> massager = massager_iter->second.Get(isolate); |
| 228 v8::Local<v8::Value> v8_args = converter->ToV8Value(&args, context); | 228 v8::Local<v8::Value> v8_args = converter->ToV8Value(&args, context); |
| 229 DCHECK(!v8_args.IsEmpty()); | 229 DCHECK(!v8_args.IsEmpty()); |
| 230 DCHECK(v8_args->IsArray()); | 230 DCHECK(v8_args->IsArray()); |
| 231 | 231 |
| 232 // Curry in the native dispatch function. Some argument massagers take | 232 // Curry in the native dispatch function. Some argument massagers take |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 auto iter = data->emitters.find(event_name); | 300 auto iter = data->emitters.find(event_name); |
| 301 DCHECK(iter != data->emitters.end()); | 301 DCHECK(iter != data->emitters.end()); |
| 302 EventEmitter* emitter = nullptr; | 302 EventEmitter* emitter = nullptr; |
| 303 gin::Converter<EventEmitter*>::FromV8( | 303 gin::Converter<EventEmitter*>::FromV8( |
| 304 context->GetIsolate(), iter->second.Get(context->GetIsolate()), &emitter); | 304 context->GetIsolate(), iter->second.Get(context->GetIsolate()), &emitter); |
| 305 CHECK(emitter); | 305 CHECK(emitter); |
| 306 return emitter->GetNumListeners(); | 306 return emitter->GetNumListeners(); |
| 307 } | 307 } |
| 308 | 308 |
| 309 } // namespace extensions | 309 } // namespace extensions |
| OLD | NEW |