2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
33 #include "CrossThreadCopier.h"
36 #include "ResourceError.h"
37 #include "ResourceRequest.h"
38 #include "ResourceResponse.h"
39 #include "SerializedScriptValue.h"
40 #include <wtf/Assertions.h>
41 #include <wtf/text/WTFString.h>
43 #if ENABLE(INDEXED_DATABASE)
44 #include "IDBDatabaseMetadata.h"
45 #include "IDBGetResult.h"
46 #include "IDBKeyData.h"
47 #include "IDBKeyRangeData.h"
52 CrossThreadCopierBase<false, false, URL>::Type CrossThreadCopierBase<false, false, URL>::copy(const URL& url)
57 CrossThreadCopierBase<false, false, String>::Type CrossThreadCopierBase<false, false, String>::copy(const String& str)
59 return str.isolatedCopy();
62 CrossThreadCopierBase<false, false, ResourceError>::Type CrossThreadCopierBase<false, false, ResourceError>::copy(const ResourceError& error)
67 CrossThreadCopierBase<false, false, ResourceRequest>::Type CrossThreadCopierBase<false, false, ResourceRequest>::copy(const ResourceRequest& request)
69 return request.copyData();
72 CrossThreadCopierBase<false, false, ResourceResponse>::Type CrossThreadCopierBase<false, false, ResourceResponse>::copy(const ResourceResponse& response)
74 return response.copyData();
77 #if ENABLE(INDEXED_DATABASE)
79 IndexedDB::TransactionMode CrossThreadCopierBase<false, false, IndexedDB::TransactionMode>::copy(const IndexedDB::TransactionMode& mode)
84 IndexedDB::CursorDirection CrossThreadCopierBase<false, false, IndexedDB::CursorDirection>::copy(const IndexedDB::CursorDirection& direction)
89 IndexedDB::CursorType CrossThreadCopierBase<false, false, IndexedDB::CursorType>::copy(const IndexedDB::CursorType& type)
94 CrossThreadCopierBase<false, false, IDBDatabaseMetadata>::Type CrossThreadCopierBase<false, false, IDBDatabaseMetadata>::copy(const IDBDatabaseMetadata& metadata)
96 return metadata.isolatedCopy();
99 CrossThreadCopierBase<false, false, IDBGetResult>::Type CrossThreadCopierBase<false, false, IDBGetResult>::copy(const IDBGetResult& result)
101 return result.isolatedCopy();
104 CrossThreadCopierBase<false, false, IDBIndexMetadata>::Type CrossThreadCopierBase<false, false, IDBIndexMetadata>::copy(const IDBIndexMetadata& metadata)
106 return metadata.isolatedCopy();
109 CrossThreadCopierBase<false, false, IDBKeyData>::Type CrossThreadCopierBase<false, false, IDBKeyData>::copy(const IDBKeyData& keyData)
111 return keyData.isolatedCopy();
114 CrossThreadCopierBase<false, false, IDBKeyRangeData>::Type CrossThreadCopierBase<false, false, IDBKeyRangeData>::copy(const IDBKeyRangeData& keyRangeData)
116 return keyRangeData.isolatedCopy();
119 CrossThreadCopierBase<false, false, IDBObjectStoreMetadata>::Type CrossThreadCopierBase<false, false, IDBObjectStoreMetadata>::copy(const IDBObjectStoreMetadata& metadata)
121 return metadata.isolatedCopy();
126 // Test CrossThreadCopier using COMPILE_ASSERT.
128 // Verify that ThreadSafeRefCounted objects get handled correctly.
129 class CopierThreadSafeRefCountedTest : public ThreadSafeRefCounted<CopierThreadSafeRefCountedTest> {
132 COMPILE_ASSERT((std::is_same<
133 PassRefPtr<CopierThreadSafeRefCountedTest>,
134 CrossThreadCopier<PassRefPtr<CopierThreadSafeRefCountedTest>>::Type
137 COMPILE_ASSERT((std::is_same<
138 PassRefPtr<CopierThreadSafeRefCountedTest>,
139 CrossThreadCopier<RefPtr<CopierThreadSafeRefCountedTest>>::Type
142 COMPILE_ASSERT((std::is_same<
143 PassRefPtr<CopierThreadSafeRefCountedTest>,
144 CrossThreadCopier<CopierThreadSafeRefCountedTest*>::Type
149 // Add a generic specialization which will let's us verify that no other template matches.
150 template<typename T> struct CrossThreadCopierBase<false, false, T> {
154 // Verify that RefCounted objects only match our generic template which exposes Type as int.
155 class CopierRefCountedTest : public RefCounted<CopierRefCountedTest> {
158 COMPILE_ASSERT((std::is_same<
160 CrossThreadCopier<PassRefPtr<CopierRefCountedTest>>::Type
162 PassRefPtrRefCountedTest);
164 COMPILE_ASSERT((std::is_same<
166 CrossThreadCopier<RefPtr<CopierRefCountedTest>>::Type
168 RefPtrRefCountedTest);
170 COMPILE_ASSERT((std::is_same<
172 CrossThreadCopier<CopierRefCountedTest*>::Type
174 RawPointerRefCountedTest);
176 // Verify that PassOwnPtr gets passed through.
177 COMPILE_ASSERT((std::is_same<
179 CrossThreadCopier<PassOwnPtr<float>>::Type
183 // Verify that PassOwnPtr does not get passed through.
184 COMPILE_ASSERT((std::is_same<
186 CrossThreadCopier<OwnPtr<float>>::Type
190 } // namespace WebCore