blob: edbf232175e4555d4f810b6ef03c74f793e32bdf [file] [log] [blame]
[email protected]273558fb2012-01-12 15:03:511// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]dd9241932010-02-24 19:23:132// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]8d86fce2009-02-26 23:37:554
tfarina556a7232014-10-05 01:02:095#ifndef CONTENT_RENDERER_RENDERER_BLINK_PLATFORM_IMPL_H_
6#define CONTENT_RENDERER_RENDERER_BLINK_PLATFORM_IMPL_H_
[email protected]8d86fce2009-02-26 23:37:557
avi1023d012015-12-25 02:39:148#include <stddef.h>
9#include <stdint.h>
10
dchengcedca5612016-04-09 01:40:1511#include <memory>
Max Morinf506af592018-04-17 12:23:3212#include <string>
dchengcedca5612016-04-09 01:40:1513
[email protected]f3112a52011-09-30 23:47:4914#include "base/compiler_specific.h"
Brett Wilsonf976d3f2017-08-18 17:23:3915#include "base/containers/id_map.h"
avi1023d012015-12-25 02:39:1416#include "base/macros.h"
Yutaka Hiranob0465f72018-05-17 05:48:2517#include "base/optional.h"
Gabriel Charette14520232018-04-30 23:27:2218#include "base/single_thread_task_runner.h"
Tsuyoshi Horo0a0f7a72017-06-26 10:19:3919#include "base/time/time.h"
avi1023d012015-12-25 02:39:1420#include "build/build_config.h"
[email protected]4db58d72014-03-24 17:05:1921#include "content/child/blink_platform_impl.h"
[email protected]f3112a52011-09-30 23:47:4922#include "content/common/content_export.h"
skyostilb4cce1b2016-03-31 17:56:3423#include "content/renderer/top_level_blame_context.h"
Julie Jeongeun Kime5e7fd8b2019-09-03 16:53:4624#include "mojo/public/cpp/bindings/pending_remote.h"
25#include "mojo/public/cpp/bindings/shared_remote.h"
Ken Rockot54311e62018-02-10 19:01:5226#include "services/network/public/mojom/url_loader_factory.mojom.h"
Luciano Pacheco626c99e82018-03-22 01:06:5627#include "services/service_manager/public/cpp/interface_provider.h"
Dmitry Gozmanf3613452018-04-17 20:22:0228#include "third_party/blink/public/common/screen_orientation/web_screen_orientation_type.h"
Mike West6e4cbb32019-02-13 09:40:1729#include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
Richard Libcc09eb2018-11-30 15:00:3530#include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom.h"
Bill Budge24c1dc1a2018-09-25 18:51:3231#include "third_party/blink/public/mojom/loader/code_cache.mojom.h"
[email protected]8d86fce2009-02-26 23:37:5532
Dominik Röttschesac240042018-07-06 09:52:4033#if defined(OS_LINUX)
34#include "components/services/font/public/cpp/font_loader.h" // nogncheck
35#include "third_party/skia/include/core/SkRefCnt.h" // nogncheck
36#endif
37
[email protected]180ef242013-11-07 06:50:4638namespace blink {
skyostil529caa292016-08-10 17:44:5139namespace scheduler {
Yuta Kitamuradeb91bb2018-05-29 05:53:2040class WebThreadScheduler;
skyostil529caa292016-08-10 17:44:5141}
[email protected]39604c32013-05-09 12:40:1742class WebGraphicsContext3DProvider;
guidou55e35dc2016-02-04 11:06:2543class WebSecurityOrigin;
Luciano Pacheco626c99e82018-03-22 01:06:5644} // namespace blink
[email protected]39604c32013-05-09 12:40:1745
Miyoung Shinccbe33232019-06-19 04:14:3046namespace media {
47class GpuVideoAcceleratorFactories;
48}
49
Matt Falkenhagend7e6a5622018-05-25 13:12:4850namespace network {
51class SharedURLLoaderFactory;
52}
53
[email protected]e9ff79c2012-10-19 21:31:2654namespace content {
Yuzhu Shen0c1715f2018-01-27 03:48:5055class ChildURLLoaderFactoryBundle;
[email protected]b180a0bb2013-03-06 00:36:1056class ThreadSafeSender;
[email protected]e9ff79c2012-10-19 21:31:2657
tfarina556a7232014-10-05 01:02:0958class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
[email protected]8d86fce2009-02-26 23:37:5559 public:
Reilly Grant9944f162017-08-29 01:22:4160 explicit RendererBlinkPlatformImpl(
Yuta Kitamuradeb91bb2018-05-29 05:53:2061 blink::scheduler::WebThreadScheduler* main_thread_scheduler);
avi5c77d212015-09-25 20:08:2562 ~RendererBlinkPlatformImpl() override;
[email protected]eb6f2c542009-10-02 04:53:5963
Hajime Hoshi315a61f2018-08-14 17:27:2864 blink::scheduler::WebThreadScheduler* main_thread_scheduler() {
65 return main_thread_scheduler_;
66 }
67
rickyzf2c93062015-09-15 09:10:5768 // Shutdown must be called just prior to shutting down blink.
69 void Shutdown();
70
[email protected]8467ae0d2013-02-27 02:02:4871 // Platform methods:
Blink Reformat1c4d759e2017-04-09 16:34:5472 blink::WebSandboxSupport* GetSandboxSupport() override;
Blink Reformat1c4d759e2017-04-09 16:34:5473 blink::WebThemeEngine* ThemeEngine() override;
[email protected]937c4eb2013-01-03 00:36:5674 virtual bool sandboxEnabled();
Miyoung Shind2dd8bc2019-03-11 02:45:4075 uint64_t VisitedLinkHash(const char* canonicalURL, size_t length) override;
76 bool IsLinkVisited(uint64_t linkHash) override;
Yutaka Hiranob0465f72018-05-17 05:48:2577 blink::WebString UserAgent() override;
Mike West6e4cbb32019-02-13 09:40:1778 blink::UserAgentMetadata UserAgentMetadata() override;
Bill Budged64546bc2018-09-28 16:06:4779 void CacheMetadata(blink::mojom::CodeCacheType cache_type,
80 const blink::WebURL&,
Tsuyoshi Horo0a0f7a72017-06-26 10:19:3981 base::Time,
Kenichi Ishibashi0265fa32018-12-26 03:24:1982 const uint8_t*,
avi1023d012015-12-25 02:39:1483 size_t) override;
Jeremy Roman84083752019-05-07 16:47:0184 void FetchCachedCode(blink::mojom::CodeCacheType cache_type,
85 const GURL&,
86 FetchCachedCodeCallback) override;
Bill Budged64546bc2018-09-28 16:06:4787 void ClearCodeCacheEntry(blink::mojom::CodeCacheType cache_type,
88 const GURL&) override;
Blink Reformat1c4d759e2017-04-09 16:34:5489 void CacheMetadataInCacheStorage(
horo244fe932016-05-10 02:27:4990 const blink::WebURL&,
Tsuyoshi Horo0a0f7a72017-06-26 10:19:3991 base::Time,
Kenichi Ishibashi0265fa32018-12-26 03:24:1992 const uint8_t*,
horo244fe932016-05-10 02:27:4993 size_t,
94 const blink::WebSecurityOrigin& cacheStorageOrigin,
95 const blink::WebString& cacheStorageCacheName) override;
Blink Reformat1c4d759e2017-04-09 16:34:5496 blink::WebString DefaultLocale() override;
97 void SuddenTerminationChanged(bool enabled) override;
Blink Reformat1c4d759e2017-04-09 16:34:5498 blink::WebString DatabaseCreateOriginIdentifier(
jsbell1d0a8a442016-03-22 20:07:2899 const blink::WebSecurityOrigin& origin) override;
Fady Samueld5c26182017-07-12 02:43:33100 viz::FrameSinkId GenerateFrameSinkId() override;
Nicolas Pena7c7847f2018-05-30 01:36:05101 bool IsLockedToSite() const override;
jsbell1d0a8a442016-03-22 20:07:28102
Blink Reformat1c4d759e2017-04-09 16:34:54103 blink::WebString FileSystemCreateOriginIdentifier(
jsbell1d0a8a442016-03-22 20:07:28104 const blink::WebSecurityOrigin& origin) override;
105
Blink Reformat1c4d759e2017-04-09 16:34:54106 bool IsThreadedAnimationEnabled() override;
danakj954b09b2017-11-02 17:56:47107 bool IsGpuCompositingDisabled() override;
Blink Reformat1c4d759e2017-04-09 16:34:54108 double AudioHardwareSampleRate() override;
109 size_t AudioHardwareBufferSize() override;
110 unsigned AudioHardwareOutputChannels() override;
[email protected]a19efb72013-01-12 17:05:46111
altimineb6bd1962017-05-03 14:52:38112 std::unique_ptr<blink::WebAudioDevice> CreateAudioDevice(
avi5c77d212015-09-25 20:08:25113 unsigned input_channels,
114 unsigned channels,
andrew.macpherson4f85155e2017-02-13 10:51:01115 const blink::WebAudioLatencyHint& latency_hint,
avi5c77d212015-09-25 20:08:25116 blink::WebAudioDevice::RenderCallback* callback,
Max Morinf506af592018-04-17 12:23:32117 const blink::WebString& input_device_id) override;
[email protected]8d22e5872013-02-22 20:07:11118
Kinuko Yasuda74d1c9e2017-05-31 14:08:51119 bool DecodeAudioFileData(blink::WebAudioBus* destination_bus,
120 const char* audio_file_data,
121 size_t data_size) override;
[email protected]99902de2013-06-20 23:04:09122
Antonio Gomes0de024e92019-07-06 11:38:02123 scoped_refptr<media::AudioCapturerSource> NewAudioCapturerSource(
124 blink::WebLocalFrame* web_frame,
125 const media::AudioSourceParameters& params) override;
Antonio Gomesa5b5ce42019-07-11 00:15:30126 viz::ContextProvider* SharedMainThreadContextProvider() override;
Antonio Gomesd27b0032019-07-16 17:06:30127 bool RTCSmoothnessAlgorithmEnabled() override;
Guido Urdanetadde6677e2019-03-08 10:58:50128 base::Optional<double> GetWebRtcMaxCaptureFrameRate() override;
Antonio Gomes0291c2c2019-06-27 00:55:51129 scoped_refptr<media::AudioRendererSink> NewAudioRendererSink(
130 blink::WebAudioDeviceSourceType source_type,
131 blink::WebLocalFrame* web_frame,
132 const media::AudioSinkParameters& params) override;
133 media::AudioLatency::LatencyType GetAudioSourceLatencyType(
134 blink::WebAudioDeviceSourceType source_type) override;
Antonio Gomes7743d5b92019-07-26 13:57:30135 base::Optional<std::string> GetWebRTCAudioProcessingConfiguration() override;
Antonio Gomesf7ed09872019-09-13 00:30:50136 bool ShouldEnforceWebRTCRoutingPreferences() override;
137 bool UsesFakeCodecForPeerConnection() override;
138 bool IsWebRtcEncryptionEnabled() override;
Antonio Gomes72027542019-10-08 15:30:10139 bool IsWebRtcStunOriginEnabled() override;
Antonio Gomesf7ed09872019-09-13 00:30:50140 base::Optional<std::string> WebRtcStunProbeTrialParameter() override;
Antonio Gomes0dcf8bd2019-09-12 18:09:40141 media::MediaPermission* GetWebRTCMediaPermission(
142 blink::WebLocalFrame* web_frame) override;
143 void GetWebRTCRendererPreferences(blink::WebLocalFrame* web_frame,
144 blink::WebString* ip_handling_policy,
145 uint16_t* udp_min_port,
Qingsi Wang337dc7a2019-10-29 01:02:04146 uint16_t* udp_max_port,
147 bool* allow_mdns_obfuscation) override;
Antonio Gomes7743d5b92019-07-26 13:57:30148 base::Optional<int> GetAgcStartupMinimumVolume() override;
Antonio Gomes6dfeca352019-08-28 13:45:03149 bool IsWebRtcHWH264DecodingEnabled(
150 webrtc::VideoCodecType video_coded_type) override;
Antonio Gomes92f054a12019-09-06 02:07:32151 bool IsWebRtcHWEncodingEnabled() override;
152 bool IsWebRtcHWDecodingEnabled() override;
Antonio Gomes69b17812019-10-13 11:48:46153 bool IsWebRtcSrtpAesGcmEnabled() override;
154 bool IsWebRtcSrtpEncryptedHeadersEnabled() override;
Antonio Gomesaf639cd2019-09-10 14:17:46155 bool AllowsLoopbackInPeerConnection() override;
Antonio Gomes92f054a12019-09-06 02:07:32156
Antonio Gomes493550b72019-07-31 08:12:44157 blink::WebVideoCaptureImplManager* GetVideoCaptureImplManager() override;
Guido Urdanetadde6677e2019-03-08 10:58:50158
altimineb6bd1962017-05-03 14:52:38159 std::unique_ptr<blink::WebGraphicsContext3DProvider>
160 CreateOffscreenGraphicsContext3DProvider(
danakj6ee20a02016-04-02 01:08:45161 const blink::Platform::ContextAttributes& attributes,
162 const blink::WebURL& top_document_web_url,
danakjf0799392016-05-19 21:44:17163 blink::Platform::GraphicsInfo* gl_info) override;
altimineb6bd1962017-05-03 14:52:38164 std::unique_ptr<blink::WebGraphicsContext3DProvider>
Blink Reformat1c4d759e2017-04-09 16:34:54165 CreateSharedOffscreenGraphicsContext3DProvider() override;
Kai Ninomiya05c10502018-08-30 20:06:21166 std::unique_ptr<blink::WebGraphicsContext3DProvider>
167 CreateWebGPUGraphicsContext3DProvider(
Austin Eng479265de2019-11-08 02:05:04168 const blink::WebURL& top_document_web_url) override;
Blink Reformat1c4d759e2017-04-09 16:34:54169 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override;
Blink Reformat1c4d759e2017-04-09 16:34:54170 blink::WebString ConvertIDNToUnicode(const blink::WebString& host) override;
Yuta Kitamura88c843772018-09-28 12:33:54171 void SetDisplayThreadPriority(base::PlatformThreadId thread_id) override;
Blink Reformat1c4d759e2017-04-09 16:34:54172 blink::BlameContext* GetTopLevelBlameContext() override;
173 void RecordRappor(const char* metric,
avi5c77d212015-09-25 20:08:25174 const blink::WebString& sample) override;
Blink Reformat1c4d759e2017-04-09 16:34:54175 void RecordRapporURL(const char* metric, const blink::WebURL& url) override;
Dean Liao0036a65f2019-03-27 01:35:44176
Hiroki Nakagawa9e2bb272019-02-12 07:17:43177 std::unique_ptr<blink::WebDedicatedWorkerHostFactoryClient>
178 CreateDedicatedWorkerHostFactoryClient(
179 blink::WebDedicatedWorker*,
Miyoung Shin996cb652019-11-28 03:27:22180 const blink::BrowserInterfaceBrokerProxy&) override;
John Abd-El-Malekf75a3192017-10-22 14:23:20181 void DidStartWorkerThread() override;
182 void WillStopWorkerThread() override;
Blink Reformat1c4d759e2017-04-09 16:34:54183 void WorkerContextCreated(const v8::Local<v8::Context>& worker) override;
Leon Hanb6bd8e62019-05-29 03:18:20184 bool IsExcludedHeaderForServiceWorkerFetchEvent(
185 const blink::WebString& header_name) override;
iclelland5c7359f2016-02-10 22:59:35186
Aditya Keerthie84331b32019-03-20 15:25:52187 void RecordMetricsForBackgroundedRendererPurge() override;
188
Kinuko Yasuda017b79e62017-10-24 17:46:10189 std::unique_ptr<blink::WebURLLoaderFactory> CreateDefaultURLLoaderFactory()
190 override;
Mythri Alle8f45f412018-08-28 10:44:07191 std::unique_ptr<blink::CodeCacheLoader> CreateCodeCacheLoader() override;
Bill Budge24c1dc1a2018-09-25 18:51:32192
Marijn Kruisselbrink20c2e292018-02-09 22:07:57193 std::unique_ptr<blink::WebURLLoaderFactory> WrapURLLoaderFactory(
194 mojo::ScopedMessagePipeHandle url_loader_factory_handle) override;
Matt Falkenhagend7e6a5622018-05-25 13:12:48195 std::unique_ptr<blink::WebURLLoaderFactory> WrapSharedURLLoaderFactory(
196 scoped_refptr<network::SharedURLLoaderFactory> factory) override;
tasak99717062017-02-15 06:34:06197
Miyoung Shinccbe33232019-06-19 04:14:30198 media::GpuVideoAcceleratorFactories* GetGpuFactories() override;
199
Tsuyoshi Horoe4b17a32017-08-25 16:01:13200 // Returns non-null.
201 // It is invalid to call this in an incomplete env where
202 // RenderThreadImpl::current() returns nullptr (e.g. in some tests).
Yuzhu Shen0c1715f2018-01-27 03:48:50203 scoped_refptr<ChildURLLoaderFactoryBundle>
204 CreateDefaultURLLoaderFactoryBundle();
Tsuyoshi Horoe4b17a32017-08-25 16:01:13205
Julie Jeongeun Kim2811b952019-10-24 00:36:12206 mojo::PendingRemote<network::mojom::URLLoaderFactory>
207 CreateNetworkURLLoaderFactory();
Kinuko Yasuda017b79e62017-10-24 17:46:10208
Nicolas Pena7c7847f2018-05-30 01:36:05209 // Tells this platform that the renderer is locked to a site (i.e., a scheme
210 // plus eTLD+1, such as https://google.com), or to a more specific origin.
211 void SetIsLockedToSite();
212
Yuzhu Shen0c1715f2018-01-27 03:48:50213 private:
[email protected]b808eb6f2010-05-18 17:09:33214 bool CheckPreparsedJsCachingEnabled() const;
215
Bill Budge24c1dc1a2018-09-25 18:51:32216 // Return the mojo interface for making CodeCache calls.
217 blink::mojom::CodeCacheHost& GetCodeCacheHost();
218
Chase Phillipsaf6f4962018-07-28 00:21:16219 scoped_refptr<base::SingleThreadTaskRunner> io_runner_;
rmcilroy321f924d2014-11-06 00:56:00220
Robert Sesek0694f7c2018-11-20 16:00:10221#if defined(OS_LINUX) || defined(OS_MACOSX)
222 std::unique_ptr<blink::WebSandboxSupport> sandbox_support_;
jbromanbae266e2015-03-09 16:52:57223#endif
[email protected]eb6f2c542009-10-02 04:53:59224
225 // This counter keeps track of the number of times sudden termination is
226 // enabled or disabled. It starts at 0 (enabled) and for every disable
227 // increments by 1, for every enable decrements by 1. When it reaches 0,
228 // we tell the browser to enable fast termination.
229 int sudden_termination_disables_;
[email protected]ab3505362009-10-30 18:11:47230
Nicolas Pena7c7847f2018-05-30 01:36:05231 // If true, the renderer process is locked to a site.
232 bool is_locked_to_site_;
233
rmcilroy321f924d2014-11-06 00:56:00234 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_;
[email protected]b180a0bb2013-03-06 00:36:10235 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
[email protected]c29b7ff2013-03-06 03:51:04236
Yuta Kitamura3331f5c2018-04-05 11:12:25237 // NOT OWNED
Yuta Kitamuradeb91bb2018-05-29 05:53:20238 blink::scheduler::WebThreadScheduler* main_thread_scheduler_;
Yuta Kitamura3331f5c2018-04-05 11:12:25239
skyostilb4cce1b2016-03-31 17:56:34240 TopLevelBlameContext top_level_blame_context_;
alexclarke82256242015-11-06 09:26:12241
Julie Jeongeun Kime5e7fd8b2019-09-03 16:53:46242 mojo::PendingRemote<blink::mojom::CodeCacheHost> code_cache_host_remote_;
243 mojo::SharedRemote<blink::mojom::CodeCacheHost> code_cache_host_;
Bill Budge24c1dc1a2018-09-25 18:51:32244
Dominik Röttschesac240042018-07-06 09:52:40245#if defined(OS_LINUX)
Dominik Röttschesac240042018-07-06 09:52:40246 sk_sp<font_service::FontLoader> font_loader_;
247#endif
248
danakj954b09b2017-11-02 17:56:47249 THREAD_CHECKER(main_thread_checker_);
250
tfarina556a7232014-10-05 01:02:09251 DISALLOW_COPY_AND_ASSIGN(RendererBlinkPlatformImpl);
[email protected]8d86fce2009-02-26 23:37:55252};
253
[email protected]e9ff79c2012-10-19 21:31:26254} // namespace content
255
tfarina556a7232014-10-05 01:02:09256#endif // CONTENT_RENDERER_RENDERER_BLINK_PLATFORM_IMPL_H_