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