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/renderer/v8_value_converter_impl.h" | 5 #include "content/renderer/v8_value_converter_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 result->Append(child); | 250 result->Append(child); |
251 } | 251 } |
252 return result; | 252 return result; |
253 } | 253 } |
254 | 254 |
255 base::BinaryValue* V8ValueConverterImpl::FromV8Buffer( | 255 base::BinaryValue* V8ValueConverterImpl::FromV8Buffer( |
256 v8::Handle<v8::Value> val) const { | 256 v8::Handle<v8::Value> val) const { |
257 char* data = NULL; | 257 char* data = NULL; |
258 size_t length = 0; | 258 size_t length = 0; |
259 | 259 |
260 WebKit::WebArrayBuffer* array_buffer = | 260 scoped_ptr<WebKit::WebArrayBuffer> array_buffer( |
261 WebKit::WebArrayBuffer::createFromV8Value(val); | 261 WebKit::WebArrayBuffer::createFromV8Value(val)); |
262 if (array_buffer) { | 262 scoped_ptr<WebKit::WebArrayBufferView> view; |
| 263 if (array_buffer.get()) { |
263 data = reinterpret_cast<char*>(array_buffer->data()); | 264 data = reinterpret_cast<char*>(array_buffer->data()); |
264 length = array_buffer->byteLength(); | 265 length = array_buffer->byteLength(); |
265 } else { | 266 } else { |
266 WebKit::WebArrayBufferView* view = | 267 view.reset(WebKit::WebArrayBufferView::createFromV8Value(val)); |
267 WebKit::WebArrayBufferView::createFromV8Value(val); | 268 if (view.get()) { |
268 if (view) { | |
269 data = reinterpret_cast<char*>(view->baseAddress()) + view->byteOffset(); | 269 data = reinterpret_cast<char*>(view->baseAddress()) + view->byteOffset(); |
270 length = view->byteLength(); | 270 length = view->byteLength(); |
271 } | 271 } |
272 } | 272 } |
273 | 273 |
274 if (data) | 274 if (data) |
275 return base::BinaryValue::CreateWithCopiedBuffer(data, length); | 275 return base::BinaryValue::CreateWithCopiedBuffer(data, length); |
276 else | 276 else |
277 return NULL; | 277 return NULL; |
278 } | 278 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 // on the browser which doesn't additionally check for null will fail. | 323 // on the browser which doesn't additionally check for null will fail. |
324 // We can avoid all bugs related to this by stripping null. | 324 // We can avoid all bugs related to this by stripping null. |
325 if (strip_null_from_objects_ && child->IsType(Value::TYPE_NULL)) | 325 if (strip_null_from_objects_ && child->IsType(Value::TYPE_NULL)) |
326 continue; | 326 continue; |
327 | 327 |
328 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), | 328 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), |
329 child.release()); | 329 child.release()); |
330 } | 330 } |
331 return result.release(); | 331 return result.release(); |
332 } | 332 } |
OLD | NEW |