| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/fileapi/file_system_url.h" | 5 #include "webkit/fileapi/file_system_url.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
| 12 #include "webkit/fileapi/external_mount_points.h" | 12 #include "webkit/fileapi/external_mount_points.h" |
| 13 #include "webkit/fileapi/file_system_types.h" | 13 #include "webkit/fileapi/file_system_types.h" |
| 14 #include "webkit/fileapi/file_system_util.h" | 14 #include "webkit/fileapi/file_system_util.h" |
| 15 #include "webkit/fileapi/isolated_context.h" | 15 #include "webkit/fileapi/isolated_context.h" |
| 16 | 16 |
| 17 namespace fileapi { | 17 namespace fileapi { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 bool ParseFileSystemURL(const GURL& url, | 21 bool ParseFileSystemURL(const GURL& url, |
| 22 GURL* origin_url, | 22 GURL* origin_url, |
| 23 FileSystemType* type, | 23 FileSystemType* type, |
| 24 FilePath* file_path) { | 24 base::FilePath* file_path) { |
| 25 GURL origin; | 25 GURL origin; |
| 26 FileSystemType file_system_type = kFileSystemTypeUnknown; | 26 FileSystemType file_system_type = kFileSystemTypeUnknown; |
| 27 | 27 |
| 28 if (!url.is_valid() || !url.SchemeIsFileSystem()) | 28 if (!url.is_valid() || !url.SchemeIsFileSystem()) |
| 29 return false; | 29 return false; |
| 30 DCHECK(url.inner_url()); | 30 DCHECK(url.inner_url()); |
| 31 | 31 |
| 32 std::string inner_path = url.inner_url()->path(); | 32 std::string inner_path = url.inner_url()->path(); |
| 33 | 33 |
| 34 const struct { | 34 const struct { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 53 return false; | 53 return false; |
| 54 | 54 |
| 55 std::string path = net::UnescapeURLComponent(url.path(), | 55 std::string path = net::UnescapeURLComponent(url.path(), |
| 56 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS | | 56 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS | |
| 57 net::UnescapeRule::CONTROL_CHARS); | 57 net::UnescapeRule::CONTROL_CHARS); |
| 58 | 58 |
| 59 // Ensure the path is relative. | 59 // Ensure the path is relative. |
| 60 while (!path.empty() && path[0] == '/') | 60 while (!path.empty() && path[0] == '/') |
| 61 path.erase(0, 1); | 61 path.erase(0, 1); |
| 62 | 62 |
| 63 FilePath converted_path = FilePath::FromUTF8Unsafe(path); | 63 base::FilePath converted_path = base::FilePath::FromUTF8Unsafe(path); |
| 64 | 64 |
| 65 // All parent references should have been resolved in the renderer. | 65 // All parent references should have been resolved in the renderer. |
| 66 if (converted_path.ReferencesParent()) | 66 if (converted_path.ReferencesParent()) |
| 67 return false; | 67 return false; |
| 68 | 68 |
| 69 if (origin_url) | 69 if (origin_url) |
| 70 *origin_url = url.GetOrigin(); | 70 *origin_url = url.GetOrigin(); |
| 71 if (type) | 71 if (type) |
| 72 *type = file_system_type; | 72 *type = file_system_type; |
| 73 if (file_path) | 73 if (file_path) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 85 mount_type_(kFileSystemTypeUnknown) { | 85 mount_type_(kFileSystemTypeUnknown) { |
| 86 } | 86 } |
| 87 | 87 |
| 88 // static | 88 // static |
| 89 FileSystemURL FileSystemURL::CreateForTest(const GURL& url) { | 89 FileSystemURL FileSystemURL::CreateForTest(const GURL& url) { |
| 90 return FileSystemURL(url); | 90 return FileSystemURL(url); |
| 91 } | 91 } |
| 92 | 92 |
| 93 FileSystemURL FileSystemURL::CreateForTest(const GURL& origin, | 93 FileSystemURL FileSystemURL::CreateForTest(const GURL& origin, |
| 94 FileSystemType type, | 94 FileSystemType type, |
| 95 const FilePath& path) { | 95 const base::FilePath& path) { |
| 96 return FileSystemURL(origin, type, path); | 96 return FileSystemURL(origin, type, path); |
| 97 } | 97 } |
| 98 | 98 |
| 99 FileSystemURL::FileSystemURL(const GURL& url) | 99 FileSystemURL::FileSystemURL(const GURL& url) |
| 100 : type_(kFileSystemTypeUnknown), | 100 : type_(kFileSystemTypeUnknown), |
| 101 mount_type_(kFileSystemTypeUnknown) { | 101 mount_type_(kFileSystemTypeUnknown) { |
| 102 is_valid_ = ParseFileSystemURL(url, &origin_, &type_, &path_); | 102 is_valid_ = ParseFileSystemURL(url, &origin_, &type_, &path_); |
| 103 mount_type_ = type_; | 103 mount_type_ = type_; |
| 104 } | 104 } |
| 105 | 105 |
| 106 FileSystemURL::FileSystemURL(const GURL& origin, | 106 FileSystemURL::FileSystemURL(const GURL& origin, |
| 107 FileSystemType type, | 107 FileSystemType type, |
| 108 const FilePath& path) | 108 const base::FilePath& path) |
| 109 : is_valid_(true), | 109 : is_valid_(true), |
| 110 origin_(origin), | 110 origin_(origin), |
| 111 type_(type), | 111 type_(type), |
| 112 mount_type_(type), | 112 mount_type_(type), |
| 113 path_(path.NormalizePathSeparators()) { | 113 path_(path.NormalizePathSeparators()) { |
| 114 } | 114 } |
| 115 | 115 |
| 116 FileSystemURL::FileSystemURL(const GURL& origin, | 116 FileSystemURL::FileSystemURL(const GURL& origin, |
| 117 FileSystemType original_type, | 117 FileSystemType original_type, |
| 118 const FilePath& original_path, | 118 const base::FilePath& original_path, |
| 119 const std::string& filesystem_id, | 119 const std::string& filesystem_id, |
| 120 FileSystemType cracked_type, | 120 FileSystemType cracked_type, |
| 121 const FilePath& cracked_path) | 121 const base::FilePath& cracked_path) |
| 122 : is_valid_(true), | 122 : is_valid_(true), |
| 123 origin_(origin), | 123 origin_(origin), |
| 124 type_(cracked_type), | 124 type_(cracked_type), |
| 125 mount_type_(original_type), | 125 mount_type_(original_type), |
| 126 path_(cracked_path.NormalizePathSeparators()), | 126 path_(cracked_path.NormalizePathSeparators()), |
| 127 filesystem_id_(filesystem_id), | 127 filesystem_id_(filesystem_id), |
| 128 virtual_path_(original_path.NormalizePathSeparators()) { | 128 virtual_path_(original_path.NormalizePathSeparators()) { |
| 129 } | 129 } |
| 130 | 130 |
| 131 FileSystemURL::~FileSystemURL() {} | 131 FileSystemURL::~FileSystemURL() {} |
| (...skipping 10 matching lines...) Expand all Loading... |
| 142 ss << " ("; | 142 ss << " ("; |
| 143 ss << GetFileSystemTypeString(type_) << "@" << filesystem_id_ << ":"; | 143 ss << GetFileSystemTypeString(type_) << "@" << filesystem_id_ << ":"; |
| 144 ss << path_.value(); | 144 ss << path_.value(); |
| 145 ss << ")"; | 145 ss << ")"; |
| 146 } else { | 146 } else { |
| 147 ss << path_.value(); | 147 ss << path_.value(); |
| 148 } | 148 } |
| 149 return ss.str(); | 149 return ss.str(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 FileSystemURL FileSystemURL::WithPath(const FilePath& path) const { | 152 FileSystemURL FileSystemURL::WithPath(const base::FilePath& path) const { |
| 153 FileSystemURL url = *this; | 153 FileSystemURL url = *this; |
| 154 url.path_ = path; | 154 url.path_ = path; |
| 155 url.virtual_path_.clear(); | 155 url.virtual_path_.clear(); |
| 156 return url; | 156 return url; |
| 157 } | 157 } |
| 158 | 158 |
| 159 bool FileSystemURL::IsParent(const FileSystemURL& child) const { | 159 bool FileSystemURL::IsParent(const FileSystemURL& child) const { |
| 160 return origin() == child.origin() && | 160 return origin() == child.origin() && |
| 161 type() == child.type() && | 161 type() == child.type() && |
| 162 filesystem_id() == child.filesystem_id() && | 162 filesystem_id() == child.filesystem_id() && |
| (...skipping 14 matching lines...) Expand all Loading... |
| 177 if (lhs.origin_ != rhs.origin_) | 177 if (lhs.origin_ != rhs.origin_) |
| 178 return lhs.origin_ < rhs.origin_; | 178 return lhs.origin_ < rhs.origin_; |
| 179 if (lhs.type_ != rhs.type_) | 179 if (lhs.type_ != rhs.type_) |
| 180 return lhs.type_ < rhs.type_; | 180 return lhs.type_ < rhs.type_; |
| 181 if (lhs.filesystem_id_ != rhs.filesystem_id_) | 181 if (lhs.filesystem_id_ != rhs.filesystem_id_) |
| 182 return lhs.filesystem_id_ < rhs.filesystem_id_; | 182 return lhs.filesystem_id_ < rhs.filesystem_id_; |
| 183 return lhs.path_ < rhs.path_; | 183 return lhs.path_ < rhs.path_; |
| 184 } | 184 } |
| 185 | 185 |
| 186 } // namespace fileapi | 186 } // namespace fileapi |
| OLD | NEW |