Split StaticPasteboard::writeString into writeString and writeStringInCustomData
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Oct 2017 07:30:20 +0000 (07:30 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Oct 2017 07:30:20 +0000 (07:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177991

Reviewed by Wenson Hsieh.

Split writeString into the one that writes into the plaform pasteboard natively and the custom pasteboard data like we did
in r222680 for readString and readStringInCustomData.

* dom/DataTransfer.cpp:
(WebCore::DataTransfer::setData):
(WebCore::DataTransfer::setDataFromItemList): Extracted out of setData.
* dom/DataTransfer.h:
* dom/DataTransferItemList.cpp:
(WebCore::DataTransferItemList::add):
* platform/StaticPasteboard.cpp:
(WebCore::updateTypes): Extacted out of writeString.
(WebCore::StaticPasteboard::writeString):
(WebCore::StaticPasteboard::writeStringInCustomData):
* platform/StaticPasteboard.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222964 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/DataTransfer.cpp
Source/WebCore/dom/DataTransfer.h
Source/WebCore/dom/DataTransferItemList.cpp
Source/WebCore/platform/StaticPasteboard.cpp
Source/WebCore/platform/StaticPasteboard.h

index 614aa06..df95cd3 100644 (file)
@@ -1,3 +1,25 @@
+2017-10-06  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Split StaticPasteboard::writeString into writeString and writeStringInCustomData
+        https://bugs.webkit.org/show_bug.cgi?id=177991
+
+        Reviewed by Wenson Hsieh.
+
+        Split writeString into the one that writes into the plaform pasteboard natively and the custom pasteboard data like we did
+        in r222680 for readString and readStringInCustomData.
+
+        * dom/DataTransfer.cpp:
+        (WebCore::DataTransfer::setData):
+        (WebCore::DataTransfer::setDataFromItemList): Extracted out of setData.
+        * dom/DataTransfer.h:
+        * dom/DataTransferItemList.cpp:
+        (WebCore::DataTransferItemList::add):
+        * platform/StaticPasteboard.cpp:
+        (WebCore::updateTypes): Extacted out of writeString.
+        (WebCore::StaticPasteboard::writeString):
+        (WebCore::StaticPasteboard::writeStringInCustomData):
+        * platform/StaticPasteboard.h:
+
 2017-10-05  Dean Jackson  <dino@apple.com>
 
         [WebGL] Safari performance is slow due to high MSAA usage
index 7dcb8d9..59d7433 100644 (file)
@@ -156,12 +156,23 @@ void DataTransfer::setData(const String& type, const String& data)
     if ((forFileDrag() || Settings::customPasteboardDataEnabled()) && m_pasteboard->containsFiles())
         return;
 
-    String normalizedType = normalizeType(type);
-    m_pasteboard->writeString(normalizedType, data);
+    auto normalizedType = normalizeType(type);
+    setDataFromItemList(normalizedType, data);
     if (m_itemList)
         m_itemList->didSetStringData(normalizedType);
 }
 
+void DataTransfer::setDataFromItemList(const String& type, const String& data)
+{
+    ASSERT(canWriteData());
+    RELEASE_ASSERT(is<StaticPasteboard>(*m_pasteboard));
+
+    if (Settings::customPasteboardDataEnabled() && !Pasteboard::isSafeTypeForDOMToReadAndWrite(type))
+        downcast<StaticPasteboard>(*m_pasteboard).writeStringInCustomData(type, data);
+    else
+        m_pasteboard->writeString(type, data);
+}
+
 void DataTransfer::updateFileList()
 {
     ASSERT(canWriteData());
index d120e0b..8400d7a 100644 (file)
@@ -65,6 +65,7 @@ public:
     String getData(const String& type) const;
 
     void setData(const String& type, const String& data);
+    void setDataFromItemList(const String& type, const String& data);
 
     void setDragImage(Element*, int x, int y);
 
index 8b27387..82ce2de 100644 (file)
@@ -78,7 +78,7 @@ ExceptionOr<RefPtr<DataTransferItem>> DataTransferItemList::add(const String& da
     if (!isSupportedType(lowercasedType))
         return nullptr;
 
-    m_dataTransfer.pasteboard().writeString(lowercasedType, data);
+    m_dataTransfer.setDataFromItemList(lowercasedType, data);
     ASSERT(m_items);
     m_items->append(DataTransferItem::create(m_weakPtrFactory.createWeakPtr(*this), lowercasedType));
     return RefPtr<DataTransferItem> { m_items->last().copyRef() };
index 8f188d7..7c0aa3d 100644 (file)
@@ -50,16 +50,24 @@ String StaticPasteboard::readStringInCustomData(const String& type)
     return m_customData.get(type);
 }
 
+static void updateTypes(Vector<String>& types, String type, bool moveToEnd)
+{
+    if (moveToEnd)
+        types.removeFirst(type);
+    ASSERT(!types.contains(type));
+    types.append(type);
+}
+
 void StaticPasteboard::writeString(const String& type, const String& value)
 {
-    auto& pasteboardData = Pasteboard::isSafeTypeForDOMToReadAndWrite(type) ? m_platformData : m_customData;
-    if (pasteboardData.set(type, value).isNewEntry)
-        m_types.append(type);
-    else {
-        m_types.removeFirst(type);
-        ASSERT(!m_types.contains(type));
-        m_types.append(type);
-    }
+    bool typeWasAlreadyPresent = !m_platformData.set(type, value).isNewEntry || m_customData.contains(type);
+    updateTypes(m_types, type, typeWasAlreadyPresent);
+}
+
+void StaticPasteboard::writeStringInCustomData(const String& type, const String& value)
+{
+    bool typeWasAlreadyPresent = !m_customData.set(type, value).isNewEntry || m_platformData.contains(type);
+    updateTypes(m_types, type, typeWasAlreadyPresent);
 }
 
 void StaticPasteboard::clear()
index 099f6a0..9cfcc72 100644 (file)
@@ -47,6 +47,7 @@ public:
     String readStringInCustomData(const String& type) final;
 
     void writeString(const String& type, const String& data) final;
+    void writeStringInCustomData(const String& type, const String& data);
     void clear() final;
     void clear(const String& type) final;