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