| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/child/v8_value_converter_impl.h" | 5 #include "content/child/v8_value_converter_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 #include <vector> |
| 14 | 15 |
| 15 #include "base/bind.h" | 16 #include "base/bind.h" |
| 16 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
| 17 #include "base/logging.h" | 18 #include "base/logging.h" |
| 18 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
| 19 #include "base/values.h" | 20 #include "base/values.h" |
| 20 #include "v8/include/v8.h" | 21 #include "v8/include/v8.h" |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 | 24 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 return ToV8Array(isolate, | 262 return ToV8Array(isolate, |
| 262 creation_context, | 263 creation_context, |
| 263 static_cast<const base::ListValue*>(value)); | 264 static_cast<const base::ListValue*>(value)); |
| 264 | 265 |
| 265 case base::Value::Type::DICTIONARY: | 266 case base::Value::Type::DICTIONARY: |
| 266 return ToV8Object(isolate, | 267 return ToV8Object(isolate, |
| 267 creation_context, | 268 creation_context, |
| 268 static_cast<const base::DictionaryValue*>(value)); | 269 static_cast<const base::DictionaryValue*>(value)); |
| 269 | 270 |
| 270 case base::Value::Type::BINARY: | 271 case base::Value::Type::BINARY: |
| 271 return ToArrayBuffer(isolate, | 272 return ToArrayBuffer(isolate, creation_context, value); |
| 272 creation_context, | |
| 273 static_cast<const base::BinaryValue*>(value)); | |
| 274 | 273 |
| 275 default: | 274 default: |
| 276 LOG(ERROR) << "Unexpected value type: " << value->GetType(); | 275 LOG(ERROR) << "Unexpected value type: " << value->GetType(); |
| 277 return v8::Null(isolate); | 276 return v8::Null(isolate); |
| 278 } | 277 } |
| 279 } | 278 } |
| 280 | 279 |
| 281 v8::Local<v8::Value> V8ValueConverterImpl::ToV8Array( | 280 v8::Local<v8::Value> V8ValueConverterImpl::ToV8Array( |
| 282 v8::Isolate* isolate, | 281 v8::Isolate* isolate, |
| 283 v8::Local<v8::Object> creation_context, | 282 v8::Local<v8::Object> creation_context, |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 return out; | 493 return out; |
| 495 } | 494 } |
| 496 | 495 |
| 497 if (val->IsArrayBuffer()) { | 496 if (val->IsArrayBuffer()) { |
| 498 auto contents = val.As<v8::ArrayBuffer>()->GetContents(); | 497 auto contents = val.As<v8::ArrayBuffer>()->GetContents(); |
| 499 return base::BinaryValue::CreateWithCopiedBuffer( | 498 return base::BinaryValue::CreateWithCopiedBuffer( |
| 500 static_cast<const char*>(contents.Data()), contents.ByteLength()); | 499 static_cast<const char*>(contents.Data()), contents.ByteLength()); |
| 501 } else if (val->IsArrayBufferView()) { | 500 } else if (val->IsArrayBufferView()) { |
| 502 v8::Local<v8::ArrayBufferView> view = val.As<v8::ArrayBufferView>(); | 501 v8::Local<v8::ArrayBufferView> view = val.As<v8::ArrayBufferView>(); |
| 503 size_t byte_length = view->ByteLength(); | 502 size_t byte_length = view->ByteLength(); |
| 504 auto buffer = base::MakeUnique<char[]>(byte_length); | 503 std::vector<char> buffer(byte_length); |
| 505 view->CopyContents(buffer.get(), byte_length); | 504 view->CopyContents(buffer.data(), buffer.size()); |
| 506 return base::MakeUnique<base::BinaryValue>(std::move(buffer), byte_length); | 505 return base::MakeUnique<base::BinaryValue>(std::move(buffer)); |
| 507 } else { | 506 } else { |
| 508 NOTREACHED() << "Only ArrayBuffer and ArrayBufferView should get here."; | 507 NOTREACHED() << "Only ArrayBuffer and ArrayBufferView should get here."; |
| 509 return nullptr; | 508 return nullptr; |
| 510 } | 509 } |
| 511 } | 510 } |
| 512 | 511 |
| 513 std::unique_ptr<base::Value> V8ValueConverterImpl::FromV8Object( | 512 std::unique_ptr<base::Value> V8ValueConverterImpl::FromV8Object( |
| 514 v8::Local<v8::Object> val, | 513 v8::Local<v8::Object> val, |
| 515 FromV8ValueState* state, | 514 FromV8ValueState* state, |
| 516 v8::Isolate* isolate) const { | 515 v8::Isolate* isolate) const { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 continue; | 608 continue; |
| 610 | 609 |
| 611 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), | 610 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), |
| 612 std::move(child)); | 611 std::move(child)); |
| 613 } | 612 } |
| 614 | 613 |
| 615 return std::move(result); | 614 return std::move(result); |
| 616 } | 615 } |
| 617 | 616 |
| 618 } // namespace content | 617 } // namespace content |
| OLD | NEW |