OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/v8_var_converter.h" | 5 #include "content/renderer/pepper/v8_var_converter.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
| 11 #include <memory> |
11 #include <stack> | 12 #include <stack> |
12 #include <string> | 13 #include <string> |
13 | 14 |
14 #include "base/bind.h" | 15 #include "base/bind.h" |
15 #include "base/containers/hash_tables.h" | 16 #include "base/containers/hash_tables.h" |
16 #include "base/location.h" | 17 #include "base/location.h" |
17 #include "base/logging.h" | 18 #include "base/logging.h" |
18 #include "base/memory/scoped_ptr.h" | |
19 #include "content/public/renderer/renderer_ppapi_host.h" | 19 #include "content/public/renderer/renderer_ppapi_host.h" |
20 #include "content/renderer/pepper/host_array_buffer_var.h" | 20 #include "content/renderer/pepper/host_array_buffer_var.h" |
21 #include "content/renderer/pepper/host_globals.h" | 21 #include "content/renderer/pepper/host_globals.h" |
22 #include "content/renderer/pepper/resource_converter.h" | 22 #include "content/renderer/pepper/resource_converter.h" |
23 #include "content/renderer/pepper/v8object_var.h" | 23 #include "content/renderer/pepper/v8object_var.h" |
24 #include "ppapi/shared_impl/array_var.h" | 24 #include "ppapi/shared_impl/array_var.h" |
25 #include "ppapi/shared_impl/dictionary_var.h" | 25 #include "ppapi/shared_impl/dictionary_var.h" |
26 #include "ppapi/shared_impl/var.h" | 26 #include "ppapi/shared_impl/var.h" |
27 #include "ppapi/shared_impl/var_tracker.h" | 27 #include "ppapi/shared_impl/var_tracker.h" |
28 #include "third_party/WebKit/public/web/WebArrayBuffer.h" | 28 #include "third_party/WebKit/public/web/WebArrayBuffer.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 *result = StringVar::StringToPPVar(std::string(*utf8, utf8.length())); | 233 *result = StringVar::StringToPPVar(std::string(*utf8, utf8.length())); |
234 } else if (val->IsObject()) { | 234 } else if (val->IsObject()) { |
235 // For any other v8 objects, the conversion happens as follows: | 235 // For any other v8 objects, the conversion happens as follows: |
236 // 1) If the object is an array buffer, return an ArrayBufferVar. | 236 // 1) If the object is an array buffer, return an ArrayBufferVar. |
237 // 2) If object vars are allowed, return the object wrapped as a | 237 // 2) If object vars are allowed, return the object wrapped as a |
238 // V8ObjectVar. This is to maintain backward compatibility with | 238 // V8ObjectVar. This is to maintain backward compatibility with |
239 // synchronous scripting in Flash. | 239 // synchronous scripting in Flash. |
240 // 3) If the object is an array, return an ArrayVar. | 240 // 3) If the object is an array, return an ArrayVar. |
241 // 4) If the object can be converted to a resource, return the ResourceVar. | 241 // 4) If the object can be converted to a resource, return the ResourceVar. |
242 // 5) Otherwise return a DictionaryVar. | 242 // 5) Otherwise return a DictionaryVar. |
243 scoped_ptr<blink::WebArrayBuffer> web_array_buffer( | 243 std::unique_ptr<blink::WebArrayBuffer> web_array_buffer( |
244 blink::WebArrayBufferConverter::createFromV8Value(val, isolate)); | 244 blink::WebArrayBufferConverter::createFromV8Value(val, isolate)); |
245 if (web_array_buffer.get()) { | 245 if (web_array_buffer.get()) { |
246 scoped_refptr<HostArrayBufferVar> buffer_var( | 246 scoped_refptr<HostArrayBufferVar> buffer_var( |
247 new HostArrayBufferVar(*web_array_buffer)); | 247 new HostArrayBufferVar(*web_array_buffer)); |
248 *result = buffer_var->GetPPVar(); | 248 *result = buffer_var->GetPPVar(); |
249 } else if (object_vars_allowed == V8VarConverter::kAllowObjectVars) { | 249 } else if (object_vars_allowed == V8VarConverter::kAllowObjectVars) { |
250 v8::Local<v8::Object> object = val.As<v8::Object>(); | 250 v8::Local<v8::Object> object = val.As<v8::Object>(); |
251 *result = content::HostGlobals::Get()-> | 251 *result = content::HostGlobals::Get()-> |
252 host_var_tracker()->V8ObjectVarForV8Object(instance, object); | 252 host_var_tracker()->V8ObjectVarForV8Object(instance, object); |
253 } else if (val->IsArray()) { | 253 } else if (val->IsArray()) { |
(...skipping 29 matching lines...) Expand all Loading... |
283 | 283 |
284 } // namespace | 284 } // namespace |
285 | 285 |
286 V8VarConverter::V8VarConverter(PP_Instance instance, | 286 V8VarConverter::V8VarConverter(PP_Instance instance, |
287 AllowObjectVars object_vars_allowed) | 287 AllowObjectVars object_vars_allowed) |
288 : instance_(instance), | 288 : instance_(instance), |
289 object_vars_allowed_(object_vars_allowed) { | 289 object_vars_allowed_(object_vars_allowed) { |
290 resource_converter_.reset(new ResourceConverterImpl(instance)); | 290 resource_converter_.reset(new ResourceConverterImpl(instance)); |
291 } | 291 } |
292 | 292 |
293 V8VarConverter::V8VarConverter(PP_Instance instance, | 293 V8VarConverter::V8VarConverter( |
294 scoped_ptr<ResourceConverter> resource_converter) | 294 PP_Instance instance, |
| 295 std::unique_ptr<ResourceConverter> resource_converter) |
295 : instance_(instance), | 296 : instance_(instance), |
296 object_vars_allowed_(kDisallowObjectVars), | 297 object_vars_allowed_(kDisallowObjectVars), |
297 resource_converter_(resource_converter.release()) {} | 298 resource_converter_(resource_converter.release()) {} |
298 | 299 |
299 V8VarConverter::~V8VarConverter() {} | 300 V8VarConverter::~V8VarConverter() {} |
300 | 301 |
301 // To/FromV8Value use a stack-based DFS search to traverse V8/Var graph. Each | 302 // To/FromV8Value use a stack-based DFS search to traverse V8/Var graph. Each |
302 // iteration, the top node on the stack examined. If the node has not been | 303 // iteration, the top node on the stack examined. If the node has not been |
303 // visited yet (i.e. sentinel == false) then it is added to the list of parents | 304 // visited yet (i.e. sentinel == false) then it is added to the list of parents |
304 // which contains all of the nodes on the path from the start node to the | 305 // which contains all of the nodes on the path from the start node to the |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 std::string(*name_utf8, name_utf8.length()), child_var); | 601 std::string(*name_utf8, name_utf8.length()), child_var); |
601 DCHECK(success); | 602 DCHECK(success); |
602 } | 603 } |
603 } | 604 } |
604 } | 605 } |
605 *result_var = root; | 606 *result_var = root; |
606 return true; | 607 return true; |
607 } | 608 } |
608 | 609 |
609 } // namespace content | 610 } // namespace content |
OLD | NEW |