Remove unused Device Motion IPC messages.
[chromium-blink-merge.git] / content / worker / worker_webkitplatformsupport_impl.cc
blob3cc4c81d5bfae762265d22a7459219f18a0b7817
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/quota_dispatcher.h"
16 #include "content/child/quota_message_filter.h"
17 #include "content/child/thread_safe_sender.h"
18 #include "content/child/webblobregistry_impl.h"
19 #include "content/child/webmessageportchannel_impl.h"
20 #include "content/common/file_utilities_messages.h"
21 #include "content/common/mime_registry_messages.h"
22 #include "content/worker/worker_thread.h"
23 #include "ipc/ipc_sync_message_filter.h"
24 #include "net/base/mime_util.h"
25 #include "third_party/WebKit/public/platform/WebBlobRegistry.h"
26 #include "third_party/WebKit/public/platform/WebFileInfo.h"
27 #include "third_party/WebKit/public/platform/WebString.h"
28 #include "third_party/WebKit/public/platform/WebURL.h"
29 #include "webkit/common/quota/quota_types.h"
30 #include "webkit/glue/webfileutilities_impl.h"
31 #include "webkit/glue/webkit_glue.h"
33 using WebKit::Platform;
34 using WebKit::WebBlobRegistry;
35 using WebKit::WebClipboard;
36 using WebKit::WebFileInfo;
37 using WebKit::WebFileSystem;
38 using WebKit::WebFileUtilities;
39 using WebKit::WebMessagePortChannel;
40 using WebKit::WebMimeRegistry;
41 using WebKit::WebSandboxSupport;
42 using WebKit::WebStorageNamespace;
43 using WebKit::WebString;
44 using WebKit::WebURL;
46 namespace content {
48 // TODO(kinuko): Probably this could be consolidated into
49 // RendererWebKitPlatformSupportImpl::FileUtilities.
50 class WorkerWebKitPlatformSupportImpl::FileUtilities
51 : public webkit_glue::WebFileUtilitiesImpl {
52 public:
53 explicit FileUtilities(ThreadSafeSender* sender)
54 : thread_safe_sender_(sender) {}
55 virtual bool getFileInfo(const WebString& path, WebFileInfo& result);
56 private:
57 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
60 bool WorkerWebKitPlatformSupportImpl::FileUtilities::getFileInfo(
61 const WebString& path,
62 WebFileInfo& web_file_info) {
63 base::PlatformFileInfo file_info;
64 base::PlatformFileError status;
65 if (!thread_safe_sender_.get() ||
66 !thread_safe_sender_->Send(new FileUtilitiesMsg_GetFileInfo(
67 base::FilePath::FromUTF16Unsafe(path), &file_info, &status)) ||
68 status != base::PLATFORM_FILE_OK) {
69 return false;
71 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info);
72 web_file_info.platformPath = path;
73 return true;
76 //------------------------------------------------------------------------------
78 WorkerWebKitPlatformSupportImpl::WorkerWebKitPlatformSupportImpl(
79 ThreadSafeSender* sender,
80 IPC::SyncMessageFilter* sync_message_filter,
81 QuotaMessageFilter* quota_message_filter)
82 : thread_safe_sender_(sender),
83 child_thread_loop_(base::MessageLoopProxy::current()),
84 sync_message_filter_(sync_message_filter),
85 quota_message_filter_(quota_message_filter) {
88 WorkerWebKitPlatformSupportImpl::~WorkerWebKitPlatformSupportImpl() {
89 WebFileSystemImpl::DeleteThreadSpecificInstance();
92 WebClipboard* WorkerWebKitPlatformSupportImpl::clipboard() {
93 NOTREACHED();
94 return NULL;
97 WebMimeRegistry* WorkerWebKitPlatformSupportImpl::mimeRegistry() {
98 return this;
101 WebFileSystem* WorkerWebKitPlatformSupportImpl::fileSystem() {
102 return WebFileSystemImpl::ThreadSpecificInstance(child_thread_loop_.get());
105 WebFileUtilities* WorkerWebKitPlatformSupportImpl::fileUtilities() {
106 if (!file_utilities_) {
107 file_utilities_.reset(new FileUtilities(thread_safe_sender_.get()));
108 file_utilities_->set_sandbox_enabled(sandboxEnabled());
110 return file_utilities_.get();
113 WebSandboxSupport* WorkerWebKitPlatformSupportImpl::sandboxSupport() {
114 NOTREACHED();
115 return NULL;
118 bool WorkerWebKitPlatformSupportImpl::sandboxEnabled() {
119 // Always return true because WebKit should always act as though the Sandbox
120 // is enabled for workers. See the comment in WebKitPlatformSupport for
121 // more info.
122 return true;
125 unsigned long long WorkerWebKitPlatformSupportImpl::visitedLinkHash(
126 const char* canonical_url,
127 size_t length) {
128 NOTREACHED();
129 return 0;
132 bool WorkerWebKitPlatformSupportImpl::isLinkVisited(
133 unsigned long long link_hash) {
134 NOTREACHED();
135 return false;
138 WebMessagePortChannel*
139 WorkerWebKitPlatformSupportImpl::createMessagePortChannel() {
140 return new WebMessagePortChannelImpl(child_thread_loop_.get());
143 void WorkerWebKitPlatformSupportImpl::setCookies(
144 const WebURL& url,
145 const WebURL& first_party_for_cookies,
146 const WebString& value) {
147 NOTREACHED();
150 WebString WorkerWebKitPlatformSupportImpl::cookies(
151 const WebURL& url, const WebURL& first_party_for_cookies) {
152 // WebSocketHandshake may access cookies in worker process.
153 return WebString();
156 WebString WorkerWebKitPlatformSupportImpl::defaultLocale() {
157 NOTREACHED();
158 return WebString();
161 WebStorageNamespace*
162 WorkerWebKitPlatformSupportImpl::createLocalStorageNamespace() {
163 NOTREACHED();
164 return 0;
167 void WorkerWebKitPlatformSupportImpl::dispatchStorageEvent(
168 const WebString& key, const WebString& old_value,
169 const WebString& new_value, const WebString& origin,
170 const WebKit::WebURL& url, bool is_local_storage) {
171 NOTREACHED();
174 Platform::FileHandle
175 WorkerWebKitPlatformSupportImpl::databaseOpenFile(
176 const WebString& vfs_file_name, int desired_flags) {
177 return DatabaseUtil::DatabaseOpenFile(
178 vfs_file_name, desired_flags, sync_message_filter_.get());
181 int WorkerWebKitPlatformSupportImpl::databaseDeleteFile(
182 const WebString& vfs_file_name, bool sync_dir) {
183 return DatabaseUtil::DatabaseDeleteFile(
184 vfs_file_name, sync_dir, sync_message_filter_.get());
187 long WorkerWebKitPlatformSupportImpl::databaseGetFileAttributes(
188 const WebString& vfs_file_name) {
189 return DatabaseUtil::DatabaseGetFileAttributes(vfs_file_name,
190 sync_message_filter_.get());
193 long long WorkerWebKitPlatformSupportImpl::databaseGetFileSize(
194 const WebString& vfs_file_name) {
195 return DatabaseUtil::DatabaseGetFileSize(vfs_file_name,
196 sync_message_filter_.get());
199 long long WorkerWebKitPlatformSupportImpl::databaseGetSpaceAvailableForOrigin(
200 const WebString& origin_identifier) {
201 return DatabaseUtil::DatabaseGetSpaceAvailable(origin_identifier,
202 sync_message_filter_.get());
205 WebKit::WebIDBFactory* WorkerWebKitPlatformSupportImpl::idbFactory() {
206 if (!web_idb_factory_)
207 web_idb_factory_.reset(
208 new RendererWebIDBFactoryImpl(thread_safe_sender_.get()));
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 WebBlobRegistry* WorkerWebKitPlatformSupportImpl::blobRegistry() {
285 if (!blob_registry_.get() && thread_safe_sender_.get())
286 blob_registry_.reset(new WebBlobRegistryImpl(thread_safe_sender_.get()));
287 return blob_registry_.get();
290 void WorkerWebKitPlatformSupportImpl::queryStorageUsageAndQuota(
291 const WebKit::WebURL& storage_partition,
292 WebKit::WebStorageQuotaType type,
293 WebKit::WebStorageQuotaCallbacks* callbacks) {
294 if (!thread_safe_sender_.get() || !quota_message_filter_.get())
295 return;
296 QuotaDispatcher::ThreadSpecificInstance(
297 thread_safe_sender_.get(),
298 quota_message_filter_.get())->QueryStorageUsageAndQuota(
299 storage_partition,
300 static_cast<quota::StorageType>(type),
301 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
304 } // namespace content