Title: [215862] trunk/Source
Revision
215862
Author
[email protected]
Date
2017-04-27 05:28:46 -0700 (Thu, 27 Apr 2017)

Log Message

[GTK] Remote inspector should support inspecting targets with previous version of backend commands
https://bugs.webkit.org/show_bug.cgi?id=171267

Reviewed by Michael Catanzaro.

Source/_javascript_Core:

Rename GetTargetList DBus method as SetupInspectorClient since this method is actually called only once by
client right after connecting to the server. The method now receives the client backend commands hash as
argument and returns the contents of the backend commands file in case the hash doesn't match with the local
version.

* PlatformGTK.cmake: Add RemoteInspectorUtils to compilation.
* inspector/remote/glib/RemoteInspectorServer.cpp:
(Inspector::RemoteInspectorServer::setupInspectorClient):
* inspector/remote/glib/RemoteInspectorServer.h:
* inspector/remote/glib/RemoteInspectorUtils.cpp: Added.
(Inspector::backendCommands):
(Inspector::backendCommandsHash):
* inspector/remote/glib/RemoteInspectorUtils.h: Added.

Source/WebInspectorUI:

Allow to use data URLs for script-src.

* UserInterface/Main.html:

Source/WebKit2:

There's a FIXME for this in the code. The remote inspector proxy allows to pass a backend commands URL when
inspecting a target. That URL, if not empty, is used as Protocol/InspectorBackendCommands.js in the inspector
code instead of the local copy. We are currently assuming that both ends use the same version of that file.

* UIProcess/glib/RemoteInspectorClient.cpp:
(WebKit::RemoteInspectorProxy::load): Pass RemoteInspectorClient::backendCommandsURL() to load().
(WebKit::RemoteInspectorClient::setupConnection): Get the local backend commands hash and pass it to
SetupInspectorClient method. Extract the server backend commands from the result and call setBackendCommands().
(WebKit::RemoteInspectorClient::setBackendCommands): Create a data URL for the server backend commands file
conents if needed.
* UIProcess/glib/RemoteInspectorClient.h:
(WebKit::RemoteInspectorClient::backendCommandsURL):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (215861 => 215862)


--- trunk/Source/_javascript_Core/ChangeLog	2017-04-27 11:02:09 UTC (rev 215861)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-04-27 12:28:46 UTC (rev 215862)
@@ -1,3 +1,24 @@
+2017-04-27  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Remote inspector should support inspecting targets with previous version of backend commands
+        https://bugs.webkit.org/show_bug.cgi?id=171267
+
+        Reviewed by Michael Catanzaro.
+
+        Rename GetTargetList DBus method as SetupInspectorClient since this method is actually called only once by
+        client right after connecting to the server. The method now receives the client backend commands hash as
+        argument and returns the contents of the backend commands file in case the hash doesn't match with the local
+        version.
+
+        * PlatformGTK.cmake: Add RemoteInspectorUtils to compilation.
+        * inspector/remote/glib/RemoteInspectorServer.cpp:
+        (Inspector::RemoteInspectorServer::setupInspectorClient):
+        * inspector/remote/glib/RemoteInspectorServer.h:
+        * inspector/remote/glib/RemoteInspectorUtils.cpp: Added.
+        (Inspector::backendCommands):
+        (Inspector::backendCommandsHash):
+        * inspector/remote/glib/RemoteInspectorUtils.h: Added.
+
 2017-04-27  Yusuke Suzuki  <[email protected]>
 
         [JSC] Handle PhantomSpread in LoadVarargs as the same to the others

Modified: trunk/Source/_javascript_Core/PlatformGTK.cmake (215861 => 215862)


--- trunk/Source/_javascript_Core/PlatformGTK.cmake	2017-04-27 11:02:09 UTC (rev 215861)
+++ trunk/Source/_javascript_Core/PlatformGTK.cmake	2017-04-27 12:28:46 UTC (rev 215862)
@@ -18,6 +18,7 @@
     inspector/remote/glib/RemoteConnectionToTargetGlib.cpp
     inspector/remote/glib/RemoteInspectorGlib.cpp
     inspector/remote/glib/RemoteInspectorServer.cpp
+    inspector/remote/glib/RemoteInspectorUtils.cpp
 )
 
 add_custom_command(

Modified: trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorServer.cpp (215861 => 215862)


--- trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorServer.cpp	2017-04-27 11:02:09 UTC (rev 215861)
+++ trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorServer.cpp	2017-04-27 12:28:46 UTC (rev 215862)
@@ -29,6 +29,7 @@
 #if ENABLE(REMOTE_INSPECTOR)
 
 #include "RemoteInspector.h"
+#include "RemoteInspectorUtils.h"
 #include <gio/gio.h>
 #include <wtf/Vector.h>
 #include <wtf/glib/GUniquePtr.h>
@@ -57,7 +58,10 @@
     "      <arg type='a(tsssb)' name='list' direction='in'/>"
     "      <arg type='b' name='remoteAutomationEnabled' direction='in'/>"
     "    </method>"
-    "    <method name='GetTargetList'/>"
+    "    <method name='SetupInspectorClient'>"
+    "      <arg type='ay' name='backendCommandsHash' direction='in'/>"
+    "      <arg type='ay' name='backendCommands' direction='out'/>"
+    "    </method>"
     "    <method name='Setup'>"
     "      <arg type='t' name='connection' direction='in'/>"
     "      <arg type='t' name='target' direction='in'/>"
@@ -88,9 +92,11 @@
         if (!g_strcmp0(methodName, "SetTargetList")) {
             inspectorServer->setTargetList(connection, parameters);
             g_dbus_method_invocation_return_value(invocation, nullptr);
-        } else if (!g_strcmp0(methodName, "GetTargetList")) {
-            inspectorServer->getTargetList(connection);
-            g_dbus_method_invocation_return_value(invocation, nullptr);
+        } else if (!g_strcmp0(methodName, "SetupInspectorClient")) {
+            GRefPtr<GVariant> backendCommandsHash;
+            g_variant_get(parameters, "(@ay)", &backendCommandsHash.outPtr());
+            auto* backendCommands = inspectorServer->setupInspectorClient(connection, g_variant_get_bytestring(backendCommandsHash.get()));
+            g_dbus_method_invocation_return_value(invocation, g_variant_new("(@ay)", backendCommands));
         } else if (!g_strcmp0(methodName, "Setup")) {
             guint64 connectionID, targetID;
             g_variant_get(parameters, "(tt)", &connectionID, &targetID);
@@ -230,14 +236,20 @@
     server->clientConnectionClosed(connection);
 }
 
-void RemoteInspectorServer::getTargetList(GDBusConnection* clientConnection)
+GVariant* RemoteInspectorServer::setupInspectorClient(GDBusConnection* clientConnection, const char* clientBackendCommandsHash)
 {
-    if (!m_clientConnection) {
-        m_clientConnection = clientConnection;
-        g_signal_connect(m_clientConnection.get(), "closed", G_CALLBACK(clientConnectionClosedCallback), this);
-    }
-    ASSERT(m_clientConnection.get() == clientConnection);
+    ASSERT(!m_clientConnection);
+    m_clientConnection = clientConnection;
+    g_signal_connect(m_clientConnection.get(), "closed", G_CALLBACK(clientConnectionClosedCallback), this);
 
+    GVariant* backendCommands;
+    if (strcmp(clientBackendCommandsHash, backendCommandsHash().data())) {
+        auto bytes = Inspector::backendCommands();
+        backendCommands = g_variant_new_bytestring(static_cast<const char*>(g_bytes_get_data(bytes.get(), nullptr)));
+    } else
+        backendCommands = g_variant_new_bytestring("");
+
+    // Ask all remote inspectors to push their target lists to notify the new client.
     for (auto* remoteInspectorConnection : m_remoteInspectorConnectionToIDMap.keys()) {
         g_dbus_connection_call(remoteInspectorConnection, nullptr,
             REMOTE_INSPECTOR_DBUS_OBJECT_PATH,
@@ -247,6 +259,8 @@
             nullptr, G_DBUS_CALL_FLAGS_NO_AUTO_START,
             -1, m_cancellable.get(), dbusConnectionCallAsyncReadyCallback, nullptr);
     }
+
+    return backendCommands;
 }
 
 void RemoteInspectorServer::setup(GDBusConnection* clientConnection, uint64_t connectionID, uint64_t targetID)

Modified: trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorServer.h (215861 => 215862)


--- trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorServer.h	2017-04-27 11:02:09 UTC (rev 215861)
+++ trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorServer.h	2017-04-27 12:28:46 UTC (rev 215862)
@@ -59,7 +59,7 @@
 
     static const GDBusInterfaceVTable s_interfaceVTable;
     void setTargetList(GDBusConnection*, GVariant*);
-    void getTargetList(GDBusConnection*);
+    GVariant* setupInspectorClient(GDBusConnection*, const char* clientBackendCommandsHash);
     void setup(GDBusConnection*, uint64_t connectionID, uint64_t targetID);
     void close(GDBusConnection*, uint64_t connectionID, uint64_t targetID);
     void clientConnectionClosed(GDBusConnection*);

Added: trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorUtils.cpp (0 => 215862)


--- trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorUtils.cpp	                        (rev 0)
+++ trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorUtils.cpp	2017-04-27 12:28:46 UTC (rev 215862)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RemoteInspectorUtils.h"
+
+#if ENABLE(REMOTE_INSPECTOR)
+
+#include <gio/gio.h>
+#include <wtf/SHA1.h>
+
+#if PLATFORM(GTK)
+#define INSPECTOR_BACKEND_COMMANDS_PATH "/org/webkitgtk/inspector/UserInterface/Protocol/InspectorBackendCommands.js"
+#endif
+
+namespace Inspector {
+
+GRefPtr<GBytes> backendCommands()
+{
+    GRefPtr<GBytes> bytes = adoptGRef(g_resources_lookup_data(INSPECTOR_BACKEND_COMMANDS_PATH, G_RESOURCE_LOOKUP_FLAGS_NONE, nullptr));
+    ASSERT(bytes);
+    return bytes;
+}
+
+const CString& backendCommandsHash()
+{
+    static CString hexDigest;
+    if (hexDigest.isNull()) {
+        auto bytes = backendCommands();
+        size_t dataSize;
+        gconstpointer data = "" &dataSize);
+        ASSERT(dataSize);
+        SHA1 sha1;
+        sha1.addBytes(static_cast<const uint8_t*>(data), dataSize);
+        hexDigest = sha1.computeHexDigest();
+    }
+    return hexDigest;
+}
+
+} // namespace Inspector
+
+#endif // ENABLE(REMOTE_INSPECTOR)

Added: trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorUtils.h (0 => 215862)


--- trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorUtils.h	                        (rev 0)
+++ trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorUtils.h	2017-04-27 12:28:46 UTC (rev 215862)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(REMOTE_INSPECTOR)
+
+#include <wtf/glib/GRefPtr.h>
+#include <wtf/text/CString.h>
+
+typedef struct _GBytes GBytes;
+
+namespace Inspector {
+
+GRefPtr<GBytes> backendCommands();
+const CString& backendCommandsHash();
+
+} // namespace Inspector
+
+#endif // ENABLE(REMOTE_INSPECTOR)

Modified: trunk/Source/WebInspectorUI/ChangeLog (215861 => 215862)


--- trunk/Source/WebInspectorUI/ChangeLog	2017-04-27 11:02:09 UTC (rev 215861)
+++ trunk/Source/WebInspectorUI/ChangeLog	2017-04-27 12:28:46 UTC (rev 215862)
@@ -1,3 +1,14 @@
+2017-04-27  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Remote inspector should support inspecting targets with previous version of backend commands
+        https://bugs.webkit.org/show_bug.cgi?id=171267
+
+        Reviewed by Michael Catanzaro.
+
+        Allow to use data URLs for script-src.
+
+        * UserInterface/Main.html:
+
 2017-04-25  Nikita Vasilyev  <[email protected]>
 
         REGRESSION (r209882): Web Inspector: Command-G does not work in the console

Modified: trunk/Source/WebInspectorUI/UserInterface/Main.html (215861 => 215862)


--- trunk/Source/WebInspectorUI/UserInterface/Main.html	2017-04-27 11:02:09 UTC (rev 215861)
+++ trunk/Source/WebInspectorUI/UserInterface/Main.html	2017-04-27 12:28:46 UTC (rev 215862)
@@ -26,7 +26,7 @@
 <html>
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-    <meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src * file: blob: resource:; connect-src * ws:; media-src * blob:; font-src * blob:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'">
+    <meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src * file: blob: resource:; connect-src * ws:; media-src * blob:; font-src * blob:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' data:">
 
     <link rel="stylesheet" href=""
 

Modified: trunk/Source/WebKit2/ChangeLog (215861 => 215862)


--- trunk/Source/WebKit2/ChangeLog	2017-04-27 11:02:09 UTC (rev 215861)
+++ trunk/Source/WebKit2/ChangeLog	2017-04-27 12:28:46 UTC (rev 215862)
@@ -1,3 +1,23 @@
+2017-04-27  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Remote inspector should support inspecting targets with previous version of backend commands
+        https://bugs.webkit.org/show_bug.cgi?id=171267
+
+        Reviewed by Michael Catanzaro.
+
+        There's a FIXME for this in the code. The remote inspector proxy allows to pass a backend commands URL when
+        inspecting a target. That URL, if not empty, is used as Protocol/InspectorBackendCommands.js in the inspector
+        code instead of the local copy. We are currently assuming that both ends use the same version of that file.
+
+        * UIProcess/glib/RemoteInspectorClient.cpp:
+        (WebKit::RemoteInspectorProxy::load): Pass RemoteInspectorClient::backendCommandsURL() to load().
+        (WebKit::RemoteInspectorClient::setupConnection): Get the local backend commands hash and pass it to
+        SetupInspectorClient method. Extract the server backend commands from the result and call setBackendCommands().
+        (WebKit::RemoteInspectorClient::setBackendCommands): Create a data URL for the server backend commands file
+        conents if needed.
+        * UIProcess/glib/RemoteInspectorClient.h:
+        (WebKit::RemoteInspectorClient::backendCommandsURL):
+
 2017-04-26  Wenson Hsieh  <[email protected]>
 
         WebItemProviderPasteboard should not synchronously load provided data

Modified: trunk/Source/WebKit2/UIProcess/glib/RemoteInspectorClient.cpp (215861 => 215862)


--- trunk/Source/WebKit2/UIProcess/glib/RemoteInspectorClient.cpp	2017-04-27 11:02:09 UTC (rev 215861)
+++ trunk/Source/WebKit2/UIProcess/glib/RemoteInspectorClient.cpp	2017-04-27 12:28:46 UTC (rev 215862)
@@ -29,8 +29,10 @@
 #if ENABLE(REMOTE_INSPECTOR)
 
 #include "RemoteWebInspectorProxy.h"
+#include <_javascript_Core/RemoteInspectorUtils.h>
 #include <gio/gio.h>
 #include <wtf/glib/GUniquePtr.h>
+#include <wtf/text/Base64.h>
 
 #if PLATFORM(GTK)
 #define REMOTE_INSPECTOR_CLIENT_DBUS_INTERFACE "org.webkitgtk.RemoteInspectorClient"
@@ -61,8 +63,7 @@
 
     void load()
     {
-        // FIXME: support old backend commands URL.
-        m_proxy->load("web", String());
+        m_proxy->load("web", m_inspectorClient.backendCommandsURL());
     }
 
     void show()
@@ -204,12 +205,38 @@
     g_dbus_connection_call(m_dbusConnection.get(), nullptr,
         INSPECTOR_DBUS_OBJECT_PATH,
         INSPECTOR_DBUS_INTERFACE,
-        "GetTargetList",
-        nullptr,
+        "SetupInspectorClient",
+        g_variant_new("(@ay)", g_variant_new_bytestring(Inspector::backendCommandsHash().data())),
         nullptr, G_DBUS_CALL_FLAGS_NO_AUTO_START,
-        -1, m_cancellable.get(), dbusConnectionCallAsyncReadyCallback, nullptr);
+        -1, m_cancellable.get(), [](GObject* source, GAsyncResult* result, gpointer userData) {
+            GUniqueOutPtr<GError> error;
+            GRefPtr<GVariant> resultVariant = adoptGRef(g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error.outPtr()));
+            if (g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED))
+                return;
+            if (!resultVariant) {
+                WTFLogAlways("RemoteInspectorClient failed to send DBus message: %s", error->message);
+                return;
+            }
+
+            auto* client = static_cast<RemoteInspectorClient*>(userData);
+            GRefPtr<GVariant> backendCommandsVariant;
+            g_variant_get(resultVariant.get(), "(@ay)", &backendCommandsVariant.outPtr());
+            client->setBackendCommands(g_variant_get_bytestring(backendCommandsVariant.get()));
+        }, this);
 }
 
+void RemoteInspectorClient::setBackendCommands(const char* backendCommands)
+{
+    if (!backendCommands || !backendCommands[0]) {
+        m_backendCommandsURL = String();
+        return;
+    }
+
+    Vector<char> base64Data;
+    base64Encode(backendCommands, strlen(backendCommands), base64Data);
+    m_backendCommandsURL = "data:text/_javascript_;base64," + base64Data;
+}
+
 void RemoteInspectorClient::connectionClosed()
 {
     g_cancellable_cancel(m_cancellable.get());

Modified: trunk/Source/WebKit2/UIProcess/glib/RemoteInspectorClient.h (215861 => 215862)


--- trunk/Source/WebKit2/UIProcess/glib/RemoteInspectorClient.h	2017-04-27 11:02:09 UTC (rev 215861)
+++ trunk/Source/WebKit2/UIProcess/glib/RemoteInspectorClient.h	2017-04-27 12:28:46 UTC (rev 215862)
@@ -65,6 +65,7 @@
 
     const HashMap<uint64_t, Vector<Target>>& targets() const { return m_targets; }
     const String& hostAndPort() const { return m_hostAndPort; }
+    const String& backendCommandsURL() const { return m_backendCommandsURL; }
 
     void inspect(uint64_t connectionID, uint64_t targetID);
     void sendMessageToBackend(uint64_t connectionID, uint64_t targetID, const String&);
@@ -76,10 +77,12 @@
     void connectionClosed();
 
     static const GDBusInterfaceVTable s_interfaceVTable;
+    void setBackendCommands(const char*);
     void setTargetList(uint64_t connectionID, Vector<Target>&&);
     void sendMessageToFrontend(uint64_t connectionID, uint64_t targetID, const char*);
 
     String m_hostAndPort;
+    String m_backendCommandsURL;
     RemoteInspectorObserver& m_observer;
     GRefPtr<GDBusConnection> m_dbusConnection;
     GRefPtr<GCancellable> m_cancellable;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to