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 14 matching lines...) Expand all Loading... |
25 | 25 |
26 bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, | 26 bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, |
27 FilePath* file_path) { | 27 FilePath* file_path) { |
28 GURL origin; | 28 GURL origin; |
29 FileSystemType file_system_type; | 29 FileSystemType file_system_type; |
30 | 30 |
31 if (url.scheme() != "filesystem") | 31 if (url.scheme() != "filesystem") |
32 return false; | 32 return false; |
33 | 33 |
34 std::string temp = url.path(); | 34 std::string temp = url.path(); |
35 // TODO(ericu) remove this code when that ceases to be true, which should be | |
36 // soon. | |
37 // On Windows, this will have backslashes for now. | |
38 // url will look something like: | |
39 // filesystem:http://example.com/temporary/\dir\file.txt | |
40 // temp will look something like: | |
41 // http://example.com/temporary/\dir\file.txt | |
42 // On posix, url will look something like: | |
43 // filesystem:http://example.com/temporary/dir/file.txt | |
44 // temp will look something like: | |
45 // http://example.com/temporary/dir/file.txt | |
46 size_t pos = temp.find('\\'); | |
47 for (; pos != std::string::npos; pos = temp.find('\\', pos + 1)) { | |
48 temp[pos] = '/'; | |
49 } | |
50 // TODO(ericu): This should probably be done elsewhere after the stackable | |
51 // layers are properly in. We're supposed to reject any paths that contain | |
52 // '..' segments, but the GURL constructor is helpfully resolving them for us. | |
53 // Make sure there aren't any before we call it. | |
54 pos = temp.find(".."); | |
55 for (; pos != std::string::npos; pos = temp.find("..", pos + 1)) { | |
56 if ((pos == 0 || temp[pos - 1] == '/') && | |
57 (pos == temp.length() - 2 || temp[pos + 2] == '/')) | |
58 return false; | |
59 } | |
60 | 35 |
61 // bare_url will look something like: | 36 // bare_url will look something like: |
62 // http://example.com/temporary//dir/file.txt [on Windows; the double slash | 37 // http://example.com/temporary/dir/file.txt. |
63 // before dir will be single on posix]. | |
64 GURL bare_url(temp); | 38 GURL bare_url(temp); |
65 | 39 |
66 // The input URL was malformed, bail out early. | 40 // The input URL was malformed, bail out early. |
67 if (bare_url.path().empty()) | 41 if (bare_url.path().empty()) |
68 return false; | 42 return false; |
69 | 43 |
70 origin = bare_url.GetOrigin(); | 44 origin = bare_url.GetOrigin(); |
71 | 45 |
72 // The input URL was malformed, bail out early. | 46 // The input URL was malformed, bail out early. |
73 if (origin.is_empty()) | 47 if (origin.is_empty()) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 path += (kExternalDir + 1); // We don't want the leading slash. | 96 path += (kExternalDir + 1); // We don't want the leading slash. |
123 break; | 97 break; |
124 default: | 98 default: |
125 NOTREACHED(); | 99 NOTREACHED(); |
126 return GURL(); | 100 return GURL(); |
127 } | 101 } |
128 return GURL(path); | 102 return GURL(path); |
129 } | 103 } |
130 | 104 |
131 } // namespace fileapi | 105 } // namespace fileapi |
OLD | NEW |