Changeset 162056 in webkit


Ignore:
Timestamp:
Jan 14, 2014 11:47:47 PM (10 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] UI process crashes when the web process crashes while printing
https://bugs.webkit.org/show_bug.cgi?id=126977

Reviewed by Gustavo Noronha Silva.

Source/WebKit2:

When the web process crashes, the printing callback is
invalidated, so the function is called with a NULL error.

  • UIProcess/API/gtk/WebKitPrintOperation.cpp:

(drawPagesForPrintingCompleted): Check wkError is not NULL before
trying to use it.

  • UIProcess/API/gtk/WebKitWebView.cpp:

(webkitWebViewPrintFrame): Set the print mode of the operation
before emitting the print signal.

Tools:

Add new test case to check that closing the window right after
printing works. It's skipped for now, because this patch only
fixes the UI process crash, but not the web process one.

  • Scripts/run-gtk-tests:

(TestRunner): Skip
/webkit2/WebKitPrintOperation/close-after-print.

  • TestWebKitAPI/Tests/WebKit2Gtk/TestPrinting.cpp:

(testPrintOperationPrintPrinter):
(findPrintToFilePrinter):
(testPrintOperationPrint):
(testPrintOperationErrors):
(testPrintOperationCloseAfterPrint):
(beforeAll):

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r162047 r162056  
     12014-01-14  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] UI process crashes when the web process crashes while printing
     4        https://bugs.webkit.org/show_bug.cgi?id=126977
     5
     6        Reviewed by Gustavo Noronha Silva.
     7
     8        When the web process crashes, the printing callback is
     9        invalidated, so the function is called with a NULL error.
     10
     11        * UIProcess/API/gtk/WebKitPrintOperation.cpp:
     12        (drawPagesForPrintingCompleted): Check wkError is not NULL before
     13        trying to use it.
     14        * UIProcess/API/gtk/WebKitWebView.cpp:
     15        (webkitWebViewPrintFrame): Set the print mode of the operation
     16        before emitting the print signal.
     17
    1182014-01-14  Brady Eidson  <beidson@apple.com>
    219
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp

    r159042 r162056  
    270270        page->endPrinting();
    271271
    272     const WebCore::ResourceError& resourceError = toImpl(wkPrintError)->platformError();
     272    const WebCore::ResourceError& resourceError = wkPrintError ? toImpl(wkPrintError)->platformError() : WebCore::ResourceError();
    273273    if (!resourceError.isNull()) {
    274274        GOwnPtr<GError> printError(g_error_new_literal(g_quark_from_string(resourceError.domain().utf8().data()),
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r161256 r162056  
    16791679{
    16801680    GRefPtr<WebKitPrintOperation> printOperation = adoptGRef(webkit_print_operation_new(webView));
     1681    webkitPrintOperationSetPrintMode(printOperation.get(), PrintInfo::PrintModeSync);
    16811682    gboolean returnValue;
    16821683    g_signal_emit(webView, signals[PRINT], 0, printOperation.get(), &returnValue);
     
    16841685        return;
    16851686
    1686     webkitPrintOperationSetPrintMode(printOperation.get(), PrintInfo::PrintModeSync);
    16871687    WebKitPrintOperationResponse response = webkitPrintOperationRunDialogForFrame(printOperation.get(), 0, frame);
    16881688    if (response == WEBKIT_PRINT_OPERATION_RESPONSE_CANCEL)
  • trunk/Tools/ChangeLog

    r162010 r162056  
     12014-01-14  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] UI process crashes when the web process crashes while printing
     4        https://bugs.webkit.org/show_bug.cgi?id=126977
     5
     6        Reviewed by Gustavo Noronha Silva.
     7
     8        Add new test case to check that closing the window right after
     9        printing works. It's skipped for now, because this patch only
     10        fixes the UI process crash, but not the web process one.
     11
     12        * Scripts/run-gtk-tests:
     13        (TestRunner): Skip
     14        /webkit2/WebKitPrintOperation/close-after-print.
     15        * TestWebKitAPI/Tests/WebKit2Gtk/TestPrinting.cpp:
     16        (testPrintOperationPrintPrinter):
     17        (findPrintToFilePrinter):
     18        (testPrintOperationPrint):
     19        (testPrintOperationErrors):
     20        (testPrintOperationCloseAfterPrint):
     21        (beforeAll):
     22
    1232014-01-14  Brent Fulgham  <bfulgham@apple.com>
    224
  • trunk/Tools/Scripts/run-gtk-tests

    r161499 r162056  
    7070        SkippedTest("WebKit2Gtk/TestContextMenu", SkippedTest.ENTIRE_SUITE, "Test times out after r150890", 117689),
    7171        SkippedTest("WebKit2Gtk/TestWebKitWebView", "/webkit2/WebKitWebView/snapshot", "Test fails", 120404),
     72        SkippedTest("WebKit2Gtk/TestPrinting", "/webkit2/WebKitPrintOperation/close-after-print", "Test times out", 126979),
    7273        SkippedTest("WebKit2/TestWebKit2", "WebKit2.MouseMoveAfterCrash", "Test is flaky", 85066),
    7374        SkippedTest("WebKit2/TestWebKit2", "WebKit2.NewFirstVisuallyNonEmptyLayoutForImages", "Test is flaky", 85066),
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestPrinting.cpp

    r161366 r162056  
    7373
    7474#ifdef HAVE_GTK_UNIX_PRINTING
     75static gboolean testPrintOperationPrintPrinter(GtkPrinter* printer, gpointer userData)
     76{
     77    if (strcmp(gtk_printer_get_name(printer), "Print to File"))
     78        return FALSE;
     79
     80    GtkPrinter** foundPrinter = static_cast<GtkPrinter**>(userData);
     81    *foundPrinter = static_cast<GtkPrinter*>(g_object_ref(printer));
     82    return TRUE;
     83}
     84
     85static GtkPrinter* findPrintToFilePrinter()
     86{
     87    GtkPrinter* printer = 0;
     88    gtk_enumerate_printers(testPrintOperationPrintPrinter, &printer, 0, TRUE);
     89    return printer;
     90}
     91
    7592class PrintTest: public WebViewTest {
    7693public:
     
    98115    }
    99116
    100     static gboolean testPrintOperationPrintPrinter(GtkPrinter* printer, gpointer userData)
    101     {
    102         if (strcmp(gtk_printer_get_name(printer), "Print to File"))
    103             return FALSE;
    104 
    105         GtkPrinter** foundPrinter = static_cast<GtkPrinter**>(userData);
    106         *foundPrinter = static_cast<GtkPrinter*>(g_object_ref(printer));
    107         return TRUE;
    108     }
    109 
    110     GtkPrinter* findPrintToFilePrinter()
    111     {
    112         GtkPrinter* printer = 0;
    113         gtk_enumerate_printers(testPrintOperationPrintPrinter, &printer, 0, TRUE);
    114         return printer;
    115     }
    116 
    117117    void waitUntilPrintFinished()
    118118    {
     
    129129    test->waitUntilLoadFinished();
    130130
    131     GRefPtr<GtkPrinter> printer = adoptGRef(test->findPrintToFilePrinter());
     131    GRefPtr<GtkPrinter> printer = adoptGRef(findPrintToFilePrinter());
    132132    if (!printer) {
    133133        g_message("%s", "Cannot test WebKitPrintOperation/print: no suitable printer found");
     
    162162    test->waitUntilLoadFinished();
    163163
    164     GRefPtr<GtkPrinter> printer = adoptGRef(test->findPrintToFilePrinter());
     164    GRefPtr<GtkPrinter> printer = adoptGRef(findPrintToFilePrinter());
    165165    if (!printer) {
    166166        g_message("%s", "Cannot test WebKitPrintOperation/print: no suitable printer found");
     
    190190    test->waitUntilPrintFinished();
    191191}
     192
     193class CloseAfterPrintTest: public WebViewTest {
     194public:
     195    MAKE_GLIB_TEST_FIXTURE(CloseAfterPrintTest);
     196
     197    static GtkWidget* webViewCreate(WebKitWebView* webView, CloseAfterPrintTest* test)
     198    {
     199        return test->createWebView();
     200    }
     201
     202    static gboolean webViewPrint(WebKitWebView* webView, WebKitPrintOperation* printOperation, CloseAfterPrintTest* test)
     203    {
     204        test->print(printOperation);
     205        return TRUE;
     206    }
     207
     208    static void printOperationFinished(WebKitPrintOperation* printOperation, CloseAfterPrintTest* test)
     209    {
     210        test->printFinished();
     211    }
     212
     213    static void webViewClosed(WebKitWebView* webView, CloseAfterPrintTest* test)
     214    {
     215        gtk_widget_destroy(GTK_WIDGET(webView));
     216        test->m_webViewClosed = true;
     217        if (test->m_printFinished)
     218            g_main_loop_quit(test->m_mainLoop);
     219    }
     220
     221    CloseAfterPrintTest()
     222        : m_webViewClosed(false)
     223        , m_printFinished(false)
     224    {
     225        webkit_settings_set_javascript_can_open_windows_automatically(webkit_web_view_get_settings(m_webView), TRUE);
     226        g_signal_connect(m_webView, "create", G_CALLBACK(webViewCreate), this);
     227    }
     228
     229    GtkWidget* createWebView()
     230    {
     231        GtkWidget* newWebView = webkit_web_view_new();
     232        g_object_ref_sink(newWebView);
     233
     234        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(newWebView));
     235        g_signal_connect(newWebView, "print", G_CALLBACK(webViewPrint), this);
     236        g_signal_connect(newWebView, "close", G_CALLBACK(webViewClosed), this);
     237        return newWebView;
     238    }
     239
     240    void print(WebKitPrintOperation* printOperation)
     241    {
     242        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(printOperation));
     243
     244        GRefPtr<GtkPrinter> printer = adoptGRef(findPrintToFilePrinter());
     245        if (!printer) {
     246            g_message("%s", "Cannot test WebKitPrintOperation/print: no suitable printer found");
     247            return;
     248        }
     249
     250        GOwnPtr<char> outputFilename(g_build_filename(kTempDirectory, "webkit-close-after-print.pdf", NULL));
     251        m_outputFile = adoptGRef(g_file_new_for_path(outputFilename.get()));
     252        GOwnPtr<char> outputURI(g_file_get_uri(m_outputFile.get()));
     253
     254        GRefPtr<GtkPrintSettings> printSettings = adoptGRef(gtk_print_settings_new());
     255        gtk_print_settings_set_printer(printSettings.get(), gtk_printer_get_name(printer.get()));
     256        gtk_print_settings_set(printSettings.get(), GTK_PRINT_SETTINGS_OUTPUT_URI, outputURI.get());
     257        webkit_print_operation_set_print_settings(printOperation, printSettings.get());
     258
     259        m_printOperation = printOperation;
     260        g_signal_connect(m_printOperation.get(), "finished", G_CALLBACK(printOperationFinished), this);
     261        webkit_print_operation_print(m_printOperation.get());
     262    }
     263
     264    void printFinished()
     265    {
     266        m_printFinished = true;
     267        m_printOperation = nullptr;
     268        g_assert(m_outputFile);
     269        g_file_delete(m_outputFile.get(), 0, 0);
     270        m_outputFile = nullptr;
     271        if (m_webViewClosed)
     272            g_main_loop_quit(m_mainLoop);
     273    }
     274
     275    void waitUntilPrintFinishedAndViewClosed()
     276    {
     277        g_main_loop_run(m_mainLoop);
     278    }
     279
     280    GRefPtr<WebKitPrintOperation> m_printOperation;
     281    GRefPtr<GFile> m_outputFile;
     282    bool m_webViewClosed;
     283    bool m_printFinished;
     284};
     285
     286static void testPrintOperationCloseAfterPrint(CloseAfterPrintTest* test, gconstpointer)
     287{
     288    test->loadHtml("<html><body onLoad=\"w = window.open();w.print();w.close();\"></body></html>", 0);
     289    test->waitUntilPrintFinishedAndViewClosed();
     290}
    192291#endif // HAVE_GTK_UNIX_PRINTING
    193292
     
    202301    PrintTest::add("WebKitPrintOperation", "print", testPrintOperationPrint);
    203302    PrintTest::add("WebKitPrintOperation", "print-errors", testPrintOperationErrors);
     303    CloseAfterPrintTest::add("WebKitPrintOperation", "close-after-print", testPrintOperationCloseAfterPrint);
    204304#endif
    205305}
Note: See TracChangeset for help on using the changeset viewer.