Changeset 205959 in webkit


Ignore:
Timestamp:
Sep 15, 2016 1:11:31 AM (8 years ago)
Author:
Carlos Garcia Campos
Message:

Merge r205909 - [GTK][Wayland] Implement clipboard support
https://bugs.webkit.org/show_bug.cgi?id=146574

Patch by Carlos Garnacho <carlosg@gnome.org> on 2016-09-14
Reviewed by Carlos Garcia Campos.

Source/WebCore:

Implement PlatformPasteboard in the GTK+ platform, and move Pasteboard
to using PasteboardStrategy so clipboard management is left to the
UIProcess.

DataObjectGtk is still used in the Pasteboard GTK implementation, it's
now just never backed by a GtkClipboard, this object is instead
serialized through PasteboardStrategy, so the UIProcess side can mirror
the content in a GtkClipboard-backed DataObjectGtk, which is then
exposed to the windowing through PlatformPasteboard/PasteboardHelper.

When requesting clipboard content, it works similarly, the UIProcess
side first updates its DataObjectGtk, which is then mirrored by the
WebProcess through the PasteboardStrategy requests.

  • PlatformGTK.cmake: Added PlatformPasteboardGtk.cpp
  • editing/gtk/EditorGtk.cpp:

(WebCore::Editor::writeSelectionToPasteboard): Eliminate usage of
PasteboardWebContent callback argument. This is done differently as
we have to signal back the WebProcess.

  • platform/Pasteboard.h: Cleaned up of direct GTK+ dependency.
  • platform/PasteboardStrategy.h: Added plumbing towards the pasteboard

proxy.

  • platform/PlatformPasteboard.h:
  • platform/gtk/DataObjectGtk.cpp:

(WebCore::DataObjectGtk::clearAllExceptFilenames): Clear the "smart
paste" flag if set, now that this is DataObjectGtk data.

  • platform/gtk/DataObjectGtk.h:

(WebCore::DataObjectGtk::canSmartReplace):
(WebCore::DataObjectGtk::setCanSmartReplace): Added functions, in order
to flag whether a DataObjectGtk has the "smart paste" feature enabled
or not.

  • platform/gtk/PasteboardGtk.cpp:

(WebCore::Pasteboard::createForCopyAndPaste):
(WebCore::Pasteboard::createForGlobalSelection):
(WebCore::Pasteboard::Pasteboard):
(WebCore::Pasteboard::writeToClipboard):
(WebCore::Pasteboard::readFromClipboard):
(WebCore::Pasteboard::writePlainText):
(WebCore::Pasteboard::write):
(WebCore::Pasteboard::writePasteboard):
(WebCore::Pasteboard::clear):
(WebCore::Pasteboard::canSmartReplace):
(WebCore::Pasteboard::read):
(WebCore::Pasteboard::hasData):
(WebCore::Pasteboard::types):
(WebCore::Pasteboard::readString):
(WebCore::Pasteboard::readFilenames): Made to use the
PasteboardStrategy instead of PasteboardHelper/GTK+ API.

  • platform/gtk/PasteboardHelper.cpp:

(WebCore::PasteboardHelper::~PasteboardHelper):
(WebCore::ClipboardSetData::ClipboardSetData):
(WebCore::clearClipboardContentsCallback):
(WebCore::PasteboardHelper::writeClipboardContents): Remove the GClosure
to notify whether the global selection has been replaced. Use std:function
instead. Remove SmartPasteInclusion argument, now figured out through
DataObjectGtk canSmartPaste() member.

  • platform/gtk/PasteboardHelper.h:
  • platform/gtk/PlatformPasteboardGtk.cpp: Added.

(WebCore::PlatformPasteboard::PlatformPasteboard):
(WebCore::PlatformPasteboard::writeToClipboard):
(WebCore::PlatformPasteboard::readFromClipboard): Implemented
PlatformPasteboard using PasteboardHelper/GTK+ API.

Source/WebKit2:

Add the necessary plumbing for the GTK+ backend to use the
PlatformPasteboard in WebCore. All selection data is transmitted
at once through the serialization of PasteboardContentGtk/DataObjectGtk.

  • PlatformGTK.cmake: Add PasteboardContentGtk.cpp and

WebPasteboardProxyGtk.cpp

  • Shared/gtk/ArgumentCodersGtk.cpp:

(IPC::encode):
(IPC::decode): Renamed from encodeDataObject/decodeDataObject
and made public.
(IPC::ArgumentCoder<DragData>::encode):
(IPC::ArgumentCoder<DragData>::decode): Update DataObjectGtk
encode/decode callers. Encode the extra canSmartReplace field.

  • Shared/gtk/ArgumentCodersGtk.h: Expose encode/decode methods for

DataObjectGtk.

  • Shared/gtk/PasteboardContent.cpp: Added. Wraps a DataObjectGtk

so it can be serialized on WebProcess/UIProcess messaging.
(WebKit::PasteboardContent::PasteboardContent):
(WebKit::PasteboardContent::encode):
(WebKit::PasteboardContent::decode): Methods to encode/decode a
PasteboardContent.

  • Shared/gtk/PasteboardContent.h: Added.
  • UIProcess/WebFrameProxy.cpp:

(WebKit::WebFrameProxy::collapseSelection): Added plumbing to allow
collapsing the global selection from the UI process side.

  • UIProcess/WebFrameProxy.h:
  • UIProcess/WebPasteboardProxy.h:
  • UIProcess/WebPasteboardProxy.messages.in: Added plumbing for the

GTK+ pasteboard proxy functions.

  • UIProcess/gtk/WebPageProxyGtk.cpp:

(WebKit::WebPageProxy::editorStateChanged):

  • UIProcess/gtk/WebPasteboardProxyGtk.cpp: Added.

(WebKit::WebPasteboardProxy::writeToClipboard):
(WebKit::WebPasteboardProxy::readFromClipboard): Implemented functions
hooking into the PlatformPasteboard. Per-selection (ie.
primary/clipboard) PlatformPasteboards are kept at this level, so those
are independently set and dealt with.
(WebKit::WebPasteboardProxy::setPrimarySelectionOwner):
(WebKit::WebPasteboardProxy::didDestroyFrame): Implemented functions
to manage the frame currently being currently interacted, so we can
signal back when the global selection has been replaced.

  • WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:

(WebKit::WebPlatformStrategies::writeToClipboard):
(WebKit::WebPlatformStrategies::readFromClipboard): Added methods to
send the WebProcess->UIProcess messages.

  • WebProcess/WebCoreSupport/WebPlatformStrategies.h:
  • WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:

(WebKit::WebEditorClient::updateGlobalSelection): Remove GClosure to
get notifications about changes in global selection ownership. This
is done through a WebPage message now, as the UI process manages the
clipboard.

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:
  • WebProcess/WebPage/gtk/WebPageGtk.cpp:

(WebKit::WebPage::collapseSelectionInFrame): Added methods to send
the UIProcess->WebProcess notification that the global selection has
been replaced.

Location:
releases/WebKitGTK/webkit-2.14/Source
Files:
4 added
26 edited

Legend:

Unmodified
Added
Removed
  • releases/WebKitGTK/webkit-2.14/Source/WebCore/ChangeLog

    r205958 r205959  
     12016-09-14  Carlos Garnacho <carlosg@gnome.org>
     2
     3        [GTK][Wayland] Implement clipboard support
     4        https://bugs.webkit.org/show_bug.cgi?id=146574
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Implement PlatformPasteboard in the GTK+ platform, and move Pasteboard
     9        to using PasteboardStrategy so clipboard management is left to the
     10        UIProcess.
     11
     12        DataObjectGtk is still used in the Pasteboard GTK implementation, it's
     13        now just never backed by a GtkClipboard, this object is instead
     14        serialized through PasteboardStrategy, so the UIProcess side can mirror
     15        the content in a GtkClipboard-backed DataObjectGtk, which is then
     16        exposed to the windowing through PlatformPasteboard/PasteboardHelper.
     17
     18        When requesting clipboard content, it works similarly, the UIProcess
     19        side first updates its DataObjectGtk, which is then mirrored by the
     20        WebProcess through the PasteboardStrategy requests.
     21
     22        * PlatformGTK.cmake: Added PlatformPasteboardGtk.cpp
     23        * editing/gtk/EditorGtk.cpp:
     24        (WebCore::Editor::writeSelectionToPasteboard): Eliminate usage of
     25        PasteboardWebContent callback argument. This is done differently as
     26        we have to signal back the WebProcess.
     27        * platform/Pasteboard.h: Cleaned up of direct GTK+ dependency.
     28        * platform/PasteboardStrategy.h: Added plumbing towards the pasteboard
     29        proxy.
     30        * platform/PlatformPasteboard.h:
     31        * platform/gtk/DataObjectGtk.cpp:
     32        (WebCore::DataObjectGtk::clearAllExceptFilenames): Clear the "smart
     33        paste" flag if set, now that this is DataObjectGtk data.
     34        * platform/gtk/DataObjectGtk.h:
     35        (WebCore::DataObjectGtk::canSmartReplace):
     36        (WebCore::DataObjectGtk::setCanSmartReplace): Added functions, in order
     37        to flag whether a DataObjectGtk has the "smart paste" feature enabled
     38        or not.
     39        * platform/gtk/PasteboardGtk.cpp:
     40        (WebCore::Pasteboard::createForCopyAndPaste):
     41        (WebCore::Pasteboard::createForGlobalSelection):
     42        (WebCore::Pasteboard::Pasteboard):
     43        (WebCore::Pasteboard::writeToClipboard):
     44        (WebCore::Pasteboard::readFromClipboard):
     45        (WebCore::Pasteboard::writePlainText):
     46        (WebCore::Pasteboard::write):
     47        (WebCore::Pasteboard::writePasteboard):
     48        (WebCore::Pasteboard::clear):
     49        (WebCore::Pasteboard::canSmartReplace):
     50        (WebCore::Pasteboard::read):
     51        (WebCore::Pasteboard::hasData):
     52        (WebCore::Pasteboard::types):
     53        (WebCore::Pasteboard::readString):
     54        (WebCore::Pasteboard::readFilenames): Made to use the
     55        PasteboardStrategy instead of PasteboardHelper/GTK+ API.
     56        * platform/gtk/PasteboardHelper.cpp:
     57        (WebCore::PasteboardHelper::~PasteboardHelper):
     58        (WebCore::ClipboardSetData::ClipboardSetData):
     59        (WebCore::clearClipboardContentsCallback):
     60        (WebCore::PasteboardHelper::writeClipboardContents): Remove the GClosure
     61        to notify whether the global selection has been replaced. Use std:function
     62        instead. Remove SmartPasteInclusion argument, now figured out through
     63        DataObjectGtk canSmartPaste() member.
     64        * platform/gtk/PasteboardHelper.h:
     65        * platform/gtk/PlatformPasteboardGtk.cpp: Added.
     66        (WebCore::PlatformPasteboard::PlatformPasteboard):
     67        (WebCore::PlatformPasteboard::writeToClipboard):
     68        (WebCore::PlatformPasteboard::readFromClipboard): Implemented
     69        PlatformPasteboard using PasteboardHelper/GTK+ API.
     70
    1712016-09-13  Carlos Garcia Campos  <cgarcia@igalia.com>
    272
  • releases/WebKitGTK/webkit-2.14/Source/WebCore/PlatformGTK.cmake

    r205116 r205959  
    222222    platform/gtk/PlatformKeyboardEventGtk.cpp
    223223    platform/gtk/PlatformMouseEventGtk.cpp
     224    platform/gtk/PlatformPasteboardGtk.cpp
    224225    platform/gtk/PlatformScreenGtk.cpp
    225226    platform/gtk/PlatformWheelEventGtk.cpp
  • releases/WebKitGTK/webkit-2.14/Source/WebCore/editing/gtk/EditorGtk.cpp

    r205958 r205959  
    126126    pasteboardContent.text = selectedTextForDataTransfer();
    127127    pasteboardContent.markup = createMarkup(*selectedRange(), nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
    128     pasteboardContent.callback = nullptr;
    129128    pasteboard.write(pasteboardContent);
    130129}
  • releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/Pasteboard.h

    r205958 r205959  
    3333#include <wtf/text/WTFString.h>
    3434
    35 #if PLATFORM(GTK)
    36 typedef struct _GtkClipboard GtkClipboard;
    37 #include <wtf/glib/GRefPtr.h>
    38 #endif
    39 
    4035#if PLATFORM(IOS)
    4136OBJC_CLASS NSArray;
     
    8479    String text;
    8580    String markup;
    86     GRefPtr<GClosure> callback;
    8781#endif
    8882};
     
    144138
    145139#if PLATFORM(GTK)
     140    explicit Pasteboard(const String& name);
    146141    explicit Pasteboard(RefPtr<DataObjectGtk>&&);
    147     explicit Pasteboard(GtkClipboard*);
    148142#endif
    149143
     
    227221
    228222#if PLATFORM(GTK)
     223    enum class ShouldIncludeSmartPaste { No, Yes };
     224    void writeToClipboard(ShouldIncludeSmartPaste = ShouldIncludeSmartPaste::No);
     225    void readFromClipboard();
    229226    RefPtr<DataObjectGtk> m_dataObject;
    230     GtkClipboard* m_gtkClipboard;
     227    String m_name;
    231228#endif
    232229
  • releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/PasteboardStrategy.h

    r203109 r205959  
    3939struct PasteboardWebContent;
    4040
     41#if PLATFORM(GTK)
     42class DataObjectGtk;
     43#endif
     44
    4145class PasteboardStrategy {
    4246public:
     
    6973    virtual long setStringForType(const String&, const String& pasteboardType, const String& pasteboardName) = 0;
    7074#endif
     75#if PLATFORM(GTK)
     76    virtual void writeToClipboard(const String& pasteboardName, const RefPtr<DataObjectGtk>&) = 0;
     77    virtual RefPtr<DataObjectGtk> readFromClipboard(const String& pasteboardName) = 0;
     78#endif // PLATFORM(GTK)
    7179protected:
    7280    virtual ~PasteboardStrategy()
  • releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/PlatformPasteboard.h

    r203109 r205959  
    4848struct PasteboardWebContent;
    4949
     50#if PLATFORM(GTK)
     51class DataObjectGtk;
     52#endif
     53
    5054class PlatformPasteboard {
    5155public:
     
    8286    WEBCORE_EXPORT int count();
    8387
     88#if PLATFORM(GTK)
     89    WEBCORE_EXPORT void writeToClipboard(const RefPtr<DataObjectGtk>&, std::function<void()>&& primarySelectionCleared);
     90    WEBCORE_EXPORT RefPtr<DataObjectGtk> readFromClipboard();
     91#endif
     92
    8493private:
    8594#if PLATFORM(MAC)
     
    8998    RetainPtr<UIPasteboard> m_pasteboard;
    9099#endif
     100#if PLATFORM(GTK)
     101    GtkClipboard* m_clipboard;
     102#endif
    91103};
    92104
  • releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/DataObjectGtk.cpp

    r205958 r205959  
    140140    m_image = nullptr;
    141141    m_unknownTypeData.clear();
     142    m_canSmartReplace = false;
    142143}
    143144
  • releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/DataObjectGtk.h

    r205958 r205959  
    4848    bool hasFilenames() const { return !m_filenames.isEmpty(); }
    4949    bool hasImage() const { return m_image; }
     50    bool canSmartReplace() const { return m_canSmartReplace; }
    5051    void clearURIList() { m_uriList = emptyString(); }
    5152    void clearURL() { m_url = URL(); }
     
    6061    void setUnknownTypeData(const String& type, const String& data) { m_unknownTypeData.set(type, data); }
    6162    void setURIList(const String&);
     63    void setCanSmartReplace(bool canSmartReplace) { m_canSmartReplace = canSmartReplace; }
    6264    String urlLabel() const;
    6365
     
    7577    GRefPtr<GdkPixbuf> m_image;
    7678    HashMap<String, String> m_unknownTypeData;
     79    bool m_canSmartReplace { false };
    7780};
    7881
  • releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardGtk.cpp

    r205958 r205959  
    2424#include "DragData.h"
    2525#include "Image.h"
     26#include "PasteboardStrategy.h"
     27#include "PlatformStrategies.h"
    2628#include "URL.h"
    27 #include "PasteboardHelper.h"
    28 #include <gtk/gtk.h>
     29#include <wtf/NeverDestroyed.h>
    2930
    3031namespace WebCore {
     
    4142std::unique_ptr<Pasteboard> Pasteboard::createForCopyAndPaste()
    4243{
    43     return std::make_unique<Pasteboard>(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
     44    return std::make_unique<Pasteboard>("CLIPBOARD");
    4445}
    4546
    4647std::unique_ptr<Pasteboard> Pasteboard::createForGlobalSelection()
    4748{
    48     return std::make_unique<Pasteboard>(gtk_clipboard_get(GDK_SELECTION_PRIMARY));
     49    return std::make_unique<Pasteboard>("PRIMARY");
    4950}
    5051
     
    7778Pasteboard::Pasteboard(RefPtr<DataObjectGtk>&& dataObject)
    7879    : m_dataObject(WTFMove(dataObject))
    79     , m_gtkClipboard(nullptr)
    8080{
    8181    ASSERT(m_dataObject);
    8282}
    8383
    84 Pasteboard::Pasteboard(GtkClipboard* gtkClipboard)
     84Pasteboard::Pasteboard(const String& name)
    8585    : m_dataObject(DataObjectGtk::create())
    86     , m_gtkClipboard(gtkClipboard)
    87 {
    88     ASSERT(m_dataObject);
    89     PasteboardHelper::singleton().registerClipboard(gtkClipboard);
     86    , m_name(name)
     87{
    9088}
    9189
     
    122120}
    123121
     122void Pasteboard::writeToClipboard(ShouldIncludeSmartPaste shouldIncludeSmartPaste)
     123{
     124    if (m_name.isNull())
     125        return;
     126    m_dataObject->setCanSmartReplace(shouldIncludeSmartPaste == ShouldIncludeSmartPaste::Yes);
     127    platformStrategies()->pasteboardStrategy()->writeToClipboard(m_name, m_dataObject);
     128}
     129
     130void Pasteboard::readFromClipboard()
     131{
     132    if (m_name.isNull())
     133        return;
     134    m_dataObject = platformStrategies()->pasteboardStrategy()->readFromClipboard(m_name);
     135}
     136
    124137void Pasteboard::writeString(const String& type, const String& data)
    125138{
     
    148161    m_dataObject->setText(text);
    149162
    150     if (m_gtkClipboard)
    151         PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject, (smartReplaceOption == CanSmartReplace) ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste);
     163    writeToClipboard(smartReplaceOption == CanSmartReplace ? ShouldIncludeSmartPaste::Yes : ShouldIncludeSmartPaste::No);
    152164}
    153165
     
    159171    m_dataObject->setURL(pasteboardURL.url, pasteboardURL.title);
    160172
    161     if (m_gtkClipboard)
    162         PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
     173    writeToClipboard();
    163174}
    164175
     
    175186        m_dataObject->setImage(pixbuf.get());
    176187
    177     if (m_gtkClipboard)
    178         PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
     188    writeToClipboard();
    179189}
    180190
     
    185195    m_dataObject->setMarkup(pasteboardContent.markup);
    186196
    187     if (m_gtkClipboard)
    188         PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject, pasteboardContent.canSmartCopyOrDelete ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste, pasteboardContent.callback.get());
     197    writeToClipboard(pasteboardContent.canSmartCopyOrDelete ? ShouldIncludeSmartPaste::Yes : ShouldIncludeSmartPaste::No);
    189198}
    190199
     
    209218    }
    210219
    211     if (m_gtkClipboard)
    212         PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
     220    writeToClipboard();
    213221}
    214222
     
    220228    // still contain the "Files" string if any files were included in the drag)."
    221229    m_dataObject->clearAllExceptFilenames();
    222 
    223     if (m_gtkClipboard)
    224         PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
     230    writeToClipboard();
    225231}
    226232
     
    246252    }
    247253
    248     if (m_gtkClipboard)
    249         PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
     254    writeToClipboard();
    250255}
    251256
    252257bool Pasteboard::canSmartReplace()
    253258{
    254     return m_gtkClipboard && PasteboardHelper::singleton().clipboardContentSupportsSmartReplace(m_gtkClipboard);
     259    readFromClipboard();
     260    return m_dataObject->canSmartReplace();
    255261}
    256262
     
    263269void Pasteboard::read(PasteboardPlainText& text)
    264270{
    265     if (m_gtkClipboard)
    266         PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
     271    readFromClipboard();
    267272    text.text = m_dataObject->text();
    268273}
     
    270275bool Pasteboard::hasData()
    271276{
    272     if (m_gtkClipboard)
    273         PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
    274 
     277    readFromClipboard();
    275278    return m_dataObject->hasText() || m_dataObject->hasMarkup() || m_dataObject->hasURIList() || m_dataObject->hasImage() || m_dataObject->hasUnknownTypeData();
    276279}
     
    278281Vector<String> Pasteboard::types()
    279282{
    280     if (m_gtkClipboard)
    281         PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
     283    readFromClipboard();
    282284
    283285    Vector<String> types;
     
    307309String Pasteboard::readString(const String& type)
    308310{
    309     if (m_gtkClipboard)
    310         PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
     311    readFromClipboard();
    311312
    312313    switch (dataObjectTypeFromHTMLClipboardType(type)) {
     
    330331Vector<String> Pasteboard::readFilenames()
    331332{
    332     if (m_gtkClipboard)
    333         PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
    334 
     333    readFromClipboard();
    335334    return m_dataObject->filenames();
    336335}
  • releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardHelper.cpp

    r205958 r205959  
    7777PasteboardHelper::~PasteboardHelper()
    7878{
    79     for (auto* clipboard : m_gtkClipboards)
    80         gtk_clipboard_store(clipboard);
    8179}
    8280
     
    116114        }
    117115    }
     116
     117    dataObject.setCanSmartReplace(gtk_clipboard_wait_is_target_available(clipboard, smartPasteAtom));
    118118}
    119119
     
    170170}
    171171
    172 GRefPtr<GtkTargetList> PasteboardHelper::targetListForDataObject(const DataObjectGtk& dataObject, SmartPasteInclusion shouldInludeSmartPaste)
     172GRefPtr<GtkTargetList> PasteboardHelper::targetListForDataObject(const DataObjectGtk& dataObject)
    173173{
    174174    GRefPtr<GtkTargetList> list = adoptGRef(gtk_target_list_new(nullptr, 0));
     
    191191        gtk_target_list_add(list.get(), unknownAtom, 0, TargetTypeUnknown);
    192192
    193     if (shouldInludeSmartPaste == IncludeSmartPaste)
     193    if (dataObject.canSmartReplace())
    194194        gtk_target_list_add(list.get(), smartPasteAtom, 0, TargetTypeSmartPaste);
    195195
     
    258258
    259259struct ClipboardSetData {
    260     ClipboardSetData(DataObjectGtk* dataObject, GClosure* callback)
     260    ClipboardSetData(DataObjectGtk* dataObject, std::function<void()>&& selectionClearedCallback)
    261261        : dataObject(dataObject)
    262         , callback(callback)
     262        , selectionClearedCallback(WTFMove(selectionClearedCallback))
    263263    {
    264264    }
     
    269269
    270270    RefPtr<DataObjectGtk> dataObject;
    271     GRefPtr<GClosure> callback;
     271    std::function<void()> selectionClearedCallback;
    272272};
    273273
     
    278278}
    279279
    280 static void clearClipboardContentsCallback(GtkClipboard* clipboard, gpointer userData)
     280static void clearClipboardContentsCallback(GtkClipboard*, gpointer userData)
    281281{
    282282    std::unique_ptr<ClipboardSetData> data(static_cast<ClipboardSetData*>(userData));
     
    286286        data->dataObject->clearAll();
    287287
    288     if (!data->callback)
    289         return;
    290 
    291     GValue firstArgument = {0, {{0}}};
    292     g_value_init(&firstArgument, G_TYPE_POINTER);
    293     g_value_set_pointer(&firstArgument, clipboard);
    294     g_closure_invoke(data->callback.get(), nullptr, 1, &firstArgument, 0);
    295 }
    296 
    297 void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, const DataObjectGtk& dataObject, SmartPasteInclusion includeSmartPaste, GClosure* callback)
    298 {
    299     GRefPtr<GtkTargetList> list = targetListForDataObject(dataObject, includeSmartPaste);
     288    if (data->selectionClearedCallback)
     289        data->selectionClearedCallback();
     290}
     291
     292void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, const DataObjectGtk& dataObject, std::function<void()>&& primarySelectionCleared)
     293{
     294    GRefPtr<GtkTargetList> list = targetListForDataObject(dataObject);
    300295
    301296    int numberOfTargets;
     
    305300        settingClipboardDataObject = const_cast<DataObjectGtk*>(&dataObject);
    306301
    307         auto data = std::make_unique<ClipboardSetData>(settingClipboardDataObject, callback);
     302        auto data = std::make_unique<ClipboardSetData>(settingClipboardDataObject, WTFMove(primarySelectionCleared));
    308303        if (gtk_clipboard_set_with_data(clipboard, table, numberOfTargets, getClipboardContentsCallback, clearClipboardContentsCallback, data.get())) {
    309304            gtk_clipboard_set_can_store(clipboard, nullptr, 0);
     
    320315}
    321316
    322 bool PasteboardHelper::clipboardContentSupportsSmartReplace(GtkClipboard* clipboard)
    323 {
    324     return gtk_clipboard_wait_is_target_available(clipboard, smartPasteAtom);
    325 }
    326 
    327 void PasteboardHelper::registerClipboard(GtkClipboard* clipboard)
    328 {
    329     ASSERT(clipboard);
    330     m_gtkClipboards.add(clipboard);
    331 }
    332 
    333 }
    334 
     317}
     318
  • releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardHelper.h

    r205958 r205959  
    2727
    2828#include "GRefPtrGtk.h"
    29 #include <wtf/HashSet.h>
    3029#include <wtf/Noncopyable.h>
    3130#include <wtf/Vector.h>
     
    4443
    4544    GtkTargetList* targetList() const;
    46     GRefPtr<GtkTargetList> targetListForDataObject(const DataObjectGtk&, SmartPasteInclusion = DoNotIncludeSmartPaste);
     45    GRefPtr<GtkTargetList> targetListForDataObject(const DataObjectGtk&);
    4746    void fillSelectionData(GtkSelectionData*, guint, const DataObjectGtk&);
    4847    void fillDataObjectFromDropData(GtkSelectionData*, guint, DataObjectGtk&);
    4948    Vector<GdkAtom> dropAtomsForContext(GtkWidget*, GdkDragContext*);
    50     void writeClipboardContents(GtkClipboard*, const DataObjectGtk&, SmartPasteInclusion = DoNotIncludeSmartPaste, GClosure* = 0);
     49    void writeClipboardContents(GtkClipboard*, const DataObjectGtk&, std::function<void()>&& primarySelectionCleared = nullptr);
    5150    void getClipboardContents(GtkClipboard*, DataObjectGtk&);
    5251
    5352    enum PasteboardTargetType { TargetTypeMarkup, TargetTypeText, TargetTypeImage, TargetTypeURIList, TargetTypeNetscapeURL, TargetTypeSmartPaste, TargetTypeUnknown };
    54     bool clipboardContentSupportsSmartReplace(GtkClipboard*);
    55 
    56     void registerClipboard(GtkClipboard*);
    5753
    5854private:
     
    6157
    6258    GRefPtr<GtkTargetList> m_targetList;
    63     HashSet<GtkClipboard*> m_gtkClipboards;
    6459};
    6560
  • releases/WebKitGTK/webkit-2.14/Source/WebKit2/ChangeLog

    r205958 r205959  
     12016-09-14  Carlos Garnacho  <carlosg@gnome.org>
     2
     3        [GTK][Wayland] Implement clipboard support
     4        https://bugs.webkit.org/show_bug.cgi?id=146574
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Add the necessary plumbing for the GTK+ backend to use the
     9        PlatformPasteboard in WebCore. All selection data is transmitted
     10        at once through the serialization of PasteboardContentGtk/DataObjectGtk.
     11
     12        * PlatformGTK.cmake: Add PasteboardContentGtk.cpp and
     13        WebPasteboardProxyGtk.cpp
     14        * Shared/gtk/ArgumentCodersGtk.cpp:
     15        (IPC::encode):
     16        (IPC::decode): Renamed from encodeDataObject/decodeDataObject
     17        and made public.
     18        (IPC::ArgumentCoder<DragData>::encode):
     19        (IPC::ArgumentCoder<DragData>::decode): Update DataObjectGtk
     20        encode/decode callers. Encode the extra canSmartReplace field.
     21        * Shared/gtk/ArgumentCodersGtk.h: Expose encode/decode methods for
     22        DataObjectGtk.
     23        * Shared/gtk/PasteboardContent.cpp: Added. Wraps a DataObjectGtk
     24        so it can be serialized on WebProcess/UIProcess messaging.
     25        (WebKit::PasteboardContent::PasteboardContent):
     26        (WebKit::PasteboardContent::encode):
     27        (WebKit::PasteboardContent::decode): Methods to encode/decode a
     28        PasteboardContent.
     29        * Shared/gtk/PasteboardContent.h: Added.
     30        * UIProcess/WebFrameProxy.cpp:
     31        (WebKit::WebFrameProxy::collapseSelection): Added plumbing to allow
     32        collapsing the global selection from the UI process side.
     33        * UIProcess/WebFrameProxy.h:
     34        * UIProcess/WebPasteboardProxy.h:
     35        * UIProcess/WebPasteboardProxy.messages.in: Added plumbing for the
     36        GTK+ pasteboard proxy functions.
     37        * UIProcess/gtk/WebPageProxyGtk.cpp:
     38        (WebKit::WebPageProxy::editorStateChanged):
     39        * UIProcess/gtk/WebPasteboardProxyGtk.cpp: Added.
     40        (WebKit::WebPasteboardProxy::writeToClipboard):
     41        (WebKit::WebPasteboardProxy::readFromClipboard): Implemented functions
     42        hooking into the PlatformPasteboard. Per-selection (ie.
     43        primary/clipboard) PlatformPasteboards are kept at this level, so those
     44        are independently set and dealt with.
     45        (WebKit::WebPasteboardProxy::setPrimarySelectionOwner):
     46        (WebKit::WebPasteboardProxy::didDestroyFrame): Implemented functions
     47        to manage the frame currently being currently interacted, so we can
     48        signal back when the global selection has been replaced.
     49        * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
     50        (WebKit::WebPlatformStrategies::writeToClipboard):
     51        (WebKit::WebPlatformStrategies::readFromClipboard): Added methods to
     52        send the WebProcess->UIProcess messages.
     53        * WebProcess/WebCoreSupport/WebPlatformStrategies.h:
     54        * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
     55        (WebKit::WebEditorClient::updateGlobalSelection): Remove GClosure to
     56        get notifications about changes in global selection ownership. This
     57        is done through a WebPage message now, as the UI process manages the
     58        clipboard.
     59        * WebProcess/WebPage/WebPage.h:
     60        * WebProcess/WebPage/WebPage.messages.in:
     61        * WebProcess/WebPage/gtk/WebPageGtk.cpp:
     62        (WebKit::WebPage::collapseSelectionInFrame): Added methods to send
     63        the UIProcess->WebProcess notification that the global selection has
     64        been replaced.
     65
    1662016-09-13  Carlos Garcia Campos  <cgarcia@igalia.com>
    267
  • releases/WebKitGTK/webkit-2.14/Source/WebKit2/PlatformGTK.cmake

    r205622 r205959  
    7171    Shared/gtk/NativeWebTouchEventGtk.cpp
    7272    Shared/gtk/NativeWebWheelEventGtk.cpp
     73    Shared/gtk/PasteboardContent.cpp
    7374    Shared/gtk/PrintInfoGtk.cpp
    7475    Shared/gtk/ProcessExecutablePathGtk.cpp
     
    312313    UIProcess/gtk/WebInspectorProxyGtk.cpp
    313314    UIProcess/gtk/WebPageProxyGtk.cpp
     315    UIProcess/gtk/WebPasteboardProxyGtk.cpp
    314316    UIProcess/gtk/WebPopupMenuProxyGtk.cpp
    315317    UIProcess/gtk/WebPreferencesGtk.cpp
  • releases/WebKitGTK/webkit-2.14/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp

    r204678 r205959  
    8383}
    8484
    85 static void encodeDataObject(Encoder& encoder, const DataObjectGtk* dataObject)
     85void encode(Encoder& encoder, const DataObjectGtk* dataObject)
    8686{
    8787    bool hasText = dataObject->hasText();
     
    114114    if (hasUnknownTypeData)
    115115        encoder << dataObject->unknownTypes();
    116 }
    117 
    118 static bool decodeDataObject(Decoder& decoder, RefPtr<DataObjectGtk>& dataObject)
     116
     117    bool canSmartReplace = dataObject->canSmartReplace();
     118    encoder << canSmartReplace;
     119}
     120
     121bool decode(Decoder& decoder, RefPtr<DataObjectGtk>& dataObject)
    119122{
    120123    RefPtr<DataObjectGtk> data = DataObjectGtk::create();
     
    182185            data->setUnknownTypeData(it->key, it->value);
    183186    }
     187
     188    bool canSmartReplace;
     189    if (!decoder.decode(canSmartReplace))
     190        return false;
     191    data->setCanSmartReplace(canSmartReplace);
    184192
    185193    dataObject = data;
     
    199207    encoder << static_cast<bool>(platformData);
    200208    if (platformData)
    201         encodeDataObject(encoder, platformData);
     209        IPC::encode(encoder, platformData);
    202210}
    203211
     
    226234    RefPtr<DataObjectGtk> platformData;
    227235    if (hasPlatformData) {
    228         if (!decodeDataObject(decoder, platformData))
     236        if (!IPC::decode(decoder, platformData))
    229237            return false;
    230238    }
  • releases/WebKitGTK/webkit-2.14/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.h

    r204678 r205959  
    5353bool decode(Decoder&, GRefPtr<GtkPageSetup>&);
    5454
     55void encode(Encoder&, const WebCore::DataObjectGtk*);
     56bool decode(Decoder&, RefPtr<WebCore::DataObjectGtk>&);
     57
    5558} // namespace IPC
    5659
  • releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebFrameProxy.cpp

    r191063 r205959  
    3232#include "WebPageMessages.h"
    3333#include "WebPageProxy.h"
     34#include "WebPasteboardProxy.h"
    3435#include "WebProcessPool.h"
    3536#include <WebCore/DOMImplementation.h>
     
    5455{
    5556    WebProcessPool::statistics().wkFrameCount--;
     57#if PLATFORM(GTK)
     58    WebPasteboardProxy::singleton().didDestroyFrame(this);
     59#endif
    5660}
    5761
     
    258262#endif
    259263
     264#if PLATFORM(GTK)
     265void WebFrameProxy::collapseSelection()
     266{
     267    if (!m_page)
     268        return;
     269
     270    m_page->process().send(Messages::WebPage::CollapseSelectionInFrame(m_frameID), m_page->pageID());
     271}
     272#endif
     273
    260274} // namespace WebKit
  • releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebFrameProxy.h

    r204668 r205959  
    125125#endif
    126126
     127#if PLATFORM(GTK)
     128    void collapseSelection();
     129#endif
     130
    127131private:
    128132    WebFrameProxy(WebPageProxy* page, uint64_t frameID);
  • releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebPasteboardProxy.h

    r204668 r205959  
    4141namespace WebKit {
    4242
     43class WebFrameProxy;
    4344class WebProcessProxy;
     45
     46#if PLATFORM(GTK)
     47class PasteboardContent;
     48#endif
    4449
    4550class WebPasteboardProxy : public IPC::MessageReceiver {
     
    5055
    5156    void addWebProcessProxy(WebProcessProxy&);
     57
     58#if PLATFORM(GTK)
     59    void setPrimarySelectionOwner(WebFrameProxy*);
     60    void didDestroyFrame(WebFrameProxy*);
     61#endif
    5262
    5363private:
     
    8292    void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size, uint64_t& newChangeCount);
    8393#endif
     94#if PLATFORM(GTK)
     95    void writeToClipboard(const String& pasteboardName, const PasteboardContent&);
     96    void readFromClipboard(const String& pasteboardName, PasteboardContent&);
     97
     98    WebFrameProxy* m_primarySelectionOwner { nullptr };
     99    WebFrameProxy* m_frameWritingToClipboard { nullptr };
     100#endif // PLATFORM(GTK)
    84101};
    85102
  • releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebPasteboardProxy.messages.in

    r177805 r205959  
    4949    SetPasteboardBufferForType(String pasteboardName, String pasteboardType, WebKit::SharedMemory::Handle handle, uint64_t size) -> (uint64_t changeCount)
    5050#endif
     51
     52#if PLATFORM(GTK)
     53    WriteToClipboard(String pasteboardName, struct WebKit::PasteboardContent pasteboardContent)
     54    ReadFromClipboard(String pasteboardName) -> (struct WebKit::PasteboardContent pasteboardContent)
     55#endif
    5156}
  • releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp

    r191628 r205959  
    3232#include "WebKitWebViewBasePrivate.h"
    3333#include "WebPageMessages.h"
     34#include "WebPasteboardProxy.h"
    3435#include "WebProcessProxy.h"
    3536#include "WebsiteDataStore.h"
     
    8081    if (editorState.shouldIgnoreCompositionSelectionChange)
    8182        return;
     83    if (m_editorState.selectionIsRange)
     84        WebPasteboardProxy::singleton().setPrimarySelectionOwner(focusedFrame());
    8285    m_pageClient.selectionDidChange();
    8386}
  • releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp

    r204327 r205959  
    7070#endif
    7171
     72#if PLATFORM(GTK)
     73#include "PasteboardContent.h"
     74#endif
     75
    7276using namespace WebCore;
    7377
     
    340344#endif // PLATFORM(COCOA)
    341345
     346#if PLATFORM(GTK)
     347// PasteboardStrategy
     348
     349void WebPlatformStrategies::writeToClipboard(const String& pasteboardName, const RefPtr<WebCore::DataObjectGtk>& dataObject)
     350{
     351    PasteboardContent pasteboardContent = PasteboardContent(dataObject.get());
     352    WebProcess::singleton().parentProcessConnection()->send(Messages::WebPasteboardProxy::WriteToClipboard(pasteboardName, pasteboardContent), 0);
     353}
     354
     355RefPtr<WebCore::DataObjectGtk> WebPlatformStrategies::readFromClipboard(const String& pasteboardName)
     356{
     357    PasteboardContent pasteboardContent;
     358    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadFromClipboard(pasteboardName), Messages::WebPasteboardProxy::ReadFromClipboard::Reply(pasteboardContent), 0);
     359    return pasteboardContent.dataObject;
     360}
     361
     362#endif // PLATFORM(GTK)
     363
    342364} // namespace WebKit
  • releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h

    r204466 r205959  
    8787    long setStringForType(const String&, const String& pasteboardType, const String& pasteboardName) override;
    8888#endif
    89 
     89#if PLATFORM(GTK)
     90    void writeToClipboard(const String& pasteboardName, const RefPtr<WebCore::DataObjectGtk>&) override;
     91    RefPtr<WebCore::DataObjectGtk> readFromClipboard(const String& pasteboardName) override;
     92#endif
    9093};
    9194
  • releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp

    r205958 r205959  
    120120}
    121121
    122 class EditorClientFrameDestructionObserver : FrameDestructionObserver {
    123 public:
    124     EditorClientFrameDestructionObserver(Frame* frame, GClosure* closure)
    125         : FrameDestructionObserver(frame)
    126         , m_closure(closure)
    127     {
    128         g_closure_add_finalize_notifier(m_closure, this, destroyOnClosureFinalization);
    129     }
    130 
    131     void frameDestroyed()
    132     {
    133         g_closure_invalidate(m_closure);
    134         FrameDestructionObserver::frameDestroyed();
    135     }
    136 private:
    137     GClosure* m_closure;
    138 
    139     static void destroyOnClosureFinalization(gpointer data, GClosure*)
    140     {
    141         // Calling delete void* will free the memory but won't invoke
    142         // the destructor, something that is a must for us.
    143         EditorClientFrameDestructionObserver* observer = static_cast<EditorClientFrameDestructionObserver*>(data);
    144         delete observer;
    145     }
    146 };
    147 
    148 static Frame* frameSettingClipboard;
    149 
    150 static void collapseSelection(GtkClipboard*, Frame* frame)
    151 {
    152     if (frameSettingClipboard && frameSettingClipboard == frame)
    153         return;
    154 
    155     // Collapse the selection without clearing it.
    156     ASSERT(frame);
    157     const VisibleSelection& selection = frame->selection().selection();
    158     frame->selection().setBase(selection.extent(), selection.affinity());
    159 }
    160 
    161122void WebEditorClient::updateGlobalSelection(Frame* frame)
    162123{
     
    167128        return;
    168129
    169     frameSettingClipboard = frame;
    170     GRefPtr<GClosure> callback = adoptGRef(g_cclosure_new(G_CALLBACK(collapseSelection), frame, nullptr));
    171     // This observer will be self-destroyed on closure finalization,
    172     // that will happen either after closure execution or after
    173     // closure invalidation.
    174     new EditorClientFrameDestructionObserver(frame, callback.get());
    175     g_closure_set_marshal(callback.get(), g_cclosure_marshal_VOID__VOID);
    176 
    177130    PasteboardWebContent pasteboardContent;
    178131    pasteboardContent.canSmartCopyOrDelete = false;
    179132    pasteboardContent.text = range->text();
    180133    pasteboardContent.markup = createMarkup(*range, nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
    181     pasteboardContent.callback = callback;
    182134    Pasteboard::createForGlobalSelection()->write(pasteboardContent);
    183     frameSettingClipboard = nullptr;
    184135}
    185136
  • releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r205733 r205959  
    644644    void confirmComposition(const String& text, int64_t selectionStart, int64_t selectionLength);
    645645    void cancelComposition();
     646
     647    void collapseSelectionInFrame(uint64_t frameID);
    646648#endif
    647649
  • releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r204318 r205959  
    341341    ConfirmComposition(String text, int64_t selectionStart, int64_t selectionLength)
    342342    CancelComposition()
     343
     344    CollapseSelectionInFrame(uint64_t frameID)
    343345#endif
    344346
  • releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp

    r187100 r205959  
    3232#include "NotImplemented.h"
    3333#include "WebEvent.h"
     34#include "WebFrame.h"
    3435#include "WebPageAccessibilityObject.h"
    3536#include "WebPageProxyMessages.h"
     37#include "WebProcess.h"
    3638#include "WindowsKeyboardCodes.h"
    3739#include <WebCore/BackForwardController.h>
     
    217219}
    218220
     221void WebPage::collapseSelectionInFrame(uint64_t frameID)
     222{
     223    WebFrame* frame = WebProcess::singleton().webFrame(frameID);
     224    if (!frame || !frame->coreFrame())
     225        return;
     226
     227    // Collapse the selection without clearing it.
     228    const VisibleSelection& selection = frame->coreFrame()->selection().selection();
     229    frame->coreFrame()->selection().setBase(selection.extent(), selection.affinity());
     230}
     231
    219232} // namespace WebKit
Note: See TracChangeset for help on using the changeset viewer.