Changeset 222699 in webkit


Ignore:
Timestamp:
Oct 2, 2017 12:03:45 AM (7 years ago)
Author:
rniwa@webkit.org
Message:

Merge readFilenames() and read(PasteboardFileReader)
https://bugs.webkit.org/show_bug.cgi?id=177728
<rdar://problem/34761725>

Reviewed by Sam Weinig.

Generalized PasteboardFileReader to return multiple files instead of just one file, and replaced the use
of Pasteboard::readFilenames() with it. Because eliminates the need for finding the list of types to read
as files in addition to file names, this patch also removes Pasteboard::typesTreatedAsFiles().

Note that Pasteboard::readFilenames() continues to exist in macOS and iOS as it's internally used by
Pasteboard::read(PasteboardFileReader) in PasteboardCocoa.mm.

No new tests since there should be no behavioral change.

  • dom/DataTransfer.cpp:

(WebCore::DataTransfer::files const): Now makes a single call to Pasteboard::read(PasteboardFileReader)
instead of reading filenames and then falling back to it. Also got rid of if-def for drag drop checks
since forDrag() and forFileDrag() are always defined since r222688.
(WebCore::PasteboardFileTypeReader): Added. Gets the list of all file types.
(WebCore::PasteboardFileTypeReader::readFilename): Added. Gets the list of all file types.
(WebCore::PasteboardFileTypeReader::readBuffer): Added. Gets the list of all file types.
(WebCore::DataTransfer::hasFileOfType): Reimplemented using PasteboardFileTypeReader.

  • editing/WebCorePasteboardFileReader.cpp:

(WebCore::WebCorePasteboardFileReader::readFilename): Added.
(WebCore::WebCorePasteboardFileReader::readBuffer): Renamed from read.

  • editing/WebCorePasteboardFileReader.h:
  • platform/Pasteboard.h:

(WebCore::PasteboardFileReader): Removed the constructor since we no longer specify a specific type to
read off of pasteboard, and renamed the existing read function to readBuffer, and added a new variant
which takes a filename.

  • platform/StaticPasteboard.h:
  • platform/cocoa/PasteboardCocoa.mm:

(WebCore::imageTypeToFakeFilename): Return "image/png" for ImageType::TIFF (to do TIFF-to-PNG conversion;
see r222656 for why this is needed) now that this function is used to convert directly from image type
converted from cocoa type instead of the one reverse-converted from MIME type.
(WebCore::mimeTypeToImageType): Deleted.
(WebCore::Pasteboard::typesTreatedAsFiles): Deleted.
(WebCore::Pasteboard::typesForLegacyUnsafeBindings): Use newly added readTypesWithSecurityCheck.
(WebCore::convertTIFFToPNG): Extracted out of read(PasteboardFileReader).
(WebCore::Pasteboard::read): Generalized to add filenames as well as image buffers as files. Because now
we're concerting Cocoa types to ImageType, we no longer have to detect when TIFF-as-PNG conversion is
happening here. We just treat ImageType::TIFF as PNG and do the conversion.
(WebCore::Pasteboard::readStringInCustomData): Use newly added readBufferForTypeWithSecurityCheck.
(WebCore::Pasteboard::readTypesWithSecurityCheck): Added.
(WebCore::Pasteboard::readBufferForTypeWithSecurityCheck): Added.

  • platform/gtk/PasteboardGtk.cpp:

(WebCore::Pasteboard::read): Implemented.
(WebCore::Pasteboard::typesTreatedAsFiles): Deleted.
(WebCore::Pasteboard::containsFiles): Implemented without calling readFilenames, which has been deleted.
(WebCore::Pasteboard::readFilenames): Deleted.

  • platform/win/PasteboardWin.cpp:

(WebCore::Pasteboard::typesTreatedAsFiles): Deleted.
(WebCore::PasteboardFileCounter): Added. Used to counts the number of files in the pasteboard.
(WebCore::PasteboardFileCounter::readFilename):
(WebCore::PasteboardFileCounter::readBuffer):
(WebCore::Pasteboard::containsFiles):
(WebCore::Pasteboard::read): Moved the code to extract filenames out of readFilenames.
(WebCore::Pasteboard::readFilenames): Deleted.

  • platform/wpe/PasteboardWPE.cpp:

(WebCore::Pasteboard::typesTreatedAsFiles): Deleted.
(WebCore::Pasteboard::readFilenames): Deleted.

Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r222698 r222699  
     12017-10-02  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Merge readFilenames() and read(PasteboardFileReader)
     4        https://bugs.webkit.org/show_bug.cgi?id=177728
     5        <rdar://problem/34761725>
     6
     7        Reviewed by Sam Weinig.
     8
     9        Generalized PasteboardFileReader to return multiple files instead of just one file, and replaced the use
     10        of Pasteboard::readFilenames() with it. Because eliminates the need for finding the list of types to read
     11        as files in addition to file names, this patch also removes Pasteboard::typesTreatedAsFiles().
     12
     13        Note that Pasteboard::readFilenames() continues to exist in macOS and iOS as it's internally used by
     14        Pasteboard::read(PasteboardFileReader) in PasteboardCocoa.mm.
     15
     16        No new tests since there should be no behavioral change.
     17
     18        * dom/DataTransfer.cpp:
     19        (WebCore::DataTransfer::files const): Now makes a single call to Pasteboard::read(PasteboardFileReader)
     20        instead of reading filenames and then falling back to it. Also got rid of if-def for drag drop checks
     21        since forDrag() and forFileDrag() are always defined since r222688.
     22        (WebCore::PasteboardFileTypeReader): Added. Gets the list of all file types.
     23        (WebCore::PasteboardFileTypeReader::readFilename): Added. Gets the list of all file types.
     24        (WebCore::PasteboardFileTypeReader::readBuffer): Added. Gets the list of all file types.
     25        (WebCore::DataTransfer::hasFileOfType): Reimplemented using PasteboardFileTypeReader.
     26        * editing/WebCorePasteboardFileReader.cpp:
     27        (WebCore::WebCorePasteboardFileReader::readFilename): Added.
     28        (WebCore::WebCorePasteboardFileReader::readBuffer): Renamed from read.
     29        * editing/WebCorePasteboardFileReader.h:
     30        * platform/Pasteboard.h:
     31        (WebCore::PasteboardFileReader): Removed the constructor since we no longer specify a specific type to
     32        read off of pasteboard, and renamed the existing read function to readBuffer, and added a new variant
     33        which takes a filename.
     34        * platform/StaticPasteboard.h:
     35        * platform/cocoa/PasteboardCocoa.mm:
     36        (WebCore::imageTypeToFakeFilename): Return "image/png" for ImageType::TIFF (to do TIFF-to-PNG conversion;
     37        see r222656 for why this is needed) now that this function is used to convert directly from image type
     38        converted from cocoa type instead of the one reverse-converted from MIME type.
     39        (WebCore::mimeTypeToImageType): Deleted.
     40        (WebCore::Pasteboard::typesTreatedAsFiles): Deleted.
     41        (WebCore::Pasteboard::typesForLegacyUnsafeBindings): Use newly added readTypesWithSecurityCheck.
     42        (WebCore::convertTIFFToPNG): Extracted out of read(PasteboardFileReader).
     43        (WebCore::Pasteboard::read): Generalized to add filenames as well as image buffers as files. Because now
     44        we're concerting Cocoa types to ImageType, we no longer have to detect when TIFF-as-PNG conversion is
     45        happening here. We just treat ImageType::TIFF as PNG and do the conversion.
     46        (WebCore::Pasteboard::readStringInCustomData): Use newly added readBufferForTypeWithSecurityCheck.
     47        (WebCore::Pasteboard::readTypesWithSecurityCheck): Added.
     48        (WebCore::Pasteboard::readBufferForTypeWithSecurityCheck): Added.
     49        * platform/gtk/PasteboardGtk.cpp:
     50        (WebCore::Pasteboard::read): Implemented.
     51        (WebCore::Pasteboard::typesTreatedAsFiles): Deleted.
     52        (WebCore::Pasteboard::containsFiles): Implemented without calling readFilenames, which has been deleted.
     53        (WebCore::Pasteboard::readFilenames): Deleted.
     54        * platform/win/PasteboardWin.cpp:
     55        (WebCore::Pasteboard::typesTreatedAsFiles): Deleted.
     56        (WebCore::PasteboardFileCounter): Added. Used to counts the number of files in the pasteboard.
     57        (WebCore::PasteboardFileCounter::readFilename):
     58        (WebCore::PasteboardFileCounter::readBuffer):
     59        (WebCore::Pasteboard::containsFiles):
     60        (WebCore::Pasteboard::read): Moved the code to extract filenames out of readFilenames.
     61        (WebCore::Pasteboard::readFilenames): Deleted.
     62        * platform/wpe/PasteboardWPE.cpp:
     63        (WebCore::Pasteboard::typesTreatedAsFiles): Deleted.
     64        (WebCore::Pasteboard::readFilenames): Deleted.
     65
    1662017-10-01  Sam Weinig  <sam@webkit.org>
    267
  • trunk/Source/WebCore/dom/DataTransfer.cpp

    r222688 r222699  
    183183FileList& DataTransfer::files() const
    184184{
    185     bool newlyCreatedFileList = !m_fileList;
    186     if (!m_fileList)
    187         m_fileList = FileList::create();
    188 
    189185    if (!canReadData()) {
    190         m_fileList->clear();
     186        if (m_fileList)
     187            m_fileList->clear();
     188        else
     189            m_fileList = FileList::create();
    191190        return *m_fileList;
    192191    }
    193192
    194 #if ENABLE(DRAG_SUPPORT)
    195193    if (forDrag() && !forFileDrag()) {
    196         ASSERT(m_fileList->isEmpty());
     194        if (m_fileList)
     195            ASSERT(m_fileList->isEmpty());
     196        else
     197            m_fileList = FileList::create();
    197198        return *m_fileList;
    198199    }
    199 #endif
    200 
    201     if (newlyCreatedFileList) {
    202         for (auto& filename : m_pasteboard->readFilenames())
    203             m_fileList->append(File::create(filename));
    204         if (m_fileList->isEmpty()) {
    205             for (auto& type : m_pasteboard->typesTreatedAsFiles()) {
    206                 WebCorePasteboardFileReader reader(type);
    207                 m_pasteboard->read(reader);
    208                 if (reader.file)
    209                     m_fileList->append(reader.file.releaseNonNull());
    210             }
    211         }
     200
     201    if (!m_fileList) {
     202        WebCorePasteboardFileReader reader;
     203        m_pasteboard->read(reader);
     204        m_fileList = FileList::create(WTFMove(reader.files));
    212205    }
    213206    return *m_fileList;
    214207}
    215208
     209struct PasteboardFileTypeReader final : PasteboardFileReader {
     210    void readFilename(const String& filename)
     211    {
     212        types.add(File::contentTypeForFile(filename));
     213    }
     214
     215    void readBuffer(const String&, const String& type, Ref<SharedBuffer>&&)
     216    {
     217        types.add(type);
     218    }
     219
     220    HashSet<String, ASCIICaseInsensitiveHash> types;
     221};
     222
    216223bool DataTransfer::hasFileOfType(const String& type)
    217224{
    218225    ASSERT_WITH_SECURITY_IMPLICATION(canReadTypes());
    219 
    220     for (auto& path : m_pasteboard->readFilenames()) {
    221         if (equalIgnoringASCIICase(File::contentTypeForFile(path), type))
    222             return true;
    223     }
    224 
    225     return false;
     226    PasteboardFileTypeReader reader;
     227    m_pasteboard->read(reader);
     228    return reader.types.contains(type);
    226229}
    227230
  • trunk/Source/WebCore/editing/WebCorePasteboardFileReader.cpp

    r222656 r222699  
    3434WebCorePasteboardFileReader::~WebCorePasteboardFileReader() = default;
    3535
    36 void WebCorePasteboardFileReader::read(const String& filename, Ref<SharedBuffer>&& buffer)
     36void WebCorePasteboardFileReader::readFilename(const String& filename)
     37{
     38    files.append(File::create(filename));
     39}
     40
     41void WebCorePasteboardFileReader::readBuffer(const String& filename, const String& type, Ref<SharedBuffer>&& buffer)
    3742{
    3843    Vector<uint8_t> data;
    3944    data.append(buffer->data(), buffer->size());
    40     file = File::create(Blob::create(WTFMove(data), type), filename);
     45    files.append(File::create(Blob::create(WTFMove(data), type), filename));
    4146}
    4247
  • trunk/Source/WebCore/editing/WebCorePasteboardFileReader.h

    r222656 r222699  
    3333
    3434struct WebCorePasteboardFileReader final : PasteboardFileReader {
    35     WebCorePasteboardFileReader(const String& type)
    36         : PasteboardFileReader(type)
    37     { }
    38 
    3935    ~WebCorePasteboardFileReader();
    4036
    41     void read(const String&, Ref<SharedBuffer>&&) final;
     37    void readFilename(const String&) final;
     38    void readBuffer(const String& filename, const String& type, Ref<SharedBuffer>&&) final;
    4239
    43     RefPtr<File> file;
     40    Vector<Ref<File>> files;
    4441};
    4542
  • trunk/Source/WebCore/platform/Pasteboard.h

    r222688 r222699  
    5959class Element;
    6060class Frame;
     61class PasteboardStrategy;
    6162class Range;
    6263class SelectionData;
     
    149150
    150151struct PasteboardFileReader {
    151     PasteboardFileReader(const String& type)
    152         : type(type)
    153     { }
    154152    virtual ~PasteboardFileReader() = default;
    155 
    156     virtual void read(const String&, Ref<SharedBuffer>&&) = 0;
    157 
    158     const String type;
     153    virtual void readFilename(const String&) = 0;
     154    virtual void readBuffer(const String& filename, const String& type, Ref<SharedBuffer>&&) = 0;
    159155};
    160156
     
    199195    virtual Vector<String> typesSafeForBindings();
    200196    virtual Vector<String> typesForLegacyUnsafeBindings();
    201     virtual Vector<String> typesTreatedAsFiles();
    202197    virtual String readString(const String& type);
    203198    virtual String readStringInCustomData(const String& type);
     
    217212
    218213    virtual bool containsFiles();
    219     virtual Vector<String> readFilenames();
    220214    virtual bool canSmartReplace();
    221215
     
    283277
    284278#if PLATFORM(COCOA)
     279    Vector<String> readFilenames();
    285280    String readPlatformValueAsString(const String& domType, long changeCount, const String& pasteboardName);
    286281    static void addHTMLClipboardTypesForCocoaType(ListHashSet<String>& resultTypes, const String& cocoaType, const String& pasteboardName);
    287282    String readStringForPlatformType(const String&);
     283    Vector<String> readTypesWithSecurityCheck();
     284    RefPtr<SharedBuffer> readBufferForTypeWithSecurityCheck(const String&);
    288285#endif
    289286
  • trunk/Source/WebCore/platform/StaticPasteboard.h

    r222688 r222699  
    4444    Vector<String> typesSafeForBindings() final { return m_types; }
    4545    Vector<String> typesForLegacyUnsafeBindings() final { return m_types; }
    46     Vector<String> typesTreatedAsFiles() final { return { }; }
    4746    String readString(const String& type) final;
    4847    String readStringInCustomData(const String& type) final;
     
    6059
    6160    bool containsFiles() final { return false; }
    62     Vector<String> readFilenames() final { return { }; }
    6361    bool canSmartReplace() final { return false; }
    6462
  • trunk/Source/WebCore/platform/cocoa/PasteboardCocoa.mm

    r222688 r222699  
    7373}
    7474
     75// String literals returned by this function must be defined exactly once
     76// since read(PasteboardFileReader&) uses HashMap<const char*> to check uniqueness.
    7577static const char* imageTypeToMIMEType(ImageType type)
    7678{
     
    8284        return "image/png"; // For Web compatibility, we pretend to have PNG instead.
    8385#else
    84         return nullptr; // Don't support TIFF on iOS for now.
     86        return nullptr; // Don't support pasting TIFF on iOS for now.
    8587#endif
    8688    case ImageType::PNG:
     
    100102        return nullptr;
    101103    case ImageType::TIFF:
     104#if PLATFORM(MAC)
     105        return "image/png"; // For Web compatibility, we pretend to have PNG instead.
     106#else
    102107        ASSERT_NOT_REACHED();
    103108        return nullptr;
     109#endif
    104110    case ImageType::PNG:
    105111        return "image.png";
     
    111117}
    112118
    113 static ImageType mimeTypeToImageType(const String& mimeType)
    114 {
    115 #if PLATFORM(MAC)
    116     if (mimeType == "image/tiff")
    117         return ImageType::TIFF;
    118 #endif
    119     if (mimeType == "image/png")
    120         return ImageType::PNG;
    121     if (mimeType == "image/jpeg")
    122         return ImageType::JPEG;
    123     if (mimeType == "image/gif")
    124         return ImageType::GIF;
    125     return ImageType::Invalid;
    126 }
    127 
    128119bool Pasteboard::shouldTreatCocoaTypeAsFile(const String& cocoaType)
    129120{
    130121    return cocoaTypeToImageType(cocoaType) != ImageType::Invalid;
    131 }
    132 
    133 Vector<String> Pasteboard::typesTreatedAsFiles()
    134 {
    135     Vector<String> cocoaTypes;
    136     platformStrategies()->pasteboardStrategy()->getTypes(cocoaTypes, m_pasteboardName);
    137 
    138     // Enforce changeCount ourselves for security. We check after reading instead of before to be
    139     // sure it doesn't change between our testing the change count and accessing the data.
    140     if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName))
    141         return { };
    142 
    143     ListHashSet<String> result;
    144     for (auto& cocoaType : cocoaTypes) {
    145         if (auto* mimeType = imageTypeToMIMEType(cocoaTypeToImageType(cocoaType)))
    146             result.add(mimeType);
    147     }
    148 
    149     Vector<String> types;
    150     copyToVector(result, types);
    151     return types;
    152122}
    153123
     
    183153Vector<String> Pasteboard::typesForLegacyUnsafeBindings()
    184154{
     155    auto cocoaTypes = readTypesWithSecurityCheck();
     156    if (cocoaTypes.isEmpty())
     157        return cocoaTypes;
     158
     159    ListHashSet<String> result;
     160    for (auto& cocoaType : cocoaTypes)
     161        addHTMLClipboardTypesForCocoaType(result, cocoaType, m_pasteboardName);
     162
    185163    Vector<String> types;
    186     platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName);
    187 
    188     // Enforce changeCount ourselves for security. We check after reading instead of before to be
    189     // sure it doesn't change between our testing the change count and accessing the data.
    190     if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName))
    191         return { };
    192 
    193     ListHashSet<String> result;
    194     for (auto& cocoaType : types)
    195         addHTMLClipboardTypesForCocoaType(result, cocoaType, m_pasteboardName);
    196 
    197164    copyToVector(result, types);
    198165    return types;
    199166}
    200167
     168#if PLATFORM(MAC)
     169static Ref<SharedBuffer> convertTIFFToPNG(SharedBuffer& tiffBuffer)
     170{
     171    auto image = adoptNS([[NSBitmapImageRep alloc] initWithData: tiffBuffer.createNSData().get()]);
     172    NSData *pngData = [image representationUsingType:NSPNGFileType properties:@{ }];
     173    return SharedBuffer::create(pngData);
     174}
     175#endif
     176
    201177void Pasteboard::read(PasteboardFileReader& reader)
    202178{
    203     auto imageType = mimeTypeToImageType(reader.type);
    204     if (imageType == ImageType::Invalid)
     179    auto filenames = readFilenames();
     180    if (!filenames.isEmpty()) {
     181        for (auto& filename : filenames)
     182            reader.readFilename(filename);
    205183        return;
    206 
    207     String cocoaTypeToRead;
    208     String tiffCocoaTypeInPasteboard;
     184    }
     185
     186    auto cocoaTypes = readTypesWithSecurityCheck();
     187    HashSet<const char*> existingMIMEs;
     188    for (auto& cocoaType : cocoaTypes) {
     189        auto imageType = cocoaTypeToImageType(cocoaType);
     190        const char* mimeType = imageTypeToMIMEType(imageType);
     191        if (!mimeType)
     192            continue;
     193        if (!existingMIMEs.add(mimeType).isNewEntry)
     194            continue;
     195        auto buffer = readBufferForTypeWithSecurityCheck(cocoaType);
     196#if PLATFORM(MAC)
     197        if (buffer && imageType == ImageType::TIFF)
     198            buffer = convertTIFFToPNG(buffer.releaseNonNull());
     199#endif
     200        if (!buffer)
     201            continue;
     202        reader.readBuffer(imageTypeToFakeFilename(imageType), mimeType, buffer.releaseNonNull());
     203    }
     204}
     205
     206String Pasteboard::readString(const String& type)
     207{
     208    return readPlatformValueAsString(type, m_changeCount, m_pasteboardName);
     209}
     210
     211String Pasteboard::readStringInCustomData(const String& type)
     212{
     213    auto buffer = readBufferForTypeWithSecurityCheck(customWebKitPasteboardDataType);
     214    if (!buffer)
     215        return { };
     216
     217    // Enforce changeCount ourselves for security. We check after reading instead of before to be
     218    // sure it doesn't change between our testing the change count and accessing the data.
     219    if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName))
     220        return { };
     221
     222    return customDataFromSharedBuffer(*buffer).sameOriginCustomData.get(type);
     223}
     224
     225void Pasteboard::writeCustomData(const PasteboardCustomData& data)
     226{
     227    m_changeCount = platformStrategies()->pasteboardStrategy()->writeCustomData(data, m_pasteboardName);
     228}
     229
     230long Pasteboard::changeCount() const
     231{
     232    return platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName);
     233}
     234
     235Vector<String> Pasteboard::readTypesWithSecurityCheck()
     236{
    209237    Vector<String> cocoaTypes;
    210238    platformStrategies()->pasteboardStrategy()->getTypes(cocoaTypes, m_pasteboardName);
    211     for (auto& cocoaType : cocoaTypes) {
    212         auto imageTypeInPasteboard = cocoaTypeToImageType(cocoaType);
    213         if (imageTypeInPasteboard == imageType) {
    214             cocoaTypeToRead = cocoaType;
    215             break;
    216         }
    217         if (tiffCocoaTypeInPasteboard.isNull() && imageTypeInPasteboard == ImageType::TIFF)
    218             tiffCocoaTypeInPasteboard = cocoaType;
    219     }
    220 
    221     bool tiffWasTreatedAsPNGForWebCompatibility = imageType == ImageType::PNG && cocoaTypeToRead.isNull() && !tiffCocoaTypeInPasteboard.isNull();
    222     if (tiffWasTreatedAsPNGForWebCompatibility)
    223         cocoaTypeToRead = tiffCocoaTypeInPasteboard;
    224 
    225     RefPtr<SharedBuffer> buffer = platformStrategies()->pasteboardStrategy()->bufferForType(cocoaTypeToRead, m_pasteboardName);
    226 
    227     // Enforce changeCount ourselves for security. We check after reading instead of before to be
    228     // sure it doesn't change between our testing the change count and accessing the data.
    229     if (!buffer || m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName))
    230         return;
    231 
    232 #if PLATFORM(MAC)
    233     if (tiffWasTreatedAsPNGForWebCompatibility) {
    234         auto tiffData = buffer->createNSData();
    235         auto image = adoptNS([[NSBitmapImageRep alloc] initWithData: tiffData.get()]);
    236         NSData *pngData = [image representationUsingType:NSPNGFileType properties:@{ }];
    237         reader.read(imageTypeToFakeFilename(imageType), SharedBuffer::create(pngData));
    238         return;
    239     }
    240 #endif
    241     reader.read(imageTypeToFakeFilename(imageType), buffer.releaseNonNull());
    242 }
    243 
    244 String Pasteboard::readString(const String& type)
    245 {
    246     return readPlatformValueAsString(type, m_changeCount, m_pasteboardName);
    247 }
    248 
    249 String Pasteboard::readStringInCustomData(const String& type)
    250 {
    251     auto buffer = platformStrategies()->pasteboardStrategy()->bufferForType(customWebKitPasteboardDataType, m_pasteboardName);
    252     if (!buffer)
    253         return { };
    254 
    255     NSString *customDataValue = customDataFromSharedBuffer(*buffer).sameOriginCustomData.get(type);
    256     if (!customDataValue.length)
    257         return { };
    258     return customDataValue;
    259 }
    260 
    261 void Pasteboard::writeCustomData(const PasteboardCustomData& data)
    262 {
    263     m_changeCount = platformStrategies()->pasteboardStrategy()->writeCustomData(data, m_pasteboardName);
    264 }
    265 
    266 long Pasteboard::changeCount() const
    267 {
    268     return platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName);
    269 }
    270 
    271 }
    272 
     239
     240    // Enforce changeCount ourselves for security. We check after reading instead of before to be
     241    // sure it doesn't change between our testing the change count and accessing the data.
     242    if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName))
     243        return { };
     244
     245    return cocoaTypes;
     246}
     247
     248RefPtr<SharedBuffer> Pasteboard::readBufferForTypeWithSecurityCheck(const String& type)
     249{
     250    auto buffer = platformStrategies()->pasteboardStrategy()->bufferForType(type, m_pasteboardName);
     251
     252    // Enforce changeCount ourselves for security. We check after reading instead of before to be
     253    // sure it doesn't change between our testing the change count and accessing the data.
     254    if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName))
     255        return nullptr;
     256
     257    return buffer;
     258}
     259
     260}
  • trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp

    r222688 r222699  
    243243}
    244244
    245 void Pasteboard::read(PasteboardFileReader&)
    246 {
     245void Pasteboard::read(PasteboardFileReader& reader)
     246{
     247    readFromClipboard();
     248    for (auto& filename : m_selectionData->filenames())
     249        reader.readFilename(filename);
    247250}
    248251
     
    285288
    286289    return types;
    287 }
    288 
    289 Vector<String> Pasteboard::typesTreatedAsFiles()
    290 {
    291     return { };
    292290}
    293291
     
    322320bool Pasteboard::containsFiles()
    323321{
    324     return readFilenames().size();
    325 }
    326 
    327 Vector<String> Pasteboard::readFilenames()
    328 {
    329     readFromClipboard();
    330     return m_selectionData->filenames();
     322    readFromClipboard();
     323    return !m_selectionData->filenames().isEmpty();
    331324}
    332325
  • trunk/Source/WebCore/platform/win/PasteboardWin.cpp

    r222688 r222699  
    284284}
    285285
    286 Vector<String> Pasteboard::typesTreatedAsFiles()
    287 {
    288     return { };
    289 }
    290 
    291286String Pasteboard::readString(const String& type)
    292287{
     
    315310}
    316311
     312struct PasteboardFileCounter final : PasteboardFileReader {
     313    void readFilename(const String&) final { ++count; }
     314    void readBuffer(const String&, const String&, Ref<SharedBuffer>&&) final { ++count; }
     315
     316    unsigned count { 0 };
     317};
     318
    317319bool Pasteboard::containsFiles()
    318320{
    319     return readFilenames().size(); // FIXME: Make this code more efficient.
    320 }
    321 
    322 Vector<String> Pasteboard::readFilenames()
    323 {
    324     Vector<String> fileNames;
    325 
     321    // FIXME: This implementation can be slightly more efficient by avoiding calls to DragQueryFileW.
     322    PasteboardFileCounter reader;
     323    read(reader);
     324    return reader.count;
     325}
     326
     327void Pasteboard::read(PasteboardFileReader& reader)
     328{
    326329#if USE(CF)
    327330    if (m_dataObject) {
    328331        STGMEDIUM medium;
    329332        if (FAILED(m_dataObject->GetData(cfHDropFormat(), &medium)))
    330             return fileNames;
     333            return;
    331334
    332335        HDROP hdrop = reinterpret_cast<HDROP>(GlobalLock(medium.hGlobal));
    333336        if (!hdrop)
    334             return fileNames;
     337            return;
    335338
    336339        WCHAR filename[MAX_PATH];
     
    339342            if (!DragQueryFileW(hdrop, i, filename, WTF_ARRAY_LENGTH(filename)))
    340343                continue;
    341             fileNames.append(filename);
     344            reader.readFilename(filename);
    342345        }
    343346
    344347        GlobalUnlock(medium.hGlobal);
    345348        ReleaseStgMedium(&medium);
    346         return fileNames;
    347     }
    348     if (!m_dragDataMap.contains(cfHDropFormat()->cfFormat))
    349         return fileNames;
    350     return m_dragDataMap.get(cfHDropFormat()->cfFormat);
     349        return;
     350    }
     351    auto list = m_dragDataMap.find(cfHDropFormat()->cfFormat);
     352    if (list == m_dragDataMap.end())
     353        return;
     354
     355    for (auto& filename : list->value)
     356        reader.readFilename(filename);
    351357#else
    352358    notImplemented();
    353     return fileNames;
     359    return { };
    354360#endif
    355361}
     
    10731079}
    10741080
    1075 void Pasteboard::read(PasteboardFileReader&)
    1076 {
    1077 }
    1078 
    10791081void Pasteboard::write(const PasteboardImage&)
    10801082{
  • trunk/Source/WebCore/platform/wpe/PasteboardWPE.cpp

    r222688 r222699  
    6161    platformStrategies()->pasteboardStrategy()->getTypes(types);
    6262    return types;
    63 }
    64 
    65 Vector<String> Pasteboard::typesTreatedAsFiles()
    66 {
    67     return { };
    6863}
    6964
     
    131126}
    132127
    133 Vector<String> Pasteboard::readFilenames()
    134 {
    135     notImplemented();
    136     return Vector<String>();
    137 }
    138 
    139128bool Pasteboard::canSmartReplace()
    140129{
Note: See TracChangeset for help on using the changeset viewer.