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

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

Issue 26564009: [PPAPI] It is now possible to pass filesystems from JavaScript to NaCl modules. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 2 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/resource_converter.h" 5 #include "content/renderer/pepper/resource_converter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "content/public/renderer/renderer_ppapi_host.h" 9 #include "content/public/renderer/renderer_ppapi_host.h"
10 #include "content/renderer/pepper/pepper_file_system_host.h"
10 #include "ipc/ipc_message.h" 11 #include "ipc/ipc_message.h"
12 #include "ppapi/host/ppapi_host.h"
13 #include "ppapi/host/resource_host.h"
14 #include "ppapi/proxy/ppapi_messages.h"
11 #include "ppapi/shared_impl/resource_var.h" 15 #include "ppapi/shared_impl/resource_var.h"
12 #include "ppapi/shared_impl/scoped_pp_var.h" 16 #include "ppapi/shared_impl/scoped_pp_var.h"
17 #include "third_party/WebKit/public/platform/WebFileSystem.h"
18 #include "third_party/WebKit/public/web/WebDOMFileSystem.h"
13 19
14 namespace { 20 namespace {
15 21
16 void FlushComplete( 22 void FlushComplete(
17 const base::Callback<void(bool)>& callback, 23 const base::Callback<void(bool)>& callback,
18 const std::vector<scoped_refptr<content::HostResourceVar> >& browser_vars, 24 const std::vector<scoped_refptr<content::HostResourceVar> >& browser_vars,
19 const std::vector<int>& pending_host_ids) { 25 const std::vector<int>& pending_host_ids) {
20 CHECK(browser_vars.size() == pending_host_ids.size()); 26 CHECK(browser_vars.size() == pending_host_ids.size());
21 for (size_t i = 0; i < browser_vars.size(); ++i) { 27 for (size_t i = 0; i < browser_vars.size(); ++i) {
22 browser_vars[i]->set_pending_browser_host_id(pending_host_ids[i]); 28 browser_vars[i]->set_pending_browser_host_id(pending_host_ids[i]);
23 } 29 }
24 callback.Run(true); 30 callback.Run(true);
25 } 31 }
26 32
33 // Converts a WebKit::WebFileSystem::Type to a PP_FileSystemType.
34 // Returns true on success, false on failure.
raymes 2013/10/11 04:02:24 Seems like this comment doesn't match the behavior
Matt Giuca 2013/10/15 00:25:16 Done.
35 PP_FileSystemType WebFileSystemTypeToPPAPI(
36 WebKit::WebFileSystem::Type type) {
raymes 2013/10/11 04:02:24 Does this fit on the previous line?
Matt Giuca 2013/10/15 00:25:16 Done.
37 switch (type) {
38 case WebKit::WebFileSystem::TypeTemporary:
39 return PP_FILESYSTEMTYPE_LOCALTEMPORARY;
40 case WebKit::WebFileSystem::TypePersistent:
41 return PP_FILESYSTEMTYPE_LOCALPERSISTENT;
42 case WebKit::WebFileSystem::TypeIsolated:
43 return PP_FILESYSTEMTYPE_ISOLATED;
44 case WebKit::WebFileSystem::TypeExternal:
45 return PP_FILESYSTEMTYPE_EXTERNAL;
46 }
raymes 2013/10/11 04:02:24 Do we need a default case for safety here?
Matt Giuca 2013/10/15 00:25:16 Done.
47 }
48
49 // Given a V8 value containing a DOMFileSystem, creates a resource host and
50 // returns the resource information for serialization.
51 // On error, false.
52 bool DOMFileSystemToResource(
53 PP_Instance instance,
54 content::RendererPpapiHost* host,
55 const WebKit::WebDOMFileSystem& dom_file_system,
56 int* pending_renderer_id,
57 IPC::Message* create_message,
58 IPC::Message* browser_host_create_message) {
59 PP_FileSystemType file_system_type;
dmichael (off chromium) 2013/10/11 19:21:36 would be better to initialize this immediately. Yo
Matt Giuca 2013/10/15 00:25:16 Done.
60 // TODO(mgiuca): Ensure that external file systems are supported.
61 DCHECK(!dom_file_system.isNull());
62
63 file_system_type = WebFileSystemTypeToPPAPI(dom_file_system.type());
64 GURL root_url = dom_file_system.rootURL();
65
66 content::PepperFileSystemHost* file_system_host =
raymes 2013/10/11 04:02:24 nit: maybe initialize a scoped_ptr here to make ow
Matt Giuca 2013/10/15 00:25:16 That doesn't work; scoped_ptr can't be copied so i
yzshen1 2013/10/15 18:38:03 nit: You could call Pass() on the scoped_ptr if yo
Matt Giuca 2013/10/17 09:17:58 Fair enough, but I think it looks fine the way I c
67 new content::PepperFileSystemHost(host, instance, 0, root_url,
68 file_system_type);
69 *pending_renderer_id = host->GetPpapiHost()->AddPendingResourceHost(
70 scoped_ptr<::ppapi::host::ResourceHost>(file_system_host));
71 if (!*pending_renderer_id)
72 return false;
73
74 *create_message = PpapiPluginMsg_FileSystem_CreateFromPendingHost(
75 file_system_type);
dmichael (off chromium) 2013/10/11 19:21:36 Maybe it would make sense to use scoped_ptr<IPC::M
Matt Giuca 2013/10/17 09:17:58 These are already being passed out of this functio
dmichael (off chromium) 2013/10/17 17:36:11 Because of the interface you have here, you also c
Matt Giuca 2013/10/18 07:09:30 Oh I see where the extra copy is here. I've fixed
76
77 *browser_host_create_message =
dmichael (off chromium) 2013/10/11 19:21:36 (same suggestion for this message)
Matt Giuca 2013/10/18 07:09:30 Done.
78 PpapiHostMsg_FileSystem_CreateFromRenderer(root_url.spec(),
79 file_system_type);
80 return true;
81 }
82
27 } // namespace 83 } // namespace
28 84
29 namespace content { 85 namespace content {
30 86
31 ResourceConverter::~ResourceConverter() {} 87 ResourceConverter::~ResourceConverter() {}
32 88
33 ResourceConverterImpl::ResourceConverterImpl(PP_Instance instance, 89 ResourceConverterImpl::ResourceConverterImpl(PP_Instance instance,
34 RendererPpapiHost* host) 90 RendererPpapiHost* host)
35 : instance_(instance), 91 : instance_(instance),
36 host_(host) { 92 host_(host) {
37 } 93 }
38 94
39 ResourceConverterImpl::~ResourceConverterImpl() { 95 ResourceConverterImpl::~ResourceConverterImpl() {
40 // Verify Flush() was called. 96 // Verify Flush() was called.
41 DCHECK(browser_host_create_messages_.empty()); 97 DCHECK(browser_host_create_messages_.empty());
42 DCHECK(browser_vars.empty()); 98 DCHECK(browser_vars.empty());
43 } 99 }
44 100
45 bool ResourceConverterImpl::FromV8Value(v8::Handle<v8::Object> val, 101 bool ResourceConverterImpl::FromV8Value(v8::Handle<v8::Object> val,
46 v8::Handle<v8::Context> context, 102 v8::Handle<v8::Context> context,
47 PP_Var* result, 103 PP_Var* result,
48 bool* was_resource) { 104 bool* was_resource) {
49 v8::Context::Scope context_scope(context); 105 v8::Context::Scope context_scope(context);
50 v8::HandleScope handle_scope(context->GetIsolate()); 106 v8::HandleScope handle_scope(context->GetIsolate());
51 107
52 *was_resource = false; 108 *was_resource = false;
53 // TODO(mgiuca): There are currently no values which can be converted to 109
54 // resources. 110 WebKit::WebDOMFileSystem dom_file_system =
111 WebKit::WebDOMFileSystem::fromV8Value(val);
112 if (!dom_file_system.isNull()) {
yzshen1 2013/10/11 17:45:45 if this if-block doesn't run, |result| is not touc
dmichael (off chromium) 2013/10/11 19:21:36 +1. I think we should leave |result| untouched and
Matt Giuca 2013/10/15 00:25:16 Yes, this was intentional (but perhaps not the bes
yzshen1 2013/10/15 18:38:03 More comment sounds like a good idea. :) On 2013/1
Matt Giuca 2013/10/17 09:17:58 Done.
113 int pending_renderer_id;
114 IPC::Message create_message;
115 IPC::Message browser_host_create_message;
116 if (!DOMFileSystemToResource(instance_, host_, dom_file_system,
117 &pending_renderer_id, &create_message,
118 &browser_host_create_message))
119 return false;
raymes 2013/10/11 04:02:24 nit: usually use { with multi-line if's
Matt Giuca 2013/10/15 00:25:16 Done.
120 scoped_refptr<HostResourceVar> result_var =
121 CreateResourceVarWithBrowserHost(
122 pending_renderer_id, create_message, browser_host_create_message);
123 *result = result_var->GetPPVar();
raymes 2013/10/11 04:02:24 optional: is it clearer to combine the previous tw
Matt Giuca 2013/10/15 00:25:16 I don't think so, because then you'll never see th
raymes 2013/10/16 00:45:14 It shouldn't be important to know that it's a scop
Matt Giuca 2013/10/17 09:17:58 OK. (Also it would be a very long line, so I'll le
124 *was_resource = true;
125 return true;
126 }
55 127
56 return true; 128 return true;
57 } 129 }
58 130
59 void ResourceConverterImpl::Flush(const base::Callback<void(bool)>& callback) { 131 void ResourceConverterImpl::Flush(const base::Callback<void(bool)>& callback) {
60 host_->CreateBrowserResourceHosts( 132 host_->CreateBrowserResourceHosts(
61 instance_, 133 instance_,
62 browser_host_create_messages_, 134 browser_host_create_messages_,
63 base::Bind(&FlushComplete, callback, browser_vars)); 135 base::Bind(&FlushComplete, callback, browser_vars));
64 browser_host_create_messages_.clear(); 136 browser_host_create_messages_.clear();
(...skipping 12 matching lines...) Expand all
77 const IPC::Message& create_message, 149 const IPC::Message& create_message,
78 const IPC::Message& browser_host_create_message) { 150 const IPC::Message& browser_host_create_message) {
79 scoped_refptr<HostResourceVar> result = 151 scoped_refptr<HostResourceVar> result =
80 CreateResourceVar(pending_renderer_id, create_message); 152 CreateResourceVar(pending_renderer_id, create_message);
81 browser_host_create_messages_.push_back(browser_host_create_message); 153 browser_host_create_messages_.push_back(browser_host_create_message);
82 browser_vars.push_back(result); 154 browser_vars.push_back(result);
83 return result; 155 return result;
84 } 156 }
85 157
86 } // namespace content 158 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698