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

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

Issue 2610743002: [Extensions Bindings] Make function definitions optional for an API. (Closed)
Patch Set: api_binding_unittest Created 3 years, 11 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
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 return live_callback.get() == callback; 57 return live_callback.get() == callback;
58 })); 58 }));
59 #endif // DCHECK_IS_ON() 59 #endif // DCHECK_IS_ON()
60 60
61 callback->Run(&args); 61 callback->Run(&args);
62 } 62 }
63 63
64 } // namespace 64 } // namespace
65 65
66 APIBinding::APIBinding(const std::string& api_name, 66 APIBinding::APIBinding(const std::string& api_name,
67 const base::ListValue& function_definitions, 67 const base::ListValue* function_definitions,
68 const base::ListValue* type_definitions, 68 const base::ListValue* type_definitions,
69 const base::ListValue* event_definitions, 69 const base::ListValue* event_definitions,
70 const APIMethodCallback& callback, 70 const APIMethodCallback& callback,
71 std::unique_ptr<APIBindingHooks> binding_hooks, 71 std::unique_ptr<APIBindingHooks> binding_hooks,
72 ArgumentSpec::RefMap* type_refs) 72 ArgumentSpec::RefMap* type_refs)
73 : api_name_(api_name), 73 : api_name_(api_name),
74 method_callback_(callback), 74 method_callback_(callback),
75 binding_hooks_(std::move(binding_hooks)), 75 binding_hooks_(std::move(binding_hooks)),
76 type_refs_(type_refs), 76 type_refs_(type_refs),
77 weak_factory_(this) { 77 weak_factory_(this) {
78 DCHECK(!method_callback_.is_null()); 78 DCHECK(!method_callback_.is_null());
79 for (const auto& func : function_definitions) { 79 if (function_definitions) {
80 const base::DictionaryValue* func_dict = nullptr; 80 for (const auto& func : *function_definitions) {
81 CHECK(func->GetAsDictionary(&func_dict)); 81 const base::DictionaryValue* func_dict = nullptr;
82 std::string name; 82 CHECK(func->GetAsDictionary(&func_dict));
83 CHECK(func_dict->GetString("name", &name)); 83 std::string name;
84 CHECK(func_dict->GetString("name", &name));
84 85
85 const base::ListValue* params = nullptr; 86 const base::ListValue* params = nullptr;
86 CHECK(func_dict->GetList("parameters", &params)); 87 CHECK(func_dict->GetList("parameters", &params));
87 signatures_[name] = base::MakeUnique<APISignature>(*params); 88 signatures_[name] = base::MakeUnique<APISignature>(*params);
89 }
88 } 90 }
89 if (type_definitions) { 91 if (type_definitions) {
90 for (const auto& type : *type_definitions) { 92 for (const auto& type : *type_definitions) {
91 const base::DictionaryValue* type_dict = nullptr; 93 const base::DictionaryValue* type_dict = nullptr;
92 CHECK(type->GetAsDictionary(&type_dict)); 94 CHECK(type->GetAsDictionary(&type_dict));
93 std::string id; 95 std::string id;
94 CHECK(type_dict->GetString("id", &id)); 96 CHECK(type_dict->GetString("id", &id));
95 DCHECK(type_refs->find(id) == type_refs->end()); 97 DCHECK(type_refs->find(id) == type_refs->end());
96 // TODO(devlin): refs are sometimes preceeded by the API namespace; we 98 // TODO(devlin): refs are sometimes preceeded by the API namespace; we
97 // might need to take that into account. 99 // might need to take that into account.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 arguments->ThrowTypeError("Invalid invocation"); 223 arguments->ThrowTypeError("Invalid invocation");
222 return; 224 return;
223 } 225 }
224 226
225 DCHECK(converted_arguments); 227 DCHECK(converted_arguments);
226 method_callback_.Run(name, std::move(converted_arguments), isolate, context, 228 method_callback_.Run(name, std::move(converted_arguments), isolate, context,
227 callback); 229 callback);
228 } 230 }
229 231
230 } // namespace extensions 232 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698