| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/worker/worker_webkitclient_impl.h" | 5 #include "chrome/worker/worker_webkitclient_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/common/database_util.h" | 9 #include "chrome/common/database_util.h" |
| 9 #include "chrome/common/file_system/webfilesystem_impl.h" | 10 #include "chrome/common/file_system/webfilesystem_impl.h" |
| 10 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
| 11 #include "chrome/common/render_messages_params.h" | 12 #include "chrome/common/render_messages_params.h" |
| 12 #include "chrome/common/webblobregistry_impl.h" | 13 #include "chrome/common/webblobregistry_impl.h" |
| 13 #include "chrome/common/webmessageportchannel_impl.h" | 14 #include "chrome/common/webmessageportchannel_impl.h" |
| 14 #include "chrome/worker/worker_thread.h" | 15 #include "chrome/worker/worker_thread.h" |
| 16 #include "ipc/ipc_sync_message_filter.h" |
| 15 #include "third_party/WebKit/WebKit/chromium/public/WebBlobRegistry.h" | 17 #include "third_party/WebKit/WebKit/chromium/public/WebBlobRegistry.h" |
| 16 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 18 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 17 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" | 19 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 20 #include "webkit/glue/webfileutilities_impl.h" |
| 21 #include "webkit/glue/webkit_glue.h" |
| 18 | 22 |
| 19 using WebKit::WebBlobRegistry; | 23 using WebKit::WebBlobRegistry; |
| 20 using WebKit::WebClipboard; | 24 using WebKit::WebClipboard; |
| 21 using WebKit::WebFileSystem; | 25 using WebKit::WebFileSystem; |
| 26 using WebKit::WebFileUtilities; |
| 22 using WebKit::WebKitClient; | 27 using WebKit::WebKitClient; |
| 23 using WebKit::WebMessagePortChannel; | 28 using WebKit::WebMessagePortChannel; |
| 24 using WebKit::WebMimeRegistry; | 29 using WebKit::WebMimeRegistry; |
| 25 using WebKit::WebSandboxSupport; | 30 using WebKit::WebSandboxSupport; |
| 26 using WebKit::WebSharedWorkerRepository; | 31 using WebKit::WebSharedWorkerRepository; |
| 27 using WebKit::WebStorageNamespace; | 32 using WebKit::WebStorageNamespace; |
| 28 using WebKit::WebString; | 33 using WebKit::WebString; |
| 29 using WebKit::WebURL; | 34 using WebKit::WebURL; |
| 30 | 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 ViewHostMsg_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 ViewHostMsg_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 |
| 31 WorkerWebKitClientImpl::WorkerWebKitClientImpl() { | 84 WorkerWebKitClientImpl::WorkerWebKitClientImpl() { |
| 32 } | 85 } |
| 33 | 86 |
| 34 WorkerWebKitClientImpl::~WorkerWebKitClientImpl() { | 87 WorkerWebKitClientImpl::~WorkerWebKitClientImpl() { |
| 35 } | 88 } |
| 36 | 89 |
| 37 WebClipboard* WorkerWebKitClientImpl::clipboard() { | 90 WebClipboard* WorkerWebKitClientImpl::clipboard() { |
| 38 NOTREACHED(); | 91 NOTREACHED(); |
| 39 return NULL; | 92 return NULL; |
| 40 } | 93 } |
| 41 | 94 |
| 42 WebMimeRegistry* WorkerWebKitClientImpl::mimeRegistry() { | 95 WebMimeRegistry* WorkerWebKitClientImpl::mimeRegistry() { |
| 43 return this; | 96 return this; |
| 44 } | 97 } |
| 45 | 98 |
| 46 WebKit::WebFileSystem* WorkerWebKitClientImpl::fileSystem() { | 99 WebFileSystem* WorkerWebKitClientImpl::fileSystem() { |
| 47 if (!web_file_system_.get()) | 100 if (!web_file_system_.get()) |
| 48 web_file_system_.reset(new WebFileSystemImpl()); | 101 web_file_system_.reset(new WebFileSystemImpl()); |
| 49 return web_file_system_.get(); | 102 return web_file_system_.get(); |
| 50 } | 103 } |
| 51 | 104 |
| 52 WebKit::WebFileUtilities* WorkerWebKitClientImpl::fileUtilities() { | 105 WebFileUtilities* WorkerWebKitClientImpl::fileUtilities() { |
| 53 return &file_utilities_; | 106 if (!file_utilities_.get()) { |
| 107 file_utilities_.reset(new FileUtilities); |
| 108 file_utilities_->set_sandbox_enabled(sandboxEnabled()); |
| 109 } |
| 110 return file_utilities_.get(); |
| 54 } | 111 } |
| 55 | 112 |
| 56 WebSandboxSupport* WorkerWebKitClientImpl::sandboxSupport() { | 113 WebSandboxSupport* WorkerWebKitClientImpl::sandboxSupport() { |
| 57 NOTREACHED(); | 114 NOTREACHED(); |
| 58 return NULL; | 115 return NULL; |
| 59 } | 116 } |
| 60 | 117 |
| 61 bool WorkerWebKitClientImpl::sandboxEnabled() { | 118 bool WorkerWebKitClientImpl::sandboxEnabled() { |
| 62 // Always return true because WebKit should always act as though the Sandbox | 119 // Always return true because WebKit should always act as though the Sandbox |
| 63 // is enabled for workers. See the comment in WebKitClient for more info. | 120 // is enabled for workers. See the comment in WebKitClient for more info. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 90 WebString WorkerWebKitClientImpl::cookies( | 147 WebString WorkerWebKitClientImpl::cookies( |
| 91 const WebURL& url, const WebURL& first_party_for_cookies) { | 148 const WebURL& url, const WebURL& first_party_for_cookies) { |
| 92 // WebSocketHandshake may access cookies in worker process. | 149 // WebSocketHandshake may access cookies in worker process. |
| 93 return WebString(); | 150 return WebString(); |
| 94 } | 151 } |
| 95 | 152 |
| 96 void WorkerWebKitClientImpl::prefetchHostName(const WebString&) { | 153 void WorkerWebKitClientImpl::prefetchHostName(const WebString&) { |
| 97 NOTREACHED(); | 154 NOTREACHED(); |
| 98 } | 155 } |
| 99 | 156 |
| 100 bool WorkerWebKitClientImpl::getFileSize(const WebString& path, | |
| 101 long long& result) { | |
| 102 NOTREACHED(); | |
| 103 return false; | |
| 104 } | |
| 105 | |
| 106 WebString WorkerWebKitClientImpl::defaultLocale() { | 157 WebString WorkerWebKitClientImpl::defaultLocale() { |
| 107 NOTREACHED(); | 158 NOTREACHED(); |
| 108 return WebString(); | 159 return WebString(); |
| 109 } | 160 } |
| 110 | 161 |
| 111 WebStorageNamespace* WorkerWebKitClientImpl::createLocalStorageNamespace( | 162 WebStorageNamespace* WorkerWebKitClientImpl::createLocalStorageNamespace( |
| 112 const WebString& path, unsigned quota) { | 163 const WebString& path, unsigned quota) { |
| 113 NOTREACHED(); | 164 NOTREACHED(); |
| 114 return 0; | 165 return 0; |
| 115 } | 166 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 NOTREACHED(); | 218 NOTREACHED(); |
| 168 return WebMimeRegistry::IsSupported; | 219 return WebMimeRegistry::IsSupported; |
| 169 } | 220 } |
| 170 | 221 |
| 171 WebMimeRegistry::SupportsType WorkerWebKitClientImpl::supportsNonImageMIMEType( | 222 WebMimeRegistry::SupportsType WorkerWebKitClientImpl::supportsNonImageMIMEType( |
| 172 const WebString&) { | 223 const WebString&) { |
| 173 NOTREACHED(); | 224 NOTREACHED(); |
| 174 return WebMimeRegistry::IsSupported; | 225 return WebMimeRegistry::IsSupported; |
| 175 } | 226 } |
| 176 | 227 |
| 177 WebString WorkerWebKitClientImpl::mimeTypeForExtension(const WebString&) { | 228 WebString WorkerWebKitClientImpl::mimeTypeForExtension( |
| 178 NOTREACHED(); | 229 const WebString& file_extension) { |
| 179 return WebString(); | 230 std::string mime_type; |
| 231 WorkerThread::current()->Send(new ViewHostMsg_GetMimeTypeFromExtension( |
| 232 webkit_glue::WebStringToFilePathString(file_extension), &mime_type)); |
| 233 return ASCIIToUTF16(mime_type); |
| 180 } | 234 } |
| 181 | 235 |
| 182 WebString WorkerWebKitClientImpl::mimeTypeFromFile(const WebString&) { | 236 WebString WorkerWebKitClientImpl::mimeTypeFromFile( |
| 183 NOTREACHED(); | 237 const WebString& file_path) { |
| 184 return WebString(); | 238 std::string mime_type; |
| 239 WorkerThread::current()->Send(new ViewHostMsg_GetMimeTypeFromFile( |
| 240 FilePath(webkit_glue::WebStringToFilePathString(file_path)), |
| 241 &mime_type)); |
| 242 return ASCIIToUTF16(mime_type); |
| 185 } | 243 } |
| 186 | 244 |
| 187 WebString WorkerWebKitClientImpl::preferredExtensionForMIMEType( | 245 WebString WorkerWebKitClientImpl::preferredExtensionForMIMEType( |
| 188 const WebString&) { | 246 const WebString& mime_type) { |
| 189 NOTREACHED(); | 247 FilePath::StringType file_extension; |
| 190 return WebString(); | 248 WorkerThread::current()->Send( |
| 249 new ViewHostMsg_GetPreferredExtensionForMimeType(UTF16ToASCII(mime_type), |
| 250 &file_extension)); |
| 251 return webkit_glue::FilePathStringToWebString(file_extension); |
| 191 } | 252 } |
| 192 | 253 |
| 193 WebBlobRegistry* WorkerWebKitClientImpl::blobRegistry() { | 254 WebBlobRegistry* WorkerWebKitClientImpl::blobRegistry() { |
| 194 if (!blob_registry_.get()) | 255 if (!blob_registry_.get()) |
| 195 blob_registry_.reset(new WebBlobRegistryImpl(WorkerThread::current())); | 256 blob_registry_.reset(new WebBlobRegistryImpl(WorkerThread::current())); |
| 196 return blob_registry_.get(); | 257 return blob_registry_.get(); |
| 197 } | 258 } |
| OLD | NEW |