#include "extensions/browser/extension_function_dispatcher.h"
#include <optional>
#include <utility>
#include "base/debug/crash_logging.h"
#include "base/functional/bind.h"
#include "base/json/json_string_value_serializer.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/process/process.h"
#include "base/ranges/algorithm.h"
#include "base/scoped_observation.h"
#include "base/trace_event/typed_macros.h"
#include "base/tracing/protos/chrome_track_event.pbzero.h"
#include "base/values.h"
#include "build/build_config.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_process_host_observer.h"
#include "content/public/browser/service_worker_context.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/url_constants.h"
#include "extensions/browser/api_activity_monitor.h"
#include "extensions/browser/bad_message.h"
#include "extensions/browser/extension_function_registry.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/process_map.h"
#include "extensions/browser/quota_service.h"
#include "extensions/browser/script_injection_tracker.h"
#include "extensions/browser/service_worker/service_worker_keepalive.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_api.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/mojom/context_type.mojom.h"
#include "extensions/common/trace_util.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_message_macros.h"
#include "mojo/public/cpp/bindings/message.h"
BrowserThread;
ChromeTrackEvent;
namespace extensions {
namespace {
void NotifyApiFunctionCalled(const ExtensionId& extension_id,
const std::string& api_name,
const base::Value::List& args,
content::BrowserContext* browser_context) { … }
bool IsRequestFromServiceWorker(const mojom::RequestParams& request_params) { … }
void ResponseCallbackOnError(ExtensionFunction::ResponseCallback callback,
ExtensionFunction::ResponseType type,
const std::string& error) { … }
bool CanRendererActOnBehalfOfExtension(
const ExtensionId& extension_id,
content::RenderFrameHost* render_frame_host,
content::RenderProcessHost& render_process_host) { … }
std::optional<bad_message::BadMessageReason> ValidateRequest(
const mojom::RequestParams& params,
content::RenderFrameHost* render_frame_host,
content::RenderProcessHost& render_process_host) { … }
const char* ToString(bad_message::BadMessageReason bad_message_code) { … }
class ScopedRequestParamsCrashKeys { … };
}
WindowController*
ExtensionFunctionDispatcher::Delegate::GetExtensionWindowController() const { … }
content::WebContents*
ExtensionFunctionDispatcher::Delegate::GetAssociatedWebContents() const { … }
content::WebContents*
ExtensionFunctionDispatcher::Delegate::GetVisibleWebContents() const { … }
ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(
content::BrowserContext* browser_context)
: … { … }
ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { … }
void ExtensionFunctionDispatcher::Dispatch(
mojom::RequestParamsPtr params,
content::RenderFrameHost& frame,
mojom::LocalFrameHost::RequestCallback callback) { … }
void ExtensionFunctionDispatcher::DispatchForServiceWorker(
mojom::RequestParamsPtr params,
int render_process_id,
mojom::ServiceWorkerHost::RequestWorkerCallback callback) { … }
void ExtensionFunctionDispatcher::DispatchWithCallbackInternal(
const mojom::RequestParams& params,
content::RenderFrameHost* render_frame_host,
content::RenderProcessHost& render_process_host,
ExtensionFunction::ResponseCallback callback) { … }
void ExtensionFunctionDispatcher::OnExtensionFunctionCompleted(
ExtensionFunction& extension_function) { … }
WindowController*
ExtensionFunctionDispatcher::GetExtensionWindowController() const { … }
content::WebContents*
ExtensionFunctionDispatcher::GetAssociatedWebContents() const { … }
content::WebContents*
ExtensionFunctionDispatcher::GetVisibleWebContents() const { … }
void ExtensionFunctionDispatcher::AddResponseTarget(ExtensionFunction* func) { … }
void ExtensionFunctionDispatcher::ProcessResponseAck(
const base::Uuid& request_uuid) { … }
scoped_refptr<ExtensionFunction>
ExtensionFunctionDispatcher::CreateExtensionFunction(
const mojom::RequestParams& params,
const Extension* extension,
int requesting_process_id,
bool is_worker_request,
const GURL* render_frame_host_url,
mojom::ContextType context_type,
ExtensionAPI* api,
ExtensionFunction::ResponseCallback callback,
content::RenderFrameHost* render_frame_host) { … }
}