<!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>[280410] 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/280410">280410</a></dd>
<dt>Author</dt> <dd>sihui_liu@apple.com</dd>
<dt>Date</dt> <dd>2021-07-28 16:35:42 -0700 (Wed, 28 Jul 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>IDBFactory.databases should not return databases with invalid version
https://bugs.webkit.org/show_bug.cgi?id=228554

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/IndexedDB/get-databases.any-expected.txt:
* web-platform-tests/IndexedDB/get-databases.any.worker-expected.txt:

Source/WebCore:

To get database information, we used to open all database files and read from them. To avoid opening new
connection to databases that are already opened, and to ensure we get the latest information, for database that
is already opened, we should get its information from UniqueIDBDatabase directly. If database is not opened, we
open its file and read. By doing this, we also fix the issue that no databases are returned in private browsing
(since there is no file created).

Also, version 0 means the database is just created and has not finished version change transaction (version 1
is the first valid version according to spec), so we should not return databases with version 0.

Tests: storage/indexeddb/getdatabases-private.html
       storage/indexeddb/getdatabases.html

* Modules/indexeddb/server/IDBBackingStore.h:
* Modules/indexeddb/server/IDBServer.cpp:
(WebCore::IDBServer::getDatabaseNameAndVersionFromOriginDirectory):
(WebCore::IDBServer::IDBServer::getAllDatabaseNamesAndVersions):
* Modules/indexeddb/server/MemoryIDBBackingStore.h:
* Modules/indexeddb/server/SQLiteIDBBackingStore.h:
* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::didDeleteBackingStore):
(WebCore::IDBServer::UniqueIDBDatabase::filePath const):
(WebCore::IDBServer::UniqueIDBDatabase::nameAndVersion const):
* Modules/indexeddb/server/UniqueIDBDatabase.h:

LayoutTests:

* storage/indexeddb/getdatabases-expected.txt: Added.
* storage/indexeddb/getdatabases-private-expected.txt: Added.
* storage/indexeddb/getdatabases-private.html: Added.
* storage/indexeddb/getdatabases.html: Added.
* storage/indexeddb/resources/getdatabases.js: Added.
(test):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsIndexedDBgetdatabasesanyexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/get-databases.any-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsIndexedDBgetdatabasesanyworkerexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/get-databases.any.worker-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBBackingStoreh">trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBServercpp">trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverMemoryIDBBackingStoreh">trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStoreh">trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabasecpp">trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabaseh">trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsstorageindexeddbgetdatabasesexpectedtxt">trunk/LayoutTests/storage/indexeddb/getdatabases-expected.txt</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbgetdatabasesprivateexpectedtxt">trunk/LayoutTests/storage/indexeddb/getdatabases-private-expected.txt</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbgetdatabasesprivatehtml">trunk/LayoutTests/storage/indexeddb/getdatabases-private.html</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbgetdatabaseshtml">trunk/LayoutTests/storage/indexeddb/getdatabases.html</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbresourcesgetdatabasesjs">trunk/LayoutTests/storage/indexeddb/resources/getdatabases.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (280409 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2021-07-28 23:33:04 UTC (rev 280409)
+++ trunk/LayoutTests/ChangeLog 2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2021-07-28  Sihui Liu  <sihui_liu@apple.com>
+
+        IDBFactory.databases should not return databases with invalid version
+        https://bugs.webkit.org/show_bug.cgi?id=228554
+
+        Reviewed by Chris Dumez.
+
+        * storage/indexeddb/getdatabases-expected.txt: Added.
+        * storage/indexeddb/getdatabases-private-expected.txt: Added.
+        * storage/indexeddb/getdatabases-private.html: Added.
+        * storage/indexeddb/getdatabases.html: Added.
+        * storage/indexeddb/resources/getdatabases.js: Added.
+        (test):
+
</ins><span class="cx"> 2021-07-28  Ayumi Kojima  <ayumi_kojima@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [ iPad ] platform/ipad/media/modern-media-controls/media-documents/media-document-audio-ios-sizing.html is a flaky timeout.
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (280409 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-07-28 23:33:04 UTC (rev 280409)
+++ trunk/LayoutTests/imported/w3c/ChangeLog    2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2021-07-28  Sihui Liu  <sihui_liu@apple.com>
+
+        IDBFactory.databases should not return databases with invalid version
+        https://bugs.webkit.org/show_bug.cgi?id=228554
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/IndexedDB/get-databases.any-expected.txt:
+        * web-platform-tests/IndexedDB/get-databases.any.worker-expected.txt:
+
</ins><span class="cx"> 2021-07-28  Ayumi Kojima  <ayumi_kojima@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, reverting r280402.
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsIndexedDBgetdatabasesanyexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/get-databases.any-expected.txt (280409 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/get-databases.any-expected.txt       2021-07-28 23:33:04 UTC (rev 280409)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/get-databases.any-expected.txt  2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -3,5 +3,5 @@
</span><span class="cx"> PASS Enumerate one database.
</span><span class="cx"> PASS Enumerate multiple databases.
</span><span class="cx"> PASS Make sure an empty list is returned for the case of no databases.
</span><del>-FAIL Ensure that databases() doesn't pick up changes that haven't commited. assert_equals: The result of databases() should be only those databases which have been created at the time of calling, regardless of versionchange transactions currently running. expected 1 but got 2
</del><ins>+PASS Ensure that databases() doesn't pick up changes that haven't commited.
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsIndexedDBgetdatabasesanyworkerexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/get-databases.any.worker-expected.txt (280409 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/get-databases.any.worker-expected.txt        2021-07-28 23:33:04 UTC (rev 280409)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/get-databases.any.worker-expected.txt   2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -3,5 +3,5 @@
</span><span class="cx"> PASS Enumerate one database.
</span><span class="cx"> PASS Enumerate multiple databases.
</span><span class="cx"> PASS Make sure an empty list is returned for the case of no databases.
</span><del>-FAIL Ensure that databases() doesn't pick up changes that haven't commited. assert_equals: The result of databases() should be only those databases which have been created at the time of calling, regardless of versionchange transactions currently running. expected 1 but got 2
</del><ins>+PASS Ensure that databases() doesn't pick up changes that haven't commited.
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbgetdatabasesexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/getdatabases-expected.txt (0 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/getdatabases-expected.txt                            (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/getdatabases-expected.txt       2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+Ensure all databases can be retrieved
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+indexedDB.open('getdatabase-first')
+PASS databases.length is 0
+indexedDB.open('getdatabase-second', 2)
+PASS databases.length is 1
+PASS databases[0].version is 1
+PASS databases[0].name is "getdatabase-first"
+PASS databases.length is 2
+PASS databases[1].version is 2
+PASS databases[1].name is "getdatabase-second"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbgetdatabasesprivateexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/getdatabases-private-expected.txt (0 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/getdatabases-private-expected.txt                            (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/getdatabases-private-expected.txt       2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+Ensure all databases can be retrieved
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+indexedDB.open('getdatabase-first')
+PASS databases.length is 0
+indexedDB.open('getdatabase-second', 2)
+PASS databases.length is 1
+PASS databases[0].version is 1
+PASS databases[0].name is "getdatabase-first"
+PASS databases.length is 2
+PASS databases[1].version is 2
+PASS databases[1].name is "getdatabase-second"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbgetdatabasesprivatehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/getdatabases-private.html (0 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/getdatabases-private.html                            (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/getdatabases-private.html       2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+<!-- webkit-test-runner [ useEphemeralSession=true ] -->
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+<script src="resources/shared.js"></script>
+</head>
+<body>
+<script src="resources/getdatabases.js"></script>
+</body>
+</html>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbgetdatabaseshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/getdatabases.html (0 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/getdatabases.html                            (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/getdatabases.html       2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -0,0 +1,9 @@
</span><ins>+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+<script src="resources/shared.js"></script>
+</head>
+<body>
+<script src="resources/getdatabases.js"></script>
+</body>
+</html>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbresourcesgetdatabasesjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/resources/getdatabases.js (0 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/resources/getdatabases.js                            (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/resources/getdatabases.js       2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -0,0 +1,45 @@
</span><ins>+if (this.importScripts) {
+    importScripts('../../../resources/js-test.js');
+    importScripts('shared.js');
+}
+
+description("Ensure all databases can be retrieved");
+
+var databases;
+
+function test() {
+    indexedDB.deleteDatabase('getdatabase-first');
+    indexedDB.deleteDatabase('getdatabase-second');
+
+    request = evalAndLog("indexedDB.open('getdatabase-first')");
+    request.onupgradeneeded = () => {
+        indexedDB.databases().then((result)=> {
+            databases = result;
+            shouldBeEqualToNumber("databases.length", 0);
+            continueTest();
+        });
+    }
+}
+
+function continueTest() {
+    request = evalAndLog("indexedDB.open('getdatabase-second', 2)");
+    request.onupgradeneeded = () => {
+        indexedDB.databases().then((result) => {
+            databases = result;
+            shouldBeEqualToNumber("databases.length", 1);
+            shouldBeEqualToNumber("databases[0].version", 1)
+            shouldBeEqualToString("databases[0].name", "getdatabase-first");
+        });
+    }
+    request.onsuccess = () => {
+        indexedDB.databases().then((result) => {
+            databases = result;
+            shouldBeEqualToNumber("databases.length", 2);
+            shouldBeEqualToNumber("databases[1].version", 2);
+            shouldBeEqualToString("databases[1].name", "getdatabase-second");
+            finishJSTest();
+        });
+    }
+}
+
+test();
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (280409 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-07-28 23:33:04 UTC (rev 280409)
+++ trunk/Source/WebCore/ChangeLog      2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2021-07-28  Sihui Liu  <sihui_liu@apple.com>
+
+        IDBFactory.databases should not return databases with invalid version
+        https://bugs.webkit.org/show_bug.cgi?id=228554
+
+        Reviewed by Chris Dumez.
+
+        To get database information, we used to open all database files and read from them. To avoid opening new 
+        connection to databases that are already opened, and to ensure we get the latest information, for database that 
+        is already opened, we should get its information from UniqueIDBDatabase directly. If database is not opened, we 
+        open its file and read. By doing this, we also fix the issue that no databases are returned in private browsing
+        (since there is no file created).
+
+        Also, version 0 means the database is just created and has not finished version change transaction (version 1 
+        is the first valid version according to spec), so we should not return databases with version 0.
+
+        Tests: storage/indexeddb/getdatabases-private.html
+               storage/indexeddb/getdatabases.html
+
+        * Modules/indexeddb/server/IDBBackingStore.h:
+        * Modules/indexeddb/server/IDBServer.cpp:
+        (WebCore::IDBServer::getDatabaseNameAndVersionFromOriginDirectory):
+        (WebCore::IDBServer::IDBServer::getAllDatabaseNamesAndVersions):
+        * Modules/indexeddb/server/MemoryIDBBackingStore.h:
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.h:
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::didDeleteBackingStore):
+        (WebCore::IDBServer::UniqueIDBDatabase::filePath const):
+        (WebCore::IDBServer::UniqueIDBDatabase::nameAndVersion const):
+        * Modules/indexeddb/server/UniqueIDBDatabase.h:
+
</ins><span class="cx"> 2021-07-28  Myles C. Maxfield  <mmaxfield@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [GPU Process] Start tracking resource uses for ImageBuffers
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h (280409 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h  2021-07-28 23:33:04 UTC (rev 280409)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h     2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -91,6 +91,7 @@
</span><span class="cx"> 
</span><span class="cx">     virtual bool supportsSimultaneousTransactions() = 0;
</span><span class="cx">     virtual bool isEphemeral() = 0;
</span><ins>+    virtual String fullDatabasePath() const = 0;
</ins><span class="cx"> 
</span><span class="cx">     virtual void close() = 0;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp (280409 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp      2021-07-28 23:33:04 UTC (rev 280409)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp 2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -508,33 +508,47 @@
</span><span class="cx">         m_uniqueIDBDatabaseMap.remove(uniqueIDBDatabase->identifier());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void getDatabaseNameAndVersionFromOriginDirectory(const String& directory, HashSet<String>& excludedDatabasePaths, Vector<IDBDatabaseNameAndVersion>& result)
+{
+    Vector<String> databaseDirectoryNames = FileSystem::listDirectory(directory);
+    for (auto& databaseDirectoryName : databaseDirectoryNames) {
+        auto fullDatabasePath = SQLiteIDBBackingStore::fullDatabasePathForDirectory(FileSystem::pathByAppendingComponent(directory, databaseDirectoryName));
+        if (excludedDatabasePaths.contains(fullDatabasePath))
+            continue;
+
+        if (auto nameAndVersion = SQLiteIDBBackingStore::databaseNameAndVersionFromFile(fullDatabasePath))
+            result.append(WTFMove(*nameAndVersion));
+    }
+}
+
</ins><span class="cx"> void IDBServer::getAllDatabaseNamesAndVersions(IDBConnectionIdentifier serverConnectionIdentifier, const IDBResourceIdentifier& requestIdentifier, const ClientOrigin& origin)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!isMainThread());
</span><span class="cx">     ASSERT(m_lock.isHeld());
</span><span class="cx"> 
</span><del>-    String oldDirectory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, m_databaseDirectoryPath, "v0");
-    Vector<String> fileNames = FileSystem::listDirectory(oldDirectory);
-    Vector<IDBDatabaseNameAndVersion> databases;
-    for (auto& fileName : fileNames) {
-        auto databaseTuple = SQLiteIDBBackingStore::databaseNameAndVersionFromFile(SQLiteIDBBackingStore::fullDatabasePathForDirectory(FileSystem::pathByAppendingComponent(oldDirectory, fileName)));
-        if (databaseTuple)
-            databases.append(WTFMove(*databaseTuple));
</del><ins>+    Vector<IDBDatabaseNameAndVersion> result;
+    HashSet<String> visitedDatabasePaths;
+
+    for (auto& database : m_uniqueIDBDatabaseMap.values()) {
+        auto path = database->filePath();
+        if (!path.isEmpty())
+            visitedDatabasePaths.add(path);
+
+        if (auto nameAndVersion = database->nameAndVersion())
+            result.append(WTFMove(*nameAndVersion));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    String oldDirectory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, m_databaseDirectoryPath, "v0");
+    getDatabaseNameAndVersionFromOriginDirectory(oldDirectory, visitedDatabasePaths, result);
+
</ins><span class="cx">     String directory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, m_databaseDirectoryPath, "v1");
</span><del>-    fileNames = FileSystem::listDirectory(directory);
-    for (auto& fileName : fileNames) {
-        auto databaseTuple = SQLiteIDBBackingStore::databaseNameAndVersionFromFile(SQLiteIDBBackingStore::fullDatabasePathForDirectory(FileSystem::pathByAppendingComponent(directory, fileName)));
-        if (databaseTuple)
-            databases.append(WTFMove(*databaseTuple));
-    }
</del><ins>+    getDatabaseNameAndVersionFromOriginDirectory(directory, visitedDatabasePaths, result);
</ins><span class="cx"> 
</span><span class="cx">     auto connection = m_connectionMap.get(serverConnectionIdentifier);
</span><span class="cx">     if (!connection)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    connection->didGetAllDatabaseNamesAndVersions(requestIdentifier, WTFMove(databases));
</del><ins>+    connection->didGetAllDatabaseNamesAndVersions(requestIdentifier, WTFMove(result));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static void collectOriginsForVersion(const String& versionPath, HashSet<WebCore::SecurityOriginData>& securityOrigins)
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverMemoryIDBBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h (280409 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h    2021-07-28 23:33:04 UTC (rev 280409)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h       2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -80,6 +80,7 @@
</span><span class="cx"> 
</span><span class="cx">     bool supportsSimultaneousTransactions() final { return true; }
</span><span class="cx">     bool isEphemeral() final { return true; }
</span><ins>+    String fullDatabasePath() const final { return nullString(); }
</ins><span class="cx"> 
</span><span class="cx">     bool hasTransaction(const IDBResourceIdentifier& identifier) const final { return m_transactions.contains(identifier); }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h (280409 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h    2021-07-28 23:33:04 UTC (rev 280409)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h       2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -86,6 +86,7 @@
</span><span class="cx"> 
</span><span class="cx">     bool supportsSimultaneousTransactions() final { return false; }
</span><span class="cx">     bool isEphemeral() final { return false; }
</span><ins>+    String fullDatabasePath() const final;
</ins><span class="cx"> 
</span><span class="cx">     bool hasTransaction(const IDBResourceIdentifier&) const final;
</span><span class="cx"> 
</span><span class="lines">@@ -103,7 +104,6 @@
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     String filenameForDatabaseName() const;
</span><del>-    String fullDatabasePath() const;
</del><span class="cx">     String fullDatabaseDirectoryWithUpgrade();
</span><span class="cx"> 
</span><span class="cx">     IDBError ensureValidRecordsTable();
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp (280409 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp      2021-07-28 23:33:04 UTC (rev 280409)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp 2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -312,7 +312,7 @@
</span><span class="cx">     ASSERT(m_currentOpenDBRequest->isDeleteRequest());
</span><span class="cx"> 
</span><span class="cx">     if (m_databaseInfo)
</span><del>-        m_mostRecentDeletedDatabaseInfo = WTFMove(m_databaseInfo);
</del><ins>+        m_mostRecentDeletedDatabaseInfo = std::exchange(m_databaseInfo, nullptr);
</ins><span class="cx"> 
</span><span class="cx">     // If this UniqueIDBDatabase was brought into existence for the purpose of deleting the file on disk,
</span><span class="cx">     // we won't have a m_mostRecentDeletedDatabaseInfo. In that case, we'll manufacture one using the
</span><span class="lines">@@ -1240,5 +1240,30 @@
</span><span class="cx">     return nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+String UniqueIDBDatabase::filePath() const
+{
+    return m_backingStore ? m_backingStore->fullDatabasePath() : nullString();
+}
+
+std::optional<IDBDatabaseNameAndVersion> UniqueIDBDatabase::nameAndVersion() const
+{
+    if (!m_backingStore)
+        return std::nullopt;
+
+    if (m_versionChangeTransaction) {
+        if (auto databaseInfo = m_versionChangeTransaction->originalDatabaseInfo()) {
+            // The database is newly created.
+            if (!databaseInfo->version())
+                return std::nullopt;
+
+            return IDBDatabaseNameAndVersion { databaseInfo->name(), databaseInfo->version() };
+        }
+
+        return std::nullopt;
+    }
+
+    return IDBDatabaseNameAndVersion { m_databaseInfo->name(), m_databaseInfo->version() };
+}
+
</ins><span class="cx"> } // namespace IDBServer
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h (280409 => 280410)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h        2021-07-28 23:33:04 UTC (rev 280409)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h   2021-07-28 23:35:42 UTC (rev 280410)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> #include "IDBBackingStore.h"
</span><span class="cx"> #include "IDBDatabaseIdentifier.h"
</span><span class="cx"> #include "IDBDatabaseInfo.h"
</span><ins>+#include "IDBDatabaseNameAndVersion.h"
</ins><span class="cx"> #include "IDBGetResult.h"
</span><span class="cx"> #include "ServerOpenDBRequest.h"
</span><span class="cx"> #include "UniqueIDBDatabaseTransaction.h"
</span><span class="lines">@@ -111,6 +112,9 @@
</span><span class="cx">     void abortActiveTransactions();
</span><span class="cx">     bool tryClose();
</span><span class="cx"> 
</span><ins>+    String filePath() const;
+    std::optional<IDBDatabaseNameAndVersion> nameAndVersion() const;
+
</ins><span class="cx"> private:
</span><span class="cx">     void handleDatabaseOperations();
</span><span class="cx">     void handleCurrentOperation();
</span></span></pre>
</div>
</div>

</body>
</html>