[GTK] Remote Inspector: add support for service workers targets
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Jan 2020 10:43:22 +0000 (10:43 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Jan 2020 10:43:22 +0000 (10:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=206821

Reviewed by Žan Doberšek.

Source/JavaScriptCore:

Handle ServiceWorker target type.

* inspector/remote/glib/RemoteInspectorGlib.cpp:
(Inspector::targetDebuggableType):
(Inspector::RemoteInspector::listingForInspectionTarget const):

Source/WebKit:

Add support for debugging service workers.

* UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp:
(WebKit::RemoteInspectorProtocolHandler::handleRequest): Pass target type to message handler too.
(WebKit::RemoteInspectorProtocolHandler::inspect): Pass the received target type to the client.
* UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.h:
* UIProcess/glib/RemoteInspectorClient.cpp:
(WebKit::RemoteInspectorProxy::load): It now receives the debuggable type that is set to the API::DebuggableInfo.
(WebKit::RemoteInspectorClient::messageHandlers): Handle service worker targets too.
(WebKit::debuggableType): Helper to convert the target type to debuggable type.
(WebKit::RemoteInspectorClient::inspect): Pass the debuggable tupe to RemoteInspectorProxy::load().
* UIProcess/glib/RemoteInspectorClient.h:
* UIProcess/gtk/WebInspectorProxyGtk.cpp:
(WebKit::WebInspectorProxy::infoForLocalDebuggable): Use WebPage as debuggable type instead of the default.

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/remote/glib/RemoteInspectorGlib.cpp
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp
Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.h
Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp
Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.h
Source/WebKit/UIProcess/Inspector/gtk/WebInspectorProxyGtk.cpp

index 96961f4..3ce9f4b 100644 (file)
@@ -1,3 +1,16 @@
+2020-01-27  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Remote Inspector: add support for service workers targets
+        https://bugs.webkit.org/show_bug.cgi?id=206821
+
+        Reviewed by Žan Doberšek.
+
+        Handle ServiceWorker target type.
+
+        * inspector/remote/glib/RemoteInspectorGlib.cpp:
+        (Inspector::targetDebuggableType):
+        (Inspector::RemoteInspector::listingForInspectionTarget const):
+
 2020-01-27  Jonathan Bedard  <jbedard@apple.com>
 
         Fix OpenSource iphoneos arm64e build
index 4a52108..4738f50 100644 (file)
@@ -146,19 +146,30 @@ void RemoteInspector::setupConnection(Ref<SocketConnection>&& connection)
         pushListingsSoon();
 }
 
+static const char* targetDebuggableType(RemoteInspectionTarget::Type type)
+{
+    switch (type) {
+    case RemoteInspectionTarget::Type::JavaScript:
+        return "JavaScript";
+    case RemoteInspectionTarget::Type::ServiceWorker:
+        return "ServiceWorker";
+    case RemoteInspectionTarget::Type::WebPage:
+        return "WebPage";
+    default:
+        break;
+    }
+
+    RELEASE_ASSERT_NOT_REACHED();
+}
+
 TargetListing RemoteInspector::listingForInspectionTarget(const RemoteInspectionTarget& target) const
 {
     if (!target.remoteDebuggingAllowed())
         return nullptr;
 
-    // FIXME: Support remote debugging of a ServiceWorker.
-    if (target.type() == RemoteInspectionTarget::Type::ServiceWorker)
-        return nullptr;
-
-    ASSERT(target.type() == RemoteInspectionTarget::Type::JavaScript || target.type() == RemoteInspectionTarget::Type::Page || target.type() == RemoteInspectionTarget::Type::WebPage);
     return g_variant_new("(tsssb)", static_cast<guint64>(target.targetIdentifier()),
-        target.type() == RemoteInspectionTarget::Type::JavaScript ? "JavaScript" : "Web",
-        target.name().utf8().data(), target.type() == RemoteInspectionTarget::Type::JavaScript ? "null" : target.url().utf8().data(),
+        targetDebuggableType(target.type()), target.name().utf8().data(),
+        target.type() == RemoteInspectionTarget::Type::JavaScript ? "null" : target.url().utf8().data(),
         target.hasLocalDebugger());
 }
 
index fc61854..5a1a63e 100644 (file)
@@ -1,3 +1,25 @@
+2020-01-27  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Remote Inspector: add support for service workers targets
+        https://bugs.webkit.org/show_bug.cgi?id=206821
+
+        Reviewed by Žan Doberšek.
+
+        Add support for debugging service workers.
+
+        * UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp:
+        (WebKit::RemoteInspectorProtocolHandler::handleRequest): Pass target type to message handler too.
+        (WebKit::RemoteInspectorProtocolHandler::inspect): Pass the received target type to the client.
+        * UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.h:
+        * UIProcess/glib/RemoteInspectorClient.cpp:
+        (WebKit::RemoteInspectorProxy::load): It now receives the debuggable type that is set to the API::DebuggableInfo.
+        (WebKit::RemoteInspectorClient::messageHandlers): Handle service worker targets too.
+        (WebKit::debuggableType): Helper to convert the target type to debuggable type.
+        (WebKit::RemoteInspectorClient::inspect): Pass the debuggable tupe to RemoteInspectorProxy::load().
+        * UIProcess/glib/RemoteInspectorClient.h:
+        * UIProcess/gtk/WebInspectorProxyGtk.cpp:
+        (WebKit::WebInspectorProxy::infoForLocalDebuggable): Use WebPage as debuggable type instead of the default.
+
 2020-01-27  Simon Fraser  <simon.fraser@apple.com>
 
         REGRESSION (r253634): cricbuzz.com media controls vanish depending on page scale
index 6ec260b..16acbd8 100644 (file)
@@ -46,11 +46,11 @@ public:
     {
         String message = serializedScriptValue.toString();
         Vector<String> tokens = message.split(':');
-        if (tokens.size() != 2)
+        if (tokens.size() != 3)
             return;
 
         URL requestURL = URL({ }, page.pageLoadState().url());
-        m_inspectorProtocolHandler.inspect(requestURL.hostAndPort(), tokens[0].toUInt64(), tokens[1].toUInt64());
+        m_inspectorProtocolHandler.inspect(requestURL.hostAndPort(), tokens[0].toUInt64(), tokens[1].toUInt64(), tokens[2]);
     }
 
     ~ScriptMessageClient() { }
@@ -143,8 +143,8 @@ void RemoteInspectorProtocolHandler::handleRequest(WebKitURISchemeRequest* reque
                 g_string_append_printf(html,
                     "<tbody><tr>"
                     "<td class=\"data\"><div class=\"targetname\">%s</div><div class=\"targeturl\">%s</div></td>"
-                    "<td class=\"input\"><input type=\"button\" value=\"Inspect\" onclick=\"window.webkit.messageHandlers.inspector.postMessage('%" G_GUINT64_FORMAT ":%" G_GUINT64_FORMAT "');\"></td>"
-                    "</tr></tbody>", target.name.data(), target.url.data(), connectionID, target.id);
+                    "<td class=\"input\"><input type=\"button\" value=\"Inspect\" onclick=\"window.webkit.messageHandlers.inspector.postMessage('%" G_GUINT64_FORMAT ":%" G_GUINT64_FORMAT ":%s');\"></td>"
+                    "</tr></tbody>", target.name.data(), target.url.data(), connectionID, target.id, target.type.data());
             }
         }
         g_string_append(html, "</table>");
@@ -155,10 +155,10 @@ void RemoteInspectorProtocolHandler::handleRequest(WebKitURISchemeRequest* reque
     webkit_uri_scheme_request_finish(request, stream.get(), streamLength, "text/html");
 }
 
-void RemoteInspectorProtocolHandler::inspect(const String& hostAndPort, uint64_t connectionID, uint64_t tatgetID)
+void RemoteInspectorProtocolHandler::inspect(const String& hostAndPort, uint64_t connectionID, uint64_t tatgetID, const String& targetType)
 {
     if (auto* client = m_inspectorClients.get(hostAndPort))
-        client->inspect(connectionID, tatgetID);
+        client->inspect(connectionID, tatgetID, targetType);
 }
 
 void RemoteInspectorProtocolHandler::targetListChanged(RemoteInspectorClient& client)
index 9bd98f6..c4873e7 100644 (file)
@@ -37,7 +37,7 @@ public:
     explicit RemoteInspectorProtocolHandler(WebKitWebContext* context);
     ~RemoteInspectorProtocolHandler();
 
-    void inspect(const String& hostAndPort, uint64_t connectionID, uint64_t targetID);
+    void inspect(const String& hostAndPort, uint64_t connectionID, uint64_t targetID, const String& targetType);
 
 private:
     static void webViewDestroyed(RemoteInspectorProtocolHandler*, WebKitWebView*);
index d9d50dc..57ef174 100644 (file)
@@ -57,11 +57,11 @@ public:
         m_proxy->invalidate();
     }
 
-    void load()
+    void load(Inspector::DebuggableType debuggableType)
     {
         // FIXME <https://webkit.org/b/205536>: this should infer more useful data about the debug target.
         Ref<API::DebuggableInfo> debuggableInfo = API::DebuggableInfo::create(DebuggableInfoData::empty());
-        debuggableInfo->setDebuggableType(Inspector::DebuggableType::WebPage);
+        debuggableInfo->setDebuggableType(debuggableType);
         m_proxy->load(WTFMove(debuggableInfo), m_inspectorClient.backendCommandsURL());
     }
 
@@ -131,7 +131,7 @@ const SocketConnection::MessageHandlers& RemoteInspectorClient::messageHandlers(
             const char* url;
             gboolean hasLocalDebugger;
             while (g_variant_iter_loop(iter.get(), "(t&s&s&sb)", &targetID, &type, &name, &url, &hasLocalDebugger)) {
-                if (!g_strcmp0(type, "Web") || !g_strcmp0(type, "JavaScript"))
+                if (!g_strcmp0(type, "JavaScript") || !g_strcmp0(type, "ServiceWorker") || !g_strcmp0(type, "WebPage"))
                     targetList.uncheckedAppend({ targetID, type, name, url });
             }
             client.setTargetList(connectionID, WTFMove(targetList));
@@ -203,7 +203,18 @@ void RemoteInspectorClient::connectionDidClose()
     m_observer.connectionClosed(*this);
 }
 
-void RemoteInspectorClient::inspect(uint64_t connectionID, uint64_t targetID)
+static Inspector::DebuggableType debuggableType(const String& targetType)
+{
+    if (targetType == "JavaScript")
+        return Inspector::DebuggableType::JavaScript;
+    if (targetType == "ServiceWorker")
+        return Inspector::DebuggableType::ServiceWorker;
+    if (targetType == "WebPage")
+        return Inspector::DebuggableType::WebPage;
+    RELEASE_ASSERT_NOT_REACHED();
+}
+
+void RemoteInspectorClient::inspect(uint64_t connectionID, uint64_t targetID, const String& targetType)
 {
     auto addResult = m_inspectorProxyMap.ensure(std::make_pair(connectionID, targetID), [this, connectionID, targetID] {
         return makeUnique<RemoteInspectorProxy>(*this, connectionID, targetID);
@@ -214,7 +225,7 @@ void RemoteInspectorClient::inspect(uint64_t connectionID, uint64_t targetID)
     }
 
     m_socketConnection->sendMessage("Setup", g_variant_new("(tt)", connectionID, targetID));
-    addResult.iterator->value->load();
+    addResult.iterator->value->load(debuggableType(targetType));
 }
 
 void RemoteInspectorClient::sendMessageToBackend(uint64_t connectionID, uint64_t targetID, const String& message)
index adee02c..324316d 100644 (file)
@@ -66,7 +66,7 @@ public:
     const String& hostAndPort() const { return m_hostAndPort; }
     const String& backendCommandsURL() const { return m_backendCommandsURL; }
 
-    void inspect(uint64_t connectionID, uint64_t targetID);
+    void inspect(uint64_t connectionID, uint64_t targetID, const String& targetType);
     void sendMessageToBackend(uint64_t connectionID, uint64_t targetID, const String&);
     void closeFromFrontend(uint64_t connectionID, uint64_t targetID);
 
index cfde349..817c398 100644 (file)
@@ -44,6 +44,7 @@
 #include "WebProcessProxy.h"
 #include <WebCore/CertificateInfo.h>
 #include <WebCore/GtkUtilities.h>
+#include <WebCore/InspectorDebuggableType.h>
 #include <WebCore/NotImplemented.h>
 #include <wtf/FileSystem.h>
 #include <wtf/text/Base64.h>
@@ -367,7 +368,9 @@ String WebInspectorProxy::inspectorBaseURL()
 DebuggableInfoData WebInspectorProxy::infoForLocalDebuggable()
 {
     // FIXME <https://webkit.org/b/205536>: this should infer more useful data about the debug target.
-    return DebuggableInfoData::empty();
+    auto data = DebuggableInfoData::empty();
+    data.debuggableType = Inspector::DebuggableType::WebPage;
+    return data;
 }
 
 unsigned WebInspectorProxy::platformInspectedWindowHeight()