Pass CreateDirectory errors up to IndexedDB.
[chromium-blink-merge.git] / content / worker / worker_webkitplatformsupport_impl.cc
blob76ad385efd7e109030368b6e831d850fbf3d5db2
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/worker/worker_webkitplatformsupport_impl.h"
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/platform_file.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "content/child/database_util.h"
13 #include "content/child/fileapi/webfilesystem_impl.h"
14 #include "content/child/indexed_db/proxy_webidbfactory_impl.h"
15 #include "content/child/thread_safe_sender.h"
16 #include "content/child/webblobregistry_impl.h"
17 #include "content/child/webmessageportchannel_impl.h"
18 #include "content/common/file_utilities_messages.h"
19 #include "content/common/mime_registry_messages.h"
20 #include "content/worker/worker_thread.h"
21 #include "ipc/ipc_sync_message_filter.h"
22 #include "net/base/mime_util.h"
23 #include "third_party/WebKit/public/platform/WebBlobRegistry.h"
24 #include "third_party/WebKit/public/platform/WebFileInfo.h"
25 #include "third_party/WebKit/public/platform/WebString.h"
26 #include "third_party/WebKit/public/platform/WebURL.h"
27 #include "webkit/glue/webfileutilities_impl.h"
28 #include "webkit/glue/webkit_glue.h"
30 using WebKit::Platform;
31 using WebKit::WebBlobRegistry;
32 using WebKit::WebClipboard;
33 using WebKit::WebFileInfo;
34 using WebKit::WebFileSystem;
35 using WebKit::WebFileUtilities;
36 using WebKit::WebMessagePortChannel;
37 using WebKit::WebMimeRegistry;
38 using WebKit::WebSandboxSupport;
39 using WebKit::WebStorageNamespace;
40 using WebKit::WebString;
41 using WebKit::WebURL;
43 namespace content {
45 // TODO(kinuko): Probably this could be consolidated into
46 // RendererWebKitPlatformSupportImpl::FileUtilities.
47 class WorkerWebKitPlatformSupportImpl::FileUtilities
48 : public webkit_glue::WebFileUtilitiesImpl {
49 public:
50 explicit FileUtilities(ThreadSafeSender* sender)
51 : thread_safe_sender_(sender) {}
52 virtual bool getFileInfo(const WebString& path, WebFileInfo& result);
53 private:
54 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
57 bool WorkerWebKitPlatformSupportImpl::FileUtilities::getFileInfo(
58 const WebString& path,
59 WebFileInfo& web_file_info) {
60 base::PlatformFileInfo file_info;
61 base::PlatformFileError status;
62 if (!thread_safe_sender_.get() ||
63 !thread_safe_sender_->Send(new FileUtilitiesMsg_GetFileInfo(
64 base::FilePath::FromUTF16Unsafe(path), &file_info, &status)) ||
65 status != base::PLATFORM_FILE_OK) {
66 return false;
68 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info);
69 web_file_info.platformPath = path;
70 return true;
73 //------------------------------------------------------------------------------
75 WorkerWebKitPlatformSupportImpl::WorkerWebKitPlatformSupportImpl(
76 ThreadSafeSender* sender,
77 IPC::SyncMessageFilter* sync_message_filter)
78 : thread_safe_sender_(sender),
79 child_thread_loop_(base::MessageLoopProxy::current()),
80 sync_message_filter_(sync_message_filter) {
83 WorkerWebKitPlatformSupportImpl::~WorkerWebKitPlatformSupportImpl() {
86 WebClipboard* WorkerWebKitPlatformSupportImpl::clipboard() {
87 NOTREACHED();
88 return NULL;
91 WebMimeRegistry* WorkerWebKitPlatformSupportImpl::mimeRegistry() {
92 return this;
95 WebFileSystem* WorkerWebKitPlatformSupportImpl::fileSystem() {
96 if (!web_file_system_)
97 web_file_system_.reset(new WebFileSystemImpl());
98 return web_file_system_.get();
101 WebFileUtilities* WorkerWebKitPlatformSupportImpl::fileUtilities() {
102 if (!file_utilities_) {
103 file_utilities_.reset(new FileUtilities(thread_safe_sender_.get()));
104 file_utilities_->set_sandbox_enabled(sandboxEnabled());
106 return file_utilities_.get();
109 WebSandboxSupport* WorkerWebKitPlatformSupportImpl::sandboxSupport() {
110 NOTREACHED();
111 return NULL;
114 bool WorkerWebKitPlatformSupportImpl::sandboxEnabled() {
115 // Always return true because WebKit should always act as though the Sandbox
116 // is enabled for workers. See the comment in WebKitPlatformSupport for
117 // more info.
118 return true;
121 unsigned long long WorkerWebKitPlatformSupportImpl::visitedLinkHash(
122 const char* canonical_url,
123 size_t length) {
124 NOTREACHED();
125 return 0;
128 bool WorkerWebKitPlatformSupportImpl::isLinkVisited(
129 unsigned long long link_hash) {
130 NOTREACHED();
131 return false;
134 WebMessagePortChannel*
135 WorkerWebKitPlatformSupportImpl::createMessagePortChannel() {
136 return new WebMessagePortChannelImpl(child_thread_loop_);
139 void WorkerWebKitPlatformSupportImpl::setCookies(
140 const WebURL& url,
141 const WebURL& first_party_for_cookies,
142 const WebString& value) {
143 NOTREACHED();
146 WebString WorkerWebKitPlatformSupportImpl::cookies(
147 const WebURL& url, const WebURL& first_party_for_cookies) {
148 // WebSocketHandshake may access cookies in worker process.
149 return WebString();
152 void WorkerWebKitPlatformSupportImpl::prefetchHostName(const WebString&) {
153 NOTREACHED();
156 WebString WorkerWebKitPlatformSupportImpl::defaultLocale() {
157 NOTREACHED();
158 return WebString();
161 WebStorageNamespace*
162 WorkerWebKitPlatformSupportImpl::createLocalStorageNamespace(
163 const WebString& path, unsigned quota) {
164 NOTREACHED();
165 return 0;
168 void WorkerWebKitPlatformSupportImpl::dispatchStorageEvent(
169 const WebString& key, const WebString& old_value,
170 const WebString& new_value, const WebString& origin,
171 const WebKit::WebURL& url, bool is_local_storage) {
172 NOTREACHED();
175 Platform::FileHandle
176 WorkerWebKitPlatformSupportImpl::databaseOpenFile(
177 const WebString& vfs_file_name, int desired_flags) {
178 return DatabaseUtil::DatabaseOpenFile(
179 vfs_file_name, desired_flags, sync_message_filter_);
182 int WorkerWebKitPlatformSupportImpl::databaseDeleteFile(
183 const WebString& vfs_file_name, bool sync_dir) {
184 return DatabaseUtil::DatabaseDeleteFile(
185 vfs_file_name, sync_dir, sync_message_filter_);
188 long WorkerWebKitPlatformSupportImpl::databaseGetFileAttributes(
189 const WebString& vfs_file_name) {
190 return DatabaseUtil::DatabaseGetFileAttributes(
191 vfs_file_name, sync_message_filter_);
194 long long WorkerWebKitPlatformSupportImpl::databaseGetFileSize(
195 const WebString& vfs_file_name) {
196 return DatabaseUtil::DatabaseGetFileSize(
197 vfs_file_name, sync_message_filter_);
200 long long WorkerWebKitPlatformSupportImpl::databaseGetSpaceAvailableForOrigin(
201 const WebString& origin_identifier) {
202 return DatabaseUtil::DatabaseGetSpaceAvailable(
203 origin_identifier, sync_message_filter_);
206 WebKit::WebIDBFactory* WorkerWebKitPlatformSupportImpl::idbFactory() {
207 if (!web_idb_factory_)
208 web_idb_factory_.reset(new RendererWebIDBFactoryImpl());
209 return web_idb_factory_.get();
212 WebMimeRegistry::SupportsType
213 WorkerWebKitPlatformSupportImpl::supportsMIMEType(
214 const WebString&) {
215 return WebMimeRegistry::IsSupported;
218 WebMimeRegistry::SupportsType
219 WorkerWebKitPlatformSupportImpl::supportsImageMIMEType(
220 const WebString&) {
221 NOTREACHED();
222 return WebMimeRegistry::IsSupported;
225 WebMimeRegistry::SupportsType
226 WorkerWebKitPlatformSupportImpl::supportsJavaScriptMIMEType(const WebString&) {
227 NOTREACHED();
228 return WebMimeRegistry::IsSupported;
231 WebMimeRegistry::SupportsType
232 WorkerWebKitPlatformSupportImpl::supportsMediaMIMEType(
233 const WebString&, const WebString&) {
234 NOTREACHED();
235 return WebMimeRegistry::IsSupported;
238 WebMimeRegistry::SupportsType
239 WorkerWebKitPlatformSupportImpl::supportsMediaMIMEType(
240 const WebString&, const WebString&, const WebString&) {
241 NOTREACHED();
242 return WebMimeRegistry::IsSupported;
245 bool WorkerWebKitPlatformSupportImpl::supportsMediaSourceMIMEType(
246 const WebKit::WebString& mimeType, const WebKit::WebString& codecs) {
247 NOTREACHED();
248 return false;
251 WebMimeRegistry::SupportsType
252 WorkerWebKitPlatformSupportImpl::supportsNonImageMIMEType(
253 const WebString&) {
254 NOTREACHED();
255 return WebMimeRegistry::IsSupported;
258 WebString WorkerWebKitPlatformSupportImpl::mimeTypeForExtension(
259 const WebString& file_extension) {
260 std::string mime_type;
261 thread_safe_sender_->Send(new MimeRegistryMsg_GetMimeTypeFromExtension(
262 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type));
263 return ASCIIToUTF16(mime_type);
266 WebString WorkerWebKitPlatformSupportImpl::wellKnownMimeTypeForExtension(
267 const WebString& file_extension) {
268 std::string mime_type;
269 net::GetWellKnownMimeTypeFromExtension(
270 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type);
271 return ASCIIToUTF16(mime_type);
274 WebString WorkerWebKitPlatformSupportImpl::mimeTypeFromFile(
275 const WebString& file_path) {
276 std::string mime_type;
277 thread_safe_sender_->Send(
278 new MimeRegistryMsg_GetMimeTypeFromFile(
279 base::FilePath::FromUTF16Unsafe(file_path),
280 &mime_type));
281 return ASCIIToUTF16(mime_type);
284 WebString WorkerWebKitPlatformSupportImpl::preferredExtensionForMIMEType(
285 const WebString& mime_type) {
286 base::FilePath::StringType file_extension;
287 thread_safe_sender_->Send(
288 new MimeRegistryMsg_GetPreferredExtensionForMimeType(
289 UTF16ToASCII(mime_type), &file_extension));
290 return base::FilePath(file_extension).AsUTF16Unsafe();
293 WebBlobRegistry* WorkerWebKitPlatformSupportImpl::blobRegistry() {
294 if (!blob_registry_.get() && thread_safe_sender_.get())
295 blob_registry_.reset(new WebBlobRegistryImpl(thread_safe_sender_.get()));
296 return blob_registry_.get();
299 } // namespace content