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

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

Issue 173143005: [PPAPI] It is now possible to pass a FileSystem to JS in PostMessage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update comment. Created 6 years, 9 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 | « no previous file | ppapi/tests/test_post_message.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/renderer/pepper/pepper_file_system_host.h"
11 #include "content/renderer/pepper/pepper_media_stream_audio_track_host.h" 11 #include "content/renderer/pepper/pepper_media_stream_audio_track_host.h"
12 #include "content/renderer/pepper/pepper_media_stream_video_track_host.h" 12 #include "content/renderer/pepper/pepper_media_stream_video_track_host.h"
13 #include "ipc/ipc_message.h" 13 #include "ipc/ipc_message.h"
14 #include "ppapi/host/ppapi_host.h" 14 #include "ppapi/host/ppapi_host.h"
15 #include "ppapi/host/resource_host.h" 15 #include "ppapi/host/resource_host.h"
16 #include "ppapi/proxy/ppapi_messages.h" 16 #include "ppapi/proxy/ppapi_messages.h"
17 #include "ppapi/shared_impl/resource_var.h" 17 #include "ppapi/shared_impl/resource_var.h"
18 #include "ppapi/shared_impl/scoped_pp_var.h" 18 #include "ppapi/shared_impl/scoped_pp_var.h"
19 #include "third_party/WebKit/public/platform/WebFileSystem.h" 19 #include "third_party/WebKit/public/platform/WebFileSystem.h"
20 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 20 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
21 #include "third_party/WebKit/public/web/WebDOMFileSystem.h" 21 #include "third_party/WebKit/public/web/WebDOMFileSystem.h"
22 #include "third_party/WebKit/public/web/WebDOMMediaStreamTrack.h" 22 #include "third_party/WebKit/public/web/WebDOMMediaStreamTrack.h"
23 #include "third_party/WebKit/public/web/WebFrame.h"
24 #include "webkit/common/fileapi/file_system_util.h"
23 25
24 using ppapi::ResourceVar; 26 using ppapi::ResourceVar;
25 27
26 namespace content { 28 namespace content {
27 namespace { 29 namespace {
28 30
29 void FlushComplete( 31 void FlushComplete(
30 const base::Callback<void(bool)>& callback, 32 const base::Callback<void(bool)>& callback,
31 const std::vector<scoped_refptr<content::HostResourceVar> >& browser_vars, 33 const std::vector<scoped_refptr<content::HostResourceVar> >& browser_vars,
32 const std::vector<int>& pending_host_ids) { 34 const std::vector<int>& pending_host_ids) {
(...skipping 14 matching lines...) Expand all
47 case blink::WebFileSystem::TypeIsolated: 49 case blink::WebFileSystem::TypeIsolated:
48 return PP_FILESYSTEMTYPE_ISOLATED; 50 return PP_FILESYSTEMTYPE_ISOLATED;
49 case blink::WebFileSystem::TypeExternal: 51 case blink::WebFileSystem::TypeExternal:
50 return PP_FILESYSTEMTYPE_EXTERNAL; 52 return PP_FILESYSTEMTYPE_EXTERNAL;
51 default: 53 default:
52 NOTREACHED(); 54 NOTREACHED();
53 return PP_FILESYSTEMTYPE_LOCALTEMPORARY; 55 return PP_FILESYSTEMTYPE_LOCALTEMPORARY;
54 } 56 }
55 } 57 }
56 58
59 // Converts a fileapi::FileSystemType to a blink::WebFileSystemType.
60 // Returns true on success, false if |type| does not correspond to a
61 // WebFileSystemType.
62 bool FileApiFileSystemTypeToWebFileSystemType(
Matt Giuca 2014/02/24 04:45:37 See Kinuko's comment on Patch Set 4 (not yet resol
kinuko 2014/02/25 05:07:05 I'm fine with this code.
63 fileapi::FileSystemType type,
64 blink::WebFileSystemType* result_type) {
65 switch (type) {
66 case fileapi::kFileSystemTypeTemporary:
67 *result_type = blink::WebFileSystemTypeTemporary;
68 return true;
69 case fileapi::kFileSystemTypePersistent:
70 *result_type = blink::WebFileSystemTypePersistent;
71 return true;
72 case fileapi::kFileSystemTypeIsolated:
73 *result_type = blink::WebFileSystemTypeIsolated;
74 return true;
75 case fileapi::kFileSystemTypeExternal:
76 *result_type = blink::WebFileSystemTypeExternal;
77 return true;
78 default:
kinuko 2014/02/25 05:07:05 nit: do we want to put NOTREACHED() here?
Matt Giuca 2014/03/06 01:06:26 I don't think we want to. It isn't a programming e
kinuko 2014/03/06 05:20:40 Ok (btw NOTREACHED won't crash renderer in product
Matt Giuca 2014/03/06 06:53:54 Yeah, I know, but the debug build still shouldn't
79 return false;
80 }
81 }
82
57 // Given a V8 value containing a DOMFileSystem, creates a resource host and 83 // Given a V8 value containing a DOMFileSystem, creates a resource host and
58 // returns the resource information for serialization. 84 // returns the resource information for serialization.
59 // On error, false. 85 // On error, false.
60 bool DOMFileSystemToResource( 86 bool DOMFileSystemToResource(
61 PP_Instance instance, 87 PP_Instance instance,
62 RendererPpapiHost* host, 88 RendererPpapiHost* host,
63 const blink::WebDOMFileSystem& dom_file_system, 89 const blink::WebDOMFileSystem& dom_file_system,
64 int* pending_renderer_id, 90 int* pending_renderer_id,
65 scoped_ptr<IPC::Message>* create_message, 91 scoped_ptr<IPC::Message>* create_message,
66 scoped_ptr<IPC::Message>* browser_host_create_message) { 92 scoped_ptr<IPC::Message>* browser_host_create_message) {
(...skipping 18 matching lines...) Expand all
85 111
86 create_message->reset( 112 create_message->reset(
87 new PpapiPluginMsg_FileSystem_CreateFromPendingHost(file_system_type)); 113 new PpapiPluginMsg_FileSystem_CreateFromPendingHost(file_system_type));
88 114
89 browser_host_create_message->reset( 115 browser_host_create_message->reset(
90 new PpapiHostMsg_FileSystem_CreateFromRenderer(root_url.spec(), 116 new PpapiHostMsg_FileSystem_CreateFromRenderer(root_url.spec(),
91 file_system_type)); 117 file_system_type));
92 return true; 118 return true;
93 } 119 }
94 120
121 bool ResourceHostToDOMFileSystem(
122 content::PepperFileSystemHost* file_system_host,
123 v8::Handle<v8::Context> context,
124 v8::Handle<v8::Value>* dom_file_system) {
125 GURL root_url = file_system_host->GetRootUrl();
126 GURL origin;
127 fileapi::FileSystemType mount_type;
128 base::FilePath virtual_path;
129 fileapi::ParseFileSystemSchemeURL(
130 root_url, &origin, &mount_type, &virtual_path);
131
132 std::string name = GetFileSystemName(origin, mount_type);
raymes 2014/02/25 04:55:44 missing namespace
kinuko 2014/02/25 05:07:05 Hmm.. does it mean we may not get the same .name v
Matt Giuca 2014/03/06 01:06:26 I don't understand this concern. Can you elaborate
kinuko 2014/03/06 05:20:40 I could be mistaken something. If we pass a DOMFil
kinuko 2014/03/06 05:30:44 Probably this code's main target is to convert a p
Matt Giuca 2014/03/06 06:53:54 OK thanks for explaining. You can also get other t
kinuko 2014/03/06 07:05:51 Most (or possibly all) filesystems use the standar
133 blink::WebFileSystemType blink_type;
134 if (!FileApiFileSystemTypeToWebFileSystemType(mount_type, &blink_type))
135 return false;
136 blink::WebFrame* frame = blink::WebFrame::frameForContext(context);
137 *dom_file_system = frame->createSerializableFileSystem(
kinuko 2014/02/25 05:07:05 Let me make sure once more (recalling past discuss
kinuko 2014/02/26 03:53:56 Btw can you instead use new WebDOMFileSystem::crea
Matt Giuca 2014/03/06 01:06:26 I don't know what you mean exactly. Can you explai
kinuko 2014/03/06 05:20:40 Yes, that's what I was asking. Serializable FileSy
Matt Giuca 2014/03/06 06:53:54 Yes, I think I remember this conversation now. I b
kinuko 2014/03/06 07:05:51 Thanks. lgtm then (as far as Raymes says yes to th
138 blink_type,
139 blink::WebString::fromUTF8(name),
140 blink::WebString::fromUTF8(root_url.spec()));
raymes 2014/02/25 04:55:44 I defer to kinuko for the creation of the dom file
141 return true;
142 }
143
95 bool DOMMediaStreamTrackToResource( 144 bool DOMMediaStreamTrackToResource(
96 PP_Instance instance, 145 PP_Instance instance,
97 RendererPpapiHost* host, 146 RendererPpapiHost* host,
98 const blink::WebDOMMediaStreamTrack& dom_media_stream_track, 147 const blink::WebDOMMediaStreamTrack& dom_media_stream_track,
99 int* pending_renderer_id, 148 int* pending_renderer_id,
100 scoped_ptr<IPC::Message>* create_message) { 149 scoped_ptr<IPC::Message>* create_message) {
101 DCHECK(!dom_media_stream_track.isNull()); 150 DCHECK(!dom_media_stream_track.isNull());
102 *pending_renderer_id = 0; 151 *pending_renderer_id = 0;
103 152
104 const blink::WebMediaStreamTrack track = dom_media_stream_track.component(); 153 const blink::WebMediaStreamTrack track = dom_media_stream_track.component();
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 ::ppapi::host::PpapiHost* ppapi_host = 281 ::ppapi::host::PpapiHost* ppapi_host =
233 renderer_ppapi_host->GetPpapiHost(); 282 renderer_ppapi_host->GetPpapiHost();
234 ::ppapi::host::ResourceHost* resource_host = 283 ::ppapi::host::ResourceHost* resource_host =
235 ppapi_host->GetResourceHost(resource_id); 284 ppapi_host->GetResourceHost(resource_id);
236 if (resource_host == NULL) { 285 if (resource_host == NULL) {
237 LOG(ERROR) << "No resource host for resource #" << resource_id; 286 LOG(ERROR) << "No resource host for resource #" << resource_id;
238 return false; 287 return false;
239 } 288 }
240 289
241 // Convert to the appropriate type of resource host. 290 // Convert to the appropriate type of resource host.
242 // TODO(mgiuca): Convert FileSystemHost resources into DOMFileSystem V8 291 if (resource_host->IsFileSystemHost()) {
243 // objects. (http://crbug.com/345158) 292 return ResourceHostToDOMFileSystem(
244 LOG(ERROR) << "The type of resource #" << resource_id 293 static_cast<content::PepperFileSystemHost*>(resource_host),
245 << " cannot be converted to a JavaScript object."; 294 context,
246 return false; 295 result);
296 } else {
297 LOG(ERROR) << "The type of resource #" << resource_id
298 << " cannot be converted to a JavaScript object.";
299 return false;
300 }
247 } 301 }
248 302
249 scoped_refptr<HostResourceVar> ResourceConverterImpl::CreateResourceVar( 303 scoped_refptr<HostResourceVar> ResourceConverterImpl::CreateResourceVar(
250 int pending_renderer_id, 304 int pending_renderer_id,
251 const IPC::Message& create_message) { 305 const IPC::Message& create_message) {
252 return new HostResourceVar(pending_renderer_id, create_message); 306 return new HostResourceVar(pending_renderer_id, create_message);
253 } 307 }
254 308
255 scoped_refptr<HostResourceVar> 309 scoped_refptr<HostResourceVar>
256 ResourceConverterImpl::CreateResourceVarWithBrowserHost( 310 ResourceConverterImpl::CreateResourceVarWithBrowserHost(
257 int pending_renderer_id, 311 int pending_renderer_id,
258 const IPC::Message& create_message, 312 const IPC::Message& create_message,
259 const IPC::Message& browser_host_create_message) { 313 const IPC::Message& browser_host_create_message) {
260 scoped_refptr<HostResourceVar> result = 314 scoped_refptr<HostResourceVar> result =
261 CreateResourceVar(pending_renderer_id, create_message); 315 CreateResourceVar(pending_renderer_id, create_message);
262 browser_host_create_messages_.push_back(browser_host_create_message); 316 browser_host_create_messages_.push_back(browser_host_create_message);
263 browser_vars.push_back(result); 317 browser_vars.push_back(result);
264 return result; 318 return result;
265 } 319 }
266 320
267 } // namespace content 321 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | ppapi/tests/test_post_message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698