OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_util.h" | 5 #include "webkit/fileapi/file_system_util.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, | 30 bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, |
31 FilePath* file_path) { | 31 FilePath* file_path) { |
32 GURL origin; | 32 GURL origin; |
33 FileSystemType file_system_type; | 33 FileSystemType file_system_type; |
34 | 34 |
35 if (url.scheme() != "filesystem") | 35 if (url.scheme() != "filesystem") |
36 return false; | 36 return false; |
37 | 37 |
38 std::string temp = url.path(); | 38 std::string temp = url.path(); |
39 // TODO(ericu) remove this code when that ceases to be true, which will be as | |
40 // soon as the WEBFILESYSTEMCALLBACKS_USE_URL_NOT_STRING macro goes into | |
41 // WebKit. | |
42 // On Windows, this will have backslashes for now. | |
43 // url will look something like: | |
44 // filesystem:http://example.com/temporary/\dir\file.txt | |
45 // temp will look something like: | |
46 // http://example.com/temporary/\dir\file.txt | |
47 // On posix, url will look something like: | |
48 // filesystem:http://example.com/temporary/dir/file.txt | |
49 // temp will look something like: | |
50 // http://example.com/temporary/dir/file.txt | |
51 size_t pos = temp.find('\\'); | |
52 for (; pos != std::string::npos; pos = temp.find('\\', pos + 1)) { | |
53 temp[pos] = '/'; | |
54 } | |
55 // TODO(ericu): This should probably be done elsewhere after the stackable | 39 // TODO(ericu): This should probably be done elsewhere after the stackable |
56 // layers are properly in. We're supposed to reject any paths that contain | 40 // layers are properly in. We're supposed to reject any paths that contain |
57 // '..' segments, but the GURL constructor is helpfully resolving them for us. | 41 // '..' segments, but the GURL constructor is helpfully resolving them for us. |
58 // Make sure there aren't any before we call it. | 42 // Make sure there aren't any before we call it. |
59 pos = temp.find(".."); | 43 size_t pos = temp.find(".."); |
60 for (; pos != std::string::npos; pos = temp.find("..", pos + 1)) { | 44 for (; pos != std::string::npos; pos = temp.find("..", pos + 1)) { |
61 if ((pos == 0 || temp[pos - 1] == '/') && | 45 if ((pos == 0 || temp[pos - 1] == '/') && |
62 (pos == temp.length() - 2 || temp[pos + 2] == '/')) | 46 (pos == temp.length() - 2 || temp[pos + 2] == '/')) |
63 return false; | 47 return false; |
64 } | 48 } |
65 | 49 |
66 // bare_url will look something like: | 50 // bare_url will look something like: |
67 // http://example.com/temporary/dir/file.txt. | 51 // http://example.com/temporary/dir/file.txt. |
68 GURL bare_url(temp); | 52 GURL bare_url(temp); |
69 | 53 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 156 |
173 // We need this work-around for file:/// URIs as | 157 // We need this work-around for file:/// URIs as |
174 // createFromDatabaseIdentifier returns empty origin_url for them. | 158 // createFromDatabaseIdentifier returns empty origin_url for them. |
175 if (origin_url.spec().empty() && | 159 if (origin_url.spec().empty() && |
176 origin_identifier.find("file__") == 0) | 160 origin_identifier.find("file__") == 0) |
177 return GURL("file:///"); | 161 return GURL("file:///"); |
178 return origin_url; | 162 return origin_url; |
179 } | 163 } |
180 | 164 |
181 } // namespace fileapi | 165 } // namespace fileapi |
OLD | NEW |