| 1 | /* |
| 2 | * Copyright (C) 2016 Apple 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 |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "IDBValue.h" |
| 28 | |
| 29 | #if ENABLE(INDEXED_DATABASE) |
| 30 | |
| 31 | #include "SerializedScriptValue.h" |
| 32 | #include <wtf/CrossThreadTask.h> |
| 33 | |
| 34 | namespace WebCore { |
| 35 | |
| 36 | IDBValue::IDBValue() |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | IDBValue::IDBValue(const SerializedScriptValue& scriptValue) |
| 41 | : m_data(ThreadSafeDataBuffer::copyVector(scriptValue.data())) |
| 42 | , m_blobURLs(scriptValue.blobURLsIsolatedCopy()) |
| 43 | , m_sessionID(scriptValue.sessionID()) |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | IDBValue::IDBValue(const ThreadSafeDataBuffer& value) |
| 48 | : m_data(value) |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | IDBValue::IDBValue(const SerializedScriptValue& scriptValue, const Vector<String>& blobURLs, const PAL::SessionID& sessionID, const Vector<String>& blobFilePaths) |
| 53 | : m_data(ThreadSafeDataBuffer::copyVector(scriptValue.data())) |
| 54 | , m_blobURLs(blobURLs) |
| 55 | , m_sessionID(sessionID) |
| 56 | , m_blobFilePaths(blobFilePaths) |
| 57 | { |
| 58 | ASSERT(m_data.data()); |
| 59 | } |
| 60 | |
| 61 | IDBValue::IDBValue(const ThreadSafeDataBuffer& value, Vector<String>&& blobURLs, const PAL::SessionID& sessionID, Vector<String>&& blobFilePaths) |
| 62 | : m_data(value) |
| 63 | , m_blobURLs(WTFMove(blobURLs)) |
| 64 | , m_sessionID(sessionID) |
| 65 | , m_blobFilePaths(WTFMove(blobFilePaths)) |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | IDBValue::IDBValue(const ThreadSafeDataBuffer& value, const Vector<String>& blobURLs, const PAL::SessionID& sessionID, const Vector<String>& blobFilePaths) |
| 70 | : m_data(value) |
| 71 | , m_blobURLs(blobURLs) |
| 72 | , m_sessionID(sessionID) |
| 73 | , m_blobFilePaths(blobFilePaths) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | void IDBValue::setAsIsolatedCopy(const IDBValue& other) |
| 78 | { |
| 79 | ASSERT(m_blobURLs.isEmpty() && m_blobFilePaths.isEmpty()); |
| 80 | |
| 81 | m_data = other.m_data; |
| 82 | m_blobURLs = crossThreadCopy(other.m_blobURLs); |
| 83 | m_sessionID = other.m_sessionID; |
| 84 | m_blobFilePaths = crossThreadCopy(other.m_blobFilePaths); |
| 85 | } |
| 86 | |
| 87 | IDBValue IDBValue::isolatedCopy() const |
| 88 | { |
| 89 | IDBValue result; |
| 90 | result.setAsIsolatedCopy(*this); |
| 91 | return result; |
| 92 | } |
| 93 | |
| 94 | } // namespace WebCore |
| 95 | |
| 96 | #endif // ENABLE(INDEXED_DATABASE) |
| 97 | |