| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 if (counts->second->Remove(*filter)) { | 121 if (counts->second->Remove(*filter)) { |
| 122 if (counts->second->is_empty()) | 122 if (counts->second->is_empty()) |
| 123 all_counts.erase(counts); // Clean up if there are no more filters. | 123 all_counts.erase(counts); // Clean up if there are no more filters. |
| 124 return true; | 124 return true; |
| 125 } | 125 } |
| 126 return false; | 126 return false; |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Returns a v8::Array containing the ids of the listeners that match the given | 129 // Returns a v8::Array containing the ids of the listeners that match the given |
| 130 // |event_filter_dict| in the given |script_context|. | 130 // |event_filter_dict| in the given |script_context|. |
| 131 v8::Local<v8::Array> GetMatchingListeners( | 131 v8::Local<v8::Array> GetMatchingListeners(ScriptContext* script_context, |
| 132 ScriptContext* script_context, | 132 const std::string& event_name, |
| 133 const std::string& event_name, | 133 const EventFilteringInfo& info) { |
| 134 const base::DictionaryValue& event_filter_dict) { | |
| 135 const EventFilter& event_filter = g_event_filter.Get(); | 134 const EventFilter& event_filter = g_event_filter.Get(); |
| 136 EventFilteringInfo info(event_filter_dict); | |
| 137 v8::Isolate* isolate = script_context->isolate(); | 135 v8::Isolate* isolate = script_context->isolate(); |
| 138 v8::Local<v8::Context> context = script_context->v8_context(); | 136 v8::Local<v8::Context> context = script_context->v8_context(); |
| 139 | 137 |
| 140 // Only match events routed to this context's RenderFrame or ones that don't | 138 // Only match events routed to this context's RenderFrame or ones that don't |
| 141 // have a routingId in their filter. | 139 // have a routingId in their filter. |
| 142 std::set<EventFilter::MatcherID> matched_event_filters = | 140 std::set<EventFilter::MatcherID> matched_event_filters = |
| 143 event_filter.MatchEvent(event_name, info, | 141 event_filter.MatchEvent(event_name, info, |
| 144 script_context->GetRenderFrame()->GetRoutingID()); | 142 script_context->GetRenderFrame()->GetRoutingID()); |
| 145 v8::Local<v8::Array> array( | 143 v8::Local<v8::Array> array( |
| 146 v8::Array::New(isolate, matched_event_filters.size())); | 144 v8::Array::New(isolate, matched_event_filters.size())); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 198 } |
| 201 } | 199 } |
| 202 | 200 |
| 203 return false; | 201 return false; |
| 204 } | 202 } |
| 205 | 203 |
| 206 // static | 204 // static |
| 207 void EventBindings::DispatchEventInContext( | 205 void EventBindings::DispatchEventInContext( |
| 208 const std::string& event_name, | 206 const std::string& event_name, |
| 209 const base::ListValue* event_args, | 207 const base::ListValue* event_args, |
| 210 const base::DictionaryValue* filtering_info, | 208 const EventFilteringInfo* filtering_info, |
| 211 ScriptContext* context) { | 209 ScriptContext* context) { |
| 212 v8::HandleScope handle_scope(context->isolate()); | 210 v8::HandleScope handle_scope(context->isolate()); |
| 213 v8::Context::Scope context_scope(context->v8_context()); | 211 v8::Context::Scope context_scope(context->v8_context()); |
| 214 | 212 |
| 215 v8::Local<v8::Array> listener_ids; | 213 v8::Local<v8::Array> listener_ids; |
| 216 if (filtering_info && !filtering_info->empty()) | 214 if (filtering_info && !filtering_info->is_empty()) |
| 217 listener_ids = GetMatchingListeners(context, event_name, *filtering_info); | 215 listener_ids = GetMatchingListeners(context, event_name, *filtering_info); |
| 218 else | 216 else |
| 219 listener_ids = v8::Array::New(context->isolate()); | 217 listener_ids = v8::Array::New(context->isolate()); |
| 220 | 218 |
| 221 v8::Local<v8::Value> v8_args[] = { | 219 v8::Local<v8::Value> v8_args[] = { |
| 222 gin::StringToSymbol(context->isolate(), event_name), | 220 gin::StringToSymbol(context->isolate(), event_name), |
| 223 content::V8ValueConverter::Create()->ToV8Value(event_args, | 221 content::V8ValueConverter::Create()->ToV8Value(event_args, |
| 224 context->v8_context()), | 222 context->v8_context()), |
| 225 listener_ids, | 223 listener_ids, |
| 226 }; | 224 }; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 for (int matcher_id : attached_matcher_ids_safe) { | 427 for (int matcher_id : attached_matcher_ids_safe) { |
| 430 DetachFilteredEvent(matcher_id, false /* is_manual */); | 428 DetachFilteredEvent(matcher_id, false /* is_manual */); |
| 431 } | 429 } |
| 432 DCHECK(attached_matcher_ids_.empty()) | 430 DCHECK(attached_matcher_ids_.empty()) |
| 433 << "Filtered events cannot be attached during invalidation"; | 431 << "Filtered events cannot be attached during invalidation"; |
| 434 | 432 |
| 435 g_unmanaged_listeners.Get().erase(context()); | 433 g_unmanaged_listeners.Get().erase(context()); |
| 436 } | 434 } |
| 437 | 435 |
| 438 } // namespace extensions | 436 } // namespace extensions |
| OLD | NEW |