android: Add screen recording tool
[chromium-blink-merge.git] / content / worker / worker_webkitplatformsupport_impl.cc
blob7176a775b3d7046bacd8881bd8a018b1187801b6
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 blink::Platform;
34 using blink::WebBlobRegistry;
35 using blink::WebClipboard;
36 using blink::WebFileInfo;
37 using blink::WebFileSystem;
38 using blink::WebFileUtilities;
39 using blink::WebMessagePortChannel;
40 using blink::WebMimeRegistry;
41 using blink::WebSandboxSupport;
42 using blink::WebStorageNamespace;
43 using blink::WebString;
44 using blink::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) {
86 if (sender)
87 blob_registry_.reset(new WebBlobRegistryImpl(sender));
90 WorkerWebKitPlatformSupportImpl::~WorkerWebKitPlatformSupportImpl() {
91 WebFileSystemImpl::DeleteThreadSpecificInstance();
94 WebClipboard* WorkerWebKitPlatformSupportImpl::clipboard() {
95 NOTREACHED();
96 return NULL;
99 WebMimeRegistry* WorkerWebKitPlatformSupportImpl::mimeRegistry() {
100 return this;
103 WebFileSystem* WorkerWebKitPlatformSupportImpl::fileSystem() {
104 return WebFileSystemImpl::ThreadSpecificInstance(child_thread_loop_.get());
107 WebFileUtilities* WorkerWebKitPlatformSupportImpl::fileUtilities() {
108 if (!file_utilities_) {
109 file_utilities_.reset(new FileUtilities(thread_safe_sender_.get()));
110 file_utilities_->set_sandbox_enabled(sandboxEnabled());
112 return file_utilities_.get();
115 WebSandboxSupport* WorkerWebKitPlatformSupportImpl::sandboxSupport() {
116 NOTREACHED();
117 return NULL;
120 bool WorkerWebKitPlatformSupportImpl::sandboxEnabled() {
121 // Always return true because WebKit should always act as though the Sandbox
122 // is enabled for workers. See the comment in WebKitPlatformSupport for
123 // more info.
124 return true;
127 unsigned long long WorkerWebKitPlatformSupportImpl::visitedLinkHash(
128 const char* canonical_url,
129 size_t length) {
130 NOTREACHED();
131 return 0;
134 bool WorkerWebKitPlatformSupportImpl::isLinkVisited(
135 unsigned long long link_hash) {
136 NOTREACHED();
137 return false;
140 WebMessagePortChannel*
141 WorkerWebKitPlatformSupportImpl::createMessagePortChannel() {
142 return new WebMessagePortChannelImpl(child_thread_loop_.get());
145 void WorkerWebKitPlatformSupportImpl::setCookies(
146 const WebURL& url,
147 const WebURL& first_party_for_cookies,
148 const WebString& value) {
149 NOTREACHED();
152 WebString WorkerWebKitPlatformSupportImpl::cookies(
153 const WebURL& url, const WebURL& first_party_for_cookies) {
154 // WebSocketHandshake may access cookies in worker process.
155 return WebString();
158 WebString WorkerWebKitPlatformSupportImpl::defaultLocale() {
159 NOTREACHED();
160 return WebString();
163 WebStorageNamespace*
164 WorkerWebKitPlatformSupportImpl::createLocalStorageNamespace() {
165 NOTREACHED();
166 return 0;
169 void WorkerWebKitPlatformSupportImpl::dispatchStorageEvent(
170 const WebString& key, const WebString& old_value,
171 const WebString& new_value, const WebString& origin,
172 const blink::WebURL& url, bool is_local_storage) {
173 NOTREACHED();
176 Platform::FileHandle
177 WorkerWebKitPlatformSupportImpl::databaseOpenFile(
178 const WebString& vfs_file_name, int desired_flags) {
179 return DatabaseUtil::DatabaseOpenFile(
180 vfs_file_name, desired_flags, sync_message_filter_.get());
183 int WorkerWebKitPlatformSupportImpl::databaseDeleteFile(
184 const WebString& vfs_file_name, bool sync_dir) {
185 return DatabaseUtil::DatabaseDeleteFile(
186 vfs_file_name, sync_dir, sync_message_filter_.get());
189 long WorkerWebKitPlatformSupportImpl::databaseGetFileAttributes(
190 const WebString& vfs_file_name) {
191 return DatabaseUtil::DatabaseGetFileAttributes(vfs_file_name,
192 sync_message_filter_.get());
195 long long WorkerWebKitPlatformSupportImpl::databaseGetFileSize(
196 const WebString& vfs_file_name) {
197 return DatabaseUtil::DatabaseGetFileSize(vfs_file_name,
198 sync_message_filter_.get());
201 long long WorkerWebKitPlatformSupportImpl::databaseGetSpaceAvailableForOrigin(
202 const WebString& origin_identifier) {
203 return DatabaseUtil::DatabaseGetSpaceAvailable(origin_identifier,
204 sync_message_filter_.get());
207 blink::WebIDBFactory* WorkerWebKitPlatformSupportImpl::idbFactory() {
208 if (!web_idb_factory_)
209 web_idb_factory_.reset(
210 new RendererWebIDBFactoryImpl(thread_safe_sender_.get()));
211 return web_idb_factory_.get();
214 WebMimeRegistry::SupportsType
215 WorkerWebKitPlatformSupportImpl::supportsMIMEType(
216 const WebString&) {
217 return WebMimeRegistry::IsSupported;
220 WebMimeRegistry::SupportsType
221 WorkerWebKitPlatformSupportImpl::supportsImageMIMEType(
222 const WebString&) {
223 NOTREACHED();
224 return WebMimeRegistry::IsSupported;
227 WebMimeRegistry::SupportsType
228 WorkerWebKitPlatformSupportImpl::supportsJavaScriptMIMEType(const WebString&) {
229 NOTREACHED();
230 return WebMimeRegistry::IsSupported;
233 WebMimeRegistry::SupportsType
234 WorkerWebKitPlatformSupportImpl::supportsMediaMIMEType(
235 const WebString&, const WebString&, const WebString&) {
236 NOTREACHED();
237 return WebMimeRegistry::IsSupported;
240 bool WorkerWebKitPlatformSupportImpl::supportsMediaSourceMIMEType(
241 const blink::WebString& mimeType, const blink::WebString& codecs) {
242 NOTREACHED();
243 return false;
246 WebMimeRegistry::SupportsType
247 WorkerWebKitPlatformSupportImpl::supportsNonImageMIMEType(
248 const WebString&) {
249 NOTREACHED();
250 return WebMimeRegistry::IsSupported;
253 WebString WorkerWebKitPlatformSupportImpl::mimeTypeForExtension(
254 const WebString& file_extension) {
255 std::string mime_type;
256 thread_safe_sender_->Send(new MimeRegistryMsg_GetMimeTypeFromExtension(
257 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type));
258 return ASCIIToUTF16(mime_type);
261 WebString WorkerWebKitPlatformSupportImpl::wellKnownMimeTypeForExtension(
262 const WebString& file_extension) {
263 std::string mime_type;
264 net::GetWellKnownMimeTypeFromExtension(
265 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type);
266 return ASCIIToUTF16(mime_type);
269 WebString WorkerWebKitPlatformSupportImpl::mimeTypeFromFile(
270 const WebString& file_path) {
271 std::string mime_type;
272 thread_safe_sender_->Send(
273 new MimeRegistryMsg_GetMimeTypeFromFile(
274 base::FilePath::FromUTF16Unsafe(file_path),
275 &mime_type));
276 return ASCIIToUTF16(mime_type);
279 WebBlobRegistry* WorkerWebKitPlatformSupportImpl::blobRegistry() {
280 return blob_registry_.get();
283 void WorkerWebKitPlatformSupportImpl::queryStorageUsageAndQuota(
284 const blink::WebURL& storage_partition,
285 blink::WebStorageQuotaType type,
286 blink::WebStorageQuotaCallbacks* callbacks) {
287 if (!thread_safe_sender_.get() || !quota_message_filter_.get())
288 return;
289 QuotaDispatcher::ThreadSpecificInstance(
290 thread_safe_sender_.get(),
291 quota_message_filter_.get())->QueryStorageUsageAndQuota(
292 storage_partition,
293 static_cast<quota::StorageType>(type),
294 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
297 } // namespace content