#include "extensions/renderer/bindings/api_request_handler.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.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_response_validator.h"
#include "extensions/renderer/bindings/exception_handler.h"
#include "extensions/renderer/bindings/js_runner.h"
#include "gin/arguments.h"
#include "gin/converter.h"
#include "gin/data_object_builder.h"
#include "third_party/blink/public/web/web_blob.h"
namespace extensions {
constexpr const char kErrorKey[] = …;
constexpr const char kResolverKey[] = …;
constexpr const char kExceptionHandlerKey[] = …;
class APIRequestHandler::ArgumentAdapter { … };
APIRequestHandler::ArgumentAdapter::ArgumentAdapter(
const base::Value::List* base_arguments,
mojom::ExtraResponseDataPtr extra_data)
: … { … }
APIRequestHandler::ArgumentAdapter::ArgumentAdapter(
const v8::LocalVector<v8::Value>& v8_arguments)
: … { … }
APIRequestHandler::ArgumentAdapter::~ArgumentAdapter() = default;
const v8::LocalVector<v8::Value>&
APIRequestHandler::ArgumentAdapter::GetArguments(
v8::Local<v8::Context> context) const { … }
class APIRequestHandler::AsyncResultHandler { … };
APIRequestHandler::AsyncResultHandler::AsyncResultHandler(
v8::Isolate* isolate,
v8::Local<v8::Function> extension_callback,
v8::Local<v8::Function> custom_callback,
binding::ResultModifierFunction result_modifier,
ExceptionHandler* exception_handler)
: … { … }
APIRequestHandler::AsyncResultHandler::AsyncResultHandler(
v8::Isolate* isolate,
v8::Local<v8::Promise::Resolver> promise_resolver,
v8::Local<v8::Function> custom_callback,
binding::ResultModifierFunction result_modifier)
: … { … }
APIRequestHandler::AsyncResultHandler::~AsyncResultHandler() = default;
void APIRequestHandler::AsyncResultHandler::ResolveRequest(
v8::Local<v8::Context> context,
APILastError* last_error,
const v8::LocalVector<v8::Value>& response_args,
const std::string& error,
mojom::ExtraResponseDataPtr extra_data) { … }
void APIRequestHandler::AsyncResultHandler::ResolvePromise(
v8::Local<v8::Context> context,
const v8::LocalVector<v8::Value>& response_args,
const std::string& error,
v8::Local<v8::Promise::Resolver> resolver) { … }
void APIRequestHandler::AsyncResultHandler::CallExtensionCallback(
v8::Local<v8::Context> context,
v8::LocalVector<v8::Value> args,
v8::Local<v8::Function> extension_callback,
ExceptionHandler* exception_handler) { … }
void APIRequestHandler::AsyncResultHandler::CustomCallbackAdaptor(
const v8::FunctionCallbackInfo<v8::Value>& info) { … }
void APIRequestHandler::AsyncResultHandler::CallCustomCallback(
v8::Local<v8::Context> context,
const v8::LocalVector<v8::Value>& response_args,
const std::string& error) { … }
APIRequestHandler::Request::Request() = default;
APIRequestHandler::Request::~Request() = default;
APIRequestHandler::RequestDetails::RequestDetails(
int request_id,
v8::Local<v8::Promise> promise)
: … { … }
APIRequestHandler::RequestDetails::~RequestDetails() = default;
APIRequestHandler::RequestDetails::RequestDetails(const RequestDetails& other) =
default;
APIRequestHandler::PendingRequest::PendingRequest(
v8::Isolate* isolate,
v8::Local<v8::Context> context,
const std::string& method_name,
std::unique_ptr<AsyncResultHandler> async_handler,
std::unique_ptr<InteractionProvider::Token> gesture_token)
: … { … }
APIRequestHandler::PendingRequest::~PendingRequest() = default;
APIRequestHandler::PendingRequest::PendingRequest(PendingRequest&&) = default;
APIRequestHandler::PendingRequest& APIRequestHandler::PendingRequest::operator=(
PendingRequest&&) = default;
APIRequestHandler::APIRequestHandler(
SendRequestMethod send_request,
APILastError last_error,
ExceptionHandler* exception_handler,
const InteractionProvider* interaction_provider)
: … { … }
APIRequestHandler::~APIRequestHandler() = default;
v8::Local<v8::Promise> APIRequestHandler::StartRequest(
v8::Local<v8::Context> context,
const std::string& method,
base::Value::List arguments_list,
binding::AsyncResponseType async_type,
v8::Local<v8::Function> callback,
v8::Local<v8::Function> custom_callback,
binding::ResultModifierFunction result_modifier) { … }
void APIRequestHandler::CompleteRequest(
int request_id,
const base::Value::List& response_args,
const std::string& error,
mojom::ExtraResponseDataPtr extra_data) { … }
void APIRequestHandler::CompleteRequest(
int request_id,
const v8::LocalVector<v8::Value>& response_args,
const std::string& error) { … }
APIRequestHandler::RequestDetails APIRequestHandler::AddPendingRequest(
v8::Local<v8::Context> context,
binding::AsyncResponseType async_type,
v8::Local<v8::Function> callback,
binding::ResultModifierFunction result_modifier) { … }
void APIRequestHandler::InvalidateContext(v8::Local<v8::Context> context) { … }
void APIRequestHandler::SetResponseValidator(
std::unique_ptr<APIResponseValidator> response_validator) { … }
std::set<int> APIRequestHandler::GetPendingRequestIdsForTesting() const { … }
int APIRequestHandler::GetNextRequestId() { … }
std::unique_ptr<APIRequestHandler::AsyncResultHandler>
APIRequestHandler::GetAsyncResultHandler(
v8::Local<v8::Context> context,
binding::AsyncResponseType async_type,
v8::Local<v8::Function> extension_callback,
v8::Local<v8::Function> custom_callback,
binding::ResultModifierFunction result_modifier,
v8::Local<v8::Promise>* promise_out) { … }
void APIRequestHandler::CompleteRequestImpl(int request_id,
ArgumentAdapter arguments,
const std::string& error) { … }
}