Changeset 179744 in webkit


Ignore:
Timestamp:
Feb 6, 2015 6:46:17 AM (9 years ago)
Author:
Carlos Garcia Campos
Message:

ASSERTION FAILED: !m_adoptionIsRequired in WTF::RefCountedBase::ref
https://bugs.webkit.org/show_bug.cgi?id=141035

Reviewed by Sergio Villar Senin.

Rename PrinterListGtk::singleton() as PrinterListGtk::getOrCreate(), and
make it return nullptr when the shared PrinterListGtk object is
still being created. This can happen if the nested loop used by
gtk_enumerate_printers dispatches a GSource that starts a new
synchronous print operation. In that case we just ignore the
second print operation, since there's already one ongoing.

  • WebProcess/WebCoreSupport/WebChromeClient.cpp:

(WebKit::WebChromeClient::print): Return early if
PrinterListGtk::getOrCreate() return nullptr.

  • WebProcess/WebPage/gtk/PrinterListGtk.cpp:

(WebKit::PrinterListGtk::getOrCreate): Return nullptr if the
PrinterListGtk is still enumerating the printers.
(WebKit::PrinterListGtk::PrinterListGtk): Initialize
m_enumeratingPrinters to true before calling
gtk_enumerate_printers, and to false once it finishes.
(WebKit::PrinterListGtk::singleton): Deleted.
(WebKit::PrinterListGtk::enumeratePrintersFunction): Deleted.

  • WebProcess/WebPage/gtk/PrinterListGtk.h:
  • WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp: Add an

assertion here since PrinterListGtk::getOrCreate() should never
return nullptr at this point.

Location:
trunk/Source/WebKit2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r179736 r179744  
     12015-02-06  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        ASSERTION FAILED: !m_adoptionIsRequired in WTF::RefCountedBase::ref
     4        https://bugs.webkit.org/show_bug.cgi?id=141035
     5
     6        Reviewed by Sergio Villar Senin.
     7
     8        Rename PrinterListGtk::singleton() as PrinterListGtk::getOrCreate(), and
     9        make it return nullptr when the shared PrinterListGtk object is
     10        still being created. This can happen if the nested loop used by
     11        gtk_enumerate_printers dispatches a GSource that starts a new
     12        synchronous print operation. In that case we just ignore the
     13        second print operation, since there's already one ongoing.
     14
     15        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
     16        (WebKit::WebChromeClient::print): Return early if
     17        PrinterListGtk::getOrCreate() return nullptr.
     18        * WebProcess/WebPage/gtk/PrinterListGtk.cpp:
     19        (WebKit::PrinterListGtk::getOrCreate): Return nullptr if the
     20        PrinterListGtk is still enumerating the printers.
     21        (WebKit::PrinterListGtk::PrinterListGtk): Initialize
     22        m_enumeratingPrinters to true before calling
     23        gtk_enumerate_printers, and to false once it finishes.
     24        (WebKit::PrinterListGtk::singleton): Deleted.
     25        (WebKit::PrinterListGtk::enumeratePrintersFunction): Deleted.
     26        * WebProcess/WebPage/gtk/PrinterListGtk.h:
     27        * WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp: Add an
     28        assertion here since PrinterListGtk::getOrCreate() should never
     29        return nullptr at this point.
     30
    1312015-02-05  Tim Horton  <timothy_horton@apple.com>
    232
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp

    r179409 r179744  
    663663    // The PrinterListGtk class gets the list of printers in the constructor so we just need to ensure there's an instance alive
    664664    // during the synchronous print operation.
    665     RefPtr<PrinterListGtk> printerList = PrinterListGtk::singleton();
     665    RefPtr<PrinterListGtk> printerList = PrinterListGtk::getOrCreate();
     666    if (!printerList) {
     667        // PrinterListGtk::getOrCreate() returns nullptr when called while a printers enumeration is ongoing.
     668        // This can happen if a synchronous print is started by a JavaScript and another one is inmeditaley started
     669        // from a JavaScript event listener. The second print operation is handled by the nested main loop used by GTK+
     670        // to enumerate the printers, and we end up here trying to get a reference of an object that is being constructed.
     671        // It's very unlikely that the user wants to print twice in a row, and other browsers don't do two print operations
     672        // in this particular case either. So, the safest solution is to return early here and ignore the second print.
     673        // See https://bugs.webkit.org/show_bug.cgi?id=141035
     674        return;
     675    }
    666676#endif
    667677
  • trunk/Source/WebKit2/WebProcess/WebPage/gtk/PrinterListGtk.cpp

    r179409 r179744  
    3535PrinterListGtk* PrinterListGtk::s_sharedPrinterList = nullptr;
    3636
    37 RefPtr<PrinterListGtk> PrinterListGtk::singleton()
     37RefPtr<PrinterListGtk> PrinterListGtk::getOrCreate()
    3838{
    3939    if (s_sharedPrinterList)
    40         return s_sharedPrinterList;
     40        return s_sharedPrinterList->isEnumeratingPrinters() ? nullptr : s_sharedPrinterList;
    4141
    4242    return adoptRef(new PrinterListGtk);
    4343}
    4444
    45 gboolean PrinterListGtk::enumeratePrintersFunction(GtkPrinter* printer)
    46 {
    47     ASSERT(s_sharedPrinterList);
    48     s_sharedPrinterList->addPrinter(printer);
    49     return FALSE;
    50 }
    51 
    5245PrinterListGtk::PrinterListGtk()
    5346    : m_defaultPrinter(nullptr)
     47    , m_enumeratingPrinters(true)
    5448{
    5549    ASSERT(!s_sharedPrinterList);
    5650    s_sharedPrinterList = this;
    57     gtk_enumerate_printers(reinterpret_cast<GtkPrinterFunc>(&enumeratePrintersFunction), nullptr, nullptr, TRUE);
     51    gtk_enumerate_printers([](GtkPrinter* printer, gpointer) -> gboolean {
     52        ASSERT(s_sharedPrinterList);
     53        s_sharedPrinterList->addPrinter(printer);
     54        return FALSE;
     55    }, nullptr, nullptr, TRUE);
     56    m_enumeratingPrinters = false;
    5857}
    5958
  • trunk/Source/WebKit2/WebProcess/WebPage/gtk/PrinterListGtk.h

    r179409 r179744  
    3939class PrinterListGtk: public RefCounted<PrinterListGtk> {
    4040public:
    41     static RefPtr<PrinterListGtk> singleton();
     41    static RefPtr<PrinterListGtk> getOrCreate();
    4242    ~PrinterListGtk();
    4343
     
    4848    PrinterListGtk();
    4949
    50     static gboolean enumeratePrintersFunction(GtkPrinter*);
    5150    void addPrinter(GtkPrinter*);
     51    bool isEnumeratingPrinters() const { return m_enumeratingPrinters; }
    5252
    5353    Vector<GRefPtr<GtkPrinter>, 4> m_printerList;
    5454    GtkPrinter* m_defaultPrinter;
     55    bool m_enumeratingPrinters;
    5556    static PrinterListGtk* s_sharedPrinterList;
    5657};
  • trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp

    r179409 r179744  
    6868        m_callbackID = callbackID;
    6969
    70         RefPtr<PrinterListGtk> printerList = PrinterListGtk::singleton();
     70        RefPtr<PrinterListGtk> printerList = PrinterListGtk::getOrCreate();
     71        ASSERT(printerList);
    7172        const char* printerName = gtk_print_settings_get_printer(m_printSettings.get());
    7273        GtkPrinter* printer = printerName ? printerList->findPrinter(printerName) : printerList->defaultPrinter();
Note: See TracChangeset for help on using the changeset viewer.