Web Inspector: REGRESSION(?): all "Show *" develop menu items cause the page to crash
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Nov 2018 04:39:45 +0000 (04:39 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Nov 2018 04:39:45 +0000 (04:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192016
<rdar://problem/46284417>

Reviewed by Devin Rousso.

Source/WebInspectorUI:

* UserInterface/Base/Main.js:
(WI.loaded):
(WI.initializeBackendTarget):
(WI.contentLoaded):
(WI.whenTargetsAvailable):
Don't evaluate any InspectorFrontendAPI commands until the frontend
has initialized a main target and the user interface.

Source/WebKit:

Previously calling the Page's inspectorController.show()
would create a frontend connection on the WebProcess side.
However now the frontend connection is handed to the WebProcess
once the UIProcess creates it. So queue actions that take place
immediately after showing the inspector until we have a frontend
to send the actions to.

* WebProcess/WebPage/WebInspector.h:
* WebProcess/WebPage/WebInspector.cpp:
(WebKit::WebInspector::setFrontendConnection):
(WebKit::WebInspector::closeFrontendConnection):
(WebKit::WebInspector::whenFrontendConnectionEstablished):
(WebKit::WebInspector::showConsole):
(WebKit::WebInspector::showResources):
(WebKit::WebInspector::showTimelines):
(WebKit::WebInspector::showMainResourceForFrame):
(WebKit::WebInspector::startPageProfiling):
(WebKit::WebInspector::stopPageProfiling):
(WebKit::WebInspector::startElementSelection):
(WebKit::WebInspector::stopElementSelection):

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/Main.js
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebPage/WebInspector.cpp
Source/WebKit/WebProcess/WebPage/WebInspector.h

index 1fd7afa..00aaf54 100644 (file)
@@ -1,3 +1,19 @@
+2018-11-28  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: REGRESSION(?): all "Show *" develop menu items cause the page to crash
+        https://bugs.webkit.org/show_bug.cgi?id=192016
+        <rdar://problem/46284417>
+
+        Reviewed by Devin Rousso.
+
+        * UserInterface/Base/Main.js:
+        (WI.loaded):
+        (WI.initializeBackendTarget):
+        (WI.contentLoaded):
+        (WI.whenTargetsAvailable):
+        Don't evaluate any InspectorFrontendAPI commands until the frontend
+        has initialized a main target and the user interface.
+
 2018-11-28  Nikita Vasilyev  <nvasilyev@apple.com>
 
         Web Inspector: Styles: enable selection of multiple properties by default
index 2d30517..39dd620 100644 (file)
@@ -157,6 +157,7 @@ WI.loaded = function()
     this.modifierKeys = {altKey: false, metaKey: false, shiftKey: false};
     this.visible = false;
     this._windowKeydownListeners = [];
+    this._targetsAvailablePromise = new WI.WrappedPromise;
 
     // Targets.
     WI.backendTarget = null;
@@ -181,6 +182,8 @@ WI.initializeBackendTarget = function(target)
     WI.backendTarget = target;
 
     WI.resetMainExecutionContext();
+
+    this._targetsAvailablePromise.resolve();
 };
 
 WI.initializePageTarget = function(target)
@@ -551,7 +554,9 @@ WI.contentLoaded = function()
     this.tabBar.addEventListener(WI.TabBar.Event.TabBarItemsReordered, this._rememberOpenTabs, this);
 
     // Signal that the frontend is now ready to receive messages.
-    InspectorFrontendAPI.loadCompleted();
+    WI.whenTargetsAvailable().then(() => {
+        InspectorFrontendAPI.loadCompleted();
+    });
 
     // Tell the InspectorFrontendHost we loaded, which causes the window to display
     // and pending InspectorFrontendAPI commands to be sent.
@@ -580,6 +585,11 @@ WI.performOneTimeFrontendInitializationsUsingTarget = function(target)
     }
 };
 
+WI.whenTargetsAvailable = function()
+{
+    return this._targetsAvailablePromise.promise;
+};
+
 WI.isTabTypeAllowed = function(tabType)
 {
     let tabClass = this._knownTabClassesByType.get(tabType);
index 207f498..64950bf 100644 (file)
@@ -1,3 +1,32 @@
+2018-11-28  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: REGRESSION(?): all "Show *" develop menu items cause the page to crash
+        https://bugs.webkit.org/show_bug.cgi?id=192016
+        <rdar://problem/46284417>
+
+        Reviewed by Devin Rousso.
+
+        Previously calling the Page's inspectorController.show()
+        would create a frontend connection on the WebProcess side.
+        However now the frontend connection is handed to the WebProcess
+        once the UIProcess creates it. So queue actions that take place
+        immediately after showing the inspector until we have a frontend
+        to send the actions to.
+
+        * WebProcess/WebPage/WebInspector.h:
+        * WebProcess/WebPage/WebInspector.cpp:
+        (WebKit::WebInspector::setFrontendConnection):
+        (WebKit::WebInspector::closeFrontendConnection):
+        (WebKit::WebInspector::whenFrontendConnectionEstablished):
+        (WebKit::WebInspector::showConsole):
+        (WebKit::WebInspector::showResources):
+        (WebKit::WebInspector::showTimelines):
+        (WebKit::WebInspector::showMainResourceForFrame):
+        (WebKit::WebInspector::startPageProfiling):
+        (WebKit::WebInspector::stopPageProfiling):
+        (WebKit::WebInspector::startElementSelection):
+        (WebKit::WebInspector::stopElementSelection):
+
 2018-11-28  Vivek Seth  <v_seth@apple.com>
 
         Consult dummy storage for HTTPS Upgrade, Apply If Appropriate
index a6f224b..8a83b80 100644 (file)
@@ -100,6 +100,10 @@ void WebInspector::setFrontendConnection(IPC::Attachment encodedConnectionIdenti
 
     m_frontendConnection = IPC::Connection::createClientConnection(connectionIdentifier, *this);
     m_frontendConnection->open();
+
+    for (auto& callback : m_frontendConnectionActions)
+        callback();
+    m_frontendConnectionActions.clear();
 }
 
 void WebInspector::closeFrontendConnection()
@@ -112,6 +116,8 @@ void WebInspector::closeFrontendConnection()
         m_frontendConnection = nullptr;
     }
 
+    m_frontendConnectionActions.clear();
+
     m_attached = false;
     m_previousCanAttach = false;
 }
@@ -121,6 +127,16 @@ void WebInspector::bringToFront()
     WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::BringToFront(), m_page->pageID());
 }
 
+void WebInspector::whenFrontendConnectionEstablished(Function<void()>&& callback)
+{
+    if (m_frontendConnection) {
+        callback();
+        return;
+    }
+
+    m_frontendConnectionActions.append(WTFMove(callback));
+}
+
 // Called by WebInspector messages
 void WebInspector::show()
 {
@@ -175,7 +191,10 @@ void WebInspector::showConsole()
         return;
 
     m_page->corePage()->inspectorController().show();
-    m_frontendConnection->send(Messages::WebInspectorUI::ShowConsole(), 0);
+
+    whenFrontendConnectionEstablished([=] {
+        m_frontendConnection->send(Messages::WebInspectorUI::ShowConsole(), 0);
+    });
 }
 
 void WebInspector::showResources()
@@ -184,7 +203,10 @@ void WebInspector::showResources()
         return;
 
     m_page->corePage()->inspectorController().show();
-    m_frontendConnection->send(Messages::WebInspectorUI::ShowResources(), 0);
+
+    whenFrontendConnectionEstablished([=] {
+        m_frontendConnection->send(Messages::WebInspectorUI::ShowResources(), 0);
+    });
 }
 
 void WebInspector::showTimelines()
@@ -193,7 +215,10 @@ void WebInspector::showTimelines()
         return;
 
     m_page->corePage()->inspectorController().show();
-    m_frontendConnection->send(Messages::WebInspectorUI::ShowTimelines(), 0);
+
+    whenFrontendConnectionEstablished([=] {
+        m_frontendConnection->send(Messages::WebInspectorUI::ShowTimelines(), 0);
+    });
 }
 
 void WebInspector::showMainResourceForFrame(uint64_t frameIdentifier)
@@ -208,7 +233,10 @@ void WebInspector::showMainResourceForFrame(uint64_t frameIdentifier)
     m_page->corePage()->inspectorController().show();
 
     String inspectorFrameIdentifier = m_page->corePage()->inspectorController().pageAgent()->frameId(frame->coreFrame());
-    m_frontendConnection->send(Messages::WebInspectorUI::ShowMainResourceForFrame(inspectorFrameIdentifier), 0);
+
+    whenFrontendConnectionEstablished([=] {
+        m_frontendConnection->send(Messages::WebInspectorUI::ShowMainResourceForFrame(inspectorFrameIdentifier), 0);
+    });
 }
 
 void WebInspector::startPageProfiling()
@@ -216,7 +244,9 @@ void WebInspector::startPageProfiling()
     if (!m_page->corePage())
         return;
 
-    m_frontendConnection->send(Messages::WebInspectorUI::StartPageProfiling(), 0);
+    whenFrontendConnectionEstablished([=] {
+        m_frontendConnection->send(Messages::WebInspectorUI::StartPageProfiling(), 0);
+    });
 }
 
 void WebInspector::stopPageProfiling()
@@ -224,7 +254,9 @@ void WebInspector::stopPageProfiling()
     if (!m_page->corePage())
         return;
 
-    m_frontendConnection->send(Messages::WebInspectorUI::StopPageProfiling(), 0);
+    whenFrontendConnectionEstablished([=] {
+        m_frontendConnection->send(Messages::WebInspectorUI::StopPageProfiling(), 0);
+    });
 }
 
 void WebInspector::startElementSelection()
@@ -232,7 +264,9 @@ void WebInspector::startElementSelection()
     if (!m_page->corePage())
         return;
 
-    m_frontendConnection->send(Messages::WebInspectorUI::StartElementSelection(), 0);
+    whenFrontendConnectionEstablished([=] {
+        m_frontendConnection->send(Messages::WebInspectorUI::StartElementSelection(), 0);
+    });
 }
 
 void WebInspector::stopElementSelection()
@@ -240,7 +274,9 @@ void WebInspector::stopElementSelection()
     if (!m_page->corePage())
         return;
 
-    m_frontendConnection->send(Messages::WebInspectorUI::StopElementSelection(), 0);
+    whenFrontendConnectionEstablished([=] {
+        m_frontendConnection->send(Messages::WebInspectorUI::StopElementSelection(), 0);
+    });
 }
 
 void WebInspector::elementSelectionChanged(bool active)
index e50396d..69029eb 100644 (file)
@@ -92,9 +92,12 @@ private:
 
     void bringToFront();
 
+    void whenFrontendConnectionEstablished(Function<void()>&&);
+
     WebPage* m_page;
 
     RefPtr<IPC::Connection> m_frontendConnection;
+    Vector<Function<void()>> m_frontendConnectionActions;
 
     bool m_attached { false };
     bool m_previousCanAttach { false };