Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: webkit/fileapi/file_system_util.cc

Issue 6904063: String->URL cleanup, chromium-side. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rolled in code review feedback. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 35 // TODO(ericu) remove this code when that ceases to be true, which will be as
36 // soon. 36 // soon as the WEBFILESYSTEMCALLBACKS_USE_URL_NOT_STRING macro goes into
37 // WebKit.
37 // On Windows, this will have backslashes for now. 38 // On Windows, this will have backslashes for now.
38 // url will look something like: 39 // url will look something like:
39 // filesystem:http://example.com/temporary/\dir\file.txt 40 // filesystem:http://example.com/temporary/\dir\file.txt
40 // temp will look something like: 41 // temp will look something like:
41 // http://example.com/temporary/\dir\file.txt 42 // http://example.com/temporary/\dir\file.txt
42 // On posix, url will look something like: 43 // On posix, url will look something like:
43 // filesystem:http://example.com/temporary/dir/file.txt 44 // filesystem:http://example.com/temporary/dir/file.txt
44 // temp will look something like: 45 // temp will look something like:
45 // http://example.com/temporary/dir/file.txt 46 // http://example.com/temporary/dir/file.txt
46 size_t pos = temp.find('\\'); 47 size_t pos = temp.find('\\');
47 for (; pos != std::string::npos; pos = temp.find('\\', pos + 1)) { 48 for (; pos != std::string::npos; pos = temp.find('\\', pos + 1)) {
48 temp[pos] = '/'; 49 temp[pos] = '/';
49 } 50 }
50 // TODO(ericu): This should probably be done elsewhere after the stackable 51 // 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 // 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 // '..' segments, but the GURL constructor is helpfully resolving them for us.
53 // Make sure there aren't any before we call it. 54 // Make sure there aren't any before we call it.
54 pos = temp.find(".."); 55 pos = temp.find("..");
55 for (; pos != std::string::npos; pos = temp.find("..", pos + 1)) { 56 for (; pos != std::string::npos; pos = temp.find("..", pos + 1)) {
56 if ((pos == 0 || temp[pos - 1] == '/') && 57 if ((pos == 0 || temp[pos - 1] == '/') &&
57 (pos == temp.length() - 2 || temp[pos + 2] == '/')) 58 (pos == temp.length() - 2 || temp[pos + 2] == '/'))
58 return false; 59 return false;
59 } 60 }
60 61
61 // bare_url will look something like: 62 // bare_url will look something like:
62 // http://example.com/temporary//dir/file.txt [on Windows; the double slash 63 // http://example.com/temporary/dir/file.txt.
63 // before dir will be single on posix].
64 GURL bare_url(temp); 64 GURL bare_url(temp);
65 65
66 // The input URL was malformed, bail out early. 66 // The input URL was malformed, bail out early.
67 if (bare_url.path().empty()) 67 if (bare_url.path().empty())
68 return false; 68 return false;
69 69
70 origin = bare_url.GetOrigin(); 70 origin = bare_url.GetOrigin();
71 71
72 // The input URL was malformed, bail out early. 72 // The input URL was malformed, bail out early.
73 if (origin.is_empty()) 73 if (origin.is_empty())
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 case kFileSystemTypeTemporary: 145 case kFileSystemTypeTemporary:
146 return quota::kStorageTypeTemporary; 146 return quota::kStorageTypeTemporary;
147 case kFileSystemTypePersistent: 147 case kFileSystemTypePersistent:
148 return quota::kStorageTypePersistent; 148 return quota::kStorageTypePersistent;
149 default: 149 default:
150 return quota::kStorageTypeUnknown; 150 return quota::kStorageTypeUnknown;
151 } 151 }
152 } 152 }
153 153
154 } // namespace fileapi 154 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698