summaryrefslogtreecommitdiff
path: root/chromium/extensions/renderer/bindings/api_binding.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/extensions/renderer/bindings/api_binding.cc')
-rw-r--r--chromium/extensions/renderer/bindings/api_binding.cc31
1 files changed, 21 insertions, 10 deletions
diff --git a/chromium/extensions/renderer/bindings/api_binding.cc b/chromium/extensions/renderer/bindings/api_binding.cc
index 16c3ef8b279..322d32c7b88 100644
--- a/chromium/extensions/renderer/bindings/api_binding.cc
+++ b/chromium/extensions/renderer/bindings/api_binding.cc
@@ -65,24 +65,32 @@ struct SignaturePair {
std::unique_ptr<APISignature> callback_signature;
};
-SignaturePair GetAPISignatureFromDictionary(const base::DictionaryValue* dict) {
- const base::ListValue* params = nullptr;
- CHECK(dict->GetList("parameters", &params));
+SignaturePair GetAPISignatureFromDictionary(const base::Value* dict) {
+ const base::Value* params =
+ dict->FindKeyOfType("parameters", base::Value::Type::LIST);
+ CHECK(params);
- bool supports_promises = false;
- dict->GetBoolean("supportsPromises", &supports_promises);
+ // The inclusion of the "returns_async" property indicates that an API
+ // supports promises.
+ const base::Value* returns_async =
+ dict->FindKeyOfType("returns_async", base::Value::Type::DICTIONARY);
SignaturePair result;
- result.method_signature = std::make_unique<APISignature>(*params);
+ result.method_signature =
+ std::make_unique<APISignature>(*params, returns_async);
result.method_signature->set_promise_support(
- supports_promises ? binding::PromiseSupport::kAllowed
- : binding::PromiseSupport::kDisallowed);
+ returns_async && APIBinding::enable_promise_support_for_testing
+ ? binding::PromiseSupport::kAllowed
+ : binding::PromiseSupport::kDisallowed);
// If response validation is enabled, parse the callback signature. Otherwise,
// there's no reason to, so don't bother.
if (result.method_signature->has_callback() &&
binding::IsResponseValidationEnabled()) {
- const base::Value* callback_params = params->GetList().back().FindKeyOfType(
- "parameters", base::Value::Type::LIST);
+ const base::Value* callback_params =
+ returns_async ? returns_async->FindKeyOfType("parameters",
+ base::Value::Type::LIST)
+ : params->GetList().back().FindKeyOfType(
+ "parameters", base::Value::Type::LIST);
if (callback_params) {
const base::ListValue* params_as_list = nullptr;
callback_params->GetAsList(&params_as_list);
@@ -532,6 +540,9 @@ void APIBinding::DecorateTemplateWithProperties(
}
// static
+bool APIBinding::enable_promise_support_for_testing = false;
+
+// static
void APIBinding::GetEventObject(
v8::Local<v8::Name> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {