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/file_path.h"
9 #include "base/file_util.h"
10 #include "base/lazy_instance.h"
11 #include "base/metrics/histogram.h"
12 #include "base/platform_file.h"
13 #include "base/shared_memory.h"
14 #include "base/utf_string_conversions.h"
15 #include "content/common/database_util.h"
16 #include "content/common/fileapi/webblobregistry_impl.h"
17 #include "content/common/fileapi/webfilesystem_impl.h"
18 #include "content/common/file_utilities_messages.h"
19 #include "content/common/indexed_db/proxy_webidbfactory_impl.h"
20 #include "content/common/mime_registry_messages.h"
21 #include "content/common/npobject_util.h"
22 #include "content/common/view_messages.h"
23 #include "content/common/webmessageportchannel_impl.h"
24 #include "content/public/common/content_switches.h"
25 #include "content/public/common/gpu_info.h"
26 #include "content/public/renderer/content_renderer_client.h"
27 #include "content/renderer/dom_storage/webstoragenamespace_impl.h"
28 #include "content/renderer/gamepad_shared_memory_reader.h"
29 #include "content/renderer/hyphenator/hyphenator.h"
30 #include "content/renderer/media/audio_hardware.h"
31 #include "content/renderer/media/media_stream_dependency_factory.h"
32 #include "content/renderer/media/renderer_webaudiodevice_impl.h"
33 #include "content/renderer/render_thread_impl.h"
34 #include "content/renderer/renderer_clipboard_client.h"
35 #include "content/renderer/websharedworkerrepository_impl.h"
36 #include "googleurl/src/gurl.h"
37 #include "ipc/ipc_sync_message_filter.h"
38 #include "media/audio/audio_output_device.h"
39 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebBlobRegistry.h"
40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h"
41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
42 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.h"
43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h"
44 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamCenter.h"
45 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamCenterClient.h"
46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
47 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
48 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
49 #include "webkit/base/file_path_string_conversions.h"
50 #include "webkit/glue/simple_webmimeregistry_impl.h"
51 #include "webkit/glue/webclipboard_impl.h"
52 #include "webkit/glue/webfileutilities_impl.h"
53 #include "webkit/glue/webkit_glue.h"
56 #include "content/common/child_process_messages.h"
57 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/win/WebSandboxSupport.h"
60 #if defined(OS_MACOSX)
61 #include "content/common/mac/font_descriptor.h"
62 #include "content/common/mac/font_loader.h"
63 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/mac/WebSandboxSupport.h"
66 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
70 #include "base/synchronization/lock.h"
71 #include "content/common/child_process_sandbox_support_impl_linux.h"
72 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/linux/WebFontFamily.h"
73 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/linux/WebSandboxSupport.h"
77 #include "base/file_descriptor_posix.h"
80 using WebKit::WebAudioDevice
;
81 using WebKit::WebBlobRegistry
;
82 using WebKit::WebFileInfo
;
83 using WebKit::WebFileSystem
;
84 using WebKit::WebFrame
;
85 using WebKit::WebGamepads
;
86 using WebKit::WebIDBFactory
;
87 using WebKit::WebKitPlatformSupport
;
88 using WebKit::WebMediaStreamCenter
;
89 using WebKit::WebMediaStreamCenterClient
;
90 using WebKit::WebRTCPeerConnectionHandler
;
91 using WebKit::WebRTCPeerConnectionHandlerClient
;
92 using WebKit::WebStorageNamespace
;
93 using WebKit::WebString
;
95 using WebKit::WebVector
;
99 static bool g_sandbox_enabled
= true;
100 base::LazyInstance
<WebGamepads
>::Leaky g_test_gamepads
=
101 LAZY_INSTANCE_INITIALIZER
;
103 //------------------------------------------------------------------------------
105 class RendererWebKitPlatformSupportImpl::MimeRegistry
106 : public webkit_glue::SimpleWebMimeRegistryImpl
{
108 virtual WebKit::WebString
mimeTypeForExtension(const WebKit::WebString
&);
109 virtual WebKit::WebString
mimeTypeFromFile(const WebKit::WebString
&);
110 virtual WebKit::WebString
preferredExtensionForMIMEType(
111 const WebKit::WebString
&);
114 class RendererWebKitPlatformSupportImpl::FileUtilities
115 : public webkit_glue::WebFileUtilitiesImpl
{
117 virtual bool getFileInfo(const WebString
& path
, WebFileInfo
& result
);
118 virtual base::PlatformFile
openFile(const WebKit::WebString
& path
,
122 #if defined(OS_ANDROID)
123 // WebKit doesn't use WebSandboxSupport on android so we don't need to
124 // implement anything here.
125 class RendererWebKitPlatformSupportImpl::SandboxSupport
{
128 class RendererWebKitPlatformSupportImpl::SandboxSupport
129 : public WebKit::WebSandboxSupport
{
131 virtual ~SandboxSupport() {}
134 virtual bool ensureFontLoaded(HFONT
);
135 #elif defined(OS_MACOSX)
136 virtual bool loadFont(
138 CGFontRef
* container
,
140 #elif defined(OS_POSIX)
141 virtual void getFontFamilyForCharacters(
142 const WebKit::WebUChar
* characters
,
143 size_t numCharacters
,
144 const char* preferred_locale
,
145 WebKit::WebFontFamily
* family
);
146 virtual void getRenderStyleForStrike(
147 const char* family
, int sizeAndStyle
, WebKit::WebFontRenderStyle
* out
);
150 // WebKit likes to ask us for the correct font family to use for a set of
151 // unicode code points. It needs this information frequently so we cache it
152 // here. The key in this map is an array of 16-bit UTF16 values from WebKit.
153 // The value is a string containing the correct font family.
154 base::Lock unicode_font_families_mutex_
;
155 std::map
<string16
, WebKit::WebFontFamily
> unicode_font_families_
;
158 #endif // defined(OS_ANDROID)
160 //------------------------------------------------------------------------------
162 RendererWebKitPlatformSupportImpl::RendererWebKitPlatformSupportImpl()
163 : clipboard_client_(new RendererClipboardClient
),
164 clipboard_(new webkit_glue::WebClipboardImpl(clipboard_client_
.get())),
165 mime_registry_(new RendererWebKitPlatformSupportImpl::MimeRegistry
),
166 sudden_termination_disables_(0),
167 plugin_refresh_allowed_(true),
168 shared_worker_repository_(new WebSharedWorkerRepositoryImpl
) {
169 if (g_sandbox_enabled
&& sandboxEnabled()) {
170 sandbox_support_
.reset(
171 new RendererWebKitPlatformSupportImpl::SandboxSupport
);
173 DVLOG(1) << "Disabling sandbox support for testing.";
177 RendererWebKitPlatformSupportImpl::~RendererWebKitPlatformSupportImpl() {
180 //------------------------------------------------------------------------------
184 bool SendSyncMessageFromAnyThreadInternal(IPC::SyncMessage
* msg
) {
185 RenderThread
* render_thread
= RenderThread::Get();
187 return render_thread
->Send(msg
);
188 scoped_refptr
<IPC::SyncMessageFilter
> sync_msg_filter(
189 ChildThread::current()->sync_message_filter());
190 return sync_msg_filter
->Send(msg
);
193 bool SendSyncMessageFromAnyThread(IPC::SyncMessage
* msg
) {
194 base::TimeTicks begin
= base::TimeTicks::Now();
195 const bool success
= SendSyncMessageFromAnyThreadInternal(msg
);
196 base::TimeDelta delta
= base::TimeTicks::Now() - begin
;
197 UMA_HISTOGRAM_TIMES("RendererSyncIPC.ElapsedTime", delta
);
203 WebKit::WebClipboard
* RendererWebKitPlatformSupportImpl::clipboard() {
204 return clipboard_
.get();
207 WebKit::WebMimeRegistry
* RendererWebKitPlatformSupportImpl::mimeRegistry() {
208 return mime_registry_
.get();
211 WebKit::WebFileUtilities
*
212 RendererWebKitPlatformSupportImpl::fileUtilities() {
213 if (!file_utilities_
.get()) {
214 file_utilities_
.reset(new FileUtilities
);
215 file_utilities_
->set_sandbox_enabled(sandboxEnabled());
217 return file_utilities_
.get();
220 WebKit::WebSandboxSupport
* RendererWebKitPlatformSupportImpl::sandboxSupport() {
221 #if defined(OS_ANDROID)
222 // WebKit doesn't use WebSandboxSupport on android.
225 return sandbox_support_
.get();
229 WebKit::WebCookieJar
* RendererWebKitPlatformSupportImpl::cookieJar() {
230 NOTREACHED() << "Use WebFrameClient::cookieJar() instead!";
234 bool RendererWebKitPlatformSupportImpl::sandboxEnabled() {
235 // As explained in WebKitPlatformSupport.h, this function is used to decide
236 // whether to allow file system operations to come out of WebKit or not.
237 // Even if the sandbox is disabled, there's no reason why the code should
238 // act any differently...unless we're in single process mode. In which
239 // case, we have no other choice. WebKitPlatformSupport.h discourages using
240 // this switch unless absolutely necessary, so hopefully we won't end up
241 // with too many code paths being different in single-process mode.
242 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess
);
245 unsigned long long RendererWebKitPlatformSupportImpl::visitedLinkHash(
246 const char* canonical_url
,
248 return GetContentClient()->renderer()->VisitedLinkHash(canonical_url
, length
);
251 bool RendererWebKitPlatformSupportImpl::isLinkVisited(
252 unsigned long long link_hash
) {
253 return GetContentClient()->renderer()->IsLinkVisited(link_hash
);
256 WebKit::WebMessagePortChannel
*
257 RendererWebKitPlatformSupportImpl::createMessagePortChannel() {
258 return new WebMessagePortChannelImpl();
261 void RendererWebKitPlatformSupportImpl::prefetchHostName(
262 const WebString
& hostname
) {
263 if (hostname
.isEmpty())
266 std::string hostname_utf8
;
267 UTF16ToUTF8(hostname
.data(), hostname
.length(), &hostname_utf8
);
268 GetContentClient()->renderer()->PrefetchHostName(
269 hostname_utf8
.data(), hostname_utf8
.length());
273 RendererWebKitPlatformSupportImpl::CheckPreparsedJsCachingEnabled() const {
274 static bool checked
= false;
275 static bool result
= false;
277 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
278 result
= command_line
.HasSwitch(switches::kEnablePreparsedJsCaching
);
284 void RendererWebKitPlatformSupportImpl::cacheMetadata(
285 const WebKit::WebURL
& url
,
286 double response_time
,
289 if (!CheckPreparsedJsCachingEnabled())
292 // Let the browser know we generated cacheable metadata for this resource. The
293 // browser may cache it and return it on subsequent responses to speed
294 // the processing of this resource.
295 std::vector
<char> copy(data
, data
+ size
);
296 RenderThread::Get()->Send(
297 new ViewHostMsg_DidGenerateCacheableMetadata(url
, response_time
, copy
));
300 WebString
RendererWebKitPlatformSupportImpl::defaultLocale() {
301 return ASCIIToUTF16(RenderThread::Get()->GetLocale());
304 void RendererWebKitPlatformSupportImpl::suddenTerminationChanged(bool enabled
) {
306 // We should not get more enables than disables, but we want it to be a
307 // non-fatal error if it does happen.
308 DCHECK_GT(sudden_termination_disables_
, 0);
309 sudden_termination_disables_
= std::max(sudden_termination_disables_
- 1,
311 if (sudden_termination_disables_
!= 0)
314 sudden_termination_disables_
++;
315 if (sudden_termination_disables_
!= 1)
319 RenderThread
* thread
= RenderThread::Get();
320 if (thread
) // NULL in unittests.
321 thread
->Send(new ViewHostMsg_SuddenTerminationChanged(enabled
));
325 RendererWebKitPlatformSupportImpl::createLocalStorageNamespace(
326 const WebString
& path
, unsigned quota
) {
327 return new WebStorageNamespaceImpl();
331 //------------------------------------------------------------------------------
333 WebIDBFactory
* RendererWebKitPlatformSupportImpl::idbFactory() {
334 if (!web_idb_factory_
.get()) {
335 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess
))
336 web_idb_factory_
.reset(WebIDBFactory::create());
338 web_idb_factory_
.reset(new RendererWebIDBFactoryImpl());
340 return web_idb_factory_
.get();
343 //------------------------------------------------------------------------------
345 WebFileSystem
* RendererWebKitPlatformSupportImpl::fileSystem() {
346 if (!web_file_system_
.get())
347 web_file_system_
.reset(new WebFileSystemImpl());
348 return web_file_system_
.get();
351 //------------------------------------------------------------------------------
354 RendererWebKitPlatformSupportImpl::MimeRegistry::mimeTypeForExtension(
355 const WebString
& file_extension
) {
356 if (IsPluginProcess())
357 return SimpleWebMimeRegistryImpl::mimeTypeForExtension(file_extension
);
359 // The sandbox restricts our access to the registry, so we need to proxy
360 // these calls over to the browser process.
361 std::string mime_type
;
362 RenderThread::Get()->Send(
363 new MimeRegistryMsg_GetMimeTypeFromExtension(
364 webkit_base::WebStringToFilePathString(file_extension
), &mime_type
));
365 return ASCIIToUTF16(mime_type
);
369 WebString
RendererWebKitPlatformSupportImpl::MimeRegistry::mimeTypeFromFile(
370 const WebString
& file_path
) {
371 if (IsPluginProcess())
372 return SimpleWebMimeRegistryImpl::mimeTypeFromFile(file_path
);
374 // The sandbox restricts our access to the registry, so we need to proxy
375 // these calls over to the browser process.
376 std::string mime_type
;
377 RenderThread::Get()->Send(new MimeRegistryMsg_GetMimeTypeFromFile(
378 FilePath(webkit_base::WebStringToFilePathString(file_path
)),
380 return ASCIIToUTF16(mime_type
);
385 RendererWebKitPlatformSupportImpl::MimeRegistry::preferredExtensionForMIMEType(
386 const WebString
& mime_type
) {
387 if (IsPluginProcess())
388 return SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType(mime_type
);
390 // The sandbox restricts our access to the registry, so we need to proxy
391 // these calls over to the browser process.
392 FilePath::StringType file_extension
;
393 RenderThread::Get()->Send(
394 new MimeRegistryMsg_GetPreferredExtensionForMimeType(
395 UTF16ToASCII(mime_type
), &file_extension
));
396 return webkit_base::FilePathStringToWebString(file_extension
);
399 //------------------------------------------------------------------------------
401 bool RendererWebKitPlatformSupportImpl::FileUtilities::getFileInfo(
402 const WebString
& path
,
403 WebFileInfo
& web_file_info
) {
404 base::PlatformFileInfo file_info
;
405 base::PlatformFileError status
;
406 if (!SendSyncMessageFromAnyThread(new FileUtilitiesMsg_GetFileInfo(
407 webkit_base::WebStringToFilePath(path
), &file_info
, &status
)) ||
408 status
!= base::PLATFORM_FILE_OK
) {
411 webkit_glue::PlatformFileInfoToWebFileInfo(file_info
, &web_file_info
);
412 web_file_info
.platformPath
= path
;
416 base::PlatformFile
RendererWebKitPlatformSupportImpl::FileUtilities::openFile(
417 const WebString
& path
,
419 IPC::PlatformFileForTransit handle
= IPC::InvalidPlatformFileForTransit();
420 SendSyncMessageFromAnyThread(new FileUtilitiesMsg_OpenFile(
421 webkit_base::WebStringToFilePath(path
), mode
, &handle
));
422 return IPC::PlatformFileForTransitToPlatformFile(handle
);
425 //------------------------------------------------------------------------------
429 bool RendererWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded(
432 GetObject(font
, sizeof(LOGFONT
), &logfont
);
433 RenderThread::Get()->PreCacheFont(logfont
);
437 #elif defined(OS_MACOSX)
439 bool RendererWebKitPlatformSupportImpl::SandboxSupport::loadFont(
440 NSFont
* src_font
, CGFontRef
* out
, uint32
* font_id
) {
441 uint32 font_data_size
;
442 FontDescriptor
src_font_descriptor(src_font
);
443 base::SharedMemoryHandle font_data
;
444 if (!RenderThread::Get()->Send(new ViewHostMsg_LoadFont(
445 src_font_descriptor
, &font_data_size
, &font_data
, font_id
))) {
451 if (font_data_size
== 0 || font_data
== base::SharedMemory::NULLHandle() ||
453 LOG(ERROR
) << "Bad response from ViewHostMsg_LoadFont() for " <<
454 src_font_descriptor
.font_name
;
460 // TODO(jeremy): Need to call back into WebKit to make sure that the font
461 // isn't already activated, based on the font id. If it's already
462 // activated, don't reactivate it here - crbug.com/72727 .
464 return FontLoader::CGFontRefFromBuffer(font_data
, font_data_size
, out
);
467 #elif defined(OS_ANDROID)
469 // WebKit doesn't use WebSandboxSupport on android so we don't need to
470 // implement anything here. This is cleaner to support than excluding the
471 // whole class for android.
473 #elif defined(OS_POSIX)
476 RendererWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacters(
477 const WebKit::WebUChar
* characters
,
478 size_t num_characters
,
479 const char* preferred_locale
,
480 WebKit::WebFontFamily
* family
) {
481 base::AutoLock
lock(unicode_font_families_mutex_
);
482 const string16
key(characters
, num_characters
);
483 const std::map
<string16
, WebKit::WebFontFamily
>::const_iterator iter
=
484 unicode_font_families_
.find(key
);
485 if (iter
!= unicode_font_families_
.end()) {
486 family
->name
= iter
->second
.name
;
487 family
->isBold
= iter
->second
.isBold
;
488 family
->isItalic
= iter
->second
.isItalic
;
492 GetFontFamilyForCharacters(
497 unicode_font_families_
.insert(make_pair(key
, *family
));
501 RendererWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike(
502 const char* family
, int sizeAndStyle
, WebKit::WebFontRenderStyle
* out
) {
503 GetRenderStyleForStrike(family
, sizeAndStyle
, out
);
508 //------------------------------------------------------------------------------
510 WebKitPlatformSupport::FileHandle
511 RendererWebKitPlatformSupportImpl::databaseOpenFile(
512 const WebString
& vfs_file_name
, int desired_flags
) {
513 return DatabaseUtil::DatabaseOpenFile(vfs_file_name
, desired_flags
);
516 int RendererWebKitPlatformSupportImpl::databaseDeleteFile(
517 const WebString
& vfs_file_name
, bool sync_dir
) {
518 return DatabaseUtil::DatabaseDeleteFile(vfs_file_name
, sync_dir
);
521 long RendererWebKitPlatformSupportImpl::databaseGetFileAttributes(
522 const WebString
& vfs_file_name
) {
523 return DatabaseUtil::DatabaseGetFileAttributes(vfs_file_name
);
526 long long RendererWebKitPlatformSupportImpl::databaseGetFileSize(
527 const WebString
& vfs_file_name
) {
528 return DatabaseUtil::DatabaseGetFileSize(vfs_file_name
);
531 long long RendererWebKitPlatformSupportImpl::databaseGetSpaceAvailableForOrigin(
532 const WebString
& origin_identifier
) {
533 return DatabaseUtil::DatabaseGetSpaceAvailable(origin_identifier
);
536 WebKit::WebSharedWorkerRepository
*
537 RendererWebKitPlatformSupportImpl::sharedWorkerRepository() {
538 if (!CommandLine::ForCurrentProcess()->HasSwitch(
539 switches::kDisableSharedWorkers
)) {
540 return shared_worker_repository_
.get();
546 bool RendererWebKitPlatformSupportImpl::canAccelerate2dCanvas() {
547 RenderThreadImpl
* thread
= RenderThreadImpl::current();
548 GpuChannelHost
* host
= thread
->EstablishGpuChannelSync(
549 CAUSE_FOR_GPU_LAUNCH_CANVAS_2D
);
553 const GPUInfo
& gpu_info
= host
->gpu_info();
554 if (gpu_info
.can_lose_context
|| gpu_info
.software_rendering
)
560 double RendererWebKitPlatformSupportImpl::audioHardwareSampleRate() {
561 return GetAudioOutputSampleRate();
564 size_t RendererWebKitPlatformSupportImpl::audioHardwareBufferSize() {
565 return GetAudioOutputBufferSize();
569 RendererWebKitPlatformSupportImpl::createAudioDevice(
571 unsigned numberOfChannels
,
573 WebAudioDevice::RenderCallback
* callback
) {
574 media::ChannelLayout layout
= media::CHANNEL_LAYOUT_UNSUPPORTED
;
576 // The |numberOfChannels| does not exactly identify the channel layout of the
577 // device. The switch statement below assigns a best guess to the channel
578 // layout based on number of channels.
579 // TODO(crogers): WebKit should give the channel layout instead of the hard
581 switch (numberOfChannels
) {
583 layout
= media::CHANNEL_LAYOUT_MONO
;
586 layout
= media::CHANNEL_LAYOUT_STEREO
;
589 layout
= media::CHANNEL_LAYOUT_2_1
;
592 layout
= media::CHANNEL_LAYOUT_4_0
;
595 layout
= media::CHANNEL_LAYOUT_5_0
;
598 layout
= media::CHANNEL_LAYOUT_5_1
;
601 layout
= media::CHANNEL_LAYOUT_7_0
;
604 layout
= media::CHANNEL_LAYOUT_7_1
;
607 layout
= media::CHANNEL_LAYOUT_STEREO
;
610 media::AudioParameters
params(
611 media::AudioParameters::AUDIO_PCM_LOW_LATENCY
, layout
,
612 static_cast<int>(sampleRate
), 16, bufferSize
);
614 return new RendererWebAudioDeviceImpl(params
, callback
);
617 //------------------------------------------------------------------------------
620 RendererWebKitPlatformSupportImpl::signedPublicKeyAndChallengeString(
621 unsigned key_size_index
,
622 const WebKit::WebString
& challenge
,
623 const WebKit::WebURL
& url
) {
624 std::string signed_public_key
;
625 RenderThread::Get()->Send(new ViewHostMsg_Keygen(
626 static_cast<uint32
>(key_size_index
),
629 &signed_public_key
));
630 return WebString::fromUTF8(signed_public_key
);
633 //------------------------------------------------------------------------------
635 void RendererWebKitPlatformSupportImpl::screenColorProfile(
636 WebVector
<char>* to_profile
) {
637 std::vector
<char> profile
;
638 RenderThread::Get()->Send(
639 new ViewHostMsg_GetMonitorColorProfile(&profile
));
640 *to_profile
= profile
;
643 //------------------------------------------------------------------------------
645 WebBlobRegistry
* RendererWebKitPlatformSupportImpl::blobRegistry() {
646 // ChildThread::current can be NULL when running some tests.
647 if (!blob_registry_
.get() && ChildThread::current()) {
648 blob_registry_
.reset(new WebBlobRegistryImpl(ChildThread::current()));
650 return blob_registry_
.get();
653 //------------------------------------------------------------------------------
655 void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads
& gamepads
) {
656 if (g_test_gamepads
== 0) {
657 if (!gamepad_shared_memory_reader_
.get())
658 gamepad_shared_memory_reader_
.reset(new GamepadSharedMemoryReader
);
659 gamepad_shared_memory_reader_
->SampleGamepads(gamepads
);
661 gamepads
= g_test_gamepads
.Get();
666 WebKit::WebString
RendererWebKitPlatformSupportImpl::userAgent(
667 const WebKit::WebURL
& url
) {
668 return WebKitPlatformSupportImpl::userAgent(url
);
671 void RendererWebKitPlatformSupportImpl::GetPlugins(
672 bool refresh
, std::vector
<webkit::WebPluginInfo
>* plugins
) {
673 if (!plugin_refresh_allowed_
)
675 RenderThread::Get()->Send(
676 new ViewHostMsg_GetPlugins(refresh
, plugins
));
679 //------------------------------------------------------------------------------
681 WebRTCPeerConnectionHandler
*
682 RendererWebKitPlatformSupportImpl::createRTCPeerConnectionHandler(
683 WebRTCPeerConnectionHandlerClient
* client
) {
684 RenderThreadImpl
* render_thread
= RenderThreadImpl::current();
685 DCHECK(render_thread
);
688 #if defined(ENABLE_WEBRTC)
689 MediaStreamDependencyFactory
* rtc_dependency_factory
=
690 render_thread
->GetMediaStreamDependencyFactory();
691 return rtc_dependency_factory
->CreateRTCPeerConnectionHandler(client
);
694 #endif // defined(ENABLE_WEBRTC)
697 //------------------------------------------------------------------------------
699 WebMediaStreamCenter
*
700 RendererWebKitPlatformSupportImpl::createMediaStreamCenter(
701 WebMediaStreamCenterClient
* client
) {
702 RenderThreadImpl
* render_thread
= RenderThreadImpl::current();
703 DCHECK(render_thread
);
706 return render_thread
->CreateMediaStreamCenter(client
);
710 bool RendererWebKitPlatformSupportImpl::SetSandboxEnabledForTesting(
712 bool was_enabled
= g_sandbox_enabled
;
713 g_sandbox_enabled
= enable
;
718 void RendererWebKitPlatformSupportImpl::SetMockGamepadsForTesting(
719 const WebGamepads
& pads
) {
720 g_test_gamepads
.Get() = pads
;
723 GpuChannelHostFactory
*
724 RendererWebKitPlatformSupportImpl::GetGpuChannelHostFactory() {
725 return RenderThreadImpl::current();
728 //------------------------------------------------------------------------------
730 bool RendererWebKitPlatformSupportImpl::canHyphenate(
731 const WebKit::WebString
& locale
) {
732 // Return false unless WebKit asks for US English dictionaries because WebKit
733 // can currently hyphenate only English words.
734 if (!locale
.isEmpty() && !locale
.equals("en-US"))
737 // Create a hyphenator object and attach it to the render thread so it can
738 // receive a dictionary file opened by a browser.
739 if (!hyphenator_
.get()) {
740 hyphenator_
.reset(new Hyphenator(base::kInvalidPlatformFileValue
));
741 if (!hyphenator_
.get())
743 return hyphenator_
->Attach(RenderThreadImpl::current(), locale
);
745 return hyphenator_
->CanHyphenate(locale
);
748 size_t RendererWebKitPlatformSupportImpl::computeLastHyphenLocation(
749 const char16
* characters
,
752 const WebKit::WebString
& locale
) {
753 // Crash if WebKit calls this function when canHyphenate returns false.
754 DCHECK(locale
.isEmpty() || locale
.equals("en-US"));
755 DCHECK(hyphenator_
.get());
756 return hyphenator_
->ComputeLastHyphenLocation(string16(characters
, length
),
760 } // namespace content