https://bugs.webkit.org/show_bug.cgi?id=76551
Source/WebCore:
Reviewed by David Levin.
Moved the implementation of crackFileSystemURL() and toURL() from
WebCore/fileapi/DOMFileSystemBase into WebCore/platform/AsyncFileSystem
so that each platform can extend/implement their behavior if necessary.
No new tests as it has no functional changes.
* fileapi/DOMFileSystemBase.cpp: Moved crackFileSystemURL() to AsyncFileSystem.
* fileapi/DOMFileSystemBase.h:
(DOMFileSystemBase):
* fileapi/EntryBase.cpp: Moved toURL() to AsyncFileSystem.
(WebCore::EntryBase::toURL):
* page/DOMWindow.cpp: Made corresponding callsite changes.
(WebCore::DOMWindow::webkitRequestFileSystem):
(WebCore::DOMWindow::webkitResolveLocalFileSystemURL):
* page/DOMWindow.h:
* platform/AsyncFileSystem.cpp:
(WebCore::AsyncFileSystem::isValidType): Added.
* platform/AsyncFileSystem.h:
(AsyncFileSystem):
* workers/WorkerContext.cpp: Made corresponding callsite changes.
(WebCore::WorkerContext::webkitRequestFileSystem):
(WebCore::WorkerContext::webkitRequestFileSystemSync):
(WebCore::WorkerContext::webkitResolveLocalFileSystemURL):
(WebCore::WorkerContext::webkitResolveLocalFileSystemSyncURL):
* workers/WorkerContext.h:
Source/WebKit/chromium:
* src/AssertMatchingEnums.cpp: Removed the matching assertion for AsyncFileSystem::External (as now we directly use WebFileSystem::TypeExternal).
* src/AsyncFileSystemChromium.cpp:
(WebCore::AsyncFileSystem::crackFileSystemURL): Added.
(WebCore::AsyncFileSystem::isValidType): Added.
(WebCore::AsyncFileSystemChromium::toURL): Added.
* src/AsyncFileSystemChromium.h:
(AsyncFileSystemChromium):
* src/WorkerAsyncFileSystemChromium.cpp: Made this subclass of AsyncFileSystemChromium (rather than that of AsyncFileSystem)
(WebCore::WorkerAsyncFileSystemChromium::WorkerAsyncFileSystemChromium):
* src/WorkerAsyncFileSystemChromium.h:
(WorkerAsyncFileSystemChromium):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@106542
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2012-02-02 Kinuko Yasuda <kinuko@chromium.org>
+
+ Cleanup: Move chrome-specific filesystem type handling code (for FileSystem API) under chromium directory (re-landing r105395)
+ https://bugs.webkit.org/show_bug.cgi?id=76551
+
+ Reviewed by David Levin.
+
+ Moved the implementation of crackFileSystemURL() and toURL() from
+ WebCore/fileapi/DOMFileSystemBase into WebCore/platform/AsyncFileSystem
+ so that each platform can extend/implement their behavior if necessary.
+
+ No new tests as it has no functional changes.
+
+ * fileapi/DOMFileSystemBase.cpp: Moved crackFileSystemURL() to AsyncFileSystem.
+ * fileapi/DOMFileSystemBase.h:
+ (DOMFileSystemBase):
+ * fileapi/EntryBase.cpp: Moved toURL() to AsyncFileSystem.
+ (WebCore::EntryBase::toURL):
+ * page/DOMWindow.cpp: Made corresponding callsite changes.
+ (WebCore::DOMWindow::webkitRequestFileSystem):
+ (WebCore::DOMWindow::webkitResolveLocalFileSystemURL):
+ * page/DOMWindow.h:
+ * platform/AsyncFileSystem.cpp:
+ (WebCore::AsyncFileSystem::isValidType): Added.
+ * platform/AsyncFileSystem.h:
+ (AsyncFileSystem):
+ * workers/WorkerContext.cpp: Made corresponding callsite changes.
+ (WebCore::WorkerContext::webkitRequestFileSystem):
+ (WebCore::WorkerContext::webkitRequestFileSystemSync):
+ (WebCore::WorkerContext::webkitResolveLocalFileSystemURL):
+ (WebCore::WorkerContext::webkitResolveLocalFileSystemSyncURL):
+ * workers/WorkerContext.h:
+
2012-02-02 Yury Semikhatsky <yurys@chromium.org>
Web Inspector: pause on uncaugh exceptions state is not properly restored
namespace WebCore {
-const char DOMFileSystemBase::kPersistentPathPrefix[] = "persistent";
-const size_t DOMFileSystemBase::kPersistentPathPrefixLength = sizeof(DOMFileSystemBase::kPersistentPathPrefix) - 1;
-const char DOMFileSystemBase::kTemporaryPathPrefix[] = "temporary";
-const size_t DOMFileSystemBase::kTemporaryPathPrefixLength = sizeof(DOMFileSystemBase::kTemporaryPathPrefix) - 1;
-const char DOMFileSystemBase::kExternalPathPrefix[] = "external";
-const size_t DOMFileSystemBase::kExternalPathPrefixLength = sizeof(DOMFileSystemBase::kExternalPathPrefix) - 1;
-
-bool DOMFileSystemBase::crackFileSystemURL(const KURL& url, AsyncFileSystem::Type& type, String& filePath)
-{
- if (!url.protocolIs("filesystem"))
- return false;
-
- KURL originURL(ParsedURLString, url.path());
- String path = decodeURLEscapeSequences(originURL.path());
- if (path.isEmpty() || path[0] != '/')
- return false;
- path = path.substring(1);
-
- if (path.startsWith(kTemporaryPathPrefix)) {
- type = AsyncFileSystem::Temporary;
- path = path.substring(kTemporaryPathPrefixLength);
- } else if (path.startsWith(kPersistentPathPrefix)) {
- type = AsyncFileSystem::Persistent;
- path = path.substring(kPersistentPathPrefixLength);
- } else if (path.startsWith(kExternalPathPrefix)) {
- type = AsyncFileSystem::External;
- path = path.substring(kExternalPathPrefixLength);
- } else
- return false;
-
- if (path.isEmpty() || path[0] != '/')
- return false;
-
- filePath.swap(path);
- return true;
-}
-
DOMFileSystemBase::DOMFileSystemBase(ScriptExecutionContext* context, const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
: m_context(context)
, m_name(name)
}
virtual ~DOMFileSystemBase();
- static const char kPersistentPathPrefix[];
- static const size_t kPersistentPathPrefixLength;
- static const char kTemporaryPathPrefix[];
- static const size_t kTemporaryPathPrefixLength;
- static const char kExternalPathPrefix[];
- static const size_t kExternalPathPrefixLength;
- static bool crackFileSystemURL(const KURL&, AsyncFileSystem::Type&, String& filePath);
-
const String& name() const { return m_name; }
AsyncFileSystem* asyncFileSystem() const { return m_asyncFileSystem.get(); }
SecurityOrigin* securityOrigin() const;
String EntryBase::toURL()
{
- String originString = m_fileSystem->securityOrigin()->toString();
- ASSERT(!originString.isEmpty());
- if (originString == "null")
- return String();
- StringBuilder result;
- result.append("filesystem:");
- result.append(originString);
- result.append("/");
- switch (m_fileSystem->asyncFileSystem()->type()) {
- case AsyncFileSystem::Temporary:
- result.append(DOMFileSystemBase::kTemporaryPathPrefix);
- break;
- case AsyncFileSystem::Persistent:
- result.append(DOMFileSystemBase::kPersistentPathPrefix);
- break;
- case AsyncFileSystem::External:
- result.append(DOMFileSystemBase::kExternalPathPrefix);
- break;
- }
- result.append(encodeWithURLEscapeSequences(m_fullPath));
- return result.toString();
+ return m_fileSystem->asyncFileSystem()->toURL(m_fileSystem->securityOrigin()->toString(), m_fullPath);
}
} // namespace WebCore
#if ENABLE(FILE_SYSTEM)
#include "AsyncFileSystem.h"
#include "DOMFileSystem.h"
-#include "DOMFileSystemBase.h"
#include "EntryCallback.h"
#include "ErrorCallback.h"
#include "FileError.h"
}
AsyncFileSystem::Type fileSystemType = static_cast<AsyncFileSystem::Type>(type);
- if (fileSystemType != AsyncFileSystem::Temporary && fileSystemType != AsyncFileSystem::Persistent && fileSystemType != AsyncFileSystem::External) {
+ if (!AsyncFileSystem::isValidType(fileSystemType)) {
DOMFileSystem::scheduleCallback(document, errorCallback, FileError::create(FileError::INVALID_MODIFICATION_ERR));
return;
}
AsyncFileSystem::Type type;
String filePath;
- if (!completedURL.isValid() || !DOMFileSystemBase::crackFileSystemURL(completedURL, type, filePath)) {
+ if (!completedURL.isValid() || !AsyncFileSystem::crackFileSystemURL(completedURL, type, filePath)) {
DOMFileSystem::scheduleCallback(document, errorCallback, FileError::create(FileError::ENCODING_ERR));
return;
}
LocalFileSystem::localFileSystem().readFileSystem(document, type, ResolveURICallbacks::create(successCallback, errorCallback, document, filePath));
}
-COMPILE_ASSERT(static_cast<int>(DOMWindow::EXTERNAL) == static_cast<int>(AsyncFileSystem::External), enum_mismatch);
-
COMPILE_ASSERT(static_cast<int>(DOMWindow::TEMPORARY) == static_cast<int>(AsyncFileSystem::Temporary), enum_mismatch);
COMPILE_ASSERT(static_cast<int>(DOMWindow::PERSISTENT) == static_cast<int>(AsyncFileSystem::Persistent), enum_mismatch);
enum FileSystemType {
TEMPORARY,
PERSISTENT,
- EXTERNAL,
};
void webkitRequestFileSystem(int type, long long size, PassRefPtr<FileSystemCallback>, PassRefPtr<ErrorCallback>);
void webkitResolveLocalFileSystemURL(const String&, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>);
namespace WebCore {
+const char AsyncFileSystem::persistentPathPrefix[] = "persistent";
+const size_t AsyncFileSystem::persistentPathPrefixLength = sizeof(AsyncFileSystem::persistentPathPrefix) - 1;
+const char AsyncFileSystem::temporaryPathPrefix[] = "temporary";
+const size_t AsyncFileSystem::temporaryPathPrefixLength = sizeof(AsyncFileSystem::temporaryPathPrefix) - 1;
+
#if !PLATFORM(CHROMIUM)
bool AsyncFileSystem::isAvailable()
{
return false;
}
+bool AsyncFileSystem::isValidType(Type type)
+{
+ return type == Temporary || type == Persistent;
+}
+
PassOwnPtr<AsyncFileSystem> AsyncFileSystem::create(Type, const String&)
{
notImplemented();
enum Type {
Temporary,
Persistent,
- External,
};
+ // Path prefixes that are used in the filesystem URLs (that can be obtained by toURL()).
+ // http://www.w3.org/TR/file-system-api/#widl-Entry-toURL
+ static const char persistentPathPrefix[];
+ static const size_t persistentPathPrefixLength;
+ static const char temporaryPathPrefix[];
+ static const size_t temporaryPathPrefixLength;
+
virtual void stop() { }
virtual bool hasPendingActivity() { return false; }
static bool isAvailable();
+ static bool isValidType(Type);
+
+ static bool crackFileSystemURL(const KURL&, Type&, String& filePath);
+
+ virtual String toURL(const String& originString, const String& fullPath) = 0;
+
// Subclass must implement this if it supports synchronous operations.
// This should return false if there are no pending operations.
virtual bool waitForOperationToComplete() { return false; }
}
AsyncFileSystem::Type fileSystemType = static_cast<AsyncFileSystem::Type>(type);
- if (fileSystemType != AsyncFileSystem::Temporary && fileSystemType != AsyncFileSystem::Persistent && fileSystemType != AsyncFileSystem::External) {
+ if (!AsyncFileSystem::isValidType(fileSystemType)) {
DOMFileSystem::scheduleCallback(this, errorCallback, FileError::create(FileError::INVALID_MODIFICATION_ERR));
return;
}
}
AsyncFileSystem::Type fileSystemType = static_cast<AsyncFileSystem::Type>(type);
- if (fileSystemType != AsyncFileSystem::Temporary && fileSystemType != AsyncFileSystem::Persistent && fileSystemType != AsyncFileSystem::External) {
+ if (!AsyncFileSystem::isValidType(fileSystemType)) {
ec = FileException::INVALID_MODIFICATION_ERR;
return 0;
}
AsyncFileSystem::Type type;
String filePath;
- if (!completedURL.isValid() || !DOMFileSystemBase::crackFileSystemURL(completedURL, type, filePath)) {
+ if (!completedURL.isValid() || !AsyncFileSystem::crackFileSystemURL(completedURL, type, filePath)) {
DOMFileSystem::scheduleCallback(this, errorCallback, FileError::create(FileError::ENCODING_ERR));
return;
}
AsyncFileSystem::Type type;
String filePath;
- if (!completedURL.isValid() || !DOMFileSystemBase::crackFileSystemURL(completedURL, type, filePath)) {
+ if (!completedURL.isValid() || !AsyncFileSystem::crackFileSystemURL(completedURL, type, filePath)) {
ec = FileException::ENCODING_ERR;
return 0;
}
COMPILE_ASSERT(static_cast<int>(WorkerContext::TEMPORARY) == static_cast<int>(AsyncFileSystem::Temporary), enum_mismatch);
COMPILE_ASSERT(static_cast<int>(WorkerContext::PERSISTENT) == static_cast<int>(AsyncFileSystem::Persistent), enum_mismatch);
-COMPILE_ASSERT(static_cast<int>(WorkerContext::EXTERNAL) == static_cast<int>(AsyncFileSystem::External), enum_mismatch);
#endif
WorkerContext::Observer::Observer(WorkerContext* context)
enum FileSystemType {
TEMPORARY,
PERSISTENT,
- EXTERNAL,
};
void webkitRequestFileSystem(int type, long long size, PassRefPtr<FileSystemCallback> successCallback, PassRefPtr<ErrorCallback>);
PassRefPtr<DOMFileSystemSync> webkitRequestFileSystemSync(int type, long long size, ExceptionCode&);
+2012-02-02 Kinuko Yasuda <kinuko@chromium.org>
+
+ Cleanup: Move chrome-specific filesystem type handling code (for FileSystem API) under chromium directory (re-landing r105395)
+ https://bugs.webkit.org/show_bug.cgi?id=76551
+
+ * src/AssertMatchingEnums.cpp: Removed the matching assertion for AsyncFileSystem::External (as now we directly use WebFileSystem::TypeExternal).
+ * src/AsyncFileSystemChromium.cpp:
+ (WebCore::AsyncFileSystem::crackFileSystemURL): Added.
+ (WebCore::AsyncFileSystem::isValidType): Added.
+ (WebCore::AsyncFileSystemChromium::toURL): Added.
+ * src/AsyncFileSystemChromium.h:
+ (AsyncFileSystemChromium):
+ * src/WorkerAsyncFileSystemChromium.cpp: Made this subclass of AsyncFileSystemChromium (rather than that of AsyncFileSystem)
+ (WebCore::WorkerAsyncFileSystemChromium::WorkerAsyncFileSystemChromium):
+ * src/WorkerAsyncFileSystemChromium.h:
+ (WorkerAsyncFileSystemChromium):
+
2012-02-01 Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
Avoid creating NamedNodeMap unnecessarily
#if ENABLE(FILE_SYSTEM)
COMPILE_ASSERT_MATCHING_ENUM(WebFileSystem::TypeTemporary, AsyncFileSystem::Temporary);
COMPILE_ASSERT_MATCHING_ENUM(WebFileSystem::TypePersistent, AsyncFileSystem::Persistent);
-COMPILE_ASSERT_MATCHING_ENUM(WebFileSystem::TypeExternal, AsyncFileSystem::External);
COMPILE_ASSERT_MATCHING_ENUM(WebFileInfo::TypeUnknown, FileMetadata::TypeUnknown);
COMPILE_ASSERT_MATCHING_ENUM(WebFileInfo::TypeFile, FileMetadata::TypeFile);
COMPILE_ASSERT_MATCHING_ENUM(WebFileInfo::TypeDirectory, FileMetadata::TypeDirectory);
#include "AsyncFileSystemCallbacks.h"
#include "AsyncFileWriterChromium.h"
+#include "SecurityOrigin.h"
#include "WebFileInfo.h"
#include "WebFileSystemCallbacksImpl.h"
#include "WebFileWriter.h"
#include "platform/WebFileSystem.h"
#include "platform/WebKitPlatformSupport.h"
#include <wtf/text/CString.h>
+#include <wtf/text/StringBuilder.h>
namespace WebCore {
+// ChromeOS-specific filesystem type.
+const AsyncFileSystem::Type externalType = static_cast<AsyncFileSystem::Type>(WebKit::WebFileSystem::TypeExternal);
+const char externalPathPrefix[] = "external";
+const size_t externalPathPrefixLength = sizeof(externalPathPrefix) - 1;
+
+// static
bool AsyncFileSystem::isAvailable()
{
return true;
}
+// static
+bool AsyncFileSystem::crackFileSystemURL(const KURL& url, AsyncFileSystem::Type& type, String& filePath)
+{
+ if (!url.protocolIs("filesystem"))
+ return false;
+
+ KURL originURL(ParsedURLString, url.path());
+ String path = decodeURLEscapeSequences(originURL.path());
+ if (path.isEmpty() || path[0] != '/')
+ return false;
+ path = path.substring(1);
+
+ if (path.startsWith(temporaryPathPrefix)) {
+ type = Temporary;
+ path = path.substring(temporaryPathPrefixLength);
+ } else if (path.startsWith(persistentPathPrefix)) {
+ type = Persistent;
+ path = path.substring(persistentPathPrefixLength);
+ } else if (path.startsWith(externalPathPrefix)) {
+ type = externalType;
+ path = path.substring(externalPathPrefixLength);
+ } else
+ return false;
+
+ if (path.isEmpty() || path[0] != '/')
+ return false;
+
+ filePath.swap(path);
+ return true;
+}
+
+// static
+bool AsyncFileSystem::isValidType(Type type)
+{
+ return type == Temporary || type == Persistent || type == static_cast<Type>(WebKit::WebFileSystem::TypeExternal);
+}
+
AsyncFileSystemChromium::AsyncFileSystemChromium(AsyncFileSystem::Type type, const KURL& rootURL)
: AsyncFileSystem(type)
, m_webFileSystem(WebKit::webKitPlatformSupport()->fileSystem())
{
}
+String AsyncFileSystemChromium::toURL(const String& originString, const String& fullPath)
+{
+ ASSERT(!originString.isEmpty());
+ if (originString == "null")
+ return String();
+
+ if (type() == externalType) {
+ // For external filesystem originString could be different from what we have in m_filesystemRootURL.
+ StringBuilder result;
+ result.append("filesystem:");
+ result.append(originString);
+ result.append("/");
+ result.append(externalPathPrefix);
+ result.append(encodeWithURLEscapeSequences(fullPath));
+ return result.toString();
+ }
+
+ // For regular types we can just call virtualPathToFileSystemURL which appends the fullPath to the m_filesystemRootURL that should look like 'filesystem:<origin>/<typePrefix>'.
+ ASSERT(SecurityOrigin::create(m_filesystemRootURL)->toString() == originString);
+ return virtualPathToFileSystemURL(fullPath);
+}
+
void AsyncFileSystemChromium::move(const String& sourcePath, const String& destinationPath, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
{
m_webFileSystem->move(virtualPathToFileSystemURL(sourcePath), virtualPathToFileSystemURL(destinationPath), new WebKit::WebFileSystemCallbacksImpl(callbacks));
virtual ~AsyncFileSystemChromium();
+ virtual String toURL(const String& originString, const String& fullPath);
virtual void move(const String& sourcePath, const String& destinationPath, PassOwnPtr<AsyncFileSystemCallbacks>);
virtual void copy(const String& sourcePath, const String& destinationPath, PassOwnPtr<AsyncFileSystemCallbacks>);
virtual void remove(const String& path, PassOwnPtr<AsyncFileSystemCallbacks>);
virtual void readDirectory(const String& path, PassOwnPtr<AsyncFileSystemCallbacks>);
virtual void createWriter(AsyncFileWriterClient* client, const String& path, PassOwnPtr<AsyncFileSystemCallbacks>);
-private:
+protected:
AsyncFileSystemChromium(AsyncFileSystem::Type, const KURL& rootURL);
WebKit::WebFileSystem* m_webFileSystem;
static const char fileSystemOperationsMode[] = "fileSystemOperationsMode";
WorkerAsyncFileSystemChromium::WorkerAsyncFileSystemChromium(ScriptExecutionContext* context, AsyncFileSystem::Type type, const WebKit::WebURL& rootURL, bool synchronous)
- : AsyncFileSystem(type)
+ : AsyncFileSystemChromium(type, rootURL)
, m_scriptExecutionContext(context)
- , m_webFileSystem(webKitPlatformSupport()->fileSystem())
, m_workerContext(static_cast<WorkerContext*>(context))
, m_synchronous(synchronous)
- , m_filesystemRootURL(rootURL)
{
- ASSERT(m_webFileSystem);
ASSERT(m_scriptExecutionContext->isWorkerContext());
WorkerLoaderProxy* workerLoaderProxy = &m_workerContext->thread()->workerLoaderProxy();
return m_bridgeForCurrentOperation;
}
-KURL WorkerAsyncFileSystemChromium::virtualPathToFileSystemURL(const String& virtualPath) const
-{
- ASSERT(!m_filesystemRootURL.isEmpty());
- KURL url = m_filesystemRootURL;
- // Remove the extra leading slash.
- url.setPath(url.path() + encodeWithURLEscapeSequences(virtualPath.substring(1)));
- return url;
-}
-
} // namespace WebCore
#endif // ENABLE(FILE_SYSTEM)
#if ENABLE(FILE_SYSTEM) && ENABLE(WORKERS)
-#include "AsyncFileSystem.h"
+#include "AsyncFileSystemChromium.h"
#include "PlatformString.h"
#include <wtf/PassOwnPtr.h>
#include <wtf/RefPtr.h>
class ScriptExecutionContext;
class WorkerContext;
-class WorkerAsyncFileSystemChromium : public AsyncFileSystem {
+class WorkerAsyncFileSystemChromium : public AsyncFileSystemChromium {
public:
static PassOwnPtr<AsyncFileSystem> create(ScriptExecutionContext* context, AsyncFileSystem::Type type, const WebKit::WebURL& rootURL, bool synchronous)
{
PassRefPtr<WebKit::WorkerFileSystemCallbacksBridge> createWorkerFileSystemCallbacksBridge(PassOwnPtr<AsyncFileSystemCallbacks>);
- // Converts a given absolute virtual path to a full origin-qualified FileSystem URL.
- KURL virtualPathToFileSystemURL(const String& virtualPath) const;
-
ScriptExecutionContext* m_scriptExecutionContext;
- WebKit::WebFileSystem* m_webFileSystem;
WebKit::WebWorkerBase* m_worker;
WorkerContext* m_workerContext;
RefPtr<WebKit::WorkerFileSystemCallbacksBridge> m_bridgeForCurrentOperation;
String m_modeForCurrentOperation;
bool m_synchronous;
- KURL m_filesystemRootURL;
};
} // namespace WebCore