<!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>[197372] 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/197372">197372</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2016-02-29 15:13:35 -0800 (Mon, 29 Feb 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Modern IDB: WebKit 2 IPC layer easily confused about multiple web processes being connected.
https://bugs.webkit.org/show_bug.cgi?id=154837

Reviewed by Alex Christensen.

Source/WebKit2:

The crux of the bug is that WebProcesses cannot assign themselves server-unique identifiers...
The server must do that for them.

A once-per-session-per-WebProcess sync message and a few updates to connection management fix this.

* DatabaseProcess/DatabaseToWebProcessConnection.cpp:
(WebKit::DatabaseToWebProcessConnection::didReceiveSyncMessage):
(WebKit::generateConnectionToServerIdentifier):
(WebKit::DatabaseToWebProcessConnection::establishIDBConnectionToServer):
* DatabaseProcess/DatabaseToWebProcessConnection.h:
* DatabaseProcess/DatabaseToWebProcessConnection.messages.in:

* WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp:
(WebKit::WebIDBConnectionToServer::WebIDBConnectionToServer):
(WebKit::generateConnectionToServerIdentifier): Deleted.

* WebProcess/Databases/WebToDatabaseProcessConnection.cpp:
(WebKit::WebToDatabaseProcessConnection::didReceiveMessage):
(WebKit::WebToDatabaseProcessConnection::idbConnectionToServerForSession):
* WebProcess/Databases/WebToDatabaseProcessConnection.h:

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess-1.html: Added.
* TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess-2.html: Added.
* TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess.mm: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2DatabaseProcessDatabaseToWebProcessConnectioncpp">trunk/Source/WebKit2/DatabaseProcess/DatabaseToWebProcessConnection.cpp</a></li>
<li><a href="#trunkSourceWebKit2DatabaseProcessDatabaseToWebProcessConnectionh">trunk/Source/WebKit2/DatabaseProcess/DatabaseToWebProcessConnection.h</a></li>
<li><a href="#trunkSourceWebKit2DatabaseProcessDatabaseToWebProcessConnectionmessagesin">trunk/Source/WebKit2/DatabaseProcess/DatabaseToWebProcessConnection.messages.in</a></li>
<li><a href="#trunkSourceWebKit2WebProcessDatabasesIndexedDBWebIDBConnectionToServercpp">trunk/Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessDatabasesWebToDatabaseProcessConnectioncpp">trunk/Source/WebKit2/WebProcess/Databases/WebToDatabaseProcessConnection.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessDatabasesWebToDatabaseProcessConnectionh">trunk/Source/WebKit2/WebProcess/Databases/WebToDatabaseProcessConnection.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2CocoaIndexedDBMultiProcess1html">trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess-1.html</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2CocoaIndexedDBMultiProcess2html">trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess-2.html</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2CocoaIndexedDBMultiProcessmm">trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (197371 => 197372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-02-29 23:06:58 UTC (rev 197371)
+++ trunk/Source/WebKit2/ChangeLog        2016-02-29 23:13:35 UTC (rev 197372)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2016-02-29  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Modern IDB: WebKit 2 IPC layer easily confused about multiple web processes being connected.
+        https://bugs.webkit.org/show_bug.cgi?id=154837
+
+        Reviewed by Alex Christensen.
+
+        The crux of the bug is that WebProcesses cannot assign themselves server-unique identifiers...
+        The server must do that for them.
+        
+        A once-per-session-per-WebProcess sync message and a few updates to connection management fix this.
+        
+        * DatabaseProcess/DatabaseToWebProcessConnection.cpp:
+        (WebKit::DatabaseToWebProcessConnection::didReceiveSyncMessage):
+        (WebKit::generateConnectionToServerIdentifier):
+        (WebKit::DatabaseToWebProcessConnection::establishIDBConnectionToServer):
+        * DatabaseProcess/DatabaseToWebProcessConnection.h:
+        * DatabaseProcess/DatabaseToWebProcessConnection.messages.in:
+
+        * WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp:
+        (WebKit::WebIDBConnectionToServer::WebIDBConnectionToServer):
+        (WebKit::generateConnectionToServerIdentifier): Deleted.
+
+        * WebProcess/Databases/WebToDatabaseProcessConnection.cpp:
+        (WebKit::WebToDatabaseProcessConnection::didReceiveMessage):
+        (WebKit::WebToDatabaseProcessConnection::idbConnectionToServerForSession):
+        * WebProcess/Databases/WebToDatabaseProcessConnection.h:
+
</ins><span class="cx"> 2016-02-29  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Don't call NetworkProcess::singleton from WebProcess when using NetworkSession
</span></span></pre></div>
<a id="trunkSourceWebKit2DatabaseProcessDatabaseToWebProcessConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/DatabaseProcess/DatabaseToWebProcessConnection.cpp (197371 => 197372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/DatabaseProcess/DatabaseToWebProcessConnection.cpp        2016-02-29 23:06:58 UTC (rev 197371)
+++ trunk/Source/WebKit2/DatabaseProcess/DatabaseToWebProcessConnection.cpp        2016-02-29 23:13:35 UTC (rev 197372)
</span><span class="lines">@@ -72,6 +72,16 @@
</span><span class="cx">     ASSERT_NOT_REACHED();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void DatabaseToWebProcessConnection::didReceiveSyncMessage(IPC::Connection&amp; connection, IPC::MessageDecoder&amp; decoder, std::unique_ptr&lt;IPC::MessageEncoder&gt;&amp; replyEncoder)
+{
+    if (decoder.messageReceiverName() == Messages::DatabaseToWebProcessConnection::messageReceiverName()) {
+        didReceiveSyncDatabaseToWebProcessConnectionMessage(connection, decoder, replyEncoder);
+        return;
+    }
+
+    ASSERT_NOT_REACHED();
+}
+
</ins><span class="cx"> void DatabaseToWebProcessConnection::didClose(IPC::Connection&amp;)
</span><span class="cx"> {
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="lines">@@ -85,8 +95,17 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><del>-void DatabaseToWebProcessConnection::establishIDBConnectionToServer(uint64_t serverConnectionIdentifier)
</del><ins>+
+static uint64_t generateConnectionToServerIdentifier()
</ins><span class="cx"> {
</span><ins>+    ASSERT(RunLoop::isMain());
+    static uint64_t identifier = 0;
+    return ++identifier;
+}
+
+void DatabaseToWebProcessConnection::establishIDBConnectionToServer(uint64_t&amp; serverConnectionIdentifier)
+{
+    serverConnectionIdentifier = generateConnectionToServerIdentifier();
</ins><span class="cx">     LOG(IndexedDB, &quot;DatabaseToWebProcessConnection::establishIDBConnectionToServer - %&quot; PRIu64, serverConnectionIdentifier);
</span><span class="cx">     ASSERT(!m_webIDBConnections.contains(serverConnectionIdentifier));
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2DatabaseProcessDatabaseToWebProcessConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/DatabaseProcess/DatabaseToWebProcessConnection.h (197371 => 197372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/DatabaseProcess/DatabaseToWebProcessConnection.h        2016-02-29 23:06:58 UTC (rev 197371)
+++ trunk/Source/WebKit2/DatabaseProcess/DatabaseToWebProcessConnection.h        2016-02-29 23:13:35 UTC (rev 197372)
</span><span class="lines">@@ -49,11 +49,13 @@
</span><span class="cx"> 
</span><span class="cx">     // IPC::Connection::Client
</span><span class="cx">     virtual void didReceiveMessage(IPC::Connection&amp;, IPC::MessageDecoder&amp;) override;
</span><ins>+    virtual void didReceiveSyncMessage(IPC::Connection&amp;, IPC::MessageDecoder&amp;, std::unique_ptr&lt;IPC::MessageEncoder&gt;&amp;) override;
</ins><span class="cx">     virtual void didClose(IPC::Connection&amp;) override;
</span><span class="cx">     virtual void didReceiveInvalidMessage(IPC::Connection&amp;, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
</span><span class="cx">     virtual IPC::ProcessType localProcessType() override { return IPC::ProcessType::Database; }
</span><span class="cx">     virtual IPC::ProcessType remoteProcessType() override { return IPC::ProcessType::Web; }
</span><span class="cx">     void didReceiveDatabaseToWebProcessConnectionMessage(IPC::Connection&amp;, IPC::MessageDecoder&amp;);
</span><ins>+    void didReceiveSyncDatabaseToWebProcessConnectionMessage(IPC::Connection&amp;, IPC::MessageDecoder&amp;, std::unique_ptr&lt;IPC::MessageEncoder&gt;&amp;);
</ins><span class="cx"> 
</span><span class="cx">     // IPC::MessageSender
</span><span class="cx">     virtual IPC::Connection* messageSenderConnection() override { return m_connection.get(); }
</span><span class="lines">@@ -61,7 +63,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx">     // Messages handlers (Modern IDB)
</span><del>-    void establishIDBConnectionToServer(uint64_t serverConnectionIdentifier);
</del><ins>+    void establishIDBConnectionToServer(uint64_t&amp; serverConnectionIdentifier);
</ins><span class="cx">     void removeIDBConnectionToServer(uint64_t serverConnectionIdentifier);
</span><span class="cx"> 
</span><span class="cx">     HashMap&lt;uint64_t, RefPtr&lt;WebIDBConnectionToClient&gt;&gt; m_webIDBConnections;
</span></span></pre></div>
<a id="trunkSourceWebKit2DatabaseProcessDatabaseToWebProcessConnectionmessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/DatabaseProcess/DatabaseToWebProcessConnection.messages.in (197371 => 197372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/DatabaseProcess/DatabaseToWebProcessConnection.messages.in        2016-02-29 23:06:58 UTC (rev 197371)
+++ trunk/Source/WebKit2/DatabaseProcess/DatabaseToWebProcessConnection.messages.in        2016-02-29 23:13:35 UTC (rev 197372)
</span><span class="lines">@@ -25,7 +25,7 @@
</span><span class="cx"> messages -&gt; DatabaseToWebProcessConnection LegacyReceiver {
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx">     # Creates a connection for communication with a WebProcess
</span><del>-    EstablishIDBConnectionToServer(uint64_t serverConnectionIdentifier)
</del><ins>+    EstablishIDBConnectionToServer() -&gt; (uint64_t serverConnectionIdentifier)
</ins><span class="cx">     RemoveIDBConnectionToServer(uint64_t serverConnectionIdentifier)
</span><span class="cx"> #endif
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessDatabasesIndexedDBWebIDBConnectionToServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp (197371 => 197372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp        2016-02-29 23:06:58 UTC (rev 197371)
+++ trunk/Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp        2016-02-29 23:13:35 UTC (rev 197372)
</span><span class="lines">@@ -49,27 +49,17 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-static uint64_t generateConnectionToServerIdentifier()
-{
-    ASSERT(RunLoop::isMain());
-    static uint64_t identifier = 0;
-    return ++identifier;
-}
-
</del><span class="cx"> Ref&lt;WebIDBConnectionToServer&gt; WebIDBConnectionToServer::create()
</span><span class="cx"> {
</span><span class="cx">     return adoptRef(*new WebIDBConnectionToServer);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> WebIDBConnectionToServer::WebIDBConnectionToServer()
</span><del>-    : m_identifier(generateConnectionToServerIdentifier())
</del><span class="cx"> {
</span><span class="cx">     relaxAdoptionRequirement();
</span><span class="cx">     m_connectionToServer = IDBClient::IDBConnectionToServer::create(*this);
</span><span class="cx"> 
</span><del>-    send(Messages::DatabaseToWebProcessConnection::EstablishIDBConnectionToServer(m_identifier));
-
-    m_isOpenInServer = true;
</del><ins>+    m_isOpenInServer = sendSync(Messages::DatabaseToWebProcessConnection::EstablishIDBConnectionToServer(), m_identifier);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> WebIDBConnectionToServer::~WebIDBConnectionToServer()
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessDatabasesWebToDatabaseProcessConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Databases/WebToDatabaseProcessConnection.cpp (197371 => 197372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Databases/WebToDatabaseProcessConnection.cpp        2016-02-29 23:06:58 UTC (rev 197371)
+++ trunk/Source/WebKit2/WebProcess/Databases/WebToDatabaseProcessConnection.cpp        2016-02-29 23:13:35 UTC (rev 197372)
</span><span class="lines">@@ -52,8 +52,8 @@
</span><span class="cx"> {
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx">     if (decoder.messageReceiverName() == Messages::WebIDBConnectionToServer::messageReceiverName()) {
</span><del>-        auto iterator = m_webIDBConnections.find(decoder.destinationID());
-        if (iterator != m_webIDBConnections.end())
</del><ins>+        auto iterator = m_webIDBConnectionsByIdentifier.find(decoder.destinationID());
+        if (iterator != m_webIDBConnectionsByIdentifier.end())
</ins><span class="cx">             iterator-&gt;value-&gt;didReceiveMessage(connection, decoder);
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="lines">@@ -74,9 +74,12 @@
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx"> WebIDBConnectionToServer&amp; WebToDatabaseProcessConnection::idbConnectionToServerForSession(const SessionID&amp; sessionID)
</span><span class="cx"> {
</span><del>-    auto result = m_webIDBConnections.add(sessionID.sessionID(), nullptr);
-    if (result.isNewEntry)
</del><ins>+    auto result = m_webIDBConnectionsBySession.add(sessionID, nullptr);
+    if (result.isNewEntry) {
</ins><span class="cx">         result.iterator-&gt;value = WebIDBConnectionToServer::create();
</span><ins>+        ASSERT(!m_webIDBConnectionsByIdentifier.contains(result.iterator-&gt;value-&gt;identifier()));
+        m_webIDBConnectionsByIdentifier.set(result.iterator-&gt;value-&gt;identifier(), result.iterator-&gt;value);
+    }
</ins><span class="cx"> 
</span><span class="cx">     return *result.iterator-&gt;value;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessDatabasesWebToDatabaseProcessConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Databases/WebToDatabaseProcessConnection.h (197371 => 197372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Databases/WebToDatabaseProcessConnection.h        2016-02-29 23:06:58 UTC (rev 197371)
+++ trunk/Source/WebKit2/WebProcess/Databases/WebToDatabaseProcessConnection.h        2016-02-29 23:13:35 UTC (rev 197372)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> #include &quot;Connection.h&quot;
</span><span class="cx"> #include &quot;MessageSender.h&quot;
</span><span class="cx"> #include &quot;WebIDBConnectionToServer.h&quot;
</span><ins>+#include &lt;WebCore/SessionID.h&gt;
</ins><span class="cx"> #include &lt;wtf/RefCounted.h&gt;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(DATABASE_PROCESS)
</span><span class="lines">@@ -71,7 +72,8 @@
</span><span class="cx">     RefPtr&lt;IPC::Connection&gt; m_connection;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><del>-    HashMap&lt;uint64_t, RefPtr&lt;WebIDBConnectionToServer&gt;&gt; m_webIDBConnections;
</del><ins>+    HashMap&lt;WebCore::SessionID, RefPtr&lt;WebIDBConnectionToServer&gt;&gt; m_webIDBConnectionsBySession;
+    HashMap&lt;uint64_t, RefPtr&lt;WebIDBConnectionToServer&gt;&gt; m_webIDBConnectionsByIdentifier;
</ins><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (197371 => 197372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-02-29 23:06:58 UTC (rev 197371)
+++ trunk/Tools/ChangeLog        2016-02-29 23:13:35 UTC (rev 197372)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-02-29  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Modern IDB: WebKit 2 IPC layer easily confused about multiple web processes being connected.
+        https://bugs.webkit.org/show_bug.cgi?id=154837
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess-1.html: Added.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess-2.html: Added.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess.mm: Added.
+
</ins><span class="cx"> 2016-02-29  Joanmarie Diggs  &lt;jdiggs@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK][jhbuild] GLib build fails with GCC 6.0
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (197371 => 197372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2016-02-29 23:06:58 UTC (rev 197371)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2016-02-29 23:13:35 UTC (rev 197372)
</span><span class="lines">@@ -66,6 +66,9 @@
</span><span class="cx">                 51B1EE961C80FAEF0064FB98 /* IndexedDBPersistence-1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51B1EE941C80FADD0064FB98 /* IndexedDBPersistence-1.html */; };
</span><span class="cx">                 51B1EE971C80FAEF0064FB98 /* IndexedDBPersistence-2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51B1EE951C80FADD0064FB98 /* IndexedDBPersistence-2.html */; };
</span><span class="cx">                 51B454EC1B4E236B0085EAA6 /* WebViewCloseInsideDidFinishLoadForFrame.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51B454EB1B4E236B0085EAA6 /* WebViewCloseInsideDidFinishLoadForFrame.mm */; };
</span><ins>+                51BCEE4A1C84F4AF0042C82E /* IndexedDBMultiProcess.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51BCEE491C84F4AF0042C82E /* IndexedDBMultiProcess.mm */; };
+                51BCEE4E1C84F53B0042C82E /* IndexedDBMultiProcess-1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51BCEE4C1C84F52C0042C82E /* IndexedDBMultiProcess-1.html */; };
+                51BCEE4F1C84F53B0042C82E /* IndexedDBMultiProcess-2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51BCEE4D1C84F52C0042C82E /* IndexedDBMultiProcess-2.html */; };
</ins><span class="cx">                 51CB4AD81B3A079C00C1B1C6 /* ModalAlertsSPI.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51CB4AD71B3A079C00C1B1C6 /* ModalAlertsSPI.cpp */; };
</span><span class="cx">                 51CD1C6C1B38CE4300142CA5 /* ModalAlerts.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51CD1C6A1B38CE3600142CA5 /* ModalAlerts.mm */; };
</span><span class="cx">                 51CD1C721B38D48400142CA5 /* modal-alerts-in-new-about-blank-window.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51CD1C711B38D48400142CA5 /* modal-alerts-in-new-about-blank-window.html */; };
</span><span class="lines">@@ -395,6 +398,8 @@
</span><span class="cx">                         dstPath = TestWebKitAPI.resources;
</span><span class="cx">                         dstSubfolderSpec = 7;
</span><span class="cx">                         files = (
</span><ins>+                                51BCEE4E1C84F53B0042C82E /* IndexedDBMultiProcess-1.html in Copy Resources */,
+                                51BCEE4F1C84F53B0042C82E /* IndexedDBMultiProcess-2.html in Copy Resources */,
</ins><span class="cx">                                 51B1EE961C80FAEF0064FB98 /* IndexedDBPersistence-1.html in Copy Resources */,
</span><span class="cx">                                 51B1EE971C80FAEF0064FB98 /* IndexedDBPersistence-2.html in Copy Resources */,
</span><span class="cx">                                 57F56A5C1C7F8CC100F31D7E /* IsNavigationActionTrusted.html in Copy Resources */,
</span><span class="lines">@@ -598,6 +603,9 @@
</span><span class="cx">                 51B1EE941C80FADD0064FB98 /* IndexedDBPersistence-1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;IndexedDBPersistence-1.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 51B1EE951C80FADD0064FB98 /* IndexedDBPersistence-2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;IndexedDBPersistence-2.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 51B454EB1B4E236B0085EAA6 /* WebViewCloseInsideDidFinishLoadForFrame.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebViewCloseInsideDidFinishLoadForFrame.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                51BCEE491C84F4AF0042C82E /* IndexedDBMultiProcess.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = IndexedDBMultiProcess.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
+                51BCEE4C1C84F52C0042C82E /* IndexedDBMultiProcess-1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;IndexedDBMultiProcess-1.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
+                51BCEE4D1C84F52C0042C82E /* IndexedDBMultiProcess-2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;IndexedDBMultiProcess-2.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 51CB4AD71B3A079C00C1B1C6 /* ModalAlertsSPI.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ModalAlertsSPI.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 51CD1C6A1B38CE3600142CA5 /* ModalAlerts.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ModalAlerts.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 51CD1C711B38D48400142CA5 /* modal-alerts-in-new-about-blank-window.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = &quot;modal-alerts-in-new-about-blank-window.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -981,6 +989,7 @@
</span><span class="cx">                                 A1A4FE5D18DD3DB700B5EA8A /* Download.mm */,
</span><span class="cx">                                 2D8104CB1BEC13E70020DA46 /* FindInPage.mm */,
</span><span class="cx">                                 2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */,
</span><ins>+                                51BCEE491C84F4AF0042C82E /* IndexedDBMultiProcess.mm */,
</ins><span class="cx">                                 51B1EE8D1C80F5880064FB98 /* IndexedDBPersistence.mm */,
</span><span class="cx">                                 37D36ED61AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm */,
</span><span class="cx">                                 51CD1C6A1B38CE3600142CA5 /* ModalAlerts.mm */,
</span><span class="lines">@@ -1075,6 +1084,8 @@
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><span class="cx">                                 A16F66B91C40EA2000BD4D24 /* ContentFiltering.html */,
</span><ins>+                                51BCEE4C1C84F52C0042C82E /* IndexedDBMultiProcess-1.html */,
+                                51BCEE4D1C84F52C0042C82E /* IndexedDBMultiProcess-2.html */,
</ins><span class="cx">                                 51B1EE941C80FADD0064FB98 /* IndexedDBPersistence-1.html */,
</span><span class="cx">                                 51B1EE951C80FADD0064FB98 /* IndexedDBPersistence-2.html */,
</span><span class="cx">                         );
</span><span class="lines">@@ -1893,6 +1904,7 @@
</span><span class="cx">                                 2D8104CC1BEC13E70020DA46 /* FindInPage.mm in Sources */,
</span><span class="cx">                                 CD225C081C45A69200140761 /* ParsedContentRange.cpp in Sources */,
</span><span class="cx">                                 41973B5D1AF22875006C7B36 /* SharedBuffer.cpp in Sources */,
</span><ins>+                                51BCEE4A1C84F4AF0042C82E /* IndexedDBMultiProcess.mm in Sources */,
</ins><span class="cx">                                 57F10D931C7E7B3800ECDF30 /* IsNavigationActionTrusted.mm in Sources */,
</span><span class="cx">                                 2DD355361BD08378005DF4A7 /* AutoLayoutIntegration.mm in Sources */,
</span><span class="cx">                                 7AA6A1521AAC0B31002B2ED3 /* WorkQueue.cpp in Sources */,
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2CocoaIndexedDBMultiProcess1html"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess-1.html (0 => 197372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess-1.html                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess-1.html        2016-02-29 23:13:35 UTC (rev 197372)
</span><span class="lines">@@ -0,0 +1,46 @@
</span><ins>+&lt;script&gt;
+
+var request = window.indexedDB.deleteDatabase(&quot;IndexedDBMultiProcess&quot;);
+request.onsuccess = function(e)
+{
+    continueTest();
+}
+request.onerror = function(e)
+{
+    // Unexpected error
+    window.webkit.messageHandlers.testHandler.postMessage('Error opening database');
+}
+
+function continueTest()
+{
+    var request = window.indexedDB.open(&quot;IndexedDBMultiProcess&quot;, 2);
+
+    request.onsuccess = function()
+    {
+        window.webkit.messageHandlers.testHandler.postMessage('Success');
+    }
+
+    request.onerror = function()
+    {
+        // Unexpected error
+        window.webkit.messageHandlers.testHandler.postMessage('Error');
+    }
+
+    request.onupgradeneeded = function(event)
+    {
+        window.webkit.messageHandlers.testHandler.postMessage('UpgradeNeeded');
+
+        var store = event.target.result.createObjectStore(&quot;TestObjectStore&quot;);
+
+        event.target.transaction.oncomplete = function() {
+            window.webkit.messageHandlers.testHandler.postMessage('Transaction complete');
+        }
+
+        event.target.transaction.onerror = function() {
+            window.webkit.messageHandlers.testHandler.postMessage('Transaction errored!');
+        }
+
+        store.put(&quot;bar&quot;, &quot;foo&quot;);
+    }
+}
+&lt;/script&gt;
</ins></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2CocoaIndexedDBMultiProcess2html"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess-2.html (0 => 197372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess-2.html                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess-2.html        2016-02-29 23:13:35 UTC (rev 197372)
</span><span class="lines">@@ -0,0 +1,32 @@
</span><ins>+&lt;script&gt;
+
+var request = window.indexedDB.open(&quot;IndexedDBMultiProcess&quot;, 2);
+
+request.onsuccess = function(event)
+{
+    var req = event.target.result.transaction(&quot;TestObjectStore&quot;).objectStore(&quot;TestObjectStore&quot;).get(&quot;foo&quot;);
+
+    req.onsuccess = function(event)
+    {
+        window.webkit.messageHandlers.testHandler.postMessage('Value of foo: ' + req.result);
+    }
+
+    req.onerror = function(event)
+    {
+        // Unexpected error
+        window.webkit.messageHandlers.testHandler.postMessage('Unexpected error');
+    }
+}
+
+request.onerror = function()
+{
+    // Unexpected error
+    window.webkit.messageHandlers.testHandler.postMessage('Unexpected error');
+}
+
+request.onupgradeneeded = function(event)
+{
+    // Unexpected upgrade needed
+    window.webkit.messageHandlers.testHandler.postMessage('Unexpected UpgradeNeeded');
+}
+&lt;/script&gt;
</ins></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2CocoaIndexedDBMultiProcessmm"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess.mm (0 => 197372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess.mm                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess.mm        2016-02-29 23:13:35 UTC (rev 197372)
</span><span class="lines">@@ -0,0 +1,90 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &quot;config.h&quot;
+
+#import &quot;PlatformUtilities.h&quot;
+#import &quot;Test.h&quot;
+#import &lt;WebKit/WebKit.h&gt;
+#import &lt;WebKit/WKProcessPoolPrivate.h&gt;
+#import &lt;WebKit/WKUserContentControllerPrivate.h&gt;
+#import &lt;WebKit/_WKProcessPoolConfiguration.h&gt;
+#import &lt;WebKit/_WKUserStyleSheet.h&gt;
+#import &lt;wtf/RetainPtr.h&gt;
+
+#if WK_API_ENABLED
+
+static bool receivedScriptMessage;
+static RetainPtr&lt;WKScriptMessage&gt; lastScriptMessage;
+
+@interface IndexedDBMPMessageHandler : NSObject &lt;WKScriptMessageHandler&gt;
+@end
+
+@implementation IndexedDBMPMessageHandler
+
+- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
+{
+    receivedScriptMessage = true;
+    lastScriptMessage = message;
+}
+
+@end
+
+TEST(IndexedDB, IndexedDBMultiProcess)
+{
+    RetainPtr&lt;IndexedDBMPMessageHandler&gt; handler = adoptNS([[IndexedDBMPMessageHandler alloc] init]);
+    RetainPtr&lt;WKWebViewConfiguration&gt; configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@&quot;testHandler&quot;];
+    [configuration.get().processPool _terminateDatabaseProcess];
+
+    RetainPtr&lt;WKWebView&gt; webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@&quot;IndexedDBMultiProcess-1&quot; withExtension:@&quot;html&quot; subdirectory:@&quot;TestWebKitAPI.resources&quot;]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&amp;receivedScriptMessage);
+    receivedScriptMessage = false;
+    RetainPtr&lt;NSString&gt; string1 = (NSString *)[lastScriptMessage body];
+
+    TestWebKitAPI::Util::run(&amp;receivedScriptMessage);
+    receivedScriptMessage = false;
+    RetainPtr&lt;NSString&gt; string2 = (NSString *)[lastScriptMessage body];
+
+    // Make a new web view with a new web process to finish the test
+    RetainPtr&lt;WKWebView&gt; webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@&quot;IndexedDBMultiProcess-2&quot; withExtension:@&quot;html&quot; subdirectory:@&quot;TestWebKitAPI.resources&quot;]];
+    [webView2 loadRequest:request];
+
+    TestWebKitAPI::Util::run(&amp;receivedScriptMessage);
+    receivedScriptMessage = false;
+    RetainPtr&lt;NSString&gt; string3 = (NSString *)[lastScriptMessage body];
+
+    EXPECT_WK_STREQ(@&quot;UpgradeNeeded&quot;, string1.get());
+    EXPECT_WK_STREQ(@&quot;Transaction complete&quot;, string2.get());
+    EXPECT_WK_STREQ(@&quot;Value of foo: bar&quot;, string3.get());
+}
+
+#endif
</ins></span></pre>
</div>
</div>

</body>
</html>