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

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

Issue 6767010: More filesystem cleanup: convert URL-encoded-as-FilePath to actual URL, where (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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_path_manager.h" 5 #include "webkit/fileapi/file_system_path_manager.h"
6 6
7 #include "base/rand_util.h" 7 #include "base/rand_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_callback_factory.h" 9 #include "base/memory/scoped_callback_factory.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 local_provider_->GetFileSystemRootPathOnFileThread( 93 local_provider_->GetFileSystemRootPathOnFileThread(
94 origin_url, type, virtual_path, create) : 94 origin_url, type, virtual_path, create) :
95 FilePath(); 95 FilePath();
96 case kFileSystemTypeUnknown: 96 case kFileSystemTypeUnknown:
97 default: 97 default:
98 NOTREACHED(); 98 NOTREACHED();
99 return FilePath(); 99 return FilePath();
100 } 100 }
101 } 101 }
102 102
103 bool FileSystemPathManager::CrackFileSystemPath(
104 const FilePath& path, GURL* origin_url, FileSystemType* type,
105 FilePath* virtual_path) const {
106 // TODO(ericu):
107 // Paths come in here [for now] as a URL, followed by a virtual path in
108 // platform format. For example, on Windows, this will look like
109 // filesystem:http://www.example.com/temporary/\path\to\file.txt.
110 // A potentially dangerous malicious path on Windows might look like:
111 // filesystem:http://www.example.com/temporary/foo/../../\path\to\file.txt.
112 // This code is ugly, but will get cleaned up as we fix the calling side.
113 // Eventually there won't be a distinction between a filesystem path and a
114 // filesystem URL--they'll all be URLs.
115 // We should be passing these to WebKit as string, not FilePath, for ease of
116 // manipulation, or possibly as GURL/KURL.
117
118 std::string path_as_string;
119 #ifdef OS_WIN
120 path_as_string = WideToUTF8(path.value());
121 #else
122 path_as_string = path.value();
123 #endif
124 GURL path_as_url(path_as_string);
125
126 FilePath local_path;
127 GURL local_url;
128 FileSystemType local_type;
129 if (!CrackFileSystemURL(path_as_url, &local_url, &local_type, &local_path))
130 return false;
131
132 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
133 // TODO(ericu): This puts the separators back to windows-standard; they come
134 // out of the above code as '/' no matter the platform. Long-term, we'll
135 // want to let the underlying FileSystemFileUtil implementation do this part,
136 // since they won't all need it.
137 local_path = local_path.NormalizeWindowsPathSeparators();
138 #endif
139
140 // Check if file access to this type of file system is allowed
141 // for this origin.
142 switch (local_type) {
143 case kFileSystemTypeTemporary:
144 case kFileSystemTypePersistent:
145 if (!sandbox_provider_->IsAccessAllowed(local_url))
146 return false;
147 break;
148 case kFileSystemTypeLocal:
149 if (!local_provider_.get() ||
150 !local_provider_->IsAccessAllowed(local_url)) {
zel 2011/04/06 21:43:00 where do we do these checks now?
ericu 2011/04/06 23:30:36 Ah, good catch. I've added a new method to FileSy
151 return false;
152 }
153 break;
154 case kFileSystemTypeUnknown:
155 default:
156 NOTREACHED();
157 return false;
158 }
159 // Any paths that include parent references are considered invalid.
160 // These should have been taken care of in CrackFileSystemURL.
161 DCHECK(!local_path.ReferencesParent());
162
163 // The given |local_path| seems valid. Populates the |origin_url|, |type|
164 // and |virtual_path| if they are given.
165
166 if (origin_url) {
167 *origin_url = local_url;
168 }
169
170 if (type)
171 *type = local_type;
172
173 if (virtual_path) {
174 *virtual_path = local_path;
175 }
176
177 return true;
178 }
179
180 bool FileSystemPathManager::IsAllowedScheme(const GURL& url) const { 103 bool FileSystemPathManager::IsAllowedScheme(const GURL& url) const {
181 // Basically we only accept http or https. We allow file:// URLs 104 // Basically we only accept http or https. We allow file:// URLs
182 // only if --allow-file-access-from-files flag is given. 105 // only if --allow-file-access-from-files flag is given.
183 return url.SchemeIs("http") || url.SchemeIs("https") || 106 return url.SchemeIs("http") || url.SchemeIs("https") ||
184 url.SchemeIs(kExtensionScheme) || 107 url.SchemeIs(kExtensionScheme) ||
185 (url.SchemeIsFile() && allow_file_access_from_files_); 108 (url.SchemeIsFile() && allow_file_access_from_files_);
186 } 109 }
187 110
188 // static 111 // static
189 std::string FileSystemPathManager::GetFileSystemTypeString( 112 std::string FileSystemPathManager::GetFileSystemTypeString(
(...skipping 21 matching lines...) Expand all
211 return true; 134 return true;
212 } 135 }
213 } 136 }
214 137
215 } // namespace fileapi 138 } // namespace fileapi
216 139
217 COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \ 140 COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \
218 int(fileapi::kFileSystemTypeTemporary), mismatching_enums); 141 int(fileapi::kFileSystemTypeTemporary), mismatching_enums);
219 COMPILE_ASSERT(int(WebFileSystem::TypePersistent) == \ 142 COMPILE_ASSERT(int(WebFileSystem::TypePersistent) == \
220 int(fileapi::kFileSystemTypePersistent), mismatching_enums); 143 int(fileapi::kFileSystemTypePersistent), mismatching_enums);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698