[GTK] UI process crashes when closing the window right after printing with javascript
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Jan 2014 07:56:42 +0000 (07:56 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Jan 2014 07:56:42 +0000 (07:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=126981

Reviewed by Gustavo Noronha Silva.

The UI process crashes because when the page is closed, the web
view is destroyed before the print operation has actually
finished. Use a weak pointer to make sure the web view pointer is
set to NULL when the it's destroyed and emit the finished callback
always so that the user can clean up the operation even when the
web view has been closed.

* UIProcess/API/gtk/WebKitPrintOperation.cpp:
(drawPagesForPrintingCompleted):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp

index 63e6e61..c2ae082 100644 (file)
@@ -1,5 +1,22 @@
 2014-01-14  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK] UI process crashes when closing the window right after printing with javascript
+        https://bugs.webkit.org/show_bug.cgi?id=126981
+
+        Reviewed by Gustavo Noronha Silva.
+
+        The UI process crashes because when the page is closed, the web
+        view is destroyed before the print operation has actually
+        finished. Use a weak pointer to make sure the web view pointer is
+        set to NULL when the it's destroyed and emit the finished callback
+        always so that the user can clean up the operation even when the
+        web view has been closed.
+
+        * UIProcess/API/gtk/WebKitPrintOperation.cpp:
+        (drawPagesForPrintingCompleted):
+
+2014-01-14  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [GTK] UI process crashes when the web process crashes while printing
         https://bugs.webkit.org/show_bug.cgi?id=126977
 
index 03f63c7..5318dd0 100644 (file)
@@ -65,13 +65,7 @@ enum {
 };
 
 struct _WebKitPrintOperationPrivate {
-    ~_WebKitPrintOperationPrivate()
-    {
-        g_signal_handler_disconnect(webView, webViewDestroyedId);
-    }
-
     WebKitWebView* webView;
-    gulong webViewDestroyedId;
     PrintInfo::PrintMode printMode;
 
     GRefPtr<GtkPrintSettings> printSettings;
@@ -82,11 +76,6 @@ static guint signals[LAST_SIGNAL] = { 0, };
 
 WEBKIT_DEFINE_TYPE(WebKitPrintOperation, webkit_print_operation, G_TYPE_OBJECT)
 
-static void webViewDestroyed(GtkWidget* webView, GObject* printOperation)
-{
-    g_object_unref(printOperation);
-}
-
 static void webkitPrintOperationConstructed(GObject* object)
 {
     WebKitPrintOperation* printOperation = WEBKIT_PRINT_OPERATION(object);
@@ -95,7 +84,7 @@ static void webkitPrintOperationConstructed(GObject* object)
     if (G_OBJECT_CLASS(webkit_print_operation_parent_class)->constructed)
         G_OBJECT_CLASS(webkit_print_operation_parent_class)->constructed(object);
 
-    priv->webViewDestroyedId = g_signal_connect(priv->webView, "destroy", G_CALLBACK(webViewDestroyed), printOperation);
+    g_object_add_weak_pointer(G_OBJECT(priv->webView), (gpointer*)&priv->webView);
 }
 
 static void webkitPrintOperationGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
@@ -263,11 +252,12 @@ static WebKitPrintOperationResponse webkitPrintOperationRunDialog(WebKitPrintOpe
 static void drawPagesForPrintingCompleted(WKErrorRef wkPrintError, WKErrorRef, void* context)
 {
     GRefPtr<WebKitPrintOperation> printOperation = adoptGRef(WEBKIT_PRINT_OPERATION(context));
-    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(printOperation->priv->webView));
 
     // When running synchronously WebPageProxy::printFrame() calls endPrinting().
-    if (printOperation->priv->printMode == PrintInfo::PrintModeAsync)
+    if (printOperation->priv->printMode == PrintInfo::PrintModeAsync && printOperation->priv->webView) {
+        WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(printOperation->priv->webView));
         page->endPrinting();
+    }
 
     const WebCore::ResourceError& resourceError = wkPrintError ? toImpl(wkPrintError)->platformError() : WebCore::ResourceError();
     if (!resourceError.isNull()) {