#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "content/renderer/renderer_blink_platform_impl.h"
#include <algorithm>
#include <memory>
#include <string_view>
#include <utility>
#include <vector>
#include "base/check_is_test.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/pattern.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "base/time/time_delta_from_string.h"
#include "build/build_config.h"
#include "cc/trees/raster_context_provider_wrapper.h"
#include "components/url_formatter/url_formatter.h"
#include "components/viz/common/features.h"
#include "content/child/child_process.h"
#include "content/common/content_constants_internal.h"
#include "content/common/features.h"
#include "content/common/user_level_memory_pressure_signal_features.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/gpu_stream_constants.h"
#include "content/public/common/origin_util.h"
#include "content/public/common/url_utils.h"
#include "content/public/common/webplugininfo.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/public/renderer/render_frame.h"
#include "content/renderer/media/audio_decoder.h"
#include "content/renderer/media/batching_media_log.h"
#include "content/renderer/media/inspector_media_event_handler.h"
#include "content/renderer/media/render_media_event_handler.h"
#include "content/renderer/media/renderer_webaudiodevice_impl.h"
#include "content/renderer/render_frame_impl.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/service_worker/controller_service_worker_connector.h"
#include "content/renderer/service_worker/service_worker_subresource_loader.h"
#include "content/renderer/v8_value_converter_impl.h"
#include "content/renderer/variations_render_thread_observer.h"
#include "content/renderer/webgraphicscontext3d_provider_impl.h"
#include "content/renderer/worker/dedicated_worker_host_factory_client.h"
#include "content/renderer/worker/worker_thread_registry.h"
#include "device/gamepad/public/cpp/gamepads.h"
#include "gin/array_buffer.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "gpu/config/gpu_driver_bug_workarounds.h"
#include "gpu/config/gpu_finch_features.h"
#include "gpu/config/gpu_info.h"
#include "gpu/ipc/client/gpu_channel_host.h"
#include "media/audio/audio_output_device.h"
#include "media/base/media_permission.h"
#include "media/base/media_switches.h"
#include "media/filters/stream_parser_factory.h"
#include "media/video/gpu_video_accelerator_factories.h"
#include "media/webrtc/webrtc_features.h"
#include "mojo/public/cpp/base/big_buffer.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "net/base/schemeful_site.h"
#include "ppapi/buildflags/buildflags.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "services/viz/public/cpp/gpu/context_provider_command_buffer.h"
#include "storage/common/database/database_identifier.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/origin_trials/trial_token_validator.h"
#include "third_party/blink/public/common/security/protocol_handler_security_level.h"
#include "third_party/blink/public/common/thread_safe_browser_interface_broker_proxy.h"
#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_provider.mojom.h"
#include "third_party/blink/public/platform/file_path_conversion.h"
#include "third_party/blink/public/platform/modules/video_capture/web_video_capture_impl_manager.h"
#include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h"
#include "third_party/blink/public/platform/url_conversion.h"
#include "third_party/blink/public/platform/web_audio_latency_hint.h"
#include "third_party/blink/public/platform/web_audio_sink_descriptor.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/public/platform/web_theme_engine.h"
#include "third_party/blink/public/platform/web_url.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/public/platform/web_v8_value_converter.h"
#include "third_party/blink/public/platform/web_vector.h"
#include "third_party/blink/public/web/modules/media/audio/audio_device_factory.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_media_inspector.h"
#include "third_party/blink/public/web/web_user_level_memory_pressure_signal_generator.h"
#include "third_party/sqlite/sqlite3.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gl/buildflags.h"
#include "url/gurl.h"
#include "url/origin.h"
#if BUILDFLAG(IS_WIN)
#include "content/renderer/font_data/font_data_manager.h"
#include "skia/ext/font_utils.h"
#include "third_party/blink/public/web/win/web_font_rendering.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "content/child/child_process_sandbox_support_impl_mac.h"
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "content/child/child_process_sandbox_support_impl_linux.h"
#include "content/child/sandboxed_process_thread_type_handler.h"
#endif
#if BUILDFLAG(IS_POSIX)
#include "base/file_descriptor_posix.h"
#endif
#if BUILDFLAG(IS_ANDROID)
#include "content/common/android/sync_compositor_statics.h"
#endif
Platform;
WebAudioDevice;
WebAudioLatencyHint;
WebAudioSinkDescriptor;
WebMediaStreamTrack;
WebString;
WebURL;
WebVector;
namespace content {
namespace {
media::AudioParameters GetAudioHardwareParams() { … }
gpu::ContextType ToGpuContextType(blink::Platform::ContextType type) { … }
}
RendererBlinkPlatformImpl::RendererBlinkPlatformImpl(
blink::scheduler::WebThreadScheduler* main_thread_scheduler)
: … { … }
RendererBlinkPlatformImpl::~RendererBlinkPlatformImpl() { … }
void RendererBlinkPlatformImpl::Shutdown() { … }
std::string RendererBlinkPlatformImpl::GetNameForHistogram(const char* name) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
void RendererBlinkPlatformImpl::SetThreadType(base::PlatformThreadId thread_id,
base::ThreadType thread_type) { … }
#endif
blink::WebSandboxSupport* RendererBlinkPlatformImpl::GetSandboxSupport() { … }
bool RendererBlinkPlatformImpl::sandboxEnabled() { … }
uint64_t RendererBlinkPlatformImpl::VisitedLinkHash(
std::string_view canonical_url) { … }
uint64_t RendererBlinkPlatformImpl::PartitionedVisitedLinkFingerprint(
std::string_view canonical_link_url,
const net::SchemefulSite& top_level_site,
const blink::WebSecurityOrigin& frame_origin) { … }
bool RendererBlinkPlatformImpl::IsLinkVisited(uint64_t link_hash) { … }
void RendererBlinkPlatformImpl::AddOrUpdateVisitedLinkSalt(
const url::Origin& origin,
uint64_t salt) { … }
blink::WebString RendererBlinkPlatformImpl::UserAgent() { … }
blink::UserAgentMetadata RendererBlinkPlatformImpl::UserAgentMetadata() { … }
bool RendererBlinkPlatformImpl::IsRedirectSafe(const GURL& from_url,
const GURL& to_url) { … }
void RendererBlinkPlatformImpl::AppendVariationsThrottles(
const url::Origin& top_origin,
std::vector<std::unique_ptr<blink::URLLoaderThrottle>>* throttles) { … }
std::unique_ptr<blink::URLLoaderThrottleProvider>
RendererBlinkPlatformImpl::CreateURLLoaderThrottleProviderForWorker(
blink::URLLoaderThrottleProviderType provider_type) { … }
std::unique_ptr<blink::WebSocketHandshakeThrottleProvider>
RendererBlinkPlatformImpl::CreateWebSocketHandshakeThrottleProvider() { … }
bool RendererBlinkPlatformImpl::ShouldUseCodeCacheWithHashing(
const blink::WebURL& request_url) const { … }
bool RendererBlinkPlatformImpl::IsolateStartsInBackground() { … }
WebString RendererBlinkPlatformImpl::DefaultLocale() { … }
void RendererBlinkPlatformImpl::SuddenTerminationChanged(bool enabled) { … }
viz::FrameSinkId RendererBlinkPlatformImpl::GenerateFrameSinkId() { … }
bool RendererBlinkPlatformImpl::IsLockedToSite() const { … }
void RendererBlinkPlatformImpl::SetIsLockedToSite() { … }
bool RendererBlinkPlatformImpl::IsGpuCompositingDisabled() const { … }
#if BUILDFLAG(IS_ANDROID)
bool RendererBlinkPlatformImpl::
IsSynchronousCompositingEnabledForAndroidWebView() {
return GetContentClient()->UsingSynchronousCompositing();
}
bool RendererBlinkPlatformImpl::
IsZeroCopySynchronousSwDrawEnabledForAndroidWebView() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kSingleProcess);
}
SkCanvas*
RendererBlinkPlatformImpl::SynchronousCompositorGetSkCanvasForAndroidWebView() {
return content::SynchronousCompositorGetSkCanvas();
}
#endif
bool RendererBlinkPlatformImpl::IsLcdTextEnabled() { … }
bool RendererBlinkPlatformImpl::IsElasticOverscrollEnabled() { … }
bool RendererBlinkPlatformImpl::IsScrollAnimatorEnabled() { … }
bool RendererBlinkPlatformImpl::IsThreadedAnimationEnabled() { … }
double RendererBlinkPlatformImpl::AudioHardwareSampleRate() { … }
size_t RendererBlinkPlatformImpl::AudioHardwareBufferSize() { … }
unsigned RendererBlinkPlatformImpl::AudioHardwareOutputChannels() { … }
base::TimeDelta RendererBlinkPlatformImpl::GetHungRendererDelay() { … }
std::unique_ptr<WebAudioDevice> RendererBlinkPlatformImpl::CreateAudioDevice(
const WebAudioSinkDescriptor& sink_descriptor,
unsigned number_of_output_channels,
const blink::WebAudioLatencyHint& latency_hint,
media::AudioRendererSink::RenderCallback* callback) { … }
bool RendererBlinkPlatformImpl::DecodeAudioFileData(
blink::WebAudioBus* destination_bus,
const char* audio_file_data,
size_t data_size) { … }
scoped_refptr<media::AudioCapturerSource>
RendererBlinkPlatformImpl::NewAudioCapturerSource(
blink::WebLocalFrame* web_frame,
const media::AudioSourceParameters& params) { … }
scoped_refptr<viz::RasterContextProvider>
RendererBlinkPlatformImpl::SharedMainThreadContextProvider() { … }
scoped_refptr<cc::RasterContextProviderWrapper>
RendererBlinkPlatformImpl::SharedCompositorWorkerContextProvider(
cc::RasterDarkModeFilter* dark_mode_filter) { … }
bool RendererBlinkPlatformImpl::IsGpuRemoteDisconnected() { … }
scoped_refptr<gpu::GpuChannelHost>
RendererBlinkPlatformImpl::EstablishGpuChannelSync() { … }
void RendererBlinkPlatformImpl::EstablishGpuChannel(
EstablishGpuChannelCallback callback) { … }
bool RendererBlinkPlatformImpl::RTCSmoothnessAlgorithmEnabled() { … }
std::optional<double>
RendererBlinkPlatformImpl::GetWebRtcMaxCaptureFrameRate() { … }
scoped_refptr<media::AudioRendererSink>
RendererBlinkPlatformImpl::NewAudioRendererSink(
blink::WebAudioDeviceSourceType source_type,
blink::WebLocalFrame* web_frame,
const media::AudioSinkParameters& params) { … }
media::AudioLatency::Type RendererBlinkPlatformImpl::GetAudioSourceLatencyType(
blink::WebAudioDeviceSourceType source_type) { … }
bool RendererBlinkPlatformImpl::ShouldEnforceWebRTCRoutingPreferences() { … }
bool RendererBlinkPlatformImpl::UsesFakeCodecForPeerConnection() { … }
bool RendererBlinkPlatformImpl::IsWebRtcEncryptionEnabled() { … }
media::MediaPermission* RendererBlinkPlatformImpl::GetWebRTCMediaPermission(
blink::WebLocalFrame* web_frame) { … }
void RendererBlinkPlatformImpl::GetWebRTCRendererPreferences(
blink::WebLocalFrame* web_frame,
blink::WebString* ip_handling_policy,
uint16_t* udp_min_port,
uint16_t* udp_max_port,
bool* allow_mdns_obfuscation) { … }
bool RendererBlinkPlatformImpl::IsWebRtcHWEncodingEnabled() { … }
bool RendererBlinkPlatformImpl::IsWebRtcHWDecodingEnabled() { … }
bool RendererBlinkPlatformImpl::IsWebRtcSrtpEncryptedHeadersEnabled() { … }
bool RendererBlinkPlatformImpl::AllowsLoopbackInPeerConnection() { … }
blink::WebVideoCaptureImplManager*
RendererBlinkPlatformImpl::GetVideoCaptureImplManager() { … }
void RendererBlinkPlatformImpl::Collect3DContextInformation(
blink::Platform::GraphicsInfo* gl_info,
const gpu::GPUInfo& gpu_info) const { … }
std::unique_ptr<blink::WebGraphicsContext3DProvider>
RendererBlinkPlatformImpl::CreateOffscreenGraphicsContext3DProvider(
const blink::Platform::ContextAttributes& web_attributes,
const blink::WebURL& document_url,
blink::Platform::GraphicsInfo* gl_info) { … }
std::unique_ptr<blink::WebGraphicsContext3DProvider>
RendererBlinkPlatformImpl::CreateSharedOffscreenGraphicsContext3DProvider() { … }
static std::unique_ptr<blink::WebGraphicsContext3DProvider>
CreateWebGPUGraphicsContext3DImpl(
const blink::WebURL& document_url,
scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { … }
std::unique_ptr<blink::WebGraphicsContext3DProvider>
RendererBlinkPlatformImpl::CreateWebGPUGraphicsContext3DProvider(
const blink::WebURL& document_url) { … }
void RendererBlinkPlatformImpl::CreateWebGPUGraphicsContext3DProviderAsync(
const blink::WebURL& document_url,
base::OnceCallback<
void(std::unique_ptr<blink::WebGraphicsContext3DProvider>)> callback) { … }
void RendererBlinkPlatformImpl::OnGpuChannelEstablished(
const blink::WebURL& document_url,
base::OnceCallback<
void(std::unique_ptr<blink::WebGraphicsContext3DProvider>)> callback,
scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { … }
gpu::GpuMemoryBufferManager*
RendererBlinkPlatformImpl::GetGpuMemoryBufferManager() { … }
blink::WebString RendererBlinkPlatformImpl::ConvertIDNToUnicode(
const blink::WebString& host) { … }
std::unique_ptr<blink::WebDedicatedWorkerHostFactoryClient>
RendererBlinkPlatformImpl::CreateDedicatedWorkerHostFactoryClient(
blink::WebDedicatedWorker* worker,
const blink::BrowserInterfaceBrokerProxy& interface_broker) { … }
void RendererBlinkPlatformImpl::DidStartWorkerThread() { … }
void RendererBlinkPlatformImpl::WillStopWorkerThread() { … }
void RendererBlinkPlatformImpl::WorkerContextCreated(
const v8::Local<v8::Context>& worker) { … }
bool RendererBlinkPlatformImpl::AllowScriptExtensionForServiceWorker(
const blink::WebSecurityOrigin& script_origin) { … }
blink::ProtocolHandlerSecurityLevel
RendererBlinkPlatformImpl::GetProtocolHandlerSecurityLevel(
const blink::WebSecurityOrigin& origin) { … }
bool RendererBlinkPlatformImpl::OriginCanAccessServiceWorkers(const GURL& url) { … }
std::tuple<blink::CrossVariantMojoRemote<
blink::mojom::ServiceWorkerContainerHostInterfaceBase>,
blink::CrossVariantMojoRemote<
blink::mojom::ServiceWorkerContainerHostInterfaceBase>>
RendererBlinkPlatformImpl::CloneServiceWorkerContainerHost(
blink::CrossVariantMojoRemote<
blink::mojom::ServiceWorkerContainerHostInterfaceBase>
service_worker_container_host) { … }
void RendererBlinkPlatformImpl::CreateServiceWorkerSubresourceLoaderFactory(
blink::CrossVariantMojoRemote<
blink::mojom::ServiceWorkerContainerHostInterfaceBase>
service_worker_container_host,
const blink::WebString& client_id,
std::unique_ptr<network::PendingSharedURLLoaderFactory> fallback_factory,
mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver,
scoped_refptr<base::SequencedTaskRunner> task_runner) { … }
std::unique_ptr<media::MediaLog> RendererBlinkPlatformImpl::GetMediaLog(
blink::MediaInspectorContext* inspector_context,
scoped_refptr<base::SingleThreadTaskRunner> owner_task_runner,
bool is_on_worker) { … }
media::GpuVideoAcceleratorFactories*
RendererBlinkPlatformImpl::GetGpuFactories() { … }
scoped_refptr<base::SequencedTaskRunner>
RendererBlinkPlatformImpl::MediaThreadTaskRunner() { … }
base::WeakPtr<media::DecoderFactory>
RendererBlinkPlatformImpl::GetMediaDecoderFactory() { … }
void RendererBlinkPlatformImpl::SetRenderingColorSpace(
const gfx::ColorSpace& color_space) { … }
gfx::ColorSpace RendererBlinkPlatformImpl::GetRenderingColorSpace() const { … }
void RendererBlinkPlatformImpl::SetActiveURL(const blink::WebURL& url,
const blink::WebString& top_url) { … }
SkBitmap* RendererBlinkPlatformImpl::GetSadPageBitmap() { … }
std::unique_ptr<blink::WebV8ValueConverter>
RendererBlinkPlatformImpl::CreateWebV8ValueConverter() { … }
void RendererBlinkPlatformImpl::AppendContentSecurityPolicy(
const blink::WebURL& url,
blink::WebVector<blink::WebContentSecurityPolicyHeader>* csp) { … }
base::PlatformThreadId RendererBlinkPlatformImpl::GetIOThreadId() const { … }
scoped_refptr<base::SingleThreadTaskRunner>
RendererBlinkPlatformImpl::VideoFrameCompositorTaskRunner() { … }
#if BUILDFLAG(IS_ANDROID)
void RendererBlinkPlatformImpl::SetPrivateMemoryFootprint(
uint64_t private_memory_footprint_bytes) {
auto* render_thread = RenderThreadImpl::current();
CHECK(render_thread);
render_thread->SetPrivateMemoryFootprint(private_memory_footprint_bytes);
}
bool RendererBlinkPlatformImpl::IsUserLevelMemoryPressureSignalEnabled() {
return features::IsUserLevelMemoryPressureSignalEnabledOn3GbDevices() ||
features::IsUserLevelMemoryPressureSignalEnabledOn4GbDevices() ||
features::IsUserLevelMemoryPressureSignalEnabledOn6GbDevices();
}
std::pair<base::TimeDelta, base::TimeDelta> RendererBlinkPlatformImpl::
InertAndMinimumIntervalOfUserLevelMemoryPressureSignal() {
if (features::IsUserLevelMemoryPressureSignalEnabledOn3GbDevices()) {
return std::make_pair(
features::InertIntervalFor3GbDevices(),
features::MinUserMemoryPressureIntervalOn3GbDevices());
}
if (features::IsUserLevelMemoryPressureSignalEnabledOn4GbDevices()) {
return std::make_pair(
features::InertIntervalFor4GbDevices(),
features::MinUserMemoryPressureIntervalOn4GbDevices());
}
if (features::IsUserLevelMemoryPressureSignalEnabledOn6GbDevices()) {
return std::make_pair(
features::InertIntervalFor6GbDevices(),
features::MinUserMemoryPressureIntervalOn6GbDevices());
}
constexpr std::pair<base::TimeDelta, base::TimeDelta>
kDefaultInertAndMinInterval =
std::make_pair(base::TimeDelta::Min(), base::Minutes(10));
return kDefaultInertAndMinInterval;
}
#endif
}