OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/glue/plugins/pepper_file_io.h" | 5 #include "webkit/glue/plugins/pepper_file_io.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/ppapi/c/dev/ppb_file_io_dev.h" |
| 9 #include "third_party/ppapi/c/dev/ppb_file_io_trusted_dev.h" |
8 #include "third_party/ppapi/c/pp_completion_callback.h" | 10 #include "third_party/ppapi/c/pp_completion_callback.h" |
9 #include "third_party/ppapi/c/pp_errors.h" | 11 #include "third_party/ppapi/c/pp_errors.h" |
10 #include "third_party/ppapi/c/ppb_file_io.h" | |
11 #include "third_party/ppapi/c/ppb_file_io_trusted.h" | |
12 #include "webkit/glue/plugins/pepper_file_ref.h" | 12 #include "webkit/glue/plugins/pepper_file_ref.h" |
13 #include "webkit/glue/plugins/pepper_plugin_module.h" | 13 #include "webkit/glue/plugins/pepper_plugin_module.h" |
14 #include "webkit/glue/plugins/pepper_resource_tracker.h" | 14 #include "webkit/glue/plugins/pepper_resource_tracker.h" |
15 | 15 |
16 namespace pepper { | 16 namespace pepper { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 PP_Resource Create(PP_Module module_id) { | 20 PP_Resource Create(PP_Module module_id) { |
21 PluginModule* module = PluginModule::FromPPModule(module_id); | 21 PluginModule* module = PluginModule::FromPPModule(module_id); |
(...skipping 17 matching lines...) Expand all Loading... |
39 return PP_ERROR_BADRESOURCE; | 39 return PP_ERROR_BADRESOURCE; |
40 | 40 |
41 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); | 41 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); |
42 if (!file_ref) | 42 if (!file_ref) |
43 return PP_ERROR_BADRESOURCE; | 43 return PP_ERROR_BADRESOURCE; |
44 | 44 |
45 return file_io->Open(file_ref, open_flags, callback); | 45 return file_io->Open(file_ref, open_flags, callback); |
46 } | 46 } |
47 | 47 |
48 int32_t Query(PP_Resource file_io_id, | 48 int32_t Query(PP_Resource file_io_id, |
49 PP_FileInfo* info, | 49 PP_FileInfo_Dev* info, |
50 PP_CompletionCallback callback) { | 50 PP_CompletionCallback callback) { |
51 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 51 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
52 if (!file_io) | 52 if (!file_io) |
53 return PP_ERROR_BADRESOURCE; | 53 return PP_ERROR_BADRESOURCE; |
54 | |
55 return file_io->Query(info, callback); | 54 return file_io->Query(info, callback); |
56 } | 55 } |
57 | 56 |
58 int32_t Touch(PP_Resource file_io_id, | 57 int32_t Touch(PP_Resource file_io_id, |
59 PP_Time last_access_time, | 58 PP_Time last_access_time, |
60 PP_Time last_modified_time, | 59 PP_Time last_modified_time, |
61 PP_CompletionCallback callback) { | 60 PP_CompletionCallback callback) { |
62 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 61 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
63 if (!file_io) | 62 if (!file_io) |
64 return PP_ERROR_BADRESOURCE; | 63 return PP_ERROR_BADRESOURCE; |
65 | |
66 return file_io->Touch(last_access_time, last_modified_time, callback); | 64 return file_io->Touch(last_access_time, last_modified_time, callback); |
67 } | 65 } |
68 | 66 |
69 int32_t Read(PP_Resource file_io_id, | 67 int32_t Read(PP_Resource file_io_id, |
70 int64_t offset, | 68 int64_t offset, |
71 char* buffer, | 69 char* buffer, |
72 int32_t bytes_to_read, | 70 int32_t bytes_to_read, |
73 PP_CompletionCallback callback) { | 71 PP_CompletionCallback callback) { |
74 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 72 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
75 if (!file_io) | 73 if (!file_io) |
76 return PP_ERROR_BADRESOURCE; | 74 return PP_ERROR_BADRESOURCE; |
77 | |
78 return file_io->Read(offset, buffer, bytes_to_read, callback); | 75 return file_io->Read(offset, buffer, bytes_to_read, callback); |
79 } | 76 } |
80 | 77 |
81 int32_t Write(PP_Resource file_io_id, | 78 int32_t Write(PP_Resource file_io_id, |
82 int64_t offset, | 79 int64_t offset, |
83 const char* buffer, | 80 const char* buffer, |
84 int32_t bytes_to_write, | 81 int32_t bytes_to_write, |
85 PP_CompletionCallback callback) { | 82 PP_CompletionCallback callback) { |
86 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 83 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
87 if (!file_io) | 84 if (!file_io) |
88 return PP_ERROR_BADRESOURCE; | 85 return PP_ERROR_BADRESOURCE; |
89 | |
90 return file_io->Write(offset, buffer, bytes_to_write, callback); | 86 return file_io->Write(offset, buffer, bytes_to_write, callback); |
91 } | 87 } |
92 | 88 |
93 int32_t SetLength(PP_Resource file_io_id, | 89 int32_t SetLength(PP_Resource file_io_id, |
94 int64_t length, | 90 int64_t length, |
95 PP_CompletionCallback callback) { | 91 PP_CompletionCallback callback) { |
96 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 92 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
97 if (!file_io) | 93 if (!file_io) |
98 return PP_ERROR_BADRESOURCE; | 94 return PP_ERROR_BADRESOURCE; |
99 | |
100 return file_io->SetLength(length, callback); | 95 return file_io->SetLength(length, callback); |
101 } | 96 } |
102 | 97 |
103 int32_t Flush(PP_Resource file_io_id, | 98 int32_t Flush(PP_Resource file_io_id, |
104 PP_CompletionCallback callback) { | 99 PP_CompletionCallback callback) { |
105 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 100 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
106 if (!file_io) | 101 if (!file_io) |
107 return PP_ERROR_BADRESOURCE; | 102 return PP_ERROR_BADRESOURCE; |
108 | |
109 return file_io->Flush(callback); | 103 return file_io->Flush(callback); |
110 } | 104 } |
111 | 105 |
112 void Close(PP_Resource file_io_id) { | 106 void Close(PP_Resource file_io_id) { |
113 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 107 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
114 if (!file_io) | 108 if (!file_io) |
115 return; | 109 return; |
116 | |
117 file_io->Close(); | 110 file_io->Close(); |
118 } | 111 } |
119 | 112 |
120 const PPB_FileIO ppb_fileio = { | 113 const PPB_FileIO_Dev ppb_fileio = { |
121 &Create, | 114 &Create, |
122 &IsFileIO, | 115 &IsFileIO, |
123 &Open, | 116 &Open, |
124 &Query, | 117 &Query, |
125 &Touch, | 118 &Touch, |
126 &Read, | 119 &Read, |
127 &Write, | 120 &Write, |
128 &SetLength, | 121 &SetLength, |
129 &Flush, | 122 &Flush, |
130 &Close | 123 &Close |
131 }; | 124 }; |
132 | 125 |
133 int32_t GetOSFileDescriptor(PP_Resource file_io_id) { | 126 int32_t GetOSFileDescriptor(PP_Resource file_io_id) { |
134 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 127 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
135 if (!file_io) | 128 if (!file_io) |
136 return PP_ERROR_BADRESOURCE; | 129 return PP_ERROR_BADRESOURCE; |
137 | |
138 return file_io->GetOSFileDescriptor(); | 130 return file_io->GetOSFileDescriptor(); |
139 } | 131 } |
140 | 132 |
141 int32_t WillWrite(PP_Resource file_io_id, | 133 int32_t WillWrite(PP_Resource file_io_id, |
142 int64_t offset, | 134 int64_t offset, |
143 int32_t bytes_to_write, | 135 int32_t bytes_to_write, |
144 PP_CompletionCallback callback) { | 136 PP_CompletionCallback callback) { |
145 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 137 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
146 if (!file_io) | 138 if (!file_io) |
147 return PP_ERROR_BADRESOURCE; | 139 return PP_ERROR_BADRESOURCE; |
148 | |
149 return file_io->WillWrite(offset, bytes_to_write, callback); | 140 return file_io->WillWrite(offset, bytes_to_write, callback); |
150 } | 141 } |
151 | 142 |
152 int32_t WillSetLength(PP_Resource file_io_id, | 143 int32_t WillSetLength(PP_Resource file_io_id, |
153 int64_t length, | 144 int64_t length, |
154 PP_CompletionCallback callback) { | 145 PP_CompletionCallback callback) { |
155 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 146 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
156 if (!file_io) | 147 if (!file_io) |
157 return PP_ERROR_BADRESOURCE; | 148 return PP_ERROR_BADRESOURCE; |
158 | |
159 return file_io->WillSetLength(length, callback); | 149 return file_io->WillSetLength(length, callback); |
160 } | 150 } |
161 | 151 |
162 const PPB_FileIOTrusted ppb_fileiotrusted = { | 152 const PPB_FileIOTrusted_Dev ppb_fileiotrusted = { |
163 &GetOSFileDescriptor, | 153 &GetOSFileDescriptor, |
164 &WillWrite, | 154 &WillWrite, |
165 &WillSetLength | 155 &WillSetLength |
166 }; | 156 }; |
167 | 157 |
168 } // namespace | 158 } // namespace |
169 | 159 |
170 FileIO::FileIO(PluginModule* module) : Resource(module) { | 160 FileIO::FileIO(PluginModule* module) : Resource(module) { |
171 } | 161 } |
172 | 162 |
173 FileIO::~FileIO() { | 163 FileIO::~FileIO() { |
174 } | 164 } |
175 | 165 |
176 // static | 166 // static |
177 const PPB_FileIO* FileIO::GetInterface() { | 167 const PPB_FileIO_Dev* FileIO::GetInterface() { |
178 return &ppb_fileio; | 168 return &ppb_fileio; |
179 } | 169 } |
180 | 170 |
181 // static | 171 // static |
182 const PPB_FileIOTrusted* FileIO::GetTrustedInterface() { | 172 const PPB_FileIOTrusted_Dev* FileIO::GetTrustedInterface() { |
183 return &ppb_fileiotrusted; | 173 return &ppb_fileiotrusted; |
184 } | 174 } |
185 | 175 |
186 int32_t FileIO::Open(FileRef* file_ref, | 176 int32_t FileIO::Open(FileRef* file_ref, |
187 int32_t open_flags, | 177 int32_t open_flags, |
188 PP_CompletionCallback callback) { | 178 PP_CompletionCallback callback) { |
189 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 179 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
190 return PP_ERROR_FAILED; | 180 return PP_ERROR_FAILED; |
191 } | 181 } |
192 | 182 |
193 int32_t FileIO::Query(PP_FileInfo* info, | 183 int32_t FileIO::Query(PP_FileInfo_Dev* info, |
194 PP_CompletionCallback callback) { | 184 PP_CompletionCallback callback) { |
195 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 185 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
196 return PP_ERROR_FAILED; | 186 return PP_ERROR_FAILED; |
197 } | 187 } |
198 | 188 |
199 int32_t FileIO::Touch(PP_Time last_access_time, | 189 int32_t FileIO::Touch(PP_Time last_access_time, |
200 PP_Time last_modified_time, | 190 PP_Time last_modified_time, |
201 PP_CompletionCallback callback) { | 191 PP_CompletionCallback callback) { |
202 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 192 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
203 return PP_ERROR_FAILED; | 193 return PP_ERROR_FAILED; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 return PP_ERROR_FAILED; | 236 return PP_ERROR_FAILED; |
247 } | 237 } |
248 | 238 |
249 int32_t FileIO::WillSetLength(int64_t length, | 239 int32_t FileIO::WillSetLength(int64_t length, |
250 PP_CompletionCallback callback) { | 240 PP_CompletionCallback callback) { |
251 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 241 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
252 return PP_ERROR_FAILED; | 242 return PP_ERROR_FAILED; |
253 } | 243 } |
254 | 244 |
255 } // namespace pepper | 245 } // namespace pepper |
OLD | NEW |