summaryrefslogtreecommitdiffstats
path: root/chrome/worker
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-15 01:38:10 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-15 01:38:10 +0000
commit7d1f3348c26eda2d1656860c821d335bf94d4cda (patch)
treecf910edd254fb577e5e47513797fc9969341a884 /chrome/worker
parent24f4babaca825d5eb07e5ad09830b77b3cd6326f (diff)
downloadchromium_src-7d1f3348c26eda2d1656860c821d335bf94d4cda.zip
chromium_src-7d1f3348c26eda2d1656860c821d335bf94d4cda.tar.gz
chromium_src-7d1f3348c26eda2d1656860c821d335bf94d4cda.tar.bz2
Support file utilities and mime-related methods on workers.
They are necessary to support File::create and File.size() on workers. BUG=none TEST=none Review URL: http://codereview.chromium.org/3660003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62692 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/worker')
-rw-r--r--chrome/worker/worker_webkitclient_impl.cc97
-rw-r--r--chrome/worker/worker_webkitclient_impl.h10
2 files changed, 86 insertions, 21 deletions
diff --git a/chrome/worker/worker_webkitclient_impl.cc b/chrome/worker/worker_webkitclient_impl.cc
index 1645fa8..1f74232 100644
--- a/chrome/worker/worker_webkitclient_impl.cc
+++ b/chrome/worker/worker_webkitclient_impl.cc
@@ -5,6 +5,7 @@
#include "chrome/worker/worker_webkitclient_impl.h"
#include "base/logging.h"
+#include "base/utf_string_conversions.h"
#include "chrome/common/database_util.h"
#include "chrome/common/file_system/webfilesystem_impl.h"
#include "chrome/common/render_messages.h"
@@ -12,13 +13,17 @@
#include "chrome/common/webblobregistry_impl.h"
#include "chrome/common/webmessageportchannel_impl.h"
#include "chrome/worker/worker_thread.h"
+#include "ipc/ipc_sync_message_filter.h"
#include "third_party/WebKit/WebKit/chromium/public/WebBlobRegistry.h"
#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
+#include "webkit/glue/webfileutilities_impl.h"
+#include "webkit/glue/webkit_glue.h"
using WebKit::WebBlobRegistry;
using WebKit::WebClipboard;
using WebKit::WebFileSystem;
+using WebKit::WebFileUtilities;
using WebKit::WebKitClient;
using WebKit::WebMessagePortChannel;
using WebKit::WebMimeRegistry;
@@ -28,6 +33,54 @@ using WebKit::WebStorageNamespace;
using WebKit::WebString;
using WebKit::WebURL;
+// TODO(kinuko): Probably this could be consolidated into
+// RendererWebKitClientImpl::FileUtilities.
+class WorkerWebKitClientImpl::FileUtilities
+ : public webkit_glue::WebFileUtilitiesImpl {
+ public:
+ virtual bool getFileSize(const WebKit::WebString& path, long long& result);
+ virtual bool getFileModificationTime(const WebKit::WebString& path,
+ double& result);
+};
+
+static bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) {
+ WorkerThread* worker_thread = WorkerThread::current();
+ if (worker_thread)
+ return worker_thread->Send(msg);
+
+ scoped_refptr<IPC::SyncMessageFilter> sync_msg_filter =
+ ChildThread::current()->sync_message_filter();
+ return sync_msg_filter->Send(msg);
+}
+
+bool WorkerWebKitClientImpl::FileUtilities::getFileSize(const WebString& path,
+ long long& result) {
+ if (SendSyncMessageFromAnyThread(new ViewHostMsg_GetFileSize(
+ webkit_glue::WebStringToFilePath(path),
+ reinterpret_cast<int64*>(&result)))) {
+ return result >= 0;
+ }
+
+ result = -1;
+ return false;
+}
+
+bool WorkerWebKitClientImpl::FileUtilities::getFileModificationTime(
+ const WebString& path,
+ double& result) {
+ base::Time time;
+ if (SendSyncMessageFromAnyThread(new ViewHostMsg_GetFileModificationTime(
+ webkit_glue::WebStringToFilePath(path), &time))) {
+ result = time.ToDoubleT();
+ return !time.is_null();
+ }
+
+ result = 0;
+ return false;
+}
+
+//------------------------------------------------------------------------------
+
WorkerWebKitClientImpl::WorkerWebKitClientImpl() {
}
@@ -43,14 +96,18 @@ WebMimeRegistry* WorkerWebKitClientImpl::mimeRegistry() {
return this;
}
-WebKit::WebFileSystem* WorkerWebKitClientImpl::fileSystem() {
+WebFileSystem* WorkerWebKitClientImpl::fileSystem() {
if (!web_file_system_.get())
web_file_system_.reset(new WebFileSystemImpl());
return web_file_system_.get();
}
-WebKit::WebFileUtilities* WorkerWebKitClientImpl::fileUtilities() {
- return &file_utilities_;
+WebFileUtilities* WorkerWebKitClientImpl::fileUtilities() {
+ if (!file_utilities_.get()) {
+ file_utilities_.reset(new FileUtilities);
+ file_utilities_->set_sandbox_enabled(sandboxEnabled());
+ }
+ return file_utilities_.get();
}
WebSandboxSupport* WorkerWebKitClientImpl::sandboxSupport() {
@@ -97,12 +154,6 @@ void WorkerWebKitClientImpl::prefetchHostName(const WebString&) {
NOTREACHED();
}
-bool WorkerWebKitClientImpl::getFileSize(const WebString& path,
- long long& result) {
- NOTREACHED();
- return false;
-}
-
WebString WorkerWebKitClientImpl::defaultLocale() {
NOTREACHED();
return WebString();
@@ -174,20 +225,30 @@ WebMimeRegistry::SupportsType WorkerWebKitClientImpl::supportsNonImageMIMEType(
return WebMimeRegistry::IsSupported;
}
-WebString WorkerWebKitClientImpl::mimeTypeForExtension(const WebString&) {
- NOTREACHED();
- return WebString();
+WebString WorkerWebKitClientImpl::mimeTypeForExtension(
+ const WebString& file_extension) {
+ std::string mime_type;
+ WorkerThread::current()->Send(new ViewHostMsg_GetMimeTypeFromExtension(
+ webkit_glue::WebStringToFilePathString(file_extension), &mime_type));
+ return ASCIIToUTF16(mime_type);
}
-WebString WorkerWebKitClientImpl::mimeTypeFromFile(const WebString&) {
- NOTREACHED();
- return WebString();
+WebString WorkerWebKitClientImpl::mimeTypeFromFile(
+ const WebString& file_path) {
+ std::string mime_type;
+ WorkerThread::current()->Send(new ViewHostMsg_GetMimeTypeFromFile(
+ FilePath(webkit_glue::WebStringToFilePathString(file_path)),
+ &mime_type));
+ return ASCIIToUTF16(mime_type);
}
WebString WorkerWebKitClientImpl::preferredExtensionForMIMEType(
- const WebString&) {
- NOTREACHED();
- return WebString();
+ const WebString& mime_type) {
+ FilePath::StringType file_extension;
+ WorkerThread::current()->Send(
+ new ViewHostMsg_GetPreferredExtensionForMimeType(UTF16ToASCII(mime_type),
+ &file_extension));
+ return webkit_glue::FilePathStringToWebString(file_extension);
}
WebBlobRegistry* WorkerWebKitClientImpl::blobRegistry() {
diff --git a/chrome/worker/worker_webkitclient_impl.h b/chrome/worker/worker_webkitclient_impl.h
index e5b3ec6..df98e7d 100644
--- a/chrome/worker/worker_webkitclient_impl.h
+++ b/chrome/worker/worker_webkitclient_impl.h
@@ -8,11 +8,14 @@
#include "base/scoped_ptr.h"
#include "third_party/WebKit/WebKit/chromium/public/WebMimeRegistry.h"
-#include "webkit/glue/webfileutilities_impl.h"
#include "webkit/glue/webkitclient_impl.h"
class WebFileSystemImpl;
+namespace WebKit {
+class WebFileUtilities;
+}
+
class WorkerWebKitClientImpl : public webkit_glue::WebKitClientImpl,
public WebKit::WebMimeRegistry {
public:
@@ -37,7 +40,6 @@ class WorkerWebKitClientImpl : public webkit_glue::WebKitClientImpl,
const WebKit::WebURL& url,
const WebKit::WebURL& first_party_for_cookies);
virtual void prefetchHostName(const WebKit::WebString&);
- virtual bool getFileSize(const WebKit::WebString& path, long long& result);
virtual WebKit::WebString defaultLocale();
virtual WebKit::WebStorageNamespace* createLocalStorageNamespace(
const WebKit::WebString& path, unsigned quota);
@@ -75,7 +77,9 @@ class WorkerWebKitClientImpl : public webkit_glue::WebKitClientImpl,
const WebKit::WebString&);
private:
- webkit_glue::WebFileUtilitiesImpl file_utilities_;
+
+ class FileUtilities;
+ scoped_ptr<FileUtilities> file_utilities_;
scoped_ptr<WebKit::WebBlobRegistry> blob_registry_;