OLD | NEW |
---|---|
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 // TODO(mgiuca): This include is not allowed from content/renderer. This is | |
25 // needed to parse a file system URL. Perhaps it can be moved to webkit/common? | |
26 #include "webkit/browser/fileapi/file_system_url.h" | |
27 #include "webkit/common/fileapi/file_system_util.h" | |
23 | 28 |
24 using ppapi::ResourceVar; | 29 using ppapi::ResourceVar; |
25 | 30 |
26 namespace content { | 31 namespace content { |
27 namespace { | 32 namespace { |
28 | 33 |
29 void FlushComplete( | 34 void FlushComplete( |
30 const base::Callback<void(bool)>& callback, | 35 const base::Callback<void(bool)>& callback, |
31 const std::vector<scoped_refptr<content::HostResourceVar> >& browser_vars, | 36 const std::vector<scoped_refptr<content::HostResourceVar> >& browser_vars, |
32 const std::vector<int>& pending_host_ids) { | 37 const std::vector<int>& pending_host_ids) { |
(...skipping 14 matching lines...) Expand all Loading... | |
47 case blink::WebFileSystem::TypeIsolated: | 52 case blink::WebFileSystem::TypeIsolated: |
48 return PP_FILESYSTEMTYPE_ISOLATED; | 53 return PP_FILESYSTEMTYPE_ISOLATED; |
49 case blink::WebFileSystem::TypeExternal: | 54 case blink::WebFileSystem::TypeExternal: |
50 return PP_FILESYSTEMTYPE_EXTERNAL; | 55 return PP_FILESYSTEMTYPE_EXTERNAL; |
51 default: | 56 default: |
52 NOTREACHED(); | 57 NOTREACHED(); |
53 return PP_FILESYSTEMTYPE_LOCALTEMPORARY; | 58 return PP_FILESYSTEMTYPE_LOCALTEMPORARY; |
54 } | 59 } |
55 } | 60 } |
56 | 61 |
62 // Converts a fileapi::FileSystemType to a blink::WebFileSystemType. | |
63 // Returns true on success, false on failure. | |
64 bool FileApiFileSystemTypeToWebFileSystemType( | |
65 fileapi::FileSystemType type, | |
66 blink::WebFileSystemType* result_type) { | |
67 switch (type) { | |
68 case fileapi::kFileSystemTypeTemporary: | |
69 *result_type = blink::WebFileSystemTypeTemporary; | |
70 return true; | |
71 case fileapi::kFileSystemTypePersistent: | |
72 *result_type = blink::WebFileSystemTypePersistent; | |
73 return true; | |
74 case fileapi::kFileSystemTypeIsolated: | |
75 *result_type = blink::WebFileSystemTypeIsolated; | |
76 return true; | |
77 case fileapi::kFileSystemTypeExternal: | |
78 *result_type = blink::WebFileSystemTypeExternal; | |
kinuko
2014/02/20 11:33:28
As you can see in file_system_types.h, these are g
Matt Giuca
2014/02/23 23:55:48
I'm uncomfortable relying on that fact. Besides, I
| |
79 return true; | |
80 default: | |
81 return false; | |
82 } | |
83 } | |
84 | |
57 // Given a V8 value containing a DOMFileSystem, creates a resource host and | 85 // Given a V8 value containing a DOMFileSystem, creates a resource host and |
58 // returns the resource information for serialization. | 86 // returns the resource information for serialization. |
59 // On error, false. | 87 // On error, false. |
60 bool DOMFileSystemToResource( | 88 bool DOMFileSystemToResource( |
61 PP_Instance instance, | 89 PP_Instance instance, |
62 RendererPpapiHost* host, | 90 RendererPpapiHost* host, |
63 const blink::WebDOMFileSystem& dom_file_system, | 91 const blink::WebDOMFileSystem& dom_file_system, |
64 int* pending_renderer_id, | 92 int* pending_renderer_id, |
65 scoped_ptr<IPC::Message>* create_message, | 93 scoped_ptr<IPC::Message>* create_message, |
66 scoped_ptr<IPC::Message>* browser_host_create_message) { | 94 scoped_ptr<IPC::Message>* browser_host_create_message) { |
(...skipping 18 matching lines...) Expand all Loading... | |
85 | 113 |
86 create_message->reset( | 114 create_message->reset( |
87 new PpapiPluginMsg_FileSystem_CreateFromPendingHost(file_system_type)); | 115 new PpapiPluginMsg_FileSystem_CreateFromPendingHost(file_system_type)); |
88 | 116 |
89 browser_host_create_message->reset( | 117 browser_host_create_message->reset( |
90 new PpapiHostMsg_FileSystem_CreateFromRenderer(root_url.spec(), | 118 new PpapiHostMsg_FileSystem_CreateFromRenderer(root_url.spec(), |
91 file_system_type)); | 119 file_system_type)); |
92 return true; | 120 return true; |
93 } | 121 } |
94 | 122 |
123 v8::Handle<v8::Value> ResourceHostToDOMFileSystem( | |
124 content::PepperFileSystemHost* file_system_host, | |
125 v8::Handle<v8::Context> context) { | |
126 GURL root_url = file_system_host->GetRootUrl(); | |
127 GURL origin; | |
128 fileapi::FileSystemType mount_type; | |
129 base::FilePath virtual_path; | |
130 fileapi::FileSystemURL::ParseFileSystemSchemeURL( | |
131 root_url, &origin, &mount_type, &virtual_path); | |
132 | |
133 std::string name = GetFileSystemName(origin, mount_type); | |
134 blink::WebFileSystemType blink_type; | |
135 FileApiFileSystemTypeToWebFileSystemType(mount_type, &blink_type); | |
136 blink::WebFrame* frame = blink::WebFrame::frameForContext(context); | |
137 return frame->createSerializableFileSystem( | |
138 blink_type, | |
139 blink::WebString::fromUTF8(name), | |
140 blink::WebString::fromUTF8(root_url.spec())); | |
141 } | |
142 | |
95 bool DOMMediaStreamTrackToResource( | 143 bool DOMMediaStreamTrackToResource( |
96 PP_Instance instance, | 144 PP_Instance instance, |
97 RendererPpapiHost* host, | 145 RendererPpapiHost* host, |
98 const blink::WebDOMMediaStreamTrack& dom_media_stream_track, | 146 const blink::WebDOMMediaStreamTrack& dom_media_stream_track, |
99 int* pending_renderer_id, | 147 int* pending_renderer_id, |
100 scoped_ptr<IPC::Message>* create_message) { | 148 scoped_ptr<IPC::Message>* create_message) { |
101 DCHECK(!dom_media_stream_track.isNull()); | 149 DCHECK(!dom_media_stream_track.isNull()); |
102 *pending_renderer_id = 0; | 150 *pending_renderer_id = 0; |
103 | 151 |
104 const blink::WebMediaStreamTrack track = dom_media_stream_track.component(); | 152 const blink::WebMediaStreamTrack track = dom_media_stream_track.component(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 ::ppapi::host::PpapiHost* ppapi_host = | 274 ::ppapi::host::PpapiHost* ppapi_host = |
227 renderer_ppapi_host->GetPpapiHost(); | 275 renderer_ppapi_host->GetPpapiHost(); |
228 ::ppapi::host::ResourceHost* resource_host = | 276 ::ppapi::host::ResourceHost* resource_host = |
229 ppapi_host->GetResourceHost(resource_id); | 277 ppapi_host->GetResourceHost(resource_id); |
230 if (resource_host == NULL) { | 278 if (resource_host == NULL) { |
231 LOG(ERROR) << "No resource host for resource #" << resource_id; | 279 LOG(ERROR) << "No resource host for resource #" << resource_id; |
232 return false; | 280 return false; |
233 } | 281 } |
234 | 282 |
235 // Convert to the appropriate type of resource host. | 283 // Convert to the appropriate type of resource host. |
236 // TODO(mgiuca): Convert FileSystemHost resources into DOMFileSystem V8 | 284 if (resource_host->IsFileSystemHost()) { |
237 // objects. (http://crbug.com/345158) | 285 *result = ResourceHostToDOMFileSystem( |
238 LOG(ERROR) << "The type of resource #" << resource_id | 286 static_cast<content::PepperFileSystemHost*>(resource_host), context); |
239 << " cannot be converted to a JavaScript object."; | 287 return true; |
240 return false; | 288 } else { |
289 LOG(ERROR) << "The type of resource #" << resource_id | |
290 << " cannot be converted to a JavaScript object."; | |
291 return false; | |
292 } | |
241 } | 293 } |
242 | 294 |
243 scoped_refptr<HostResourceVar> ResourceConverterImpl::CreateResourceVar( | 295 scoped_refptr<HostResourceVar> ResourceConverterImpl::CreateResourceVar( |
244 int pending_renderer_id, | 296 int pending_renderer_id, |
245 const IPC::Message& create_message) { | 297 const IPC::Message& create_message) { |
246 return new HostResourceVar(pending_renderer_id, create_message); | 298 return new HostResourceVar(pending_renderer_id, create_message); |
247 } | 299 } |
248 | 300 |
249 scoped_refptr<HostResourceVar> | 301 scoped_refptr<HostResourceVar> |
250 ResourceConverterImpl::CreateResourceVarWithBrowserHost( | 302 ResourceConverterImpl::CreateResourceVarWithBrowserHost( |
251 int pending_renderer_id, | 303 int pending_renderer_id, |
252 const IPC::Message& create_message, | 304 const IPC::Message& create_message, |
253 const IPC::Message& browser_host_create_message) { | 305 const IPC::Message& browser_host_create_message) { |
254 scoped_refptr<HostResourceVar> result = | 306 scoped_refptr<HostResourceVar> result = |
255 CreateResourceVar(pending_renderer_id, create_message); | 307 CreateResourceVar(pending_renderer_id, create_message); |
256 browser_host_create_messages_.push_back(browser_host_create_message); | 308 browser_host_create_messages_.push_back(browser_host_create_message); |
257 browser_vars.push_back(result); | 309 browser_vars.push_back(result); |
258 return result; | 310 return result; |
259 } | 311 } |
260 | 312 |
261 } // namespace content | 313 } // namespace content |
OLD | NEW |