Add ICU message format support
[chromium-blink-merge.git] / content / renderer / renderer_blink_platform_impl.cc
blobed79baa498e6c1bf538aec098f13b00425d9e35a
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_blink_platform_impl.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/lazy_instance.h"
10 #include "base/location.h"
11 #include "base/logging.h"
12 #include "base/memory/shared_memory.h"
13 #include "base/metrics/histogram.h"
14 #include "base/numerics/safe_conversions.h"
15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/utf_string_conversions.h"
18 #include "base/thread_task_runner_handle.h"
19 #include "build/build_config.h"
20 #include "cc/blink/context_provider_web_context.h"
21 #include "components/scheduler/child/web_scheduler_impl.h"
22 #include "components/scheduler/renderer/renderer_scheduler.h"
23 #include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h"
24 #include "content/child/database_util.h"
25 #include "content/child/file_info_util.h"
26 #include "content/child/fileapi/webfilesystem_impl.h"
27 #include "content/child/indexed_db/webidbfactory_impl.h"
28 #include "content/child/npapi/npobject_util.h"
29 #include "content/child/quota_dispatcher.h"
30 #include "content/child/quota_message_filter.h"
31 #include "content/child/simple_webmimeregistry_impl.h"
32 #include "content/child/thread_safe_sender.h"
33 #include "content/child/web_database_observer_impl.h"
34 #include "content/child/webblobregistry_impl.h"
35 #include "content/child/webfileutilities_impl.h"
36 #include "content/child/webmessageportchannel_impl.h"
37 #include "content/common/file_utilities_messages.h"
38 #include "content/common/gpu/client/context_provider_command_buffer.h"
39 #include "content/common/gpu/client/gpu_channel_host.h"
40 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
41 #include "content/common/gpu/gpu_process_launch_causes.h"
42 #include "content/common/mime_registry_messages.h"
43 #include "content/common/view_messages.h"
44 #include "content/public/common/content_switches.h"
45 #include "content/public/common/service_registry.h"
46 #include "content/public/common/webplugininfo.h"
47 #include "content/public/renderer/content_renderer_client.h"
48 #include "content/renderer/battery_status/battery_status_dispatcher.h"
49 #include "content/renderer/cache_storage/webserviceworkercachestorage_impl.h"
50 #include "content/renderer/device_sensors/device_light_event_pump.h"
51 #include "content/renderer/device_sensors/device_motion_event_pump.h"
52 #include "content/renderer/device_sensors/device_orientation_event_pump.h"
53 #include "content/renderer/dom_storage/webstoragenamespace_impl.h"
54 #include "content/renderer/gamepad_shared_memory_reader.h"
55 #include "content/renderer/media/audio_decoder.h"
56 #include "content/renderer/media/renderer_webaudiodevice_impl.h"
57 #include "content/renderer/media/renderer_webmidiaccessor_impl.h"
58 #include "content/renderer/render_thread_impl.h"
59 #include "content/renderer/renderer_clipboard_delegate.h"
60 #include "content/renderer/screen_orientation/screen_orientation_observer.h"
61 #include "content/renderer/webclipboard_impl.h"
62 #include "content/renderer/webgraphicscontext3d_provider_impl.h"
63 #include "content/renderer/webpublicsuffixlist_impl.h"
64 #include "gpu/config/gpu_info.h"
65 #include "ipc/ipc_sync_message_filter.h"
66 #include "media/audio/audio_output_device.h"
67 #include "media/base/audio_hardware_config.h"
68 #include "media/base/key_systems.h"
69 #include "media/base/mime_util.h"
70 #include "media/blink/webcontentdecryptionmodule_impl.h"
71 #include "media/filters/stream_parser_factory.h"
72 #include "net/base/net_util.h"
73 #include "storage/common/database/database_identifier.h"
74 #include "storage/common/quota/quota_types.h"
75 #include "third_party/WebKit/public/platform/WebBatteryStatusListener.h"
76 #include "third_party/WebKit/public/platform/WebBlobRegistry.h"
77 #include "third_party/WebKit/public/platform/WebDeviceLightListener.h"
78 #include "third_party/WebKit/public/platform/WebFileInfo.h"
79 #include "third_party/WebKit/public/platform/WebGamepads.h"
80 #include "third_party/WebKit/public/platform/WebMediaStreamCenter.h"
81 #include "third_party/WebKit/public/platform/WebMediaStreamCenterClient.h"
82 #include "third_party/WebKit/public/platform/WebPluginListBuilder.h"
83 #include "third_party/WebKit/public/platform/WebURL.h"
84 #include "third_party/WebKit/public/platform/WebVector.h"
85 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceMotionListener.h"
86 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceOrientationListener.h"
87 #include "ui/gfx/color_profile.h"
88 #include "url/gurl.h"
90 #if defined(OS_ANDROID)
91 #include "content/renderer/android/synchronous_compositor_factory.h"
92 #include "content/renderer/media/android/audio_decoder_android.h"
93 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h"
94 #endif
96 #if defined(OS_MACOSX)
97 #include "content/common/mac/font_descriptor.h"
98 #include "content/common/mac/font_loader.h"
99 #include "content/renderer/webscrollbarbehavior_impl_mac.h"
100 #include "third_party/WebKit/public/platform/mac/WebSandboxSupport.h"
101 #endif
103 #if defined(OS_POSIX)
104 #include "base/file_descriptor_posix.h"
105 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
106 #include <map>
107 #include <string>
109 #include "base/synchronization/lock.h"
110 #include "content/common/child_process_sandbox_support_impl_linux.h"
111 #include "third_party/WebKit/public/platform/linux/WebFallbackFont.h"
112 #include "third_party/WebKit/public/platform/linux/WebSandboxSupport.h"
113 #include "third_party/icu/source/common/unicode/utf16.h"
114 #endif
115 #endif
117 #if defined(OS_WIN)
118 #include "content/common/child_process_messages.h"
119 #endif
121 #if defined(USE_AURA)
122 #include "content/renderer/webscrollbarbehavior_impl_gtkoraura.h"
123 #elif !defined(OS_MACOSX)
124 #include "third_party/WebKit/public/platform/WebScrollbarBehavior.h"
125 #define WebScrollbarBehaviorImpl blink::WebScrollbarBehavior
126 #endif
128 #if defined(ENABLE_WEBRTC)
129 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
130 #endif
132 using blink::Platform;
133 using blink::WebAudioDevice;
134 using blink::WebBlobRegistry;
135 using blink::WebDatabaseObserver;
136 using blink::WebFileInfo;
137 using blink::WebFileSystem;
138 using blink::WebGamepad;
139 using blink::WebGamepads;
140 using blink::WebIDBFactory;
141 using blink::WebMIDIAccessor;
142 using blink::WebMediaStreamCenter;
143 using blink::WebMediaStreamCenterClient;
144 using blink::WebMimeRegistry;
145 using blink::WebRTCPeerConnectionHandler;
146 using blink::WebRTCPeerConnectionHandlerClient;
147 using blink::WebStorageNamespace;
148 using blink::WebString;
149 using blink::WebURL;
150 using blink::WebVector;
152 namespace content {
154 namespace {
156 bool g_sandbox_enabled = true;
157 double g_test_device_light_data = -1;
158 base::LazyInstance<blink::WebDeviceMotionData>::Leaky
159 g_test_device_motion_data = LAZY_INSTANCE_INITIALIZER;
160 base::LazyInstance<blink::WebDeviceOrientationData>::Leaky
161 g_test_device_orientation_data = LAZY_INSTANCE_INITIALIZER;
162 // Set in startListening() when running layout tests, unset in stopListening(),
163 // not owned by us.
164 blink::WebBatteryStatusListener* g_test_battery_status_listener = nullptr;
166 } // namespace
168 //------------------------------------------------------------------------------
170 class RendererBlinkPlatformImpl::MimeRegistry
171 : public SimpleWebMimeRegistryImpl {
172 public:
173 virtual blink::WebMimeRegistry::SupportsType supportsMediaMIMEType(
174 const blink::WebString& mime_type,
175 const blink::WebString& codecs,
176 const blink::WebString& key_system);
177 virtual bool supportsMediaSourceMIMEType(const blink::WebString& mime_type,
178 const blink::WebString& codecs);
179 virtual blink::WebString mimeTypeForExtension(
180 const blink::WebString& file_extension);
181 virtual blink::WebString mimeTypeFromFile(
182 const blink::WebString& file_path);
185 class RendererBlinkPlatformImpl::FileUtilities : public WebFileUtilitiesImpl {
186 public:
187 explicit FileUtilities(ThreadSafeSender* sender)
188 : thread_safe_sender_(sender) {}
189 virtual bool getFileInfo(const WebString& path, WebFileInfo& result);
190 private:
191 bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) const;
192 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
195 #if !defined(OS_ANDROID) && !defined(OS_WIN)
196 class RendererBlinkPlatformImpl::SandboxSupport
197 : public blink::WebSandboxSupport {
198 public:
199 virtual ~SandboxSupport() {}
201 #if defined(OS_MACOSX)
202 virtual bool loadFont(
203 NSFont* src_font,
204 CGFontRef* container,
205 uint32* font_id);
206 #elif defined(OS_POSIX)
207 virtual void getFallbackFontForCharacter(
208 blink::WebUChar32 character,
209 const char* preferred_locale,
210 blink::WebFallbackFont* fallbackFont);
211 virtual void getRenderStyleForStrike(
212 const char* family, int sizeAndStyle, blink::WebFontRenderStyle* out);
214 private:
215 // WebKit likes to ask us for the correct font family to use for a set of
216 // unicode code points. It needs this information frequently so we cache it
217 // here.
218 base::Lock unicode_font_families_mutex_;
219 std::map<int32_t, blink::WebFallbackFont> unicode_font_families_;
220 #endif
222 #endif // !defined(OS_ANDROID) && !defined(OS_WIN)
224 //------------------------------------------------------------------------------
226 RendererBlinkPlatformImpl::RendererBlinkPlatformImpl(
227 scheduler::RendererScheduler* renderer_scheduler)
228 : BlinkPlatformImpl(renderer_scheduler->DefaultTaskRunner()),
229 main_thread_(
230 new scheduler::WebThreadImplForRendererScheduler(renderer_scheduler)),
231 clipboard_delegate_(new RendererClipboardDelegate),
232 clipboard_(new WebClipboardImpl(clipboard_delegate_.get())),
233 mime_registry_(new RendererBlinkPlatformImpl::MimeRegistry),
234 sudden_termination_disables_(0),
235 plugin_refresh_allowed_(true),
236 default_task_runner_(renderer_scheduler->DefaultTaskRunner()),
237 web_scrollbar_behavior_(new WebScrollbarBehaviorImpl) {
238 #if !defined(OS_ANDROID) && !defined(OS_WIN)
239 if (g_sandbox_enabled && sandboxEnabled()) {
240 sandbox_support_.reset(new RendererBlinkPlatformImpl::SandboxSupport);
241 } else {
242 DVLOG(1) << "Disabling sandbox support for testing.";
244 #endif
246 // ChildThread may not exist in some tests.
247 if (ChildThreadImpl::current()) {
248 sync_message_filter_ = ChildThreadImpl::current()->sync_message_filter();
249 thread_safe_sender_ = ChildThreadImpl::current()->thread_safe_sender();
250 quota_message_filter_ = ChildThreadImpl::current()->quota_message_filter();
251 blob_registry_.reset(new WebBlobRegistryImpl(thread_safe_sender_.get()));
252 web_idb_factory_.reset(new WebIDBFactoryImpl(thread_safe_sender_.get()));
253 web_database_observer_impl_.reset(
254 new WebDatabaseObserverImpl(sync_message_filter_.get()));
258 RendererBlinkPlatformImpl::~RendererBlinkPlatformImpl() {
259 WebFileSystemImpl::DeleteThreadSpecificInstance();
262 //------------------------------------------------------------------------------
264 blink::WebThread* RendererBlinkPlatformImpl::currentThread() {
265 if (main_thread_->isCurrentThread())
266 return main_thread_.get();
267 return BlinkPlatformImpl::currentThread();
270 blink::WebClipboard* RendererBlinkPlatformImpl::clipboard() {
271 blink::WebClipboard* clipboard =
272 GetContentClient()->renderer()->OverrideWebClipboard();
273 if (clipboard)
274 return clipboard;
275 return clipboard_.get();
278 blink::WebMimeRegistry* RendererBlinkPlatformImpl::mimeRegistry() {
279 return mime_registry_.get();
282 blink::WebFileUtilities* RendererBlinkPlatformImpl::fileUtilities() {
283 if (!file_utilities_) {
284 file_utilities_.reset(new FileUtilities(thread_safe_sender_.get()));
285 file_utilities_->set_sandbox_enabled(sandboxEnabled());
287 return file_utilities_.get();
290 blink::WebSandboxSupport* RendererBlinkPlatformImpl::sandboxSupport() {
291 #if defined(OS_ANDROID) || defined(OS_WIN)
292 // These platforms do not require sandbox support.
293 return NULL;
294 #else
295 return sandbox_support_.get();
296 #endif
299 blink::WebCookieJar* RendererBlinkPlatformImpl::cookieJar() {
300 NOTREACHED() << "Use WebFrameClient::cookieJar() instead!";
301 return NULL;
304 blink::WebThemeEngine* RendererBlinkPlatformImpl::themeEngine() {
305 blink::WebThemeEngine* theme_engine =
306 GetContentClient()->renderer()->OverrideThemeEngine();
307 if (theme_engine)
308 return theme_engine;
309 return BlinkPlatformImpl::themeEngine();
312 bool RendererBlinkPlatformImpl::sandboxEnabled() {
313 // As explained in Platform.h, this function is used to decide
314 // whether to allow file system operations to come out of WebKit or not.
315 // Even if the sandbox is disabled, there's no reason why the code should
316 // act any differently...unless we're in single process mode. In which
317 // case, we have no other choice. Platform.h discourages using
318 // this switch unless absolutely necessary, so hopefully we won't end up
319 // with too many code paths being different in single-process mode.
320 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
321 switches::kSingleProcess);
324 unsigned long long RendererBlinkPlatformImpl::visitedLinkHash(
325 const char* canonical_url,
326 size_t length) {
327 return GetContentClient()->renderer()->VisitedLinkHash(canonical_url, length);
330 bool RendererBlinkPlatformImpl::isLinkVisited(unsigned long long link_hash) {
331 return GetContentClient()->renderer()->IsLinkVisited(link_hash);
334 void RendererBlinkPlatformImpl::createMessageChannel(
335 blink::WebMessagePortChannel** channel1,
336 blink::WebMessagePortChannel** channel2) {
337 WebMessagePortChannelImpl::CreatePair(
338 default_task_runner_, channel1, channel2);
341 blink::WebPrescientNetworking*
342 RendererBlinkPlatformImpl::prescientNetworking() {
343 return GetContentClient()->renderer()->GetPrescientNetworking();
346 void RendererBlinkPlatformImpl::cacheMetadata(const blink::WebURL& url,
347 int64 response_time,
348 const char* data,
349 size_t size) {
350 // Let the browser know we generated cacheable metadata for this resource. The
351 // browser may cache it and return it on subsequent responses to speed
352 // the processing of this resource.
353 std::vector<char> copy(data, data + size);
354 RenderThread::Get()->Send(new ViewHostMsg_DidGenerateCacheableMetadata(
355 url, base::Time::FromInternalValue(response_time), copy));
358 WebString RendererBlinkPlatformImpl::defaultLocale() {
359 return base::ASCIIToUTF16(RenderThread::Get()->GetLocale());
362 void RendererBlinkPlatformImpl::suddenTerminationChanged(bool enabled) {
363 if (enabled) {
364 // We should not get more enables than disables, but we want it to be a
365 // non-fatal error if it does happen.
366 DCHECK_GT(sudden_termination_disables_, 0);
367 sudden_termination_disables_ = std::max(sudden_termination_disables_ - 1,
369 if (sudden_termination_disables_ != 0)
370 return;
371 } else {
372 sudden_termination_disables_++;
373 if (sudden_termination_disables_ != 1)
374 return;
377 RenderThread* thread = RenderThread::Get();
378 if (thread) // NULL in unittests.
379 thread->Send(new ViewHostMsg_SuddenTerminationChanged(enabled));
382 WebStorageNamespace* RendererBlinkPlatformImpl::createLocalStorageNamespace() {
383 return new WebStorageNamespaceImpl();
387 //------------------------------------------------------------------------------
389 WebIDBFactory* RendererBlinkPlatformImpl::idbFactory() {
390 return web_idb_factory_.get();
393 //------------------------------------------------------------------------------
395 blink::WebServiceWorkerCacheStorage* RendererBlinkPlatformImpl::cacheStorage(
396 const WebString& origin_identifier) {
397 const GURL origin =
398 storage::GetOriginFromIdentifier(origin_identifier.utf8());
399 return new WebServiceWorkerCacheStorageImpl(thread_safe_sender_.get(),
400 origin);
403 //------------------------------------------------------------------------------
405 WebFileSystem* RendererBlinkPlatformImpl::fileSystem() {
406 return WebFileSystemImpl::ThreadSpecificInstance(default_task_runner_);
409 //------------------------------------------------------------------------------
411 WebMimeRegistry::SupportsType
412 RendererBlinkPlatformImpl::MimeRegistry::supportsMediaMIMEType(
413 const WebString& mime_type,
414 const WebString& codecs,
415 const WebString& key_system) {
416 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type);
417 // Not supporting the container is a flat-out no.
418 if (!media::IsSupportedMediaMimeType(mime_type_ascii))
419 return IsNotSupported;
421 if (!key_system.isEmpty()) {
422 // Check whether the key system is supported with the mime_type and codecs.
424 // Chromium only supports ASCII parameters.
425 if (!base::IsStringASCII(key_system))
426 return IsNotSupported;
428 std::string key_system_ascii =
429 media::GetUnprefixedKeySystemName(base::UTF16ToASCII(
430 base::StringPiece16(key_system)));
431 std::vector<std::string> strict_codecs;
432 media::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, true);
434 if (!media::PrefixedIsSupportedKeySystemWithMediaMimeType(
435 mime_type_ascii, strict_codecs, key_system_ascii)) {
436 return IsNotSupported;
439 // Continue processing the mime_type and codecs.
442 // Check list of strict codecs to see if it is supported.
443 if (media::IsStrictMediaMimeType(mime_type_ascii)) {
444 // Check if the codecs are a perfect match.
445 std::vector<std::string> strict_codecs;
446 media::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, false);
447 return static_cast<WebMimeRegistry::SupportsType> (
448 media::IsSupportedStrictMediaMimeType(mime_type_ascii, strict_codecs));
451 // If we don't recognize the codec, it's possible we support it.
452 std::vector<std::string> parsed_codecs;
453 media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true);
454 if (!media::AreSupportedMediaCodecs(parsed_codecs))
455 return MayBeSupported;
457 // Otherwise we have a perfect match.
458 return IsSupported;
461 bool RendererBlinkPlatformImpl::MimeRegistry::supportsMediaSourceMIMEType(
462 const blink::WebString& mime_type,
463 const WebString& codecs) {
464 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type);
465 std::vector<std::string> parsed_codec_ids;
466 media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false);
467 if (mime_type_ascii.empty())
468 return false;
469 return media::StreamParserFactory::IsTypeSupported(
470 mime_type_ascii, parsed_codec_ids);
473 WebString RendererBlinkPlatformImpl::MimeRegistry::mimeTypeForExtension(
474 const WebString& file_extension) {
475 if (IsPluginProcess())
476 return SimpleWebMimeRegistryImpl::mimeTypeForExtension(file_extension);
478 // The sandbox restricts our access to the registry, so we need to proxy
479 // these calls over to the browser process.
480 std::string mime_type;
481 RenderThread::Get()->Send(
482 new MimeRegistryMsg_GetMimeTypeFromExtension(
483 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type));
484 return base::ASCIIToUTF16(mime_type);
487 WebString RendererBlinkPlatformImpl::MimeRegistry::mimeTypeFromFile(
488 const WebString& file_path) {
489 if (IsPluginProcess())
490 return SimpleWebMimeRegistryImpl::mimeTypeFromFile(file_path);
492 // The sandbox restricts our access to the registry, so we need to proxy
493 // these calls over to the browser process.
494 std::string mime_type;
495 RenderThread::Get()->Send(new MimeRegistryMsg_GetMimeTypeFromFile(
496 base::FilePath::FromUTF16Unsafe(file_path),
497 &mime_type));
498 return base::ASCIIToUTF16(mime_type);
501 //------------------------------------------------------------------------------
503 bool RendererBlinkPlatformImpl::FileUtilities::getFileInfo(
504 const WebString& path,
505 WebFileInfo& web_file_info) {
506 base::File::Info file_info;
507 base::File::Error status = base::File::FILE_ERROR_MAX;
508 if (!SendSyncMessageFromAnyThread(new FileUtilitiesMsg_GetFileInfo(
509 base::FilePath::FromUTF16Unsafe(path), &file_info, &status)) ||
510 status != base::File::FILE_OK) {
511 return false;
513 FileInfoToWebFileInfo(file_info, &web_file_info);
514 web_file_info.platformPath = path;
515 return true;
518 bool RendererBlinkPlatformImpl::FileUtilities::SendSyncMessageFromAnyThread(
519 IPC::SyncMessage* msg) const {
520 base::TimeTicks begin = base::TimeTicks::Now();
521 const bool success = thread_safe_sender_->Send(msg);
522 base::TimeDelta delta = base::TimeTicks::Now() - begin;
523 UMA_HISTOGRAM_TIMES("RendererSyncIPC.ElapsedTime", delta);
524 return success;
527 //------------------------------------------------------------------------------
529 #if defined(OS_MACOSX)
531 bool RendererBlinkPlatformImpl::SandboxSupport::loadFont(NSFont* src_font,
532 CGFontRef* out,
533 uint32* font_id) {
534 uint32 font_data_size;
535 FontDescriptor src_font_descriptor(src_font);
536 base::SharedMemoryHandle font_data;
537 if (!RenderThread::Get()->Send(new ViewHostMsg_LoadFont(
538 src_font_descriptor, &font_data_size, &font_data, font_id))) {
539 *out = NULL;
540 *font_id = 0;
541 return false;
544 if (font_data_size == 0 || font_data == base::SharedMemory::NULLHandle() ||
545 *font_id == 0) {
546 LOG(ERROR) << "Bad response from ViewHostMsg_LoadFont() for " <<
547 src_font_descriptor.font_name;
548 *out = NULL;
549 *font_id = 0;
550 return false;
553 // TODO(jeremy): Need to call back into WebKit to make sure that the font
554 // isn't already activated, based on the font id. If it's already
555 // activated, don't reactivate it here - crbug.com/72727 .
557 return FontLoader::CGFontRefFromBuffer(font_data, font_data_size, out);
560 #elif defined(OS_POSIX) && !defined(OS_ANDROID)
562 void RendererBlinkPlatformImpl::SandboxSupport::getFallbackFontForCharacter(
563 blink::WebUChar32 character,
564 const char* preferred_locale,
565 blink::WebFallbackFont* fallbackFont) {
566 base::AutoLock lock(unicode_font_families_mutex_);
567 const std::map<int32_t, blink::WebFallbackFont>::const_iterator iter =
568 unicode_font_families_.find(character);
569 if (iter != unicode_font_families_.end()) {
570 fallbackFont->name = iter->second.name;
571 fallbackFont->filename = iter->second.filename;
572 fallbackFont->fontconfigInterfaceId = iter->second.fontconfigInterfaceId;
573 fallbackFont->ttcIndex = iter->second.ttcIndex;
574 fallbackFont->isBold = iter->second.isBold;
575 fallbackFont->isItalic = iter->second.isItalic;
576 return;
579 GetFallbackFontForCharacter(character, preferred_locale, fallbackFont);
580 unicode_font_families_.insert(std::make_pair(character, *fallbackFont));
583 void RendererBlinkPlatformImpl::SandboxSupport::getRenderStyleForStrike(
584 const char* family,
585 int sizeAndStyle,
586 blink::WebFontRenderStyle* out) {
587 GetRenderStyleForStrike(family, sizeAndStyle, out);
590 #endif
592 //------------------------------------------------------------------------------
594 Platform::FileHandle RendererBlinkPlatformImpl::databaseOpenFile(
595 const WebString& vfs_file_name,
596 int desired_flags) {
597 return DatabaseUtil::DatabaseOpenFile(
598 vfs_file_name, desired_flags, sync_message_filter_.get());
601 int RendererBlinkPlatformImpl::databaseDeleteFile(
602 const WebString& vfs_file_name,
603 bool sync_dir) {
604 return DatabaseUtil::DatabaseDeleteFile(
605 vfs_file_name, sync_dir, sync_message_filter_.get());
608 long RendererBlinkPlatformImpl::databaseGetFileAttributes(
609 const WebString& vfs_file_name) {
610 return DatabaseUtil::DatabaseGetFileAttributes(vfs_file_name,
611 sync_message_filter_.get());
614 long long RendererBlinkPlatformImpl::databaseGetFileSize(
615 const WebString& vfs_file_name) {
616 return DatabaseUtil::DatabaseGetFileSize(vfs_file_name,
617 sync_message_filter_.get());
620 long long RendererBlinkPlatformImpl::databaseGetSpaceAvailableForOrigin(
621 const WebString& origin_identifier) {
622 return DatabaseUtil::DatabaseGetSpaceAvailable(origin_identifier,
623 sync_message_filter_.get());
626 bool RendererBlinkPlatformImpl::databaseSetFileSize(
627 const WebString& vfs_file_name, long long size) {
628 return DatabaseUtil::DatabaseSetFileSize(
629 vfs_file_name, size, sync_message_filter_.get());
632 bool RendererBlinkPlatformImpl::canAccelerate2dCanvas() {
633 #if defined(OS_ANDROID)
634 SynchronousCompositorFactory* factory =
635 SynchronousCompositorFactory::GetInstance();
636 if (factory && factory->OverrideWithFactory()) {
637 return factory->GetGPUInfo().SupportsAccelerated2dCanvas();
639 #endif
641 RenderThreadImpl* thread = RenderThreadImpl::current();
642 GpuChannelHost* host = thread->EstablishGpuChannelSync(
643 CAUSE_FOR_GPU_LAUNCH_CANVAS_2D);
644 if (!host)
645 return false;
647 return host->gpu_info().SupportsAccelerated2dCanvas();
650 bool RendererBlinkPlatformImpl::isThreadedCompositingEnabled() {
651 RenderThreadImpl* thread = RenderThreadImpl::current();
652 // thread can be NULL in tests.
653 return thread && thread->compositor_task_runner().get();
656 double RendererBlinkPlatformImpl::audioHardwareSampleRate() {
657 RenderThreadImpl* thread = RenderThreadImpl::current();
658 return thread->GetAudioHardwareConfig()->GetOutputSampleRate();
661 size_t RendererBlinkPlatformImpl::audioHardwareBufferSize() {
662 RenderThreadImpl* thread = RenderThreadImpl::current();
663 return thread->GetAudioHardwareConfig()->GetOutputBufferSize();
666 unsigned RendererBlinkPlatformImpl::audioHardwareOutputChannels() {
667 RenderThreadImpl* thread = RenderThreadImpl::current();
668 return thread->GetAudioHardwareConfig()->GetOutputChannels();
671 WebDatabaseObserver* RendererBlinkPlatformImpl::databaseObserver() {
672 return web_database_observer_impl_.get();
675 WebAudioDevice* RendererBlinkPlatformImpl::createAudioDevice(
676 size_t buffer_size,
677 unsigned input_channels,
678 unsigned channels,
679 double sample_rate,
680 WebAudioDevice::RenderCallback* callback,
681 const blink::WebString& input_device_id) {
682 // Use a mock for testing.
683 blink::WebAudioDevice* mock_device =
684 GetContentClient()->renderer()->OverrideCreateAudioDevice(sample_rate);
685 if (mock_device)
686 return mock_device;
688 // The |channels| does not exactly identify the channel layout of the
689 // device. The switch statement below assigns a best guess to the channel
690 // layout based on number of channels.
691 media::ChannelLayout layout = media::CHANNEL_LAYOUT_UNSUPPORTED;
692 switch (channels) {
693 case 1:
694 layout = media::CHANNEL_LAYOUT_MONO;
695 break;
696 case 2:
697 layout = media::CHANNEL_LAYOUT_STEREO;
698 break;
699 case 3:
700 layout = media::CHANNEL_LAYOUT_2_1;
701 break;
702 case 4:
703 layout = media::CHANNEL_LAYOUT_4_0;
704 break;
705 case 5:
706 layout = media::CHANNEL_LAYOUT_5_0;
707 break;
708 case 6:
709 layout = media::CHANNEL_LAYOUT_5_1;
710 break;
711 case 7:
712 layout = media::CHANNEL_LAYOUT_7_0;
713 break;
714 case 8:
715 layout = media::CHANNEL_LAYOUT_7_1;
716 break;
717 default:
718 // If the layout is not supported (more than 9 channels), falls back to
719 // discrete mode.
720 layout = media::CHANNEL_LAYOUT_DISCRETE;
723 int session_id = 0;
724 if (input_device_id.isNull() ||
725 !base::StringToInt(base::UTF16ToUTF8(
726 base::StringPiece16(input_device_id)), &session_id)) {
727 if (input_channels > 0)
728 DLOG(WARNING) << "createAudioDevice(): request for audio input ignored";
730 input_channels = 0;
733 // For CHANNEL_LAYOUT_DISCRETE, pass the explicit channel count along with
734 // the channel layout when creating an |AudioParameters| object.
735 media::AudioParameters params(
736 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
737 layout, channels, static_cast<int>(sample_rate), 16, buffer_size,
738 media::AudioParameters::NO_EFFECTS);
740 return new RendererWebAudioDeviceImpl(params, callback, session_id);
743 #if defined(OS_ANDROID)
744 bool RendererBlinkPlatformImpl::loadAudioResource(
745 blink::WebAudioBus* destination_bus,
746 const char* audio_file_data,
747 size_t data_size) {
748 return DecodeAudioFileData(destination_bus,
749 audio_file_data,
750 data_size,
751 thread_safe_sender_);
753 #else
754 bool RendererBlinkPlatformImpl::loadAudioResource(
755 blink::WebAudioBus* destination_bus,
756 const char* audio_file_data,
757 size_t data_size) {
758 return DecodeAudioFileData(
759 destination_bus, audio_file_data, data_size);
761 #endif // defined(OS_ANDROID)
763 //------------------------------------------------------------------------------
765 blink::WebMIDIAccessor* RendererBlinkPlatformImpl::createMIDIAccessor(
766 blink::WebMIDIAccessorClient* client) {
767 blink::WebMIDIAccessor* accessor =
768 GetContentClient()->renderer()->OverrideCreateMIDIAccessor(client);
769 if (accessor)
770 return accessor;
772 return new RendererWebMIDIAccessorImpl(client);
775 void RendererBlinkPlatformImpl::getPluginList(
776 bool refresh,
777 blink::WebPluginListBuilder* builder) {
778 #if defined(ENABLE_PLUGINS)
779 std::vector<WebPluginInfo> plugins;
780 if (!plugin_refresh_allowed_)
781 refresh = false;
782 RenderThread::Get()->Send(
783 new ViewHostMsg_GetPlugins(refresh, &plugins));
784 for (size_t i = 0; i < plugins.size(); ++i) {
785 const WebPluginInfo& plugin = plugins[i];
787 builder->addPlugin(
788 plugin.name, plugin.desc,
789 plugin.path.BaseName().AsUTF16Unsafe());
791 for (size_t j = 0; j < plugin.mime_types.size(); ++j) {
792 const WebPluginMimeType& mime_type = plugin.mime_types[j];
794 builder->addMediaTypeToLastPlugin(
795 WebString::fromUTF8(mime_type.mime_type), mime_type.description);
797 for (size_t k = 0; k < mime_type.file_extensions.size(); ++k) {
798 builder->addFileExtensionToLastMediaType(
799 WebString::fromUTF8(mime_type.file_extensions[k]));
803 #endif
806 //------------------------------------------------------------------------------
808 blink::WebPublicSuffixList* RendererBlinkPlatformImpl::publicSuffixList() {
809 return &public_suffix_list_;
812 //------------------------------------------------------------------------------
814 blink::WebString RendererBlinkPlatformImpl::signedPublicKeyAndChallengeString(
815 unsigned key_size_index,
816 const blink::WebString& challenge,
817 const blink::WebURL& url) {
818 std::string signed_public_key;
819 RenderThread::Get()->Send(new ViewHostMsg_Keygen(
820 static_cast<uint32>(key_size_index),
821 challenge.utf8(),
822 GURL(url),
823 &signed_public_key));
824 return WebString::fromUTF8(signed_public_key);
827 //------------------------------------------------------------------------------
829 void RendererBlinkPlatformImpl::screenColorProfile(
830 WebVector<char>* to_profile) {
831 #if defined(OS_WIN)
832 // On Windows screen color profile is only available in the browser.
833 std::vector<char> profile;
834 // This Send() can be called from any impl-side thread. Use a thread
835 // safe send to avoid crashing trying to access RenderThread::Get(),
836 // which is not accessible from arbitrary threads.
837 thread_safe_sender_->Send(
838 new ViewHostMsg_GetMonitorColorProfile(&profile));
839 *to_profile = profile;
840 #else
841 // On other platforms, the primary monitor color profile can be read
842 // directly.
843 gfx::ColorProfile profile;
844 *to_profile = profile.profile();
845 #endif
848 //------------------------------------------------------------------------------
850 blink::WebScrollbarBehavior* RendererBlinkPlatformImpl::scrollbarBehavior() {
851 return web_scrollbar_behavior_.get();
854 //------------------------------------------------------------------------------
856 WebBlobRegistry* RendererBlinkPlatformImpl::blobRegistry() {
857 // blob_registry_ can be NULL when running some tests.
858 return blob_registry_.get();
861 //------------------------------------------------------------------------------
863 void RendererBlinkPlatformImpl::sampleGamepads(WebGamepads& gamepads) {
864 PlatformEventObserverBase* observer =
865 platform_event_observers_.Lookup(blink::WebPlatformEventGamepad);
866 if (!observer)
867 return;
868 static_cast<RendererGamepadProvider*>(observer)->SampleGamepads(gamepads);
871 //------------------------------------------------------------------------------
873 WebRTCPeerConnectionHandler*
874 RendererBlinkPlatformImpl::createRTCPeerConnectionHandler(
875 WebRTCPeerConnectionHandlerClient* client) {
876 RenderThreadImpl* render_thread = RenderThreadImpl::current();
877 DCHECK(render_thread);
878 if (!render_thread)
879 return NULL;
881 #if defined(ENABLE_WEBRTC)
882 WebRTCPeerConnectionHandler* peer_connection_handler =
883 GetContentClient()->renderer()->OverrideCreateWebRTCPeerConnectionHandler(
884 client);
885 if (peer_connection_handler)
886 return peer_connection_handler;
888 PeerConnectionDependencyFactory* rtc_dependency_factory =
889 render_thread->GetPeerConnectionDependencyFactory();
890 return rtc_dependency_factory->CreateRTCPeerConnectionHandler(client);
891 #else
892 return NULL;
893 #endif // defined(ENABLE_WEBRTC)
896 //------------------------------------------------------------------------------
898 WebMediaStreamCenter* RendererBlinkPlatformImpl::createMediaStreamCenter(
899 WebMediaStreamCenterClient* client) {
900 RenderThreadImpl* render_thread = RenderThreadImpl::current();
901 DCHECK(render_thread);
902 if (!render_thread)
903 return NULL;
904 return render_thread->CreateMediaStreamCenter(client);
907 // static
908 bool RendererBlinkPlatformImpl::SetSandboxEnabledForTesting(bool enable) {
909 bool was_enabled = g_sandbox_enabled;
910 g_sandbox_enabled = enable;
911 return was_enabled;
914 //------------------------------------------------------------------------------
916 blink::WebSpeechSynthesizer* RendererBlinkPlatformImpl::createSpeechSynthesizer(
917 blink::WebSpeechSynthesizerClient* client) {
918 return GetContentClient()->renderer()->OverrideSpeechSynthesizer(client);
921 //------------------------------------------------------------------------------
923 bool RendererBlinkPlatformImpl::processMemorySizesInBytes(
924 size_t* private_bytes,
925 size_t* shared_bytes) {
926 content::RenderThread::Get()->Send(
927 new ViewHostMsg_GetProcessMemorySizes(private_bytes, shared_bytes));
928 return true;
931 //------------------------------------------------------------------------------
933 blink::WebGraphicsContext3D*
934 RendererBlinkPlatformImpl::createOffscreenGraphicsContext3D(
935 const blink::WebGraphicsContext3D::Attributes& attributes) {
936 return createOffscreenGraphicsContext3D(attributes, NULL);
939 blink::WebGraphicsContext3D*
940 RendererBlinkPlatformImpl::createOffscreenGraphicsContext3D(
941 const blink::WebGraphicsContext3D::Attributes& attributes,
942 blink::WebGraphicsContext3D* share_context) {
943 return createOffscreenGraphicsContext3D(attributes, share_context, NULL);
946 blink::WebGraphicsContext3D*
947 RendererBlinkPlatformImpl::createOffscreenGraphicsContext3D(
948 const blink::WebGraphicsContext3D::Attributes& attributes,
949 blink::WebGraphicsContext3D* share_context,
950 blink::WebGLInfo* gl_info) {
951 if (!RenderThreadImpl::current())
952 return NULL;
954 #if defined(OS_ANDROID)
955 SynchronousCompositorFactory* factory =
956 SynchronousCompositorFactory::GetInstance();
957 if (factory && factory->OverrideWithFactory()) {
958 scoped_ptr<gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl>
959 in_process_context(
960 factory->CreateOffscreenGraphicsContext3D(attributes));
961 if (!in_process_context || !in_process_context->InitializeOnCurrentThread())
962 return NULL;
963 return in_process_context.release();
965 #endif
967 scoped_refptr<GpuChannelHost> gpu_channel_host(
968 RenderThreadImpl::current()->EstablishGpuChannelSync(
969 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE));
971 if (gpu_channel_host.get() && gl_info) {
972 const gpu::GPUInfo& gpu_info = gpu_channel_host->gpu_info();
973 switch (gpu_info.context_info_state) {
974 case gpu::kCollectInfoSuccess:
975 case gpu::kCollectInfoNonFatalFailure:
976 gl_info->vendorInfo.assign(
977 blink::WebString::fromUTF8(gpu_info.gl_vendor));
978 gl_info->rendererInfo.assign(
979 blink::WebString::fromUTF8(gpu_info.gl_renderer));
980 gl_info->driverVersion.assign(
981 blink::WebString::fromUTF8(gpu_info.driver_version));
982 gl_info->vendorId = gpu_info.gpu.vendor_id;
983 gl_info->deviceId = gpu_info.gpu.device_id;
984 break;
985 case gpu::kCollectInfoFatalFailure:
986 case gpu::kCollectInfoNone:
987 gl_info->contextInfoCollectionFailure.assign(blink::WebString::fromUTF8(
988 "GPUInfoCollectionFailure: GPU initialization Failed. GPU "
989 "Info not Collected."));
990 break;
991 default:
992 NOTREACHED();
996 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
997 bool lose_context_when_out_of_memory = false;
998 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
999 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
1000 gpu_channel_host.get(),
1001 attributes,
1002 lose_context_when_out_of_memory,
1003 GURL(attributes.topDocumentURL),
1004 limits,
1005 static_cast<WebGraphicsContext3DCommandBufferImpl*>(share_context)));
1007 // Most likely the GPU process exited and the attempt to reconnect to it
1008 // failed. Need to try to restore the context again later.
1009 if (!context || !context->InitializeOnCurrentThread())
1010 return NULL;
1011 return context.release();
1014 //------------------------------------------------------------------------------
1016 blink::WebGraphicsContext3DProvider*
1017 RendererBlinkPlatformImpl::createSharedOffscreenGraphicsContext3DProvider() {
1018 scoped_refptr<cc_blink::ContextProviderWebContext> provider =
1019 RenderThreadImpl::current()->SharedMainThreadContextProvider();
1020 if (!provider.get())
1021 return NULL;
1022 return new WebGraphicsContext3DProviderImpl(provider);
1025 //------------------------------------------------------------------------------
1027 blink::WebCompositorSupport* RendererBlinkPlatformImpl::compositorSupport() {
1028 return &compositor_support_;
1031 //------------------------------------------------------------------------------
1033 blink::WebString RendererBlinkPlatformImpl::convertIDNToUnicode(
1034 const blink::WebString& host,
1035 const blink::WebString& languages) {
1036 return net::IDNToUnicode(host.utf8(), languages.utf8());
1039 //------------------------------------------------------------------------------
1041 void RendererBlinkPlatformImpl::recordRappor(const char* metric,
1042 const blink::WebString& sample) {
1043 GetContentClient()->renderer()->RecordRappor(metric, sample.utf8());
1046 void RendererBlinkPlatformImpl::recordRapporURL(const char* metric,
1047 const blink::WebURL& url) {
1048 GetContentClient()->renderer()->RecordRapporURL(metric, url);
1051 //------------------------------------------------------------------------------
1053 // static
1054 void RendererBlinkPlatformImpl::SetMockDeviceLightDataForTesting(double data) {
1055 g_test_device_light_data = data;
1058 //------------------------------------------------------------------------------
1060 // static
1061 void RendererBlinkPlatformImpl::SetMockDeviceMotionDataForTesting(
1062 const blink::WebDeviceMotionData& data) {
1063 g_test_device_motion_data.Get() = data;
1066 //------------------------------------------------------------------------------
1068 // static
1069 void RendererBlinkPlatformImpl::SetMockDeviceOrientationDataForTesting(
1070 const blink::WebDeviceOrientationData& data) {
1071 g_test_device_orientation_data.Get() = data;
1074 //------------------------------------------------------------------------------
1076 void RendererBlinkPlatformImpl::vibrate(unsigned int milliseconds) {
1077 GetConnectedVibrationManagerService()->Vibrate(
1078 base::checked_cast<int64>(milliseconds));
1079 vibration_manager_.reset();
1082 void RendererBlinkPlatformImpl::cancelVibration() {
1083 GetConnectedVibrationManagerService()->Cancel();
1084 vibration_manager_.reset();
1087 device::VibrationManagerPtr&
1088 RendererBlinkPlatformImpl::GetConnectedVibrationManagerService() {
1089 if (!vibration_manager_) {
1090 RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService(
1091 mojo::GetProxy(&vibration_manager_));
1093 return vibration_manager_;
1096 //------------------------------------------------------------------------------
1098 // static
1099 PlatformEventObserverBase*
1100 RendererBlinkPlatformImpl::CreatePlatformEventObserverFromType(
1101 blink::WebPlatformEventType type) {
1102 RenderThread* thread = RenderThreadImpl::current();
1104 // When running layout tests, those observers should not listen to the actual
1105 // hardware changes. In order to make that happen, they will receive a null
1106 // thread.
1107 if (thread && RenderThreadImpl::current()->layout_test_mode())
1108 thread = NULL;
1110 switch (type) {
1111 case blink::WebPlatformEventDeviceMotion:
1112 return new DeviceMotionEventPump(thread);
1113 case blink::WebPlatformEventDeviceOrientation:
1114 return new DeviceOrientationEventPump(thread);
1115 case blink::WebPlatformEventDeviceLight:
1116 return new DeviceLightEventPump(thread);
1117 case blink::WebPlatformEventGamepad:
1118 return new GamepadSharedMemoryReader(thread);
1119 case blink::WebPlatformEventScreenOrientation:
1120 return new ScreenOrientationObserver();
1121 default:
1122 // A default statement is required to prevent compilation errors when
1123 // Blink adds a new type.
1124 DVLOG(1) << "RendererBlinkPlatformImpl::startListening() with "
1125 "unknown type.";
1128 return NULL;
1131 void RendererBlinkPlatformImpl::SetPlatformEventObserverForTesting(
1132 blink::WebPlatformEventType type,
1133 scoped_ptr<PlatformEventObserverBase> observer) {
1134 DCHECK(type != blink::WebPlatformEventBattery);
1136 if (platform_event_observers_.Lookup(type))
1137 platform_event_observers_.Remove(type);
1138 platform_event_observers_.AddWithID(observer.release(), type);
1141 void RendererBlinkPlatformImpl::startListening(
1142 blink::WebPlatformEventType type,
1143 blink::WebPlatformEventListener* listener) {
1144 if (type == blink::WebPlatformEventBattery) {
1145 if (RenderThreadImpl::current() &&
1146 RenderThreadImpl::current()->layout_test_mode()) {
1147 g_test_battery_status_listener =
1148 static_cast<blink::WebBatteryStatusListener*>(listener);
1149 } else {
1150 battery_status_dispatcher_.reset(new BatteryStatusDispatcher(
1151 static_cast<blink::WebBatteryStatusListener*>(listener)));
1153 return;
1156 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type);
1157 if (!observer) {
1158 observer = CreatePlatformEventObserverFromType(type);
1159 if (!observer)
1160 return;
1161 platform_event_observers_.AddWithID(observer, static_cast<int32>(type));
1163 observer->Start(listener);
1165 // Device events (motion, orientation and light) expect to get an event fired
1166 // as soon as a listener is registered if a fake data was passed before.
1167 // TODO(mlamouri,timvolodine): make those send mock values directly instead of
1168 // using this broken pattern.
1169 if (RenderThreadImpl::current() &&
1170 RenderThreadImpl::current()->layout_test_mode() &&
1171 (type == blink::WebPlatformEventDeviceMotion ||
1172 type == blink::WebPlatformEventDeviceOrientation ||
1173 type == blink::WebPlatformEventDeviceLight)) {
1174 SendFakeDeviceEventDataForTesting(type);
1178 void RendererBlinkPlatformImpl::SendFakeDeviceEventDataForTesting(
1179 blink::WebPlatformEventType type) {
1180 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type);
1181 CHECK(observer);
1183 void* data = 0;
1185 switch (type) {
1186 case blink::WebPlatformEventDeviceMotion:
1187 if (!(g_test_device_motion_data == 0))
1188 data = &g_test_device_motion_data.Get();
1189 break;
1190 case blink::WebPlatformEventDeviceOrientation:
1191 if (!(g_test_device_orientation_data == 0))
1192 data = &g_test_device_orientation_data.Get();
1193 break;
1194 case blink::WebPlatformEventDeviceLight:
1195 if (g_test_device_light_data >= 0)
1196 data = &g_test_device_light_data;
1197 break;
1198 default:
1199 NOTREACHED();
1200 break;
1203 if (!data)
1204 return;
1206 base::ThreadTaskRunnerHandle::Get()->PostTask(
1207 FROM_HERE, base::Bind(&PlatformEventObserverBase::SendFakeDataForTesting,
1208 base::Unretained(observer), data));
1211 void RendererBlinkPlatformImpl::stopListening(
1212 blink::WebPlatformEventType type) {
1213 if (type == blink::WebPlatformEventBattery) {
1214 g_test_battery_status_listener = nullptr;
1215 battery_status_dispatcher_.reset();
1216 return;
1219 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type);
1220 if (!observer)
1221 return;
1222 observer->Stop();
1225 //------------------------------------------------------------------------------
1227 void RendererBlinkPlatformImpl::queryStorageUsageAndQuota(
1228 const blink::WebURL& storage_partition,
1229 blink::WebStorageQuotaType type,
1230 blink::WebStorageQuotaCallbacks callbacks) {
1231 if (!thread_safe_sender_.get() || !quota_message_filter_.get())
1232 return;
1233 QuotaDispatcher::ThreadSpecificInstance(thread_safe_sender_.get(),
1234 quota_message_filter_.get())
1235 ->QueryStorageUsageAndQuota(
1236 storage_partition,
1237 static_cast<storage::StorageType>(type),
1238 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
1241 //------------------------------------------------------------------------------
1243 void RendererBlinkPlatformImpl::MockBatteryStatusChangedForTesting(
1244 const blink::WebBatteryStatus& status) {
1245 if (!g_test_battery_status_listener)
1246 return;
1247 g_test_battery_status_listener->updateBatteryStatus(status);
1250 } // namespace content