| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "public/web/WebBlob.h" | |
| 32 | |
| 33 #include "bindings/core/v8/V8Binding.h" | |
| 34 #include "bindings/core/v8/V8Blob.h" | |
| 35 #include "core/fileapi/Blob.h" | |
| 36 #include "platform/FileMetadata.h" | |
| 37 #include "platform/blob/BlobData.h" | |
| 38 #include <memory> | |
| 39 | |
| 40 namespace blink { | |
| 41 | |
| 42 WebBlob WebBlob::CreateFromUUID(const WebString& uuid, | |
| 43 const WebString& type, | |
| 44 long long size) { | |
| 45 return Blob::Create(BlobDataHandle::Create(uuid, type, size)); | |
| 46 } | |
| 47 | |
| 48 WebBlob WebBlob::CreateFromFile(const WebString& path, long long size) { | |
| 49 std::unique_ptr<BlobData> blob_data = BlobData::Create(); | |
| 50 blob_data->AppendFile(path, 0, size, InvalidFileTime()); | |
| 51 return Blob::Create(BlobDataHandle::Create(std::move(blob_data), size)); | |
| 52 } | |
| 53 | |
| 54 WebBlob WebBlob::FromV8Value(v8::Local<v8::Value> value) { | |
| 55 if (V8Blob::hasInstance(value, v8::Isolate::GetCurrent())) { | |
| 56 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); | |
| 57 Blob* blob = V8Blob::toImpl(object); | |
| 58 DCHECK(blob); | |
| 59 return blob; | |
| 60 } | |
| 61 return WebBlob(); | |
| 62 } | |
| 63 | |
| 64 void WebBlob::Reset() { | |
| 65 private_.Reset(); | |
| 66 } | |
| 67 | |
| 68 void WebBlob::Assign(const WebBlob& other) { | |
| 69 private_ = other.private_; | |
| 70 } | |
| 71 | |
| 72 WebString WebBlob::Uuid() { | |
| 73 if (!private_.Get()) | |
| 74 return WebString(); | |
| 75 return private_->Uuid(); | |
| 76 } | |
| 77 | |
| 78 v8::Local<v8::Value> WebBlob::ToV8Value(v8::Local<v8::Object> creation_context, | |
| 79 v8::Isolate* isolate) { | |
| 80 // We no longer use |creationContext| because it's often misused and points | |
| 81 // to a context faked by user script. | |
| 82 DCHECK(creation_context->CreationContext() == isolate->GetCurrentContext()); | |
| 83 if (!private_.Get()) | |
| 84 return v8::Local<v8::Value>(); | |
| 85 return ToV8(private_.Get(), isolate->GetCurrentContext()->Global(), isolate); | |
| 86 } | |
| 87 | |
| 88 WebBlob::WebBlob(Blob* blob) : private_(blob) {} | |
| 89 | |
| 90 WebBlob& WebBlob::operator=(Blob* blob) { | |
| 91 private_ = blob; | |
| 92 return *this; | |
| 93 } | |
| 94 | |
| 95 } // namespace blink | |
| OLD | NEW |