Modified: trunk/Source/WebKit/gtk/WebCoreSupport/InspectorClientGtk.cpp (106830 => 106831)
--- trunk/Source/WebKit/gtk/WebCoreSupport/InspectorClientGtk.cpp 2012-02-06 20:00:24 UTC (rev 106830)
+++ trunk/Source/WebKit/gtk/WebCoreSupport/InspectorClientGtk.cpp 2012-02-06 20:12:38 UTC (rev 106831)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 Gustavo Noronha Silva
+ * Copyright (C) 2008, 2012 Gustavo Noronha Silva
* Copyright (C) 2010 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
@@ -171,6 +171,7 @@
void InspectorClient::releaseFrontendPage()
{
m_frontendPage = 0;
+ m_frontendClient = 0;
}
void InspectorClient::highlight()
@@ -220,9 +221,10 @@
InspectorFrontendClient::~InspectorFrontendClient()
{
if (m_inspectorClient) {
- m_inspectorClient->disconnectFrontendClient();
+ m_inspectorClient->releaseFrontendPage();
m_inspectorClient = 0;
}
+
ASSERT(!m_webInspector);
}
@@ -230,12 +232,14 @@
{
if (!m_webInspector)
return;
- WebKitWebInspector* webInspector = m_webInspector;
- m_webInspector = 0;
- g_signal_handlers_disconnect_by_func(m_inspectorWebView, (gpointer)notifyWebViewDestroyed, (gpointer)this);
- m_inspectorWebView = 0;
+ GRefPtr<WebKitWebInspector> webInspector = adoptGRef(m_webInspector.leakRef());
+ if (m_inspectorWebView) {
+ g_signal_handlers_disconnect_by_func(m_inspectorWebView, reinterpret_cast<gpointer>(notifyWebViewDestroyed), this);
+ m_inspectorWebView = 0;
+ }
+
if (notifyInspectorController)
core(m_inspectedWebView)->inspectorController()->disconnectFrontend();
@@ -243,14 +247,11 @@
m_inspectorClient->releaseFrontendPage();
gboolean handled = FALSE;
- g_signal_emit_by_name(webInspector, "close-window", &handled);
+ g_signal_emit_by_name(webInspector.get(), "close-window", &handled);
ASSERT(handled);
// Please do not use member variables here because InspectorFrontendClient object pointed by 'this'
// has been implicitly deleted by "close-window" function.
-
- /* we should now dispose our own reference */
- g_object_unref(webInspector);
}
String InspectorFrontendClient::localizedStringsURL()
@@ -274,7 +275,7 @@
return;
gboolean handled = FALSE;
- g_signal_emit_by_name(m_webInspector, "show-window", &handled);
+ g_signal_emit_by_name(m_webInspector.get(), "show-window", &handled);
}
void InspectorFrontendClient::closeWindow()
@@ -288,7 +289,7 @@
return;
gboolean handled = FALSE;
- g_signal_emit_by_name(m_webInspector, "attach-window", &handled);
+ g_signal_emit_by_name(m_webInspector.get(), "attach-window", &handled);
}
void InspectorFrontendClient::detachWindow()
@@ -297,7 +298,7 @@
return;
gboolean handled = FALSE;
- g_signal_emit_by_name(m_webInspector, "detach-window", &handled);
+ g_signal_emit_by_name(m_webInspector.get(), "detach-window", &handled);
}
void InspectorFrontendClient::setAttachedWindowHeight(unsigned height)
@@ -310,7 +311,7 @@
if (!m_inspectorWebView)
return;
- webkit_web_inspector_set_inspected_uri(m_webInspector, newURL.utf8().data());
+ webkit_web_inspector_set_inspected_uri(m_webInspector.get(), newURL.utf8().data());
}
}
Added: trunk/Source/WebKit/gtk/tests/testwebinspector.c (0 => 106831)
--- trunk/Source/WebKit/gtk/tests/testwebinspector.c (rev 0)
+++ trunk/Source/WebKit/gtk/tests/testwebinspector.c 2012-02-06 20:12:38 UTC (rev 106831)
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2012 Gustavo Noronha Silva <[email protected]>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "test_utils.h"
+
+#include <string.h>
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <webkit/webkit.h>
+
+#if GTK_CHECK_VERSION(2, 14, 0)
+
+GMainLoop *loop;
+GtkWidget *window;
+
+static gboolean quitLoop(gpointer data)
+{
+ g_main_loop_quit(loop);
+ return TRUE;
+}
+
+/* Ignore simple translation-related messages and upgrade other
+ * messages to warnings.
+ */
+static gboolean consoleMessageCallback(WebKitWebView* webView, const char* message, unsigned int line, const char* sourceId)
+{
+ if (strstr(message, "Localized string") || strstr(message, "Protocol Error: the message is for non-existing domain 'Profiler'"))
+ return TRUE;
+
+ g_warning("Console: %s @%d: %s\n", sourceId, line, message);
+ return TRUE;
+}
+
+static WebKitWebView* inspectElementCallback(WebKitWebInspector *inspector, WebKitWebView *inspectedWebView, int *timesElementInspected)
+{
+ *timesElementInspected = *timesElementInspected + 1;
+
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+
+ GtkWidget *newWebView = webkit_web_view_new();
+ gtk_container_add(GTK_CONTAINER(window), newWebView);
+
+ g_signal_connect(newWebView, "console-message",
+ G_CALLBACK(consoleMessageCallback), NULL);
+
+ return WEBKIT_WEB_VIEW(newWebView);
+}
+
+static gboolean closeInspector (WebKitWebInspector *inspector, int *timesClosed)
+{
+ *timesClosed = *timesClosed + 1;
+
+ gtk_widget_destroy(window);
+ return TRUE;
+}
+
+static gboolean showInspector (WebKitWebInspector *inspector, gpointer data)
+{
+ g_idle_add(quitLoop, NULL);
+ return TRUE;
+}
+
+static void test_webkit_web_inspector_close_and_inspect()
+{
+ WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
+
+ WebKitWebSettings *settings = webkit_web_view_get_settings(webView);
+ g_object_set(settings, "enable-developer-extras", TRUE, NULL);
+
+ webkit_web_view_load_string (webView,
+ "<html><body><p>woohoo</p></body></html>",
+ "text/html", "UTF-8", "file://");
+
+ WebKitWebInspector *inspector = webkit_web_view_get_inspector(webView);
+
+ int timesElementInspected = 0;
+ int timesClosed = 0;
+ g_object_connect(inspector,
+ "signal::inspect-web-view", G_CALLBACK(inspectElementCallback), ×ElementInspected,
+ "signal::show-window", G_CALLBACK(showInspector), NULL,
+ "signal::close-window", G_CALLBACK(closeInspector), ×Closed,
+ NULL);
+
+ webkit_web_inspector_inspect_coordinates(inspector, 0.0, 0.0);
+ g_assert_cmpint(timesElementInspected, ==, 1);
+
+ loop = g_main_loop_new(NULL, TRUE);
+ g_main_loop_run(loop);
+
+ webkit_web_inspector_close(inspector);
+ g_assert_cmpint(timesClosed, ==, 1);
+
+ webkit_web_inspector_inspect_coordinates(inspector, 0.0, 0.0);
+ g_assert_cmpint(timesElementInspected, ==, 2);
+
+ g_main_loop_run(loop);
+
+ gtk_widget_destroy(GTK_WIDGET(webView));
+ g_assert_cmpint(timesClosed, ==, 2);
+
+ g_main_loop_unref(loop);
+}
+
+static void test_webkit_web_inspector_destroy_inspected_web_view()
+{
+ WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
+
+ WebKitWebSettings *settings = webkit_web_view_get_settings(webView);
+ g_object_set(settings, "enable-developer-extras", TRUE, NULL);
+
+ webkit_web_view_load_string (webView,
+ "<html><body><p>woohoo</p></body></html>",
+ "text/html", "UTF-8", "file://");
+
+ WebKitWebInspector *inspector = webkit_web_view_get_inspector(webView);
+
+ int timesElementInspected = 0;
+ int timesClosed = 0;
+ g_object_connect(inspector,
+ "signal::inspect-web-view", G_CALLBACK(inspectElementCallback), ×ElementInspected,
+ "signal::show-window", G_CALLBACK(showInspector), NULL,
+ "signal::close-window", G_CALLBACK(closeInspector), ×Closed,
+ NULL);
+
+ webkit_web_inspector_inspect_coordinates(inspector, 0.0, 0.0);
+ g_assert_cmpint(timesElementInspected, ==, 1);
+
+ loop = g_main_loop_new(NULL, TRUE);
+ g_main_loop_run(loop);
+
+ gtk_widget_destroy(GTK_WIDGET(webView));
+ g_assert_cmpint(timesClosed, ==, 1);
+
+ g_main_loop_unref(loop);
+}
+
+int main(int argc, char** argv)
+{
+ gtk_test_init(&argc, &argv, NULL);
+
+ g_test_bug_base("https://bugs.webkit.org/");
+ g_test_add_func("/webkit/webinspector/destroy-inspected-web-view", test_webkit_web_inspector_destroy_inspected_web_view);
+ g_test_add_func("/webkit/webinspector/close-and-inspect", test_webkit_web_inspector_close_and_inspect);
+
+ return g_test_run ();
+}
+
+#else
+int main(int argc, char** argv)
+{
+ g_critical("You will need gtk-2.14.0 to run the unit tests. Doing nothing now.");
+ return 0;
+}
+
+#endif