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

Side by Side Diff: webkit/plugins/ppapi/ppb_flash_file_impl.cc

Issue 7038032: Fix PP_FileOpenFlags_Dev handling: (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: . 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
« no previous file with comments | « webkit/plugins/ppapi/ppb_file_io_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/plugins/ppapi/ppb_flash_file_impl.h" 5 #include "webkit/plugins/ppapi/ppb_flash_file_impl.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "ppapi/c/dev/pp_file_info_dev.h" 11 #include "ppapi/c/dev/pp_file_info_dev.h"
12 #include "ppapi/c/dev/ppb_file_io_dev.h" 12 #include "ppapi/c/dev/ppb_file_io_dev.h"
13 #include "ppapi/c/private/ppb_flash_file.h" 13 #include "ppapi/c/private/ppb_flash_file.h"
14 #include "webkit/plugins/ppapi/common.h" 14 #include "webkit/plugins/ppapi/common.h"
15 #include "webkit/plugins/ppapi/error_util.h"
16 #include "webkit/plugins/ppapi/file_path.h" 15 #include "webkit/plugins/ppapi/file_path.h"
16 #include "webkit/plugins/ppapi/file_type_conversions.h"
17 #include "webkit/plugins/ppapi/plugin_delegate.h" 17 #include "webkit/plugins/ppapi/plugin_delegate.h"
18 #include "webkit/plugins/ppapi/plugin_module.h" 18 #include "webkit/plugins/ppapi/plugin_module.h"
19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
20 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" 20 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
21 #include "webkit/plugins/ppapi/resource_tracker.h" 21 #include "webkit/plugins/ppapi/resource_tracker.h"
22 22
23 #if defined(OS_WIN) 23 #if defined(OS_WIN)
24 #include "base/utf_string_conversions.h" 24 #include "base/utf_string_conversions.h"
25 #endif 25 #endif
26 26
27 namespace webkit { 27 namespace webkit {
28 namespace ppapi { 28 namespace ppapi {
29 29
30 namespace { 30 namespace {
31 31
32 // TODO(viettrungluu): The code below is duplicated in ppb_file_io_impl.cc
33 // (where it's incorrect to boot).
34 // Returns |true| if okay.
35 bool ConvertFromPPFileOpenFlags(int32_t pp_open_flags, int* flags_out) {
36 int flags = 0;
37 if (pp_open_flags & PP_FILEOPENFLAG_READ)
38 flags |= base::PLATFORM_FILE_READ;
39 if (pp_open_flags & PP_FILEOPENFLAG_WRITE) {
40 flags |= base::PLATFORM_FILE_WRITE;
41 flags |= base::PLATFORM_FILE_WRITE_ATTRIBUTES;
42 }
43 if (pp_open_flags & PP_FILEOPENFLAG_TRUNCATE) {
44 if (!(pp_open_flags & PP_FILEOPENFLAG_WRITE))
45 return false;
46 flags |= base::PLATFORM_FILE_TRUNCATE;
47 }
48 if (pp_open_flags & PP_FILEOPENFLAG_CREATE) {
49 if (pp_open_flags & PP_FILEOPENFLAG_EXCLUSIVE)
50 flags |= base::PLATFORM_FILE_CREATE;
51 else
52 flags |= base::PLATFORM_FILE_OPEN_ALWAYS;
53 } else {
54 flags |= base::PLATFORM_FILE_OPEN;
55 }
56 *flags_out = flags;
57 return true;
58 }
59
60 void FreeDirContents(PP_Instance instance, PP_DirContents_Dev* contents) { 32 void FreeDirContents(PP_Instance instance, PP_DirContents_Dev* contents) {
61 DCHECK(contents); 33 DCHECK(contents);
62 for (int32_t i = 0; i < contents->count; ++i) { 34 for (int32_t i = 0; i < contents->count; ++i) {
63 delete [] contents->entries[i].name; 35 delete [] contents->entries[i].name;
64 } 36 }
65 delete [] contents->entries; 37 delete [] contents->entries;
66 delete contents; 38 delete contents;
67 } 39 }
68 40
69 } // namespace 41 } // namespace
70 42
71 // PPB_Flash_File_ModuleLocal_Impl --------------------------------------------- 43 // PPB_Flash_File_ModuleLocal_Impl ---------------------------------------------
72 44
73 namespace { 45 namespace {
74 46
75 bool CreateThreadAdapterForInstance(PP_Instance instance) { 47 bool CreateThreadAdapterForInstance(PP_Instance instance) {
76 return false; // No multithreaded access allowed. 48 return false; // No multithreaded access allowed.
77 } 49 }
78 50
79 void ClearThreadAdapterForInstance(PP_Instance instance) { 51 void ClearThreadAdapterForInstance(PP_Instance instance) {
80 } 52 }
81 53
82 int32_t OpenModuleLocalFile(PP_Instance pp_instance, 54 int32_t OpenModuleLocalFile(PP_Instance pp_instance,
83 const char* path, 55 const char* path,
84 int32_t mode, 56 int32_t mode,
85 PP_FileHandle* file) { 57 PP_FileHandle* file) {
86 int flags = 0; 58 int flags = 0;
87 if (!path || !ConvertFromPPFileOpenFlags(mode, &flags) || !file) 59 if (!path || !PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || !file)
88 return PP_ERROR_BADARGUMENT; 60 return PP_ERROR_BADARGUMENT;
89 61
90 PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); 62 PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance);
91 if (!instance) 63 if (!instance)
92 return PP_ERROR_FAILED; 64 return PP_ERROR_FAILED;
93 65
94 base::PlatformFile base_file; 66 base::PlatformFile base_file;
95 base::PlatformFileError result = instance->delegate()->OpenFile( 67 base::PlatformFileError result = instance->delegate()->OpenFile(
96 PepperFilePath::MakeModuleLocal(instance->module(), path), 68 PepperFilePath::MakeModuleLocal(instance->module(), path),
97 flags, 69 flags,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 204 }
233 205
234 // PPB_Flash_File_FileRef_Impl ------------------------------------------------- 206 // PPB_Flash_File_FileRef_Impl -------------------------------------------------
235 207
236 namespace { 208 namespace {
237 209
238 int32_t OpenFileRefFile(PP_Resource file_ref_id, 210 int32_t OpenFileRefFile(PP_Resource file_ref_id,
239 int32_t mode, 211 int32_t mode,
240 PP_FileHandle* file) { 212 PP_FileHandle* file) {
241 int flags = 0; 213 int flags = 0;
242 if (!ConvertFromPPFileOpenFlags(mode, &flags) || !file) 214 if (!PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || !file)
243 return PP_ERROR_BADARGUMENT; 215 return PP_ERROR_BADARGUMENT;
244 216
245 scoped_refptr<PPB_FileRef_Impl> file_ref( 217 scoped_refptr<PPB_FileRef_Impl> file_ref(
246 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); 218 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id));
247 if (!file_ref) 219 if (!file_ref)
248 return PP_ERROR_BADRESOURCE; 220 return PP_ERROR_BADRESOURCE;
249 221
250 PluginInstance* instance = file_ref->instance(); 222 PluginInstance* instance = file_ref->instance();
251 if (!instance) 223 if (!instance)
252 return PP_ERROR_FAILED; 224 return PP_ERROR_FAILED;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 268
297 } // namespace 269 } // namespace
298 270
299 // static 271 // static
300 const PPB_Flash_File_FileRef* PPB_Flash_File_FileRef_Impl::GetInterface() { 272 const PPB_Flash_File_FileRef* PPB_Flash_File_FileRef_Impl::GetInterface() {
301 return &ppb_flash_file_fileref; 273 return &ppb_flash_file_fileref;
302 } 274 }
303 275
304 } // namespace ppapi 276 } // namespace ppapi
305 } // namespace webkit 277 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_file_io_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698