| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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. | |
| 4 | |
| 5 #include "chrome/worker/worker_webkitclient_impl.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "chrome/worker/worker_thread.h" | |
| 10 #include "content/common/database_util.h" | |
| 11 #include "content/common/file_system/webfilesystem_impl.h" | |
| 12 #include "content/common/file_utilities_messages.h" | |
| 13 #include "content/common/mime_registry_messages.h" | |
| 14 #include "content/common/webblobregistry_impl.h" | |
| 15 #include "content/common/webmessageportchannel_impl.h" | |
| 16 #include "ipc/ipc_sync_message_filter.h" | |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobRegistry.h" | |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | |
| 20 #include "webkit/glue/webfileutilities_impl.h" | |
| 21 #include "webkit/glue/webkit_glue.h" | |
| 22 | |
| 23 using WebKit::WebBlobRegistry; | |
| 24 using WebKit::WebClipboard; | |
| 25 using WebKit::WebFileSystem; | |
| 26 using WebKit::WebFileUtilities; | |
| 27 using WebKit::WebKitClient; | |
| 28 using WebKit::WebMessagePortChannel; | |
| 29 using WebKit::WebMimeRegistry; | |
| 30 using WebKit::WebSandboxSupport; | |
| 31 using WebKit::WebSharedWorkerRepository; | |
| 32 using WebKit::WebStorageNamespace; | |
| 33 using WebKit::WebString; | |
| 34 using WebKit::WebURL; | |
| 35 | |
| 36 // TODO(kinuko): Probably this could be consolidated into | |
| 37 // RendererWebKitClientImpl::FileUtilities. | |
| 38 class WorkerWebKitClientImpl::FileUtilities | |
| 39 : public webkit_glue::WebFileUtilitiesImpl { | |
| 40 public: | |
| 41 virtual bool getFileSize(const WebKit::WebString& path, long long& result); | |
| 42 virtual bool getFileModificationTime(const WebKit::WebString& path, | |
| 43 double& result); | |
| 44 }; | |
| 45 | |
| 46 static bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) { | |
| 47 WorkerThread* worker_thread = WorkerThread::current(); | |
| 48 if (worker_thread) | |
| 49 return worker_thread->Send(msg); | |
| 50 | |
| 51 scoped_refptr<IPC::SyncMessageFilter> sync_msg_filter( | |
| 52 ChildThread::current()->sync_message_filter()); | |
| 53 return sync_msg_filter->Send(msg); | |
| 54 } | |
| 55 | |
| 56 bool WorkerWebKitClientImpl::FileUtilities::getFileSize(const WebString& path, | |
| 57 long long& result) { | |
| 58 if (SendSyncMessageFromAnyThread(new FileUtilitiesMsg_GetFileSize( | |
| 59 webkit_glue::WebStringToFilePath(path), | |
| 60 reinterpret_cast<int64*>(&result)))) { | |
| 61 return result >= 0; | |
| 62 } | |
| 63 | |
| 64 result = -1; | |
| 65 return false; | |
| 66 } | |
| 67 | |
| 68 bool WorkerWebKitClientImpl::FileUtilities::getFileModificationTime( | |
| 69 const WebString& path, | |
| 70 double& result) { | |
| 71 base::Time time; | |
| 72 if (SendSyncMessageFromAnyThread(new FileUtilitiesMsg_GetFileModificationTime( | |
| 73 webkit_glue::WebStringToFilePath(path), &time))) { | |
| 74 result = time.ToDoubleT(); | |
| 75 return !time.is_null(); | |
| 76 } | |
| 77 | |
| 78 result = 0; | |
| 79 return false; | |
| 80 } | |
| 81 | |
| 82 //------------------------------------------------------------------------------ | |
| 83 | |
| 84 WorkerWebKitClientImpl::WorkerWebKitClientImpl() { | |
| 85 } | |
| 86 | |
| 87 WorkerWebKitClientImpl::~WorkerWebKitClientImpl() { | |
| 88 } | |
| 89 | |
| 90 WebClipboard* WorkerWebKitClientImpl::clipboard() { | |
| 91 NOTREACHED(); | |
| 92 return NULL; | |
| 93 } | |
| 94 | |
| 95 WebMimeRegistry* WorkerWebKitClientImpl::mimeRegistry() { | |
| 96 return this; | |
| 97 } | |
| 98 | |
| 99 WebFileSystem* WorkerWebKitClientImpl::fileSystem() { | |
| 100 if (!web_file_system_.get()) | |
| 101 web_file_system_.reset(new WebFileSystemImpl()); | |
| 102 return web_file_system_.get(); | |
| 103 } | |
| 104 | |
| 105 WebFileUtilities* WorkerWebKitClientImpl::fileUtilities() { | |
| 106 if (!file_utilities_.get()) { | |
| 107 file_utilities_.reset(new FileUtilities); | |
| 108 file_utilities_->set_sandbox_enabled(sandboxEnabled()); | |
| 109 } | |
| 110 return file_utilities_.get(); | |
| 111 } | |
| 112 | |
| 113 WebSandboxSupport* WorkerWebKitClientImpl::sandboxSupport() { | |
| 114 NOTREACHED(); | |
| 115 return NULL; | |
| 116 } | |
| 117 | |
| 118 bool WorkerWebKitClientImpl::sandboxEnabled() { | |
| 119 // Always return true because WebKit should always act as though the Sandbox | |
| 120 // is enabled for workers. See the comment in WebKitClient for more info. | |
| 121 return true; | |
| 122 } | |
| 123 | |
| 124 unsigned long long WorkerWebKitClientImpl::visitedLinkHash( | |
| 125 const char* canonical_url, | |
| 126 size_t length) { | |
| 127 NOTREACHED(); | |
| 128 return 0; | |
| 129 } | |
| 130 | |
| 131 bool WorkerWebKitClientImpl::isLinkVisited(unsigned long long link_hash) { | |
| 132 NOTREACHED(); | |
| 133 return false; | |
| 134 } | |
| 135 | |
| 136 WebMessagePortChannel* | |
| 137 WorkerWebKitClientImpl::createMessagePortChannel() { | |
| 138 return new WebMessagePortChannelImpl(); | |
| 139 } | |
| 140 | |
| 141 void WorkerWebKitClientImpl::setCookies(const WebURL& url, | |
| 142 const WebURL& first_party_for_cookies, | |
| 143 const WebString& value) { | |
| 144 NOTREACHED(); | |
| 145 } | |
| 146 | |
| 147 WebString WorkerWebKitClientImpl::cookies( | |
| 148 const WebURL& url, const WebURL& first_party_for_cookies) { | |
| 149 // WebSocketHandshake may access cookies in worker process. | |
| 150 return WebString(); | |
| 151 } | |
| 152 | |
| 153 void WorkerWebKitClientImpl::prefetchHostName(const WebString&) { | |
| 154 NOTREACHED(); | |
| 155 } | |
| 156 | |
| 157 WebString WorkerWebKitClientImpl::defaultLocale() { | |
| 158 NOTREACHED(); | |
| 159 return WebString(); | |
| 160 } | |
| 161 | |
| 162 WebStorageNamespace* WorkerWebKitClientImpl::createLocalStorageNamespace( | |
| 163 const WebString& path, unsigned quota) { | |
| 164 NOTREACHED(); | |
| 165 return 0; | |
| 166 } | |
| 167 | |
| 168 void WorkerWebKitClientImpl::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(); | |
| 173 } | |
| 174 | |
| 175 WebSharedWorkerRepository* WorkerWebKitClientImpl::sharedWorkerRepository() { | |
| 176 return 0; | |
| 177 } | |
| 178 | |
| 179 WebKitClient::FileHandle WorkerWebKitClientImpl::databaseOpenFile( | |
| 180 const WebString& vfs_file_name, int desired_flags) { | |
| 181 return DatabaseUtil::databaseOpenFile(vfs_file_name, desired_flags); | |
| 182 } | |
| 183 | |
| 184 int WorkerWebKitClientImpl::databaseDeleteFile( | |
| 185 const WebString& vfs_file_name, bool sync_dir) { | |
| 186 return DatabaseUtil::databaseDeleteFile(vfs_file_name, sync_dir); | |
| 187 } | |
| 188 | |
| 189 long WorkerWebKitClientImpl::databaseGetFileAttributes( | |
| 190 const WebString& vfs_file_name) { | |
| 191 return DatabaseUtil::databaseGetFileAttributes(vfs_file_name); | |
| 192 } | |
| 193 | |
| 194 long long WorkerWebKitClientImpl::databaseGetFileSize( | |
| 195 const WebString& vfs_file_name) { | |
| 196 return DatabaseUtil::databaseGetFileSize(vfs_file_name); | |
| 197 } | |
| 198 | |
| 199 WebMimeRegistry::SupportsType WorkerWebKitClientImpl::supportsMIMEType( | |
| 200 const WebString&) { | |
| 201 return WebMimeRegistry::IsSupported; | |
| 202 } | |
| 203 | |
| 204 WebMimeRegistry::SupportsType WorkerWebKitClientImpl::supportsImageMIMEType( | |
| 205 const WebString&) { | |
| 206 NOTREACHED(); | |
| 207 return WebMimeRegistry::IsSupported; | |
| 208 } | |
| 209 | |
| 210 WebMimeRegistry::SupportsType | |
| 211 WorkerWebKitClientImpl::supportsJavaScriptMIMEType(const WebString&) { | |
| 212 NOTREACHED(); | |
| 213 return WebMimeRegistry::IsSupported; | |
| 214 } | |
| 215 | |
| 216 WebMimeRegistry::SupportsType WorkerWebKitClientImpl::supportsMediaMIMEType( | |
| 217 const WebString&, const WebString&) { | |
| 218 NOTREACHED(); | |
| 219 return WebMimeRegistry::IsSupported; | |
| 220 } | |
| 221 | |
| 222 WebMimeRegistry::SupportsType WorkerWebKitClientImpl::supportsNonImageMIMEType( | |
| 223 const WebString&) { | |
| 224 NOTREACHED(); | |
| 225 return WebMimeRegistry::IsSupported; | |
| 226 } | |
| 227 | |
| 228 WebString WorkerWebKitClientImpl::mimeTypeForExtension( | |
| 229 const WebString& file_extension) { | |
| 230 std::string mime_type; | |
| 231 SendSyncMessageFromAnyThread(new MimeRegistryMsg_GetMimeTypeFromExtension( | |
| 232 webkit_glue::WebStringToFilePathString(file_extension), &mime_type)); | |
| 233 return ASCIIToUTF16(mime_type); | |
| 234 } | |
| 235 | |
| 236 WebString WorkerWebKitClientImpl::mimeTypeFromFile( | |
| 237 const WebString& file_path) { | |
| 238 std::string mime_type; | |
| 239 SendSyncMessageFromAnyThread(new MimeRegistryMsg_GetMimeTypeFromFile( | |
| 240 FilePath(webkit_glue::WebStringToFilePathString(file_path)), | |
| 241 &mime_type)); | |
| 242 return ASCIIToUTF16(mime_type); | |
| 243 } | |
| 244 | |
| 245 WebString WorkerWebKitClientImpl::preferredExtensionForMIMEType( | |
| 246 const WebString& mime_type) { | |
| 247 FilePath::StringType file_extension; | |
| 248 SendSyncMessageFromAnyThread( | |
| 249 new MimeRegistryMsg_GetPreferredExtensionForMimeType( | |
| 250 UTF16ToASCII(mime_type), &file_extension)); | |
| 251 return webkit_glue::FilePathStringToWebString(file_extension); | |
| 252 } | |
| 253 | |
| 254 WebBlobRegistry* WorkerWebKitClientImpl::blobRegistry() { | |
| 255 if (!blob_registry_.get()) | |
| 256 blob_registry_.reset(new WebBlobRegistryImpl(WorkerThread::current())); | |
| 257 return blob_registry_.get(); | |
| 258 } | |
| OLD | NEW |