#include "extensions/renderer/bindings/api_event_handler.h"
#include <map>
#include <memory>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/supports_user_data.h"
#include "base/values.h"
#include "content/public/renderer/v8_value_converter.h"
#include "extensions/common/mojom/event_dispatcher.mojom.h"
#include "extensions/renderer/bindings/api_response_validator.h"
#include "extensions/renderer/bindings/event_emitter.h"
#include "extensions/renderer/bindings/get_per_context_data.h"
#include "extensions/renderer/bindings/js_runner.h"
#include "gin/converter.h"
#include "gin/data_object_builder.h"
#include "gin/handle.h"
#include "gin/per_context_data.h"
namespace extensions {
namespace {
constexpr char kFilterIdKey[] = …;
constexpr char kEventNameKey[] = …;
struct APIEventPerContextData : public base::SupportsUserData::Data { … };
constexpr char APIEventPerContextData::kPerContextDataKey[];
void DispatchEvent(const v8::FunctionCallbackInfo<v8::Value>& info) { … }
}
APIEventHandler::APIEventHandler(
const APIEventListeners::ListenersUpdated& listeners_changed,
const APIEventListeners::ContextOwnerIdGetter& context_owner_id_getter,
ExceptionHandler* exception_handler)
: … { … }
APIEventHandler::~APIEventHandler() = default;
void APIEventHandler::SetResponseValidator(
std::unique_ptr<APIResponseValidator> validator) { … }
v8::Local<v8::Object> APIEventHandler::CreateEventInstance(
const std::string& event_name,
bool supports_filters,
bool supports_lazy_listeners,
int max_listeners,
bool notify_on_change,
v8::Local<v8::Context> context) { … }
v8::Local<v8::Object> APIEventHandler::CreateAnonymousEventInstance(
v8::Local<v8::Context> context) { … }
void APIEventHandler::InvalidateCustomEvent(v8::Local<v8::Context> context,
v8::Local<v8::Object> event) { … }
void APIEventHandler::FireEventInContext(const std::string& event_name,
v8::Local<v8::Context> context,
const base::Value::List& args,
mojom::EventFilteringInfoPtr filter) { … }
void APIEventHandler::FireEventInContext(const std::string& event_name,
v8::Local<v8::Context> context,
v8::LocalVector<v8::Value>* arguments,
mojom::EventFilteringInfoPtr filter,
JSRunner::ResultCallback callback) { … }
void APIEventHandler::RegisterArgumentMassager(
v8::Local<v8::Context> context,
const std::string& event_name,
v8::Local<v8::Function> massager) { … }
bool APIEventHandler::HasListenerForEvent(const std::string& event_name,
v8::Local<v8::Context> context) { … }
void APIEventHandler::InvalidateContext(v8::Local<v8::Context> context) { … }
size_t APIEventHandler::GetNumEventListenersForTesting(
const std::string& event_name,
v8::Local<v8::Context> context) { … }
}