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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | 275 // Hold onto a weak reference to |filter| so that it can be used after passing |
276 // ownership to |event_filter|. | 276 // ownership to |event_filter|. |
277 base::DictionaryValue* filter_weak = filter.get(); | 277 base::DictionaryValue* filter_weak = filter.get(); |
Devlin
2016/08/11 19:08:12
This makes me sad, because there's an awful lot of
meacer
2016/08/11 21:53:00
Done. It seems safe to do this, but I wonder if I
Devlin
2016/08/11 21:57:39
I wouldn't be opposed to a DCHECK, if you want to
meacer
2016/08/11 22:04:27
On second thought this seemed overkill so decided
| |
278 int id = g_event_filter.Get().AddEventMatcher( | 278 int id = g_event_filter.Get().AddEventMatcher( |
279 event_name, ParseEventMatcher(std::move(filter))); | 279 event_name, ParseEventMatcher(std::move(filter))); |
280 if (id == -1) | |
281 return; | |
Devlin
2016/08/11 19:08:12
It looks like other places this fails, we return -
meacer
2016/08/11 21:53:00
Line 259 doesn't set it to -1. Should I add it the
Devlin
2016/08/11 21:57:39
I think line 259 throws an error if it fails, so w
meacer
2016/08/11 22:04:27
Ah, okay didn't read it well.
| |
280 attached_matcher_ids_.insert(id); | 282 attached_matcher_ids_.insert(id); |
281 | 283 |
282 // Only send IPCs the first time a filter gets added. | 284 // Only send IPCs the first time a filter gets added. |
283 std::string extension_id = context()->GetExtensionID(); | 285 std::string extension_id = context()->GetExtensionID(); |
284 if (AddFilter(event_name, extension_id, *filter_weak)) { | 286 if (AddFilter(event_name, extension_id, *filter_weak)) { |
285 bool lazy = ExtensionFrameHelper::IsContextForEventPage(context()); | 287 bool lazy = ExtensionFrameHelper::IsContextForEventPage(context()); |
286 content::RenderThread::Get()->Send(new ExtensionHostMsg_AddFilteredListener( | 288 content::RenderThread::Get()->Send(new ExtensionHostMsg_AddFilteredListener( |
287 extension_id, event_name, *filter_weak, lazy)); | 289 extension_id, event_name, *filter_weak, lazy)); |
288 } | 290 } |
289 | 291 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 // Same for filtered events. | 362 // Same for filtered events. |
361 std::set<int> attached_matcher_ids_safe = attached_matcher_ids_; | 363 std::set<int> attached_matcher_ids_safe = attached_matcher_ids_; |
362 for (int matcher_id : attached_matcher_ids_safe) { | 364 for (int matcher_id : attached_matcher_ids_safe) { |
363 DetachFilteredEvent(matcher_id, false /* is_manual */); | 365 DetachFilteredEvent(matcher_id, false /* is_manual */); |
364 } | 366 } |
365 DCHECK(attached_matcher_ids_.empty()) | 367 DCHECK(attached_matcher_ids_.empty()) |
366 << "Filtered events cannot be attached during invalidation"; | 368 << "Filtered events cannot be attached during invalidation"; |
367 } | 369 } |
368 | 370 |
369 } // namespace extensions | 371 } // namespace extensions |
OLD | NEW |