OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/renderer_webkitplatformsupport_impl.h" | 5 #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
24 #include "content/public/common/gpu_info.h" | 24 #include "content/public/common/gpu_info.h" |
25 #include "content/public/renderer/content_renderer_client.h" | 25 #include "content/public/renderer/content_renderer_client.h" |
26 #include "content/renderer/dom_storage/webstoragenamespace_impl.h" | 26 #include "content/renderer/dom_storage/webstoragenamespace_impl.h" |
27 #include "content/renderer/gamepad_shared_memory_reader.h" | 27 #include "content/renderer/gamepad_shared_memory_reader.h" |
28 #include "content/renderer/hyphenator/hyphenator.h" | 28 #include "content/renderer/hyphenator/hyphenator.h" |
29 #include "content/renderer/media/audio_hardware.h" | 29 #include "content/renderer/media/audio_hardware.h" |
30 #include "content/renderer/media/media_stream_dependency_factory.h" | 30 #include "content/renderer/media/media_stream_dependency_factory.h" |
31 #include "content/renderer/media/renderer_webaudiodevice_impl.h" | 31 #include "content/renderer/media/renderer_webaudiodevice_impl.h" |
32 #include "content/renderer/render_thread_impl.h" | 32 #include "content/renderer/render_thread_impl.h" |
33 #include "content/renderer/render_view_impl.h" | |
34 #include "content/renderer/renderer_clipboard_client.h" | 33 #include "content/renderer/renderer_clipboard_client.h" |
35 #include "content/renderer/websharedworkerrepository_impl.h" | 34 #include "content/renderer/websharedworkerrepository_impl.h" |
36 #include "googleurl/src/gurl.h" | 35 #include "googleurl/src/gurl.h" |
37 #include "ipc/ipc_sync_message_filter.h" | 36 #include "ipc/ipc_sync_message_filter.h" |
38 #include "media/audio/audio_output_device.h" | 37 #include "media/audio/audio_output_device.h" |
39 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebBlobRegis
try.h" | 38 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebBlobRegis
try.h" |
40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h" | 39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h" |
41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
42 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.
h" | 41 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.
h" |
43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h" | 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h" |
(...skipping 25 matching lines...) Expand all Loading... |
69 #include "base/synchronization/lock.h" | 68 #include "base/synchronization/lock.h" |
70 #include "content/common/child_process_sandbox_support_impl_linux.h" | 69 #include "content/common/child_process_sandbox_support_impl_linux.h" |
71 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/linux/WebFon
tFamily.h" | 70 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/linux/WebFon
tFamily.h" |
72 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/linux/WebSan
dboxSupport.h" | 71 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/linux/WebSan
dboxSupport.h" |
73 #endif | 72 #endif |
74 | 73 |
75 #if defined(OS_POSIX) | 74 #if defined(OS_POSIX) |
76 #include "base/file_descriptor_posix.h" | 75 #include "base/file_descriptor_posix.h" |
77 #endif | 76 #endif |
78 | 77 |
79 using content::RenderThread; | |
80 using WebKit::WebAudioDevice; | 78 using WebKit::WebAudioDevice; |
81 using WebKit::WebBlobRegistry; | 79 using WebKit::WebBlobRegistry; |
82 using WebKit::WebFileInfo; | 80 using WebKit::WebFileInfo; |
83 using WebKit::WebFileSystem; | 81 using WebKit::WebFileSystem; |
84 using WebKit::WebFrame; | 82 using WebKit::WebFrame; |
85 using WebKit::WebGamepads; | 83 using WebKit::WebGamepads; |
86 using WebKit::WebIDBFactory; | 84 using WebKit::WebIDBFactory; |
87 using WebKit::WebKitPlatformSupport; | 85 using WebKit::WebKitPlatformSupport; |
88 using WebKit::WebMediaStreamCenter; | 86 using WebKit::WebMediaStreamCenter; |
89 using WebKit::WebMediaStreamCenterClient; | 87 using WebKit::WebMediaStreamCenterClient; |
90 using WebKit::WebPeerConnection00Handler; | 88 using WebKit::WebPeerConnection00Handler; |
91 using WebKit::WebPeerConnection00HandlerClient; | 89 using WebKit::WebPeerConnection00HandlerClient; |
92 using WebKit::WebRTCPeerConnectionHandler; | 90 using WebKit::WebRTCPeerConnectionHandler; |
93 using WebKit::WebRTCPeerConnectionHandlerClient; | 91 using WebKit::WebRTCPeerConnectionHandlerClient; |
94 using WebKit::WebStorageNamespace; | 92 using WebKit::WebStorageNamespace; |
95 using WebKit::WebString; | 93 using WebKit::WebString; |
96 using WebKit::WebURL; | 94 using WebKit::WebURL; |
97 using WebKit::WebVector; | 95 using WebKit::WebVector; |
98 | 96 |
| 97 namespace content { |
| 98 |
99 static bool g_sandbox_enabled = true; | 99 static bool g_sandbox_enabled = true; |
100 | 100 |
101 //------------------------------------------------------------------------------ | 101 //------------------------------------------------------------------------------ |
102 | 102 |
103 class RendererWebKitPlatformSupportImpl::MimeRegistry | 103 class RendererWebKitPlatformSupportImpl::MimeRegistry |
104 : public webkit_glue::SimpleWebMimeRegistryImpl { | 104 : public webkit_glue::SimpleWebMimeRegistryImpl { |
105 public: | 105 public: |
106 virtual WebKit::WebString mimeTypeForExtension(const WebKit::WebString&); | 106 virtual WebKit::WebString mimeTypeForExtension(const WebKit::WebString&); |
107 virtual WebKit::WebString mimeTypeFromFile(const WebKit::WebString&); | 107 virtual WebKit::WebString mimeTypeFromFile(const WebKit::WebString&); |
108 virtual WebKit::WebString preferredExtensionForMIMEType( | 108 virtual WebKit::WebString preferredExtensionForMIMEType( |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 // act any differently...unless we're in single process mode. In which | 236 // act any differently...unless we're in single process mode. In which |
237 // case, we have no other choice. WebKitPlatformSupport.h discourages using | 237 // case, we have no other choice. WebKitPlatformSupport.h discourages using |
238 // this switch unless absolutely necessary, so hopefully we won't end up | 238 // this switch unless absolutely necessary, so hopefully we won't end up |
239 // with too many code paths being different in single-process mode. | 239 // with too many code paths being different in single-process mode. |
240 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); | 240 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); |
241 } | 241 } |
242 | 242 |
243 unsigned long long RendererWebKitPlatformSupportImpl::visitedLinkHash( | 243 unsigned long long RendererWebKitPlatformSupportImpl::visitedLinkHash( |
244 const char* canonical_url, | 244 const char* canonical_url, |
245 size_t length) { | 245 size_t length) { |
246 return content::GetContentClient()->renderer()->VisitedLinkHash( | 246 return GetContentClient()->renderer()->VisitedLinkHash(canonical_url, length); |
247 canonical_url, length); | |
248 } | 247 } |
249 | 248 |
250 bool RendererWebKitPlatformSupportImpl::isLinkVisited( | 249 bool RendererWebKitPlatformSupportImpl::isLinkVisited( |
251 unsigned long long link_hash) { | 250 unsigned long long link_hash) { |
252 return content::GetContentClient()->renderer()->IsLinkVisited(link_hash); | 251 return GetContentClient()->renderer()->IsLinkVisited(link_hash); |
253 } | 252 } |
254 | 253 |
255 WebKit::WebMessagePortChannel* | 254 WebKit::WebMessagePortChannel* |
256 RendererWebKitPlatformSupportImpl::createMessagePortChannel() { | 255 RendererWebKitPlatformSupportImpl::createMessagePortChannel() { |
257 return new WebMessagePortChannelImpl(); | 256 return new WebMessagePortChannelImpl(); |
258 } | 257 } |
259 | 258 |
260 void RendererWebKitPlatformSupportImpl::prefetchHostName( | 259 void RendererWebKitPlatformSupportImpl::prefetchHostName( |
261 const WebString& hostname) { | 260 const WebString& hostname) { |
262 if (hostname.isEmpty()) | 261 if (hostname.isEmpty()) |
263 return; | 262 return; |
264 | 263 |
265 std::string hostname_utf8; | 264 std::string hostname_utf8; |
266 UTF16ToUTF8(hostname.data(), hostname.length(), &hostname_utf8); | 265 UTF16ToUTF8(hostname.data(), hostname.length(), &hostname_utf8); |
267 content::GetContentClient()->renderer()->PrefetchHostName( | 266 GetContentClient()->renderer()->PrefetchHostName( |
268 hostname_utf8.data(), hostname_utf8.length()); | 267 hostname_utf8.data(), hostname_utf8.length()); |
269 } | 268 } |
270 | 269 |
271 bool | 270 bool |
272 RendererWebKitPlatformSupportImpl::CheckPreparsedJsCachingEnabled() const { | 271 RendererWebKitPlatformSupportImpl::CheckPreparsedJsCachingEnabled() const { |
273 static bool checked = false; | 272 static bool checked = false; |
274 static bool result = false; | 273 static bool result = false; |
275 if (!checked) { | 274 if (!checked) { |
276 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 275 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
277 result = command_line.HasSwitch(switches::kEnablePreparsedJsCaching); | 276 result = command_line.HasSwitch(switches::kEnablePreparsedJsCaching); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 const string16 key(characters, num_characters); | 480 const string16 key(characters, num_characters); |
482 const std::map<string16, WebKit::WebFontFamily>::const_iterator iter = | 481 const std::map<string16, WebKit::WebFontFamily>::const_iterator iter = |
483 unicode_font_families_.find(key); | 482 unicode_font_families_.find(key); |
484 if (iter != unicode_font_families_.end()) { | 483 if (iter != unicode_font_families_.end()) { |
485 family->name = iter->second.name; | 484 family->name = iter->second.name; |
486 family->isBold = iter->second.isBold; | 485 family->isBold = iter->second.isBold; |
487 family->isItalic = iter->second.isItalic; | 486 family->isItalic = iter->second.isItalic; |
488 return; | 487 return; |
489 } | 488 } |
490 | 489 |
491 content::GetFontFamilyForCharacters( | 490 GetFontFamilyForCharacters( |
492 characters, | 491 characters, |
493 num_characters, | 492 num_characters, |
494 preferred_locale, | 493 preferred_locale, |
495 family); | 494 family); |
496 unicode_font_families_.insert(make_pair(key, *family)); | 495 unicode_font_families_.insert(make_pair(key, *family)); |
497 } | 496 } |
498 | 497 |
499 void | 498 void |
500 RendererWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike( | 499 RendererWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike( |
501 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out) { | 500 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out) { |
502 content::GetRenderStyleForStrike(family, sizeAndStyle, out); | 501 GetRenderStyleForStrike(family, sizeAndStyle, out); |
503 } | 502 } |
504 | 503 |
505 #endif | 504 #endif |
506 | 505 |
507 //------------------------------------------------------------------------------ | 506 //------------------------------------------------------------------------------ |
508 | 507 |
509 WebKitPlatformSupport::FileHandle | 508 WebKitPlatformSupport::FileHandle |
510 RendererWebKitPlatformSupportImpl::databaseOpenFile( | 509 RendererWebKitPlatformSupportImpl::databaseOpenFile( |
511 const WebString& vfs_file_name, int desired_flags) { | 510 const WebString& vfs_file_name, int desired_flags) { |
512 return DatabaseUtil::DatabaseOpenFile(vfs_file_name, desired_flags); | 511 return DatabaseUtil::DatabaseOpenFile(vfs_file_name, desired_flags); |
(...skipping 25 matching lines...) Expand all Loading... |
538 switches::kDisableSharedWorkers)) { | 537 switches::kDisableSharedWorkers)) { |
539 return shared_worker_repository_.get(); | 538 return shared_worker_repository_.get(); |
540 } else { | 539 } else { |
541 return NULL; | 540 return NULL; |
542 } | 541 } |
543 } | 542 } |
544 | 543 |
545 bool RendererWebKitPlatformSupportImpl::canAccelerate2dCanvas() { | 544 bool RendererWebKitPlatformSupportImpl::canAccelerate2dCanvas() { |
546 RenderThreadImpl* thread = RenderThreadImpl::current(); | 545 RenderThreadImpl* thread = RenderThreadImpl::current(); |
547 GpuChannelHost* host = thread->EstablishGpuChannelSync( | 546 GpuChannelHost* host = thread->EstablishGpuChannelSync( |
548 content::CAUSE_FOR_GPU_LAUNCH_CANVAS_2D); | 547 CAUSE_FOR_GPU_LAUNCH_CANVAS_2D); |
549 if (!host) | 548 if (!host) |
550 return false; | 549 return false; |
551 | 550 |
552 const content::GPUInfo& gpu_info = host->gpu_info(); | 551 const GPUInfo& gpu_info = host->gpu_info(); |
553 if (gpu_info.can_lose_context || gpu_info.software_rendering) | 552 if (gpu_info.can_lose_context || gpu_info.software_rendering) |
554 return false; | 553 return false; |
555 | 554 |
556 return true; | 555 return true; |
557 } | 556 } |
558 | 557 |
559 double RendererWebKitPlatformSupportImpl::audioHardwareSampleRate() { | 558 double RendererWebKitPlatformSupportImpl::audioHardwareSampleRate() { |
560 return audio_hardware::GetOutputSampleRate(); | 559 return audio_hardware::GetOutputSampleRate(); |
561 } | 560 } |
562 | 561 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 if (!blob_registry_.get() && ChildThread::current()) { | 645 if (!blob_registry_.get() && ChildThread::current()) { |
647 blob_registry_.reset(new WebBlobRegistryImpl(ChildThread::current())); | 646 blob_registry_.reset(new WebBlobRegistryImpl(ChildThread::current())); |
648 } | 647 } |
649 return blob_registry_.get(); | 648 return blob_registry_.get(); |
650 } | 649 } |
651 | 650 |
652 //------------------------------------------------------------------------------ | 651 //------------------------------------------------------------------------------ |
653 | 652 |
654 void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) { | 653 void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) { |
655 if (!gamepad_shared_memory_reader_.get()) | 654 if (!gamepad_shared_memory_reader_.get()) |
656 gamepad_shared_memory_reader_.reset(new content::GamepadSharedMemoryReader); | 655 gamepad_shared_memory_reader_.reset(new GamepadSharedMemoryReader); |
657 gamepad_shared_memory_reader_->SampleGamepads(gamepads); | 656 gamepad_shared_memory_reader_->SampleGamepads(gamepads); |
658 } | 657 } |
659 | 658 |
660 WebKit::WebString RendererWebKitPlatformSupportImpl::userAgent( | 659 WebKit::WebString RendererWebKitPlatformSupportImpl::userAgent( |
661 const WebKit::WebURL& url) { | 660 const WebKit::WebURL& url) { |
662 return WebKitPlatformSupportImpl::userAgent(url); | 661 return WebKitPlatformSupportImpl::userAgent(url); |
663 } | 662 } |
664 | 663 |
665 void RendererWebKitPlatformSupportImpl::GetPlugins( | 664 void RendererWebKitPlatformSupportImpl::GetPlugins( |
666 bool refresh, std::vector<webkit::WebPluginInfo>* plugins) { | 665 bool refresh, std::vector<webkit::WebPluginInfo>* plugins) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 bool RendererWebKitPlatformSupportImpl::canHyphenate( | 733 bool RendererWebKitPlatformSupportImpl::canHyphenate( |
735 const WebKit::WebString& locale) { | 734 const WebKit::WebString& locale) { |
736 // Return false unless WebKit asks for US English dictionaries because WebKit | 735 // Return false unless WebKit asks for US English dictionaries because WebKit |
737 // can currently hyphenate only English words. | 736 // can currently hyphenate only English words. |
738 if (!locale.isEmpty() && !locale.equals("en-US")) | 737 if (!locale.isEmpty() && !locale.equals("en-US")) |
739 return false; | 738 return false; |
740 | 739 |
741 // Create a hyphenator object and attach it to the render thread so it can | 740 // Create a hyphenator object and attach it to the render thread so it can |
742 // receive a dictionary file opened by a browser. | 741 // receive a dictionary file opened by a browser. |
743 if (!hyphenator_.get()) { | 742 if (!hyphenator_.get()) { |
744 hyphenator_.reset(new content::Hyphenator(base::kInvalidPlatformFileValue)); | 743 hyphenator_.reset(new Hyphenator(base::kInvalidPlatformFileValue)); |
745 if (!hyphenator_.get()) | 744 if (!hyphenator_.get()) |
746 return false; | 745 return false; |
747 return hyphenator_->Attach(RenderThreadImpl::current(), locale); | 746 return hyphenator_->Attach(RenderThreadImpl::current(), locale); |
748 } | 747 } |
749 return hyphenator_->CanHyphenate(locale); | 748 return hyphenator_->CanHyphenate(locale); |
750 } | 749 } |
751 | 750 |
752 size_t RendererWebKitPlatformSupportImpl::computeLastHyphenLocation( | 751 size_t RendererWebKitPlatformSupportImpl::computeLastHyphenLocation( |
753 const char16* characters, | 752 const char16* characters, |
754 size_t length, | 753 size_t length, |
755 size_t before_index, | 754 size_t before_index, |
756 const WebKit::WebString& locale) { | 755 const WebKit::WebString& locale) { |
757 // Crash if WebKit calls this function when canHyphenate returns false. | 756 // Crash if WebKit calls this function when canHyphenate returns false. |
758 DCHECK(locale.isEmpty() || locale.equals("en-US")); | 757 DCHECK(locale.isEmpty() || locale.equals("en-US")); |
759 DCHECK(hyphenator_.get()); | 758 DCHECK(hyphenator_.get()); |
760 return hyphenator_->ComputeLastHyphenLocation(string16(characters, length), | 759 return hyphenator_->ComputeLastHyphenLocation(string16(characters, length), |
761 before_index); | 760 before_index); |
762 } | 761 } |
| 762 |
| 763 } // namespace content |
OLD | NEW |