1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/renderer_webkitplatformsupport_impl.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/lazy_instance.h"
10 #include "base/memory/shared_memory.h"
11 #include "base/message_loop/message_loop_proxy.h"
12 #include "base/metrics/histogram.h"
13 #include "base/platform_file.h"
14 #include "base/safe_numerics.h"
15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/utf_string_conversions.h"
17 #include "content/child/database_util.h"
18 #include "content/child/fileapi/webfilesystem_impl.h"
19 #include "content/child/indexed_db/proxy_webidbfactory_impl.h"
20 #include "content/child/npapi/npobject_util.h"
21 #include "content/child/quota_dispatcher.h"
22 #include "content/child/quota_message_filter.h"
23 #include "content/child/thread_safe_sender.h"
24 #include "content/child/webblobregistry_impl.h"
25 #include "content/child/webmessageportchannel_impl.h"
26 #include "content/common/file_utilities_messages.h"
27 #include "content/common/gpu/client/context_provider_command_buffer.h"
28 #include "content/common/gpu/client/gpu_channel_host.h"
29 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
30 #include "content/common/gpu/gpu_process_launch_causes.h"
31 #include "content/common/mime_registry_messages.h"
32 #include "content/common/view_messages.h"
33 #include "content/public/common/content_switches.h"
34 #include "content/public/common/webplugininfo.h"
35 #include "content/public/renderer/content_renderer_client.h"
36 #include "content/renderer/device_orientation/device_motion_event_pump.h"
37 #include "content/renderer/device_orientation/device_orientation_event_pump.h"
38 #include "content/renderer/dom_storage/webstoragenamespace_impl.h"
39 #include "content/renderer/gamepad_shared_memory_reader.h"
40 #include "content/renderer/media/audio_decoder.h"
41 #include "content/renderer/media/crypto/key_systems.h"
42 #include "content/renderer/media/media_stream_dependency_factory.h"
43 #include "content/renderer/media/renderer_webaudiodevice_impl.h"
44 #include "content/renderer/media/renderer_webmidiaccessor_impl.h"
45 #include "content/renderer/media/webcontentdecryptionmodule_impl.h"
46 #include "content/renderer/render_thread_impl.h"
47 #include "content/renderer/renderer_clipboard_client.h"
48 #include "content/renderer/webclipboard_impl.h"
49 #include "content/renderer/webcrypto/webcrypto_impl.h"
50 #include "content/renderer/websharedworkerrepository_impl.h"
51 #include "gpu/config/gpu_info.h"
52 #include "ipc/ipc_sync_message_filter.h"
53 #include "media/audio/audio_output_device.h"
54 #include "media/base/audio_hardware_config.h"
55 #include "media/filters/stream_parser_factory.h"
56 #include "net/base/mime_util.h"
57 #include "net/base/net_util.h"
58 #include "third_party/WebKit/public/platform/WebBlobRegistry.h"
59 #include "third_party/WebKit/public/platform/WebDeviceMotionListener.h"
60 #include "third_party/WebKit/public/platform/WebDeviceOrientationListener.h"
61 #include "third_party/WebKit/public/platform/WebFileInfo.h"
62 #include "third_party/WebKit/public/platform/WebGamepads.h"
63 #include "third_party/WebKit/public/platform/WebMediaStreamCenter.h"
64 #include "third_party/WebKit/public/platform/WebMediaStreamCenterClient.h"
65 #include "third_party/WebKit/public/platform/WebPluginListBuilder.h"
66 #include "third_party/WebKit/public/platform/WebURL.h"
67 #include "third_party/WebKit/public/platform/WebVector.h"
68 #include "third_party/WebKit/public/web/WebFrame.h"
69 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
71 #include "webkit/common/gpu/webgraphicscontext3d_provider_impl.h"
72 #include "webkit/common/quota/quota_types.h"
73 #include "webkit/glue/simple_webmimeregistry_impl.h"
74 #include "webkit/glue/webfileutilities_impl.h"
75 #include "webkit/glue/webkit_glue.h"
78 #include "content/common/child_process_messages.h"
79 #include "third_party/WebKit/public/platform/win/WebSandboxSupport.h"
82 #if defined(OS_MACOSX)
83 #include "content/common/mac/font_descriptor.h"
84 #include "content/common/mac/font_loader.h"
85 #include "third_party/WebKit/public/platform/mac/WebSandboxSupport.h"
88 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
92 #include "base/synchronization/lock.h"
93 #include "content/common/child_process_sandbox_support_impl_linux.h"
94 #include "third_party/WebKit/public/platform/linux/WebFontFamily.h"
95 #include "third_party/WebKit/public/platform/linux/WebSandboxSupport.h"
96 #include "third_party/icu/source/common/unicode/utf16.h"
100 #include "base/file_descriptor_posix.h"
103 #if defined(OS_ANDROID)
104 #include "content/renderer/media/android/audio_decoder_android.h"
107 using WebKit::WebAudioDevice
;
108 using WebKit::WebBlobRegistry
;
109 using WebKit::WebFileInfo
;
110 using WebKit::WebFileSystem
;
111 using WebKit::WebFrame
;
112 using WebKit::WebGamepads
;
113 using WebKit::WebIDBFactory
;
114 using WebKit::WebMIDIAccessor
;
115 using WebKit::Platform
;
116 using WebKit::WebMediaStreamCenter
;
117 using WebKit::WebMediaStreamCenterClient
;
118 using WebKit::WebMimeRegistry
;
119 using WebKit::WebRTCPeerConnectionHandler
;
120 using WebKit::WebRTCPeerConnectionHandlerClient
;
121 using WebKit::WebStorageNamespace
;
122 using WebKit::WebString
;
123 using WebKit::WebURL
;
124 using WebKit::WebVector
;
128 static bool g_sandbox_enabled
= true;
129 base::LazyInstance
<WebGamepads
>::Leaky g_test_gamepads
=
130 LAZY_INSTANCE_INITIALIZER
;
131 base::LazyInstance
<WebKit::WebDeviceMotionData
>::Leaky
132 g_test_device_motion_data
= LAZY_INSTANCE_INITIALIZER
;
133 base::LazyInstance
<WebKit::WebDeviceOrientationData
>::Leaky
134 g_test_device_orientation_data
= LAZY_INSTANCE_INITIALIZER
;
136 //------------------------------------------------------------------------------
138 class RendererWebKitPlatformSupportImpl::MimeRegistry
139 : public webkit_glue::SimpleWebMimeRegistryImpl
{
141 virtual WebKit::WebMimeRegistry::SupportsType
supportsMediaMIMEType(
142 const WebKit::WebString
& mime_type
,
143 const WebKit::WebString
& codecs
,
144 const WebKit::WebString
& key_system
);
145 virtual bool supportsMediaSourceMIMEType(const WebKit::WebString
& mime_type
,
146 const WebKit::WebString
& codecs
);
147 virtual WebKit::WebString
mimeTypeForExtension(
148 const WebKit::WebString
& file_extension
);
149 virtual WebKit::WebString
mimeTypeFromFile(
150 const WebKit::WebString
& file_path
);
153 class RendererWebKitPlatformSupportImpl::FileUtilities
154 : public webkit_glue::WebFileUtilitiesImpl
{
156 explicit FileUtilities(ThreadSafeSender
* sender
)
157 : thread_safe_sender_(sender
) {}
158 virtual bool getFileInfo(const WebString
& path
, WebFileInfo
& result
);
160 bool SendSyncMessageFromAnyThread(IPC::SyncMessage
* msg
) const;
161 scoped_refptr
<ThreadSafeSender
> thread_safe_sender_
;
164 #if defined(OS_ANDROID)
165 // WebKit doesn't use WebSandboxSupport on android so we don't need to
166 // implement anything here.
167 class RendererWebKitPlatformSupportImpl::SandboxSupport
{
170 class RendererWebKitPlatformSupportImpl::SandboxSupport
171 : public WebKit::WebSandboxSupport
{
173 virtual ~SandboxSupport() {}
176 virtual bool ensureFontLoaded(HFONT
);
177 #elif defined(OS_MACOSX)
178 virtual bool loadFont(
180 CGFontRef
* container
,
182 #elif defined(OS_POSIX)
183 virtual void getFontFamilyForCharacter(
184 WebKit::WebUChar32 character
,
185 const char* preferred_locale
,
186 WebKit::WebFontFamily
* family
);
187 virtual void getRenderStyleForStrike(
188 const char* family
, int sizeAndStyle
, WebKit::WebFontRenderStyle
* out
);
191 // WebKit likes to ask us for the correct font family to use for a set of
192 // unicode code points. It needs this information frequently so we cache it
194 base::Lock unicode_font_families_mutex_
;
195 std::map
<int32_t, WebKit::WebFontFamily
> unicode_font_families_
;
198 #endif // defined(OS_ANDROID)
200 //------------------------------------------------------------------------------
202 RendererWebKitPlatformSupportImpl::RendererWebKitPlatformSupportImpl()
203 : clipboard_client_(new RendererClipboardClient
),
204 clipboard_(new WebClipboardImpl(clipboard_client_
.get())),
205 mime_registry_(new RendererWebKitPlatformSupportImpl::MimeRegistry
),
206 sudden_termination_disables_(0),
207 plugin_refresh_allowed_(true),
208 shared_worker_repository_(new WebSharedWorkerRepositoryImpl
),
209 child_thread_loop_(base::MessageLoopProxy::current()) {
210 if (g_sandbox_enabled
&& sandboxEnabled()) {
211 sandbox_support_
.reset(
212 new RendererWebKitPlatformSupportImpl::SandboxSupport
);
214 DVLOG(1) << "Disabling sandbox support for testing.";
217 // ChildThread may not exist in some tests.
218 if (ChildThread::current()) {
219 sync_message_filter_
= ChildThread::current()->sync_message_filter();
220 thread_safe_sender_
= ChildThread::current()->thread_safe_sender();
221 quota_message_filter_
= ChildThread::current()->quota_message_filter();
222 blob_registry_
.reset(new WebBlobRegistryImpl(thread_safe_sender_
));
226 RendererWebKitPlatformSupportImpl::~RendererWebKitPlatformSupportImpl() {
227 WebFileSystemImpl::DeleteThreadSpecificInstance();
230 //------------------------------------------------------------------------------
232 WebKit::WebClipboard
* RendererWebKitPlatformSupportImpl::clipboard() {
233 WebKit::WebClipboard
* clipboard
=
234 GetContentClient()->renderer()->OverrideWebClipboard();
237 return clipboard_
.get();
240 WebKit::WebMimeRegistry
* RendererWebKitPlatformSupportImpl::mimeRegistry() {
241 return mime_registry_
.get();
244 WebKit::WebFileUtilities
*
245 RendererWebKitPlatformSupportImpl::fileUtilities() {
246 if (!file_utilities_
) {
247 file_utilities_
.reset(new FileUtilities(thread_safe_sender_
.get()));
248 file_utilities_
->set_sandbox_enabled(sandboxEnabled());
250 return file_utilities_
.get();
253 WebKit::WebSandboxSupport
* RendererWebKitPlatformSupportImpl::sandboxSupport() {
254 #if defined(OS_ANDROID)
255 // WebKit doesn't use WebSandboxSupport on android.
258 return sandbox_support_
.get();
262 WebKit::WebCookieJar
* RendererWebKitPlatformSupportImpl::cookieJar() {
263 NOTREACHED() << "Use WebFrameClient::cookieJar() instead!";
267 WebKit::WebThemeEngine
* RendererWebKitPlatformSupportImpl::themeEngine() {
268 WebKit::WebThemeEngine
* theme_engine
=
269 GetContentClient()->renderer()->OverrideThemeEngine();
272 return WebKitPlatformSupportImpl::themeEngine();
275 bool RendererWebKitPlatformSupportImpl::sandboxEnabled() {
276 // As explained in Platform.h, this function is used to decide
277 // whether to allow file system operations to come out of WebKit or not.
278 // Even if the sandbox is disabled, there's no reason why the code should
279 // act any differently...unless we're in single process mode. In which
280 // case, we have no other choice. Platform.h discourages using
281 // this switch unless absolutely necessary, so hopefully we won't end up
282 // with too many code paths being different in single-process mode.
283 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess
);
286 unsigned long long RendererWebKitPlatformSupportImpl::visitedLinkHash(
287 const char* canonical_url
,
289 return GetContentClient()->renderer()->VisitedLinkHash(canonical_url
, length
);
292 bool RendererWebKitPlatformSupportImpl::isLinkVisited(
293 unsigned long long link_hash
) {
294 return GetContentClient()->renderer()->IsLinkVisited(link_hash
);
297 WebKit::WebMessagePortChannel
*
298 RendererWebKitPlatformSupportImpl::createMessagePortChannel() {
299 return new WebMessagePortChannelImpl(child_thread_loop_
.get());
302 WebKit::WebPrescientNetworking
*
303 RendererWebKitPlatformSupportImpl::prescientNetworking() {
304 return GetContentClient()->renderer()->GetPrescientNetworking();
308 RendererWebKitPlatformSupportImpl::CheckPreparsedJsCachingEnabled() const {
309 static bool checked
= false;
310 static bool result
= false;
312 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
313 result
= command_line
.HasSwitch(switches::kEnablePreparsedJsCaching
);
319 void RendererWebKitPlatformSupportImpl::cacheMetadata(
320 const WebKit::WebURL
& url
,
321 double response_time
,
324 if (!CheckPreparsedJsCachingEnabled())
327 // Let the browser know we generated cacheable metadata for this resource. The
328 // browser may cache it and return it on subsequent responses to speed
329 // the processing of this resource.
330 std::vector
<char> copy(data
, data
+ size
);
331 RenderThread::Get()->Send(
332 new ViewHostMsg_DidGenerateCacheableMetadata(url
, response_time
, copy
));
335 WebString
RendererWebKitPlatformSupportImpl::defaultLocale() {
336 return ASCIIToUTF16(RenderThread::Get()->GetLocale());
339 void RendererWebKitPlatformSupportImpl::suddenTerminationChanged(bool enabled
) {
341 // We should not get more enables than disables, but we want it to be a
342 // non-fatal error if it does happen.
343 DCHECK_GT(sudden_termination_disables_
, 0);
344 sudden_termination_disables_
= std::max(sudden_termination_disables_
- 1,
346 if (sudden_termination_disables_
!= 0)
349 sudden_termination_disables_
++;
350 if (sudden_termination_disables_
!= 1)
354 RenderThread
* thread
= RenderThread::Get();
355 if (thread
) // NULL in unittests.
356 thread
->Send(new ViewHostMsg_SuddenTerminationChanged(enabled
));
360 RendererWebKitPlatformSupportImpl::createLocalStorageNamespace() {
361 return new WebStorageNamespaceImpl();
365 //------------------------------------------------------------------------------
367 WebIDBFactory
* RendererWebKitPlatformSupportImpl::idbFactory() {
368 if (!web_idb_factory_
)
369 web_idb_factory_
.reset(
370 new RendererWebIDBFactoryImpl(thread_safe_sender_
.get()));
371 return web_idb_factory_
.get();
374 //------------------------------------------------------------------------------
376 WebFileSystem
* RendererWebKitPlatformSupportImpl::fileSystem() {
377 return WebFileSystemImpl::ThreadSpecificInstance(child_thread_loop_
.get());
380 //------------------------------------------------------------------------------
382 WebMimeRegistry::SupportsType
383 RendererWebKitPlatformSupportImpl::MimeRegistry::supportsMediaMIMEType(
384 const WebString
& mime_type
,
385 const WebString
& codecs
,
386 const WebString
& key_system
) {
387 const std::string mime_type_ascii
= ToASCIIOrEmpty(mime_type
);
388 // Not supporting the container is a flat-out no.
389 if (!net::IsSupportedMediaMimeType(mime_type_ascii
))
390 return IsNotSupported
;
392 if (!key_system
.isEmpty()) {
393 // Check whether the key system is supported with the mime_type and codecs.
395 std::vector
<std::string
> strict_codecs
;
396 bool strip_suffix
= !net::IsStrictMediaMimeType(mime_type_ascii
);
397 net::ParseCodecString(ToASCIIOrEmpty(codecs
), &strict_codecs
, strip_suffix
);
399 if (!IsSupportedKeySystemWithMediaMimeType(
400 mime_type_ascii
, strict_codecs
, ToASCIIOrEmpty(key_system
)))
401 return IsNotSupported
;
403 // Continue processing the mime_type and codecs.
406 // Check list of strict codecs to see if it is supported.
407 if (net::IsStrictMediaMimeType(mime_type_ascii
)) {
408 // We support the container, but no codecs were specified.
410 return MayBeSupported
;
412 // Check if the codecs are a perfect match.
413 std::vector
<std::string
> strict_codecs
;
414 net::ParseCodecString(ToASCIIOrEmpty(codecs
), &strict_codecs
, false);
415 if (!net::IsSupportedStrictMediaMimeType(mime_type_ascii
, strict_codecs
))
416 return IsNotSupported
;
422 // If we don't recognize the codec, it's possible we support it.
423 std::vector
<std::string
> parsed_codecs
;
424 net::ParseCodecString(ToASCIIOrEmpty(codecs
), &parsed_codecs
, true);
425 if (!net::AreSupportedMediaCodecs(parsed_codecs
))
426 return MayBeSupported
;
428 // Otherwise we have a perfect match.
433 RendererWebKitPlatformSupportImpl::MimeRegistry::supportsMediaSourceMIMEType(
434 const WebKit::WebString
& mime_type
,
435 const WebString
& codecs
) {
436 const std::string mime_type_ascii
= ToASCIIOrEmpty(mime_type
);
437 std::vector
<std::string
> parsed_codec_ids
;
438 net::ParseCodecString(ToASCIIOrEmpty(codecs
), &parsed_codec_ids
, false);
439 if (mime_type_ascii
.empty())
441 return media::StreamParserFactory::IsTypeSupported(
442 mime_type_ascii
, parsed_codec_ids
);
446 RendererWebKitPlatformSupportImpl::MimeRegistry::mimeTypeForExtension(
447 const WebString
& file_extension
) {
448 if (IsPluginProcess())
449 return SimpleWebMimeRegistryImpl::mimeTypeForExtension(file_extension
);
451 // The sandbox restricts our access to the registry, so we need to proxy
452 // these calls over to the browser process.
453 std::string mime_type
;
454 RenderThread::Get()->Send(
455 new MimeRegistryMsg_GetMimeTypeFromExtension(
456 base::FilePath::FromUTF16Unsafe(file_extension
).value(), &mime_type
));
457 return ASCIIToUTF16(mime_type
);
460 WebString
RendererWebKitPlatformSupportImpl::MimeRegistry::mimeTypeFromFile(
461 const WebString
& file_path
) {
462 if (IsPluginProcess())
463 return SimpleWebMimeRegistryImpl::mimeTypeFromFile(file_path
);
465 // The sandbox restricts our access to the registry, so we need to proxy
466 // these calls over to the browser process.
467 std::string mime_type
;
468 RenderThread::Get()->Send(new MimeRegistryMsg_GetMimeTypeFromFile(
469 base::FilePath::FromUTF16Unsafe(file_path
),
471 return ASCIIToUTF16(mime_type
);
474 //------------------------------------------------------------------------------
476 bool RendererWebKitPlatformSupportImpl::FileUtilities::getFileInfo(
477 const WebString
& path
,
478 WebFileInfo
& web_file_info
) {
479 base::PlatformFileInfo file_info
;
480 base::PlatformFileError status
;
481 if (!SendSyncMessageFromAnyThread(new FileUtilitiesMsg_GetFileInfo(
482 base::FilePath::FromUTF16Unsafe(path
), &file_info
, &status
)) ||
483 status
!= base::PLATFORM_FILE_OK
) {
486 webkit_glue::PlatformFileInfoToWebFileInfo(file_info
, &web_file_info
);
487 web_file_info
.platformPath
= path
;
491 bool RendererWebKitPlatformSupportImpl::FileUtilities::
492 SendSyncMessageFromAnyThread(IPC::SyncMessage
* msg
) const {
493 base::TimeTicks begin
= base::TimeTicks::Now();
494 const bool success
= thread_safe_sender_
->Send(msg
);
495 base::TimeDelta delta
= base::TimeTicks::Now() - begin
;
496 UMA_HISTOGRAM_TIMES("RendererSyncIPC.ElapsedTime", delta
);
500 //------------------------------------------------------------------------------
504 bool RendererWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded(
507 GetObject(font
, sizeof(LOGFONT
), &logfont
);
508 RenderThread::Get()->PreCacheFont(logfont
);
512 #elif defined(OS_MACOSX)
514 bool RendererWebKitPlatformSupportImpl::SandboxSupport::loadFont(
515 NSFont
* src_font
, CGFontRef
* out
, uint32
* font_id
) {
516 uint32 font_data_size
;
517 FontDescriptor
src_font_descriptor(src_font
);
518 base::SharedMemoryHandle font_data
;
519 if (!RenderThread::Get()->Send(new ViewHostMsg_LoadFont(
520 src_font_descriptor
, &font_data_size
, &font_data
, font_id
))) {
526 if (font_data_size
== 0 || font_data
== base::SharedMemory::NULLHandle() ||
528 LOG(ERROR
) << "Bad response from ViewHostMsg_LoadFont() for " <<
529 src_font_descriptor
.font_name
;
535 // TODO(jeremy): Need to call back into WebKit to make sure that the font
536 // isn't already activated, based on the font id. If it's already
537 // activated, don't reactivate it here - crbug.com/72727 .
539 return FontLoader::CGFontRefFromBuffer(font_data
, font_data_size
, out
);
542 #elif defined(OS_ANDROID)
544 // WebKit doesn't use WebSandboxSupport on android so we don't need to
545 // implement anything here. This is cleaner to support than excluding the
546 // whole class for android.
548 #elif defined(OS_POSIX)
551 RendererWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacter(
552 WebKit::WebUChar32 character
,
553 const char* preferred_locale
,
554 WebKit::WebFontFamily
* family
) {
555 base::AutoLock
lock(unicode_font_families_mutex_
);
556 const std::map
<int32_t, WebKit::WebFontFamily
>::const_iterator iter
=
557 unicode_font_families_
.find(character
);
558 if (iter
!= unicode_font_families_
.end()) {
559 family
->name
= iter
->second
.name
;
560 family
->isBold
= iter
->second
.isBold
;
561 family
->isItalic
= iter
->second
.isItalic
;
565 GetFontFamilyForCharacter(character
, preferred_locale
, family
);
566 unicode_font_families_
.insert(std::make_pair(character
, *family
));
570 RendererWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike(
571 const char* family
, int sizeAndStyle
, WebKit::WebFontRenderStyle
* out
) {
572 GetRenderStyleForStrike(family
, sizeAndStyle
, out
);
577 //------------------------------------------------------------------------------
580 RendererWebKitPlatformSupportImpl::databaseOpenFile(
581 const WebString
& vfs_file_name
, int desired_flags
) {
582 return DatabaseUtil::DatabaseOpenFile(
583 vfs_file_name
, desired_flags
, sync_message_filter_
.get());
586 int RendererWebKitPlatformSupportImpl::databaseDeleteFile(
587 const WebString
& vfs_file_name
, bool sync_dir
) {
588 return DatabaseUtil::DatabaseDeleteFile(
589 vfs_file_name
, sync_dir
, sync_message_filter_
.get());
592 long RendererWebKitPlatformSupportImpl::databaseGetFileAttributes(
593 const WebString
& vfs_file_name
) {
594 return DatabaseUtil::DatabaseGetFileAttributes(vfs_file_name
,
595 sync_message_filter_
.get());
598 long long RendererWebKitPlatformSupportImpl::databaseGetFileSize(
599 const WebString
& vfs_file_name
) {
600 return DatabaseUtil::DatabaseGetFileSize(vfs_file_name
,
601 sync_message_filter_
.get());
604 long long RendererWebKitPlatformSupportImpl::databaseGetSpaceAvailableForOrigin(
605 const WebString
& origin_identifier
) {
606 return DatabaseUtil::DatabaseGetSpaceAvailable(origin_identifier
,
607 sync_message_filter_
.get());
610 WebKit::WebSharedWorkerRepository
*
611 RendererWebKitPlatformSupportImpl::sharedWorkerRepository() {
612 #if !defined(OS_ANDROID)
613 if (!CommandLine::ForCurrentProcess()->HasSwitch(
614 switches::kDisableSharedWorkers
)) {
615 return shared_worker_repository_
.get();
620 // Shared workers are unsupported on Android. Returning NULL will prevent the
621 // window.SharedWorker constructor from being exposed. http://crbug.com/154571
626 bool RendererWebKitPlatformSupportImpl::canAccelerate2dCanvas() {
627 RenderThreadImpl
* thread
= RenderThreadImpl::current();
628 GpuChannelHost
* host
= thread
->EstablishGpuChannelSync(
629 CAUSE_FOR_GPU_LAUNCH_CANVAS_2D
);
633 const gpu::GPUInfo
& gpu_info
= host
->gpu_info();
634 if (gpu_info
.can_lose_context
|| gpu_info
.software_rendering
)
640 bool RendererWebKitPlatformSupportImpl::isThreadedCompositingEnabled() {
641 return !!RenderThreadImpl::current()->compositor_message_loop_proxy().get();
644 double RendererWebKitPlatformSupportImpl::audioHardwareSampleRate() {
645 RenderThreadImpl
* thread
= RenderThreadImpl::current();
646 return thread
->GetAudioHardwareConfig()->GetOutputSampleRate();
649 size_t RendererWebKitPlatformSupportImpl::audioHardwareBufferSize() {
650 RenderThreadImpl
* thread
= RenderThreadImpl::current();
651 return thread
->GetAudioHardwareConfig()->GetOutputBufferSize();
654 unsigned RendererWebKitPlatformSupportImpl::audioHardwareOutputChannels() {
655 RenderThreadImpl
* thread
= RenderThreadImpl::current();
656 return thread
->GetAudioHardwareConfig()->GetOutputChannels();
659 // TODO(crogers): remove deprecated API as soon as WebKit calls new API.
661 RendererWebKitPlatformSupportImpl::createAudioDevice(
665 WebAudioDevice::RenderCallback
* callback
) {
666 return createAudioDevice(
667 buffer_size
, 0, channels
, sample_rate
, callback
, "default");
670 // TODO(crogers): remove deprecated API as soon as WebKit calls new API.
672 RendererWebKitPlatformSupportImpl::createAudioDevice(
674 unsigned input_channels
,
677 WebAudioDevice::RenderCallback
* callback
) {
678 return createAudioDevice(
679 buffer_size
, input_channels
, channels
, sample_rate
, callback
, "default");
683 RendererWebKitPlatformSupportImpl::createAudioDevice(
685 unsigned input_channels
,
688 WebAudioDevice::RenderCallback
* callback
,
689 const WebKit::WebString
& input_device_id
) {
690 // Use a mock for testing.
691 WebKit::WebAudioDevice
* mock_device
=
692 GetContentClient()->renderer()->OverrideCreateAudioDevice(sample_rate
);
696 // The |channels| does not exactly identify the channel layout of the
697 // device. The switch statement below assigns a best guess to the channel
698 // layout based on number of channels.
699 // TODO(crogers): WebKit should give the channel layout instead of the hard
701 media::ChannelLayout layout
= media::CHANNEL_LAYOUT_UNSUPPORTED
;
704 layout
= media::CHANNEL_LAYOUT_MONO
;
707 layout
= media::CHANNEL_LAYOUT_STEREO
;
710 layout
= media::CHANNEL_LAYOUT_2_1
;
713 layout
= media::CHANNEL_LAYOUT_4_0
;
716 layout
= media::CHANNEL_LAYOUT_5_0
;
719 layout
= media::CHANNEL_LAYOUT_5_1
;
722 layout
= media::CHANNEL_LAYOUT_7_0
;
725 layout
= media::CHANNEL_LAYOUT_7_1
;
728 layout
= media::CHANNEL_LAYOUT_STEREO
;
732 if (input_device_id
.isNull() ||
733 !base::StringToInt(UTF16ToUTF8(input_device_id
), &session_id
)) {
734 if (input_channels
> 0)
735 DLOG(WARNING
) << "createAudioDevice(): request for audio input ignored";
740 media::AudioParameters
params(
741 media::AudioParameters::AUDIO_PCM_LOW_LATENCY
,
742 layout
, input_channels
,
743 static_cast<int>(sample_rate
), 16, buffer_size
);
745 return new RendererWebAudioDeviceImpl(params
, callback
, session_id
);
748 #if defined(OS_ANDROID)
749 bool RendererWebKitPlatformSupportImpl::loadAudioResource(
750 WebKit::WebAudioBus
* destination_bus
, const char* audio_file_data
,
751 size_t data_size
, double sample_rate
) {
752 return DecodeAudioFileData(destination_bus
,
756 thread_safe_sender_
);
759 bool RendererWebKitPlatformSupportImpl::loadAudioResource(
760 WebKit::WebAudioBus
* destination_bus
, const char* audio_file_data
,
761 size_t data_size
, double sample_rate
) {
762 return DecodeAudioFileData(
763 destination_bus
, audio_file_data
, data_size
, sample_rate
);
765 #endif // defined(OS_ANDROID)
767 //------------------------------------------------------------------------------
769 WebKit::WebContentDecryptionModule
*
770 RendererWebKitPlatformSupportImpl::createContentDecryptionModule(
771 const WebKit::WebString
& key_system
) {
772 return WebContentDecryptionModuleImpl::Create(key_system
);
775 //------------------------------------------------------------------------------
777 WebKit::WebMIDIAccessor
*
778 RendererWebKitPlatformSupportImpl::createMIDIAccessor(
779 WebKit::WebMIDIAccessorClient
* client
) {
780 WebKit::WebMIDIAccessor
* accessor
=
781 GetContentClient()->renderer()->OverrideCreateMIDIAccessor(client
);
785 return new RendererWebMIDIAccessorImpl(client
);
788 void RendererWebKitPlatformSupportImpl::getPluginList(
790 WebKit::WebPluginListBuilder
* builder
) {
791 #if defined(ENABLE_PLUGINS)
792 std::vector
<WebPluginInfo
> plugins
;
793 if (!plugin_refresh_allowed_
)
795 RenderThread::Get()->Send(
796 new ViewHostMsg_GetPlugins(refresh
, &plugins
));
797 for (size_t i
= 0; i
< plugins
.size(); ++i
) {
798 const WebPluginInfo
& plugin
= plugins
[i
];
801 plugin
.name
, plugin
.desc
,
802 plugin
.path
.BaseName().AsUTF16Unsafe());
804 for (size_t j
= 0; j
< plugin
.mime_types
.size(); ++j
) {
805 const WebPluginMimeType
& mime_type
= plugin
.mime_types
[j
];
807 builder
->addMediaTypeToLastPlugin(
808 WebString::fromUTF8(mime_type
.mime_type
), mime_type
.description
);
810 for (size_t k
= 0; k
< mime_type
.file_extensions
.size(); ++k
) {
811 builder
->addFileExtensionToLastMediaType(
812 WebString::fromUTF8(mime_type
.file_extensions
[k
]));
819 //------------------------------------------------------------------------------
822 RendererWebKitPlatformSupportImpl::signedPublicKeyAndChallengeString(
823 unsigned key_size_index
,
824 const WebKit::WebString
& challenge
,
825 const WebKit::WebURL
& url
) {
826 std::string signed_public_key
;
827 RenderThread::Get()->Send(new ViewHostMsg_Keygen(
828 static_cast<uint32
>(key_size_index
),
831 &signed_public_key
));
832 return WebString::fromUTF8(signed_public_key
);
835 //------------------------------------------------------------------------------
837 void RendererWebKitPlatformSupportImpl::screenColorProfile(
838 WebVector
<char>* to_profile
) {
839 std::vector
<char> profile
;
840 RenderThread::Get()->Send(
841 new ViewHostMsg_GetMonitorColorProfile(&profile
));
842 *to_profile
= profile
;
845 //------------------------------------------------------------------------------
847 WebBlobRegistry
* RendererWebKitPlatformSupportImpl::blobRegistry() {
848 // blob_registry_ can be NULL when running some tests.
849 return blob_registry_
.get();
852 //------------------------------------------------------------------------------
854 void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads
& gamepads
) {
855 if (g_test_gamepads
== 0) {
856 RenderThreadImpl::current()->SampleGamepads(&gamepads
);
858 gamepads
= g_test_gamepads
.Get();
862 WebKit::WebString
RendererWebKitPlatformSupportImpl::userAgent(
863 const WebKit::WebURL
& url
) {
864 return WebKitPlatformSupportImpl::userAgent(url
);
867 //------------------------------------------------------------------------------
869 WebRTCPeerConnectionHandler
*
870 RendererWebKitPlatformSupportImpl::createRTCPeerConnectionHandler(
871 WebRTCPeerConnectionHandlerClient
* client
) {
872 RenderThreadImpl
* render_thread
= RenderThreadImpl::current();
873 DCHECK(render_thread
);
877 #if defined(ENABLE_WEBRTC)
878 WebRTCPeerConnectionHandler
* peer_connection_handler
=
879 GetContentClient()->renderer()->OverrideCreateWebRTCPeerConnectionHandler(
881 if (peer_connection_handler
)
882 return peer_connection_handler
;
884 MediaStreamDependencyFactory
* rtc_dependency_factory
=
885 render_thread
->GetMediaStreamDependencyFactory();
886 return rtc_dependency_factory
->CreateRTCPeerConnectionHandler(client
);
889 #endif // defined(ENABLE_WEBRTC)
892 //------------------------------------------------------------------------------
894 WebMediaStreamCenter
*
895 RendererWebKitPlatformSupportImpl::createMediaStreamCenter(
896 WebMediaStreamCenterClient
* client
) {
897 RenderThreadImpl
* render_thread
= RenderThreadImpl::current();
898 DCHECK(render_thread
);
901 return render_thread
->CreateMediaStreamCenter(client
);
905 bool RendererWebKitPlatformSupportImpl::SetSandboxEnabledForTesting(
907 bool was_enabled
= g_sandbox_enabled
;
908 g_sandbox_enabled
= enable
;
913 void RendererWebKitPlatformSupportImpl::SetMockGamepadsForTesting(
914 const WebGamepads
& pads
) {
915 g_test_gamepads
.Get() = pads
;
918 //------------------------------------------------------------------------------
920 WebKit::WebSpeechSynthesizer
*
921 RendererWebKitPlatformSupportImpl::createSpeechSynthesizer(
922 WebKit::WebSpeechSynthesizerClient
* client
) {
923 return GetContentClient()->renderer()->OverrideSpeechSynthesizer(client
);
926 //------------------------------------------------------------------------------
928 bool RendererWebKitPlatformSupportImpl::processMemorySizesInBytes(
929 size_t* private_bytes
, size_t* shared_bytes
) {
930 content::RenderThread::Get()->Send(
931 new ViewHostMsg_GetProcessMemorySizes(private_bytes
, shared_bytes
));
935 //------------------------------------------------------------------------------
937 WebKit::WebGraphicsContext3D
*
938 RendererWebKitPlatformSupportImpl::createOffscreenGraphicsContext3D(
939 const WebKit::WebGraphicsContext3D::Attributes
& attributes
) {
940 if (!RenderThreadImpl::current())
943 scoped_refptr
<GpuChannelHost
> gpu_channel_host(
944 RenderThreadImpl::current()->EstablishGpuChannelSync(
945 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE
));
946 return WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
947 gpu_channel_host
.get(),
949 GURL(attributes
.topDocumentURL
));
952 //------------------------------------------------------------------------------
954 WebKit::WebGraphicsContext3DProvider
* RendererWebKitPlatformSupportImpl::
955 createSharedOffscreenGraphicsContext3DProvider() {
956 scoped_refptr
<cc::ContextProvider
> provider
=
957 RenderThreadImpl::current()->SharedMainThreadContextProvider();
960 return new webkit::gpu::WebGraphicsContext3DProviderImpl(provider
);
963 //------------------------------------------------------------------------------
965 WebKit::WebCompositorSupport
*
966 RendererWebKitPlatformSupportImpl::compositorSupport() {
967 return &compositor_support_
;
970 //------------------------------------------------------------------------------
972 WebKit::WebString
RendererWebKitPlatformSupportImpl::convertIDNToUnicode(
973 const WebKit::WebString
& host
,
974 const WebKit::WebString
& languages
) {
975 return net::IDNToUnicode(host
.utf8(), languages
.utf8());
978 //------------------------------------------------------------------------------
980 void RendererWebKitPlatformSupportImpl::setDeviceMotionListener(
981 WebKit::WebDeviceMotionListener
* listener
) {
982 if (g_test_device_motion_data
== 0) {
983 if (!device_motion_event_pump_
) {
984 device_motion_event_pump_
.reset(new DeviceMotionEventPump
);
985 device_motion_event_pump_
->Attach(RenderThreadImpl::current());
987 device_motion_event_pump_
->SetListener(listener
);
988 } else if (listener
) {
989 // Testing mode: just echo the test data to the listener.
990 base::MessageLoopProxy::current()->PostTask(
992 base::Bind(&WebKit::WebDeviceMotionListener::didChangeDeviceMotion
,
993 base::Unretained(listener
),
994 g_test_device_motion_data
.Get()));
999 void RendererWebKitPlatformSupportImpl::SetMockDeviceMotionDataForTesting(
1000 const WebKit::WebDeviceMotionData
& data
) {
1001 g_test_device_motion_data
.Get() = data
;
1004 //------------------------------------------------------------------------------
1006 void RendererWebKitPlatformSupportImpl::setDeviceOrientationListener(
1007 WebKit::WebDeviceOrientationListener
* listener
) {
1008 if (g_test_device_orientation_data
== 0) {
1009 if (!device_orientation_event_pump_
) {
1010 device_orientation_event_pump_
.reset(new DeviceOrientationEventPump
);
1011 device_orientation_event_pump_
->Attach(RenderThreadImpl::current());
1013 device_orientation_event_pump_
->SetListener(listener
);
1014 } else if (listener
) {
1015 // Testing mode: just echo the test data to the listener.
1016 base::MessageLoopProxy::current()->PostTask(
1019 &WebKit::WebDeviceOrientationListener::didChangeDeviceOrientation
,
1020 base::Unretained(listener
),
1021 g_test_device_orientation_data
.Get()));
1026 void RendererWebKitPlatformSupportImpl::SetMockDeviceOrientationDataForTesting(
1027 const WebKit::WebDeviceOrientationData
& data
) {
1028 g_test_device_orientation_data
.Get() = data
;
1031 //------------------------------------------------------------------------------
1033 WebKit::WebCrypto
* RendererWebKitPlatformSupportImpl::crypto() {
1035 web_crypto_
.reset(new WebCryptoImpl());
1036 return web_crypto_
.get();
1040 //------------------------------------------------------------------------------
1042 #if defined(OS_ANDROID)
1043 void RendererWebKitPlatformSupportImpl::vibrate(unsigned int milliseconds
) {
1044 RenderThread::Get()->Send(
1045 new ViewHostMsg_Vibrate(base::checked_numeric_cast
<int64
>(milliseconds
)));
1048 void RendererWebKitPlatformSupportImpl::cancelVibration() {
1049 RenderThread::Get()->Send(new ViewHostMsg_CancelVibration());
1051 #endif // defined(OS_ANDROID)
1053 //------------------------------------------------------------------------------
1055 void RendererWebKitPlatformSupportImpl::queryStorageUsageAndQuota(
1056 const WebKit::WebURL
& storage_partition
,
1057 WebKit::WebStorageQuotaType type
,
1058 WebKit::WebStorageQuotaCallbacks
* callbacks
) {
1059 if (!thread_safe_sender_
.get() || !quota_message_filter_
.get())
1061 QuotaDispatcher::ThreadSpecificInstance(
1062 thread_safe_sender_
.get(),
1063 quota_message_filter_
.get())->QueryStorageUsageAndQuota(
1065 static_cast<quota::StorageType
>(type
),
1066 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks
));
1069 } // namespace content