Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Side by Side Diff: extensions/renderer/api_binding.cc

Issue 2768093002: [Reland][Extensions Bindings] Add support for filtered events (Closed)
Patch Set: Fix Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/renderer/BUILD.gn ('k') | extensions/renderer/api_binding_js_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_binding.h" 5 #include "extensions/renderer/api_binding.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 std::string full_name; 83 std::string full_name;
84 // The expected API signature. 84 // The expected API signature.
85 const APISignature* signature; 85 const APISignature* signature;
86 // The callback used by the v8 function. 86 // The callback used by the v8 function.
87 APIBinding::HandlerCallback callback; 87 APIBinding::HandlerCallback callback;
88 }; 88 };
89 89
90 struct APIBinding::EventData { 90 struct APIBinding::EventData {
91 EventData(std::string exposed_name, 91 EventData(std::string exposed_name,
92 std::string full_name, 92 std::string full_name,
93 bool supports_filters,
93 APIEventHandler* event_handler) 94 APIEventHandler* event_handler)
94 : exposed_name(std::move(exposed_name)), 95 : exposed_name(std::move(exposed_name)),
95 full_name(std::move(full_name)), 96 full_name(std::move(full_name)),
97 supports_filters(supports_filters),
96 event_handler(event_handler) {} 98 event_handler(event_handler) {}
97 99
98 // The name of the event on the API object (e.g. onCreated). 100 // The name of the event on the API object (e.g. onCreated).
99 std::string exposed_name; 101 std::string exposed_name;
100 // The fully-specified name of the event (e.g. tabs.onCreated). 102 // The fully-specified name of the event (e.g. tabs.onCreated).
101 std::string full_name; 103 std::string full_name;
104 // Whether the event supports filters.
105 bool supports_filters;
102 // The associated event handler. This raw pointer is safe because the 106 // The associated event handler. This raw pointer is safe because the
103 // EventData is only accessed from the callbacks associated with the 107 // EventData is only accessed from the callbacks associated with the
104 // APIBinding, and both the APIBinding and APIEventHandler are owned by the 108 // APIBinding, and both the APIBinding and APIEventHandler are owned by the
105 // same object (the APIBindingsSystem). 109 // same object (the APIBindingsSystem).
106 APIEventHandler* event_handler; 110 APIEventHandler* event_handler;
107 }; 111 };
108 112
109 struct APIBinding::CustomPropertyData { 113 struct APIBinding::CustomPropertyData {
110 CustomPropertyData(const std::string& type_name, 114 CustomPropertyData(const std::string& type_name,
111 const std::string& property_name, 115 const std::string& property_name,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 211
208 if (event_definitions) { 212 if (event_definitions) {
209 events_.reserve(event_definitions->GetSize()); 213 events_.reserve(event_definitions->GetSize());
210 for (const auto& event : *event_definitions) { 214 for (const auto& event : *event_definitions) {
211 const base::DictionaryValue* event_dict = nullptr; 215 const base::DictionaryValue* event_dict = nullptr;
212 CHECK(event->GetAsDictionary(&event_dict)); 216 CHECK(event->GetAsDictionary(&event_dict));
213 std::string name; 217 std::string name;
214 CHECK(event_dict->GetString("name", &name)); 218 CHECK(event_dict->GetString("name", &name));
215 std::string full_name = 219 std::string full_name =
216 base::StringPrintf("%s.%s", api_name_.c_str(), name.c_str()); 220 base::StringPrintf("%s.%s", api_name_.c_str(), name.c_str());
217 events_.push_back(base::MakeUnique<EventData>( 221 const base::ListValue* filters = nullptr;
218 std::move(name), std::move(full_name), event_handler)); 222 bool supports_filters =
223 event_dict->GetList("filters", &filters) && !filters->empty();
224 events_.push_back(
225 base::MakeUnique<EventData>(std::move(name), std::move(full_name),
226 supports_filters, event_handler));
219 } 227 }
220 } 228 }
221 } 229 }
222 230
223 APIBinding::~APIBinding() {} 231 APIBinding::~APIBinding() {}
224 232
225 v8::Local<v8::Object> APIBinding::CreateInstance( 233 v8::Local<v8::Object> APIBinding::CreateInstance(
226 v8::Local<v8::Context> context, 234 v8::Local<v8::Context> context,
227 v8::Isolate* isolate, 235 v8::Isolate* isolate,
228 const AvailabilityCallback& is_available) { 236 const AvailabilityCallback& is_available) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 v8::Isolate* isolate = info.GetIsolate(); 376 v8::Isolate* isolate = info.GetIsolate();
369 v8::HandleScope handle_scope(isolate); 377 v8::HandleScope handle_scope(isolate);
370 v8::Local<v8::Context> context = info.Holder()->CreationContext(); 378 v8::Local<v8::Context> context = info.Holder()->CreationContext();
371 if (!IsContextValid(context)) 379 if (!IsContextValid(context))
372 return; 380 return;
373 381
374 CHECK(info.Data()->IsExternal()); 382 CHECK(info.Data()->IsExternal());
375 auto* event_data = 383 auto* event_data =
376 static_cast<EventData*>(info.Data().As<v8::External>()->Value()); 384 static_cast<EventData*>(info.Data().As<v8::External>()->Value());
377 info.GetReturnValue().Set(event_data->event_handler->CreateEventInstance( 385 info.GetReturnValue().Set(event_data->event_handler->CreateEventInstance(
378 event_data->full_name, context)); 386 event_data->full_name, event_data->supports_filters, context));
379 } 387 }
380 388
381 void APIBinding::GetCustomPropertyObject( 389 void APIBinding::GetCustomPropertyObject(
382 v8::Local<v8::Name> property_name, 390 v8::Local<v8::Name> property_name,
383 const v8::PropertyCallbackInfo<v8::Value>& info) { 391 const v8::PropertyCallbackInfo<v8::Value>& info) {
384 v8::Isolate* isolate = info.GetIsolate(); 392 v8::Isolate* isolate = info.GetIsolate();
385 v8::HandleScope handle_scope(isolate); 393 v8::HandleScope handle_scope(isolate);
386 v8::Local<v8::Context> context = info.Holder()->CreationContext(); 394 v8::Local<v8::Context> context = info.Holder()->CreationContext();
387 if (!IsContextValid(context)) 395 if (!IsContextValid(context))
388 return; 396 return;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 if (invalid_invocation) { 471 if (invalid_invocation) {
464 arguments->ThrowTypeError("Invalid invocation"); 472 arguments->ThrowTypeError("Invalid invocation");
465 return; 473 return;
466 } 474 }
467 475
468 request_handler_->StartRequest(context, name, std::move(converted_arguments), 476 request_handler_->StartRequest(context, name, std::move(converted_arguments),
469 callback, custom_callback); 477 callback, custom_callback);
470 } 478 }
471 479
472 } // namespace extensions 480 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/BUILD.gn ('k') | extensions/renderer/api_binding_js_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698