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

Side by Side Diff: content/browser/renderer_host/pepper/pepper_flash_file_message_filter.cc

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 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 #include "content/browser/renderer_host/pepper/pepper_flash_file_message_filter. h" 5 #include "content/browser/renderer_host/pepper/pepper_flash_file_message_filter. h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_enumerator.h" 9 #include "base/files/file_enumerator.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 107
108 int32_t PepperFlashFileMessageFilter::OnOpenFile( 108 int32_t PepperFlashFileMessageFilter::OnOpenFile(
109 ppapi::host::HostMessageContext* context, 109 ppapi::host::HostMessageContext* context,
110 const ppapi::PepperFilePath& path, 110 const ppapi::PepperFilePath& path,
111 int pp_open_flags) { 111 int pp_open_flags) {
112 base::FilePath full_path = ValidateAndConvertPepperFilePath( 112 base::FilePath full_path = ValidateAndConvertPepperFilePath(
113 path, 113 path,
114 base::Bind(&CanOpenWithPepperFlags, pp_open_flags)); 114 base::Bind(&CanOpenWithPepperFlags, pp_open_flags));
115 if (full_path.empty()) { 115 if (full_path.empty()) {
116 return ppapi::PlatformFileErrorToPepperError( 116 return ppapi::FileErrorToPepperError(
117 base::PLATFORM_FILE_ERROR_ACCESS_DENIED); 117 base::File::FILE_ERROR_ACCESS_DENIED);
118 } 118 }
119 119
120 int platform_file_flags = 0; 120 int platform_file_flags = 0;
121 if (!ppapi::PepperFileOpenFlagsToPlatformFileFlags( 121 if (!ppapi::PepperFileOpenFlagsToPlatformFileFlags(
122 pp_open_flags, &platform_file_flags)) { 122 pp_open_flags, &platform_file_flags)) {
123 return base::PLATFORM_FILE_ERROR_FAILED; 123 return base::File::FILE_ERROR_FAILED;
124 } 124 }
125 125
126 // TODO(rvargas): Convert this code to base::File.
126 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 127 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED;
127 base::PlatformFile file_handle = base::CreatePlatformFile( 128 base::PlatformFile file_handle = base::CreatePlatformFile(
128 full_path, platform_file_flags, NULL, &error); 129 full_path, platform_file_flags, NULL, &error);
129 if (error != base::PLATFORM_FILE_OK) { 130 if (error != base::PLATFORM_FILE_OK) {
130 DCHECK_EQ(file_handle, base::kInvalidPlatformFileValue); 131 DCHECK_EQ(file_handle, base::kInvalidPlatformFileValue);
131 return ppapi::PlatformFileErrorToPepperError(error); 132 return ppapi::FileErrorToPepperError(static_cast<base::File::Error>(error));
132 } 133 }
133 134
134 // Make sure we didn't try to open a directory: directory fd shouldn't be 135 // Make sure we didn't try to open a directory: directory fd shouldn't be
135 // passed to untrusted processes because they open security holes. 136 // passed to untrusted processes because they open security holes.
136 base::PlatformFileInfo info; 137 base::PlatformFileInfo info;
137 if (!base::GetPlatformFileInfo(file_handle, &info) || info.is_directory) { 138 if (!base::GetPlatformFileInfo(file_handle, &info) || info.is_directory) {
138 // When in doubt, throw it out. 139 // When in doubt, throw it out.
139 base::ClosePlatformFile(file_handle); 140 base::ClosePlatformFile(file_handle);
140 return ppapi::PlatformFileErrorToPepperError( 141 return ppapi::FileErrorToPepperError(
141 base::PLATFORM_FILE_ERROR_ACCESS_DENIED); 142 base::File::FILE_ERROR_ACCESS_DENIED);
142 } 143 }
143 144
144 IPC::PlatformFileForTransit file = IPC::GetFileHandleForProcess(file_handle, 145 IPC::PlatformFileForTransit file = IPC::GetFileHandleForProcess(file_handle,
145 plugin_process_handle_, true); 146 plugin_process_handle_, true);
146 ppapi::host::ReplyMessageContext reply_context = 147 ppapi::host::ReplyMessageContext reply_context =
147 context->MakeReplyMessageContext(); 148 context->MakeReplyMessageContext();
148 reply_context.params.AppendHandle(ppapi::proxy::SerializedHandle( 149 reply_context.params.AppendHandle(ppapi::proxy::SerializedHandle(
149 ppapi::proxy::SerializedHandle::FILE, file)); 150 ppapi::proxy::SerializedHandle::FILE, file));
150 SendReply(reply_context, IPC::Message()); 151 SendReply(reply_context, IPC::Message());
151 return PP_OK_COMPLETIONPENDING; 152 return PP_OK_COMPLETIONPENDING;
152 } 153 }
153 154
154 int32_t PepperFlashFileMessageFilter::OnRenameFile( 155 int32_t PepperFlashFileMessageFilter::OnRenameFile(
155 ppapi::host::HostMessageContext* context, 156 ppapi::host::HostMessageContext* context,
156 const ppapi::PepperFilePath& from_path, 157 const ppapi::PepperFilePath& from_path,
157 const ppapi::PepperFilePath& to_path) { 158 const ppapi::PepperFilePath& to_path) {
158 base::FilePath from_full_path = ValidateAndConvertPepperFilePath( 159 base::FilePath from_full_path = ValidateAndConvertPepperFilePath(
159 from_path, base::Bind(&CanCreateReadWrite)); 160 from_path, base::Bind(&CanCreateReadWrite));
160 base::FilePath to_full_path = ValidateAndConvertPepperFilePath( 161 base::FilePath to_full_path = ValidateAndConvertPepperFilePath(
161 to_path, base::Bind(&CanCreateReadWrite)); 162 to_path, base::Bind(&CanCreateReadWrite));
162 if (from_full_path.empty() || to_full_path.empty()) { 163 if (from_full_path.empty() || to_full_path.empty()) {
163 return ppapi::PlatformFileErrorToPepperError( 164 return ppapi::FileErrorToPepperError(
164 base::PLATFORM_FILE_ERROR_ACCESS_DENIED); 165 base::File::FILE_ERROR_ACCESS_DENIED);
165 } 166 }
166 167
167 bool result = base::Move(from_full_path, to_full_path); 168 bool result = base::Move(from_full_path, to_full_path);
168 return ppapi::PlatformFileErrorToPepperError(result ? 169 return ppapi::FileErrorToPepperError(result ?
169 base::PLATFORM_FILE_OK : base::PLATFORM_FILE_ERROR_ACCESS_DENIED); 170 base::File::FILE_OK : base::File::FILE_ERROR_ACCESS_DENIED);
170 } 171 }
171 172
172 int32_t PepperFlashFileMessageFilter::OnDeleteFileOrDir( 173 int32_t PepperFlashFileMessageFilter::OnDeleteFileOrDir(
173 ppapi::host::HostMessageContext* context, 174 ppapi::host::HostMessageContext* context,
174 const ppapi::PepperFilePath& path, 175 const ppapi::PepperFilePath& path,
175 bool recursive) { 176 bool recursive) {
176 base::FilePath full_path = ValidateAndConvertPepperFilePath( 177 base::FilePath full_path = ValidateAndConvertPepperFilePath(
177 path, base::Bind(&CanCreateReadWrite)); 178 path, base::Bind(&CanCreateReadWrite));
178 if (full_path.empty()) { 179 if (full_path.empty()) {
179 return ppapi::PlatformFileErrorToPepperError( 180 return ppapi::FileErrorToPepperError(
180 base::PLATFORM_FILE_ERROR_ACCESS_DENIED); 181 base::File::FILE_ERROR_ACCESS_DENIED);
181 } 182 }
182 183
183 bool result = base::DeleteFile(full_path, recursive); 184 bool result = base::DeleteFile(full_path, recursive);
184 return ppapi::PlatformFileErrorToPepperError(result ? 185 return ppapi::FileErrorToPepperError(result ?
185 base::PLATFORM_FILE_OK : base::PLATFORM_FILE_ERROR_ACCESS_DENIED); 186 base::File::FILE_OK : base::File::FILE_ERROR_ACCESS_DENIED);
186 } 187 }
187 int32_t PepperFlashFileMessageFilter::OnCreateDir( 188 int32_t PepperFlashFileMessageFilter::OnCreateDir(
188 ppapi::host::HostMessageContext* context, 189 ppapi::host::HostMessageContext* context,
189 const ppapi::PepperFilePath& path) { 190 const ppapi::PepperFilePath& path) {
190 base::FilePath full_path = ValidateAndConvertPepperFilePath( 191 base::FilePath full_path = ValidateAndConvertPepperFilePath(
191 path, base::Bind(&CanCreateReadWrite)); 192 path, base::Bind(&CanCreateReadWrite));
192 if (full_path.empty()) { 193 if (full_path.empty()) {
193 return ppapi::PlatformFileErrorToPepperError( 194 return ppapi::FileErrorToPepperError(
194 base::PLATFORM_FILE_ERROR_ACCESS_DENIED); 195 base::File::FILE_ERROR_ACCESS_DENIED);
195 } 196 }
196 197
197 bool result = base::CreateDirectory(full_path); 198 bool result = base::CreateDirectory(full_path);
198 return ppapi::PlatformFileErrorToPepperError(result ? 199 return ppapi::FileErrorToPepperError(result ?
199 base::PLATFORM_FILE_OK : base::PLATFORM_FILE_ERROR_ACCESS_DENIED); 200 base::File::FILE_OK : base::File::FILE_ERROR_ACCESS_DENIED);
200 } 201 }
201 202
202 int32_t PepperFlashFileMessageFilter::OnQueryFile( 203 int32_t PepperFlashFileMessageFilter::OnQueryFile(
203 ppapi::host::HostMessageContext* context, 204 ppapi::host::HostMessageContext* context,
204 const ppapi::PepperFilePath& path) { 205 const ppapi::PepperFilePath& path) {
205 base::FilePath full_path = ValidateAndConvertPepperFilePath( 206 base::FilePath full_path = ValidateAndConvertPepperFilePath(
206 path, base::Bind(&CanRead)); 207 path, base::Bind(&CanRead));
207 if (full_path.empty()) { 208 if (full_path.empty()) {
208 return ppapi::PlatformFileErrorToPepperError( 209 return ppapi::FileErrorToPepperError(
209 base::PLATFORM_FILE_ERROR_ACCESS_DENIED); 210 base::File::FILE_ERROR_ACCESS_DENIED);
210 } 211 }
211 212
212 // TODO(rvargas): convert this code to use base::File::Info. 213 base::File::Info info;
213 base::PlatformFileInfo info; 214 bool result = base::GetFileInfo(full_path, &info);
214 bool result = base::GetFileInfo(full_path,
215 reinterpret_cast<base::File::Info*>(&info));
216 context->reply_msg = PpapiPluginMsg_FlashFile_QueryFileReply(info); 215 context->reply_msg = PpapiPluginMsg_FlashFile_QueryFileReply(info);
217 return ppapi::PlatformFileErrorToPepperError(result ? 216 return ppapi::FileErrorToPepperError(result ?
218 base::PLATFORM_FILE_OK : base::PLATFORM_FILE_ERROR_ACCESS_DENIED); 217 base::File::FILE_OK : base::File::FILE_ERROR_ACCESS_DENIED);
219 } 218 }
220 219
221 int32_t PepperFlashFileMessageFilter::OnGetDirContents( 220 int32_t PepperFlashFileMessageFilter::OnGetDirContents(
222 ppapi::host::HostMessageContext* context, 221 ppapi::host::HostMessageContext* context,
223 const ppapi::PepperFilePath& path) { 222 const ppapi::PepperFilePath& path) {
224 base::FilePath full_path = ValidateAndConvertPepperFilePath( 223 base::FilePath full_path = ValidateAndConvertPepperFilePath(
225 path, base::Bind(&CanRead)); 224 path, base::Bind(&CanRead));
226 if (full_path.empty()) { 225 if (full_path.empty()) {
227 return ppapi::PlatformFileErrorToPepperError( 226 return ppapi::FileErrorToPepperError(
228 base::PLATFORM_FILE_ERROR_ACCESS_DENIED); 227 base::File::FILE_ERROR_ACCESS_DENIED);
229 } 228 }
230 229
231 ppapi::DirContents contents; 230 ppapi::DirContents contents;
232 base::FileEnumerator enumerator(full_path, false, 231 base::FileEnumerator enumerator(full_path, false,
233 base::FileEnumerator::FILES | 232 base::FileEnumerator::FILES |
234 base::FileEnumerator::DIRECTORIES | 233 base::FileEnumerator::DIRECTORIES |
235 base::FileEnumerator::INCLUDE_DOT_DOT); 234 base::FileEnumerator::INCLUDE_DOT_DOT);
236 235
237 while (!enumerator.Next().empty()) { 236 while (!enumerator.Next().empty()) {
238 base::FileEnumerator::FileInfo info = enumerator.GetInfo(); 237 base::FileEnumerator::FileInfo info = enumerator.GetInfo();
(...skipping 10 matching lines...) Expand all
249 248
250 int32_t PepperFlashFileMessageFilter::OnCreateTemporaryFile( 249 int32_t PepperFlashFileMessageFilter::OnCreateTemporaryFile(
251 ppapi::host::HostMessageContext* context) { 250 ppapi::host::HostMessageContext* context) {
252 ppapi::PepperFilePath dir_path( 251 ppapi::PepperFilePath dir_path(
253 ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, base::FilePath()); 252 ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, base::FilePath());
254 base::FilePath validated_dir_path = ValidateAndConvertPepperFilePath( 253 base::FilePath validated_dir_path = ValidateAndConvertPepperFilePath(
255 dir_path, base::Bind(&CanCreateReadWrite)); 254 dir_path, base::Bind(&CanCreateReadWrite));
256 if (validated_dir_path.empty() || 255 if (validated_dir_path.empty() ||
257 (!base::DirectoryExists(validated_dir_path) && 256 (!base::DirectoryExists(validated_dir_path) &&
258 !base::CreateDirectory(validated_dir_path))) { 257 !base::CreateDirectory(validated_dir_path))) {
259 return ppapi::PlatformFileErrorToPepperError( 258 return ppapi::FileErrorToPepperError(
260 base::PLATFORM_FILE_ERROR_ACCESS_DENIED); 259 base::File::FILE_ERROR_ACCESS_DENIED);
261 } 260 }
262 261
263 base::FilePath file_path; 262 base::FilePath file_path;
264 if (!base::CreateTemporaryFileInDir(validated_dir_path, &file_path)) { 263 if (!base::CreateTemporaryFileInDir(validated_dir_path, &file_path)) {
265 return ppapi::PlatformFileErrorToPepperError( 264 return ppapi::FileErrorToPepperError(
266 base::PLATFORM_FILE_ERROR_FAILED); 265 base::File::FILE_ERROR_FAILED);
267 } 266 }
268 267
268 // TODO(rvargas): Convert this code to base::File.
269 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 269 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED;
270 base::PlatformFile file_handle = base::CreatePlatformFile( 270 base::PlatformFile file_handle = base::CreatePlatformFile(
271 file_path, 271 file_path,
272 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_READ | 272 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_READ |
273 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_TEMPORARY | 273 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_TEMPORARY |
274 base::PLATFORM_FILE_DELETE_ON_CLOSE, 274 base::PLATFORM_FILE_DELETE_ON_CLOSE, NULL, &error);
275 NULL, &error);
276 275
277 if (error != base::PLATFORM_FILE_OK) { 276 if (error != base::PLATFORM_FILE_OK) {
278 DCHECK_EQ(file_handle, base::kInvalidPlatformFileValue); 277 DCHECK_EQ(file_handle, base::kInvalidPlatformFileValue);
279 return ppapi::PlatformFileErrorToPepperError(error); 278 return ppapi::FileErrorToPepperError(static_cast<base::File::Error>(error));
280 } 279 }
281 280
282 IPC::PlatformFileForTransit file = IPC::GetFileHandleForProcess(file_handle, 281 IPC::PlatformFileForTransit file = IPC::GetFileHandleForProcess(file_handle,
283 plugin_process_handle_, true); 282 plugin_process_handle_, true);
284 ppapi::host::ReplyMessageContext reply_context = 283 ppapi::host::ReplyMessageContext reply_context =
285 context->MakeReplyMessageContext(); 284 context->MakeReplyMessageContext();
286 reply_context.params.AppendHandle(ppapi::proxy::SerializedHandle( 285 reply_context.params.AppendHandle(ppapi::proxy::SerializedHandle(
287 ppapi::proxy::SerializedHandle::FILE, file)); 286 ppapi::proxy::SerializedHandle::FILE, file));
288 SendReply(reply_context, IPC::Message()); 287 SendReply(reply_context, IPC::Message());
289 return PP_OK_COMPLETIONPENDING; 288 return PP_OK_COMPLETIONPENDING;
(...skipping 19 matching lines...) Expand all
309 file_path = plugin_data_directory_.Append(pepper_path.path()); 308 file_path = plugin_data_directory_.Append(pepper_path.path());
310 break; 309 break;
311 default: 310 default:
312 NOTREACHED(); 311 NOTREACHED();
313 break; 312 break;
314 } 313 }
315 return file_path; 314 return file_path;
316 } 315 }
317 316
318 } // namespace content 317 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698