Diff
Modified: trunk/Source/WebKit/ChangeLog (292598 => 292599)
--- trunk/Source/WebKit/ChangeLog 2022-04-08 11:15:48 UTC (rev 292598)
+++ trunk/Source/WebKit/ChangeLog 2022-04-08 11:56:29 UTC (rev 292599)
@@ -1,5 +1,32 @@
2022-04-08 Carlos Garcia Campos <[email protected]>
+ [GTK] RemoteInspector: update target list page contents on change instead of reloading
+ https://bugs.webkit.org/show_bug.cgi?id=238990
+
+ Reviewed by Adrian Perez de Castro.
+
+ We can use webkit_web_view_run_javascript() to replace the target list with the new one. This also fixes the race
+ condition when loading inspector:// for the first time that target list is always empty. The web view HashSet is
+ now a HashMap where the value is a pointer to the client to be able to associate web view with its client
+ without having to check the host and port.
+
+ * UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp:
+ (WebKit::RemoteInspectorProtocolHandler::~RemoteInspectorProtocolHandler): Disconnect web view signals.
+ (WebKit::RemoteInspectorProtocolHandler::handleRequest): On new web view, connect to notify::uri and remove the
+ web view if it's no longer showing an inspector page list.
+ (WebKit::RemoteInspectorProtocolHandler::updateTargetList): Update the target list html.
+ (WebKit::RemoteInspectorProtocolHandler::webViewLoadChanged): Call updateTargetList() when load finished.
+ (WebKit::RemoteInspectorProtocolHandler::targetListChanged): Call updateTargetList() for web views that are not
+ loading. For loading web view connect to load-event to update the target list once the load finishes.
+ (WebKit::RemoteInspectorProtocolHandler::connectionClosed): Remove the associated web views.
+ * UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.h:
+ * UIProcess/Inspector/glib/RemoteInspectorClient.cpp:
+ (WebKit::RemoteInspectorClient::appendTargertList const): Append the target list html to the given GString.
+ (WebKit::RemoteInspectorClient::buildTargetListPage const): Use appendTargertList() now.
+ * UIProcess/Inspector/glib/RemoteInspectorClient.h:
+
+2022-04-08 Carlos Garcia Campos <[email protected]>
+
Web Inspector: Use computedStyleMap() instead of deprecated getPropertyCSSValue()
https://bugs.webkit.org/show_bug.cgi?id=238661
Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp (292598 => 292599)
--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp 2022-04-08 11:15:48 UTC (rev 292598)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp 2022-04-08 11:56:29 UTC (rev 292599)
@@ -30,6 +30,7 @@
#include "WebPageProxy.h"
#include "WebScriptMessageHandler.h"
#include <wtf/URL.h>
+#include <wtf/glib/GUniquePtr.h>
#include <wtf/text/StringToIntegerConversion.h>
namespace WebKit {
@@ -78,8 +79,10 @@
RemoteInspectorProtocolHandler::~RemoteInspectorProtocolHandler()
{
- for (auto* webView : m_webViews)
+ for (auto* webView : m_webViews.keys()) {
+ g_signal_handlers_disconnect_by_data(webView, this);
g_object_weak_unref(G_OBJECT(webView), reinterpret_cast<GWeakNotify>(webViewDestroyed), this);
+ }
for (auto* userContentManager : m_userContentManagers) {
webkitUserContentManagerGetUserContentControllerProxy(userContentManager)->removeUserMessageHandlerForName("inspector"_s, API::ContentWorld::pageContentWorld());
@@ -108,9 +111,18 @@
auto* webView = webkit_uri_scheme_request_get_web_view(request);
ASSERT(webView);
- auto webViewResult = m_webViews.add(webView);
- if (webViewResult.isNewEntry)
+ auto webViewResult = m_webViews.add(webView, nullptr);
+ if (webViewResult.isNewEntry) {
+ g_signal_connect(webView, "notify::uri", G_CALLBACK(+[](WebKitWebView* webView, GParamSpec*, RemoteInspectorProtocolHandler* handler) {
+ URL webViewURL = URL(String::fromUTF8(webkit_web_view_get_uri(webView)));
+ if (!webViewURL.protocolIs("inspector") || !handler->m_inspectorClients.contains(webViewURL.hostAndPort())) {
+ g_signal_handlers_disconnect_by_data(webView, handler);
+ g_object_weak_unref(G_OBJECT(webView), reinterpret_cast<GWeakNotify>(webViewDestroyed), handler);
+ handler->m_webViews.remove(webView);
+ }
+ }), this);
g_object_weak_ref(G_OBJECT(webView), reinterpret_cast<GWeakNotify>(webViewDestroyed), this);
+ }
auto* userContentManager = webkit_web_view_get_user_content_manager(webView);
auto userContentManagerResult = m_userContentManagers.add(userContentManager);
@@ -123,6 +135,7 @@
auto* client = m_inspectorClients.ensure(requestURL.hostAndPort(), [this, &requestURL] {
return makeUnique<RemoteInspectorClient>(requestURL.hostAndPort(), *this);
}).iterator->value.get();
+ webViewResult.iterator->value = client;
auto* html = client->buildTargetListPage(RemoteInspectorClient::InspectorType::UI);
gsize streamLength = html->len;
@@ -136,31 +149,51 @@
client->inspect(connectionID, tatgetID, targetType);
}
+void RemoteInspectorProtocolHandler::updateTargetList(WebKitWebView* webView)
+{
+ auto* clientForWebView = m_webViews.get(webView);
+ if (!clientForWebView)
+ return;
+
+ GString* script = g_string_new("document.getElementById('targetlist').innerHTML='");
+ clientForWebView->appendTargertList(script, RemoteInspectorClient::InspectorType::UI, RemoteInspectorClient::ShouldEscapeSingleQuote::Yes);
+ g_string_append(script, "';");
+ webkit_web_view_run_javascript(webView, script->str, nullptr, nullptr, nullptr);
+ g_string_free(script, TRUE);
+}
+
+void RemoteInspectorProtocolHandler::webViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent event, RemoteInspectorProtocolHandler* handler)
+{
+ if (event != WEBKIT_LOAD_FINISHED)
+ return;
+
+ g_signal_handlers_disconnect_by_func(webView, reinterpret_cast<gpointer>(webViewLoadChanged), handler);
+ handler->updateTargetList(webView);
+}
+
void RemoteInspectorProtocolHandler::targetListChanged(RemoteInspectorClient& client)
{
- Vector<WebKitWebView*, 4> webViewsToRemove;
- for (auto* webView : m_webViews) {
- if (webkit_web_view_is_loading(webView))
+ for (auto* webView : m_webViews.keys()) {
+ if (m_webViews.get(webView) != &client)
continue;
- URL webViewURL = URL(String { webkit_web_view_get_uri(webView) });
- auto clientForWebView = m_inspectorClients.get(webViewURL.hostAndPort());
- if (!clientForWebView) {
- // This view is not showing a inspector view anymore.
- webViewsToRemove.append(webView);
- } else if (clientForWebView == &client)
- webkit_web_view_reload(webView);
+ if (webkit_web_view_is_loading(webView))
+ g_signal_connect(webView, "load-changed", reinterpret_cast<GCallback>(webViewLoadChanged), this);
+ else
+ updateTargetList(webView);
}
-
- for (auto* webView : webViewsToRemove) {
- g_object_weak_unref(G_OBJECT(webView), reinterpret_cast<GWeakNotify>(webViewDestroyed), this);
- m_webViews.remove(webView);
- }
}
void RemoteInspectorProtocolHandler::connectionClosed(RemoteInspectorClient& client)
{
- targetListChanged(client);
+ m_webViews.removeIf([&](auto& entry) {
+ if (entry.value == &client) {
+ g_signal_handlers_disconnect_by_data(entry.key, this);
+ g_object_weak_unref(G_OBJECT(entry.key), reinterpret_cast<GWeakNotify>(webViewDestroyed), this);
+ return true;
+ }
+ return false;
+ });
m_inspectorClients.remove(client.hostAndPort());
}
Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.h (292598 => 292599)
--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.h 2022-04-08 11:15:48 UTC (rev 292598)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.h 2022-04-08 11:56:29 UTC (rev 292599)
@@ -44,6 +44,8 @@
static void userContentManagerDestroyed(RemoteInspectorProtocolHandler*, WebKitUserContentManager*);
void handleRequest(WebKitURISchemeRequest*);
+ void updateTargetList(WebKitWebView*);
+ static void webViewLoadChanged(WebKitWebView*, WebKitLoadEvent, RemoteInspectorProtocolHandler*);
// RemoteInspectorObserver.
void targetListChanged(RemoteInspectorClient&) override;
@@ -51,7 +53,7 @@
HashMap<String, std::unique_ptr<RemoteInspectorClient>> m_inspectorClients;
HashSet<WebKitUserContentManager*> m_userContentManagers;
- HashSet<WebKitWebView*> m_webViews;
+ HashMap<WebKitWebView*, RemoteInspectorClient*> m_webViews;
};
} // namespace WebKit
Modified: trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp (292598 => 292599)
--- trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp 2022-04-08 11:15:48 UTC (rev 292598)
+++ trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp 2022-04-08 11:56:29 UTC (rev 292599)
@@ -292,27 +292,8 @@
proxy->sendMessageToFrontend(String::fromUTF8(message));
}
-GString* RemoteInspectorClient::buildTargetListPage(InspectorType inspectorType) const
+void RemoteInspectorClient::appendTargertList(GString* html, InspectorType inspectorType, ShouldEscapeSingleQuote escapeSingleQuote) const
{
- GString* html = g_string_new(
- "<html><head><title>Remote inspector</title>"
- "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
- "<style>"
- " h1 { color: #babdb6; text-shadow: 0 1px 0 white; margin-bottom: 0; }"
- " html { font-family: -webkit-system-font; font-size: 11pt; color: #2e3436; padding: 20px 20px 0 20px; background-color: #f6f6f4; "
- " background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #eeeeec), color-stop(1, #f6f6f4));"
- " background-size: 100% 5em; background-repeat: no-repeat; }"
- " table { width: 100%; border-collapse: collapse; }"
- " table, td { border: 1px solid #d3d7cf; border-left: none; border-right: none; }"
- " p { margin-bottom: 30px; }"
- " td { padding: 15px; }"
- " td.data { width: 200px; }"
- " .targetname { font-weight: bold; }"
- " .targeturl { color: #babdb6; }"
- " td.input { width: 64px; }"
- " input { width: 100%; padding: 8px; }"
- "</style>"
- "</head><body><h1>Inspectable targets</h1>");
if (m_targets.isEmpty())
g_string_append(html, "<p>No targets found</p>");
else {
@@ -327,8 +308,16 @@
switch (inspectorType) {
case InspectorType::UI:
- g_string_append_printf(html, "\"window.webkit.messageHandlers.inspector.postMessage('%" G_GUINT64_FORMAT ":%" G_GUINT64_FORMAT ":%s');\"",
- connectionID, target.id, target.type.data());
+ g_string_append(html, "\"window.webkit.messageHandlers.inspector.postMessage(");
+ if (escapeSingleQuote == ShouldEscapeSingleQuote::Yes)
+ g_string_append(html, "\\'");
+ else
+ g_string_append_c(html, '\'');
+ g_string_append_printf(html, "%" G_GUINT64_FORMAT ":%" G_GUINT64_FORMAT ":%s", connectionID, target.id, target.type.data());
+ if (escapeSingleQuote == ShouldEscapeSingleQuote::Yes)
+ g_string_append(html, "\\')\"");
+ else
+ g_string_append(html, "')\"");
break;
case InspectorType::HTTP:
g_string_append_printf(html,
@@ -343,8 +332,33 @@
}
g_string_append(html, "</table>");
}
- g_string_append(html, "</body></html>");
+}
+GString* RemoteInspectorClient::buildTargetListPage(InspectorType inspectorType) const
+{
+ GString* html = g_string_new(
+ "<html><head><title>Remote inspector</title>"
+ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
+ "<style>"
+ " h1 { color: #babdb6; text-shadow: 0 1px 0 white; margin-bottom: 0; }"
+ " html { font-family: -webkit-system-font; font-size: 11pt; color: #2e3436; padding: 20px 20px 0 20px; background-color: #f6f6f4; "
+ " background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #eeeeec), color-stop(1, #f6f6f4));"
+ " background-size: 100% 5em; background-repeat: no-repeat; }"
+ " table { width: 100%; border-collapse: collapse; }"
+ " table, td { border: 1px solid #d3d7cf; border-left: none; border-right: none; }"
+ " p { margin-bottom: 30px; }"
+ " td { padding: 15px; }"
+ " td.data { width: 200px; }"
+ " .targetname { font-weight: bold; }"
+ " .targeturl { color: #babdb6; }"
+ " td.input { width: 64px; }"
+ " input { width: 100%; padding: 8px; }"
+ "</style>"
+ "</head><body><h1>Inspectable targets</h1>"
+ "<div id='targetlist'>");
+ appendTargertList(html, inspectorType, ShouldEscapeSingleQuote::No);
+ g_string_append(html, "</div></body></html>");
+
return html;
}
Modified: trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.h (292598 => 292599)
--- trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.h 2022-04-08 11:15:48 UTC (rev 292598)
+++ trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.h 2022-04-08 11:56:29 UTC (rev 292599)
@@ -59,6 +59,8 @@
enum class InspectorType { UI, HTTP };
GString* buildTargetListPage(InspectorType) const;
+ enum class ShouldEscapeSingleQuote : bool { No, Yes };
+ void appendTargertList(GString*, InspectorType, ShouldEscapeSingleQuote) const;
void inspect(uint64_t connectionID, uint64_t targetID, const String& targetType, InspectorType = InspectorType::UI);
void sendMessageToBackend(uint64_t connectionID, uint64_t targetID, const String&);
void closeFromFrontend(uint64_t connectionID, uint64_t targetID);