Changeset 159042 in webkit
- Timestamp:
- Nov 11, 2013 12:30:06 AM (10 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r159041 r159042 1 2013-11-11 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK] Crash when printing via javascript in WebKit2 4 https://bugs.webkit.org/show_bug.cgi?id=124043 5 6 Reviewed by Martin Robinson. 7 8 It happens because the print operation when started by the 9 WebProcess due to a DOM operation is supposed to be synchronous 10 and our print operation is always asynchronous. This is currently 11 handled only in the UI process because other ports print 12 synchronously in the WebProcess. In the GTK+ port we need to 13 notify the WebProcess that the print operation should run 14 synchronously when request by a DOM operation. Together with the 15 print settings and page setup we now send a print mode that can be 16 sync or async. When printing in sync mode we run a nested main loop 17 for the print operation, making sure that print sources have a 18 higher priority. 19 20 * Shared/PrintInfo.cpp: 21 (WebKit::PrintInfo::encode): Encode the print mode. 22 (WebKit::PrintInfo::decode): Decode the print mode. 23 * Shared/PrintInfo.h: Add PrintMode enum. 24 * Shared/gtk/PrintInfoGtk.cpp: 25 (WebKit::PrintInfo::PrintInfo): Initialize print mode. 26 * UIProcess/API/gtk/WebKitPrintOperation.cpp: 27 (drawPagesForPrintingCompleted): Do not call endPrinting() when 28 printing synchronously because WebPageProxy already calls it right 29 after sending the message to the WebProcess. 30 (webkitPrintOperationPrintPagesForFrame): Create the PrintInfo 31 struct with a print mode. 32 (webkitPrintOperationSetPrintMode): Helper private function to set 33 the print mode of the print operation. 34 * UIProcess/API/gtk/WebKitPrintOperationPrivate.h: 35 * UIProcess/API/gtk/WebKitWebView.cpp: 36 (webkitWebViewPrintFrame): Set sync print mode when printing due 37 to a UIClient request. 38 * WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp: 39 (WebKit::PrintPagesData::PrintPagesData): Create a main loop when 40 printing synchronously. 41 (WebKit::WebPrintOperationGtk::WebPrintOperationGtk): Initialize 42 print mode. 43 (WebKit::WebPrintOperationGtk::printPagesIdleDone): Finish the 44 nested main loop when printing synchronously. 45 (WebKit::WebPrintOperationGtk::print): Run a nested main loop when 46 printing synchronously. 47 * WebProcess/WebPage/gtk/WebPrintOperationGtk.h: 48 (WebKit::WebPrintOperationGtk::printMode): Return the print mode. 49 1 50 2013-11-10 Carlos Garcia Campos <cgarcia@igalia.com> 2 51 -
trunk/Source/WebKit2/Shared/PrintInfo.cpp
r141619 r159042 53 53 CoreIPC::encode(encoder, printSettings.get()); 54 54 CoreIPC::encode(encoder, pageSetup.get()); 55 encoder.encodeEnum(printMode); 55 56 #endif 56 57 } … … 70 71 if (!CoreIPC::decode(decoder, info.pageSetup)) 71 72 return false; 73 if (!decoder.decodeEnum(info.printMode)) 74 return false; 72 75 #endif 73 76 -
trunk/Source/WebKit2/Shared/PrintInfo.h
r143499 r159042 48 48 PrintInfo(); 49 49 #if PLATFORM(GTK) 50 explicit PrintInfo(GtkPrintSettings*, GtkPageSetup*); 50 enum PrintMode { 51 PrintModeAsync, 52 PrintModeSync 53 }; 54 55 explicit PrintInfo(GtkPrintSettings*, GtkPageSetup*, PrintMode = PrintModeAsync); 51 56 #else 52 57 explicit PrintInfo(NSPrintInfo *); … … 60 65 GRefPtr<GtkPrintSettings> printSettings; 61 66 GRefPtr<GtkPageSetup> pageSetup; 67 PrintMode printMode; 62 68 #endif 63 69 -
trunk/Source/WebKit2/Shared/gtk/PrintInfoGtk.cpp
r106102 r159042 31 31 namespace WebKit { 32 32 33 PrintInfo::PrintInfo(GtkPrintSettings* settings, GtkPageSetup* pageSetup )33 PrintInfo::PrintInfo(GtkPrintSettings* settings, GtkPageSetup* pageSetup, PrintMode printMode) 34 34 : pageSetupScaleFactor(gtk_print_settings_get_scale(settings) / 100.0) 35 35 , availablePaperWidth(gtk_page_setup_get_paper_width(pageSetup, GTK_UNIT_POINTS) - gtk_page_setup_get_left_margin(pageSetup, GTK_UNIT_POINTS) - gtk_page_setup_get_right_margin(pageSetup, GTK_UNIT_POINTS)) … … 37 37 , printSettings(settings) 38 38 , pageSetup(pageSetup) 39 , printMode(printMode) 39 40 { 40 41 ASSERT(settings); -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp
r159041 r159042 21 21 #include "WebKitPrintOperation.h" 22 22 23 #include "PrintInfo.h"24 23 #include "WebKitPrintOperationPrivate.h" 25 24 #include "WebKitPrivate.h" … … 74 73 WebKitWebView* webView; 75 74 gulong webViewDestroyedId; 75 PrintInfo::PrintMode printMode; 76 76 77 77 GRefPtr<GtkPrintSettings> printSettings; … … 265 265 GRefPtr<WebKitPrintOperation> printOperation = adoptGRef(WEBKIT_PRINT_OPERATION(context)); 266 266 WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(printOperation->priv->webView)); 267 page->endPrinting(); 267 268 // When running synchronously WebPageProxy::printFrame() calls endPrinting(). 269 if (printOperation->priv->printMode == PrintInfo::PrintModeAsync) 270 page->endPrinting(); 268 271 269 272 const WebCore::ResourceError& resourceError = toImpl(wkPrintError)->platformError(); … … 279 282 static void webkitPrintOperationPrintPagesForFrame(WebKitPrintOperation* printOperation, WebFrameProxy* webFrame, GtkPrintSettings* printSettings, GtkPageSetup* pageSetup) 280 283 { 281 PrintInfo printInfo(printSettings, pageSetup );284 PrintInfo printInfo(printSettings, pageSetup, printOperation->priv->printMode); 282 285 WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(printOperation->priv->webView)); 283 286 page->drawPagesForPrinting(webFrame, printInfo, PrintFinishedCallback::create(g_object_ref(printOperation), &drawPagesForPrintingCompleted)); … … 299 302 webkitPrintOperationPrintPagesForFrame(printOperation, webFrame, priv->printSettings.get(), priv->pageSetup.get()); 300 303 return response; 304 } 305 306 void webkitPrintOperationSetPrintMode(WebKitPrintOperation* printOperation, PrintInfo::PrintMode printMode) 307 { 308 printOperation->priv->printMode = printMode; 301 309 } 302 310 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperationPrivate.h
r108069 r159042 21 21 #define WebKitPrintOperationPrivate_h 22 22 23 #include "PrintInfo.h" 23 24 #include "WebFrameProxy.h" 24 25 #include "WebKitPrintOperation.h" 25 26 26 27 WebKitPrintOperationResponse webkitPrintOperationRunDialogForFrame(WebKitPrintOperation*, GtkWindow* parent, WebKit::WebFrameProxy*); 28 void webkitPrintOperationSetPrintMode(WebKitPrintOperation*, WebKit::PrintInfo::PrintMode); 27 29 28 30 #endif // WebKitPrintOperationPrivate_h -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp
r158437 r159042 1684 1684 return; 1685 1685 1686 webkitPrintOperationSetPrintMode(printOperation.get(), PrintInfo::PrintModeSync); 1686 1687 WebKitPrintOperationResponse response = webkitPrintOperationRunDialogForFrame(printOperation.get(), 0, frame); 1687 1688 if (response == WEBKIT_PRINT_OPERATION_RESPONSE_CANCEL) -
trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp
r130509 r159042 110 110 m_callbackID = callbackID; 111 111 gtk_enumerate_printers(reinterpret_cast<GtkPrinterFunc>(enumeratePrintersFunction), this, 112 reinterpret_cast<GDestroyNotify>(enumeratePrintersFinished), FALSE);112 reinterpret_cast<GDestroyNotify>(enumeratePrintersFinished), m_printMode == PrintInfo::PrintModeSync); 113 113 } 114 114 … … 218 218 , isValid(true) 219 219 { 220 if (printOperation->printMode() == PrintInfo::PrintModeSync) 221 mainLoop = adoptGRef(g_main_loop_new(0, FALSE)); 222 220 223 if (printOperation->collateCopies()) { 221 224 collatedCopies = printOperation->copies(); … … 359 362 360 363 RefPtr<WebPrintOperationGtk> printOperation; 364 GRefPtr<GMainLoop> mainLoop; 361 365 362 366 int totalPrinted; … … 393 397 , m_printSettings(printInfo.printSettings.get()) 394 398 , m_pageSetup(printInfo.pageSetup.get()) 399 , m_printMode(printInfo.printMode) 395 400 , m_printContext(0) 396 401 , m_callbackID(0) … … 670 675 { 671 676 PrintPagesData* data = static_cast<PrintPagesData*>(userData); 677 if (data->mainLoop) 678 g_main_loop_quit(data->mainLoop.get()); 672 679 673 680 data->printOperation->printPagesDone(); … … 706 713 m_yDPI = yDPI; 707 714 m_cairoContext = adoptRef(cairo_create(surface)); 708 m_printPagesIdleId = gdk_threads_add_idle_full(G_PRIORITY_DEFAULT_IDLE + 10, printPagesIdle, 709 data.leakPtr(), printPagesIdleDone); 710 } 711 712 } 715 716 // Make sure the print pages idle has more priority than IPC messages comming from 717 // the IO thread, so that the EndPrinting message is always handled once the print 718 // operation has finished. See https://bugs.webkit.org/show_bug.cgi?id=122801. 719 unsigned idlePriority = m_printMode == PrintInfo::PrintModeSync ? G_PRIORITY_DEFAULT - 10 : G_PRIORITY_DEFAULT_IDLE + 10; 720 GMainLoop* mainLoop = data->mainLoop.get(); 721 m_printPagesIdleId = gdk_threads_add_idle_full(idlePriority, printPagesIdle, data.leakPtr(), printPagesIdleDone); 722 if (m_printMode == PrintInfo::PrintModeSync) { 723 ASSERT(mainLoop); 724 g_main_loop_run(mainLoop); 725 } 726 } 727 728 } -
trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPrintOperationGtk.h
r130028 r159042 54 54 GtkPrintSettings* printSettings() const { return m_printSettings.get(); } 55 55 GtkPageSetup* pageSetup() const { return m_pageSetup.get(); } 56 PrintInfo::PrintMode printMode() const { return m_printMode; } 56 57 void setNumberOfPagesToPrint(size_t numberOfPages) { m_numberOfPagesToPrint = numberOfPages; } 57 58 unsigned int pagesToPrint() const { return m_pagesToPrint; } … … 96 97 GRefPtr<GtkPrintSettings> m_printSettings; 97 98 GRefPtr<GtkPageSetup> m_pageSetup; 99 PrintInfo::PrintMode m_printMode; 98 100 WebCore::PrintContext* m_printContext; 99 101 uint64_t m_callbackID;
Note: See TracChangeset
for help on using the changeset viewer.