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

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: Fixes for dmichael 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 "the trusted
247 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && 251 // NaCl plugin". In that case, we may have already done work for the
248 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY && 252 // untrusted plugin, and the call above will give a non-zero
249 type != PP_FILESYSTEMTYPE_EXTERNAL && 253 // child_process_id.
250 type != PP_FILESYSTEMTYPE_ISOLATED) 254 if (host_->IsRunningInProcess())
251 return PP_ERROR_FAILED; 255 child_process_id = 0;
256
257 std::vector<PP_Resource> resources;
258 resources.push_back(file_ref_resource);
259 browser_connection->SendBrowserFileRefGetInfo(
260 child_process_id,
261 resources,
262 base::Bind(&PepperFileIOHost::DidGetFileRefInfo,
263 weak_factory_.GetWeakPtr(),
264 context->MakeReplyMessageContext(),
265 platform_file_flags));
266 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
267 return PP_OK_COMPLETIONPENDING;
268 }
269
270 void PepperFileIOHost::DidGetFileRefInfo(
271 ppapi::host::ReplyMessageContext reply_context,
272 int platform_file_flags,
273 const std::vector<ppapi::FileRefDetailedInfo>& infos) {
274 if (infos.size() != 1) {
275 reply_context.params.set_result(PP_ERROR_FAILED);
276 host()->SendReply(reply_context,
277 PpapiPluginMsg_FileIO_OpenReply());
278 return;
279 }
280
281 PP_FileSystemType type = infos[0].file_system_type;
252 file_system_type_ = type; 282 file_system_type_ = type;
253 283 if (type != PP_FILESYSTEMTYPE_EXTERNAL) {
254 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api); 284 const std::string& file_system_url_spec = infos[0].file_system_url_spec;
255 if (file_ref->HasValidFileSystem()) { 285 file_system_url_ = GURL(file_system_url_spec);
256 file_system_url_ = file_ref->GetFileSystemURL();
257 286
258 FileSystemDispatcher* file_system_dispatcher = 287 FileSystemDispatcher* file_system_dispatcher =
259 ChildThread::current()->file_system_dispatcher(); 288 ChildThread::current()->file_system_dispatcher();
289
260 AsyncOpenFileSystemURLCallback callback = base::Bind( 290 AsyncOpenFileSystemURLCallback callback = base::Bind(
261 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, 291 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback,
262 weak_factory_.GetWeakPtr(), 292 weak_factory_.GetWeakPtr(),
263 context->MakeReplyMessageContext()); 293 reply_context);
264 file_system_dispatcher->OpenFile( 294 file_system_dispatcher->OpenFile(
265 file_system_url_, platform_file_flags, 295 file_system_url_, platform_file_flags,
266 base::Bind(&DidOpenFileSystemURL, callback), 296 base::Bind(&DidOpenFileSystemURL, callback),
267 base::Bind(&DidFailOpenFileSystemURL, callback)); 297 base::Bind(&DidFailOpenFileSystemURL, callback));
268 } else { 298 } 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( 299 int message_id = pending_async_open_files_.Add(new AsyncOpenFileCallback(
272 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, 300 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback,
273 weak_factory_.GetWeakPtr(), 301 weak_factory_.GetWeakPtr(),
274 context->MakeReplyMessageContext()))); 302 reply_context)));
275 RenderThreadImpl::current()->Send(new ViewHostMsg_AsyncOpenPepperFile( 303 RenderThreadImpl::current()->Send(new ViewHostMsg_AsyncOpenPepperFile(
276 routing_id_, file_ref->GetSystemPath(), open_flags, message_id)); 304 routing_id_, infos[0].external_path, open_flags_, message_id));
277 } 305 }
278
279 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
280 return PP_OK_COMPLETIONPENDING;
281 } 306 }
282 307
283 int32_t PepperFileIOHost::OnHostMsgQuery( 308 int32_t PepperFileIOHost::OnHostMsgQuery(
284 ppapi::host::HostMessageContext* context) { 309 ppapi::host::HostMessageContext* context) {
285 int32_t rv = state_manager_.CheckOperationState( 310 int32_t rv = state_manager_.CheckOperationState(
286 FileIOStateManager::OPERATION_EXCLUSIVE, true); 311 FileIOStateManager::OPERATION_EXCLUSIVE, true);
287 if (rv != PP_OK) 312 if (rv != PP_OK)
288 return rv; 313 return rv;
289 314
290 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( 315 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 668 // 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 669 // depends on whether is negative or not. It is the result here. We translate
645 // for the callback. 670 // for the callback.
646 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); 671 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
647 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); 672 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written));
648 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); 673 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply());
649 state_manager_.SetOperationFinished(); 674 state_manager_.SetOperationFinished();
650 } 675 }
651 676
652 } // namespace content 677 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698