#include "extensions/renderer/bindings/api_binding_hooks.h"
#include "base/debug/dump_without_crashing.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/stringprintf.h"
#include "base/supports_user_data.h"
#include "extensions/renderer/bindings/api_binding_hooks_delegate.h"
#include "extensions/renderer/bindings/api_binding_util.h"
#include "extensions/renderer/bindings/api_request_handler.h"
#include "extensions/renderer/bindings/api_signature.h"
#include "extensions/renderer/bindings/js_runner.h"
#include "gin/arguments.h"
#include "gin/data_object_builder.h"
#include "gin/handle.h"
#include "gin/object_template_builder.h"
#include "gin/per_context_data.h"
#include "gin/wrappable.h"
namespace extensions {
namespace {
class JSHookInterface final : public gin::Wrappable<JSHookInterface> { … };
const char kExtensionAPIHooksPerContextKey[] = …;
struct APIHooksPerContextData : public base::SupportsUserData::Data { … };
gin::WrapperInfo JSHookInterface::kWrapperInfo = …;
v8::Local<v8::Object> GetJSHookInterfaceObject(
const std::string& api_name,
v8::Local<v8::Context> context,
bool should_create) { … }
void CompleteHandleRequestHelper(
const v8::FunctionCallbackInfo<v8::Value>& info,
bool did_succeed) { … }
void AddSuccessAndFailureCallbacks(
v8::Local<v8::Context> context,
binding::AsyncResponseType async_type,
APIRequestHandler& request_handler,
binding::ResultModifierFunction result_modifier,
base::WeakPtr<APIBindingHooks> weak_ptr,
v8::LocalVector<v8::Value>* arguments,
APIBindingHooks::RequestResult& result) { … }
}
APIBindingHooks::RequestResult::RequestResult(ResultCode code) : … { … }
APIBindingHooks::RequestResult::RequestResult(
ResultCode code,
v8::Local<v8::Function> custom_callback)
: … { … }
APIBindingHooks::RequestResult::RequestResult(
ResultCode code,
v8::Local<v8::Function> custom_callback,
binding::ResultModifierFunction result_modifier)
: … { … }
APIBindingHooks::RequestResult::RequestResult(std::string invocation_error)
: … { … }
APIBindingHooks::RequestResult::~RequestResult() = default;
APIBindingHooks::RequestResult::RequestResult(RequestResult&& other) = default;
APIBindingHooks::APIBindingHooks(const std::string& api_name,
APIRequestHandler* request_handler)
: … { … }
APIBindingHooks::~APIBindingHooks() = default;
APIBindingHooks::RequestResult APIBindingHooks::RunHooks(
const std::string& method_name,
v8::Local<v8::Context> context,
const APISignature* signature,
v8::LocalVector<v8::Value>* arguments,
const APITypeReferenceMap& type_refs) { … }
void APIBindingHooks::CompleteHandleRequest(int request_id,
bool did_succeed,
gin::Arguments* arguments) { … }
v8::Local<v8::Object> APIBindingHooks::GetJSHookInterface(
v8::Local<v8::Context> context) { … }
bool APIBindingHooks::CreateCustomEvent(v8::Local<v8::Context> context,
const std::string& event_name,
v8::Local<v8::Value>* event_out) { … }
void APIBindingHooks::InitializeTemplate(
v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> object_template,
const APITypeReferenceMap& type_refs) { … }
void APIBindingHooks::InitializeInstance(v8::Local<v8::Context> context,
v8::Local<v8::Object> instance) { … }
void APIBindingHooks::SetDelegate(
std::unique_ptr<APIBindingHooksDelegate> delegate) { … }
bool APIBindingHooks::UpdateArguments(v8::Local<v8::Function> function,
v8::Local<v8::Context> context,
v8::LocalVector<v8::Value>* arguments) { … }
}