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_video_track_host.h" |
11 #include "ipc/ipc_message.h" | 12 #include "ipc/ipc_message.h" |
12 #include "ppapi/host/ppapi_host.h" | 13 #include "ppapi/host/ppapi_host.h" |
13 #include "ppapi/host/resource_host.h" | 14 #include "ppapi/host/resource_host.h" |
14 #include "ppapi/proxy/ppapi_messages.h" | 15 #include "ppapi/proxy/ppapi_messages.h" |
15 #include "ppapi/shared_impl/resource_var.h" | 16 #include "ppapi/shared_impl/resource_var.h" |
16 #include "ppapi/shared_impl/scoped_pp_var.h" | 17 #include "ppapi/shared_impl/scoped_pp_var.h" |
17 #include "third_party/WebKit/public/platform/WebFileSystem.h" | 18 #include "third_party/WebKit/public/platform/WebFileSystem.h" |
| 19 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
18 #include "third_party/WebKit/public/web/WebDOMFileSystem.h" | 20 #include "third_party/WebKit/public/web/WebDOMFileSystem.h" |
| 21 #include "third_party/WebKit/public/web/WebDOMMediaStreamTrack.h" |
19 | 22 |
| 23 namespace content { |
20 namespace { | 24 namespace { |
21 | 25 |
22 void FlushComplete( | 26 void FlushComplete( |
23 const base::Callback<void(bool)>& callback, | 27 const base::Callback<void(bool)>& callback, |
24 const std::vector<scoped_refptr<content::HostResourceVar> >& browser_vars, | 28 const std::vector<scoped_refptr<content::HostResourceVar> >& browser_vars, |
25 const std::vector<int>& pending_host_ids) { | 29 const std::vector<int>& pending_host_ids) { |
26 CHECK(browser_vars.size() == pending_host_ids.size()); | 30 CHECK(browser_vars.size() == pending_host_ids.size()); |
27 for (size_t i = 0; i < browser_vars.size(); ++i) { | 31 for (size_t i = 0; i < browser_vars.size(); ++i) { |
28 browser_vars[i]->set_pending_browser_host_id(pending_host_ids[i]); | 32 browser_vars[i]->set_pending_browser_host_id(pending_host_ids[i]); |
29 } | 33 } |
(...skipping 15 matching lines...) Expand all Loading... |
45 NOTREACHED(); | 49 NOTREACHED(); |
46 return PP_FILESYSTEMTYPE_LOCALTEMPORARY; | 50 return PP_FILESYSTEMTYPE_LOCALTEMPORARY; |
47 } | 51 } |
48 } | 52 } |
49 | 53 |
50 // Given a V8 value containing a DOMFileSystem, creates a resource host and | 54 // Given a V8 value containing a DOMFileSystem, creates a resource host and |
51 // returns the resource information for serialization. | 55 // returns the resource information for serialization. |
52 // On error, false. | 56 // On error, false. |
53 bool DOMFileSystemToResource( | 57 bool DOMFileSystemToResource( |
54 PP_Instance instance, | 58 PP_Instance instance, |
55 content::RendererPpapiHost* host, | 59 RendererPpapiHost* host, |
56 const blink::WebDOMFileSystem& dom_file_system, | 60 const blink::WebDOMFileSystem& dom_file_system, |
57 int* pending_renderer_id, | 61 int* pending_renderer_id, |
58 scoped_ptr<IPC::Message>* create_message, | 62 scoped_ptr<IPC::Message>* create_message, |
59 scoped_ptr<IPC::Message>* browser_host_create_message) { | 63 scoped_ptr<IPC::Message>* browser_host_create_message) { |
60 DCHECK(!dom_file_system.isNull()); | 64 DCHECK(!dom_file_system.isNull()); |
61 | 65 |
62 PP_FileSystemType file_system_type = | 66 PP_FileSystemType file_system_type = |
63 WebFileSystemTypeToPPAPI(dom_file_system.type()); | 67 WebFileSystemTypeToPPAPI(dom_file_system.type()); |
64 GURL root_url = dom_file_system.rootURL(); | 68 GURL root_url = dom_file_system.rootURL(); |
65 | 69 |
66 // External file systems are not currently supported. (Without this check, | 70 // External file systems are not currently supported. (Without this check, |
67 // there would be a CHECK-fail in FileRefResource.) | 71 // there would be a CHECK-fail in FileRefResource.) |
68 // TODO(mgiuca): Support external file systems. | 72 // TODO(mgiuca): Support external file systems. |
69 if (file_system_type == PP_FILESYSTEMTYPE_EXTERNAL) | 73 if (file_system_type == PP_FILESYSTEMTYPE_EXTERNAL) |
70 return false; | 74 return false; |
71 | 75 |
72 *pending_renderer_id = host->GetPpapiHost()->AddPendingResourceHost( | 76 *pending_renderer_id = host->GetPpapiHost()->AddPendingResourceHost( |
73 scoped_ptr<ppapi::host::ResourceHost>( | 77 scoped_ptr<ppapi::host::ResourceHost>( |
74 new content::PepperFileSystemHost(host, instance, 0, root_url, | 78 new PepperFileSystemHost(host, instance, 0, root_url, |
75 file_system_type))); | 79 file_system_type))); |
76 if (*pending_renderer_id == 0) | 80 if (*pending_renderer_id == 0) |
77 return false; | 81 return false; |
78 | 82 |
79 create_message->reset( | 83 create_message->reset( |
80 new PpapiPluginMsg_FileSystem_CreateFromPendingHost(file_system_type)); | 84 new PpapiPluginMsg_FileSystem_CreateFromPendingHost(file_system_type)); |
81 | 85 |
82 browser_host_create_message->reset( | 86 browser_host_create_message->reset( |
83 new PpapiHostMsg_FileSystem_CreateFromRenderer(root_url.spec(), | 87 new PpapiHostMsg_FileSystem_CreateFromRenderer(root_url.spec(), |
84 file_system_type)); | 88 file_system_type)); |
85 return true; | 89 return true; |
86 } | 90 } |
87 | 91 |
| 92 bool DOMMediaStreamTrackToResource( |
| 93 PP_Instance instance, |
| 94 RendererPpapiHost* host, |
| 95 const blink::WebDOMMediaStreamTrack& dom_media_stream_track, |
| 96 int* pending_renderer_id, |
| 97 scoped_ptr<IPC::Message>* create_message) { |
| 98 DCHECK(!dom_media_stream_track.isNull()); |
| 99 *pending_renderer_id = 0; |
| 100 |
| 101 const blink::WebMediaStreamTrack track = dom_media_stream_track.component(); |
| 102 const std::string id = track.source().id().utf8(); |
| 103 |
| 104 if (track.source().type() == blink::WebMediaStreamSource::TypeVideo) { |
| 105 *pending_renderer_id = host->GetPpapiHost()->AddPendingResourceHost( |
| 106 scoped_ptr<ppapi::host::ResourceHost>( |
| 107 new PepperMediaStreamVideoTrackHost(host, instance, 0, track))); |
| 108 if (*pending_renderer_id == 0) |
| 109 return false; |
| 110 |
| 111 create_message->reset( |
| 112 new PpapiPluginMsg_MediaStreamVideoTrack_CreateFromPendingHost(id)); |
| 113 return true; |
| 114 } else if (track.source().type() == blink::WebMediaStreamSource::TypeAudio) { |
| 115 // TODO(penghuang): support audio track. |
| 116 return false; |
| 117 } |
| 118 |
| 119 return false; |
| 120 } |
| 121 |
88 } // namespace | 122 } // namespace |
89 | 123 |
90 namespace content { | |
91 | |
92 ResourceConverter::~ResourceConverter() {} | 124 ResourceConverter::~ResourceConverter() {} |
93 | 125 |
94 ResourceConverterImpl::ResourceConverterImpl(PP_Instance instance, | 126 ResourceConverterImpl::ResourceConverterImpl(PP_Instance instance, |
95 RendererPpapiHost* host) | 127 RendererPpapiHost* host) |
96 : instance_(instance), | 128 : instance_(instance), |
97 host_(host) { | 129 host_(host) { |
98 } | 130 } |
99 | 131 |
100 ResourceConverterImpl::~ResourceConverterImpl() { | 132 ResourceConverterImpl::~ResourceConverterImpl() { |
101 // Verify Flush() was called. | 133 // Verify Flush() was called. |
(...skipping 24 matching lines...) Expand all Loading... |
126 DCHECK(create_message); | 158 DCHECK(create_message); |
127 DCHECK(browser_host_create_message); | 159 DCHECK(browser_host_create_message); |
128 scoped_refptr<HostResourceVar> result_var = | 160 scoped_refptr<HostResourceVar> result_var = |
129 CreateResourceVarWithBrowserHost( | 161 CreateResourceVarWithBrowserHost( |
130 pending_renderer_id, *create_message, *browser_host_create_message); | 162 pending_renderer_id, *create_message, *browser_host_create_message); |
131 *result = result_var->GetPPVar(); | 163 *result = result_var->GetPPVar(); |
132 *was_resource = true; | 164 *was_resource = true; |
133 return true; | 165 return true; |
134 } | 166 } |
135 | 167 |
| 168 blink::WebDOMMediaStreamTrack dom_media_stream_track = |
| 169 blink::WebDOMMediaStreamTrack::fromV8Value(val); |
| 170 if (!dom_media_stream_track.isNull()) { |
| 171 int pending_renderer_id; |
| 172 scoped_ptr<IPC::Message> create_message; |
| 173 if (!DOMMediaStreamTrackToResource(instance_, host_, dom_media_stream_track, |
| 174 &pending_renderer_id, &create_message)) { |
| 175 return false; |
| 176 } |
| 177 DCHECK(create_message); |
| 178 scoped_refptr<HostResourceVar> result_var = CreateResourceVar( |
| 179 pending_renderer_id, *create_message); |
| 180 *result = result_var->GetPPVar(); |
| 181 *was_resource = true; |
| 182 return true; |
| 183 } |
| 184 |
136 // The value was not convertible to a resource. Return true with | 185 // The value was not convertible to a resource. Return true with |
137 // |was_resource| set to false. As per the interface of FromV8Value, |result| | 186 // |was_resource| set to false. As per the interface of FromV8Value, |result| |
138 // may be left unmodified in this case. | 187 // may be left unmodified in this case. |
139 return true; | 188 return true; |
140 } | 189 } |
141 | 190 |
142 void ResourceConverterImpl::Flush(const base::Callback<void(bool)>& callback) { | 191 void ResourceConverterImpl::Flush(const base::Callback<void(bool)>& callback) { |
143 host_->CreateBrowserResourceHosts( | 192 host_->CreateBrowserResourceHosts( |
144 instance_, | 193 instance_, |
145 browser_host_create_messages_, | 194 browser_host_create_messages_, |
(...skipping 14 matching lines...) Expand all Loading... |
160 const IPC::Message& create_message, | 209 const IPC::Message& create_message, |
161 const IPC::Message& browser_host_create_message) { | 210 const IPC::Message& browser_host_create_message) { |
162 scoped_refptr<HostResourceVar> result = | 211 scoped_refptr<HostResourceVar> result = |
163 CreateResourceVar(pending_renderer_id, create_message); | 212 CreateResourceVar(pending_renderer_id, create_message); |
164 browser_host_create_messages_.push_back(browser_host_create_message); | 213 browser_host_create_messages_.push_back(browser_host_create_message); |
165 browser_vars.push_back(result); | 214 browser_vars.push_back(result); |
166 return result; | 215 return result; |
167 } | 216 } |
168 | 217 |
169 } // namespace content | 218 } // namespace content |
OLD | NEW |