#include "extensions/renderer/bindings/api_signature.h"
#include <algorithm>
#include "base/containers/contains.h"
#include "base/memory/raw_ref.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "content/public/renderer/v8_value_converter.h"
#include "extensions/renderer/bindings/api_binding_util.h"
#include "extensions/renderer/bindings/api_invocation_errors.h"
#include "extensions/renderer/bindings/argument_spec.h"
#include "gin/arguments.h"
namespace extensions {
namespace {
std::vector<std::unique_ptr<ArgumentSpec>> ValueListToArgumentSpecs(
const base::Value::List& specification_list,
bool uses_returns_async) { … }
std::unique_ptr<APISignature::ReturnsAsync> BuildReturnsAsyncFromValues(
const base::Value::Dict& returns_async_spec) { … }
std::string ArgumentSpecsToString(
const std::vector<std::unique_ptr<ArgumentSpec>>& argument_specs) { … }
class ArgumentParser { … };
class V8ArgumentParser : public ArgumentParser { … };
class BaseValueArgumentParser : public ArgumentParser { … };
bool ArgumentParser::ParseArgumentsImpl(bool signature_has_callback) { … }
bool ArgumentParser::ResolveArguments(
base::span<const v8::Local<v8::Value>> provided,
base::span<const std::unique_ptr<ArgumentSpec>> expected,
v8::LocalVector<v8::Value>* result,
size_t index,
bool allow_omitted_final_argument) { … }
bool ArgumentParser::ParseArgument(const ArgumentSpec& spec,
v8::Local<v8::Value> value) { … }
bool ArgumentParser::ParseCallback(const ArgumentSpec& spec,
v8::Local<v8::Value> value) { … }
APISignature::V8ParseResult V8ArgumentParser::ParseArguments(
bool signature_has_callback) { … }
APISignature::JSONParseResult BaseValueArgumentParser::ParseArguments(
bool signature_has_callback) { … }
bool ValidateSignatureForInternalCaller(
v8::Local<v8::Context> context,
const v8::LocalVector<v8::Value>& arguments,
const std::vector<std::unique_ptr<ArgumentSpec>>& expected,
const APITypeReferenceMap& type_refs,
std::string* error) { … }
}
APISignature::ReturnsAsync::ReturnsAsync() = default;
APISignature::ReturnsAsync::~ReturnsAsync() = default;
APISignature::V8ParseResult::V8ParseResult() = default;
APISignature::V8ParseResult::~V8ParseResult() = default;
APISignature::V8ParseResult::V8ParseResult(V8ParseResult&& other) = default;
APISignature::V8ParseResult& APISignature::V8ParseResult::operator=(
V8ParseResult&& other) = default;
APISignature::JSONParseResult::JSONParseResult() = default;
APISignature::JSONParseResult::~JSONParseResult() = default;
APISignature::JSONParseResult::JSONParseResult(JSONParseResult&& other) =
default;
APISignature::JSONParseResult& APISignature::JSONParseResult::operator=(
JSONParseResult&& other) = default;
APISignature::APISignature(
std::vector<std::unique_ptr<ArgumentSpec>> signature,
std::unique_ptr<APISignature::ReturnsAsync> returns_async,
BindingAccessChecker* access_checker)
: … { … }
APISignature::~APISignature() = default;
std::unique_ptr<APISignature> APISignature::CreateFromValues(
const base::Value& spec_list,
const base::Value* returns_async,
BindingAccessChecker* access_checker) { … }
APISignature::V8ParseResult APISignature::ParseArgumentsToV8(
v8::Local<v8::Context> context,
const v8::LocalVector<v8::Value>& arguments,
const APITypeReferenceMap& type_refs) const { … }
APISignature::JSONParseResult APISignature::ParseArgumentsToJSON(
v8::Local<v8::Context> context,
const v8::LocalVector<v8::Value>& arguments,
const APITypeReferenceMap& type_refs) const { … }
APISignature::JSONParseResult APISignature::ConvertArgumentsIgnoringSchema(
v8::Local<v8::Context> context,
const v8::LocalVector<v8::Value>& arguments) const { … }
bool APISignature::ValidateResponse(v8::Local<v8::Context> context,
const v8::LocalVector<v8::Value>& arguments,
const APITypeReferenceMap& type_refs,
std::string* error) const { … }
bool APISignature::ValidateCall(v8::Local<v8::Context> context,
const v8::LocalVector<v8::Value>& arguments,
const APITypeReferenceMap& type_refs,
std::string* error) const { … }
std::string APISignature::GetExpectedSignature() const { … }
PromisesAllowed APISignature::CheckPromisesAllowed(
v8::Local<v8::Context> context) const { … }
}