[content shell] hook up testRunner.dumpEditingCallbacks
[chromium-blink-merge.git] / content / worker / worker_webkitplatformsupport_impl.cc
blob4cd6f262d97d5ab33ca4f0d8e76becb5eb1fb151
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/logging.h"
8 #include "base/platform_file.h"
9 #include "base/utf_string_conversions.h"
10 #include "content/common/database_util.h"
11 #include "content/common/fileapi/webblobregistry_impl.h"
12 #include "content/common/fileapi/webfilesystem_impl.h"
13 #include "content/common/file_utilities_messages.h"
14 #include "content/common/indexed_db/proxy_webidbfactory_impl.h"
15 #include "content/common/mime_registry_messages.h"
16 #include "content/common/webmessageportchannel_impl.h"
17 #include "content/worker/worker_thread.h"
18 #include "ipc/ipc_sync_message_filter.h"
19 #include "net/base/mime_util.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebBlobRegistry.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
24 #include "webkit/base/file_path_string_conversions.h"
25 #include "webkit/glue/webfileutilities_impl.h"
26 #include "webkit/glue/webkit_glue.h"
28 using WebKit::WebBlobRegistry;
29 using WebKit::WebClipboard;
30 using WebKit::WebFileInfo;
31 using WebKit::WebFileSystem;
32 using WebKit::WebFileUtilities;
33 using WebKit::WebKitPlatformSupport;
34 using WebKit::WebMessagePortChannel;
35 using WebKit::WebMimeRegistry;
36 using WebKit::WebSandboxSupport;
37 using WebKit::WebStorageNamespace;
38 using WebKit::WebString;
39 using WebKit::WebURL;
41 namespace content {
43 // TODO(kinuko): Probably this could be consolidated into
44 // RendererWebKitPlatformSupportImpl::FileUtilities.
45 class WorkerWebKitPlatformSupportImpl::FileUtilities
46 : public webkit_glue::WebFileUtilitiesImpl {
47 public:
48 virtual bool getFileInfo(const WebString& path, WebFileInfo& result);
51 static bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) {
52 WorkerThread* worker_thread = WorkerThread::current();
53 if (worker_thread)
54 return worker_thread->Send(msg);
56 scoped_refptr<IPC::SyncMessageFilter> sync_msg_filter(
57 ChildThread::current()->sync_message_filter());
58 return sync_msg_filter->Send(msg);
61 bool WorkerWebKitPlatformSupportImpl::FileUtilities::getFileInfo(
62 const WebString& path,
63 WebFileInfo& web_file_info) {
64 base::PlatformFileInfo file_info;
65 base::PlatformFileError status;
66 if (!SendSyncMessageFromAnyThread(new FileUtilitiesMsg_GetFileInfo(
67 webkit_base::WebStringToFilePath(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() {
81 WorkerWebKitPlatformSupportImpl::~WorkerWebKitPlatformSupportImpl() {
84 WebClipboard* WorkerWebKitPlatformSupportImpl::clipboard() {
85 NOTREACHED();
86 return NULL;
89 WebMimeRegistry* WorkerWebKitPlatformSupportImpl::mimeRegistry() {
90 return this;
93 WebFileSystem* WorkerWebKitPlatformSupportImpl::fileSystem() {
94 if (!web_file_system_.get())
95 web_file_system_.reset(new WebFileSystemImpl());
96 return web_file_system_.get();
99 WebFileUtilities* WorkerWebKitPlatformSupportImpl::fileUtilities() {
100 if (!file_utilities_.get()) {
101 file_utilities_.reset(new FileUtilities);
102 file_utilities_->set_sandbox_enabled(sandboxEnabled());
104 return file_utilities_.get();
107 WebSandboxSupport* WorkerWebKitPlatformSupportImpl::sandboxSupport() {
108 NOTREACHED();
109 return NULL;
112 bool WorkerWebKitPlatformSupportImpl::sandboxEnabled() {
113 // Always return true because WebKit should always act as though the Sandbox
114 // is enabled for workers. See the comment in WebKitPlatformSupport for
115 // more info.
116 return true;
119 unsigned long long WorkerWebKitPlatformSupportImpl::visitedLinkHash(
120 const char* canonical_url,
121 size_t length) {
122 NOTREACHED();
123 return 0;
126 bool WorkerWebKitPlatformSupportImpl::isLinkVisited(
127 unsigned long long link_hash) {
128 NOTREACHED();
129 return false;
132 WebMessagePortChannel*
133 WorkerWebKitPlatformSupportImpl::createMessagePortChannel() {
134 return new WebMessagePortChannelImpl();
137 void WorkerWebKitPlatformSupportImpl::setCookies(
138 const WebURL& url,
139 const WebURL& first_party_for_cookies,
140 const WebString& value) {
141 NOTREACHED();
144 WebString WorkerWebKitPlatformSupportImpl::cookies(
145 const WebURL& url, const WebURL& first_party_for_cookies) {
146 // WebSocketHandshake may access cookies in worker process.
147 return WebString();
150 void WorkerWebKitPlatformSupportImpl::prefetchHostName(const WebString&) {
151 NOTREACHED();
154 WebString WorkerWebKitPlatformSupportImpl::defaultLocale() {
155 NOTREACHED();
156 return WebString();
159 WebStorageNamespace*
160 WorkerWebKitPlatformSupportImpl::createLocalStorageNamespace(
161 const WebString& path, unsigned quota) {
162 NOTREACHED();
163 return 0;
166 void WorkerWebKitPlatformSupportImpl::dispatchStorageEvent(
167 const WebString& key, const WebString& old_value,
168 const WebString& new_value, const WebString& origin,
169 const WebKit::WebURL& url, bool is_local_storage) {
170 NOTREACHED();
173 WebKitPlatformSupport::FileHandle
174 WorkerWebKitPlatformSupportImpl::databaseOpenFile(
175 const WebString& vfs_file_name, int desired_flags) {
176 return DatabaseUtil::DatabaseOpenFile(vfs_file_name, desired_flags);
179 int WorkerWebKitPlatformSupportImpl::databaseDeleteFile(
180 const WebString& vfs_file_name, bool sync_dir) {
181 return DatabaseUtil::DatabaseDeleteFile(vfs_file_name, sync_dir);
184 long WorkerWebKitPlatformSupportImpl::databaseGetFileAttributes(
185 const WebString& vfs_file_name) {
186 return DatabaseUtil::DatabaseGetFileAttributes(vfs_file_name);
189 long long WorkerWebKitPlatformSupportImpl::databaseGetFileSize(
190 const WebString& vfs_file_name) {
191 return DatabaseUtil::DatabaseGetFileSize(vfs_file_name);
194 long long WorkerWebKitPlatformSupportImpl::databaseGetSpaceAvailableForOrigin(
195 const WebString& origin_identifier) {
196 return DatabaseUtil::DatabaseGetSpaceAvailable(origin_identifier);
199 WebKit::WebIDBFactory* WorkerWebKitPlatformSupportImpl::idbFactory() {
200 if (!web_idb_factory_.get())
201 web_idb_factory_.reset(new RendererWebIDBFactoryImpl());
202 return web_idb_factory_.get();
205 WebMimeRegistry::SupportsType
206 WorkerWebKitPlatformSupportImpl::supportsMIMEType(
207 const WebString&) {
208 return WebMimeRegistry::IsSupported;
211 WebMimeRegistry::SupportsType
212 WorkerWebKitPlatformSupportImpl::supportsImageMIMEType(
213 const WebString&) {
214 NOTREACHED();
215 return WebMimeRegistry::IsSupported;
218 WebMimeRegistry::SupportsType
219 WorkerWebKitPlatformSupportImpl::supportsJavaScriptMIMEType(const WebString&) {
220 NOTREACHED();
221 return WebMimeRegistry::IsSupported;
224 WebMimeRegistry::SupportsType
225 WorkerWebKitPlatformSupportImpl::supportsMediaMIMEType(
226 const WebString&, const WebString&) {
227 NOTREACHED();
228 return WebMimeRegistry::IsSupported;
231 WebMimeRegistry::SupportsType
232 WorkerWebKitPlatformSupportImpl::supportsMediaMIMEType(
233 const WebString&, const WebString&, const WebString&) {
234 NOTREACHED();
235 return WebMimeRegistry::IsSupported;
238 WebMimeRegistry::SupportsType
239 WorkerWebKitPlatformSupportImpl::supportsNonImageMIMEType(
240 const WebString&) {
241 NOTREACHED();
242 return WebMimeRegistry::IsSupported;
245 WebString WorkerWebKitPlatformSupportImpl::mimeTypeForExtension(
246 const WebString& file_extension) {
247 std::string mime_type;
248 SendSyncMessageFromAnyThread(new MimeRegistryMsg_GetMimeTypeFromExtension(
249 webkit_base::WebStringToFilePathString(file_extension), &mime_type));
250 return ASCIIToUTF16(mime_type);
253 WebString WorkerWebKitPlatformSupportImpl::wellKnownMimeTypeForExtension(
254 const WebString& file_extension) {
255 std::string mime_type;
256 net::GetWellKnownMimeTypeFromExtension(
257 webkit_base::WebStringToFilePathString(file_extension), &mime_type);
258 return ASCIIToUTF16(mime_type);
261 WebString WorkerWebKitPlatformSupportImpl::mimeTypeFromFile(
262 const WebString& file_path) {
263 std::string mime_type;
264 SendSyncMessageFromAnyThread(new MimeRegistryMsg_GetMimeTypeFromFile(
265 FilePath(webkit_base::WebStringToFilePathString(file_path)),
266 &mime_type));
267 return ASCIIToUTF16(mime_type);
270 WebString WorkerWebKitPlatformSupportImpl::preferredExtensionForMIMEType(
271 const WebString& mime_type) {
272 FilePath::StringType file_extension;
273 SendSyncMessageFromAnyThread(
274 new MimeRegistryMsg_GetPreferredExtensionForMimeType(
275 UTF16ToASCII(mime_type), &file_extension));
276 return webkit_base::FilePathStringToWebString(file_extension);
279 WebBlobRegistry* WorkerWebKitPlatformSupportImpl::blobRegistry() {
280 if (!blob_registry_.get())
281 blob_registry_.reset(new WebBlobRegistryImpl(WorkerThread::current()));
282 return blob_registry_.get();
285 } // namespace content