#include "extensions/renderer/native_extension_bindings_system.h"
#include <string_view>
#include <utility>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/typed_macros.h"
#include "base/tracing/protos/chrome_track_event.pbzero.h"
#include "components/crx_file/id_util.h"
#include "content/public/common/content_switches.h"
#include "content/public/renderer/render_thread.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_api.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/features/feature.h"
#include "extensions/common/features/feature_provider.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_handlers/content_capabilities_handler.h"
#include "extensions/common/manifest_handlers/externally_connectable.h"
#include "extensions/common/mojom/context_type.mojom.h"
#include "extensions/common/mojom/event_dispatcher.mojom.h"
#include "extensions/common/mojom/frame.mojom.h"
#include "extensions/common/switches.h"
#include "extensions/common/utils/extension_utils.h"
#include "extensions/renderer/api_activity_logger.h"
#include "extensions/renderer/bindings/api_binding_bridge.h"
#include "extensions/renderer/bindings/api_binding_hooks.h"
#include "extensions/renderer/bindings/api_binding_js_util.h"
#include "extensions/renderer/bindings/api_binding_util.h"
#include "extensions/renderer/console.h"
#include "extensions/renderer/extension_frame_helper.h"
#include "extensions/renderer/extension_interaction_provider.h"
#include "extensions/renderer/extension_js_runner.h"
#include "extensions/renderer/get_script_context.h"
#include "extensions/renderer/ipc_message_sender.h"
#include "extensions/renderer/module_system.h"
#include "extensions/renderer/renderer_extension_registry.h"
#include "extensions/renderer/renderer_frame_context_data.h"
#include "extensions/renderer/script_context.h"
#include "extensions/renderer/script_context_set_iterable.h"
#include "extensions/renderer/trace_util.h"
#include "extensions/renderer/worker_thread_util.h"
#include "gin/converter.h"
#include "gin/data_object_builder.h"
#include "gin/handle.h"
#include "gin/per_context_data.h"
#include "third_party/blink/public/mojom/devtools/console_message.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_registration.mojom.h"
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "v8/include/v8-context.h"
#include "v8/include/v8-isolate.h"
#include "v8/include/v8-object.h"
#include "v8/include/v8-primitive.h"
#include "v8/include/v8-template.h"
ChromeTrackEvent;
namespace extensions {
namespace {
const char kBindingsSystemPerContextKey[] = …;
bool IsPrefixedAPI(std::string_view api, std::string_view root_api) { … }
std::string_view GetFirstDifferentAPIName(std::string_view api_name,
std::string_view reference) { … }
struct BindingsSystemPerContextData : public base::SupportsUserData::Data { … };
v8::Local<v8::Object> GetOrCreateChrome(v8::Local<v8::Context> context) { … }
BindingsSystemPerContextData* GetBindingsDataFromContext(
v8::Local<v8::Context> context) { … }
void AddConsoleError(v8::Local<v8::Context> context, const std::string& error) { … }
const base::Value::Dict& GetAPISchema(const std::string& api_name) { … }
bool IsAPIFeatureAvailable(v8::Local<v8::Context> context,
const std::string& name) { … }
bool ArePromisesAllowed(v8::Local<v8::Context> context) { … }
v8::Local<v8::Object> CreateRootBinding(v8::Local<v8::Context> context,
ScriptContext* script_context,
const std::string& name,
APIBindingsSystem* bindings_system) { … }
v8::Local<v8::Object> CreateFullBinding(
v8::Local<v8::Context> context,
ScriptContext* script_context,
APIBindingsSystem* bindings_system,
const FeatureProvider* api_feature_provider,
const std::string& root_name) { … }
std::string GetContextOwner(v8::Local<v8::Context> context) { … }
bool DoesContextNeedMessagingApis(ScriptContext* context) { … }
const char* const kWebAvailableFeatures[] = …;
bool ShouldCollectJSStackTrace(const APIRequestHandler::Request& request) { … }
}
NativeExtensionBindingsSystem::NativeExtensionBindingsSystem(
Delegate* delegate,
std::unique_ptr<IPCMessageSender> ipc_message_sender)
: … { … }
NativeExtensionBindingsSystem::~NativeExtensionBindingsSystem() = default;
void NativeExtensionBindingsSystem::DidCreateScriptContext(
ScriptContext* context) { … }
void NativeExtensionBindingsSystem::WillReleaseScriptContext(
ScriptContext* context) { … }
void NativeExtensionBindingsSystem::UpdateBindingsForContext(
ScriptContext* context) { … }
void NativeExtensionBindingsSystem::DispatchEventInContext(
const std::string& event_name,
const base::Value::List& event_args,
const mojom::EventFilteringInfoPtr& filtering_info,
ScriptContext* context) { … }
bool NativeExtensionBindingsSystem::HasEventListenerInContext(
const std::string& event_name,
ScriptContext* context) { … }
void NativeExtensionBindingsSystem::HandleResponse(
int request_id,
bool success,
const base::Value::List& response,
const std::string& error,
mojom::ExtraResponseDataPtr extra_data) { … }
IPCMessageSender* NativeExtensionBindingsSystem::GetIPCMessageSender() { … }
void NativeExtensionBindingsSystem::UpdateBindings(
const ExtensionId& extension_id,
bool permissions_changed,
ScriptContextSetIterable* script_context_set) { … }
void NativeExtensionBindingsSystem::OnExtensionRemoved(const ExtensionId& id) { … }
v8::Local<v8::Object> NativeExtensionBindingsSystem::GetAPIObjectForTesting(
ScriptContext* context,
const std::string& api_name) { … }
void NativeExtensionBindingsSystem::BindingAccessor(
v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) { … }
void NativeExtensionBindingsSystem::ThrowDeveloperModeRestrictedError(
v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) { … }
v8::Local<v8::Object> NativeExtensionBindingsSystem::GetAPIHelper(
v8::Local<v8::Context> context,
v8::Local<v8::String> api_name) { … }
v8::Local<v8::Object> NativeExtensionBindingsSystem::GetLastErrorParents(
v8::Local<v8::Context> context,
v8::Local<v8::Object>* secondary_parent) { … }
void NativeExtensionBindingsSystem::GetInternalAPI(
const v8::FunctionCallbackInfo<v8::Value>& info) { … }
void NativeExtensionBindingsSystem::SendRequest(
std::unique_ptr<APIRequestHandler::Request> request,
v8::Local<v8::Context> context) { … }
void NativeExtensionBindingsSystem::OnEventListenerChanged(
const std::string& event_name,
binding::EventListenersChanged change,
const base::Value::Dict* filter,
bool update_lazy_listeners,
v8::Local<v8::Context> context) { … }
void NativeExtensionBindingsSystem::GetJSBindingUtil(
v8::Local<v8::Context> context,
v8::Local<v8::Value>* binding_util_out) { … }
void NativeExtensionBindingsSystem::UpdateContentCapabilities(
ScriptContext* context) { … }
void NativeExtensionBindingsSystem::SetScriptingParams(ScriptContext* context) { … }
}