Changeset 53477 in webkit


Ignore:
Timestamp:
Jan 19, 2010 11:11:23 AM (14 years ago)
Author:
kov@webkit.org
Message:

Reviewed by Xan Lopez.

[GTK] More crashes related to the clipboard management
https://bugs.webkit.org/show_bug.cgi?id=33746

Pass the WebKitWebView object (which is a GObject, thus
ref-counted) to the clipboard functions instead of passing the
Page - this allows us to explicitely protect the object inbetween
the clipboard call and its callbacks, which fixes the crash.

  • WebCoreSupport/EditorClientGtk.cpp: (WebKit::EditorClient::respondToChangedSelection):
  • WebCoreSupport/PasteboardHelperGtk.cpp: (WebKit::getClipboardContentsCallback): (WebKit::clearClipboardContentsCallback): (WebKit::PasteboardHelperGtk::writeClipboardContents):
Location:
trunk/WebKit/gtk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/gtk/ChangeLog

    r53351 r53477  
     12010-01-19  Gustavo Noronha Silva  <gns@gnome.org>
     2
     3        Reviewed by Xan Lopez.
     4
     5        [GTK] More crashes related to the clipboard management
     6        https://bugs.webkit.org/show_bug.cgi?id=33746
     7
     8        Pass the WebKitWebView object (which is a GObject, thus
     9        ref-counted) to the clipboard functions instead of passing the
     10        Page - this allows us to explicitely protect the object inbetween
     11        the clipboard call and its callbacks, which fixes the crash.
     12
     13        * WebCoreSupport/EditorClientGtk.cpp:
     14        (WebKit::EditorClient::respondToChangedSelection):
     15        * WebCoreSupport/PasteboardHelperGtk.cpp:
     16        (WebKit::getClipboardContentsCallback):
     17        (WebKit::clearClipboardContentsCallback):
     18        (WebKit::PasteboardHelperGtk::writeClipboardContents):
     19
    1202010-01-15  Alejandro G. Castro  <alex@igalia.com>
    221
  • trunk/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp

    r53264 r53477  
    207207        dataObject->clear();
    208208        dataObject->setRange(targetFrame->selection()->toNormalizedRange());
    209         pasteboardHelperInstance()->writeClipboardContents(clipboard, corePage);
     209        pasteboardHelperInstance()->writeClipboardContents(clipboard, m_webView);
    210210    }
    211211#endif
  • trunk/WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.cpp

    r53304 r53477  
    123123    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    124124    ASSERT(dataObject);
     125    dataObject->clear();
    125126
    126     dataObject->clear();
    127     if (data) {
    128         WebCore::Page* corePage = reinterpret_cast<WebCore::Page*>(data);
     127    // This will be true for clipboards other than X11 primary.
     128    if (!data)
     129        return;
    129130
    130         if (!corePage->focusController())
    131             return;
     131    WebKitWebView* webView = reinterpret_cast<WebKitWebView*>(data);
     132    WebCore::Page* corePage = core(webView);
    132133
    133         Frame* frame = corePage->focusController()->focusedOrMainFrame();
     134    if (!corePage || !corePage->focusController()) {
     135        g_object_unref(webView);
     136        return;
     137    }
    134138
    135         // Collapse the selection without clearing it
    136         ASSERT(frame);
    137         frame->selection()->setBase(frame->selection()->extent(), frame->selection()->affinity());
    138     }
     139    Frame* frame = corePage->focusController()->focusedOrMainFrame();
     140
     141    // Collapse the selection without clearing it
     142    ASSERT(frame);
     143    frame->selection()->setBase(frame->selection()->extent(), frame->selection()->affinity());
     144
     145    g_object_unref(webView);
    139146}
    140147
     
    149156    if (numberOfTargets > 0 && table) {
    150157        settingClipboard = true;
    151         gtk_clipboard_set_with_data(clipboard, table, numberOfTargets,
    152                                     getClipboardContentsCallback,
    153                                     clearClipboardContentsCallback, data);
     158
     159        // Protect the web view from being destroyed before one of the clipboard callbacks
     160        // is called. Balanced in both getClipboardContentsCallback and
     161        // clearClipboardContentsCallback.
     162        WebKitWebView* webView = static_cast<WebKitWebView*>(data);
     163        g_object_ref(webView);
     164
     165        gboolean succeeded = gtk_clipboard_set_with_data(clipboard, table, numberOfTargets,
     166                                                         getClipboardContentsCallback,
     167                                                         clearClipboardContentsCallback, data);
     168        if (!succeeded)
     169            g_object_unref(webView);
     170
    154171        settingClipboard = false;
    155172    } else
Note: See TracChangeset for help on using the changeset viewer.