Title: [239107] trunk/Source/WebCore
Revision
239107
Author
wenson_hs...@apple.com
Date
2018-12-12 09:06:49 -0800 (Wed, 12 Dec 2018)

Log Message

[iOS] A few API tests are failing after r239086
https://bugs.webkit.org/show_bug.cgi?id=192608

Reviewed by Zalan Bujtas.

These test failures were caused by a missing Vector size check in `Pasteboard::readFilePaths` before accessing
the first item. Fix this by adding a helper method on PasteboardItemInfo to grab the file path for the highest
fidelity pasteboard item (returning the null string if there are none), and use this in a few places that grab
the highest fidelity path using Vector::first().

While `Pasteboard::readRespectingUTIFidelities` does have a bounds check before accessing the list of paths,
this patch still replaces it with a call to `pathForHighestFidelityItem()`, so that the intent is more clear.

* platform/PasteboardItemInfo.h:
(WebCore::PasteboardItemInfo::pathForHighestFidelityItem const):
* platform/ios/PasteboardIOS.mm:
(WebCore::Pasteboard::readRespectingUTIFidelities):
(WebCore::Pasteboard::readFilePaths):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (239106 => 239107)


--- trunk/Source/WebCore/ChangeLog	2018-12-12 17:05:41 UTC (rev 239106)
+++ trunk/Source/WebCore/ChangeLog	2018-12-12 17:06:49 UTC (rev 239107)
@@ -1,3 +1,24 @@
+2018-12-12  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [iOS] A few API tests are failing after r239086
+        https://bugs.webkit.org/show_bug.cgi?id=192608
+
+        Reviewed by Zalan Bujtas.
+
+        These test failures were caused by a missing Vector size check in `Pasteboard::readFilePaths` before accessing
+        the first item. Fix this by adding a helper method on PasteboardItemInfo to grab the file path for the highest
+        fidelity pasteboard item (returning the null string if there are none), and use this in a few places that grab
+        the highest fidelity path using Vector::first().
+
+        While `Pasteboard::readRespectingUTIFidelities` does have a bounds check before accessing the list of paths,
+        this patch still replaces it with a call to `pathForHighestFidelityItem()`, so that the intent is more clear.
+
+        * platform/PasteboardItemInfo.h:
+        (WebCore::PasteboardItemInfo::pathForHighestFidelityItem const):
+        * platform/ios/PasteboardIOS.mm:
+        (WebCore::Pasteboard::readRespectingUTIFidelities):
+        (WebCore::Pasteboard::readFilePaths):
+
 2018-12-12  Carlos Garcia Campos  <cgar...@igalia.com>
 
         Unreviewed. Fix WPE build after r239101.

Modified: trunk/Source/WebCore/platform/PasteboardItemInfo.h (239106 => 239107)


--- trunk/Source/WebCore/platform/PasteboardItemInfo.h	2018-12-12 17:05:41 UTC (rev 239106)
+++ trunk/Source/WebCore/platform/PasteboardItemInfo.h	2018-12-12 17:06:49 UTC (rev 239107)
@@ -55,6 +55,15 @@
         return pathsForFileUpload[index];
     }
 
+    String pathForHighestFidelityItem() const
+    {
+        if (pathsForFileUpload.isEmpty())
+            return { };
+
+        ASSERT(!pathsForFileUpload.first().isEmpty());
+        return pathsForFileUpload.first();
+    }
+
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static std::optional<PasteboardItemInfo> decode(Decoder&);
 };

Modified: trunk/Source/WebCore/platform/ios/PasteboardIOS.mm (239106 => 239107)


--- trunk/Source/WebCore/platform/ios/PasteboardIOS.mm	2018-12-12 17:05:41 UTC (rev 239106)
+++ trunk/Source/WebCore/platform/ios/PasteboardIOS.mm	2018-12-12 17:06:49 UTC (rev 239107)
@@ -294,9 +294,10 @@
     for (NSUInteger index = 0, numberOfItems = strategy.getPasteboardItemsCount(m_pasteboardName); index < numberOfItems; ++index) {
 #if ENABLE(ATTACHMENT_ELEMENT)
         auto info = strategy.informationForItemAtIndex(index, m_pasteboardName);
-        bool canReadAttachment = policy == WebContentReadingPolicy::AnyType && RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() && !info.pathsForFileUpload.isEmpty();
+        auto attachmentFilePath = info.pathForHighestFidelityItem();
+        bool canReadAttachment = policy == WebContentReadingPolicy::AnyType && RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() && !attachmentFilePath.isEmpty();
         if (canReadAttachment && info.preferredPresentationStyle == PasteboardItemPresentationStyle::Attachment) {
-            reader.readFilePaths({ info.pathsForFileUpload.first() });
+            reader.readFilePaths({ WTFMove(attachmentFilePath) });
             continue;
         }
 #endif
@@ -317,7 +318,7 @@
         }
 #if ENABLE(ATTACHMENT_ELEMENT)
         if (canReadAttachment && result == ReaderResult::DidNotReadType)
-            reader.readFilePaths({ info.pathsForFileUpload.first() });
+            reader.readFilePaths({ WTFMove(attachmentFilePath) });
 #endif
     }
 }
@@ -459,7 +460,7 @@
     auto& strategy = *platformStrategies()->pasteboardStrategy();
     for (NSUInteger index = 0, numberOfItems = strategy.getPasteboardItemsCount(m_pasteboardName); index < numberOfItems; ++index) {
         // Currently, drag and drop is the only case on iOS where the "pasteboard" may contain file paths.
-        auto filePath = strategy.informationForItemAtIndex(index, m_pasteboardName).pathsForFileUpload.first();
+        auto filePath = strategy.informationForItemAtIndex(index, m_pasteboardName).pathForHighestFidelityItem();
         if (!filePath.isEmpty())
             filePaths.append(WTFMove(filePath));
     }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to