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

Side by Side Diff: net/url_request/url_request_file_job.cc

Issue 10068021: Fix file access on Chrome for ChromeOS on Linux (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed clang problem Created 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // For loading files, we make use of overlapped i/o to ensure that reading from 5 // For loading files, we make use of overlapped i/o to ensure that reading from
6 // the filesystem (e.g., a network filesystem) does not block the calling 6 // the filesystem (e.g., a network filesystem) does not block the calling
7 // thread. An alternative approach would be to use a background thread or pool 7 // thread. An alternative approach would be to use a background thread or pool
8 // of threads, but it seems better to leverage the operating system's ability 8 // of threads, but it seems better to leverage the operating system's ability
9 // to do background file reads for us. 9 // to do background file reads for us.
10 // 10 //
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 : URLRequestJob(request), 87 : URLRequestJob(request),
88 file_path_(file_path), 88 file_path_(file_path),
89 stream_(NULL), 89 stream_(NULL),
90 is_directory_(false), 90 is_directory_(false),
91 remaining_bytes_(0) { 91 remaining_bytes_(0) {
92 } 92 }
93 93
94 // static 94 // static
95 URLRequestJob* URLRequestFileJob::Factory(URLRequest* request, 95 URLRequestJob* URLRequestFileJob::Factory(URLRequest* request,
96 const std::string& scheme) { 96 const std::string& scheme) {
97
98 FilePath file_path; 97 FilePath file_path;
99 const bool is_file = FileURLToFilePath(request->url(), &file_path); 98 const bool is_file = FileURLToFilePath(request->url(), &file_path);
100 99
101 #if defined(OS_CHROMEOS) 100 // Check file access permissions.
102 // Check file access. 101 if (!request->IsFileAccessAllowed(file_path))
103 if (AccessDisabled(file_path))
104 return new URLRequestErrorJob(request, ERR_ACCESS_DENIED); 102 return new URLRequestErrorJob(request, ERR_ACCESS_DENIED);
105 #endif
106 103
107 // We need to decide whether to create URLRequestFileJob for file access or 104 // We need to decide whether to create URLRequestFileJob for file access or
108 // URLRequestFileDirJob for directory access. To avoid accessing the 105 // URLRequestFileDirJob for directory access. To avoid accessing the
109 // filesystem, we only look at the path string here. 106 // filesystem, we only look at the path string here.
110 // The code in the URLRequestFileJob::Start() method discovers that a path, 107 // The code in the URLRequestFileJob::Start() method discovers that a path,
111 // which doesn't end with a slash, should really be treated as a directory, 108 // which doesn't end with a slash, should really be treated as a directory,
112 // and it then redirects to the URLRequestFileDirJob. 109 // and it then redirects to the URLRequestFileDirJob.
113 if (is_file && 110 if (is_file &&
114 file_util::EndsWithSeparator(file_path) && 111 file_util::EndsWithSeparator(file_path) &&
115 file_path.IsAbsolute()) 112 file_path.IsAbsolute())
116 return new URLRequestFileDirJob(request, file_path); 113 return new URLRequestFileDirJob(request, file_path);
117 114
118 // Use a regular file request job for all non-directories (including invalid 115 // Use a regular file request job for all non-directories (including invalid
119 // file names). 116 // file names).
120 return new URLRequestFileJob(request, file_path); 117 return new URLRequestFileJob(request, file_path);
121 } 118 }
122 119
123 #if defined(OS_CHROMEOS)
124 static const char* const kLocalAccessWhiteList[] = {
125 "/home/chronos/user/Downloads",
126 "/home/chronos/user/log",
127 "/media",
128 "/opt/oem",
129 "/usr/share/chromeos-assets",
130 "/tmp",
131 "/var/log",
132 };
133
134 // static
135 bool URLRequestFileJob::AccessDisabled(const FilePath& file_path) {
136 if (URLRequest::IsFileAccessAllowed()) { // for tests.
137 return false;
138 }
139
140 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
141 const FilePath white_listed_path(kLocalAccessWhiteList[i]);
142 // FilePath::operator== should probably handle trailing seperators.
143 if (white_listed_path == file_path.StripTrailingSeparators() ||
144 white_listed_path.IsParent(file_path)) {
145 return false;
146 }
147 }
148 return true;
149 }
150 #endif // OS_CHROMEOS
151
152 void URLRequestFileJob::Start() { 120 void URLRequestFileJob::Start() {
153 DCHECK(!async_resolver_); 121 DCHECK(!async_resolver_);
154 async_resolver_ = new AsyncResolver(this); 122 async_resolver_ = new AsyncResolver(this);
155 base::WorkerPool::PostTask( 123 base::WorkerPool::PostTask(
156 FROM_HERE, 124 FROM_HERE,
157 base::Bind(&AsyncResolver::Resolve, async_resolver_.get(), file_path_), 125 base::Bind(&AsyncResolver::Resolve, async_resolver_.get(), file_path_),
158 true); 126 true);
159 } 127 }
160 128
161 void URLRequestFileJob::Kill() { 129 void URLRequestFileJob::Kill() {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); 328 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result));
361 } 329 }
362 330
363 remaining_bytes_ -= result; 331 remaining_bytes_ -= result;
364 DCHECK_GE(remaining_bytes_, 0); 332 DCHECK_GE(remaining_bytes_, 0);
365 333
366 NotifyReadComplete(result); 334 NotifyReadComplete(result);
367 } 335 }
368 336
369 } // namespace net 337 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698