#include <optional>
#include "base/feature_list.h"
#include "base/metrics/histogram_functions.h"
#include "base/types/optional_util.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "extensions/browser/api/messaging/channel_endpoint.h"
#include "extensions/browser/api/messaging/extension_message_port.h"
#include "extensions/browser/api/messaging/message_service.h"
#include "extensions/browser/bad_message.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/script_injection_tracker.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/trace_util.h"
BrowserThread;
RenderProcessHost;
ChromeTrackEvent;
namespace extensions {
namespace {
bool IsPortContextSandboxed(RenderProcessHost& process,
const PortContext& context) { … }
bool IsValidMessagingSource(RenderProcessHost& process,
const MessagingEndpoint& source_endpoint,
const PortContext& source_context) { … }
bool IsValidMessagingTarget(RenderProcessHost& process,
const MessagingEndpoint& source_endpoint,
const ExtensionId& target_id) { … }
bool IsValidSourceContext(RenderProcessHost& process,
const PortContext& source_context) { … }
bool IsValidSourceUrl(content::RenderProcessHost& process,
const GURL& source_url,
const PortContext& source_context) { … }
base::debug::CrashKeyString* GetTargetIdCrashKey() { … }
base::debug::CrashKeyString* GetSourceOriginCrashKey() { … }
base::debug::CrashKeyString* GetSourceUrlCrashKey() { … }
class ScopedExternalConnectionInfoCrashKeys { … };
std::optional<ExtensionId> ValidateSourceContextAndExtractExtensionId(
content::RenderProcessHost& process,
const PortContext& source_context) { … }
}
void MessageService::OpenChannelToExtension(
const ChannelEndpoint& source,
const PortId& source_port_id,
const ExternalConnectionInfo& info,
mojom::ChannelType channel_type,
const std::string& channel_name,
mojo::PendingAssociatedRemote<extensions::mojom::MessagePort> port,
mojo::PendingAssociatedReceiver<extensions::mojom::MessagePortHost>
port_host) { … }
void MessageService::OpenChannelToNativeApp(
const ChannelEndpoint& source,
const PortId& source_port_id,
const std::string& native_app_name,
mojo::PendingAssociatedRemote<extensions::mojom::MessagePort> port,
mojo::PendingAssociatedReceiver<extensions::mojom::MessagePortHost>
port_host) { … }
void MessageService::OpenChannelToTab(
const ChannelEndpoint& source,
const PortId& source_port_id,
int tab_id,
int frame_id,
const std::string& document_id,
mojom::ChannelType channel_type,
const std::string& channel_name,
mojo::PendingAssociatedRemote<extensions::mojom::MessagePort> port,
mojo::PendingAssociatedReceiver<extensions::mojom::MessagePortHost>
port_host) { … }
void MessageService::OpenPort(RenderProcessHost* process,
const PortId& port_id,
const PortContext& source) { … }
void MessageService::ClosePort(RenderProcessHost* process,
const PortId& port_id,
const PortContext& port_context,
bool force_close) { … }
void MessageService::NotifyResponsePending(RenderProcessHost* process,
const PortId& port_id,
const PortContext& port_context) { … }
}