Changeset 239107 in webkit


Ignore:
Timestamp:
Dec 12, 2018 9:06:49 AM (5 years ago)
Author:
Wenson Hsieh
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):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r239102 r239107  
     12018-12-12  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] A few API tests are failing after r239086
     4        https://bugs.webkit.org/show_bug.cgi?id=192608
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        These test failures were caused by a missing Vector size check in `Pasteboard::readFilePaths` before accessing
     9        the first item. Fix this by adding a helper method on PasteboardItemInfo to grab the file path for the highest
     10        fidelity pasteboard item (returning the null string if there are none), and use this in a few places that grab
     11        the highest fidelity path using Vector::first().
     12
     13        While `Pasteboard::readRespectingUTIFidelities` does have a bounds check before accessing the list of paths,
     14        this patch still replaces it with a call to `pathForHighestFidelityItem()`, so that the intent is more clear.
     15
     16        * platform/PasteboardItemInfo.h:
     17        (WebCore::PasteboardItemInfo::pathForHighestFidelityItem const):
     18        * platform/ios/PasteboardIOS.mm:
     19        (WebCore::Pasteboard::readRespectingUTIFidelities):
     20        (WebCore::Pasteboard::readFilePaths):
     21
    1222018-12-12  Carlos Garcia Campos  <cgarcia@igalia.com>
    223
  • trunk/Source/WebCore/platform/PasteboardItemInfo.h

    r239086 r239107  
    5656    }
    5757
     58    String pathForHighestFidelityItem() const
     59    {
     60        if (pathsForFileUpload.isEmpty())
     61            return { };
     62
     63        ASSERT(!pathsForFileUpload.first().isEmpty());
     64        return pathsForFileUpload.first();
     65    }
     66
    5867    template<class Encoder> void encode(Encoder&) const;
    5968    template<class Decoder> static std::optional<PasteboardItemInfo> decode(Decoder&);
  • trunk/Source/WebCore/platform/ios/PasteboardIOS.mm

    r239086 r239107  
    295295#if ENABLE(ATTACHMENT_ELEMENT)
    296296        auto info = strategy.informationForItemAtIndex(index, m_pasteboardName);
    297         bool canReadAttachment = policy == WebContentReadingPolicy::AnyType && RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() && !info.pathsForFileUpload.isEmpty();
     297        auto attachmentFilePath = info.pathForHighestFidelityItem();
     298        bool canReadAttachment = policy == WebContentReadingPolicy::AnyType && RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() && !attachmentFilePath.isEmpty();
    298299        if (canReadAttachment && info.preferredPresentationStyle == PasteboardItemPresentationStyle::Attachment) {
    299             reader.readFilePaths({ info.pathsForFileUpload.first() });
     300            reader.readFilePaths({ WTFMove(attachmentFilePath) });
    300301            continue;
    301302        }
     
    318319#if ENABLE(ATTACHMENT_ELEMENT)
    319320        if (canReadAttachment && result == ReaderResult::DidNotReadType)
    320             reader.readFilePaths({ info.pathsForFileUpload.first() });
     321            reader.readFilePaths({ WTFMove(attachmentFilePath) });
    321322#endif
    322323    }
     
    460461    for (NSUInteger index = 0, numberOfItems = strategy.getPasteboardItemsCount(m_pasteboardName); index < numberOfItems; ++index) {
    461462        // Currently, drag and drop is the only case on iOS where the "pasteboard" may contain file paths.
    462         auto filePath = strategy.informationForItemAtIndex(index, m_pasteboardName).pathsForFileUpload.first();
     463        auto filePath = strategy.informationForItemAtIndex(index, m_pasteboardName).pathForHighestFidelityItem();
    463464        if (!filePath.isEmpty())
    464465            filePaths.append(WTFMove(filePath));
Note: See TracChangeset for help on using the changeset viewer.