Web Inspector: Keep Web Inspector window alive across process swaps (PSON) (Local...
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 17 Nov 2018 01:28:41 +0000 (01:28 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 17 Nov 2018 01:28:41 +0000 (01:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191740
<rdar://problem/45470897>

Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

* 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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238330 268f45cc-cd09-0410-ab3c-d52691b4dbfc

34 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/unit-tests/target-manager-expected.txt
LayoutTests/inspector/unit-tests/target-manager.html
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/InspectorFrontendChannel.h
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Protocol/Connection.js
Source/WebInspectorUI/UserInterface/Protocol/InspectorBackend.js
Source/WebInspectorUI/UserInterface/Test.html
Source/WebInspectorUI/UserInterface/Test/Test.js
Source/WebKit/ChangeLog
Source/WebKit/Scripts/webkit/messages.py
Source/WebKit/UIProcess/InspectorTargetProxy.cpp
Source/WebKit/UIProcess/WebInspectorProxy.cpp
Source/WebKit/UIProcess/WebInspectorProxy.h
Source/WebKit/UIProcess/WebInspectorProxy.messages.in
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebPageProxy.messages.in
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebInspectorClient.cpp
Source/WebKit/WebProcess/WebPage/WebInspector.cpp
Source/WebKit/WebProcess/WebPage/WebInspector.h
Source/WebKit/WebProcess/WebPage/WebInspector.messages.in
Source/WebKit/WebProcess/WebPage/WebInspectorUI.cpp
Source/WebKit/WebProcess/WebPage/WebInspectorUI.h
Source/WebKit/WebProcess/WebPage/WebInspectorUI.messages.in
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in
Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetController.cpp
Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetController.h
Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetFrontendChannel.cpp
Source/WebKit/WebProcess/WebPage/WebPageInspectorTargetFrontendChannel.h

index 3449006..1ff84c3 100644 (file)
@@ -1,3 +1,15 @@
+2018-11-16  Joseph Pecoraro  <pecoraro@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  <jeremyj@apple.com>
 
         Include AirPlay destination name in AirPlay placard.
index d21ddb7..a673a28 100644 (file)
@@ -6,7 +6,7 @@ Test for TargetManager and other global WI.Target objects.
 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
index 7bc9cc5..9a2219b 100644 (file)
@@ -30,7 +30,7 @@ function test()
             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();
         }
     });
index 489d29f..0d73e2e 100644 (file)
@@ -1,3 +1,14 @@
+2018-11-16  Joseph Pecoraro  <pecoraro@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  <fpizlo@apple.com>
 
         All users of ArrayBuffer should agree on the same max size
index 3abc1d2..bec5a6a 100644 (file)
@@ -46,3 +46,15 @@ public:
 };
 
 } // 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
index 377c761..d722992 100644 (file)
@@ -1,3 +1,30 @@
+2018-11-16  Joseph Pecoraro  <pecoraro@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  <mattbaker@apple.com>
 
         Web Inspector: TreeOutline shouldn't select first child of an expanded element on right arrow key
index d5f607c..91624c2 100644 (file)
@@ -96,7 +96,8 @@ InspectorBackend.Connection = class InspectorBackendConnection
         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"]));
         }
 
index 76b62cf..579a93e 100644 (file)
@@ -163,7 +163,7 @@ InspectorBackendClass = class InspectorBackendClass
     runAfterPendingDispatches(script)
     {
         // FIXME: Should this respect pending dispatches in all connections?
-        InspectorBackend.backendConnection.runAfterPendingDispatches(script);
+        WI.mainTarget.connection.runAfterPendingDispatches(script);
     }
 
     activateDomain(domainName, activationDebuggableTypes)
index a80db37..07199a6 100644 (file)
@@ -75,6 +75,8 @@
 
     <script src="Protocol/DirectBackendTarget.js"></script>
     <script src="Protocol/MultiplexingBackendTarget.js"></script>
+    <script src="Protocol/JavaScriptContextTarget.js"></script>
+    <script src="Protocol/PageTarget.js"></script>
     <script src="Protocol/WorkerTarget.js"></script>
 
     <script src="Protocol/InspectorObserver.js"></script>
index ad1c542..7f6c726 100644 (file)
@@ -75,8 +75,11 @@ WI.loaded = function()
     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.terminatePageTarget = function(target)
 
 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.performOneTimeFrontendInitializationsUsingTarget = function(target)
         WI.consoleManager.initializeLogChannels(target);
     }
 
+    // FIXME: This slows down test debug logging considerably.
     if (!WI.__didPerformCSSInitialization && target.CSSAgent) {
         WI.__didPerformCSSInitialization = true;
         WI.CSSCompletions.initializeCSSCompletions(target);
index a0209f6..8107aa8 100644 (file)
@@ -1,3 +1,128 @@
+2018-11-16  Joseph Pecoraro  <pecoraro@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  <mcatanzaro@igalia.com>
 
         [GTK][WPE] Add "WebKitDeviceInfoPermissionRequest.h" into webkit2.h
index 1c59113..b332265 100644 (file)
@@ -390,6 +390,7 @@ def headers_for_type(type):
         'JSC::MessageLevel': ['<JavaScriptCore/ConsoleTypes.h>'],
         'JSC::MessageSource': ['<JavaScriptCore/ConsoleTypes.h>'],
         'Inspector::InspectorTargetType': ['<JavaScriptCore/InspectorTarget.h>'],
+        'Inspector::FrontendChannel::ConnectionType': ['<JavaScriptCore/InspectorFrontendChannel.h>'],
         'MonotonicTime': ['<wtf/MonotonicTime.h>'],
         'Seconds': ['<wtf/Seconds.h>'],
         'WallTime': ['<wtf/WallTime.h>'],
index 54870c8..4a3d8a9 100644 (file)
@@ -46,10 +46,10 @@ InspectorTargetProxy::InspectorTargetProxy(WebPageProxy& page, const String& tar
 {
 }
 
-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&)
index 8cd6213..9df893e 100644 (file)
@@ -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 @@ WebPreferences& WebInspectorProxy::inspectorPagePreferences() const
 
 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 @@ void WebInspectorProxy::invalidate()
     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 @@ void WebInspectorProxy::closeForCrash()
     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 @@ void WebInspectorProxy::createFrontendPage()
     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,7 +395,9 @@ void WebInspectorProxy::createInspectorPage(IPC::Attachment connectionIdentifier
     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);
@@ -425,6 +469,8 @@ void WebInspectorProxy::closeFrontendPageAndWindow()
     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 @@ void WebInspectorProxy::closeFrontendPageAndWindow()
     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);
 }
index d4e6069..fbcbb9f 100644 (file)
@@ -30,6 +30,7 @@
 #include "Attachment.h"
 #include "MessageReceiver.h"
 #include "WebInspectorUtilities.h"
+#include <JavaScriptCore/InspectorFrontendChannel.h>
 #include <wtf/Forward.h>
 #include <wtf/RefPtr.h>
 #include <wtf/text/WTFString.h>
@@ -70,6 +71,7 @@ enum class AttachmentSide {
 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 @@ public:
     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 @@ private:
     // 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 @@ private:
 #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();
index 3b28e8f..1e027d3 100644 (file)
 # 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()
index d1d1432..caab5e6 100644 (file)
@@ -800,7 +800,6 @@ void WebPageProxy::finishAttachingToWebProcess(ShouldDelayAttachingDrawingArea s
     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 @@ void WebPageProxy::finishAttachingToWebProcess(ShouldDelayAttachingDrawingArea s
 
     initializeWebPage(shouldDelayAttachingDrawingArea);
 
+    m_inspector->updateForNewPageProcess(this);
+
 #if ENABLE(REMOTE_INSPECTOR)
     remoteInspectorInformationDidChange();
 #endif
@@ -939,6 +940,9 @@ void WebPageProxy::close()
     m_activeContextMenu = nullptr;
 #endif
 
+    m_inspector->invalidate();
+    m_inspector = nullptr;
+
     m_backForwardList->pageClosed();
     m_inspectorController->pageClosed();
     pageClient().pageClosed();
@@ -6250,10 +6254,7 @@ void WebPageProxy::resetState(ResetStateReason resetStateReason)
     }
     closeOverlayedViews();
 
-    if (m_inspector) {
-        m_inspector->invalidate();
-        m_inspector = nullptr;
-    }
+    m_inspector->reset();
 
 #if ENABLE(FULLSCREEN_API)
     if (m_fullScreenManager) {
@@ -6283,8 +6284,6 @@ void WebPageProxy::resetState(ResetStateReason resetStateReason)
 
     m_toolTip = String();
 
-    m_inspectorHasLocalFrontend = false;
-
     m_mainFrameHasHorizontalScrollbar = false;
     m_mainFrameHasVerticalScrollbar = false;
 
index 906cf12..9f7459b 100644 (file)
@@ -380,9 +380,6 @@ public:
 
     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 @@ private:
     bool m_controlledByAutomation { false };
 
     unsigned m_inspectorFrontendCount { 0 };
-    bool m_inspectorHasLocalFrontend { false };
 
 #if PLATFORM(COCOA)
     bool m_isSmartInsertDeleteEnabled { false };
index 4e0d675..698b2c1 100644 (file)
@@ -418,7 +418,6 @@ messages -> WebPageProxy {
     DisableInspectorNodeSearch()
 #endif
 
-    SetHasLocalInspectorFrontend(bool hasLocalFrontend)
     DidChangeInspectorFrontendCount(uint64_t count)
 
     CreateInspectorTarget(String targetId, enum:uint8_t Inspector::InspectorTargetType type)
index 32c079a..7d4ac37 100644 (file)
@@ -2136,12 +2136,6 @@ Ref<WebProcessProxy> WebProcessPool::processForNavigationInternal(WebPageProxy&
         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();
index 912ca3c..c6b1fe1 100644 (file)
@@ -90,9 +90,9 @@ void WebInspectorClient::frontendCountChanged(unsigned count)
 
 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()
index 2daa636..952898d 100644 (file)
@@ -70,46 +70,35 @@ WebInspector::~WebInspector()
         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);
-    m_frontendConnection->open();
-
-    m_page->setHasLocalInspectorFrontend(true);
+    if (!IPC::Connection::identifierIsValid(connectionIdentifier))
+        return;
 
-    WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::CreateInspectorPage(connectionClientPort, canAttachWindow(), underTest), m_page->pageID());
-#endif
+    m_frontendConnection = IPC::Connection::createClientConnection(connectionIdentifier, *this);
+    m_frontendConnection->open();
 }
 
 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 @@ void WebInspector::close()
     if (!m_frontendConnection)
         return;
 
-    m_page->corePage()->inspectorController().disconnectFrontend(*this);
     closeFrontendConnection();
 }
 
@@ -289,17 +277,4 @@ void WebInspector::updateDockingAvailability()
     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
index 5c11df3..e50396d 100644 (file)
@@ -28,7 +28,6 @@
 #include "APIObject.h"
 #include "Connection.h"
 #include "MessageReceiver.h"
-#include <JavaScriptCore/InspectorFrontendChannel.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/text/WTFString.h>
 
@@ -36,7 +35,7 @@ namespace WebKit {
 
 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 @@ public:
 
     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 @@ public:
     void stopElementSelection();
     void elementSelectionChanged(bool);
 
-    void sendMessageToBackend(const String&);
+    void setFrontendConnection(IPC::Attachment);
 
     void disconnectFromPage() { close(); }
 
@@ -91,7 +87,7 @@ private:
     bool canAttachWindow();
 
     // Called from WebInspectorClient
-    void openFrontendConnection(bool underTest);
+    void openLocalInspectorFrontend(bool underTest);
     void closeFrontendConnection();
 
     void bringToFront();
index 07e8f2d..bd754c1 100644 (file)
@@ -40,5 +40,5 @@ messages -> WebInspector {
     StartElementSelection()
     StopElementSelection()
 
-    SendMessageToBackend(String message)
+    SetFrontendConnection(IPC::Attachment connectionIdentifier)
 }
index 7fcfd97..e82b569 100644 (file)
@@ -52,22 +52,8 @@ WebInspectorUI::WebInspectorUI(WebPage& page)
     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 @@ void WebInspectorUI::establishConnection(IPC::Attachment encodedConnectionIdenti
     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 @@ void WebInspectorUI::closeWindow()
 {
     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::pageUnpaused()
 
 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
index 543ee26..5b030ec 100644 (file)
@@ -46,11 +46,12 @@ public:
     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();
index 372ed3c..dea0fe5 100644 (file)
@@ -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()
index 0e38466..4eb1b48 100644 (file)
@@ -2777,9 +2777,9 @@ void WebPage::setControlledByAutomation(bool controlled)
     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 @@ RemoteWebInspectorUI* WebPage::remoteInspectorUI()
     return m_remoteInspectorUI.get();
 }
 
-void WebPage::setHasLocalInspectorFrontend(bool hasLocalFrontend)
-{
-    send(Messages::WebPageProxy::SetHasLocalInspectorFrontend(hasLocalFrontend));
-}
-
 void WebPage::inspectorFrontendCountChanged(unsigned count)
 {
     send(Messages::WebPageProxy::DidChangeInspectorFrontendCount(count));
index c695278..a2da4aa 100644 (file)
@@ -50,6 +50,7 @@
 #include "WebBackForwardListProxy.h"
 #include "WebURLSchemeHandler.h"
 #include "WebUserContentController.h"
+#include <JavaScriptCore/InspectorFrontendChannel.h>
 #include <WebCore/ActivityState.h>
 #include <WebCore/DictionaryPopupInfo.h>
 #include <WebCore/DisabledAdaptations.h>
@@ -299,7 +300,6 @@ public:
     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 @@ public:
     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);
 
index 46cd050..fe479f5 100644 (file)
@@ -111,7 +111,7 @@ messages -> WebPage LegacyReceiver {
 
     SetControlledByAutomation(bool controlled)
 
-    ConnectInspector(String targetId)
+    ConnectInspector(String targetId, Inspector::FrontendChannel::ConnectionType connectionType)
     DisconnectInspector(String targetId)
     SendMessageToTargetBackend(String targetId, String message)
 
index b97b77f..b0d703c 100644 (file)
@@ -61,7 +61,7 @@ void WebPageInspectorTargetController::removeTarget(Inspector::InspectorTarget&
     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 @@ void WebPageInspectorTargetController::connectInspector(const String& targetId)
 
     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);
     }
 
index 8a6f95c..3e92b7a 100644 (file)
@@ -47,7 +47,7 @@ public:
     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);
index 39da9a9..8d78807 100644 (file)
 
 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)
 {
 }
 
index fc9acdd..76af62a 100644 (file)
@@ -36,18 +36,19 @@ class WebPageInspectorTargetController;
 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