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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 content::V8ValueConverter::create()); | 265 content::V8ValueConverter::create()); |
266 std::unique_ptr<base::Value> filter_value(converter->FromV8Value( | 266 std::unique_ptr<base::Value> filter_value(converter->FromV8Value( |
267 v8::Local<v8::Object>::Cast(args[1]), context()->v8_context())); | 267 v8::Local<v8::Object>::Cast(args[1]), context()->v8_context())); |
268 if (!filter_value || !filter_value->IsType(base::Value::TYPE_DICTIONARY)) { | 268 if (!filter_value || !filter_value->IsType(base::Value::TYPE_DICTIONARY)) { |
269 args.GetReturnValue().Set(static_cast<int32_t>(-1)); | 269 args.GetReturnValue().Set(static_cast<int32_t>(-1)); |
270 return; | 270 return; |
271 } | 271 } |
272 filter = base::DictionaryValue::From(std::move(filter_value)); | 272 filter = base::DictionaryValue::From(std::move(filter_value)); |
273 } | 273 } |
274 | 274 |
275 // Hold onto a weak reference to |filter| so that it can be used after passing | |
276 // ownership to |event_filter|. | |
277 base::DictionaryValue* filter_weak = filter.get(); | |
278 int id = g_event_filter.Get().AddEventMatcher( | 275 int id = g_event_filter.Get().AddEventMatcher( |
279 event_name, ParseEventMatcher(std::move(filter))); | 276 event_name, ParseEventMatcher(std::move(filter))); |
277 if (id == -1) { | |
278 args.GetReturnValue().Set(static_cast<int32_t>(-1)); | |
279 return; | |
280 } | |
280 attached_matcher_ids_.insert(id); | 281 attached_matcher_ids_.insert(id); |
281 | 282 |
282 // Only send IPCs the first time a filter gets added. | 283 // Only send IPCs the first time a filter gets added. |
284 base::DictionaryValue* filter_weak = | |
285 g_event_filter.Get().GetEventMatcher(id)->value(); | |
Devlin
2016/08/11 21:57:39
I wonder if we should also DCHECK that we get an E
meacer
2016/08/11 22:04:28
Done.
| |
283 std::string extension_id = context()->GetExtensionID(); | 286 std::string extension_id = context()->GetExtensionID(); |
284 if (AddFilter(event_name, extension_id, *filter_weak)) { | 287 if (AddFilter(event_name, extension_id, *filter_weak)) { |
285 bool lazy = ExtensionFrameHelper::IsContextForEventPage(context()); | 288 bool lazy = ExtensionFrameHelper::IsContextForEventPage(context()); |
286 content::RenderThread::Get()->Send(new ExtensionHostMsg_AddFilteredListener( | 289 content::RenderThread::Get()->Send(new ExtensionHostMsg_AddFilteredListener( |
287 extension_id, event_name, *filter_weak, lazy)); | 290 extension_id, event_name, *filter_weak, lazy)); |
288 } | 291 } |
289 | 292 |
290 args.GetReturnValue().Set(static_cast<int32_t>(id)); | 293 args.GetReturnValue().Set(static_cast<int32_t>(id)); |
291 } | 294 } |
292 | 295 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 // Same for filtered events. | 363 // Same for filtered events. |
361 std::set<int> attached_matcher_ids_safe = attached_matcher_ids_; | 364 std::set<int> attached_matcher_ids_safe = attached_matcher_ids_; |
362 for (int matcher_id : attached_matcher_ids_safe) { | 365 for (int matcher_id : attached_matcher_ids_safe) { |
363 DetachFilteredEvent(matcher_id, false /* is_manual */); | 366 DetachFilteredEvent(matcher_id, false /* is_manual */); |
364 } | 367 } |
365 DCHECK(attached_matcher_ids_.empty()) | 368 DCHECK(attached_matcher_ids_.empty()) |
366 << "Filtered events cannot be attached during invalidation"; | 369 << "Filtered events cannot be attached during invalidation"; |
367 } | 370 } |
368 | 371 |
369 } // namespace extensions | 372 } // namespace extensions |
OLD | NEW |