Changeset 173687 in webkit


Ignore:
Timestamp:
Sep 17, 2014 12:05:45 AM (10 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Fix layering violations in PasteboardGtk
https://bugs.webkit.org/show_bug.cgi?id=136802

Reviewed by Darin Adler.

Source/WebCore:

Refactor the Pasteboard code moving the WebCore parts to the Editor.

  • PlatformGTK.cmake: Add new file to compilation.
  • editing/Editor.cpp:

(WebCore::Editor::performCutOrCopy):
(WebCore::Editor::copyImage):

  • editing/Editor.h:
  • editing/gtk/EditorGtk.cpp: Added.

(WebCore::createFragmentFromPasteBoardData):
(WebCore::Editor::pasteWithPasteboard):
(WebCore::getImageAndURLForElement):
(WebCore::Editor::writeImageToPasteboard):
(WebCore::Editor::writeSelectionToPasteboard):

  • page/DragController.cpp:

(WebCore::DragController::startDrag):

  • page/gtk/DragControllerGtk.cpp:

(WebCore::DragController::declareAndWriteDragImage):

  • platform/Pasteboard.h:
  • platform/gtk/DataObjectGtk.cpp: Remove range member, the caller

should call setText() + setMarkup() intead.
(WebCore::DataObjectGtk::setText):
(WebCore::DataObjectGtk::setMarkup):
(WebCore::DataObjectGtk::clearText):
(WebCore::DataObjectGtk::clearMarkup):
(WebCore::DataObjectGtk::clearAllExceptFilenames):

  • platform/gtk/DataObjectGtk.h:

(WebCore::DataObjectGtk::hasText):
(WebCore::DataObjectGtk::hasMarkup):
(WebCore::DataObjectGtk::clearImage):
(WebCore::DataObjectGtk::text):
(WebCore::DataObjectGtk::markup):
(WebCore::DataObjectGtk::setRange): Deleted.

  • platform/gtk/GtkDragAndDropHelper.h:
  • platform/gtk/PasteboardGtk.cpp:

(WebCore::PasteboardImage::PasteboardImage):
(WebCore::PasteboardImage::~PasteboardImage):
(WebCore::Pasteboard::write):
(WebCore::Pasteboard::writeSelection): Deleted.
(WebCore::getURLForImageElement): Deleted.
(WebCore::Pasteboard::writeImage): Deleted.
(WebCore::Pasteboard::documentFragment): Deleted.

  • platform/gtk/PasteboardHelper.cpp:

(WebCore::displayFromFrame): Deleted.
(WebCore::PasteboardHelper::getPrimarySelectionClipboard): Deleted.

  • platform/gtk/PasteboardHelper.h:

Source/WebKit2:

  • WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:

(WebKit::WebEditorClient::updateGlobalSelection): Use new API to
update the global selection.

Location:
trunk/Source
Files:
2 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r173686 r173687  
     12014-09-16  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Fix layering violations in PasteboardGtk
     4        https://bugs.webkit.org/show_bug.cgi?id=136802
     5
     6        Reviewed by Darin Adler.
     7
     8        Refactor the Pasteboard code moving the WebCore parts to the Editor.
     9
     10        * PlatformGTK.cmake: Add new file to compilation.
     11        * editing/Editor.cpp:
     12        (WebCore::Editor::performCutOrCopy):
     13        (WebCore::Editor::copyImage):
     14        * editing/Editor.h:
     15        * editing/gtk/EditorGtk.cpp: Added.
     16        (WebCore::createFragmentFromPasteBoardData):
     17        (WebCore::Editor::pasteWithPasteboard):
     18        (WebCore::getImageAndURLForElement):
     19        (WebCore::Editor::writeImageToPasteboard):
     20        (WebCore::Editor::writeSelectionToPasteboard):
     21        * page/DragController.cpp:
     22        (WebCore::DragController::startDrag):
     23        * page/gtk/DragControllerGtk.cpp:
     24        (WebCore::DragController::declareAndWriteDragImage):
     25        * platform/Pasteboard.h:
     26        * platform/gtk/DataObjectGtk.cpp: Remove range member, the caller
     27        should call setText() + setMarkup() intead.
     28        (WebCore::DataObjectGtk::setText):
     29        (WebCore::DataObjectGtk::setMarkup):
     30        (WebCore::DataObjectGtk::clearText):
     31        (WebCore::DataObjectGtk::clearMarkup):
     32        (WebCore::DataObjectGtk::clearAllExceptFilenames):
     33        * platform/gtk/DataObjectGtk.h:
     34        (WebCore::DataObjectGtk::hasText):
     35        (WebCore::DataObjectGtk::hasMarkup):
     36        (WebCore::DataObjectGtk::clearImage):
     37        (WebCore::DataObjectGtk::text):
     38        (WebCore::DataObjectGtk::markup):
     39        (WebCore::DataObjectGtk::setRange): Deleted.
     40        * platform/gtk/GtkDragAndDropHelper.h:
     41        * platform/gtk/PasteboardGtk.cpp:
     42        (WebCore::PasteboardImage::PasteboardImage):
     43        (WebCore::PasteboardImage::~PasteboardImage):
     44        (WebCore::Pasteboard::write):
     45        (WebCore::Pasteboard::writeSelection): Deleted.
     46        (WebCore::getURLForImageElement): Deleted.
     47        (WebCore::Pasteboard::writeImage): Deleted.
     48        (WebCore::Pasteboard::documentFragment): Deleted.
     49        * platform/gtk/PasteboardHelper.cpp:
     50        (WebCore::displayFromFrame): Deleted.
     51        (WebCore::PasteboardHelper::getPrimarySelectionClipboard): Deleted.
     52        * platform/gtk/PasteboardHelper.h:
     53
    1542014-09-16  Carlos Garcia Campos  <cgarcia@igalia.com>
    255
  • trunk/Source/WebCore/PlatformGTK.cmake

    r173651 r173687  
    181181
    182182    editing/atk/FrameSelectionAtk.cpp
     183    editing/gtk/EditorGtk.cpp
    183184
    184185    page/gtk/DragControllerGtk.cpp
  • trunk/Source/WebCore/editing/Editor.cpp

    r173665 r173687  
    563563#endif
    564564
    565 #if !PLATFORM(COCOA) && !PLATFORM(EFL)
     565#if !PLATFORM(COCOA) && !PLATFORM(EFL) && !PLATFORM(GTK)
    566566void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText, MailBlockquoteHandling mailBlockquoteHandling)
    567567{
     
    13251325
    13261326        if (imageElement) {
    1327 #if PLATFORM(COCOA) || PLATFORM(EFL)
     1327#if PLATFORM(COCOA) || PLATFORM(EFL) || PLATFORM(GTK)
    13281328            writeImageToPasteboard(*Pasteboard::createForCopyAndPaste(), *imageElement, document().url(), document().title());
    13291329#else
     
    13311331#endif
    13321332        } else {
    1333 #if PLATFORM(COCOA) || PLATFORM(EFL)
     1333#if PLATFORM(COCOA) || PLATFORM(EFL) || PLATFORM(GTK)
    13341334            writeSelectionToPasteboard(*Pasteboard::createForCopyAndPaste());
    13351335#else
     
    14371437        url = result.absoluteImageURL();
    14381438
    1439 #if PLATFORM(COCOA) || PLATFORM(EFL)
     1439#if PLATFORM(COCOA) || PLATFORM(EFL) || PLATFORM(GTK)
    14401440    writeImageToPasteboard(*Pasteboard::createForCopyAndPaste(), *element, url, result.altDisplayString());
    14411441#else
  • trunk/Source/WebCore/editing/Editor.h

    r173235 r173687  
    444444#endif
    445445
    446 #if PLATFORM(COCOA) || PLATFORM(EFL)
     446#if PLATFORM(COCOA) || PLATFORM(EFL) || PLATFORM(GTK)
    447447    WEBCORE_EXPORT void writeSelectionToPasteboard(Pasteboard&);
    448448    WEBCORE_EXPORT void writeImageToPasteboard(Pasteboard&, Element& imageElement, const URL&, const String& title);
  • trunk/Source/WebCore/page/DragController.cpp

    r173686 r173687  
    784784                dataTransfer.pasteboard().writePlainText(src.editor().selectedTextForDataTransfer(), Pasteboard::CannotSmartReplace);
    785785            else {
    786 #if PLATFORM(COCOA) || PLATFORM(EFL)
     786#if PLATFORM(COCOA) || PLATFORM(EFL) || PLATFORM(GTK)
    787787                src.editor().writeSelectionToPasteboard(dataTransfer.pasteboard());
    788788#else
  • trunk/Source/WebCore/page/gtk/DragControllerGtk.cpp

    r173686 r173687  
    3232#include "DocumentFragment.h"
    3333#include "DragData.h"
     34#include "Editor.h"
    3435#include "Element.h"
    3536#include "Frame.h"
     
    7677void DragController::declareAndWriteDragImage(DataTransfer& dataTransfer, Element& element, const URL& url, const String& label)
    7778{
    78     dataTransfer.pasteboard().writeImage(element, url, label);
     79    Frame* frame = element.document().frame();
     80    ASSERT(frame);
     81    frame->editor().writeImageToPasteboard(dataTransfer.pasteboard(), element, url, label);
    7982}
    8083
  • trunk/Source/WebCore/platform/Pasteboard.h

    r172862 r173687  
    3535#if PLATFORM(GTK)
    3636typedef struct _GtkClipboard GtkClipboard;
     37#include <wtf/gobject/GRefPtr.h>
    3738#endif
    3839
     
    7980    Vector<RefPtr<SharedBuffer>> clientData;
    8081#endif
     82#if PLATFORM(GTK)
     83    bool canSmartCopyOrDelete;
     84    String text;
     85    String markup;
     86    GRefPtr<GClosure> callback;
     87#endif
    8188};
    8289
     
    8693#if PLATFORM(MAC)
    8794    String userVisibleForm;
     95#endif
     96#if PLATFORM(GTK)
     97    String markup;
    8898#endif
    8999};
     
    93103    WEBCORE_EXPORT ~PasteboardImage();
    94104    RefPtr<Image> image;
     105#if !(PLATFORM(EFL) || PLATFORM(WIN))
     106    PasteboardURL url;
     107#endif
    95108#if !(PLATFORM(EFL) || PLATFORM(GTK) || PLATFORM(WIN))
    96     PasteboardURL url;
    97109    RefPtr<SharedBuffer> resourceData;
    98110    String resourceMIMEType;
     
    163175#endif
    164176
    165 #if PLATFORM(GTK) || PLATFORM(WIN)
     177#if PLATFORM(WIN)
    166178    PassRefPtr<DocumentFragment> documentFragment(Frame&, Range&, bool allowPlainText, bool& chosePlainText); // FIXME: Layering violation.
    167179    void writeImage(Element&, const URL&, const String& title); // FIXME: Layering violation.
  • trunk/Source/WebCore/platform/gtk/DataObjectGtk.cpp

    r163797 r173687  
    2020#include "DataObjectGtk.h"
    2121
    22 #include "markup.h"
    2322#include <gtk/gtk.h>
    2423#include <wtf/gobject/GUniquePtr.h>
     24#include <wtf/text/CString.h>
    2525#include <wtf/text/StringBuilder.h>
    2626
     
    3434}
    3535
    36 String DataObjectGtk::text() const
    37 {
    38     if (m_range) {
    39         String text = m_range->text();
    40         replaceNonBreakingSpaceWithSpace(text);
    41         return text;
    42     }
    43     return m_text;
    44 }
    45 
    46 String DataObjectGtk::markup() const
    47 {
    48     if (m_range)
    49         return createMarkup(*m_range, 0, AnnotateForInterchange, false, ResolveNonLocalURLs);
    50     return m_markup;
    51 }
    52 
    5336HashMap<String, String> DataObjectGtk::unknownTypes() const
    5437{
     
    5841void DataObjectGtk::setText(const String& newText)
    5942{
    60     m_range = 0;
    6143    m_text = newText;
    6244    replaceNonBreakingSpaceWithSpace(m_text);
     
    6547void DataObjectGtk::setMarkup(const String& newMarkup)
    6648{
    67     m_range = 0;
    6849    m_markup = newMarkup;
    6950}
     
    132113void DataObjectGtk::clearText()
    133114{
    134     m_range = 0;
    135     m_text = "";
     115    m_text = emptyString();
    136116}
    137117
    138118void DataObjectGtk::clearMarkup()
    139119{
    140     m_range = 0;
    141     m_markup = "";
     120    m_markup = emptyString();
    142121}
    143122
     
    155134void DataObjectGtk::clearAllExceptFilenames()
    156135{
    157     m_text = "";
    158     m_markup = "";
    159     m_uriList = "";
     136    m_text = emptyString();
     137    m_markup = emptyString();
     138    m_uriList = emptyString();
    160139    m_url = URL();
    161     m_image = 0;
    162     m_range = 0;
     140    m_image = nullptr;
    163141    m_unknownTypeData.clear();
    164142}
  • trunk/Source/WebCore/platform/gtk/DataObjectGtk.h

    r159837 r173687  
    2222#include "FileList.h"
    2323#include "URL.h"
    24 #include "Range.h"
    2524#include <wtf/RefCounted.h>
    2625#include <wtf/gobject/GRefPtr.h>
    27 #include <wtf/text/CString.h>
    2826#include <wtf/text/StringHash.h>
    2927
     
    4139    const Vector<String>& filenames() const { return m_filenames; }
    4240    GdkPixbuf* image() const { return m_image.get(); }
    43     void setRange(PassRefPtr<Range> newRange) { m_range = newRange; }
    4441    void setImage(GdkPixbuf* newImage) { m_image = newImage; }
    4542    void setURL(const URL&, const String&);
    4643    bool hasUnknownTypeData() const { return !m_unknownTypeData.isEmpty(); }
    47     bool hasText() const { return m_range || !m_text.isEmpty(); }
    48     bool hasMarkup() const { return m_range || !m_markup.isEmpty(); }
     44    bool hasText() const { return !m_text.isEmpty(); }
     45    bool hasMarkup() const { return !m_markup.isEmpty(); }
    4946    bool hasURIList() const { return !m_uriList.isEmpty(); }
    5047    bool hasURL() const { return !m_url.isEmpty() && m_url.isValid(); }
     
    5350    void clearURIList() { m_uriList = ""; }
    5451    void clearURL() { m_url = URL(); }
    55     void clearImage() { m_image = 0; }
     52    void clearImage() { m_image = nullptr; }
    5653
    57     String text() const;
    58     String markup() const;
     54    String text() const { return m_text; }
     55    String markup() const { return m_markup; }
    5956    String unknownTypeData(const String& type) const { return m_unknownTypeData.get(type); }
    6057    HashMap<String, String> unknownTypes() const;
     
    7976    Vector<String> m_filenames;
    8077    GRefPtr<GdkPixbuf> m_image;
    81     RefPtr<Range> m_range;
    8278    HashMap<String, String> m_unknownTypeData;
    8379};
  • trunk/Source/WebCore/platform/gtk/GtkDragAndDropHelper.h

    r157058 r173687  
    2828struct DroppingContext;
    2929class DragData;
     30class IntPoint;
    3031
    3132typedef void (*DragExitedCallback)(GtkWidget*, DragData&, bool dropHappened);
  • trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp

    r169327 r173687  
    2121#include "Pasteboard.h"
    2222
    23 #include "CachedImage.h"
    2423#include "DataObjectGtk.h"
    25 #include "DocumentFragment.h"
    2624#include "DragData.h"
    27 #include "Editor.h"
    28 #include "Frame.h"
    29 #include "HTMLImageElement.h"
    30 #include "HTMLInputElement.h"
    31 #include "HTMLNames.h"
    32 #include "HTMLParserIdioms.h"
    3325#include "Image.h"
    3426#include "URL.h"
    3527#include "PasteboardHelper.h"
    36 #include "RenderImage.h"
    37 #include "SVGElement.h"
    38 #include "SVGNames.h"
    39 #include "XLinkNames.h"
    40 #include "markup.h"
    4128#include <gtk/gtk.h>
    42 
     29#include <wtf/PassOwnPtr.h>
    4330
    4431namespace WebCore {
     
    8976}
    9077#endif
     78
     79// Making this non-inline so that WebKit 2's decoding doesn't have to include Image.h.
     80PasteboardImage::PasteboardImage()
     81{
     82}
     83
     84PasteboardImage::~PasteboardImage()
     85{
     86}
    9187
    9288Pasteboard::Pasteboard(PassRefPtr<DataObjectGtk> dataObject)
     
    157153}
    158154
    159 void Pasteboard::writeSelection(Range& selectedRange, bool canSmartCopyOrDelete, Frame& frame, ShouldSerializeSelectedTextForDataTransfer shouldSerializeSelectedTextForDataTransfer)
    160 {
    161     m_dataObject->clearAll();
    162     m_dataObject->setText(shouldSerializeSelectedTextForDataTransfer == IncludeImageAltTextForDataTransfer ? frame.editor().selectedTextForDataTransfer() : frame.editor().selectedText());
    163     m_dataObject->setMarkup(createMarkup(selectedRange, 0, AnnotateForInterchange, false, ResolveNonLocalURLs));
    164 
    165     if (m_gtkClipboard)
    166         PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(m_gtkClipboard, canSmartCopyOrDelete ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste);
    167 }
    168 
    169155void Pasteboard::writePlainText(const String& text, SmartReplaceOption smartReplaceOption)
    170156{
     
    187173}
    188174
    189 static URL getURLForImageElement(Element& element)
    190 {
    191     // FIXME: Later this code should be shared with Chromium somehow. Chances are all platforms want it.
    192     AtomicString urlString;
    193     if (isHTMLImageElement(element) || isHTMLInputElement(element))
    194         urlString = element.getAttribute(HTMLNames::srcAttr);
    195     else if (element.hasTagName(SVGNames::imageTag))
    196         urlString = element.getAttribute(XLinkNames::hrefAttr);
    197     else if (element.hasTagName(HTMLNames::embedTag) || isHTMLObjectElement(element))
    198         urlString = element.imageSourceURL();
    199 
    200     return urlString.isEmpty() ? URL() : element.document().completeURL(stripLeadingAndTrailingHTMLSpaces(urlString));
    201 }
    202 
    203 void Pasteboard::writeImage(Element& element, const URL&, const String& title)
    204 {
    205     if (!(element.renderer() && element.renderer()->isRenderImage()))
    206         return;
    207 
    208     RenderImage* renderer = toRenderImage(element.renderer());
    209     CachedImage* cachedImage = renderer->cachedImage();
    210     if (!cachedImage || cachedImage->errorOccurred())
    211         return;
    212     Image* image = cachedImage->imageForRenderer(renderer);
    213     ASSERT(image);
    214 
    215     m_dataObject->clearAll();
    216 
    217     URL url = getURLForImageElement(element);
    218     if (!url.isEmpty()) {
    219         m_dataObject->setURL(url, title);
    220 
    221         m_dataObject->setMarkup(createMarkup(element, IncludeNode, 0, ResolveAllURLs));
    222     }
    223 
    224     GRefPtr<GdkPixbuf> pixbuf = adoptGRef(image->getGdkPixbuf());
    225     m_dataObject->setImage(pixbuf.get());
    226 
    227     if (m_gtkClipboard)
    228         PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(m_gtkClipboard);
     175void Pasteboard::write(const PasteboardImage& pasteboardImage)
     176{
     177    m_dataObject->clearAll();
     178    if (!pasteboardImage.url.url.isEmpty()) {
     179        m_dataObject->setURL(pasteboardImage.url.url, pasteboardImage.url.title);
     180        m_dataObject->setMarkup(pasteboardImage.url.markup);
     181    }
     182
     183    GRefPtr<GdkPixbuf> pixbuf = adoptGRef(pasteboardImage.image->getGdkPixbuf());
     184    if (pixbuf)
     185        m_dataObject->setImage(pixbuf.get());
     186
     187    if (m_gtkClipboard)
     188        PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(m_gtkClipboard);
     189}
     190
     191void Pasteboard::write(const PasteboardWebContent& pasteboardContent)
     192{
     193    m_dataObject->clearAll();
     194    m_dataObject->setText(pasteboardContent.text);
     195    m_dataObject->setMarkup(pasteboardContent.markup);
     196
     197    if (m_gtkClipboard)
     198        PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(m_gtkClipboard, pasteboardContent.canSmartCopyOrDelete ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste, pasteboardContent.callback.get());
    229199}
    230200
     
    303273#endif
    304274
    305 PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame& frame, Range& context, bool allowPlainText, bool& chosePlainText)
    306 {
    307     if (m_gtkClipboard)
    308         PasteboardHelper::defaultPasteboardHelper()->getClipboardContents(m_gtkClipboard);
    309 
    310     chosePlainText = false;
    311 
    312     if (m_dataObject->hasMarkup()) {
    313         if (frame.document()) {
    314             RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(*frame.document(), m_dataObject->markup(), emptyString(), DisallowScriptingAndPluginContent);
    315             if (fragment)
    316                 return fragment.release();
    317         }
    318     }
    319 
    320     if (!allowPlainText)
    321         return 0;
    322 
    323     if (m_dataObject->hasText()) {
    324         chosePlainText = true;
    325         RefPtr<DocumentFragment> fragment = createFragmentFromText(context, m_dataObject->text());
    326         if (fragment)
    327             return fragment.release();
    328     }
    329 
    330     return 0;
    331 }
    332 
    333275void Pasteboard::read(PasteboardPlainText& text)
    334276{
  • trunk/Source/WebCore/platform/gtk/PasteboardHelper.cpp

    r173350 r173687  
    2424#include "PasteboardHelper.h"
    2525
    26 #include "Chrome.h"
    2726#include "DataObjectGtk.h"
    28 #include "Frame.h"
    2927#include "GRefPtrGtk.h"
    3028#include "GtkVersioning.h"
    31 #include "Page.h"
    3229#include "Pasteboard.h"
    3330#include "TextResourceDecoder.h"
    3431#include <gtk/gtk.h>
    3532#include <wtf/gobject/GUniquePtr.h>
     33#include <wtf/text/CString.h>
    3634
    3735namespace WebCore {
     
    9492{
    9593    gtk_target_list_unref(m_targetList);
    96 }
    97 
    98 static inline GdkDisplay* displayFromFrame(Frame* frame)
    99 {
    100     ASSERT(frame);
    101     Page* page = frame->page();
    102     ASSERT(page);
    103     PlatformPageClient client = page->chrome().platformPageClient();
    104     return client ? gtk_widget_get_display(client) : gdk_display_get_default();
    105 }
    106 
    107 GtkClipboard* PasteboardHelper::getPrimarySelectionClipboard(Frame* frame) const
    108 {
    109     return gtk_clipboard_get_for_display(displayFromFrame(frame), GDK_SELECTION_PRIMARY);
    11094}
    11195
     
    310294        return;
    311295
    312     GClosure* callback = static_cast<GClosure*>(data);
     296    GRefPtr<GClosure> callback = adoptGRef(static_cast<GClosure*>(data));
    313297    GValue firstArgument = {0, {{0}}};
    314298    g_value_init(&firstArgument, G_TYPE_POINTER);
    315299    g_value_set_pointer(&firstArgument, clipboard);
    316     g_closure_invoke(callback, 0, 1, &firstArgument, 0);
    317     g_closure_unref(callback);
     300    g_closure_invoke(callback.get(), nullptr, 1, &firstArgument, 0);
    318301}
    319302
     
    329312        settingClipboardDataObject = dataObject;
    330313
    331         gtk_clipboard_set_with_data(clipboard, table, numberOfTargets,
    332             getClipboardContentsCallback, clearClipboardContentsCallback, callback);
    333         gtk_clipboard_set_can_store(clipboard, 0, 0);
    334 
    335         settingClipboardDataObject = 0;
     314        if (gtk_clipboard_set_with_data(clipboard, table, numberOfTargets, getClipboardContentsCallback, clearClipboardContentsCallback, g_closure_ref(callback)))
     315            gtk_clipboard_set_can_store(clipboard, nullptr, 0);
     316        else {
     317            // When gtk_clipboard_set_with_data fails the callbacks are ignored, so we need to release the reference we were passing to clearClipboardContentsCallback.
     318            g_closure_unref(callback);
     319        }
     320
     321        settingClipboardDataObject = nullptr;
    336322
    337323    } else
  • trunk/Source/WebCore/platform/gtk/PasteboardHelper.h

    r154750 r173687  
    2626#define PasteboardHelper_h
    2727
    28 #include "Frame.h"
    2928#include <glib-object.h>
     29#include <wtf/Vector.h>
    3030
    3131namespace WebCore {
     
    4141    enum SmartPasteInclusion { IncludeSmartPaste, DoNotIncludeSmartPaste };
    4242
    43     GtkClipboard* getPrimarySelectionClipboard(Frame*) const;
    4443    GtkTargetList* targetList() const;
    4544    GtkTargetList* targetListForDataObject(DataObjectGtk*, SmartPasteInclusion = DoNotIncludeSmartPaste);
  • trunk/Source/WebKit2/ChangeLog

    r173686 r173687  
     12014-09-16  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Fix layering violations in PasteboardGtk
     4        https://bugs.webkit.org/show_bug.cgi?id=136802
     5
     6        Reviewed by Darin Adler.
     7
     8        * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
     9        (WebKit::WebEditorClient::updateGlobalSelection): Use new API to
     10        update the global selection.
     11
    1122014-09-16  Carlos Garcia Campos  <cgarcia@igalia.com>
    213
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp

    r170774 r173687  
    2121#include "WebEditorClient.h"
    2222
    23 #include "Frame.h"
    24 #include "FrameDestructionObserver.h"
    2523#include "PlatformKeyboardEvent.h"
    2624#include "WebPage.h"
     
    2927#include <WebCore/DataObjectGtk.h>
    3028#include <WebCore/Document.h>
     29#include <WebCore/Frame.h>
     30#include <WebCore/FrameDestructionObserver.h>
    3131#include <WebCore/KeyboardEvent.h>
    32 #include <WebCore/PasteboardHelper.h>
     32#include <WebCore/Pasteboard.h>
    3333#include <WebCore/WindowsKeyboardCodes.h>
     34#include <WebCore/markup.h>
     35#include <wtf/gobject/GRefPtr.h>
    3436
    3537using namespace WebCore;
     
    176178{
    177179#if PLATFORM(X11)
    178     GtkClipboard* clipboard = PasteboardHelper::defaultPasteboardHelper()->getPrimarySelectionClipboard(frame);
    179     DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    180 
    181180    if (!frame->selection().isRange())
    182181        return;
    183182
    184     dataObject->clearAll();
    185     dataObject->setRange(frame->selection().toNormalizedRange());
    186 
    187183    frameSettingClipboard = frame;
    188     GClosure* callback = g_cclosure_new(G_CALLBACK(collapseSelection), frame, 0);
     184    GRefPtr<GClosure> callback = adoptGRef(g_cclosure_new(G_CALLBACK(collapseSelection), frame, nullptr));
    189185    // This observer will be self-destroyed on closure finalization,
    190186    // that will happen either after closure execution or after
    191187    // closure invalidation.
    192     new EditorClientFrameDestructionObserver(frame, callback);
    193     g_closure_set_marshal(callback, g_cclosure_marshal_VOID__VOID);
    194     PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(clipboard, PasteboardHelper::DoNotIncludeSmartPaste, callback);
    195     frameSettingClipboard = 0;
     188    new EditorClientFrameDestructionObserver(frame, callback.get());
     189    g_closure_set_marshal(callback.get(), g_cclosure_marshal_VOID__VOID);
     190
     191    RefPtr<Range> range = frame->selection().toNormalizedRange();
     192    PasteboardWebContent pasteboardContent;
     193    pasteboardContent.canSmartCopyOrDelete = false;
     194    pasteboardContent.text = range->text();
     195    pasteboardContent.markup = createMarkup(*range, nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
     196    pasteboardContent.callback = callback;
     197    Pasteboard::createForGlobalSelection()->write(pasteboardContent);
     198    frameSettingClipboard = nullptr;
    196199#endif
    197200}
Note: See TracChangeset for help on using the changeset viewer.