OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 | 89 |
90 bool DOMFileSystemBase::crackFileSystemURL(const KURL& url, FileSystemType& type , String& filePath) | 90 bool DOMFileSystemBase::crackFileSystemURL(const KURL& url, FileSystemType& type , String& filePath) |
91 { | 91 { |
92 if (!url.protocolIs("filesystem")) | 92 if (!url.protocolIs("filesystem")) |
93 return false; | 93 return false; |
94 | 94 |
95 if (!url.innerURL()) | 95 if (!url.innerURL()) |
96 return false; | 96 return false; |
97 | 97 |
98 String typeString = url.innerURL()->path().substring(1); | 98 String typeString = url.innerURL()->path().substring(1); |
99 if (typeString == temporaryPathPrefix) | 99 if (!pathPrefixToFileSystemType(typeString, type)) |
100 type = FileSystemTypeTemporary; | |
101 else if (typeString == persistentPathPrefix) | |
102 type = FileSystemTypePersistent; | |
103 else if (typeString == externalPathPrefix) | |
104 type = FileSystemTypeExternal; | |
105 else | |
106 return false; | 100 return false; |
107 | 101 |
108 filePath = decodeURLEscapeSequences(url.path()); | 102 filePath = decodeURLEscapeSequences(url.path()); |
109 return true; | 103 return true; |
110 } | 104 } |
111 | 105 |
106 KURL DOMFileSystemBase::createFileSystemRootURL(const String& origin, FileSystem Type type) | |
107 { | |
108 String typeString; | |
109 if (type == FileSystemTypeTemporary) | |
110 typeString = temporaryPathPrefix; | |
111 else if (type == FileSystemTypePersistent) | |
112 typeString = persistentPathPrefix; | |
113 else if (type == FileSystemTypeExternal) | |
114 typeString = externalPathPrefix; | |
115 else | |
116 return KURL(); | |
117 | |
118 StringBuilder result; | |
119 result.append("filesystem:"); | |
120 result.append(origin); | |
121 result.append("/"); | |
122 result.append(typeString); | |
123 result.append("/"); | |
abarth-chromium
2013/09/13 17:33:01
You should use use operator+ as follows:
String r
nhiroki
2013/09/16 16:36:07
Done.
| |
124 return KURL(ParsedURLString, result.toString()); | |
125 } | |
126 | |
112 bool DOMFileSystemBase::supportsToURL() const | 127 bool DOMFileSystemBase::supportsToURL() const |
113 { | 128 { |
114 ASSERT(isValidType(m_type)); | 129 ASSERT(isValidType(m_type)); |
115 return m_type != FileSystemTypeIsolated; | 130 return m_type != FileSystemTypeIsolated; |
116 } | 131 } |
117 | 132 |
118 KURL DOMFileSystemBase::createFileSystemURL(const EntryBase* entry) const | 133 KURL DOMFileSystemBase::createFileSystemURL(const EntryBase* entry) const |
119 { | 134 { |
120 return createFileSystemURL(entry->fullPath()); | 135 return createFileSystemURL(entry->fullPath()); |
121 } | 136 } |
(...skipping 16 matching lines...) Expand all Loading... | |
138 } | 153 } |
139 | 154 |
140 // For regular types we can just append the entry's fullPath to the m_filesy stemRootURL that should look like 'filesystem:<origin>/<typePrefix>'. | 155 // For regular types we can just append the entry's fullPath to the m_filesy stemRootURL that should look like 'filesystem:<origin>/<typePrefix>'. |
141 ASSERT(!m_filesystemRootURL.isEmpty()); | 156 ASSERT(!m_filesystemRootURL.isEmpty()); |
142 KURL url = m_filesystemRootURL; | 157 KURL url = m_filesystemRootURL; |
143 // Remove the extra leading slash. | 158 // Remove the extra leading slash. |
144 url.setPath(url.path() + encodeWithURLEscapeSequences(fullPath.substring(1)) ); | 159 url.setPath(url.path() + encodeWithURLEscapeSequences(fullPath.substring(1)) ); |
145 return url; | 160 return url; |
146 } | 161 } |
147 | 162 |
163 bool DOMFileSystemBase::pathToAbsolutePath(FileSystemType type, const EntryBase* base, String path, String& absolutePath) | |
164 { | |
165 ASSERT(base); | |
166 | |
167 if (!DOMFilePath::isAbsolute(path)) | |
168 path = DOMFilePath::append(base->fullPath(), path); | |
169 absolutePath = DOMFilePath::removeExtraParentReferences(path); | |
170 | |
171 if ((type == FileSystemTypeTemporary || type == FileSystemTypePersistent) && !DOMFilePath::isValidPath(absolutePath)) | |
172 return false; | |
173 return true; | |
abarth-chromium
2013/09/13 17:33:01
There's no need to write "return false" or "return
nhiroki
2013/09/16 16:36:07
Done.
| |
174 } | |
175 | |
176 bool DOMFileSystemBase::pathPrefixToFileSystemType(const String& pathPrefix, Fil eSystemType& type) | |
177 { | |
178 if (pathPrefix == temporaryPathPrefix) { | |
179 type = FileSystemTypeTemporary; | |
180 return true; | |
181 } | |
182 | |
183 if (pathPrefix == persistentPathPrefix) { | |
184 type = FileSystemTypePersistent; | |
185 return true; | |
186 } | |
187 | |
188 if (pathPrefix == externalPathPrefix) { | |
189 type = FileSystemTypeExternal; | |
190 return true; | |
191 } | |
192 | |
193 return false; | |
194 } | |
195 | |
148 bool DOMFileSystemBase::getMetadata(const EntryBase* entry, PassRefPtr<MetadataC allback> successCallback, PassRefPtr<ErrorCallback> errorCallback, SynchronousTy pe synchronousType) | 196 bool DOMFileSystemBase::getMetadata(const EntryBase* entry, PassRefPtr<MetadataC allback> successCallback, PassRefPtr<ErrorCallback> errorCallback, SynchronousTy pe synchronousType) |
149 { | 197 { |
150 OwnPtr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::create(success Callback, errorCallback, this)); | 198 OwnPtr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::create(success Callback, errorCallback, this)); |
151 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 199 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
152 fileSystem()->readMetadata(createFileSystemURL(entry), callbacks.release()); | 200 fileSystem()->readMetadata(createFileSystemURL(entry), callbacks.release()); |
153 return true; | 201 return true; |
154 } | 202 } |
155 | 203 |
156 static bool verifyAndGetDestinationPathForCopyOrMove(const EntryBase* source, En tryBase* parent, const String& newName, String& destinationPath) | 204 static bool verifyAndGetDestinationPathForCopyOrMove(const EntryBase* source, En tryBase* parent, const String& newName, String& destinationPath) |
157 { | 205 { |
(...skipping 17 matching lines...) Expand all Loading... | |
175 | 223 |
176 destinationPath = parent->fullPath(); | 224 destinationPath = parent->fullPath(); |
177 if (!newName.isEmpty()) | 225 if (!newName.isEmpty()) |
178 destinationPath = DOMFilePath::append(destinationPath, newName); | 226 destinationPath = DOMFilePath::append(destinationPath, newName); |
179 else | 227 else |
180 destinationPath = DOMFilePath::append(destinationPath, source->name()); | 228 destinationPath = DOMFilePath::append(destinationPath, source->name()); |
181 | 229 |
182 return true; | 230 return true; |
183 } | 231 } |
184 | 232 |
185 static bool pathToAbsolutePath(FileSystemType type, const EntryBase* base, Strin g path, String& absolutePath) | |
186 { | |
187 ASSERT(base); | |
188 | |
189 if (!DOMFilePath::isAbsolute(path)) | |
190 path = DOMFilePath::append(base->fullPath(), path); | |
191 absolutePath = DOMFilePath::removeExtraParentReferences(path); | |
192 | |
193 if ((type == FileSystemTypeTemporary || type == FileSystemTypePersistent) && !DOMFilePath::isValidPath(absolutePath)) | |
194 return false; | |
195 return true; | |
196 } | |
197 | |
198 bool DOMFileSystemBase::move(const EntryBase* source, EntryBase* parent, const S tring& newName, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallb ack> errorCallback, SynchronousType synchronousType) | 233 bool DOMFileSystemBase::move(const EntryBase* source, EntryBase* parent, const S tring& newName, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallb ack> errorCallback, SynchronousType synchronousType) |
199 { | 234 { |
200 String destinationPath; | 235 String destinationPath; |
201 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti nationPath)) | 236 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti nationPath)) |
202 return false; | 237 return false; |
203 | 238 |
204 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal lback, errorCallback, parent->filesystem(), destinationPath, source->isDirectory ())); | 239 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal lback, errorCallback, parent->filesystem(), destinationPath, source->isDirectory ())); |
205 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 240 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
206 | 241 |
207 fileSystem()->move(createFileSystemURL(source), parent->filesystem()->create FileSystemURL(destinationPath), callbacks.release()); | 242 fileSystem()->move(createFileSystemURL(source), parent->filesystem()->create FileSystemURL(destinationPath), callbacks.release()); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 ASSERT(DOMFilePath::isAbsolute(path)); | 330 ASSERT(DOMFilePath::isAbsolute(path)); |
296 | 331 |
297 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::create(successC allback, errorCallback, reader, path)); | 332 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::create(successC allback, errorCallback, reader, path)); |
298 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 333 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
299 | 334 |
300 fileSystem()->readDirectory(createFileSystemURL(path), callbacks.release()); | 335 fileSystem()->readDirectory(createFileSystemURL(path), callbacks.release()); |
301 return true; | 336 return true; |
302 } | 337 } |
303 | 338 |
304 } // namespace WebCore | 339 } // namespace WebCore |
OLD | NEW |