| 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_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
| 13 #include "base/shared_memory.h" | 13 #include "base/shared_memory.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "content/common/database_util.h" | 15 #include "content/common/database_util.h" |
| 16 #include "content/common/file_utilities_messages.h" | 16 #include "content/common/file_utilities_messages.h" |
| 17 #include "content/common/fileapi/webblobregistry_impl.h" | 17 #include "content/common/fileapi/webblobregistry_impl.h" |
| 18 #include "content/common/fileapi/webfilesystem_impl.h" | 18 #include "content/common/fileapi/webfilesystem_impl.h" |
| 19 #include "content/common/indexed_db/proxy_webidbfactory_impl.h" | 19 #include "content/common/indexed_db/proxy_webidbfactory_impl.h" |
| 20 #include "content/common/mime_registry_messages.h" | 20 #include "content/common/mime_registry_messages.h" |
| 21 #include "content/common/npobject_util.h" | 21 #include "content/common/npobject_util.h" |
| 22 #include "content/common/thread_safe_sender.h" |
| 22 #include "content/common/view_messages.h" | 23 #include "content/common/view_messages.h" |
| 23 #include "content/common/webmessageportchannel_impl.h" | 24 #include "content/common/webmessageportchannel_impl.h" |
| 24 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
| 25 #include "content/public/common/gpu_info.h" | 26 #include "content/public/common/gpu_info.h" |
| 26 #include "content/public/renderer/content_renderer_client.h" | 27 #include "content/public/renderer/content_renderer_client.h" |
| 27 #include "content/renderer/dom_storage/webstoragenamespace_impl.h" | 28 #include "content/renderer/dom_storage/webstoragenamespace_impl.h" |
| 28 #include "content/renderer/gamepad_shared_memory_reader.h" | 29 #include "content/renderer/gamepad_shared_memory_reader.h" |
| 29 #include "content/renderer/hyphenator/hyphenator.h" | 30 #include "content/renderer/hyphenator/hyphenator.h" |
| 30 #include "content/renderer/media/media_stream_dependency_factory.h" | 31 #include "content/renderer/media/media_stream_dependency_factory.h" |
| 31 #include "content/renderer/media/renderer_webaudiodevice_impl.h" | 32 #include "content/renderer/media/renderer_webaudiodevice_impl.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 public: | 108 public: |
| 108 virtual WebKit::WebString mimeTypeForExtension(const WebKit::WebString&); | 109 virtual WebKit::WebString mimeTypeForExtension(const WebKit::WebString&); |
| 109 virtual WebKit::WebString mimeTypeFromFile(const WebKit::WebString&); | 110 virtual WebKit::WebString mimeTypeFromFile(const WebKit::WebString&); |
| 110 virtual WebKit::WebString preferredExtensionForMIMEType( | 111 virtual WebKit::WebString preferredExtensionForMIMEType( |
| 111 const WebKit::WebString&); | 112 const WebKit::WebString&); |
| 112 }; | 113 }; |
| 113 | 114 |
| 114 class RendererWebKitPlatformSupportImpl::FileUtilities | 115 class RendererWebKitPlatformSupportImpl::FileUtilities |
| 115 : public webkit_glue::WebFileUtilitiesImpl { | 116 : public webkit_glue::WebFileUtilitiesImpl { |
| 116 public: | 117 public: |
| 118 explicit FileUtilities(ThreadSafeSender* sender) |
| 119 : thread_safe_sender_(sender) {} |
| 117 virtual bool getFileInfo(const WebString& path, WebFileInfo& result); | 120 virtual bool getFileInfo(const WebString& path, WebFileInfo& result); |
| 118 virtual base::PlatformFile openFile(const WebKit::WebString& path, | 121 virtual base::PlatformFile openFile(const WebKit::WebString& path, |
| 119 int mode); | 122 int mode); |
| 123 private: |
| 124 bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) const; |
| 125 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 120 }; | 126 }; |
| 121 | 127 |
| 122 class RendererWebKitPlatformSupportImpl::Hyphenator | 128 class RendererWebKitPlatformSupportImpl::Hyphenator |
| 123 : public WebKit::WebHyphenator { | 129 : public WebKit::WebHyphenator { |
| 124 public: | 130 public: |
| 125 Hyphenator(); | 131 Hyphenator(); |
| 126 virtual ~Hyphenator(); | 132 virtual ~Hyphenator(); |
| 127 | 133 |
| 128 virtual bool canHyphenate(const WebKit::WebString& locale) OVERRIDE; | 134 virtual bool canHyphenate(const WebKit::WebString& locale) OVERRIDE; |
| 129 virtual size_t computeLastHyphenLocation( | 135 virtual size_t computeLastHyphenLocation( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 hyphenator_(new RendererWebKitPlatformSupportImpl::Hyphenator), | 190 hyphenator_(new RendererWebKitPlatformSupportImpl::Hyphenator), |
| 185 sudden_termination_disables_(0), | 191 sudden_termination_disables_(0), |
| 186 plugin_refresh_allowed_(true), | 192 plugin_refresh_allowed_(true), |
| 187 shared_worker_repository_(new WebSharedWorkerRepositoryImpl) { | 193 shared_worker_repository_(new WebSharedWorkerRepositoryImpl) { |
| 188 if (g_sandbox_enabled && sandboxEnabled()) { | 194 if (g_sandbox_enabled && sandboxEnabled()) { |
| 189 sandbox_support_.reset( | 195 sandbox_support_.reset( |
| 190 new RendererWebKitPlatformSupportImpl::SandboxSupport); | 196 new RendererWebKitPlatformSupportImpl::SandboxSupport); |
| 191 } else { | 197 } else { |
| 192 DVLOG(1) << "Disabling sandbox support for testing."; | 198 DVLOG(1) << "Disabling sandbox support for testing."; |
| 193 } | 199 } |
| 200 |
| 201 // ChildThread may not exist in some tests. |
| 202 if (ChildThread::current()) |
| 203 thread_safe_sender_ = ChildThread::current()->thread_safe_sender(); |
| 194 } | 204 } |
| 195 | 205 |
| 196 RendererWebKitPlatformSupportImpl::~RendererWebKitPlatformSupportImpl() { | 206 RendererWebKitPlatformSupportImpl::~RendererWebKitPlatformSupportImpl() { |
| 197 } | 207 } |
| 198 | 208 |
| 199 //------------------------------------------------------------------------------ | 209 //------------------------------------------------------------------------------ |
| 200 | 210 |
| 201 namespace { | |
| 202 | |
| 203 bool SendSyncMessageFromAnyThreadInternal(IPC::SyncMessage* msg) { | |
| 204 RenderThread* render_thread = RenderThread::Get(); | |
| 205 if (render_thread) | |
| 206 return render_thread->Send(msg); | |
| 207 scoped_refptr<IPC::SyncMessageFilter> sync_msg_filter( | |
| 208 ChildThread::current()->sync_message_filter()); | |
| 209 return sync_msg_filter->Send(msg); | |
| 210 } | |
| 211 | |
| 212 bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) { | |
| 213 base::TimeTicks begin = base::TimeTicks::Now(); | |
| 214 const bool success = SendSyncMessageFromAnyThreadInternal(msg); | |
| 215 base::TimeDelta delta = base::TimeTicks::Now() - begin; | |
| 216 UMA_HISTOGRAM_TIMES("RendererSyncIPC.ElapsedTime", delta); | |
| 217 return success; | |
| 218 } | |
| 219 | |
| 220 } // namespace | |
| 221 | |
| 222 WebKit::WebClipboard* RendererWebKitPlatformSupportImpl::clipboard() { | 211 WebKit::WebClipboard* RendererWebKitPlatformSupportImpl::clipboard() { |
| 223 WebKit::WebClipboard* clipboard = | 212 WebKit::WebClipboard* clipboard = |
| 224 GetContentClient()->renderer()->OverrideWebClipboard(); | 213 GetContentClient()->renderer()->OverrideWebClipboard(); |
| 225 if (clipboard) | 214 if (clipboard) |
| 226 return clipboard; | 215 return clipboard; |
| 227 return clipboard_.get(); | 216 return clipboard_.get(); |
| 228 } | 217 } |
| 229 | 218 |
| 230 WebKit::WebMimeRegistry* RendererWebKitPlatformSupportImpl::mimeRegistry() { | 219 WebKit::WebMimeRegistry* RendererWebKitPlatformSupportImpl::mimeRegistry() { |
| 231 WebKit::WebMimeRegistry* mime_registry = | 220 WebKit::WebMimeRegistry* mime_registry = |
| 232 GetContentClient()->renderer()->OverrideWebMimeRegistry(); | 221 GetContentClient()->renderer()->OverrideWebMimeRegistry(); |
| 233 if (mime_registry) | 222 if (mime_registry) |
| 234 return mime_registry; | 223 return mime_registry; |
| 235 return mime_registry_.get(); | 224 return mime_registry_.get(); |
| 236 } | 225 } |
| 237 | 226 |
| 238 WebKit::WebFileUtilities* | 227 WebKit::WebFileUtilities* |
| 239 RendererWebKitPlatformSupportImpl::fileUtilities() { | 228 RendererWebKitPlatformSupportImpl::fileUtilities() { |
| 240 if (!file_utilities_.get()) { | 229 if (!file_utilities_.get()) { |
| 241 file_utilities_.reset(new FileUtilities); | 230 file_utilities_.reset(new FileUtilities(thread_safe_sender_)); |
| 242 file_utilities_->set_sandbox_enabled(sandboxEnabled()); | 231 file_utilities_->set_sandbox_enabled(sandboxEnabled()); |
| 243 } | 232 } |
| 244 return file_utilities_.get(); | 233 return file_utilities_.get(); |
| 245 } | 234 } |
| 246 | 235 |
| 247 WebKit::WebSandboxSupport* RendererWebKitPlatformSupportImpl::sandboxSupport() { | 236 WebKit::WebSandboxSupport* RendererWebKitPlatformSupportImpl::sandboxSupport() { |
| 248 #if defined(OS_ANDROID) | 237 #if defined(OS_ANDROID) |
| 249 // WebKit doesn't use WebSandboxSupport on android. | 238 // WebKit doesn't use WebSandboxSupport on android. |
| 250 return NULL; | 239 return NULL; |
| 251 #else | 240 #else |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 | 429 |
| 441 base::PlatformFile RendererWebKitPlatformSupportImpl::FileUtilities::openFile( | 430 base::PlatformFile RendererWebKitPlatformSupportImpl::FileUtilities::openFile( |
| 442 const WebString& path, | 431 const WebString& path, |
| 443 int mode) { | 432 int mode) { |
| 444 IPC::PlatformFileForTransit handle = IPC::InvalidPlatformFileForTransit(); | 433 IPC::PlatformFileForTransit handle = IPC::InvalidPlatformFileForTransit(); |
| 445 SendSyncMessageFromAnyThread(new FileUtilitiesMsg_OpenFile( | 434 SendSyncMessageFromAnyThread(new FileUtilitiesMsg_OpenFile( |
| 446 webkit_base::WebStringToFilePath(path), mode, &handle)); | 435 webkit_base::WebStringToFilePath(path), mode, &handle)); |
| 447 return IPC::PlatformFileForTransitToPlatformFile(handle); | 436 return IPC::PlatformFileForTransitToPlatformFile(handle); |
| 448 } | 437 } |
| 449 | 438 |
| 439 bool RendererWebKitPlatformSupportImpl::FileUtilities:: |
| 440 SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) const { |
| 441 base::TimeTicks begin = base::TimeTicks::Now(); |
| 442 const bool success = thread_safe_sender_->Send(msg); |
| 443 base::TimeDelta delta = base::TimeTicks::Now() - begin; |
| 444 UMA_HISTOGRAM_TIMES("RendererSyncIPC.ElapsedTime", delta); |
| 445 return success; |
| 446 } |
| 447 |
| 450 //------------------------------------------------------------------------------ | 448 //------------------------------------------------------------------------------ |
| 451 | 449 |
| 452 RendererWebKitPlatformSupportImpl::Hyphenator::Hyphenator() {} | 450 RendererWebKitPlatformSupportImpl::Hyphenator::Hyphenator() {} |
| 453 | 451 |
| 454 RendererWebKitPlatformSupportImpl::Hyphenator::~Hyphenator() {} | 452 RendererWebKitPlatformSupportImpl::Hyphenator::~Hyphenator() {} |
| 455 | 453 |
| 456 bool RendererWebKitPlatformSupportImpl::Hyphenator::canHyphenate( | 454 bool RendererWebKitPlatformSupportImpl::Hyphenator::canHyphenate( |
| 457 const WebKit::WebString& locale) { | 455 const WebKit::WebString& locale) { |
| 458 // Return false unless WebKit asks for US English dictionaries because WebKit | 456 // Return false unless WebKit asks for US English dictionaries because WebKit |
| 459 // can currently hyphenate only English words. | 457 // can currently hyphenate only English words. |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 WebVector<char>* to_profile) { | 736 WebVector<char>* to_profile) { |
| 739 std::vector<char> profile; | 737 std::vector<char> profile; |
| 740 RenderThread::Get()->Send( | 738 RenderThread::Get()->Send( |
| 741 new ViewHostMsg_GetMonitorColorProfile(&profile)); | 739 new ViewHostMsg_GetMonitorColorProfile(&profile)); |
| 742 *to_profile = profile; | 740 *to_profile = profile; |
| 743 } | 741 } |
| 744 | 742 |
| 745 //------------------------------------------------------------------------------ | 743 //------------------------------------------------------------------------------ |
| 746 | 744 |
| 747 WebBlobRegistry* RendererWebKitPlatformSupportImpl::blobRegistry() { | 745 WebBlobRegistry* RendererWebKitPlatformSupportImpl::blobRegistry() { |
| 748 // ChildThread::current can be NULL when running some tests. | 746 // thread_safe_sender_ can be NULL when running some tests. |
| 749 if (!blob_registry_.get() && ChildThread::current()) { | 747 if (!blob_registry_.get() && thread_safe_sender_.get()) |
| 750 blob_registry_.reset(new WebBlobRegistryImpl(ChildThread::current())); | 748 blob_registry_.reset(new WebBlobRegistryImpl(thread_safe_sender_)); |
| 751 } | |
| 752 return blob_registry_.get(); | 749 return blob_registry_.get(); |
| 753 } | 750 } |
| 754 | 751 |
| 755 //------------------------------------------------------------------------------ | 752 //------------------------------------------------------------------------------ |
| 756 | 753 |
| 757 void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) { | 754 void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) { |
| 758 if (g_test_gamepads == 0) { | 755 if (g_test_gamepads == 0) { |
| 759 if (!gamepad_shared_memory_reader_.get()) | 756 if (!gamepad_shared_memory_reader_.get()) |
| 760 gamepad_shared_memory_reader_.reset(new GamepadSharedMemoryReader); | 757 gamepad_shared_memory_reader_.reset(new GamepadSharedMemoryReader); |
| 761 gamepad_shared_memory_reader_->SampleGamepads(gamepads); | 758 gamepad_shared_memory_reader_->SampleGamepads(gamepads); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 //------------------------------------------------------------------------------ | 846 //------------------------------------------------------------------------------ |
| 850 | 847 |
| 851 bool RendererWebKitPlatformSupportImpl::processMemorySizesInBytes( | 848 bool RendererWebKitPlatformSupportImpl::processMemorySizesInBytes( |
| 852 size_t* private_bytes, size_t* shared_bytes) { | 849 size_t* private_bytes, size_t* shared_bytes) { |
| 853 content::RenderThread::Get()->Send( | 850 content::RenderThread::Get()->Send( |
| 854 new ViewHostMsg_GetProcessMemorySizes(private_bytes, shared_bytes)); | 851 new ViewHostMsg_GetProcessMemorySizes(private_bytes, shared_bytes)); |
| 855 return true; | 852 return true; |
| 856 } | 853 } |
| 857 | 854 |
| 858 } // namespace content | 855 } // namespace content |
| OLD | NEW |