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

Side by Side Diff: content/renderer/pepper/pepper_file_io_host.cc

Issue 21966004: Pepper: Move FileRef to the "new" resource proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CreateInfo/DetailedInfo rename Created 7 years, 4 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/renderer/pepper/pepper_file_io_host.h" 5 #include "content/renderer/pepper/pepper_file_io_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_util_proxy.h" 11 #include "base/files/file_util_proxy.h"
12 #include "content/child/child_thread.h" 12 #include "content/child/child_thread.h"
13 #include "content/child/fileapi/file_system_dispatcher.h" 13 #include "content/child/fileapi/file_system_dispatcher.h"
14 #include "content/child/quota_dispatcher.h" 14 #include "content/child/quota_dispatcher.h"
15 #include "content/common/fileapi/file_system_messages.h" 15 #include "content/common/fileapi/file_system_messages.h"
16 #include "content/common/view_messages.h" 16 #include "content/common/view_messages.h"
17 #include "content/public/common/content_client.h" 17 #include "content/public/common/content_client.h"
18 #include "content/public/renderer/content_renderer_client.h" 18 #include "content/public/renderer/content_renderer_client.h"
19 #include "content/renderer/pepper/host_globals.h" 19 #include "content/renderer/pepper/host_globals.h"
20 #include "content/renderer/pepper/pepper_browser_connection.h"
20 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 21 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
21 #include "content/renderer/pepper/ppb_file_ref_impl.h" 22 #include "content/renderer/pepper/plugin_module.h"
22 #include "content/renderer/pepper/quota_file_io.h" 23 #include "content/renderer/pepper/quota_file_io.h"
24 #include "content/renderer/pepper/renderer_ppapi_host_impl.h"
23 #include "content/renderer/render_thread_impl.h" 25 #include "content/renderer/render_thread_impl.h"
24 #include "ppapi/c/pp_errors.h" 26 #include "ppapi/c/pp_errors.h"
25 #include "ppapi/host/dispatch_host_message.h" 27 #include "ppapi/host/dispatch_host_message.h"
26 #include "ppapi/host/ppapi_host.h" 28 #include "ppapi/host/ppapi_host.h"
27 #include "ppapi/proxy/ppapi_messages.h" 29 #include "ppapi/proxy/ppapi_messages.h"
28 #include "ppapi/shared_impl/file_type_conversion.h" 30 #include "ppapi/shared_impl/file_type_conversion.h"
29 #include "ppapi/shared_impl/time_conversion.h" 31 #include "ppapi/shared_impl/time_conversion.h"
30 #include "ppapi/thunk/enter.h" 32 #include "ppapi/thunk/enter.h"
31 #include "third_party/WebKit/public/web/WebPluginContainer.h" 33 #include "third_party/WebKit/public/web/WebPluginContainer.h"
32 34
33 namespace content { 35 namespace content {
34 36
35 using ppapi::FileIOStateManager; 37 using ppapi::FileIOStateManager;
36 using ppapi::PPTimeToTime; 38 using ppapi::PPTimeToTime;
37 using ppapi::host::ReplyMessageContext; 39 using ppapi::host::ReplyMessageContext;
38 using ppapi::thunk::EnterResourceNoLock; 40 using ppapi::thunk::EnterResourceNoLock;
39 using ppapi::thunk::PPB_FileRef_API;
40 41
41 namespace { 42 namespace {
42 43
43 // The maximum size we'll support reading in one chunk. The renderer process 44 // The maximum size we'll support reading in one chunk. The renderer process
44 // must allocate a buffer sized according to the request of the plugin. To 45 // must allocate a buffer sized according to the request of the plugin. To
45 // keep things from getting out of control, we cap the read size to this value. 46 // keep things from getting out of control, we cap the read size to this value.
46 // This should generally be OK since the API specifies that it may perform a 47 // This should generally be OK since the API specifies that it may perform a
47 // partial read. 48 // partial read.
48 static const int32_t kMaxReadSize = 32 * 1024 * 1024; // 32MB 49 static const int32_t kMaxReadSize = 32 * 1024 * 1024; // 32MB
49 50
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 base::PlatformFileError error_code) { 132 base::PlatformFileError error_code) {
132 base::PlatformFile invalid_file = base::kInvalidPlatformFileValue; 133 base::PlatformFile invalid_file = base::kInvalidPlatformFileValue;
133 callback.Run(error_code, 134 callback.Run(error_code,
134 base::PassPlatformFile(&invalid_file), 135 base::PassPlatformFile(&invalid_file),
135 quota::kQuotaLimitTypeUnknown, 136 quota::kQuotaLimitTypeUnknown,
136 PepperFileIOHost::NotifyCloseFileCallback()); 137 PepperFileIOHost::NotifyCloseFileCallback());
137 } 138 }
138 139
139 } // namespace 140 } // namespace
140 141
141 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host, 142 PepperFileIOHost::PepperFileIOHost(RendererPpapiHostImpl* host,
142 PP_Instance instance, 143 PP_Instance instance,
143 PP_Resource resource) 144 PP_Resource resource)
144 : ResourceHost(host->GetPpapiHost(), instance, resource), 145 : ResourceHost(host->GetPpapiHost(), instance, resource),
146 host_(host),
147 plugin_instance_(HostGlobals::Get()->GetInstance(instance)),
145 file_(base::kInvalidPlatformFileValue), 148 file_(base::kInvalidPlatformFileValue),
146 file_system_type_(PP_FILESYSTEMTYPE_INVALID), 149 file_system_type_(PP_FILESYSTEMTYPE_INVALID),
147 quota_policy_(quota::kQuotaLimitTypeUnknown), 150 quota_policy_(quota::kQuotaLimitTypeUnknown),
148 is_running_in_process_(host->IsRunningInProcess()), 151 is_running_in_process_(host->IsRunningInProcess()),
149 open_flags_(0), 152 open_flags_(0),
150 weak_factory_(this), 153 weak_factory_(this),
151 routing_id_(RenderThreadImpl::current()->GenerateRoutingID()) { 154 routing_id_(RenderThreadImpl::current()->GenerateRoutingID()) {
152 ChildThread::current()->AddRoute(routing_id_, this); 155 ChildThread::current()->AddRoute(routing_id_, this);
153 } 156 }
154 157
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 234
232 // TODO(tommycli): Eventually just pass the Pepper flags straight to the 235 // TODO(tommycli): Eventually just pass the Pepper flags straight to the
233 // FileSystemDispatcher so it can handle doing the security check. 236 // FileSystemDispatcher so it can handle doing the security check.
234 int platform_file_flags = 0; 237 int platform_file_flags = 0;
235 open_flags_ = open_flags; 238 open_flags_ = open_flags;
236 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, 239 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags,
237 &platform_file_flags)) { 240 &platform_file_flags)) {
238 return PP_ERROR_BADARGUMENT; 241 return PP_ERROR_BADARGUMENT;
239 } 242 }
240 243
241 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref_resource, true); 244 RenderView* render_view = host_->GetRenderViewForInstance(pp_instance());
242 if (enter.failed()) 245 PepperBrowserConnection* browser_connection =
243 return PP_ERROR_BADRESOURCE; 246 PepperBrowserConnection::Get(render_view);
247 int child_process_id = plugin_instance_->module()->GetPluginChildId();
244 248
245 PPB_FileRef_API* file_ref_api = enter.object(); 249 // Explicitly set child_process_id to 0 if we're running in process. This is
246 PP_FileSystemType type = file_ref_api->GetFileSystemType(); 250 // necessary in the case where we're a host for a resource in a trusted
dmichael (off chromium) 2013/08/08 21:24:03 s/"a trusted plugin"/"the trusted NaCl plugin" i.e
teravest 2013/08/09 02:00:08 Done.
247 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && 251 // plugin. In that case, we may have already done work for the untrusted
248 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY && 252 // plugin, and the call above will give a non-zero child_process_id.
249 type != PP_FILESYSTEMTYPE_EXTERNAL && 253 if (host_->IsRunningInProcess())
250 type != PP_FILESYSTEMTYPE_ISOLATED) 254 child_process_id = 0;
dmichael (off chromium) 2013/08/08 21:24:03 optional suggestion: If you have to do this in ver
251 return PP_ERROR_FAILED; 255
256 std::vector<PP_Resource> resources;
257 resources.push_back(file_ref_resource);
258 browser_connection->SendBrowserFileRefGetInfo(
259 child_process_id,
260 resources,
261 base::Bind(&PepperFileIOHost::DidGetFileRefInfo,
262 weak_factory_.GetWeakPtr(),
263 context->MakeReplyMessageContext(),
264 platform_file_flags));
265 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
266 return PP_OK_COMPLETIONPENDING;
267 }
268
269 void PepperFileIOHost::DidGetFileRefInfo(
270 ppapi::host::ReplyMessageContext reply_context,
271 int platform_file_flags,
272 const std::vector<ppapi::FileRefDetailedInfo>& infos) {
273 if (infos.size() != 1) {
274 reply_context.params.set_result(PP_ERROR_FAILED);
275 host()->SendReply(reply_context,
276 PpapiPluginMsg_FileIO_OpenReply());
277 return;
278 }
279
280 PP_FileSystemType type = infos[0].file_system_type;
yzshen1 2013/08/08 23:16:21 Maybe directly assign to file_system_type_?
teravest 2013/08/09 02:00:08 Done.
252 file_system_type_ = type; 281 file_system_type_ = type;
253 282 if (type != PP_FILESYSTEMTYPE_EXTERNAL) {
254 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api); 283 const std::string& file_system_url_spec = infos[0].file_system_url_spec;
yzshen1 2013/08/08 23:16:21 nit: Maybe merge line 283 and 284?
teravest 2013/08/09 02:00:08 Done.
255 if (file_ref->HasValidFileSystem()) { 284 file_system_url_ = GURL(file_system_url_spec);
256 file_system_url_ = file_ref->GetFileSystemURL();
257 285
258 FileSystemDispatcher* file_system_dispatcher = 286 FileSystemDispatcher* file_system_dispatcher =
259 ChildThread::current()->file_system_dispatcher(); 287 ChildThread::current()->file_system_dispatcher();
288
260 AsyncOpenFileSystemURLCallback callback = base::Bind( 289 AsyncOpenFileSystemURLCallback callback = base::Bind(
261 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, 290 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback,
262 weak_factory_.GetWeakPtr(), 291 weak_factory_.GetWeakPtr(),
263 context->MakeReplyMessageContext()); 292 reply_context);
264 file_system_dispatcher->OpenFile( 293 file_system_dispatcher->OpenFile(
265 file_system_url_, platform_file_flags, 294 file_system_url_, platform_file_flags,
266 base::Bind(&DidOpenFileSystemURL, callback), 295 base::Bind(&DidOpenFileSystemURL, callback),
267 base::Bind(&DidFailOpenFileSystemURL, callback)); 296 base::Bind(&DidFailOpenFileSystemURL, callback));
268 } else { 297 } else {
269 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL)
270 return PP_ERROR_FAILED;
271 int message_id = pending_async_open_files_.Add(new AsyncOpenFileCallback( 298 int message_id = pending_async_open_files_.Add(new AsyncOpenFileCallback(
272 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, 299 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback,
273 weak_factory_.GetWeakPtr(), 300 weak_factory_.GetWeakPtr(),
274 context->MakeReplyMessageContext()))); 301 reply_context)));
275 RenderThreadImpl::current()->Send(new ViewHostMsg_AsyncOpenPepperFile( 302 RenderThreadImpl::current()->Send(new ViewHostMsg_AsyncOpenPepperFile(
276 routing_id_, file_ref->GetSystemPath(), open_flags, message_id)); 303 routing_id_, infos[0].external_path, open_flags_, message_id));
277 } 304 }
278
279 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
280 return PP_OK_COMPLETIONPENDING;
281 } 305 }
282 306
283 int32_t PepperFileIOHost::OnHostMsgQuery( 307 int32_t PepperFileIOHost::OnHostMsgQuery(
284 ppapi::host::HostMessageContext* context) { 308 ppapi::host::HostMessageContext* context) {
285 int32_t rv = state_manager_.CheckOperationState( 309 int32_t rv = state_manager_.CheckOperationState(
286 FileIOStateManager::OPERATION_EXCLUSIVE, true); 310 FileIOStateManager::OPERATION_EXCLUSIVE, true);
287 if (rv != PP_OK) 311 if (rv != PP_OK)
288 return rv; 312 return rv;
289 313
290 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( 314 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile(
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 // On the plugin side, the callback expects a parameter with different meaning 667 // On the plugin side, the callback expects a parameter with different meaning
644 // depends on whether is negative or not. It is the result here. We translate 668 // depends on whether is negative or not. It is the result here. We translate
645 // for the callback. 669 // for the callback.
646 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); 670 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
647 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); 671 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written));
648 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); 672 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply());
649 state_manager_.SetOperationFinished(); 673 state_manager_.SetOperationFinished();
650 } 674 }
651 675
652 } // namespace content 676 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698