Chromium Code Reviews| 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/worker/worker_webkitplatformsupport_impl.h" | 5 #include "content/worker/worker_webkitplatformsupport_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "content/common/child_process.h" | |
| 10 #include "content/common/database_util.h" | 11 #include "content/common/database_util.h" |
| 11 #include "content/common/fileapi/webblobregistry_impl.h" | 12 #include "content/common/fileapi/webblobregistry_impl.h" |
| 12 #include "content/common/fileapi/webfilesystem_impl.h" | 13 #include "content/common/fileapi/webfilesystem_impl.h" |
| 13 #include "content/common/file_utilities_messages.h" | 14 #include "content/common/file_utilities_messages.h" |
| 14 #include "content/common/indexed_db/proxy_webidbfactory_impl.h" | 15 #include "content/common/indexed_db/proxy_webidbfactory_impl.h" |
| 15 #include "content/common/mime_registry_messages.h" | 16 #include "content/common/mime_registry_messages.h" |
| 17 #include "content/common/thread_safe_sender.h" | |
| 16 #include "content/common/webmessageportchannel_impl.h" | 18 #include "content/common/webmessageportchannel_impl.h" |
| 17 #include "content/worker/worker_thread.h" | 19 #include "content/worker/worker_thread.h" |
| 18 #include "ipc/ipc_sync_message_filter.h" | 20 #include "ipc/ipc_sync_message_filter.h" |
| 19 #include "net/base/mime_util.h" | 21 #include "net/base/mime_util.h" |
| 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebBlobRegistry.h" | 22 #include "third_party/WebKit/Source/Platform/chromium/public/WebBlobRegistry.h" |
| 21 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileInfo.h" | 23 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileInfo.h" |
| 22 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
| 23 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" | 25 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
| 24 #include "webkit/base/file_path_string_conversions.h" | 26 #include "webkit/base/file_path_string_conversions.h" |
| 25 #include "webkit/glue/webfileutilities_impl.h" | 27 #include "webkit/glue/webfileutilities_impl.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 38 using WebKit::WebString; | 40 using WebKit::WebString; |
| 39 using WebKit::WebURL; | 41 using WebKit::WebURL; |
| 40 | 42 |
| 41 namespace content { | 43 namespace content { |
| 42 | 44 |
| 43 // TODO(kinuko): Probably this could be consolidated into | 45 // TODO(kinuko): Probably this could be consolidated into |
| 44 // RendererWebKitPlatformSupportImpl::FileUtilities. | 46 // RendererWebKitPlatformSupportImpl::FileUtilities. |
| 45 class WorkerWebKitPlatformSupportImpl::FileUtilities | 47 class WorkerWebKitPlatformSupportImpl::FileUtilities |
| 46 : public webkit_glue::WebFileUtilitiesImpl { | 48 : public webkit_glue::WebFileUtilitiesImpl { |
| 47 public: | 49 public: |
| 50 explicit FileUtilities(ThreadSafeSender* sender) | |
| 51 : thread_safe_sender_(sender) {} | |
| 48 virtual bool getFileInfo(const WebString& path, WebFileInfo& result); | 52 virtual bool getFileInfo(const WebString& path, WebFileInfo& result); |
| 53 private: | |
| 54 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | |
| 49 }; | 55 }; |
| 50 | 56 |
| 51 static bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) { | |
| 52 WorkerThread* worker_thread = WorkerThread::current(); | |
| 53 if (worker_thread) | |
| 54 return worker_thread->Send(msg); | |
| 55 | |
| 56 scoped_refptr<IPC::SyncMessageFilter> sync_msg_filter( | |
| 57 ChildThread::current()->sync_message_filter()); | |
| 58 return sync_msg_filter->Send(msg); | |
| 59 } | |
| 60 | |
| 61 bool WorkerWebKitPlatformSupportImpl::FileUtilities::getFileInfo( | 57 bool WorkerWebKitPlatformSupportImpl::FileUtilities::getFileInfo( |
| 62 const WebString& path, | 58 const WebString& path, |
| 63 WebFileInfo& web_file_info) { | 59 WebFileInfo& web_file_info) { |
| 64 base::PlatformFileInfo file_info; | 60 base::PlatformFileInfo file_info; |
| 65 base::PlatformFileError status; | 61 base::PlatformFileError status; |
| 66 if (!SendSyncMessageFromAnyThread(new FileUtilitiesMsg_GetFileInfo( | 62 if (!thread_safe_sender_->Send(new FileUtilitiesMsg_GetFileInfo( |
| 67 webkit_base::WebStringToFilePath(path), &file_info, &status)) || | 63 webkit_base::WebStringToFilePath(path), &file_info, &status)) || |
| 68 status != base::PLATFORM_FILE_OK) { | 64 status != base::PLATFORM_FILE_OK) { |
| 69 return false; | 65 return false; |
| 70 } | 66 } |
| 71 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); | 67 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); |
| 72 web_file_info.platformPath = path; | 68 web_file_info.platformPath = path; |
| 73 return true; | 69 return true; |
| 74 } | 70 } |
| 75 | 71 |
| 76 //------------------------------------------------------------------------------ | 72 //------------------------------------------------------------------------------ |
| 77 | 73 |
| 78 WorkerWebKitPlatformSupportImpl::WorkerWebKitPlatformSupportImpl() { | 74 WorkerWebKitPlatformSupportImpl::WorkerWebKitPlatformSupportImpl() { |
| 75 // ChildProcess and ChildThread may not exist in some tests. | |
| 76 if (ChildProcess::current()) | |
|
jam
2013/02/27 21:40:15
it's confusing to see that ChildProcess needs to b
| |
| 77 thread_safe_sender_ = ChildThread::current()->thread_safe_sender(); | |
| 79 } | 78 } |
| 80 | 79 |
| 81 WorkerWebKitPlatformSupportImpl::~WorkerWebKitPlatformSupportImpl() { | 80 WorkerWebKitPlatformSupportImpl::~WorkerWebKitPlatformSupportImpl() { |
| 82 } | 81 } |
| 83 | 82 |
| 84 WebClipboard* WorkerWebKitPlatformSupportImpl::clipboard() { | 83 WebClipboard* WorkerWebKitPlatformSupportImpl::clipboard() { |
| 85 NOTREACHED(); | 84 NOTREACHED(); |
| 86 return NULL; | 85 return NULL; |
| 87 } | 86 } |
| 88 | 87 |
| 89 WebMimeRegistry* WorkerWebKitPlatformSupportImpl::mimeRegistry() { | 88 WebMimeRegistry* WorkerWebKitPlatformSupportImpl::mimeRegistry() { |
| 90 return this; | 89 return this; |
| 91 } | 90 } |
| 92 | 91 |
| 93 WebFileSystem* WorkerWebKitPlatformSupportImpl::fileSystem() { | 92 WebFileSystem* WorkerWebKitPlatformSupportImpl::fileSystem() { |
| 94 if (!web_file_system_.get()) | 93 if (!web_file_system_.get()) |
| 95 web_file_system_.reset(new WebFileSystemImpl()); | 94 web_file_system_.reset(new WebFileSystemImpl()); |
| 96 return web_file_system_.get(); | 95 return web_file_system_.get(); |
| 97 } | 96 } |
| 98 | 97 |
| 99 WebFileUtilities* WorkerWebKitPlatformSupportImpl::fileUtilities() { | 98 WebFileUtilities* WorkerWebKitPlatformSupportImpl::fileUtilities() { |
| 100 if (!file_utilities_.get()) { | 99 if (!file_utilities_.get()) { |
| 101 file_utilities_.reset(new FileUtilities); | 100 file_utilities_.reset(new FileUtilities(thread_safe_sender_)); |
| 102 file_utilities_->set_sandbox_enabled(sandboxEnabled()); | 101 file_utilities_->set_sandbox_enabled(sandboxEnabled()); |
| 103 } | 102 } |
| 104 return file_utilities_.get(); | 103 return file_utilities_.get(); |
| 105 } | 104 } |
| 106 | 105 |
| 107 WebSandboxSupport* WorkerWebKitPlatformSupportImpl::sandboxSupport() { | 106 WebSandboxSupport* WorkerWebKitPlatformSupportImpl::sandboxSupport() { |
| 108 NOTREACHED(); | 107 NOTREACHED(); |
| 109 return NULL; | 108 return NULL; |
| 110 } | 109 } |
| 111 | 110 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 WebMimeRegistry::SupportsType | 237 WebMimeRegistry::SupportsType |
| 239 WorkerWebKitPlatformSupportImpl::supportsNonImageMIMEType( | 238 WorkerWebKitPlatformSupportImpl::supportsNonImageMIMEType( |
| 240 const WebString&) { | 239 const WebString&) { |
| 241 NOTREACHED(); | 240 NOTREACHED(); |
| 242 return WebMimeRegistry::IsSupported; | 241 return WebMimeRegistry::IsSupported; |
| 243 } | 242 } |
| 244 | 243 |
| 245 WebString WorkerWebKitPlatformSupportImpl::mimeTypeForExtension( | 244 WebString WorkerWebKitPlatformSupportImpl::mimeTypeForExtension( |
| 246 const WebString& file_extension) { | 245 const WebString& file_extension) { |
| 247 std::string mime_type; | 246 std::string mime_type; |
| 248 SendSyncMessageFromAnyThread(new MimeRegistryMsg_GetMimeTypeFromExtension( | 247 thread_safe_sender_->Send(new MimeRegistryMsg_GetMimeTypeFromExtension( |
| 249 webkit_base::WebStringToFilePathString(file_extension), &mime_type)); | 248 webkit_base::WebStringToFilePathString(file_extension), &mime_type)); |
| 250 return ASCIIToUTF16(mime_type); | 249 return ASCIIToUTF16(mime_type); |
| 251 } | 250 } |
| 252 | 251 |
| 253 WebString WorkerWebKitPlatformSupportImpl::wellKnownMimeTypeForExtension( | 252 WebString WorkerWebKitPlatformSupportImpl::wellKnownMimeTypeForExtension( |
| 254 const WebString& file_extension) { | 253 const WebString& file_extension) { |
| 255 std::string mime_type; | 254 std::string mime_type; |
| 256 net::GetWellKnownMimeTypeFromExtension( | 255 net::GetWellKnownMimeTypeFromExtension( |
| 257 webkit_base::WebStringToFilePathString(file_extension), &mime_type); | 256 webkit_base::WebStringToFilePathString(file_extension), &mime_type); |
| 258 return ASCIIToUTF16(mime_type); | 257 return ASCIIToUTF16(mime_type); |
| 259 } | 258 } |
| 260 | 259 |
| 261 WebString WorkerWebKitPlatformSupportImpl::mimeTypeFromFile( | 260 WebString WorkerWebKitPlatformSupportImpl::mimeTypeFromFile( |
| 262 const WebString& file_path) { | 261 const WebString& file_path) { |
| 263 std::string mime_type; | 262 std::string mime_type; |
| 264 SendSyncMessageFromAnyThread(new MimeRegistryMsg_GetMimeTypeFromFile( | 263 thread_safe_sender_->Send( |
| 265 base::FilePath(webkit_base::WebStringToFilePathString(file_path)), | 264 new MimeRegistryMsg_GetMimeTypeFromFile( |
| 266 &mime_type)); | 265 base::FilePath(webkit_base::WebStringToFilePathString(file_path)), |
| 266 &mime_type)); | |
| 267 return ASCIIToUTF16(mime_type); | 267 return ASCIIToUTF16(mime_type); |
| 268 } | 268 } |
| 269 | 269 |
| 270 WebString WorkerWebKitPlatformSupportImpl::preferredExtensionForMIMEType( | 270 WebString WorkerWebKitPlatformSupportImpl::preferredExtensionForMIMEType( |
| 271 const WebString& mime_type) { | 271 const WebString& mime_type) { |
| 272 base::FilePath::StringType file_extension; | 272 base::FilePath::StringType file_extension; |
| 273 SendSyncMessageFromAnyThread( | 273 thread_safe_sender_->Send( |
| 274 new MimeRegistryMsg_GetPreferredExtensionForMimeType( | 274 new MimeRegistryMsg_GetPreferredExtensionForMimeType( |
| 275 UTF16ToASCII(mime_type), &file_extension)); | 275 UTF16ToASCII(mime_type), &file_extension)); |
| 276 return webkit_base::FilePathStringToWebString(file_extension); | 276 return webkit_base::FilePathStringToWebString(file_extension); |
| 277 } | 277 } |
| 278 | 278 |
| 279 WebBlobRegistry* WorkerWebKitPlatformSupportImpl::blobRegistry() { | 279 WebBlobRegistry* WorkerWebKitPlatformSupportImpl::blobRegistry() { |
| 280 if (!blob_registry_.get()) | 280 if (!blob_registry_.get() && thread_safe_sender_.get()) |
| 281 blob_registry_.reset(new WebBlobRegistryImpl(WorkerThread::current())); | 281 blob_registry_.reset(new WebBlobRegistryImpl(thread_safe_sender_)); |
| 282 return blob_registry_.get(); | 282 return blob_registry_.get(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 } // namespace content | 285 } // namespace content |
| OLD | NEW |