Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / content / renderer / renderer_blink_platform_impl.cc
blob9df9ef4497071f88f05749111d8f448e3c7516b7
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 "components/url_formatter/url_formatter.h"
25 #include "content/child/database_util.h"
26 #include "content/child/file_info_util.h"
27 #include "content/child/fileapi/webfilesystem_impl.h"
28 #include "content/child/indexed_db/webidbfactory_impl.h"
29 #include "content/child/npapi/npobject_util.h"
30 #include "content/child/quota_dispatcher.h"
31 #include "content/child/quota_message_filter.h"
32 #include "content/child/simple_webmimeregistry_impl.h"
33 #include "content/child/thread_safe_sender.h"
34 #include "content/child/web_database_observer_impl.h"
35 #include "content/child/webblobregistry_impl.h"
36 #include "content/child/webfileutilities_impl.h"
37 #include "content/child/webmessageportchannel_impl.h"
38 #include "content/common/file_utilities_messages.h"
39 #include "content/common/frame_messages.h"
40 #include "content/common/gpu/client/context_provider_command_buffer.h"
41 #include "content/common/gpu/client/gpu_channel_host.h"
42 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
43 #include "content/common/gpu/gpu_process_launch_causes.h"
44 #include "content/common/mime_registry_messages.h"
45 #include "content/common/render_process_messages.h"
46 #include "content/public/common/content_switches.h"
47 #include "content/public/common/service_registry.h"
48 #include "content/public/common/webplugininfo.h"
49 #include "content/public/renderer/content_renderer_client.h"
50 #include "content/renderer/battery_status/battery_status_dispatcher.h"
51 #include "content/renderer/cache_storage/webserviceworkercachestorage_impl.h"
52 #include "content/renderer/device_sensors/device_light_event_pump.h"
53 #include "content/renderer/device_sensors/device_motion_event_pump.h"
54 #include "content/renderer/device_sensors/device_orientation_event_pump.h"
55 #include "content/renderer/dom_storage/webstoragenamespace_impl.h"
56 #include "content/renderer/gamepad_shared_memory_reader.h"
57 #include "content/renderer/media/audio_decoder.h"
58 #include "content/renderer/media/media_recorder_handler.h"
59 #include "content/renderer/media/renderer_webaudiodevice_impl.h"
60 #include "content/renderer/media/renderer_webmidiaccessor_impl.h"
61 #include "content/renderer/render_thread_impl.h"
62 #include "content/renderer/renderer_clipboard_delegate.h"
63 #include "content/renderer/screen_orientation/screen_orientation_observer.h"
64 #include "content/renderer/webclipboard_impl.h"
65 #include "content/renderer/webgraphicscontext3d_provider_impl.h"
66 #include "content/renderer/webpublicsuffixlist_impl.h"
67 #include "gpu/config/gpu_info.h"
68 #include "ipc/ipc_sync_message_filter.h"
69 #include "media/audio/audio_output_device.h"
70 #include "media/base/audio_hardware_config.h"
71 #include "media/base/key_systems.h"
72 #include "media/base/mime_util.h"
73 #include "media/blink/webcontentdecryptionmodule_impl.h"
74 #include "media/filters/stream_parser_factory.h"
75 #include "storage/common/database/database_identifier.h"
76 #include "storage/common/quota/quota_types.h"
77 #include "third_party/WebKit/public/platform/WebBatteryStatusListener.h"
78 #include "third_party/WebKit/public/platform/WebBlobRegistry.h"
79 #include "third_party/WebKit/public/platform/WebDeviceLightListener.h"
80 #include "third_party/WebKit/public/platform/WebFileInfo.h"
81 #include "third_party/WebKit/public/platform/WebGamepads.h"
82 #include "third_party/WebKit/public/platform/WebMediaStreamCenter.h"
83 #include "third_party/WebKit/public/platform/WebMediaStreamCenterClient.h"
84 #include "third_party/WebKit/public/platform/WebPluginListBuilder.h"
85 #include "third_party/WebKit/public/platform/WebURL.h"
86 #include "third_party/WebKit/public/platform/WebVector.h"
87 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceMotionListener.h"
88 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceOrientationListener.h"
89 #include "ui/gfx/color_profile.h"
90 #include "url/gurl.h"
92 #if defined(OS_ANDROID)
93 #include "content/renderer/android/synchronous_compositor_factory.h"
94 #include "content/renderer/media/android/audio_decoder_android.h"
95 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h"
96 #endif
98 #if defined(OS_MACOSX)
99 #include "content/common/mac/font_descriptor.h"
100 #include "content/common/mac/font_loader.h"
101 #include "content/renderer/webscrollbarbehavior_impl_mac.h"
102 #include "third_party/WebKit/public/platform/mac/WebSandboxSupport.h"
103 #endif
105 #if defined(OS_POSIX)
106 #include "base/file_descriptor_posix.h"
107 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
108 #include <map>
109 #include <string>
111 #include "base/synchronization/lock.h"
112 #include "content/common/child_process_sandbox_support_impl_linux.h"
113 #include "third_party/WebKit/public/platform/linux/WebFallbackFont.h"
114 #include "third_party/WebKit/public/platform/linux/WebSandboxSupport.h"
115 #include "third_party/icu/source/common/unicode/utf16.h"
116 #endif
117 #endif
119 #if defined(OS_WIN)
120 #include "content/common/child_process_messages.h"
121 #endif
123 #if defined(USE_AURA)
124 #include "content/renderer/webscrollbarbehavior_impl_gtkoraura.h"
125 #elif !defined(OS_MACOSX)
126 #include "third_party/WebKit/public/platform/WebScrollbarBehavior.h"
127 #define WebScrollbarBehaviorImpl blink::WebScrollbarBehavior
128 #endif
130 #if defined(ENABLE_WEBRTC)
131 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
132 #endif
134 using blink::Platform;
135 using blink::WebAudioDevice;
136 using blink::WebBlobRegistry;
137 using blink::WebDatabaseObserver;
138 using blink::WebFileInfo;
139 using blink::WebFileSystem;
140 using blink::WebGamepad;
141 using blink::WebGamepads;
142 using blink::WebIDBFactory;
143 using blink::WebMIDIAccessor;
144 using blink::WebMediaRecorderHandler;
145 using blink::WebMediaStreamCenter;
146 using blink::WebMediaStreamCenterClient;
147 using blink::WebMimeRegistry;
148 using blink::WebRTCPeerConnectionHandler;
149 using blink::WebRTCPeerConnectionHandlerClient;
150 using blink::WebStorageNamespace;
151 using blink::WebString;
152 using blink::WebURL;
153 using blink::WebVector;
155 namespace content {
157 namespace {
159 bool g_sandbox_enabled = true;
160 double g_test_device_light_data = -1;
161 base::LazyInstance<blink::WebDeviceMotionData>::Leaky
162 g_test_device_motion_data = LAZY_INSTANCE_INITIALIZER;
163 base::LazyInstance<blink::WebDeviceOrientationData>::Leaky
164 g_test_device_orientation_data = LAZY_INSTANCE_INITIALIZER;
165 // Set in startListening() when running layout tests, unset in stopListening(),
166 // not owned by us.
167 blink::WebBatteryStatusListener* g_test_battery_status_listener = nullptr;
169 } // namespace
171 //------------------------------------------------------------------------------
173 class RendererBlinkPlatformImpl::MimeRegistry
174 : public SimpleWebMimeRegistryImpl {
175 public:
176 virtual blink::WebMimeRegistry::SupportsType supportsMediaMIMEType(
177 const blink::WebString& mime_type,
178 const blink::WebString& codecs,
179 const blink::WebString& key_system);
180 virtual bool supportsMediaSourceMIMEType(const blink::WebString& mime_type,
181 const blink::WebString& codecs);
182 virtual blink::WebString mimeTypeForExtension(
183 const blink::WebString& file_extension);
184 virtual blink::WebString mimeTypeFromFile(
185 const blink::WebString& file_path);
188 class RendererBlinkPlatformImpl::FileUtilities : public WebFileUtilitiesImpl {
189 public:
190 explicit FileUtilities(ThreadSafeSender* sender)
191 : thread_safe_sender_(sender) {}
192 virtual bool getFileInfo(const WebString& path, WebFileInfo& result);
193 private:
194 bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) const;
195 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
198 #if !defined(OS_ANDROID) && !defined(OS_WIN)
199 class RendererBlinkPlatformImpl::SandboxSupport
200 : public blink::WebSandboxSupport {
201 public:
202 virtual ~SandboxSupport() {}
204 #if defined(OS_MACOSX)
205 virtual bool loadFont(
206 NSFont* src_font,
207 CGFontRef* container,
208 uint32* font_id);
209 #elif defined(OS_POSIX)
210 virtual void getFallbackFontForCharacter(
211 blink::WebUChar32 character,
212 const char* preferred_locale,
213 blink::WebFallbackFont* fallbackFont);
214 virtual void getRenderStyleForStrike(
215 const char* family, int sizeAndStyle, blink::WebFontRenderStyle* out);
217 private:
218 // WebKit likes to ask us for the correct font family to use for a set of
219 // unicode code points. It needs this information frequently so we cache it
220 // here.
221 base::Lock unicode_font_families_mutex_;
222 std::map<int32_t, blink::WebFallbackFont> unicode_font_families_;
223 #endif
225 #endif // !defined(OS_ANDROID) && !defined(OS_WIN)
227 //------------------------------------------------------------------------------
229 RendererBlinkPlatformImpl::RendererBlinkPlatformImpl(
230 scheduler::RendererScheduler* renderer_scheduler)
231 : BlinkPlatformImpl(renderer_scheduler->DefaultTaskRunner()),
232 main_thread_(
233 new scheduler::WebThreadImplForRendererScheduler(renderer_scheduler)),
234 clipboard_delegate_(new RendererClipboardDelegate),
235 clipboard_(new WebClipboardImpl(clipboard_delegate_.get())),
236 mime_registry_(new RendererBlinkPlatformImpl::MimeRegistry),
237 sudden_termination_disables_(0),
238 plugin_refresh_allowed_(true),
239 default_task_runner_(renderer_scheduler->DefaultTaskRunner()),
240 web_scrollbar_behavior_(new WebScrollbarBehaviorImpl) {
241 #if !defined(OS_ANDROID) && !defined(OS_WIN)
242 if (g_sandbox_enabled && sandboxEnabled()) {
243 sandbox_support_.reset(new RendererBlinkPlatformImpl::SandboxSupport);
244 } else {
245 DVLOG(1) << "Disabling sandbox support for testing.";
247 #endif
249 // ChildThread may not exist in some tests.
250 if (ChildThreadImpl::current()) {
251 sync_message_filter_ = ChildThreadImpl::current()->sync_message_filter();
252 thread_safe_sender_ = ChildThreadImpl::current()->thread_safe_sender();
253 quota_message_filter_ = ChildThreadImpl::current()->quota_message_filter();
254 blob_registry_.reset(new WebBlobRegistryImpl(thread_safe_sender_.get()));
255 web_idb_factory_.reset(new WebIDBFactoryImpl(thread_safe_sender_.get()));
256 web_database_observer_impl_.reset(
257 new WebDatabaseObserverImpl(sync_message_filter_.get()));
261 RendererBlinkPlatformImpl::~RendererBlinkPlatformImpl() {
262 WebFileSystemImpl::DeleteThreadSpecificInstance();
265 void RendererBlinkPlatformImpl::Shutdown() {
266 #if !defined(OS_ANDROID) && !defined(OS_WIN)
267 // SandboxSupport contains a map of WebFontFamily objects, which hold
268 // WebCStrings, which become invalidated when blink is shut down. Hence, we
269 // need to clear that map now, just before blink::shutdown() is called.
270 sandbox_support_.reset();
271 #endif
274 //------------------------------------------------------------------------------
276 blink::WebThread* RendererBlinkPlatformImpl::currentThread() {
277 if (main_thread_->isCurrentThread())
278 return main_thread_.get();
279 return BlinkPlatformImpl::currentThread();
282 blink::WebClipboard* RendererBlinkPlatformImpl::clipboard() {
283 blink::WebClipboard* clipboard =
284 GetContentClient()->renderer()->OverrideWebClipboard();
285 if (clipboard)
286 return clipboard;
287 return clipboard_.get();
290 blink::WebMimeRegistry* RendererBlinkPlatformImpl::mimeRegistry() {
291 return mime_registry_.get();
294 blink::WebFileUtilities* RendererBlinkPlatformImpl::fileUtilities() {
295 if (!file_utilities_) {
296 file_utilities_.reset(new FileUtilities(thread_safe_sender_.get()));
297 file_utilities_->set_sandbox_enabled(sandboxEnabled());
299 return file_utilities_.get();
302 blink::WebSandboxSupport* RendererBlinkPlatformImpl::sandboxSupport() {
303 #if defined(OS_ANDROID) || defined(OS_WIN)
304 // These platforms do not require sandbox support.
305 return NULL;
306 #else
307 return sandbox_support_.get();
308 #endif
311 blink::WebCookieJar* RendererBlinkPlatformImpl::cookieJar() {
312 NOTREACHED() << "Use WebFrameClient::cookieJar() instead!";
313 return NULL;
316 blink::WebThemeEngine* RendererBlinkPlatformImpl::themeEngine() {
317 blink::WebThemeEngine* theme_engine =
318 GetContentClient()->renderer()->OverrideThemeEngine();
319 if (theme_engine)
320 return theme_engine;
321 return BlinkPlatformImpl::themeEngine();
324 bool RendererBlinkPlatformImpl::sandboxEnabled() {
325 // As explained in Platform.h, this function is used to decide
326 // whether to allow file system operations to come out of WebKit or not.
327 // Even if the sandbox is disabled, there's no reason why the code should
328 // act any differently...unless we're in single process mode. In which
329 // case, we have no other choice. Platform.h discourages using
330 // this switch unless absolutely necessary, so hopefully we won't end up
331 // with too many code paths being different in single-process mode.
332 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
333 switches::kSingleProcess);
336 unsigned long long RendererBlinkPlatformImpl::visitedLinkHash(
337 const char* canonical_url,
338 size_t length) {
339 return GetContentClient()->renderer()->VisitedLinkHash(canonical_url, length);
342 bool RendererBlinkPlatformImpl::isLinkVisited(unsigned long long link_hash) {
343 return GetContentClient()->renderer()->IsLinkVisited(link_hash);
346 void RendererBlinkPlatformImpl::createMessageChannel(
347 blink::WebMessagePortChannel** channel1,
348 blink::WebMessagePortChannel** channel2) {
349 WebMessagePortChannelImpl::CreatePair(
350 default_task_runner_, channel1, channel2);
353 blink::WebPrescientNetworking*
354 RendererBlinkPlatformImpl::prescientNetworking() {
355 return GetContentClient()->renderer()->GetPrescientNetworking();
358 void RendererBlinkPlatformImpl::cacheMetadata(const blink::WebURL& url,
359 int64 response_time,
360 const char* data,
361 size_t size) {
362 // Let the browser know we generated cacheable metadata for this resource. The
363 // browser may cache it and return it on subsequent responses to speed
364 // the processing of this resource.
365 std::vector<char> copy(data, data + size);
366 RenderThread::Get()->Send(
367 new RenderProcessHostMsg_DidGenerateCacheableMetadata(
368 url, base::Time::FromInternalValue(response_time), copy));
371 WebString RendererBlinkPlatformImpl::defaultLocale() {
372 return base::ASCIIToUTF16(RenderThread::Get()->GetLocale());
375 void RendererBlinkPlatformImpl::suddenTerminationChanged(bool enabled) {
376 if (enabled) {
377 // We should not get more enables than disables, but we want it to be a
378 // non-fatal error if it does happen.
379 DCHECK_GT(sudden_termination_disables_, 0);
380 sudden_termination_disables_ = std::max(sudden_termination_disables_ - 1,
382 if (sudden_termination_disables_ != 0)
383 return;
384 } else {
385 sudden_termination_disables_++;
386 if (sudden_termination_disables_ != 1)
387 return;
390 RenderThread* thread = RenderThread::Get();
391 if (thread) // NULL in unittests.
392 thread->Send(new RenderProcessHostMsg_SuddenTerminationChanged(enabled));
395 WebStorageNamespace* RendererBlinkPlatformImpl::createLocalStorageNamespace() {
396 return new WebStorageNamespaceImpl();
400 //------------------------------------------------------------------------------
402 WebIDBFactory* RendererBlinkPlatformImpl::idbFactory() {
403 return web_idb_factory_.get();
406 //------------------------------------------------------------------------------
408 blink::WebServiceWorkerCacheStorage* RendererBlinkPlatformImpl::cacheStorage(
409 const WebString& origin_identifier) {
410 const GURL origin =
411 storage::GetOriginFromIdentifier(origin_identifier.utf8());
412 return new WebServiceWorkerCacheStorageImpl(thread_safe_sender_.get(),
413 origin);
416 //------------------------------------------------------------------------------
418 WebFileSystem* RendererBlinkPlatformImpl::fileSystem() {
419 return WebFileSystemImpl::ThreadSpecificInstance(default_task_runner_);
422 //------------------------------------------------------------------------------
424 WebMimeRegistry::SupportsType
425 RendererBlinkPlatformImpl::MimeRegistry::supportsMediaMIMEType(
426 const WebString& mime_type,
427 const WebString& codecs,
428 const WebString& key_system) {
429 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type);
430 // Not supporting the container is a flat-out no.
431 if (!media::IsSupportedMediaMimeType(mime_type_ascii))
432 return IsNotSupported;
434 if (!key_system.isEmpty()) {
435 // Check whether the key system is supported with the mime_type and codecs.
437 // Chromium only supports ASCII parameters.
438 if (!base::IsStringASCII(key_system))
439 return IsNotSupported;
441 std::string key_system_ascii =
442 media::GetUnprefixedKeySystemName(base::UTF16ToASCII(
443 base::StringPiece16(key_system)));
444 std::vector<std::string> strict_codecs;
445 media::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, true);
447 if (!media::PrefixedIsSupportedKeySystemWithMediaMimeType(
448 mime_type_ascii, strict_codecs, key_system_ascii)) {
449 return IsNotSupported;
452 // Continue processing the mime_type and codecs.
455 // Check list of strict codecs to see if it is supported.
456 if (media::IsStrictMediaMimeType(mime_type_ascii)) {
457 // Check if the codecs are a perfect match.
458 std::vector<std::string> strict_codecs;
459 media::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, false);
460 return static_cast<WebMimeRegistry::SupportsType> (
461 media::IsSupportedStrictMediaMimeType(mime_type_ascii, strict_codecs));
464 // If we don't recognize the codec, it's possible we support it.
465 std::vector<std::string> parsed_codecs;
466 media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true);
467 if (!media::AreSupportedMediaCodecs(parsed_codecs))
468 return MayBeSupported;
470 // Otherwise we have a perfect match.
471 return IsSupported;
474 bool RendererBlinkPlatformImpl::MimeRegistry::supportsMediaSourceMIMEType(
475 const blink::WebString& mime_type,
476 const WebString& codecs) {
477 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type);
478 std::vector<std::string> parsed_codec_ids;
479 media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false);
480 if (mime_type_ascii.empty())
481 return false;
482 return media::StreamParserFactory::IsTypeSupported(
483 mime_type_ascii, parsed_codec_ids);
486 WebString RendererBlinkPlatformImpl::MimeRegistry::mimeTypeForExtension(
487 const WebString& file_extension) {
488 if (IsPluginProcess())
489 return SimpleWebMimeRegistryImpl::mimeTypeForExtension(file_extension);
491 // The sandbox restricts our access to the registry, so we need to proxy
492 // these calls over to the browser process.
493 std::string mime_type;
494 RenderThread::Get()->Send(
495 new MimeRegistryMsg_GetMimeTypeFromExtension(
496 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type));
497 return base::ASCIIToUTF16(mime_type);
500 WebString RendererBlinkPlatformImpl::MimeRegistry::mimeTypeFromFile(
501 const WebString& file_path) {
502 if (IsPluginProcess())
503 return SimpleWebMimeRegistryImpl::mimeTypeFromFile(file_path);
505 // The sandbox restricts our access to the registry, so we need to proxy
506 // these calls over to the browser process.
507 std::string mime_type;
508 RenderThread::Get()->Send(new MimeRegistryMsg_GetMimeTypeFromFile(
509 base::FilePath::FromUTF16Unsafe(file_path),
510 &mime_type));
511 return base::ASCIIToUTF16(mime_type);
514 //------------------------------------------------------------------------------
516 bool RendererBlinkPlatformImpl::FileUtilities::getFileInfo(
517 const WebString& path,
518 WebFileInfo& web_file_info) {
519 base::File::Info file_info;
520 base::File::Error status = base::File::FILE_ERROR_MAX;
521 if (!SendSyncMessageFromAnyThread(new FileUtilitiesMsg_GetFileInfo(
522 base::FilePath::FromUTF16Unsafe(path), &file_info, &status)) ||
523 status != base::File::FILE_OK) {
524 return false;
526 FileInfoToWebFileInfo(file_info, &web_file_info);
527 web_file_info.platformPath = path;
528 return true;
531 bool RendererBlinkPlatformImpl::FileUtilities::SendSyncMessageFromAnyThread(
532 IPC::SyncMessage* msg) const {
533 base::TimeTicks begin = base::TimeTicks::Now();
534 const bool success = thread_safe_sender_->Send(msg);
535 base::TimeDelta delta = base::TimeTicks::Now() - begin;
536 UMA_HISTOGRAM_TIMES("RendererSyncIPC.ElapsedTime", delta);
537 return success;
540 //------------------------------------------------------------------------------
542 #if defined(OS_MACOSX)
544 bool RendererBlinkPlatformImpl::SandboxSupport::loadFont(NSFont* src_font,
545 CGFontRef* out,
546 uint32* font_id) {
547 uint32 font_data_size;
548 FontDescriptor src_font_descriptor(src_font);
549 base::SharedMemoryHandle font_data;
550 if (!RenderThread::Get()->Send(new RenderProcessHostMsg_LoadFont(
551 src_font_descriptor, &font_data_size, &font_data, font_id))) {
552 *out = NULL;
553 *font_id = 0;
554 return false;
557 if (font_data_size == 0 || font_data == base::SharedMemory::NULLHandle() ||
558 *font_id == 0) {
559 LOG(ERROR) << "Bad response from RenderProcessHostMsg_LoadFont() for " <<
560 src_font_descriptor.font_name;
561 *out = NULL;
562 *font_id = 0;
563 return false;
566 // TODO(jeremy): Need to call back into WebKit to make sure that the font
567 // isn't already activated, based on the font id. If it's already
568 // activated, don't reactivate it here - crbug.com/72727 .
570 return FontLoader::CGFontRefFromBuffer(font_data, font_data_size, out);
573 #elif defined(OS_POSIX) && !defined(OS_ANDROID)
575 void RendererBlinkPlatformImpl::SandboxSupport::getFallbackFontForCharacter(
576 blink::WebUChar32 character,
577 const char* preferred_locale,
578 blink::WebFallbackFont* fallbackFont) {
579 base::AutoLock lock(unicode_font_families_mutex_);
580 const std::map<int32_t, blink::WebFallbackFont>::const_iterator iter =
581 unicode_font_families_.find(character);
582 if (iter != unicode_font_families_.end()) {
583 fallbackFont->name = iter->second.name;
584 fallbackFont->filename = iter->second.filename;
585 fallbackFont->fontconfigInterfaceId = iter->second.fontconfigInterfaceId;
586 fallbackFont->ttcIndex = iter->second.ttcIndex;
587 fallbackFont->isBold = iter->second.isBold;
588 fallbackFont->isItalic = iter->second.isItalic;
589 return;
592 GetFallbackFontForCharacter(character, preferred_locale, fallbackFont);
593 unicode_font_families_.insert(std::make_pair(character, *fallbackFont));
596 void RendererBlinkPlatformImpl::SandboxSupport::getRenderStyleForStrike(
597 const char* family,
598 int sizeAndStyle,
599 blink::WebFontRenderStyle* out) {
600 GetRenderStyleForStrike(family, sizeAndStyle, out);
603 #endif
605 //------------------------------------------------------------------------------
607 Platform::FileHandle RendererBlinkPlatformImpl::databaseOpenFile(
608 const WebString& vfs_file_name,
609 int desired_flags) {
610 return DatabaseUtil::DatabaseOpenFile(
611 vfs_file_name, desired_flags, sync_message_filter_.get());
614 int RendererBlinkPlatformImpl::databaseDeleteFile(
615 const WebString& vfs_file_name,
616 bool sync_dir) {
617 return DatabaseUtil::DatabaseDeleteFile(
618 vfs_file_name, sync_dir, sync_message_filter_.get());
621 long RendererBlinkPlatformImpl::databaseGetFileAttributes(
622 const WebString& vfs_file_name) {
623 return DatabaseUtil::DatabaseGetFileAttributes(vfs_file_name,
624 sync_message_filter_.get());
627 long long RendererBlinkPlatformImpl::databaseGetFileSize(
628 const WebString& vfs_file_name) {
629 return DatabaseUtil::DatabaseGetFileSize(vfs_file_name,
630 sync_message_filter_.get());
633 long long RendererBlinkPlatformImpl::databaseGetSpaceAvailableForOrigin(
634 const WebString& origin_identifier) {
635 return DatabaseUtil::DatabaseGetSpaceAvailable(origin_identifier,
636 sync_message_filter_.get());
639 bool RendererBlinkPlatformImpl::databaseSetFileSize(
640 const WebString& vfs_file_name, long long size) {
641 return DatabaseUtil::DatabaseSetFileSize(
642 vfs_file_name, size, sync_message_filter_.get());
645 bool RendererBlinkPlatformImpl::canAccelerate2dCanvas() {
646 #if defined(OS_ANDROID)
647 SynchronousCompositorFactory* factory =
648 SynchronousCompositorFactory::GetInstance();
649 if (factory && factory->OverrideWithFactory()) {
650 return factory->GetGPUInfo().SupportsAccelerated2dCanvas();
652 #endif
654 RenderThreadImpl* thread = RenderThreadImpl::current();
655 GpuChannelHost* host = thread->EstablishGpuChannelSync(
656 CAUSE_FOR_GPU_LAUNCH_CANVAS_2D);
657 if (!host)
658 return false;
660 return host->gpu_info().SupportsAccelerated2dCanvas();
663 bool RendererBlinkPlatformImpl::isThreadedCompositingEnabled() {
664 RenderThreadImpl* thread = RenderThreadImpl::current();
665 // thread can be NULL in tests.
666 return thread && thread->compositor_task_runner().get();
669 bool RendererBlinkPlatformImpl::isThreadedAnimationEnabled() {
670 RenderThreadImpl* thread = RenderThreadImpl::current();
671 return thread ? thread->IsThreadedAnimationEnabled() : true;
674 double RendererBlinkPlatformImpl::audioHardwareSampleRate() {
675 RenderThreadImpl* thread = RenderThreadImpl::current();
676 return thread->GetAudioHardwareConfig()->GetOutputSampleRate();
679 size_t RendererBlinkPlatformImpl::audioHardwareBufferSize() {
680 RenderThreadImpl* thread = RenderThreadImpl::current();
681 return thread->GetAudioHardwareConfig()->GetOutputBufferSize();
684 unsigned RendererBlinkPlatformImpl::audioHardwareOutputChannels() {
685 RenderThreadImpl* thread = RenderThreadImpl::current();
686 return thread->GetAudioHardwareConfig()->GetOutputChannels();
689 WebDatabaseObserver* RendererBlinkPlatformImpl::databaseObserver() {
690 return web_database_observer_impl_.get();
693 WebAudioDevice* RendererBlinkPlatformImpl::createAudioDevice(
694 size_t buffer_size,
695 unsigned input_channels,
696 unsigned channels,
697 double sample_rate,
698 WebAudioDevice::RenderCallback* callback,
699 const blink::WebString& input_device_id) {
700 // Use a mock for testing.
701 blink::WebAudioDevice* mock_device =
702 GetContentClient()->renderer()->OverrideCreateAudioDevice(sample_rate);
703 if (mock_device)
704 return mock_device;
706 // The |channels| does not exactly identify the channel layout of the
707 // device. The switch statement below assigns a best guess to the channel
708 // layout based on number of channels.
709 media::ChannelLayout layout = media::CHANNEL_LAYOUT_UNSUPPORTED;
710 switch (channels) {
711 case 1:
712 layout = media::CHANNEL_LAYOUT_MONO;
713 break;
714 case 2:
715 layout = media::CHANNEL_LAYOUT_STEREO;
716 break;
717 case 3:
718 layout = media::CHANNEL_LAYOUT_2_1;
719 break;
720 case 4:
721 layout = media::CHANNEL_LAYOUT_4_0;
722 break;
723 case 5:
724 layout = media::CHANNEL_LAYOUT_5_0;
725 break;
726 case 6:
727 layout = media::CHANNEL_LAYOUT_5_1;
728 break;
729 case 7:
730 layout = media::CHANNEL_LAYOUT_7_0;
731 break;
732 case 8:
733 layout = media::CHANNEL_LAYOUT_7_1;
734 break;
735 default:
736 // If the layout is not supported (more than 9 channels), falls back to
737 // discrete mode.
738 layout = media::CHANNEL_LAYOUT_DISCRETE;
741 int session_id = 0;
742 if (input_device_id.isNull() ||
743 !base::StringToInt(base::UTF16ToUTF8(
744 base::StringPiece16(input_device_id)), &session_id)) {
745 if (input_channels > 0)
746 DLOG(WARNING) << "createAudioDevice(): request for audio input ignored";
748 input_channels = 0;
751 // For CHANNEL_LAYOUT_DISCRETE, pass the explicit channel count along with
752 // the channel layout when creating an |AudioParameters| object.
753 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
754 layout, static_cast<int>(sample_rate), 16,
755 buffer_size);
756 params.set_channels_for_discrete(channels);
758 return new RendererWebAudioDeviceImpl(params, callback, session_id);
761 #if defined(OS_ANDROID)
762 bool RendererBlinkPlatformImpl::loadAudioResource(
763 blink::WebAudioBus* destination_bus,
764 const char* audio_file_data,
765 size_t data_size) {
766 return DecodeAudioFileData(destination_bus,
767 audio_file_data,
768 data_size,
769 thread_safe_sender_);
771 #else
772 bool RendererBlinkPlatformImpl::loadAudioResource(
773 blink::WebAudioBus* destination_bus,
774 const char* audio_file_data,
775 size_t data_size) {
776 return DecodeAudioFileData(
777 destination_bus, audio_file_data, data_size);
779 #endif // defined(OS_ANDROID)
781 //------------------------------------------------------------------------------
783 blink::WebMIDIAccessor* RendererBlinkPlatformImpl::createMIDIAccessor(
784 blink::WebMIDIAccessorClient* client) {
785 blink::WebMIDIAccessor* accessor =
786 GetContentClient()->renderer()->OverrideCreateMIDIAccessor(client);
787 if (accessor)
788 return accessor;
790 return new RendererWebMIDIAccessorImpl(client);
793 void RendererBlinkPlatformImpl::getPluginList(
794 bool refresh,
795 blink::WebPluginListBuilder* builder) {
796 #if defined(ENABLE_PLUGINS)
797 std::vector<WebPluginInfo> plugins;
798 if (!plugin_refresh_allowed_)
799 refresh = false;
800 RenderThread::Get()->Send(new FrameHostMsg_GetPlugins(refresh, &plugins));
801 for (const WebPluginInfo& plugin : plugins) {
802 builder->addPlugin(
803 plugin.name, plugin.desc,
804 plugin.path.BaseName().AsUTF16Unsafe());
806 for (const WebPluginMimeType& mime_type : plugin.mime_types) {
807 builder->addMediaTypeToLastPlugin(
808 WebString::fromUTF8(mime_type.mime_type), mime_type.description);
810 for (const auto& extension : mime_type.file_extensions) {
811 builder->addFileExtensionToLastMediaType(
812 WebString::fromUTF8(extension));
816 #endif
819 //------------------------------------------------------------------------------
821 blink::WebPublicSuffixList* RendererBlinkPlatformImpl::publicSuffixList() {
822 return &public_suffix_list_;
825 //------------------------------------------------------------------------------
827 blink::WebString RendererBlinkPlatformImpl::signedPublicKeyAndChallengeString(
828 unsigned key_size_index,
829 const blink::WebString& challenge,
830 const blink::WebURL& url) {
831 std::string signed_public_key;
832 RenderThread::Get()->Send(new RenderProcessHostMsg_Keygen(
833 static_cast<uint32>(key_size_index),
834 challenge.utf8(),
835 GURL(url),
836 &signed_public_key));
837 return WebString::fromUTF8(signed_public_key);
840 //------------------------------------------------------------------------------
842 void RendererBlinkPlatformImpl::screenColorProfile(
843 WebVector<char>* to_profile) {
844 #if defined(OS_WIN)
845 // On Windows screen color profile is only available in the browser.
846 std::vector<char> profile;
847 // This Send() can be called from any impl-side thread. Use a thread
848 // safe send to avoid crashing trying to access RenderThread::Get(),
849 // which is not accessible from arbitrary threads.
850 thread_safe_sender_->Send(
851 new RenderProcessHostMsg_GetMonitorColorProfile(&profile));
852 *to_profile = profile;
853 #else
854 // On other platforms, the primary monitor color profile can be read
855 // directly.
856 gfx::ColorProfile profile;
857 *to_profile = profile.profile();
858 #endif
861 //------------------------------------------------------------------------------
863 blink::WebScrollbarBehavior* RendererBlinkPlatformImpl::scrollbarBehavior() {
864 return web_scrollbar_behavior_.get();
867 //------------------------------------------------------------------------------
869 WebBlobRegistry* RendererBlinkPlatformImpl::blobRegistry() {
870 // blob_registry_ can be NULL when running some tests.
871 return blob_registry_.get();
874 //------------------------------------------------------------------------------
876 void RendererBlinkPlatformImpl::sampleGamepads(WebGamepads& gamepads) {
877 PlatformEventObserverBase* observer =
878 platform_event_observers_.Lookup(blink::WebPlatformEventGamepad);
879 if (!observer)
880 return;
881 static_cast<RendererGamepadProvider*>(observer)->SampleGamepads(gamepads);
884 //------------------------------------------------------------------------------
886 WebMediaRecorderHandler*
887 RendererBlinkPlatformImpl::createMediaRecorderHandler() {
888 #if !defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
889 return new content::MediaRecorderHandler();
890 #else
891 return nullptr;
892 #endif
895 //------------------------------------------------------------------------------
897 WebRTCPeerConnectionHandler*
898 RendererBlinkPlatformImpl::createRTCPeerConnectionHandler(
899 WebRTCPeerConnectionHandlerClient* client) {
900 RenderThreadImpl* render_thread = RenderThreadImpl::current();
901 DCHECK(render_thread);
902 if (!render_thread)
903 return NULL;
905 #if defined(ENABLE_WEBRTC)
906 WebRTCPeerConnectionHandler* peer_connection_handler =
907 GetContentClient()->renderer()->OverrideCreateWebRTCPeerConnectionHandler(
908 client);
909 if (peer_connection_handler)
910 return peer_connection_handler;
912 PeerConnectionDependencyFactory* rtc_dependency_factory =
913 render_thread->GetPeerConnectionDependencyFactory();
914 return rtc_dependency_factory->CreateRTCPeerConnectionHandler(client);
915 #else
916 return NULL;
917 #endif // defined(ENABLE_WEBRTC)
920 //------------------------------------------------------------------------------
922 WebMediaStreamCenter* RendererBlinkPlatformImpl::createMediaStreamCenter(
923 WebMediaStreamCenterClient* client) {
924 RenderThreadImpl* render_thread = RenderThreadImpl::current();
925 DCHECK(render_thread);
926 if (!render_thread)
927 return NULL;
928 return render_thread->CreateMediaStreamCenter(client);
931 // static
932 bool RendererBlinkPlatformImpl::SetSandboxEnabledForTesting(bool enable) {
933 bool was_enabled = g_sandbox_enabled;
934 g_sandbox_enabled = enable;
935 return was_enabled;
938 //------------------------------------------------------------------------------
940 blink::WebSpeechSynthesizer* RendererBlinkPlatformImpl::createSpeechSynthesizer(
941 blink::WebSpeechSynthesizerClient* client) {
942 return GetContentClient()->renderer()->OverrideSpeechSynthesizer(client);
945 //------------------------------------------------------------------------------
947 bool RendererBlinkPlatformImpl::processMemorySizesInBytes(
948 size_t* private_bytes,
949 size_t* shared_bytes) {
950 content::RenderThread::Get()->Send(
951 new RenderProcessHostMsg_GetProcessMemorySizes(
952 private_bytes, shared_bytes));
953 return true;
956 //------------------------------------------------------------------------------
958 blink::WebGraphicsContext3D*
959 RendererBlinkPlatformImpl::createOffscreenGraphicsContext3D(
960 const blink::WebGraphicsContext3D::Attributes& attributes) {
961 return createOffscreenGraphicsContext3D(attributes, NULL);
964 blink::WebGraphicsContext3D*
965 RendererBlinkPlatformImpl::createOffscreenGraphicsContext3D(
966 const blink::WebGraphicsContext3D::Attributes& attributes,
967 blink::WebGraphicsContext3D* share_context) {
968 return createOffscreenGraphicsContext3D(attributes, share_context, NULL);
971 blink::WebGraphicsContext3D*
972 RendererBlinkPlatformImpl::createOffscreenGraphicsContext3D(
973 const blink::WebGraphicsContext3D::Attributes& attributes,
974 blink::WebGraphicsContext3D* share_context,
975 blink::WebGLInfo* gl_info) {
976 if (!RenderThreadImpl::current())
977 return NULL;
979 #if defined(OS_ANDROID)
980 SynchronousCompositorFactory* factory =
981 SynchronousCompositorFactory::GetInstance();
982 if (factory && factory->OverrideWithFactory()) {
983 scoped_ptr<gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl>
984 in_process_context(
985 factory->CreateOffscreenGraphicsContext3D(attributes));
986 if (!in_process_context || !in_process_context->InitializeOnCurrentThread())
987 return NULL;
988 return in_process_context.release();
990 #endif
992 scoped_refptr<GpuChannelHost> gpu_channel_host(
993 RenderThreadImpl::current()->EstablishGpuChannelSync(
994 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE));
996 if (gpu_channel_host.get() && gl_info) {
997 const gpu::GPUInfo& gpu_info = gpu_channel_host->gpu_info();
998 switch (gpu_info.context_info_state) {
999 case gpu::kCollectInfoSuccess:
1000 case gpu::kCollectInfoNonFatalFailure:
1001 gl_info->vendorInfo.assign(
1002 blink::WebString::fromUTF8(gpu_info.gl_vendor));
1003 gl_info->rendererInfo.assign(
1004 blink::WebString::fromUTF8(gpu_info.gl_renderer));
1005 gl_info->driverVersion.assign(
1006 blink::WebString::fromUTF8(gpu_info.driver_version));
1007 gl_info->vendorId = gpu_info.gpu.vendor_id;
1008 gl_info->deviceId = gpu_info.gpu.device_id;
1009 break;
1010 case gpu::kCollectInfoFatalFailure:
1011 case gpu::kCollectInfoNone:
1012 gl_info->contextInfoCollectionFailure.assign(blink::WebString::fromUTF8(
1013 "GPUInfoCollectionFailure: GPU initialization Failed. GPU "
1014 "Info not Collected."));
1015 break;
1016 default:
1017 NOTREACHED();
1021 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
1022 bool lose_context_when_out_of_memory = false;
1023 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
1024 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
1025 gpu_channel_host.get(),
1026 attributes,
1027 lose_context_when_out_of_memory,
1028 GURL(attributes.topDocumentURL),
1029 limits,
1030 static_cast<WebGraphicsContext3DCommandBufferImpl*>(share_context)));
1032 // Most likely the GPU process exited and the attempt to reconnect to it
1033 // failed. Need to try to restore the context again later.
1034 if (!context || !context->InitializeOnCurrentThread())
1035 return NULL;
1036 return context.release();
1039 //------------------------------------------------------------------------------
1041 blink::WebGraphicsContext3DProvider*
1042 RendererBlinkPlatformImpl::createSharedOffscreenGraphicsContext3DProvider() {
1043 scoped_refptr<cc_blink::ContextProviderWebContext> provider =
1044 RenderThreadImpl::current()->SharedMainThreadContextProvider();
1045 if (!provider.get())
1046 return NULL;
1047 return new WebGraphicsContext3DProviderImpl(provider);
1050 //------------------------------------------------------------------------------
1052 blink::WebCompositorSupport* RendererBlinkPlatformImpl::compositorSupport() {
1053 return &compositor_support_;
1056 //------------------------------------------------------------------------------
1058 blink::WebString RendererBlinkPlatformImpl::convertIDNToUnicode(
1059 const blink::WebString& host,
1060 const blink::WebString& languages) {
1061 return url_formatter::IDNToUnicode(host.utf8(), languages.utf8());
1064 //------------------------------------------------------------------------------
1066 void RendererBlinkPlatformImpl::recordRappor(const char* metric,
1067 const blink::WebString& sample) {
1068 GetContentClient()->renderer()->RecordRappor(metric, sample.utf8());
1071 void RendererBlinkPlatformImpl::recordRapporURL(const char* metric,
1072 const blink::WebURL& url) {
1073 GetContentClient()->renderer()->RecordRapporURL(metric, url);
1076 //------------------------------------------------------------------------------
1078 // static
1079 void RendererBlinkPlatformImpl::SetMockDeviceLightDataForTesting(double data) {
1080 g_test_device_light_data = data;
1083 //------------------------------------------------------------------------------
1085 // static
1086 void RendererBlinkPlatformImpl::SetMockDeviceMotionDataForTesting(
1087 const blink::WebDeviceMotionData& data) {
1088 g_test_device_motion_data.Get() = data;
1091 //------------------------------------------------------------------------------
1093 // static
1094 void RendererBlinkPlatformImpl::SetMockDeviceOrientationDataForTesting(
1095 const blink::WebDeviceOrientationData& data) {
1096 g_test_device_orientation_data.Get() = data;
1099 //------------------------------------------------------------------------------
1101 void RendererBlinkPlatformImpl::vibrate(unsigned int milliseconds) {
1102 GetConnectedVibrationManagerService()->Vibrate(
1103 base::checked_cast<int64>(milliseconds));
1104 vibration_manager_.reset();
1107 void RendererBlinkPlatformImpl::cancelVibration() {
1108 GetConnectedVibrationManagerService()->Cancel();
1109 vibration_manager_.reset();
1112 device::VibrationManagerPtr&
1113 RendererBlinkPlatformImpl::GetConnectedVibrationManagerService() {
1114 if (!vibration_manager_) {
1115 RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService(
1116 mojo::GetProxy(&vibration_manager_));
1118 return vibration_manager_;
1121 //------------------------------------------------------------------------------
1123 // static
1124 PlatformEventObserverBase*
1125 RendererBlinkPlatformImpl::CreatePlatformEventObserverFromType(
1126 blink::WebPlatformEventType type) {
1127 RenderThread* thread = RenderThreadImpl::current();
1129 // When running layout tests, those observers should not listen to the actual
1130 // hardware changes. In order to make that happen, they will receive a null
1131 // thread.
1132 if (thread && RenderThreadImpl::current()->layout_test_mode())
1133 thread = NULL;
1135 switch (type) {
1136 case blink::WebPlatformEventDeviceMotion:
1137 return new DeviceMotionEventPump(thread);
1138 case blink::WebPlatformEventDeviceOrientation:
1139 return new DeviceOrientationEventPump(thread);
1140 case blink::WebPlatformEventDeviceLight:
1141 return new DeviceLightEventPump(thread);
1142 case blink::WebPlatformEventGamepad:
1143 return new GamepadSharedMemoryReader(thread);
1144 case blink::WebPlatformEventScreenOrientation:
1145 return new ScreenOrientationObserver();
1146 default:
1147 // A default statement is required to prevent compilation errors when
1148 // Blink adds a new type.
1149 DVLOG(1) << "RendererBlinkPlatformImpl::startListening() with "
1150 "unknown type.";
1153 return NULL;
1156 void RendererBlinkPlatformImpl::SetPlatformEventObserverForTesting(
1157 blink::WebPlatformEventType type,
1158 scoped_ptr<PlatformEventObserverBase> observer) {
1159 DCHECK(type != blink::WebPlatformEventBattery);
1161 if (platform_event_observers_.Lookup(type))
1162 platform_event_observers_.Remove(type);
1163 platform_event_observers_.AddWithID(observer.release(), type);
1166 void RendererBlinkPlatformImpl::startListening(
1167 blink::WebPlatformEventType type,
1168 blink::WebPlatformEventListener* listener) {
1169 if (type == blink::WebPlatformEventBattery) {
1170 if (RenderThreadImpl::current() &&
1171 RenderThreadImpl::current()->layout_test_mode()) {
1172 g_test_battery_status_listener =
1173 static_cast<blink::WebBatteryStatusListener*>(listener);
1174 } else {
1175 battery_status_dispatcher_.reset(new BatteryStatusDispatcher(
1176 static_cast<blink::WebBatteryStatusListener*>(listener)));
1178 return;
1181 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type);
1182 if (!observer) {
1183 observer = CreatePlatformEventObserverFromType(type);
1184 if (!observer)
1185 return;
1186 platform_event_observers_.AddWithID(observer, static_cast<int32>(type));
1188 observer->Start(listener);
1190 // Device events (motion, orientation and light) expect to get an event fired
1191 // as soon as a listener is registered if a fake data was passed before.
1192 // TODO(mlamouri,timvolodine): make those send mock values directly instead of
1193 // using this broken pattern.
1194 if (RenderThreadImpl::current() &&
1195 RenderThreadImpl::current()->layout_test_mode() &&
1196 (type == blink::WebPlatformEventDeviceMotion ||
1197 type == blink::WebPlatformEventDeviceOrientation ||
1198 type == blink::WebPlatformEventDeviceLight)) {
1199 SendFakeDeviceEventDataForTesting(type);
1203 void RendererBlinkPlatformImpl::SendFakeDeviceEventDataForTesting(
1204 blink::WebPlatformEventType type) {
1205 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type);
1206 CHECK(observer);
1208 void* data = 0;
1210 switch (type) {
1211 case blink::WebPlatformEventDeviceMotion:
1212 if (!(g_test_device_motion_data == 0))
1213 data = &g_test_device_motion_data.Get();
1214 break;
1215 case blink::WebPlatformEventDeviceOrientation:
1216 if (!(g_test_device_orientation_data == 0))
1217 data = &g_test_device_orientation_data.Get();
1218 break;
1219 case blink::WebPlatformEventDeviceLight:
1220 if (g_test_device_light_data >= 0)
1221 data = &g_test_device_light_data;
1222 break;
1223 default:
1224 NOTREACHED();
1225 break;
1228 if (!data)
1229 return;
1231 base::ThreadTaskRunnerHandle::Get()->PostTask(
1232 FROM_HERE, base::Bind(&PlatformEventObserverBase::SendFakeDataForTesting,
1233 base::Unretained(observer), data));
1236 void RendererBlinkPlatformImpl::stopListening(
1237 blink::WebPlatformEventType type) {
1238 if (type == blink::WebPlatformEventBattery) {
1239 g_test_battery_status_listener = nullptr;
1240 battery_status_dispatcher_.reset();
1241 return;
1244 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type);
1245 if (!observer)
1246 return;
1247 observer->Stop();
1250 //------------------------------------------------------------------------------
1252 void RendererBlinkPlatformImpl::queryStorageUsageAndQuota(
1253 const blink::WebURL& storage_partition,
1254 blink::WebStorageQuotaType type,
1255 blink::WebStorageQuotaCallbacks callbacks) {
1256 if (!thread_safe_sender_.get() || !quota_message_filter_.get())
1257 return;
1258 QuotaDispatcher::ThreadSpecificInstance(thread_safe_sender_.get(),
1259 quota_message_filter_.get())
1260 ->QueryStorageUsageAndQuota(
1261 storage_partition,
1262 static_cast<storage::StorageType>(type),
1263 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
1266 //------------------------------------------------------------------------------
1268 void RendererBlinkPlatformImpl::MockBatteryStatusChangedForTesting(
1269 const blink::WebBatteryStatus& status) {
1270 if (!g_test_battery_status_listener)
1271 return;
1272 g_test_battery_status_listener->updateBatteryStatus(status);
1275 } // namespace content