| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/event_bindings.h" | 5 #include "extensions/renderer/event_bindings.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 ScriptContext* context) { | 211 ScriptContext* context) { |
| 212 v8::HandleScope handle_scope(context->isolate()); | 212 v8::HandleScope handle_scope(context->isolate()); |
| 213 v8::Context::Scope context_scope(context->v8_context()); | 213 v8::Context::Scope context_scope(context->v8_context()); |
| 214 | 214 |
| 215 v8::Local<v8::Array> listener_ids; | 215 v8::Local<v8::Array> listener_ids; |
| 216 if (filtering_info && !filtering_info->empty()) | 216 if (filtering_info && !filtering_info->empty()) |
| 217 listener_ids = GetMatchingListeners(context, event_name, *filtering_info); | 217 listener_ids = GetMatchingListeners(context, event_name, *filtering_info); |
| 218 else | 218 else |
| 219 listener_ids = v8::Array::New(context->isolate()); | 219 listener_ids = v8::Array::New(context->isolate()); |
| 220 | 220 |
| 221 std::unique_ptr<content::V8ValueConverter> converter( | |
| 222 content::V8ValueConverter::create()); | |
| 223 v8::Local<v8::Value> v8_args[] = { | 221 v8::Local<v8::Value> v8_args[] = { |
| 224 gin::StringToSymbol(context->isolate(), event_name), | 222 gin::StringToSymbol(context->isolate(), event_name), |
| 225 converter->ToV8Value(event_args, context->v8_context()), listener_ids, | 223 content::V8ValueConverter::Create()->ToV8Value(event_args, |
| 224 context->v8_context()), |
| 225 listener_ids, |
| 226 }; | 226 }; |
| 227 | 227 |
| 228 context->module_system()->CallModuleMethodSafe( | 228 context->module_system()->CallModuleMethodSafe( |
| 229 kEventBindings, "dispatchEvent", arraysize(v8_args), v8_args); | 229 kEventBindings, "dispatchEvent", arraysize(v8_args), v8_args); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void EventBindings::AttachEventHandler( | 232 void EventBindings::AttachEventHandler( |
| 233 const v8::FunctionCallbackInfo<v8::Value>& args) { | 233 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 234 CHECK_EQ(1, args.Length()); | 234 CHECK_EQ(1, args.Length()); |
| 235 CHECK(args[0]->IsString()); | 235 CHECK(args[0]->IsString()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 CHECK_EQ(2, args.Length()); | 315 CHECK_EQ(2, args.Length()); |
| 316 CHECK(args[0]->IsString()); | 316 CHECK(args[0]->IsString()); |
| 317 CHECK(args[1]->IsObject()); | 317 CHECK(args[1]->IsObject()); |
| 318 | 318 |
| 319 std::string event_name = *v8::String::Utf8Value(args[0]); | 319 std::string event_name = *v8::String::Utf8Value(args[0]); |
| 320 if (!context()->HasAccessOrThrowError(event_name)) | 320 if (!context()->HasAccessOrThrowError(event_name)) |
| 321 return; | 321 return; |
| 322 | 322 |
| 323 std::unique_ptr<base::DictionaryValue> filter; | 323 std::unique_ptr<base::DictionaryValue> filter; |
| 324 { | 324 { |
| 325 std::unique_ptr<content::V8ValueConverter> converter( | 325 std::unique_ptr<base::Value> filter_value = |
| 326 content::V8ValueConverter::create()); | 326 content::V8ValueConverter::Create()->FromV8Value( |
| 327 std::unique_ptr<base::Value> filter_value(converter->FromV8Value( | 327 v8::Local<v8::Object>::Cast(args[1]), context()->v8_context()); |
| 328 v8::Local<v8::Object>::Cast(args[1]), context()->v8_context())); | |
| 329 if (!filter_value || !filter_value->IsType(base::Value::Type::DICTIONARY)) { | 328 if (!filter_value || !filter_value->IsType(base::Value::Type::DICTIONARY)) { |
| 330 args.GetReturnValue().Set(static_cast<int32_t>(-1)); | 329 args.GetReturnValue().Set(static_cast<int32_t>(-1)); |
| 331 return; | 330 return; |
| 332 } | 331 } |
| 333 filter = base::DictionaryValue::From(std::move(filter_value)); | 332 filter = base::DictionaryValue::From(std::move(filter_value)); |
| 334 } | 333 } |
| 335 | 334 |
| 336 int id = g_event_filter.Get().AddEventMatcher( | 335 int id = g_event_filter.Get().AddEventMatcher( |
| 337 event_name, ParseEventMatcher(std::move(filter))); | 336 event_name, ParseEventMatcher(std::move(filter))); |
| 338 if (id == -1) { | 337 if (id == -1) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 for (int matcher_id : attached_matcher_ids_safe) { | 433 for (int matcher_id : attached_matcher_ids_safe) { |
| 435 DetachFilteredEvent(matcher_id, false /* is_manual */); | 434 DetachFilteredEvent(matcher_id, false /* is_manual */); |
| 436 } | 435 } |
| 437 DCHECK(attached_matcher_ids_.empty()) | 436 DCHECK(attached_matcher_ids_.empty()) |
| 438 << "Filtered events cannot be attached during invalidation"; | 437 << "Filtered events cannot be attached during invalidation"; |
| 439 | 438 |
| 440 g_unmanaged_listeners.Get().erase(context()); | 439 g_unmanaged_listeners.Get().erase(context()); |
| 441 } | 440 } |
| 442 | 441 |
| 443 } // namespace extensions | 442 } // namespace extensions |
| OLD | NEW |