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" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 // Raw external file system access is not allowed, but external file system | 99 // Raw external file system access is not allowed, but external file system |
100 // access through fileapi is allowed. (Without this check, there would be a | 100 // access through fileapi is allowed. (Without this check, there would be a |
101 // CHECK failure in FileRefResource.) | 101 // CHECK failure in FileRefResource.) |
102 if ((file_system_type == PP_FILESYSTEMTYPE_EXTERNAL) && | 102 if ((file_system_type == PP_FILESYSTEMTYPE_EXTERNAL) && |
103 (!root_url.is_valid())) { | 103 (!root_url.is_valid())) { |
104 return false; | 104 return false; |
105 } | 105 } |
106 | 106 |
107 *pending_renderer_id = host->GetPpapiHost()->AddPendingResourceHost( | 107 *pending_renderer_id = host->GetPpapiHost()->AddPendingResourceHost( |
108 scoped_ptr<ppapi::host::ResourceHost>( | 108 scoped_ptr<ppapi::host::ResourceHost>(new PepperFileSystemHost( |
109 new PepperFileSystemHost(host, instance, 0, root_url, | 109 host, instance, 0, root_url, file_system_type))); |
110 file_system_type))); | |
111 if (*pending_renderer_id == 0) | 110 if (*pending_renderer_id == 0) |
112 return false; | 111 return false; |
113 | 112 |
114 create_message->reset( | 113 create_message->reset( |
115 new PpapiPluginMsg_FileSystem_CreateFromPendingHost(file_system_type)); | 114 new PpapiPluginMsg_FileSystem_CreateFromPendingHost(file_system_type)); |
116 | 115 |
117 browser_host_create_message->reset( | 116 browser_host_create_message->reset( |
118 new PpapiHostMsg_FileSystem_CreateFromRenderer(root_url.spec(), | 117 new PpapiHostMsg_FileSystem_CreateFromRenderer(root_url.spec(), |
119 file_system_type)); | 118 file_system_type)); |
120 return true; | 119 return true; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 #endif | 180 #endif |
182 return false; | 181 return false; |
183 } | 182 } |
184 | 183 |
185 } // namespace | 184 } // namespace |
186 | 185 |
187 ResourceConverter::~ResourceConverter() {} | 186 ResourceConverter::~ResourceConverter() {} |
188 | 187 |
189 ResourceConverterImpl::ResourceConverterImpl(PP_Instance instance, | 188 ResourceConverterImpl::ResourceConverterImpl(PP_Instance instance, |
190 RendererPpapiHost* host) | 189 RendererPpapiHost* host) |
191 : instance_(instance), | 190 : instance_(instance), host_(host) {} |
192 host_(host) { | |
193 } | |
194 | 191 |
195 ResourceConverterImpl::~ResourceConverterImpl() { | 192 ResourceConverterImpl::~ResourceConverterImpl() { |
196 // Verify Flush() was called. | 193 // Verify Flush() was called. |
197 DCHECK(browser_host_create_messages_.empty()); | 194 DCHECK(browser_host_create_messages_.empty()); |
198 DCHECK(browser_vars.empty()); | 195 DCHECK(browser_vars.empty()); |
199 } | 196 } |
200 | 197 |
201 bool ResourceConverterImpl::FromV8Value(v8::Handle<v8::Object> val, | 198 bool ResourceConverterImpl::FromV8Value(v8::Handle<v8::Object> val, |
202 v8::Handle<v8::Context> context, | 199 v8::Handle<v8::Context> context, |
203 PP_Var* result, | 200 PP_Var* result, |
204 bool* was_resource) { | 201 bool* was_resource) { |
205 v8::Context::Scope context_scope(context); | 202 v8::Context::Scope context_scope(context); |
206 v8::HandleScope handle_scope(context->GetIsolate()); | 203 v8::HandleScope handle_scope(context->GetIsolate()); |
207 | 204 |
208 *was_resource = false; | 205 *was_resource = false; |
209 | 206 |
210 blink::WebDOMFileSystem dom_file_system = | 207 blink::WebDOMFileSystem dom_file_system = |
211 blink::WebDOMFileSystem::fromV8Value(val); | 208 blink::WebDOMFileSystem::fromV8Value(val); |
212 if (!dom_file_system.isNull()) { | 209 if (!dom_file_system.isNull()) { |
213 int pending_renderer_id; | 210 int pending_renderer_id; |
214 scoped_ptr<IPC::Message> create_message; | 211 scoped_ptr<IPC::Message> create_message; |
215 scoped_ptr<IPC::Message> browser_host_create_message; | 212 scoped_ptr<IPC::Message> browser_host_create_message; |
216 if (!DOMFileSystemToResource(instance_, host_, dom_file_system, | 213 if (!DOMFileSystemToResource(instance_, |
217 &pending_renderer_id, &create_message, | 214 host_, |
| 215 dom_file_system, |
| 216 &pending_renderer_id, |
| 217 &create_message, |
218 &browser_host_create_message)) { | 218 &browser_host_create_message)) { |
219 return false; | 219 return false; |
220 } | 220 } |
221 DCHECK(create_message); | 221 DCHECK(create_message); |
222 DCHECK(browser_host_create_message); | 222 DCHECK(browser_host_create_message); |
223 scoped_refptr<HostResourceVar> result_var = | 223 scoped_refptr<HostResourceVar> result_var = |
224 CreateResourceVarWithBrowserHost( | 224 CreateResourceVarWithBrowserHost( |
225 pending_renderer_id, *create_message, *browser_host_create_message); | 225 pending_renderer_id, *create_message, *browser_host_create_message); |
226 *result = result_var->GetPPVar(); | 226 *result = result_var->GetPPVar(); |
227 *was_resource = true; | 227 *was_resource = true; |
228 return true; | 228 return true; |
229 } | 229 } |
230 | 230 |
231 blink::WebDOMMediaStreamTrack dom_media_stream_track = | 231 blink::WebDOMMediaStreamTrack dom_media_stream_track = |
232 blink::WebDOMMediaStreamTrack::fromV8Value(val); | 232 blink::WebDOMMediaStreamTrack::fromV8Value(val); |
233 if (!dom_media_stream_track.isNull()) { | 233 if (!dom_media_stream_track.isNull()) { |
234 int pending_renderer_id; | 234 int pending_renderer_id; |
235 scoped_ptr<IPC::Message> create_message; | 235 scoped_ptr<IPC::Message> create_message; |
236 if (!DOMMediaStreamTrackToResource(instance_, host_, dom_media_stream_track, | 236 if (!DOMMediaStreamTrackToResource(instance_, |
237 &pending_renderer_id, &create_message)) { | 237 host_, |
| 238 dom_media_stream_track, |
| 239 &pending_renderer_id, |
| 240 &create_message)) { |
238 return false; | 241 return false; |
239 } | 242 } |
240 DCHECK(create_message); | 243 DCHECK(create_message); |
241 scoped_refptr<HostResourceVar> result_var = CreateResourceVar( | 244 scoped_refptr<HostResourceVar> result_var = |
242 pending_renderer_id, *create_message); | 245 CreateResourceVar(pending_renderer_id, *create_message); |
243 *result = result_var->GetPPVar(); | 246 *result = result_var->GetPPVar(); |
244 *was_resource = true; | 247 *was_resource = true; |
245 return true; | 248 return true; |
246 } | 249 } |
247 | 250 |
248 // The value was not convertible to a resource. Return true with | 251 // The value was not convertible to a resource. Return true with |
249 // |was_resource| set to false. As per the interface of FromV8Value, |result| | 252 // |was_resource| set to false. As per the interface of FromV8Value, |result| |
250 // may be left unmodified in this case. | 253 // may be left unmodified in this case. |
251 return true; | 254 return true; |
252 } | 255 } |
(...skipping 22 matching lines...) Expand all Loading... |
275 // Get the renderer-side resource host for this resource. | 278 // Get the renderer-side resource host for this resource. |
276 content::RendererPpapiHost* renderer_ppapi_host = | 279 content::RendererPpapiHost* renderer_ppapi_host = |
277 content::RendererPpapiHost::GetForPPInstance(instance_); | 280 content::RendererPpapiHost::GetForPPInstance(instance_); |
278 if (!renderer_ppapi_host) { | 281 if (!renderer_ppapi_host) { |
279 // This should never happen: the RendererPpapiHost is owned by the module | 282 // This should never happen: the RendererPpapiHost is owned by the module |
280 // and should outlive instances associated with it. However, if it doesn't | 283 // and should outlive instances associated with it. However, if it doesn't |
281 // for some reason, we do not want to crash. | 284 // for some reason, we do not want to crash. |
282 NOTREACHED(); | 285 NOTREACHED(); |
283 return false; | 286 return false; |
284 } | 287 } |
285 ::ppapi::host::PpapiHost* ppapi_host = | 288 ::ppapi::host::PpapiHost* ppapi_host = renderer_ppapi_host->GetPpapiHost(); |
286 renderer_ppapi_host->GetPpapiHost(); | |
287 ::ppapi::host::ResourceHost* resource_host = | 289 ::ppapi::host::ResourceHost* resource_host = |
288 ppapi_host->GetResourceHost(resource_id); | 290 ppapi_host->GetResourceHost(resource_id); |
289 if (resource_host == NULL) { | 291 if (resource_host == NULL) { |
290 LOG(ERROR) << "No resource host for resource #" << resource_id; | 292 LOG(ERROR) << "No resource host for resource #" << resource_id; |
291 return false; | 293 return false; |
292 } | 294 } |
293 | 295 |
294 // Convert to the appropriate type of resource host. | 296 // Convert to the appropriate type of resource host. |
295 if (resource_host->IsFileSystemHost()) { | 297 if (resource_host->IsFileSystemHost()) { |
296 return ResourceHostToDOMFileSystem( | 298 return ResourceHostToDOMFileSystem( |
(...skipping 19 matching lines...) Expand all Loading... |
316 const IPC::Message& create_message, | 318 const IPC::Message& create_message, |
317 const IPC::Message& browser_host_create_message) { | 319 const IPC::Message& browser_host_create_message) { |
318 scoped_refptr<HostResourceVar> result = | 320 scoped_refptr<HostResourceVar> result = |
319 CreateResourceVar(pending_renderer_id, create_message); | 321 CreateResourceVar(pending_renderer_id, create_message); |
320 browser_host_create_messages_.push_back(browser_host_create_message); | 322 browser_host_create_messages_.push_back(browser_host_create_message); |
321 browser_vars.push_back(result); | 323 browser_vars.push_back(result); |
322 return result; | 324 return result; |
323 } | 325 } |
324 | 326 |
325 } // namespace content | 327 } // namespace content |
OLD | NEW |