summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/file_system_util.cc
diff options
context:
space:
mode:
authoradamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-08 03:29:35 +0000
committeradamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-08 03:29:35 +0000
commit8fbe7994047c3ec60182b4b2540d825c95e9f6ef (patch)
treeaf6dfd9cb03fa40c22ffad2b8a739f425f6d8626 /webkit/fileapi/file_system_util.cc
parent6aa800f9d7af07c758cacd2c7d0425c706e4f057 (diff)
downloadchromium_src-8fbe7994047c3ec60182b4b2540d825c95e9f6ef.zip
chromium_src-8fbe7994047c3ec60182b4b2540d825c95e9f6ef.tar.gz
chromium_src-8fbe7994047c3ec60182b4b2540d825c95e9f6ef.tar.bz2
First crack at FileSystemURLRequestJob for handling filesystem: URLs.
Disabled behind a switch, "--enable-filesystem-url-scheme". Review URL: http://codereview.chromium.org/6262015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74082 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/file_system_util.cc')
-rw-r--r--webkit/fileapi/file_system_util.cc62
1 files changed, 62 insertions, 0 deletions
diff --git a/webkit/fileapi/file_system_util.cc b/webkit/fileapi/file_system_util.cc
new file mode 100644
index 0000000..07aa5a6
--- /dev/null
+++ b/webkit/fileapi/file_system_util.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/fileapi/file_system_util.h"
+
+#include "build/build_config.h"
+
+#include "base/file_path.h"
+#include "base/sys_string_conversions.h"
+#include "googleurl/src/gurl.h"
+#include "net/base/escape.h"
+#include "webkit/fileapi/file_system_types.h"
+
+namespace fileapi {
+
+static const char kPersistentDir[] = "/persistent/";
+static const char kTemporaryDir[] = "/temporary/";
+
+bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type,
+ FilePath* file_path) {
+ *origin_url = GURL();
+ *type = kFileSystemTypeUnknown;
+ *file_path = FilePath();
+
+ if (url.scheme() != "filesystem")
+ return false;
+
+ GURL bare_url(url.path());
+ *origin_url = bare_url.GetOrigin();
+
+ // The input URL was malformed, bail out early.
+ if (origin_url->is_empty() || bare_url.path().empty())
+ return false;
+
+ std::string path = UnescapeURLComponent(bare_url.path(),
+ UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS);
+ if (path.compare(0, strlen(kPersistentDir), kPersistentDir) == 0) {
+ *type = kFileSystemTypePersistent;
+ path = path.substr(strlen(kPersistentDir));
+ } else if (path.compare(0, strlen(kTemporaryDir), kTemporaryDir) == 0) {
+ *type = kFileSystemTypeTemporary;
+ path = path.substr(strlen(kTemporaryDir));
+ } else {
+ return false;
+ }
+
+ // Ensure the path is relative.
+ while (!path.empty() && path[0] == '/')
+ path.erase(0, 1);
+
+#if defined(OS_WIN)
+ const FilePath::StringType& sys_path = base::SysUTF8ToWide(path);
+#elif defined(OS_POSIX)
+ const FilePath::StringType& sys_path = path;
+#endif
+
+ *file_path = FilePath(sys_path);
+ return true;
+}
+
+} // namespace fileapi