Title: [238330] trunk
Revision
238330
Author
joep...@webkit.org
Date
2018-11-16 17:28:41 -0800 (Fri, 16 Nov 2018)

Log Message

Web Inspector: Keep Web Inspector window alive across process swaps (PSON) (Local Inspector)
https://bugs.webkit.org/show_bug.cgi?id=191740
<rdar://problem/45470897>

Reviewed by Timothy Hatcher.

Source/_javascript_Core:

* inspector/InspectorFrontendChannel.h:
Expose EnumTraits for ConnectionType for WebKit IPC messages.

Source/WebInspectorUI:

* UserInterface/Protocol/Connection.js:
(InspectorBackend.Connection.prototype._dispatchResponse):
Hide the TargetAgent does not exist message. This is necessary so that WebKitLegacy
tests don't include this line in output each test.

* UserInterface/Test.html:
* UserInterface/Test/Test.js:
(WI.loaded):
(WI.resetMainExecutionContext):
(WI.performOneTimeFrontendInitializationsUsingTarget):
Behave more like Main.js and initialize a MultiplexingBackendTarget when the
TargetAgent is available.

* UserInterface/Protocol/InspectorBackend.js:
(InspectorBackendClass.prototype.runAfterPendingDispatches):
Use the main target, a.k.a. the page connection. The backend target's
messages don't have any responses, so this was effectively not waiting
at all.

Source/WebKit:

When a web page asks to open a local Web Inspector, that inspector
will now connect in the UIProcess (WebPageProxy / WebPageInspectorController)
instead of the WebContentProcess (WebKit::WebInspector / InspectorController).

Previously a WebInspectorProxy was re-created every time the WebPageProxy's
WebPage / WebProcess was changed, effectively closing the Web Inspector
frontend when the WebPage was swapped or crashed.

This change keeps the WebInspectorProxy alive as long as the WebPageProxy
is alive. During process swaps, or process crashes, the WebInspectorProxy
is reset when the page is reset and updated when the page's WebProcess
changes. Since WebInspectorProxy owns the Web Inspector view / window
the Web Inspector window can be kept alive across (and attached state)
across WebPage / WebProcess changes.

Previously the WebContentProcess's WebKit::WebInspector was the Local
FrontendChannel for the WebCore::InspectorController. This can't
outlive the single WebContentProcess.

This change makes the UIProcesses' WebInspectorProxy the Local FrontendChannel
for the WebKit::WebPageInspectorController. Given the WebInspectorProxy
now stays alive alongside the WebPageProxy this will live across process changes.
This means that the WebInspectorUI process must send its backend messages to
the WebInspectorProxy -> WebPageInspectorController now instead of the
old path WebInspector -> WebCore::InspectorController.

A direct IPC connection is still maintained between the WebContentProcess's
WebKit::WebInspector and the InspectorProcess's WebInspectorUI. Previously
this connection was established by WebKit::WebInspector vending an
IPC::Attachment to the WebInspectorUI process. This patch inverts that
relationship, because the WebInspectorUI process now lives across multiple
WebContentProcess changes. The WebInspectorUI now vends the IPC::Attachment
to the WebContentProcess each time the process changes. This way they can both
still communicate through normal Messages::WebInspector/WebInspectorUI
messages and everything behaves as previously expected.

* Scripts/webkit/messages.py:
Header for Inspector::FrontendChannel::ConnectionType.

* WebProcess/WebCoreSupport/WebInspectorClient.cpp:
(WebKit::WebInspectorClient::openLocalFrontend):
* WebProcess/WebPage/WebInspector.cpp:
(WebKit::WebInspector::openLocalInspectorFrontend):
(WebKit::WebInspector::setFrontendConnection):
(WebKit::WebInspector::closeFrontendConnection):
(WebKit::WebInspector::close):
(WebKit::WebInspector::openFrontendConnection): Deleted.
(WebKit::WebInspector::sendMessageToBackend): Deleted.
(WebKit::WebInspector::sendMessageToFrontend): Deleted.
On the WebProcess side we ask the UIProcess to open a local frontend and now
receive instead of vend an IPC connection to the WebInspectorUI process.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::finishAttachingToWebProcess):
(WebKit::WebPageProxy::close):
(WebKit::WebPageProxy::resetState):
Keep the WebInspectorProxy alive alongside the WebPageProxy.
Update it as processes / states change.

* UIProcess/WebInspectorProxy.h:
* UIProcess/WebInspectorProxy.messages.in:
* UIProcess/WebInspectorProxy.cpp:
(WebKit::WebInspectorProxy::openLocalInspectorFrontend):
(WebKit::WebInspectorProxy::createInspectorPage): Deleted.
(WebKit::WebInspectorProxy::sendMessageToFrontend):
(WebKit::WebInspectorProxy::closeFrontendPageAndWindow):
Open and close a local frontend by being the FrontendChannel on the UIProcess side.

(WebKit::WebInspectorProxy::sendMessageToBackend):
Dispatch WebInspectorUI backend messages to the UIProcess's InspectorController
now that the InspectorController is here instead of in the WebProcess.

(WebKit::WebInspectorProxy::setFrontendConnection):
Transfer the WebProcess <-> InspectorProcess IPC connection through us
because we are the one link between them when processes change.

(WebKit::WebInspectorProxy::invalidate):
(WebKit::WebInspectorProxy::frontendLoaded):
Be safer and handle inspectedPage being potentially null.

* WebProcess/WebPage/WebPageInspectorTargetController.cpp:
(WebKit::WebPageInspectorTargetController::connectInspector):
* WebProcess/WebPage/WebPageInspectorTargetController.h:
* WebProcess/WebPage/WebPageInspectorTargetFrontendChannel.cpp:
(WebKit::WebPageInspectorTargetFrontendChannel::create):
(WebKit::WebPageInspectorTargetFrontendChannel::WebPageInspectorTargetFrontendChannel):
* WebProcess/WebPage/WebPageInspectorTargetFrontendChannel.h:
* UIProcess/InspectorTargetProxy.cpp:
(WebKit::InspectorTargetProxy::connect):
Proxy the ConnectionType received on the UIProcess side to the WebProcess side
when connecting to sub-targets.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::connectInspector):
(WebKit::WebPage::setHasLocalInspectorFrontend): Deleted.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::hasLocalInspectorFrontend const): Deleted.
(WebKit::WebPageProxy::setHasLocalInspectorFrontend): Deleted.
* UIProcess/WebPageProxy.messages.in:
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::processForNavigationInternal):
Eliminate the hasLocalInspectorFrontend state that was only used
to disable PSON. PSON no longer needs to be disabled for this reason.

* WebProcess/WebPage/WebInspector.h:
* WebProcess/WebPage/WebInspector.messages.in:
* WebProcess/WebPage/WebInspectorUI.cpp:
(WebKit::WebInspectorUI::establishConnection):
(WebKit::WebInspectorUI::updateConnection):
(WebKit::WebInspectorUI::closeWindow):
(WebKit::WebInspectorUI::sendMessageToBackend):
* WebProcess/WebPage/WebInspectorUI.h:
* WebProcess/WebPage/WebInspectorUI.messages.in:
Vend an IPC connection on demand to the WebProcess side.

LayoutTests:

* inspector/unit-tests/target-manager-expected.txt:
* inspector/unit-tests/target-manager.html:
Update test to pass in both a MultiplexingBackendTarget and DirectBackendTarget world.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (238329 => 238330)


--- trunk/LayoutTests/ChangeLog	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/LayoutTests/ChangeLog	2018-11-17 01:28:41 UTC (rev 238330)
@@ -1,3 +1,15 @@
+2018-11-16  Joseph Pecoraro  <pecor...@apple.com>
+
+        Web Inspector: Keep Web Inspector window alive across process swaps (PSON) (Local Inspector)
+        https://bugs.webkit.org/show_bug.cgi?id=191740
+        <rdar://problem/45470897>
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/unit-tests/target-manager-expected.txt:
+        * inspector/unit-tests/target-manager.html:
+        Update test to pass in both a MultiplexingBackendTarget and DirectBackendTarget world.
+
 2018-11-16  Jeremy Jones  <jere...@apple.com>
 
         Include AirPlay destination name in AirPlay placard.

Modified: trunk/LayoutTests/inspector/unit-tests/target-manager-expected.txt (238329 => 238330)


--- trunk/LayoutTests/inspector/unit-tests/target-manager-expected.txt	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/LayoutTests/inspector/unit-tests/target-manager-expected.txt	2018-11-17 01:28:41 UTC (rev 238330)
@@ -6,7 +6,7 @@
 PASS: Targets list should always start out with the main target.
 PASS: Target list should always contain the main target.
 PASS: Main target should have an ExecutionContext.
-PASS: Main target should have the global RuntimeAgent.
+PASS: Main target should have the page target's RuntimeAgent.
 Target - Symbol(page) - Page
 
 -- Running test case: TargetManager.WorkerTarget.Create

Modified: trunk/LayoutTests/inspector/unit-tests/target-manager.html (238329 => 238330)


--- trunk/LayoutTests/inspector/unit-tests/target-manager.html	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/LayoutTests/inspector/unit-tests/target-manager.html	2018-11-17 01:28:41 UTC (rev 238330)
@@ -30,7 +30,7 @@
             InspectorTest.expectEqual(WI.targets.length, 1, "Targets list should always start out with the main target.");
             InspectorTest.expectEqual([...WI.targets][0], WI.mainTarget, "Target list should always contain the main target.");
             InspectorTest.expectNotNull(WI.mainTarget.executionContext, "Main target should have an ExecutionContext.");
-            InspectorTest.expectEqual(WI.mainTarget.RuntimeAgent, RuntimeAgent, "Main target should have the global RuntimeAgent.");
+            InspectorTest.expectEqual(WI.mainTarget.RuntimeAgent, WI.pageTarget.RuntimeAgent, "Main target should have the page target's RuntimeAgent.");
             dumpTargets();
         }
     });

Modified: trunk/Source/_javascript_Core/ChangeLog (238329 => 238330)


--- trunk/Source/_javascript_Core/ChangeLog	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/_javascript_Core/ChangeLog	2018-11-17 01:28:41 UTC (rev 238330)
@@ -1,3 +1,14 @@
+2018-11-16  Joseph Pecoraro  <pecor...@apple.com>
+
+        Web Inspector: Keep Web Inspector window alive across process swaps (PSON) (Local Inspector)
+        https://bugs.webkit.org/show_bug.cgi?id=191740
+        <rdar://problem/45470897>
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/InspectorFrontendChannel.h:
+        Expose EnumTraits for ConnectionType for WebKit IPC messages.
+
 2018-11-16  Filip Pizlo  <fpi...@apple.com>
 
         All users of ArrayBuffer should agree on the same max size

Modified: trunk/Source/_javascript_Core/inspector/InspectorFrontendChannel.h (238329 => 238330)


--- trunk/Source/_javascript_Core/inspector/InspectorFrontendChannel.h	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/_javascript_Core/inspector/InspectorFrontendChannel.h	2018-11-17 01:28:41 UTC (rev 238330)
@@ -46,3 +46,15 @@
 };
 
 } // namespace Inspector
+
+namespace WTF {
+
+template<> struct EnumTraits<Inspector::FrontendChannel::ConnectionType> {
+    using values = EnumValues<
+        Inspector::FrontendChannel::ConnectionType,
+        Inspector::FrontendChannel::ConnectionType::Remote,
+        Inspector::FrontendChannel::ConnectionType::Local
+    >;
+};
+
+} // namespace WTF

Modified: trunk/Source/WebInspectorUI/ChangeLog (238329 => 238330)


--- trunk/Source/WebInspectorUI/ChangeLog	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebInspectorUI/ChangeLog	2018-11-17 01:28:41 UTC (rev 238330)
@@ -1,3 +1,30 @@
+2018-11-16  Joseph Pecoraro  <pecor...@apple.com>
+
+        Web Inspector: Keep Web Inspector window alive across process swaps (PSON) (Local Inspector)
+        https://bugs.webkit.org/show_bug.cgi?id=191740
+        <rdar://problem/45470897>
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Protocol/Connection.js:
+        (InspectorBackend.Connection.prototype._dispatchResponse):
+        Hide the TargetAgent does not exist message. This is necessary so that WebKitLegacy
+        tests don't include this line in output each test.
+
+        * UserInterface/Test.html:
+        * UserInterface/Test/Test.js:
+        (WI.loaded):
+        (WI.resetMainExecutionContext):
+        (WI.performOneTimeFrontendInitializationsUsingTarget):
+        Behave more like Main.js and initialize a MultiplexingBackendTarget when the
+        TargetAgent is available.
+
+        * UserInterface/Protocol/InspectorBackend.js:
+        (InspectorBackendClass.prototype.runAfterPendingDispatches):
+        Use the main target, a.k.a. the page connection. The backend target's
+        messages don't have any responses, so this was effectively not waiting
+        at all.
+
 2018-11-16  Matt Baker  <mattba...@apple.com>
 
         Web Inspector: TreeOutline shouldn't select first child of an expanded element on right arrow key

Modified: trunk/Source/WebInspectorUI/UserInterface/Protocol/Connection.js (238329 => 238330)


--- trunk/Source/WebInspectorUI/UserInterface/Protocol/Connection.js	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebInspectorUI/UserInterface/Protocol/Connection.js	2018-11-17 01:28:41 UTC (rev 238330)
@@ -96,7 +96,8 @@
         console.assert(this._pendingResponses.size >= 0);
 
         if (messageObject["error"]) {
-            if (messageObject["error"].code !== -32000)
+            // FIXME: Eliminate Target.exists
+            if (messageObject["error"].code !== -32000 && messageObject["error"].message !== "'Target' domain was not found")
                 console.error("Request with id = " + messageObject["id"] + " failed. " + JSON.stringify(messageObject["error"]));
         }
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Protocol/InspectorBackend.js (238329 => 238330)


--- trunk/Source/WebInspectorUI/UserInterface/Protocol/InspectorBackend.js	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebInspectorUI/UserInterface/Protocol/InspectorBackend.js	2018-11-17 01:28:41 UTC (rev 238330)
@@ -163,7 +163,7 @@
     runAfterPendingDispatches(script)
     {
         // FIXME: Should this respect pending dispatches in all connections?
-        InspectorBackend.backendConnection.runAfterPendingDispatches(script);
+        WI.mainTarget.connection.runAfterPendingDispatches(script);
     }
 
     activateDomain(domainName, activationDebuggableTypes)

Modified: trunk/Source/WebInspectorUI/UserInterface/Test/Test.js (238329 => 238330)


--- trunk/Source/WebInspectorUI/UserInterface/Test/Test.js	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebInspectorUI/UserInterface/Test/Test.js	2018-11-17 01:28:41 UTC (rev 238330)
@@ -75,8 +75,11 @@
     WI.backendTarget = null;
     WI.pageTarget = null;
 
-    // Tests directly connect to a page target.
-    WI.targetManager.createDirectBackendTarget();
+    // FIXME: Eliminate `TargetAgent.exists`.
+    TargetAgent.exists((error) => {
+        if (error)
+            WI.targetManager.createDirectBackendTarget();
+    });
 };
 
 WI.initializeBackendTarget = function(target)
@@ -107,9 +110,11 @@
 
 WI.resetMainExecutionContext = function()
 {
-    console.assert(WI.mainTarget.executionContext);
+    if (WI.mainTarget instanceof WI.MultiplexingBackendTarget)
+        return;
 
-    WI.runtimeManager.activeExecutionContext = WI.mainTarget.executionContext;
+    if (WI.mainTarget.executionContext)
+        WI.runtimeManager.activeExecutionContext = WI.mainTarget.executionContext;
 };
 
 WI.redirectGlobalAgentsToConnection = function(connection)
@@ -138,6 +143,7 @@
         WI.consoleManager.initializeLogChannels(target);
     }
 
+    // FIXME: This slows down test debug logging considerably.
     if (!WI.__didPerformCSSInitialization && target.CSSAgent) {
         WI.__didPerformCSSInitialization = true;
         WI.CSSCompletions.initializeCSSCompletions(target);

Modified: trunk/Source/WebInspectorUI/UserInterface/Test.html (238329 => 238330)


--- trunk/Source/WebInspectorUI/UserInterface/Test.html	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebInspectorUI/UserInterface/Test.html	2018-11-17 01:28:41 UTC (rev 238330)
@@ -75,6 +75,8 @@
 
     <script src=""
     <script src=""
+    <script src=""
+    <script src=""
     <script src=""
 
     <script src=""

Modified: trunk/Source/WebKit/ChangeLog (238329 => 238330)


--- trunk/Source/WebKit/ChangeLog	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/ChangeLog	2018-11-17 01:28:41 UTC (rev 238330)
@@ -1,3 +1,128 @@
+2018-11-16  Joseph Pecoraro  <pecor...@apple.com>
+
+        Web Inspector: Keep Web Inspector window alive across process swaps (PSON) (Local Inspector)
+        https://bugs.webkit.org/show_bug.cgi?id=191740
+        <rdar://problem/45470897>
+
+        Reviewed by Timothy Hatcher.
+
+        When a web page asks to open a local Web Inspector, that inspector
+        will now connect in the UIProcess (WebPageProxy / WebPageInspectorController)
+        instead of the WebContentProcess (WebKit::WebInspector / InspectorController).
+
+        Previously a WebInspectorProxy was re-created every time the WebPageProxy's
+        WebPage / WebProcess was changed, effectively closing the Web Inspector
+        frontend when the WebPage was swapped or crashed.
+
+        This change keeps the WebInspectorProxy alive as long as the WebPageProxy
+        is alive. During process swaps, or process crashes, the WebInspectorProxy
+        is reset when the page is reset and updated when the page's WebProcess
+        changes. Since WebInspectorProxy owns the Web Inspector view / window
+        the Web Inspector window can be kept alive across (and attached state)
+        across WebPage / WebProcess changes.
+
+        Previously the WebContentProcess's WebKit::WebInspector was the Local
+        FrontendChannel for the WebCore::InspectorController. This can't
+        outlive the single WebContentProcess.
+
+        This change makes the UIProcesses' WebInspectorProxy the Local FrontendChannel
+        for the WebKit::WebPageInspectorController. Given the WebInspectorProxy
+        now stays alive alongside the WebPageProxy this will live across process changes.
+        This means that the WebInspectorUI process must send its backend messages to
+        the WebInspectorProxy -> WebPageInspectorController now instead of the
+        old path WebInspector -> WebCore::InspectorController.
+
+        A direct IPC connection is still maintained between the WebContentProcess's
+        WebKit::WebInspector and the InspectorProcess's WebInspectorUI. Previously
+        this connection was established by WebKit::WebInspector vending an
+        IPC::Attachment to the WebInspectorUI process. This patch inverts that
+        relationship, because the WebInspectorUI process now lives across multiple
+        WebContentProcess changes. The WebInspectorUI now vends the IPC::Attachment
+        to the WebContentProcess each time the process changes. This way they can both
+        still communicate through normal Messages::WebInspector/WebInspectorUI
+        messages and everything behaves as previously expected.
+
+        * Scripts/webkit/messages.py:
+        Header for Inspector::FrontendChannel::ConnectionType.
+
+        * WebProcess/WebCoreSupport/WebInspectorClient.cpp:
+        (WebKit::WebInspectorClient::openLocalFrontend):
+        * WebProcess/WebPage/WebInspector.cpp:
+        (WebKit::WebInspector::openLocalInspectorFrontend):
+        (WebKit::WebInspector::setFrontendConnection):
+        (WebKit::WebInspector::closeFrontendConnection):
+        (WebKit::WebInspector::close):
+        (WebKit::WebInspector::openFrontendConnection): Deleted.
+        (WebKit::WebInspector::sendMessageToBackend): Deleted.
+        (WebKit::WebInspector::sendMessageToFrontend): Deleted.
+        On the WebProcess side we ask the UIProcess to open a local frontend and now
+        receive instead of vend an IPC connection to the WebInspectorUI process.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::finishAttachingToWebProcess):
+        (WebKit::WebPageProxy::close):
+        (WebKit::WebPageProxy::resetState):
+        Keep the WebInspectorProxy alive alongside the WebPageProxy.
+        Update it as processes / states change.
+
+        * UIProcess/WebInspectorProxy.h:
+        * UIProcess/WebInspectorProxy.messages.in:
+        * UIProcess/WebInspectorProxy.cpp:
+        (WebKit::WebInspectorProxy::openLocalInspectorFrontend):
+        (WebKit::WebInspectorProxy::createInspectorPage): Deleted.
+        (WebKit::WebInspectorProxy::sendMessageToFrontend):
+        (WebKit::WebInspectorProxy::closeFrontendPageAndWindow):
+        Open and close a local frontend by being the FrontendChannel on the UIProcess side.
+
+        (WebKit::WebInspectorProxy::sendMessageToBackend):
+        Dispatch WebInspectorUI backend messages to the UIProcess's InspectorController
+        now that the InspectorController is here instead of in the WebProcess.
+
+        (WebKit::WebInspectorProxy::setFrontendConnection):
+        Transfer the WebProcess <-> InspectorProcess IPC connection through us
+        because we are the one link between them when processes change.
+
+        (WebKit::WebInspectorProxy::invalidate):
+        (WebKit::WebInspectorProxy::frontendLoaded):
+        Be safer and handle inspectedPage being potentially null.
+
+        * WebProcess/WebPage/WebPageInspectorTargetController.cpp:
+        (WebKit::WebPageInspectorTargetController::connectInspector):
+        * WebProcess/WebPage/WebPageInspectorTargetController.h:
+        * WebProcess/WebPage/WebPageInspectorTargetFrontendChannel.cpp:
+        (WebKit::WebPageInspectorTargetFrontendChannel::create):
+        (WebKit::WebPageInspectorTargetFrontendChannel::WebPageInspectorTargetFrontendChannel):
+        * WebProcess/WebPage/WebPageInspectorTargetFrontendChannel.h:
+        * UIProcess/InspectorTargetProxy.cpp:
+        (WebKit::InspectorTargetProxy::connect):
+        Proxy the ConnectionType received on the UIProcess side to the WebProcess side
+        when connecting to sub-targets.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::connectInspector):
+        (WebKit::WebPage::setHasLocalInspectorFrontend): Deleted.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::hasLocalInspectorFrontend const): Deleted.
+        (WebKit::WebPageProxy::setHasLocalInspectorFrontend): Deleted.
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::processForNavigationInternal):
+        Eliminate the hasLocalInspectorFrontend state that was only used
+        to disable PSON. PSON no longer needs to be disabled for this reason.
+
+        * WebProcess/WebPage/WebInspector.h:
+        * WebProcess/WebPage/WebInspector.messages.in:
+        * WebProcess/WebPage/WebInspectorUI.cpp:
+        (WebKit::WebInspectorUI::establishConnection):
+        (WebKit::WebInspectorUI::updateConnection):
+        (WebKit::WebInspectorUI::closeWindow):
+        (WebKit::WebInspectorUI::sendMessageToBackend):
+        * WebProcess/WebPage/WebInspectorUI.h:
+        * WebProcess/WebPage/WebInspectorUI.messages.in:
+        Vend an IPC connection on demand to the WebProcess side.
+
 2018-11-16  Michael Catanzaro  <mcatanz...@igalia.com>
 
         [GTK][WPE] Add "WebKitDeviceInfoPermissionRequest.h" into webkit2.h

Modified: trunk/Source/WebKit/Scripts/webkit/messages.py (238329 => 238330)


--- trunk/Source/WebKit/Scripts/webkit/messages.py	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/Scripts/webkit/messages.py	2018-11-17 01:28:41 UTC (rev 238330)
@@ -390,6 +390,7 @@
         'JSC::MessageLevel': ['<_javascript_Core/ConsoleTypes.h>'],
         'JSC::MessageSource': ['<_javascript_Core/ConsoleTypes.h>'],
         'Inspector::InspectorTargetType': ['<_javascript_Core/InspectorTarget.h>'],
+        'Inspector::FrontendChannel::ConnectionType': ['<_javascript_Core/InspectorFrontendChannel.h>'],
         'MonotonicTime': ['<wtf/MonotonicTime.h>'],
         'Seconds': ['<wtf/Seconds.h>'],
         'WallTime': ['<wtf/WallTime.h>'],

Modified: trunk/Source/WebKit/UIProcess/InspectorTargetProxy.cpp (238329 => 238330)


--- trunk/Source/WebKit/UIProcess/InspectorTargetProxy.cpp	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/UIProcess/InspectorTargetProxy.cpp	2018-11-17 01:28:41 UTC (rev 238330)
@@ -46,10 +46,10 @@
 {
 }
 
-void InspectorTargetProxy::connect(Inspector::FrontendChannel&)
+void InspectorTargetProxy::connect(Inspector::FrontendChannel& channel)
 {
     if (m_page.isValid())
-        m_page.process().send(Messages::WebPage::ConnectInspector(identifier()), m_page.pageID());
+        m_page.process().send(Messages::WebPage::ConnectInspector(identifier(), channel.connectionType()), m_page.pageID());
 }
 
 void InspectorTargetProxy::disconnect(Inspector::FrontendChannel&)

Modified: trunk/Source/WebKit/UIProcess/WebInspectorProxy.cpp (238329 => 238330)


--- trunk/Source/WebKit/UIProcess/WebInspectorProxy.cpp	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/UIProcess/WebInspectorProxy.cpp	2018-11-17 01:28:41 UTC (rev 238330)
@@ -36,6 +36,7 @@
 #include "WebInspectorProxyMessages.h"
 #include "WebInspectorUIMessages.h"
 #include "WebPageGroup.h"
+#include "WebPageInspectorController.h"
 #include "WebPageProxy.h"
 #include "WebPreferences.h"
 #include "WebProcessPool.h"
@@ -83,7 +84,8 @@
 
 void WebInspectorProxy::invalidate()
 {
-    m_inspectedPage->process().removeMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_inspectedPage->pageID());
+    if (m_inspectedPage)
+        m_inspectedPage->process().removeMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_inspectedPage->pageID());
 
     closeFrontendPageAndWindow();
     platformInvalidate();
@@ -91,6 +93,14 @@
     m_inspectedPage = nullptr;
 }
 
+void WebInspectorProxy::sendMessageToFrontend(const String& message)
+{
+    if (!m_inspectorPage)
+        return;
+
+    m_inspectorPage->process().send(Messages::WebInspectorUI::SendMessageToFrontend(message), m_inspectorPage->pageID());
+}
+
 // Public APIs
 bool WebInspectorProxy::isFront()
 {
@@ -160,6 +170,34 @@
     platformDidCloseForCrash();
 }
 
+void WebInspectorProxy::reset()
+{
+    if (m_inspectedPage) {
+        m_inspectedPage->process().removeMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_inspectedPage->pageID());
+        m_inspectedPage = nullptr;
+    }
+}
+
+void WebInspectorProxy::updateForNewPageProcess(WebPageProxy* inspectedPage)
+{
+    ASSERT(!m_inspectedPage);
+    ASSERT(inspectedPage);
+
+    m_inspectedPage = inspectedPage;
+    m_inspectedPage->process().addMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_inspectedPage->pageID(), *this);
+
+    if (m_inspectorPage)
+        m_inspectorPage->process().send(Messages::WebInspectorUI::UpdateConnection(), m_inspectorPage->pageID());
+}
+
+void WebInspectorProxy::setFrontendConnection(IPC::Attachment connectionIdentifier)
+{
+    if (!m_inspectedPage)
+        return;
+
+    m_inspectedPage->process().send(Messages::WebInspector::SetFrontendConnection(connectionIdentifier), m_inspectedPage->pageID());
+}
+
 void WebInspectorProxy::showConsole()
 {
     if (!m_inspectedPage)
@@ -340,12 +378,16 @@
     m_inspectorPage->process().assumeReadAccessToBaseURL(WebInspectorProxy::inspectorBaseURL());
 }
 
-// Called by WebInspectorProxy messages
-void WebInspectorProxy::createInspectorPage(IPC::Attachment connectionIdentifier, bool canAttach, bool underTest)
+void WebInspectorProxy::openLocalInspectorFrontend(bool canAttach, bool underTest)
 {
     if (!m_inspectedPage)
         return;
 
+    if (m_inspectedPage->inspectorController().hasLocalFrontend()) {
+        show();
+        return;
+    }
+
     m_underTest = underTest;
     createFrontendPage();
 
@@ -353,8 +395,10 @@
     if (!m_inspectorPage)
         return;
 
-    m_inspectorPage->process().send(Messages::WebInspectorUI::EstablishConnection(WTFMove(connectionIdentifier), m_inspectedPage->pageID(), m_underTest, inspectionLevel()), m_inspectorPage->pageID());
+    m_inspectorPage->process().send(Messages::WebInspectorUI::EstablishConnection(m_inspectedPage->pageID(), m_underTest, inspectionLevel()), m_inspectorPage->pageID());
 
+    m_inspectedPage->inspectorController().connectFrontend(*this);
+
     if (!m_underTest) {
         m_canAttach = platformCanAttach(canAttach);
         m_isAttached = shouldOpenAttached();
@@ -425,6 +469,8 @@
     m_inspectorPage->process().send(Messages::WebInspectorUI::SetIsVisible(m_isVisible), m_inspectorPage->pageID());
     m_inspectorPage->process().removeMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_inspectedPage->pageID());
 
+    m_inspectedPage->inspectorController().disconnectFrontend(*this);
+
     if (m_isAttached)
         platformDetach();
 
@@ -438,8 +484,19 @@
     platformCloseFrontendPageAndWindow();
 }
 
+void WebInspectorProxy::sendMessageToBackend(const String& message)
+{
+    if (!m_inspectedPage)
+        return;
+
+    m_inspectedPage->inspectorController().dispatchMessageFromFrontend(message);
+}
+
 void WebInspectorProxy::frontendLoaded()
 {
+    if (!m_inspectedPage)
+        return;
+
     if (auto* automationSession = m_inspectedPage->process().processPool().automationSession())
         automationSession->inspectorFrontendLoaded(*m_inspectedPage);
 }

Modified: trunk/Source/WebKit/UIProcess/WebInspectorProxy.h (238329 => 238330)


--- trunk/Source/WebKit/UIProcess/WebInspectorProxy.h	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/UIProcess/WebInspectorProxy.h	2018-11-17 01:28:41 UTC (rev 238330)
@@ -30,6 +30,7 @@
 #include "Attachment.h"
 #include "MessageReceiver.h"
 #include "WebInspectorUtilities.h"
+#include <_javascript_Core/InspectorFrontendChannel.h>
 #include <wtf/Forward.h>
 #include <wtf/RefPtr.h>
 #include <wtf/text/WTFString.h>
@@ -70,6 +71,7 @@
 class WebInspectorProxy
     : public API::ObjectImpl<API::Object::Type::Inspector>
     , public IPC::MessageReceiver
+    , public Inspector::FrontendChannel
 #if PLATFORM(WIN)
     , public WebCore::WindowMessageListener
 #endif
@@ -98,6 +100,9 @@
     void close();
     void closeForCrash();
 
+    void reset();
+    void updateForNewPageProcess(WebPageProxy*);
+
 #if PLATFORM(MAC) && WK_API_ENABLED
     static RetainPtr<NSWindow> createFrontendWindow(NSRect savedWindowFrame);
 
@@ -167,6 +172,10 @@
     // IPC::MessageReceiver
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
 
+    // Inspector::FrontendChannel
+    void sendMessageToFrontend(const String& message) override;
+    ConnectionType connectionType() const override { return ConnectionType::Local; }
+
     WebPageProxy* platformCreateFrontendPage();
     void platformCreateFrontendWindow();
     void platformCloseFrontendPageAndWindow();
@@ -196,7 +205,10 @@
 #endif
 
     // Called by WebInspectorProxy messages
-    void createInspectorPage(IPC::Attachment, bool canAttach, bool underTest);
+    void openLocalInspectorFrontend(bool canAttach, bool underTest);
+    void setFrontendConnection(IPC::Attachment);
+
+    void sendMessageToBackend(const String&);
     void frontendLoaded();
     void didClose();
     void bringToFront();

Modified: trunk/Source/WebKit/UIProcess/WebInspectorProxy.messages.in (238329 => 238330)


--- trunk/Source/WebKit/UIProcess/WebInspectorProxy.messages.in	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/UIProcess/WebInspectorProxy.messages.in	2018-11-17 01:28:41 UTC (rev 238330)
@@ -21,8 +21,11 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 messages -> WebInspectorProxy {
-    CreateInspectorPage(IPC::Attachment connectionIdentifier, bool canAttach, bool underTest)
+    OpenLocalInspectorFrontend(bool canAttach, bool underTest)
+    SetFrontendConnection(IPC::Attachment connectionIdentifier)
 
+    SendMessageToBackend(String message)
+
     FrontendLoaded()
     DidClose()
     BringToFront()

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (238329 => 238330)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2018-11-17 01:28:41 UTC (rev 238330)
@@ -800,7 +800,6 @@
     updateActivityState();
     updateThrottleState();
 
-    m_inspector = WebInspectorProxy::create(this);
 #if ENABLE(FULLSCREEN_API)
     m_fullScreenManager = std::make_unique<WebFullScreenManagerProxy>(*this, pageClient().fullScreenManagerProxyClient());
 #endif
@@ -823,6 +822,8 @@
 
     initializeWebPage(shouldDelayAttachingDrawingArea);
 
+    m_inspector->updateForNewPageProcess(this);
+
 #if ENABLE(REMOTE_INSPECTOR)
     remoteInspectorInformationDidChange();
 #endif
@@ -939,6 +940,9 @@
     m_activeContextMenu = nullptr;
 #endif
 
+    m_inspector->invalidate();
+    m_inspector = nullptr;
+
     m_backForwardList->pageClosed();
     m_inspectorController->pageClosed();
     pageClient().pageClosed();
@@ -6250,10 +6254,7 @@
     }
     closeOverlayedViews();
 
-    if (m_inspector) {
-        m_inspector->invalidate();
-        m_inspector = nullptr;
-    }
+    m_inspector->reset();
 
 #if ENABLE(FULLSCREEN_API)
     if (m_fullScreenManager) {
@@ -6283,8 +6284,6 @@
 
     m_toolTip = String();
 
-    m_inspectorHasLocalFrontend = false;
-
     m_mainFrameHasHorizontalScrollbar = false;
     m_mainFrameHasVerticalScrollbar = false;
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (238329 => 238330)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-11-17 01:28:41 UTC (rev 238330)
@@ -380,9 +380,6 @@
 
     WebInspectorProxy* inspector() const;
 
-    bool hasLocalInspectorFrontend() const { return m_inspectorHasLocalFrontend; }
-    void setHasLocalInspectorFrontend(bool hasLocalFrontend) { m_inspectorHasLocalFrontend = hasLocalFrontend; }
-
     void didChangeInspectorFrontendCount(unsigned count) { m_inspectorFrontendCount = count; }
     unsigned inspectorFrontendCount() const { return m_inspectorFrontendCount; }
 
@@ -2117,7 +2114,6 @@
     bool m_controlledByAutomation { false };
 
     unsigned m_inspectorFrontendCount { 0 };
-    bool m_inspectorHasLocalFrontend { false };
 
 #if PLATFORM(COCOA)
     bool m_isSmartInsertDeleteEnabled { false };

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (238329 => 238330)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2018-11-17 01:28:41 UTC (rev 238330)
@@ -418,7 +418,6 @@
     DisableInspectorNodeSearch()
 #endif
 
-    SetHasLocalInspectorFrontend(bool hasLocalFrontend)
     DidChangeInspectorFrontendCount(uint64_t count)
 
     CreateInspectorTarget(String targetId, enum:uint8_t Inspector::InspectorTargetType type)

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (238329 => 238330)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-11-17 01:28:41 UTC (rev 238330)
@@ -2136,12 +2136,6 @@
         return page.process();
     }
 
-    // FIXME: We should support process swap with a local web inspector.
-    if (page.hasLocalInspectorFrontend()) {
-        reason = "A Local Web Inspector frontend is connected"_s;
-        return page.process();
-    }
-
     if (m_automationSession) {
         reason = "An automation session is active"_s;
         return page.process();

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebInspectorClient.cpp (238329 => 238330)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebInspectorClient.cpp	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebInspectorClient.cpp	2018-11-17 01:28:41 UTC (rev 238330)
@@ -90,9 +90,9 @@
 
 Inspector::FrontendChannel* WebInspectorClient::openLocalFrontend(InspectorController* controller)
 {
-    m_page->inspector()->openFrontendConnection(controller->isUnderTest());
+    m_page->inspector()->openLocalInspectorFrontend(controller->isUnderTest());
 
-    return m_page->inspector();
+    return nullptr;
 }
 
 void WebInspectorClient::bringFrontendToFront()

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebInspector.cpp (238329 => 238330)


--- trunk/Source/WebKit/WebProcess/WebPage/WebInspector.cpp	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebInspector.cpp	2018-11-17 01:28:41 UTC (rev 238330)
@@ -70,46 +70,35 @@
         m_frontendConnection->invalidate();
 }
 
-// Called from WebInspectorClient
-void WebInspector::openFrontendConnection(bool underTest)
+void WebInspector::openLocalInspectorFrontend(bool underTest)
 {
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::OpenLocalInspectorFrontend(canAttachWindow(), underTest), m_page->pageID());
+}
+
+void WebInspector::setFrontendConnection(IPC::Attachment encodedConnectionIdentifier)
+{
+    ASSERT(!m_frontendConnection);
+
 #if USE(UNIX_DOMAIN_SOCKETS)
-    IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection();
-    IPC::Connection::Identifier connectionIdentifier(socketPair.server);
-    IPC::Attachment connectionClientPort(socketPair.client);
+    IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.releaseFileDescriptor());
 #elif OS(DARWIN)
-    mach_port_t listeningPort = MACH_PORT_NULL;
-    if (mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &listeningPort) != KERN_SUCCESS)
-        CRASH();
-
-    if (mach_port_insert_right(mach_task_self(), listeningPort, listeningPort, MACH_MSG_TYPE_MAKE_SEND) != KERN_SUCCESS)
-        CRASH();
-
-    IPC::Connection::Identifier connectionIdentifier(listeningPort);
-    IPC::Attachment connectionClientPort(listeningPort, MACH_MSG_TYPE_MOVE_SEND);
-#elif PLATFORM(WIN)
-    IPC::Connection::Identifier connectionIdentifier, connClient;
-    IPC::Connection::createServerAndClientIdentifiers(connectionIdentifier, connClient);
-    IPC::Attachment connectionClientPort(connClient);
+    IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.port());
+#elif OS(WINDOWS)
+    IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.handle());
 #else
     notImplemented();
     return;
 #endif
 
-#if USE(UNIX_DOMAIN_SOCKETS) || OS(DARWIN) || PLATFORM(WIN)
-    m_frontendConnection = IPC::Connection::createServerConnection(connectionIdentifier, *this);
+    if (!IPC::Connection::identifierIsValid(connectionIdentifier))
+        return;
+
+    m_frontendConnection = IPC::Connection::createClientConnection(connectionIdentifier, *this);
     m_frontendConnection->open();
-
-    m_page->setHasLocalInspectorFrontend(true);
-
-    WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::CreateInspectorPage(connectionClientPort, canAttachWindow(), underTest), m_page->pageID());
-#endif
 }
 
 void WebInspector::closeFrontendConnection()
 {
-    m_page->setHasLocalInspectorFrontend(false);
-
     WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::DidClose(), m_page->pageID());
 
     // If we tried to close the frontend before it was created, then no connection exists yet.
@@ -145,7 +134,6 @@
     if (!m_frontendConnection)
         return;
 
-    m_page->corePage()->inspectorController().disconnectFrontend(*this);
     closeFrontendConnection();
 }
 
@@ -289,17 +277,4 @@
     WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::AttachAvailabilityChanged(canAttachWindow), m_page->pageID());
 }
 
-void WebInspector::sendMessageToBackend(const String& message)
-{
-    if (!m_page->corePage())
-        return;
-
-    m_page->corePage()->inspectorController().dispatchMessageFromFrontend(message);
-}
-
-void WebInspector::sendMessageToFrontend(const String& message)
-{
-    m_frontendConnection->send(Messages::WebInspectorUI::SendMessageToFrontend(message), 0);
-}
-
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebInspector.h (238329 => 238330)


--- trunk/Source/WebKit/WebProcess/WebPage/WebInspector.h	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebInspector.h	2018-11-17 01:28:41 UTC (rev 238330)
@@ -28,7 +28,6 @@
 #include "APIObject.h"
 #include "Connection.h"
 #include "MessageReceiver.h"
-#include <_javascript_Core/InspectorFrontendChannel.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/text/WTFString.h>
 
@@ -36,7 +35,7 @@
 
 class WebPage;
 
-class WebInspector : public API::ObjectImpl<API::Object::Type::BundleInspector>, private IPC::Connection::Client, public Inspector::FrontendChannel {
+class WebInspector : public API::ObjectImpl<API::Object::Type::BundleInspector>, private IPC::Connection::Client {
 public:
     static Ref<WebInspector> create(WebPage*);
 
@@ -44,9 +43,6 @@
 
     void updateDockingAvailability();
 
-    void sendMessageToFrontend(const String& message) override;
-    ConnectionType connectionType() const override { return ConnectionType::Local; }
-
     // Implemented in generated WebInspectorMessageReceiver.cpp
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
 
@@ -78,7 +74,7 @@
     void stopElementSelection();
     void elementSelectionChanged(bool);
 
-    void sendMessageToBackend(const String&);
+    void setFrontendConnection(IPC::Attachment);
 
     void disconnectFromPage() { close(); }
 
@@ -91,7 +87,7 @@
     bool canAttachWindow();
 
     // Called from WebInspectorClient
-    void openFrontendConnection(bool underTest);
+    void openLocalInspectorFrontend(bool underTest);
     void closeFrontendConnection();
 
     void bringToFront();

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebInspector.messages.in (238329 => 238330)


--- trunk/Source/WebKit/WebProcess/WebPage/WebInspector.messages.in	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebInspector.messages.in	2018-11-17 01:28:41 UTC (rev 238330)
@@ -40,5 +40,5 @@
     StartElementSelection()
     StopElementSelection()
 
-    SendMessageToBackend(String message)
+    SetFrontendConnection(IPC::Attachment connectionIdentifier)
 }

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebInspectorUI.cpp (238329 => 238330)


--- trunk/Source/WebKit/WebProcess/WebPage/WebInspectorUI.cpp	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebInspectorUI.cpp	2018-11-17 01:28:41 UTC (rev 238330)
@@ -52,22 +52,8 @@
     RuntimeEnabledFeatures::sharedFeatures().setImageBitmapOffscreenCanvasEnabled(true);
 }
 
-void WebInspectorUI::establishConnection(IPC::Attachment encodedConnectionIdentifier, uint64_t inspectedPageIdentifier, bool underTest, unsigned inspectionLevel)
+void WebInspectorUI::establishConnection(uint64_t inspectedPageIdentifier, bool underTest, unsigned inspectionLevel)
 {
-#if USE(UNIX_DOMAIN_SOCKETS)
-    IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.releaseFileDescriptor());
-#elif OS(DARWIN)
-    IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.port());
-#elif OS(WINDOWS)
-    IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.handle());
-#else
-    notImplemented();
-    return;
-#endif
-
-    if (!IPC::Connection::identifierIsValid(connectionIdentifier))
-        return;
-
     m_inspectedPageIdentifier = inspectedPageIdentifier;
     m_frontendAPIDispatcher.reset();
     m_underTest = underTest;
@@ -76,8 +62,45 @@
     m_frontendController = &m_page.corePage()->inspectorController();
     m_frontendController->setInspectorFrontendClient(this);
 
-    m_backendConnection = IPC::Connection::createClientConnection(connectionIdentifier, *this);
+    updateConnection();
+}
+
+void WebInspectorUI::updateConnection()
+{
+    if (m_backendConnection) {
+        m_backendConnection->invalidate();
+        m_backendConnection = nullptr;
+    }
+
+#if USE(UNIX_DOMAIN_SOCKETS)
+    IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection();
+    IPC::Connection::Identifier connectionIdentifier(socketPair.server);
+    IPC::Attachment connectionClientPort(socketPair.client);
+#elif OS(DARWIN)
+    mach_port_t listeningPort = MACH_PORT_NULL;
+    if (mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &listeningPort) != KERN_SUCCESS)
+        CRASH();
+
+    if (mach_port_insert_right(mach_task_self(), listeningPort, listeningPort, MACH_MSG_TYPE_MAKE_SEND) != KERN_SUCCESS)
+        CRASH();
+
+    IPC::Connection::Identifier connectionIdentifier(listeningPort);
+    IPC::Attachment connectionClientPort(listeningPort, MACH_MSG_TYPE_MOVE_SEND);
+#elif PLATFORM(WIN)
+    IPC::Connection::Identifier connectionIdentifier, connClient;
+    IPC::Connection::createServerAndClientIdentifiers(connectionIdentifier, connClient);
+    IPC::Attachment connectionClientPort(connClient);
+#else
+    notImplemented();
+    return;
+#endif
+
+#if USE(UNIX_DOMAIN_SOCKETS) || OS(DARWIN) || PLATFORM(WIN)
+    m_backendConnection = IPC::Connection::createServerConnection(connectionIdentifier, *this);
     m_backendConnection->open();
+#endif
+
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::SetFrontendConnection(connectionClientPort), m_inspectedPageIdentifier);
 }
 
 void WebInspectorUI::windowObjectCleared()
@@ -125,13 +148,15 @@
 {
     WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::DidClose(), m_inspectedPageIdentifier);
 
-    if (m_backendConnection)
+    if (m_backendConnection) {
         m_backendConnection->invalidate();
-    m_backendConnection = nullptr;
+        m_backendConnection = nullptr;
+    }
 
-    if (m_frontendController)
+    if (m_frontendController) {
         m_frontendController->setInspectorFrontendClient(nullptr);
-    m_frontendController = nullptr;
+        m_frontendController = nullptr;
+    }
 
     if (m_frontendHost)
         m_frontendHost->disconnectClient();
@@ -303,8 +328,7 @@
 
 void WebInspectorUI::sendMessageToBackend(const String& message)
 {
-    if (m_backendConnection)
-        m_backendConnection->send(Messages::WebInspector::SendMessageToBackend(message), 0);
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::SendMessageToBackend(message), m_inspectedPageIdentifier);
 }
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebInspectorUI.h (238329 => 238330)


--- trunk/Source/WebKit/WebProcess/WebPage/WebInspectorUI.h	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebInspectorUI.h	2018-11-17 01:28:41 UTC (rev 238330)
@@ -46,11 +46,12 @@
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
 
     // IPC::Connection::Client
-    void didClose(IPC::Connection&) override { closeWindow(); }
+    void didClose(IPC::Connection&) override { /* Do nothing, the inspected page process may have crashed and may be getting replaced. */ }
     void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference, IPC::StringReference) override { closeWindow(); }
 
     // Called by WebInspectorUI messages
-    void establishConnection(IPC::Attachment connectionIdentifier, uint64_t inspectedPageIdentifier, bool underTest, unsigned inspectionLevel);
+    void establishConnection(uint64_t inspectedPageIdentifier, bool underTest, unsigned inspectionLevel);
+    void updateConnection();
 
     void showConsole();
     void showResources();

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebInspectorUI.messages.in (238329 => 238330)


--- trunk/Source/WebKit/WebProcess/WebPage/WebInspectorUI.messages.in	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebInspectorUI.messages.in	2018-11-17 01:28:41 UTC (rev 238330)
@@ -21,7 +21,8 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 messages -> WebInspectorUI {
-    EstablishConnection(IPC::Attachment connectionIdentifier, uint64_t inspectedPageIdentifier, bool underTest, unsigned inspectionLevel)
+    EstablishConnection(uint64_t inspectedPageIdentifier, bool underTest, unsigned inspectionLevel)
+    UpdateConnection()
 
     AttachedBottom()
     AttachedRight()

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (238329 => 238330)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-11-17 01:28:41 UTC (rev 238330)
@@ -2777,9 +2777,9 @@
     m_page->setControlledByAutomation(controlled);
 }
 
-void WebPage::connectInspector(const String& targetId)
+void WebPage::connectInspector(const String& targetId, Inspector::FrontendChannel::ConnectionType connectionType)
 {
-    m_inspectorTargetController->connectInspector(targetId);
+    m_inspectorTargetController->connectInspector(targetId, connectionType);
 }
 
 void WebPage::disconnectInspector(const String& targetId)
@@ -3486,11 +3486,6 @@
     return m_remoteInspectorUI.get();
 }
 
-void WebPage::setHasLocalInspectorFrontend(bool hasLocalFrontend)
-{
-    send(Messages::WebPageProxy::SetHasLocalInspectorFrontend(hasLocalFrontend));
-}
-
 void WebPage::inspectorFrontendCountChanged(unsigned count)
 {
     send(Messages::WebPageProxy::DidChangeInspectorFrontendCount(count));

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (238329 => 238330)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2018-11-17 01:28:41 UTC (rev 238330)
@@ -50,6 +50,7 @@
 #include "WebBackForwardListProxy.h"
 #include "WebURLSchemeHandler.h"
 #include "WebUserContentController.h"
+#include <_javascript_Core/InspectorFrontendChannel.h>
 #include <WebCore/ActivityState.h>
 #include <WebCore/DictionaryPopupInfo.h>
 #include <WebCore/DisabledAdaptations.h>
@@ -299,7 +300,6 @@
     RemoteWebInspectorUI* remoteInspectorUI();
     bool isInspectorPage() { return !!m_inspectorUI || !!m_remoteInspectorUI; }
 
-    void setHasLocalInspectorFrontend(bool);
     void inspectorFrontendCountChanged(unsigned);
 
 #if PLATFORM(IOS_FAMILY) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
@@ -1043,7 +1043,7 @@
     bool isControlledByAutomation() const;
     void setControlledByAutomation(bool);
 
-    void connectInspector(const String& targetId);
+    void connectInspector(const String& targetId, Inspector::FrontendChannel::ConnectionType);
     void disconnectInspector(const String& targetId);
     void sendMessageToTargetBackend(const String& targetId, const String& message);
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (238329 => 238330)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2018-11-17 01:28:41 UTC (rev 238330)
@@ -111,7 +111,7 @@
 
     SetControlledByAutomation(bool controlled)
 
-    ConnectInspector(String targetId)
+    ConnectInspector(String targetId, Inspector::FrontendChannel::ConnectionType connectionType)
     DisconnectInspector(String targetId)
     SendMessageToTargetBackend(String targetId, String message)
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetController.cpp (238329 => 238330)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetController.cpp	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetController.cpp	2018-11-17 01:28:41 UTC (rev 238330)
@@ -61,7 +61,7 @@
     m_targetFrontendChannels.remove(target.identifier());
 }
 
-void WebPageInspectorTargetController::connectInspector(const String& targetId)
+void WebPageInspectorTargetController::connectInspector(const String& targetId, Inspector::FrontendChannel::ConnectionType connectionType)
 {
     InspectorTarget* target = m_targets.get(targetId);
     if (!target)
@@ -69,7 +69,7 @@
 
     RefPtr<WebPageInspectorTargetFrontendChannel> channel = m_targetFrontendChannels.get(targetId);
     if (!channel) {
-        channel = WebPageInspectorTargetFrontendChannel::create(*this, targetId);
+        channel = WebPageInspectorTargetFrontendChannel::create(*this, targetId, connectionType);
         m_targetFrontendChannels.set(target->identifier(), channel);
     }
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetController.h (238329 => 238330)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetController.h	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetController.h	2018-11-17 01:28:41 UTC (rev 238330)
@@ -47,7 +47,7 @@
     void addTarget(Inspector::InspectorTarget&);
     void removeTarget(Inspector::InspectorTarget&);
 
-    void connectInspector(const String& targetId);
+    void connectInspector(const String& targetId, Inspector::FrontendChannel::ConnectionType);
     void disconnectInspector(const String& targetId);
     void sendMessageToTargetBackend(const String& targetId, const String& message);
     void sendMessageToTargetFrontend(const String& targetId, const String& message);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetFrontendChannel.cpp (238329 => 238330)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetFrontendChannel.cpp	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetFrontendChannel.cpp	2018-11-17 01:28:41 UTC (rev 238330)
@@ -30,14 +30,15 @@
 
 namespace WebKit {
 
-Ref<WebPageInspectorTargetFrontendChannel> WebPageInspectorTargetFrontendChannel::create(WebPageInspectorTargetController& targetController, const String& targetId)
+Ref<WebPageInspectorTargetFrontendChannel> WebPageInspectorTargetFrontendChannel::create(WebPageInspectorTargetController& targetController, const String& targetId, Inspector::FrontendChannel::ConnectionType connectionType)
 {
-    return adoptRef(*new WebPageInspectorTargetFrontendChannel(targetController, targetId));
+    return adoptRef(*new WebPageInspectorTargetFrontendChannel(targetController, targetId, connectionType));
 }
 
-WebPageInspectorTargetFrontendChannel::WebPageInspectorTargetFrontendChannel(WebPageInspectorTargetController& targetController, const String& targetId)
+WebPageInspectorTargetFrontendChannel::WebPageInspectorTargetFrontendChannel(WebPageInspectorTargetController& targetController, const String& targetId, Inspector::FrontendChannel::ConnectionType connectionType)
     : m_targetController(targetController)
     , m_targetId(targetId)
+    , m_connectionType(connectionType)
 {
 }
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetFrontendChannel.h (238329 => 238330)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetFrontendChannel.h	2018-11-17 01:14:26 UTC (rev 238329)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetFrontendChannel.h	2018-11-17 01:28:41 UTC (rev 238330)
@@ -36,18 +36,19 @@
 class WebPageInspectorTargetFrontendChannel final : public RefCounted<WebPageInspectorTargetFrontendChannel>, public Inspector::FrontendChannel {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static Ref<WebPageInspectorTargetFrontendChannel> create(WebPageInspectorTargetController&, const String& targetId);
+    static Ref<WebPageInspectorTargetFrontendChannel> create(WebPageInspectorTargetController&, const String& targetId, Inspector::FrontendChannel::ConnectionType);
     virtual ~WebPageInspectorTargetFrontendChannel() = default;
 
 private:
-    WebPageInspectorTargetFrontendChannel(WebPageInspectorTargetController&, const String& targetId);
+    WebPageInspectorTargetFrontendChannel(WebPageInspectorTargetController&, const String& targetId, Inspector::FrontendChannel::ConnectionType);
 
-    ConnectionType connectionType() const override { return ConnectionType::Remote; }
+    ConnectionType connectionType() const override { return m_connectionType; }
     void sendMessageToFrontend(const String& message) override;
 
 private:
     WebPageInspectorTargetController& m_targetController;
     String m_targetId;
+    Inspector::FrontendChannel::ConnectionType m_connectionType { Inspector::FrontendChannel::ConnectionType::Remote };
 };
 
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to