Commit 07d6d0ca authored by kov@webkit.org's avatar kov@webkit.org
Browse files

[GTK] Insta-crash when closing browser with inspector window opened

https://bugs.webkit.org/show_bug.cgi?id=50744

Reviewed by Martin Robinson.

Source/WebKit/gtk:

* GNUmakefile.am:
* WebCoreSupport/InspectorClientGtk.cpp:
(WebKit::InspectorClient::releaseFrontendPage): also let go of the
frontend client when releasing the frontend page;
(WebKit::InspectorFrontendClient::~InspectorFrontendClient(): Call releaseFrontendPage()
like other ports do instead of just disconnectFrontendClient().
(WebKit::InspectorFrontendClient::destroyInspectorWindow): Use GRefPtr for the
inspector ref.
(WebKit::InspectorFrontendClient::bringToFront): Adjust for GRefPtr usage.
(WebKit::InspectorFrontendClient::attachWindow): Ditto.
(WebKit::InspectorFrontendClient::detachWindow): Ditto.
(WebKit::InspectorFrontendClient::inspectedURLChanged): Ditto.
* WebCoreSupport/InspectorClientGtk.h:
(InspectorFrontendClient): Use GRefPtr for inspector member.
* tests/testwebinspector.c: Added. Test that killing a WebView with the inspector
open does not crash, and that closing and reinspecting works.
(quitLoop):
(consoleMessageCallback):
(inspectElementCallback):
(closeInspector):
(showInspector):
(test_webkit_web_inspector_close_and_inspect):
(test_webkit_web_inspector_destroy_inspected_web_view):
(main):

LayoutTests:

* platform/gtk/Skipped: unskip inspector/debugger/open-close-open.html,
which now passes.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@106831 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent feafc892
2012-02-05 Gustavo Noronha Silva <gns@gnome.org>
[GTK] Insta-crash when closing browser with inspector window opened
https://bugs.webkit.org/show_bug.cgi?id=50744
Reviewed by Martin Robinson.
* platform/gtk/Skipped: unskip inspector/debugger/open-close-open.html,
which now passes.
2012-02-06 Joshua Bell <jsbell@chromium.org>
 
IndexedDB: Raise exception during add/put call if autoIncrement key insertion will fail
......@@ -101,9 +101,6 @@ fast/forms/multiple-form-submission-protection-mouse.html
# This test crashes whatever test follows it. Perhaps it's related to the previous failure.
fast/dom/gc-10.html
# https://bugs.webkit.org/show_bug.cgi?id=50744
inspector/debugger/open-close-open.html
# [GTK] fast/workers/storage/use-same-database-in-page-and-workers.html fails an ASSERT
# https://bugs.webkit.org/show_bug.cgi?id=56147
# Fails assertion: ASSERT(m_workerContext->hasOneRef());
......
2012-02-05 Gustavo Noronha Silva <gns@gnome.org>
[GTK] Insta-crash when closing browser with inspector window opened
https://bugs.webkit.org/show_bug.cgi?id=50744
Reviewed by Martin Robinson.
* GNUmakefile.am:
* WebCoreSupport/InspectorClientGtk.cpp:
(WebKit::InspectorClient::releaseFrontendPage): also let go of the
frontend client when releasing the frontend page;
(WebKit::InspectorFrontendClient::~InspectorFrontendClient(): Call releaseFrontendPage()
like other ports do instead of just disconnectFrontendClient().
(WebKit::InspectorFrontendClient::destroyInspectorWindow): Use GRefPtr for the
inspector ref.
(WebKit::InspectorFrontendClient::bringToFront): Adjust for GRefPtr usage.
(WebKit::InspectorFrontendClient::attachWindow): Ditto.
(WebKit::InspectorFrontendClient::detachWindow): Ditto.
(WebKit::InspectorFrontendClient::inspectedURLChanged): Ditto.
* WebCoreSupport/InspectorClientGtk.h:
(InspectorFrontendClient): Use GRefPtr for inspector member.
* tests/testwebinspector.c: Added. Test that killing a WebView with the inspector
open does not crash, and that closing and reinspecting works.
(quitLoop):
(consoleMessageCallback):
(inspectElementCallback):
(closeInspector):
(showInspector):
(test_webkit_web_inspector_close_and_inspect):
(test_webkit_web_inspector_destroy_inspected_web_view):
(main):
2012-02-06 Gustavo Noronha Silva <gns@gnome.org>
 
Add a null check for the gdkwindow, that will happen if the window
......
......@@ -456,6 +456,7 @@ TEST_PROGS += \
Programs/unittests/testatk \
Programs/unittests/testatkroles \
Programs/unittests/testhittestresult \
Programs/unittests/testwebinspector \
Programs/unittests/testwebsettings \
Programs/unittests/testwebresource \
Programs/unittests/testwebdatasource \
......@@ -555,6 +556,11 @@ Programs_unittests_testatkroles_CFLAGS = $(webkit_tests_cflags)
Programs_unittests_testatkroles_LDADD = $(webkit_tests_ldadd)
Programs_unittests_testatkroles_LDFLAGS = $(webkit_tests_ldflags)
Programs_unittests_testwebinspector_SOURCES = Source/WebKit/gtk/tests/testwebinspector.c Source/WebKit/gtk/tests/test_utils.c
Programs_unittests_testwebinspector_CFLAGS = $(webkit_tests_cflags)
Programs_unittests_testwebinspector_LDADD = $(webkit_tests_ldadd)
Programs_unittests_testwebinspector_LDFLAGS = $(webkit_tests_ldflags)
Programs_unittests_testwebsettings_SOURCES = Source/WebKit/gtk/tests/testwebsettings.c
Programs_unittests_testwebsettings_CFLAGS = $(webkit_tests_cflags)
Programs_unittests_testwebsettings_LDADD = $(webkit_tests_ldadd)
......
/*
* 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::bringFrontendToFront()
void InspectorClient::releaseFrontendPage()
{
m_frontendPage = 0;
m_frontendClient = 0;
}
void InspectorClient::highlight()
......@@ -220,9 +221,10 @@ InspectorFrontendClient::InspectorFrontendClient(WebKitWebView* inspectedWebView
InspectorFrontendClient::~InspectorFrontendClient()
{
if (m_inspectorClient) {
m_inspectorClient->disconnectFrontendClient();
m_inspectorClient->releaseFrontendPage();
m_inspectorClient = 0;
}
ASSERT(!m_webInspector);
}
......@@ -230,11 +232,13 @@ void InspectorFrontendClient::destroyInspectorWindow(bool notifyInspectorControl
{
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 @@ void InspectorFrontendClient::destroyInspectorWindow(bool notifyInspectorControl
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 @@ void InspectorFrontendClient::bringToFront()
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 @@ void InspectorFrontendClient::attachWindow()
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 @@ void InspectorFrontendClient::detachWindow()
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 @@ void InspectorFrontendClient::inspectedURLChanged(const String& newURL)
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());
}
}
......
......@@ -30,6 +30,7 @@
#define InspectorClientGtk_h
#include "GOwnPtr.h"
#include "GRefPtr.h"
#include "InspectorClient.h"
#include "InspectorFrontendClientLocal.h"
#include "webkitwebview.h"
......@@ -98,7 +99,7 @@ namespace WebKit {
private:
WebKitWebView* m_inspectorWebView;
WebKitWebView* m_inspectedWebView;
WebKitWebInspector* m_webInspector;
GRefPtr<WebKitWebInspector> m_webInspector;
InspectorClient* m_inspectorClient;
};
}
......
/*
* Copyright (C) 2012 Gustavo Noronha Silva <gns@gnome.org>
*
* 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), &timesElementInspected,
"signal::show-window", G_CALLBACK(showInspector), NULL,
"signal::close-window", G_CALLBACK(closeInspector), &timesClosed,
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), &timesElementInspected,
"signal::show-window", G_CALLBACK(showInspector), NULL,
"signal::close-window", G_CALLBACK(closeInspector), &timesClosed,
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment