Chromium Code Reviews| 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 #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 Loading... | |
| 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( | |
| 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: | |
| 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 Loading... | |
| 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 type; | |
| 128 base::FilePath virtual_path; | |
| 129 fileapi::ParseFileSystemSchemeURL(root_url, &origin, &type, &virtual_path); | |
| 130 | |
| 131 std::string name = fileapi::GetFileSystemName(origin, type); | |
| 132 blink::WebFileSystemType blink_type; | |
| 133 if (!FileApiFileSystemTypeToWebFileSystemType(type, &blink_type)) | |
| 134 return false; | |
| 135 blink::WebFrame* frame = blink::WebFrame::frameForContext(context); | |
| 136 blink::WebDOMFileSystem web_dom_file_system = blink::WebDOMFileSystem::create( | |
|
Ronghua Wu (Left Chromium)
2014/03/07 23:55:12
Hi Matt,
In the video track case, the pepper host
Matt Giuca
2014/03/10 04:51:42
Since this isn't relevant to reviewing the CL, I'd
| |
| 137 frame, | |
| 138 blink_type, | |
| 139 blink::WebString::fromUTF8(name), | |
| 140 root_url, | |
| 141 blink::WebDOMFileSystem::SerializableTypeSerializable); | |
| 142 *dom_file_system = web_dom_file_system.toV8Value(); | |
| 143 return true; | |
| 144 } | |
| 145 | |
| 95 bool DOMMediaStreamTrackToResource( | 146 bool DOMMediaStreamTrackToResource( |
| 96 PP_Instance instance, | 147 PP_Instance instance, |
| 97 RendererPpapiHost* host, | 148 RendererPpapiHost* host, |
| 98 const blink::WebDOMMediaStreamTrack& dom_media_stream_track, | 149 const blink::WebDOMMediaStreamTrack& dom_media_stream_track, |
| 99 int* pending_renderer_id, | 150 int* pending_renderer_id, |
| 100 scoped_ptr<IPC::Message>* create_message) { | 151 scoped_ptr<IPC::Message>* create_message) { |
| 101 DCHECK(!dom_media_stream_track.isNull()); | 152 DCHECK(!dom_media_stream_track.isNull()); |
| 102 *pending_renderer_id = 0; | 153 *pending_renderer_id = 0; |
| 103 | 154 |
| 104 const blink::WebMediaStreamTrack track = dom_media_stream_track.component(); | 155 const blink::WebMediaStreamTrack track = dom_media_stream_track.component(); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 ::ppapi::host::PpapiHost* ppapi_host = | 283 ::ppapi::host::PpapiHost* ppapi_host = |
| 233 renderer_ppapi_host->GetPpapiHost(); | 284 renderer_ppapi_host->GetPpapiHost(); |
| 234 ::ppapi::host::ResourceHost* resource_host = | 285 ::ppapi::host::ResourceHost* resource_host = |
| 235 ppapi_host->GetResourceHost(resource_id); | 286 ppapi_host->GetResourceHost(resource_id); |
| 236 if (resource_host == NULL) { | 287 if (resource_host == NULL) { |
| 237 LOG(ERROR) << "No resource host for resource #" << resource_id; | 288 LOG(ERROR) << "No resource host for resource #" << resource_id; |
| 238 return false; | 289 return false; |
| 239 } | 290 } |
| 240 | 291 |
| 241 // Convert to the appropriate type of resource host. | 292 // Convert to the appropriate type of resource host. |
| 242 // TODO(mgiuca): Convert FileSystemHost resources into DOMFileSystem V8 | 293 if (resource_host->IsFileSystemHost()) { |
| 243 // objects. (http://crbug.com/345158) | 294 return ResourceHostToDOMFileSystem( |
| 244 LOG(ERROR) << "The type of resource #" << resource_id | 295 static_cast<content::PepperFileSystemHost*>(resource_host), |
| 245 << " cannot be converted to a JavaScript object."; | 296 context, |
| 246 return false; | 297 result); |
| 298 } else { | |
| 299 LOG(ERROR) << "The type of resource #" << resource_id | |
| 300 << " cannot be converted to a JavaScript object."; | |
| 301 return false; | |
| 302 } | |
| 247 } | 303 } |
| 248 | 304 |
| 249 scoped_refptr<HostResourceVar> ResourceConverterImpl::CreateResourceVar( | 305 scoped_refptr<HostResourceVar> ResourceConverterImpl::CreateResourceVar( |
| 250 int pending_renderer_id, | 306 int pending_renderer_id, |
| 251 const IPC::Message& create_message) { | 307 const IPC::Message& create_message) { |
| 252 return new HostResourceVar(pending_renderer_id, create_message); | 308 return new HostResourceVar(pending_renderer_id, create_message); |
| 253 } | 309 } |
| 254 | 310 |
| 255 scoped_refptr<HostResourceVar> | 311 scoped_refptr<HostResourceVar> |
| 256 ResourceConverterImpl::CreateResourceVarWithBrowserHost( | 312 ResourceConverterImpl::CreateResourceVarWithBrowserHost( |
| 257 int pending_renderer_id, | 313 int pending_renderer_id, |
| 258 const IPC::Message& create_message, | 314 const IPC::Message& create_message, |
| 259 const IPC::Message& browser_host_create_message) { | 315 const IPC::Message& browser_host_create_message) { |
| 260 scoped_refptr<HostResourceVar> result = | 316 scoped_refptr<HostResourceVar> result = |
| 261 CreateResourceVar(pending_renderer_id, create_message); | 317 CreateResourceVar(pending_renderer_id, create_message); |
| 262 browser_host_create_messages_.push_back(browser_host_create_message); | 318 browser_host_create_messages_.push_back(browser_host_create_message); |
| 263 browser_vars.push_back(result); | 319 browser_vars.push_back(result); |
| 264 return result; | 320 return result; |
| 265 } | 321 } |
| 266 | 322 |
| 267 } // namespace content | 323 } // namespace content |
| OLD | NEW |