<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[201232] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/201232">201232</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2016-05-20 16:15:15 -0700 (Fri, 20 May 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Modern IDB: Properly handle blobs in Workers.
https://bugs.webkit.org/show_bug.cgi?id=157947
Reviewed by Alex Christensen.
Source/WebCore:
Test: storage/indexeddb/modern/blob-simple-workers.html
* Modules/indexeddb/IDBTransaction.cpp:
(WebCore::IDBTransaction::putOrAddOnServer): Use writeBlobsToDiskForIndexedDBSynchronously from
background threads instead of the asynchronous form.
Add ability to set an existing empty IDBValue to be an isolated copy of a different IDBValue:
* Modules/indexeddb/IDBValue.cpp:
(WebCore::IDBValue::setAsIsolatedCopy):
(WebCore::IDBValue::isolatedCopy):
* Modules/indexeddb/IDBValue.h:
Add a method - only to be called from a non-main thread - that synchronously writes blobs to disk:
* bindings/js/SerializedScriptValue.cpp:
(WebCore::SerializedScriptValue::writeBlobsToDiskForIndexedDBSynchronously):
* bindings/js/SerializedScriptValue.h:
LayoutTests:
* storage/indexeddb/modern/blob-simple-workers-expected.txt: Added.
* storage/indexeddb/modern/blob-simple-workers.html: Added.
* storage/indexeddb/modern/resources/blob-simple-workers.js: Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbIDBTransactioncpp">trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbIDBValuecpp">trunk/Source/WebCore/Modules/indexeddb/IDBValue.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbIDBValueh">trunk/Source/WebCore/Modules/indexeddb/IDBValue.h</a></li>
<li><a href="#trunkSourceWebCorebindingsjsSerializedScriptValuecpp">trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsjsSerializedScriptValueh">trunk/Source/WebCore/bindings/js/SerializedScriptValue.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernblobsimpleworkersexpectedtxt">trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers-expected.txt</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernblobsimpleworkershtml">trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers.html</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernresourcesblobsimpleworkersjs">trunk/LayoutTests/storage/indexeddb/modern/resources/blob-simple-workers.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (201231 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-05-20 22:53:35 UTC (rev 201231)
+++ trunk/LayoutTests/ChangeLog        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2016-05-20 Brady Eidson <beidson@apple.com>
+
+ Modern IDB: Properly handle blobs in Workers.
+ https://bugs.webkit.org/show_bug.cgi?id=157947
+
+ Reviewed by Alex Christensen.
+
+ * storage/indexeddb/modern/blob-simple-workers-expected.txt: Added.
+ * storage/indexeddb/modern/blob-simple-workers.html: Added.
+ * storage/indexeddb/modern/resources/blob-simple-workers.js: Added.
+
</ins><span class="cx"> 2016-05-20 Myles C. Maxfield <mmaxfield@apple.com>
</span><span class="cx">
</span><span class="cx"> [Cocoa] REGRESSION(r184899): Ascent adjustments are applied to web fonts
</span></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernblobsimpleworkersexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers-expected.txt (0 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers-expected.txt         (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers-expected.txt        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -0,0 +1,48 @@
</span><ins>+[Worker] This tests basic operations putting blobs into an object store and then retrieving them.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/blob-simple-workers.js
+[Worker] indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
+[Worker]
+[Worker] indexedDB.deleteDatabase(dbname)
+[Worker] indexedDB.open(dbname)
+[Worker] Initial upgrade needed: Old version - 0 New version - 1
+[Worker] Let's create a blob and store it in IndexedDB twice.
+[Worker] Added blob to database once
+[Worker] Added blob to database twice
+[Worker] Let's retrieve the blob again and verify the contents is the same.
+[Worker] Got blob from database
+[Worker] Correct text: true
+[Worker] Let's retrieve it again, create an object URL for the blob, load it via an XMLHttpRequest, and verify the contents are the same.
+[Worker] Got blob from database
+[Worker] Correct responseText: true
+[Worker] Retrieve both blob entries from the database and verify contents.
+[Worker] Correct text on first value: true
+[Worker] Correct text on second value: true
+[Worker] Got item from cursor
+[Worker] Got item from cursor
+[Worker] Finished cursor
+[Worker] Got right number of items: true
+[Worker] Correct text: true
+[Worker] Retrieve blobs from database via index and verify contents.
+[Worker] Got blob from database
+[Worker] Correct text: true
+[Worker] Got item from cursor
+[Worker] Got item from cursor
+[Worker] Finished cursor
+[Worker] Got right number of items: true
+[Worker] Correct text: true
+[Worker] Correct text: true
+[Worker] Slice the the retrieved blob and verify its contents.
+[Worker] Correct text: true
+[Worker] Store a blob back in the database, and keep holding on to the blob, verifying that it still can be read.
+[Worker] Got blob from database
+[Worker] Stored blob back into database
+[Worker] Correct text: true
+[Worker] Correct responseText: true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernblobsimpleworkershtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers.html (0 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers.html         (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers.html        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+<html>
+<head>
+<script src="../../../resources/js-test.js"></script>
+<script src="../resources/shared.js"></script>
+</head>
+<body>
+<script>
+if (window.internals)
+ window.internals.settings.setIndexedDBWorkersEnabled(true);
+worker = startWorker('resources/blob-simple-workers.js');</script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernresourcesblobsimpleworkersjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/resources/blob-simple-workers.js (0 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/resources/blob-simple-workers.js         (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/resources/blob-simple-workers.js        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -0,0 +1,270 @@
</span><ins>+if (this.importScripts) {
+ importScripts('../../../../resources/js-test.js');
+ importScripts('../../resources/shared.js');
+}
+
+// Original implementation of test from Mozilla: ./dom/indexedDB/test/test_blob_simple.html
+description("This tests basic operations putting blobs into an object store and then retrieving them.");
+
+indexedDBTest(prepareDatabase);
+
+function done()
+{
+ finishJSTest();
+}
+
+function log(message)
+{
+ debug(message);
+}
+
+var testGenerator;
+
+function continueWithEvent(event)
+{
+ testGenerator.next(event);
+}
+
+function asyncContinue()
+{
+ setTimeout("testGenerator.next();", 0);
+}
+
+function idbRequest(request)
+{
+ request.onerror = continueWithEvent;
+ request.onsuccess = continueWithEvent;
+}
+
+var db;
+
+function prepareDatabase(event)
+{
+ debug("Initial upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
+
+ db = event.target.result;
+ db.createObjectStore("foo", { autoIncrement: true }).createIndex("foo", "index");
+ event.target.onsuccess = function() {
+ testGenerator = testSteps();
+ testGenerator.next();
+ };
+}
+
+function is(a, b, message) {
+ result = a == b ? "true" : "false";
+ debug(message + ": " + result);
+}
+
+function* testSteps()
+{
+ debug("Let's create a blob and store it in IndexedDB twice.");
+
+ const BLOB_DATA = ["fun ", "times ", "all ", "around!"];
+ const INDEX_KEY = 5;
+ let blob = new Blob(BLOB_DATA, { type: "text/plain" });
+ let data = { blob: blob, index: INDEX_KEY };
+
+ objectStore = db.transaction("foo", "readwrite").objectStore("foo");
+
+ idbRequest(objectStore.add(data));
+ event = yield;
+
+ debug("Added blob to database once");
+
+ let key1 = event.target.result;
+
+ idbRequest(objectStore.add(data));
+ event = yield;
+
+ debug("Added blob to database twice");
+
+ let key2 = event.target.result;
+
+ debug("Let's retrieve the blob again and verify the contents is the same.");
+
+ objectStore = db.transaction("foo").objectStore("foo");
+ idbRequest(objectStore.get(key1));
+ event = yield;
+
+ debug("Got blob from database");
+
+ let fileReader = new FileReader();
+ fileReader.onload = continueWithEvent;
+ fileReader.readAsText(event.target.result.blob);
+ event = yield;
+
+ is(event.target.result, BLOB_DATA.join(""), "Correct text");
+
+ debug("Let's retrieve it again, create an object URL for the blob, load it via an XMLHttpRequest, and verify the contents are the same.");
+
+ objectStore = db.transaction("foo").objectStore("foo");
+ idbRequest(objectStore.get(key1));
+ event = yield;
+
+ debug("Got blob from database");
+
+ let blobURL = URL.createObjectURL(event.target.result.blob);
+
+ let xhr = new XMLHttpRequest();
+ xhr.open("GET", blobURL);
+ xhr.onload = continueWithEvent;
+ xhr.send();
+ yield;
+
+ URL.revokeObjectURL(blobURL);
+ is(xhr.responseText, BLOB_DATA.join(""), "Correct responseText");
+
+ debug("Retrieve both blob entries from the database and verify contents.");
+
+ var objects = []
+
+ objectStore = db.transaction("foo").objectStore("foo");
+ idbRequest(objectStore.get(key1));
+ event = yield;
+
+ objects.push(event.target.result);
+
+ objectStore = db.transaction("foo").objectStore("foo");
+ idbRequest(objectStore.get(key2));
+ event = yield;
+
+ objects.push(event.target.result);
+
+ fileReader = new FileReader();
+ fileReader.onload = continueWithEvent;
+ fileReader.readAsText(objects[0].blob);
+ event = yield;
+
+ is(event.target.result, BLOB_DATA.join(""), "Correct text on first value");
+
+ fileReader = new FileReader();
+ fileReader.onload = continueWithEvent;
+ fileReader.readAsText(objects[1].blob);
+ event = yield;
+
+ is(event.target.result, BLOB_DATA.join(""), "Correct text on second value");
+
+ let cursorResults = [];
+
+ objectStore = db.transaction("foo").objectStore("foo");
+ objectStore.openCursor().onsuccess = function(event) {
+ let cursor = event.target.result;
+ if (cursor) {
+ debug("Got item from cursor");
+ cursorResults.push(cursor.value);
+ cursor.continue();
+ }
+ else {
+ debug("Finished cursor");
+ asyncContinue();
+ }
+ };
+ yield;
+
+ is(cursorResults.length, 2, "Got right number of items");
+
+ fileReader = new FileReader();
+ fileReader.onload = continueWithEvent;
+ fileReader.readAsText(cursorResults[0].blob);
+ event = yield;
+
+ is(event.target.result, BLOB_DATA.join(""), "Correct text");
+
+ debug("Retrieve blobs from database via index and verify contents.");
+
+ index = db.transaction("foo").objectStore("foo").index("foo");
+ idbRequest(index.get(INDEX_KEY));
+ event = yield;
+
+ debug("Got blob from database");
+
+ fileReader = new FileReader();
+ fileReader.onload = continueWithEvent;
+ fileReader.readAsText(event.target.result.blob);
+ event = yield;
+
+ is(event.target.result, BLOB_DATA.join(""), "Correct text");
+
+ cursorResults = [];
+
+ index = db.transaction("foo").objectStore("foo").index("foo");
+ index.openCursor().onsuccess = function(event) {
+ let cursor = event.target.result;
+ if (cursor) {
+ debug("Got item from cursor");
+ cursorResults.push(cursor.value);
+ cursor.continue();
+ }
+ else {
+ debug("Finished cursor");
+ asyncContinue();
+ }
+ };
+ yield;
+
+ is(cursorResults.length, 2, "Got right number of items");
+
+ fileReader = new FileReader();
+ fileReader.onload = continueWithEvent;
+ fileReader.readAsText(cursorResults[0].blob);
+ event = yield;
+
+ is(event.target.result, BLOB_DATA.join(""), "Correct text");
+
+ fileReader = new FileReader();
+ fileReader.onload = continueWithEvent;
+ fileReader.readAsText(cursorResults[1].blob);
+ event = yield;
+
+ is(event.target.result, BLOB_DATA.join(""), "Correct text");
+
+ debug("Slice the the retrieved blob and verify its contents.");
+
+ let slice = cursorResults[1].blob.slice(0, BLOB_DATA[0].length);
+
+ fileReader = new FileReader();
+ fileReader.onload = continueWithEvent;
+ fileReader.readAsText(slice);
+ event = yield;
+
+ is(event.target.result, BLOB_DATA[0], "Correct text");
+
+ debug("Store a blob back in the database, and keep holding on to the " +
+ "blob, verifying that it still can be read.");
+
+ objectStore = db.transaction("foo").objectStore("foo");
+ idbRequest(objectStore.get(key1));
+ event = yield;
+
+ let blobFromDB = event.target.result.blob;
+ debug("Got blob from database");
+
+ let txn = db.transaction("foo", "readwrite");
+ txn.objectStore("foo").put(event.target.result, key1);
+ txn.oncomplete = continueWithEvent;
+ event = yield;
+
+ debug("Stored blob back into database");
+
+ fileReader = new FileReader();
+ fileReader.onload = continueWithEvent;
+ fileReader.readAsText(blobFromDB);
+ event = yield;
+
+ is(event.target.result, BLOB_DATA.join(""), "Correct text");
+
+ blobURL = URL.createObjectURL(blobFromDB);
+
+ xhr = new XMLHttpRequest();
+ xhr.open("GET", blobURL);
+ xhr.onload = continueWithEvent;
+ xhr.send();
+ yield;
+
+ URL.revokeObjectURL(blobURL);
+
+ is(xhr.responseText, BLOB_DATA.join(""), "Correct responseText");
+
+ finishJSTest();
+ }
+
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (201231 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-05-20 22:53:35 UTC (rev 201231)
+++ trunk/Source/WebCore/ChangeLog        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2016-05-20 Brady Eidson <beidson@apple.com>
+
+ Modern IDB: Properly handle blobs in Workers.
+ https://bugs.webkit.org/show_bug.cgi?id=157947
+
+ Reviewed by Alex Christensen.
+
+ Test: storage/indexeddb/modern/blob-simple-workers.html
+
+ * Modules/indexeddb/IDBTransaction.cpp:
+ (WebCore::IDBTransaction::putOrAddOnServer): Use writeBlobsToDiskForIndexedDBSynchronously from
+ background threads instead of the asynchronous form.
+
+ Add ability to set an existing empty IDBValue to be an isolated copy of a different IDBValue:
+ * Modules/indexeddb/IDBValue.cpp:
+ (WebCore::IDBValue::setAsIsolatedCopy):
+ (WebCore::IDBValue::isolatedCopy):
+ * Modules/indexeddb/IDBValue.h:
+
+ Add a method - only to be called from a non-main thread - that synchronously writes blobs to disk:
+ * bindings/js/SerializedScriptValue.cpp:
+ (WebCore::SerializedScriptValue::writeBlobsToDiskForIndexedDBSynchronously):
+ * bindings/js/SerializedScriptValue.h:
+
</ins><span class="cx"> 2016-05-20 Anders Carlsson <andersca@apple.com>
</span><span class="cx">
</span><span class="cx"> Allow named images on iOS
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbIDBTransactioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp (201231 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp        2016-05-20 22:53:35 UTC (rev 201231)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -938,7 +938,7 @@
</span><span class="cx"> void IDBTransaction::putOrAddOnServer(IDBClient::TransactionOperation& operation, RefPtr<IDBKey> key, RefPtr<SerializedScriptValue> value, const IndexedDB::ObjectStoreOverwriteMode& overwriteMode)
</span><span class="cx"> {
</span><span class="cx"> LOG(IndexedDB, "IDBTransaction::putOrAddOnServer");
</span><del>- ASSERT(currentThread() == m_database->originThreadID());
</del><ins>+ ASSERT(currentThread() == originThreadID());
</ins><span class="cx"> ASSERT(!isReadOnly());
</span><span class="cx"> ASSERT(value);
</span><span class="cx">
</span><span class="lines">@@ -947,9 +947,30 @@
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ // Due to current limitations on our ability to post tasks back to a worker thread,
+ // workers currently write blobs to disk synchronously.
+ // FIXME: https://bugs.webkit.org/show_bug.cgi?id=157958 - Make this asynchronous after refactoring allows it.
+ if (!isMainThread()) {
+ auto idbValue = value->writeBlobsToDiskForIndexedDBSynchronously();
+ if (idbValue.data().data())
+ m_database->connectionProxy().putOrAdd(operation, key.get(), idbValue, overwriteMode);
+ else {
+ // If the IDBValue doesn't have any data, then something went wrong writing the blobs to disk.
+ // In that case, we cannot successfully store this record, so we callback with an error.
+ RefPtr<IDBClient::TransactionOperation> protectedOperation(&operation);
+ auto result = IDBResultData::error(operation.identifier(), { IDBDatabaseException::UnknownError, ASCIILiteral("Error preparing Blob/File data to be stored in object store") });
+ scriptExecutionContext()->postTask([protectedOperation, result](ScriptExecutionContext&) {
+ protectedOperation->completed(result);
+ });
+ }
+ return;
+ }
+
</ins><span class="cx"> RefPtr<IDBTransaction> protectedThis(this);
</span><span class="cx"> RefPtr<IDBClient::TransactionOperation> protectedOperation(&operation);
</span><span class="cx"> value->writeBlobsToDiskForIndexedDB([protectedThis, this, protectedOperation, key, value, overwriteMode](const IDBValue& idbValue) {
</span><ins>+ ASSERT(currentThread() == originThreadID());
+ ASSERT(isMainThread());
</ins><span class="cx"> if (idbValue.data().data()) {
</span><span class="cx"> m_database->connectionProxy().putOrAdd(*protectedOperation, key.get(), idbValue, overwriteMode);
</span><span class="cx"> return;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbIDBValuecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/IDBValue.cpp (201231 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/IDBValue.cpp        2016-05-20 22:53:35 UTC (rev 201231)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBValue.cpp        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx">
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx">
</span><ins>+#include "CrossThreadCopier.h"
</ins><span class="cx"> #include "SerializedScriptValue.h"
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -69,19 +70,19 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void IDBValue::setAsIsolatedCopy(const IDBValue& other)
+{
+ ASSERT(m_blobURLs.isEmpty() && m_blobFilePaths.isEmpty());
+
+ m_data = other.m_data;
+ m_blobURLs = CrossThreadCopier<Vector<String>>::copy(other.m_blobURLs);
+ m_blobFilePaths = CrossThreadCopier<Vector<String>>::copy(other.m_blobFilePaths);
+}
+
</ins><span class="cx"> IDBValue IDBValue::isolatedCopy() const
</span><span class="cx"> {
</span><span class="cx"> IDBValue result;
</span><del>- result.m_data = m_data;
-
- result.m_blobURLs.reserveInitialCapacity(m_blobURLs.size());
- for (auto& url : m_blobURLs)
- result.m_blobURLs.uncheckedAppend(url.isolatedCopy());
-
- result.m_blobFilePaths.reserveInitialCapacity(m_blobFilePaths.size());
- for (auto& path : m_blobFilePaths)
- result.m_blobFilePaths.uncheckedAppend(path.isolatedCopy());
-
</del><ins>+ result.setAsIsolatedCopy(*this);
</ins><span class="cx"> return result;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbIDBValueh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/IDBValue.h (201231 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/IDBValue.h        2016-05-20 22:53:35 UTC (rev 201231)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBValue.h        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -42,6 +42,7 @@
</span><span class="cx"> IDBValue(const ThreadSafeDataBuffer&, Vector<String>&& blobURLs, Vector<String>&& blobFilePaths);
</span><span class="cx"> IDBValue(const ThreadSafeDataBuffer&, const Vector<String>& blobURLs, const Vector<String>& blobFilePaths);
</span><span class="cx">
</span><ins>+ void setAsIsolatedCopy(const IDBValue&);
</ins><span class="cx"> IDBValue isolatedCopy() const;
</span><span class="cx">
</span><span class="cx"> const ThreadSafeDataBuffer& data() const { return m_data; }
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsSerializedScriptValuecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp (201231 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp        2016-05-20 22:53:35 UTC (rev 201231)
+++ trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -79,6 +79,7 @@
</span><span class="cx"> #include <runtime/TypedArrays.h>
</span><span class="cx"> #include <wtf/HashTraits.h>
</span><span class="cx"> #include <wtf/MainThread.h>
</span><ins>+#include <wtf/RunLoop.h>
</ins><span class="cx"> #include <wtf/Vector.h>
</span><span class="cx">
</span><span class="cx"> using namespace JSC;
</span><span class="lines">@@ -2816,6 +2817,33 @@
</span><span class="cx"> completionHandler({ *this, m_blobURLs, blobFilePaths });
</span><span class="cx"> });
</span><span class="cx"> }
</span><ins>+
+IDBValue SerializedScriptValue::writeBlobsToDiskForIndexedDBSynchronously()
+{
+ ASSERT(!isMainThread());
+
+ IDBValue value;
+ IDBValue* valuePtr = &value;
+
+ Lock lock;
+ Condition condition;
+ Condition* conditionPtr = &condition;
+ lock.lock();
+
+ RunLoop::main().dispatch([this, conditionPtr, valuePtr] {
+ writeBlobsToDiskForIndexedDB([conditionPtr, valuePtr](const IDBValue& result) {
+ ASSERT(isMainThread());
+ valuePtr->setAsIsolatedCopy(result);
+
+ conditionPtr->notifyAll();
+ });
+ });
+
+ condition.wait(lock);
+
+ return value;
+}
+
</ins><span class="cx"> #endif // ENABLE(INDEXED_DATABASE)
</span><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsSerializedScriptValueh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/SerializedScriptValue.h (201231 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/SerializedScriptValue.h        2016-05-20 22:53:35 UTC (rev 201231)
+++ trunk/Source/WebCore/bindings/js/SerializedScriptValue.h        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -87,6 +87,7 @@
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx"> Vector<String> blobURLsIsolatedCopy() const;
</span><span class="cx"> void writeBlobsToDiskForIndexedDB(std::function<void (const IDBValue&)> completionHandler);
</span><ins>+ IDBValue writeBlobsToDiskForIndexedDBSynchronously();
</ins><span class="cx"> #endif // ENABLE(INDEXED_DATABASE)
</span><span class="cx">
</span><span class="cx"> static Ref<SerializedScriptValue> createFromWireBytes(Vector<uint8_t>&& data)
</span></span></pre>
</div>
</div>
</body>
</html>