Changeset 45168 in webkit


Ignore:
Timestamp:
Jun 25, 2009 2:24:33 AM (15 years ago)
Author:
eric@webkit.org
Message:

2009-06-24 Dan Bernstein <mitz@apple.com>

Reviewed by Simon Fraser.

  • test for <rdar://problem/7001817> REGRESSION (r41902): Base position track at UCSC Genome Browser doesn't work because image map prevents img from hit-testing
  • fast/replaced/image-map-2-expected.txt: Added.
  • fast/replaced/image-map-2.html: Added.

2009-05-21 Eric Seidel <eric@webkit.org>

Reviewed by Maciej Stachowiak.

Expose files in the clipboard in ondrop events
https://bugs.webkit.org/show_bug.cgi?id=25916

Make it possible for applications like gmail to implement
drag and drop of attachments onto email messages.

This patch exposes an event.dataTransfer.files accessor
on the drop event. No information is exposed during dragover.
This follows the HTML 5 drag and drop security model:
http://www.w3.org/TR/html5/editing.html#security-risks-in-the-drag-and-drop-model
The test http/tests/security/clipboard/clipboard-file-access.html
verifies this behavior.

Internet Explorer shows historical documentation of supporting
getData('File') as a way of exposing files on the pasteboard. The current version of their docs:
http://msdn.microsoft.com/en-us/library/ms537658(VS.85).aspx
has removed this reference (as far as I can tell IE never implemented it)
I have a printed copy of that URL from 2008 on my desk describing getData('File') in IE.
IE does not follow the HTML5 clipboard security model and always allows access to the full clipboard, even on dragover.

I choose not to use IE's getData('File') and instead added .files
so that the accessor could have a type, matching WebKit's existing
.files accessor on HTMLInputElement.

Mozilla has equivalent file access:
event.dataTransfer.mozGetDataAt("application/x-moz-file", 0);
which also does not return a typed value.
https://developer.mozilla.org/En/DragDrop/Recommended_Drag_Types#Dragging_Files

This is only implemented for Mac WebKit. All other platforms (including Apple's Win WebKit)
have incomplete Clipboard implementations and will require experts from those platforms
to add this functionality. Right now they all have Clipboard*::files() methods which call notImplemented();

Test: http/tests/security/clipboard/clipboard-file-access.html

  • dom/Clipboard.h:
  • dom/Clipboard.idl:
  • platform/chromium/ClipboardChromium.cpp: (WebCore::ClipboardChromium::files):
  • platform/chromium/ClipboardChromium.h:
  • platform/gtk/ClipboardGtk.cpp: (WebCore::ClipboardGtk::files):
  • platform/gtk/ClipboardGtk.h:
  • platform/mac/ClipboardMac.h:
  • platform/mac/ClipboardMac.mm: (WebCore::absoluteURLsFromPasteboardFilenames): (WebCore::absoluteURLsFromPasteboard): (WebCore::ClipboardMac::files):
  • platform/qt/ClipboardQt.cpp: (WebCore::ClipboardQt::files):
  • platform/qt/ClipboardQt.h:
  • platform/win/ClipboardWin.cpp: (WebCore::ClipboardWin::files):
  • platform/win/ClipboardWin.h:
  • platform/wx/ClipboardWx.cpp: (WebCore::ClipboardWx::files):
  • platform/wx/ClipboardWx.h:
Location:
trunk
Files:
8 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r45143 r45168  
    427427        * fast/dom/resources/event-attribute-availability.js:
    428428
     4292009-05-21  Eric Seidel  <eric@webkit.org>
     430
     431        Reviewed by Maciej Stachowiak.
     432
     433        Expose files in the clipboard in ondrop events.
     434        https://bugs.webkit.org/show_bug.cgi?id=25916
     435
     436        File.fileSize subtests fail due to limitations of DRT during http tests:
     437        https://bugs.webkit.org/show_bug.cgi?id=25909
     438
     439        Directory subtests fail until correct of directory File tests is decided by:
     440        https://bugs.webkit.org/show_bug.cgi?id=25879
     441
     442        * http/tests/security/clipboard/clipboard-file-access-expected.txt: Added.
     443        * http/tests/security/clipboard/clipboard-file-access.html: Added.
     444        * http/tests/security/clipboard/resources/TEMPLATE.html: Added.
     445        * http/tests/security/clipboard/resources/apple.gif: Copied from LayoutTests/editing/pasteboard/resources/apple.gif.
     446        * http/tests/security/clipboard/resources/clipboard-file-access.js: Added.
     447        (var):
     448        (moveMouseToCenterOfElement):
     449        (dragFilesOntoDragTarget):
     450        (fileListShouldBe):
     451        (draggingPathsShouldResultInFiles):
     452        (runTest):
     453        * http/tests/security/clipboard/resources/mozilla.gif: Copied from LayoutTests/editing/pasteboard/resources/mozilla.gif.
     454
    4294552009-06-22  David Levin  <levin@chromium.org>
    430456
  • trunk/WebCore/ChangeLog

    r45165 r45168  
     12009-05-21  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Maciej Stachowiak.
     4
     5        Expose files in the clipboard in ondrop events
     6        https://bugs.webkit.org/show_bug.cgi?id=25916
     7
     8        Make it possible for applications like gmail to implement
     9        drag and drop of attachments onto email messages.
     10
     11        This patch exposes an event.dataTransfer.files accessor
     12        on the drop event.  No information is exposed during dragover.
     13        This follows the HTML 5 drag and drop security model:
     14        http://www.w3.org/TR/html5/editing.html#security-risks-in-the-drag-and-drop-model
     15        The test http/tests/security/clipboard/clipboard-file-access.html
     16        verifies this behavior.
     17
     18        Internet Explorer shows historical documentation of supporting
     19        getData('File') as a way of exposing files on the pasteboard.  The current version of their docs:
     20        http://msdn.microsoft.com/en-us/library/ms537658(VS.85).aspx
     21        has removed this reference (as far as I can tell IE never implemented it)
     22        I have a printed copy of that URL from 2008 on my desk describing getData('File') in IE.
     23        IE does not follow the HTML5 clipboard security model and always allows access to the full clipboard, even on dragover.
     24
     25        I choose not to use IE's getData('File') and instead added .files
     26        so that the accessor could have a type, matching WebKit's existing
     27        .files accessor on HTMLInputElement.
     28
     29        Mozilla has equivalent file access:
     30        event.dataTransfer.mozGetDataAt("application/x-moz-file", 0);
     31        which also does not return a typed value.
     32        https://developer.mozilla.org/En/DragDrop/Recommended_Drag_Types#Dragging_Files
     33
     34        This is only implemented for Mac WebKit.  All other platforms (including Apple's Win WebKit)
     35        have incomplete Clipboard implementations and will require experts from those platforms
     36        to add this functionality.  Right now they all have Clipboard*::files() methods which call notImplemented();
     37
     38        Test: http/tests/security/clipboard/clipboard-file-access.html
     39
     40        * dom/Clipboard.h:
     41        * dom/Clipboard.idl:
     42        * platform/chromium/ClipboardChromium.cpp:
     43        (WebCore::ClipboardChromium::files):
     44        * platform/chromium/ClipboardChromium.h:
     45        * platform/gtk/ClipboardGtk.cpp:
     46        (WebCore::ClipboardGtk::files):
     47        * platform/gtk/ClipboardGtk.h:
     48        * platform/mac/ClipboardMac.h:
     49        * platform/mac/ClipboardMac.mm:
     50        (WebCore::absoluteURLsFromPasteboardFilenames):
     51        (WebCore::absoluteURLsFromPasteboard):
     52        (WebCore::ClipboardMac::files):
     53        * platform/qt/ClipboardQt.cpp:
     54        (WebCore::ClipboardQt::files):
     55        * platform/qt/ClipboardQt.h:
     56        * platform/win/ClipboardWin.cpp:
     57        (WebCore::ClipboardWin::files):
     58        * platform/win/ClipboardWin.h:
     59        * platform/wx/ClipboardWx.cpp:
     60        (WebCore::ClipboardWx::files):
     61        * platform/wx/ClipboardWx.h:
     62
    1632009-06-25  Eric Seidel  <eric@webkit.org>
    264
  • trunk/WebCore/dom/Clipboard.h

    r45087 r45168  
    3434namespace WebCore {
    3535
     36    class FileList;
     37
    3638    // State available during IE's events for drag and drop and copy/paste
    3739    class Clipboard : public RefCounted<Clipboard> {
     
    5456        // extensions beyond IE's API
    5557        virtual HashSet<String> types() const = 0;
    56    
     58        virtual PassRefPtr<FileList> files() const = 0;
     59
    5760        IntPoint dragLocation() const { return m_dragLoc; }
    5861        CachedImage* dragImage() const { return m_dragImage.get(); }
  • trunk/WebCore/dom/Clipboard.idl

    r30735 r45168  
    3535                 attribute [ConvertNullStringTo=Undefined] DOMString effectAllowed;
    3636        readonly attribute [CustomGetter] Array types;
     37        readonly attribute FileList files;
    3738
    3839        [Custom] void clearData(in [Optional] DOMString type)
  • trunk/WebCore/platform/chromium/ClipboardChromium.cpp

    r42156 r45168  
    176176}
    177177
     178PassRefPtr<FileList> ClipboardChromium::files() const
     179{
     180    notImplemented();
     181    return 0;
     182}
     183
    178184void ClipboardChromium::setDragImage(CachedImage* image, Node* node, const IntPoint& loc)
    179185{
  • trunk/WebCore/platform/chromium/ClipboardChromium.h

    r43335 r45168  
    6060
    6161        // extensions beyond IE's API
    62         HashSet<String> types() const;
     62        virtual HashSet<String> types() const;
     63        virtual PassRefPtr<FileList> files() const;
    6364
    6465        void setDragImage(CachedImage*, const IntPoint&);
  • trunk/WebCore/platform/gtk/ClipboardGtk.cpp

    r34544 r45168  
    7070}
    7171
     72PassRefPtr<FileList> ClipboardGtk::files() const
     73{
     74    notImplemented();
     75    return 0;
     76}
     77
    7278IntPoint ClipboardGtk::dragLocation() const
    7379{
  • trunk/WebCore/platform/gtk/ClipboardGtk.h

    r34544 r45168  
    4848        bool setData(const String&, const String&);
    4949
    50         HashSet<String> types() const;
     50        virtual HashSet<String> types() const;
     51        virtual PassRefPtr<FileList> files() const;
     52
    5153        IntPoint dragLocation() const;
    5254        CachedImage* dragImage() const;
  • trunk/WebCore/platform/mac/ClipboardMac.h

    r34544 r45168  
    4242
    4343class Frame;
     44class FileList;
    4445
    4546class ClipboardMac : public Clipboard, public CachedResourceClient {
     
    6162    // extensions beyond IE's API
    6263    virtual HashSet<String> types() const;
     64    virtual PassRefPtr<FileList> files() const;
    6365
    6466    void setDragImage(CachedImage*, const IntPoint&);
  • trunk/WebCore/platform/mac/ClipboardMac.mm

    r43852 r45168  
    3232#import "Editor.h"
    3333#import "FoundationExtras.h"
     34#import "FileList.h"
    3435#import "Frame.h"
    3536#import "Image.h"
     
    140141}
    141142
    142 static NSArray *absoluteURLsFromPasteboardFilenames(NSPasteboard* pasteboard, bool onlyFirstURL)
     143static NSArray *absoluteURLsFromPasteboardFilenames(NSPasteboard* pasteboard, bool onlyFirstURL = false)
    143144{
    144145    NSArray *fileList = [pasteboard propertyListForType:NSFilenamesPboardType];
     
    164165}
    165166
    166 static NSArray *absoluteURLsFromPasteboard(NSPasteboard* pasteboard, bool onlyFirstURL)
     167static NSArray *absoluteURLsFromPasteboard(NSPasteboard* pasteboard, bool onlyFirstURL = false)
    167168{
    168169    // NOTE: We must always check [availableTypes containsObject:] before accessing pasteboard data
     
    273274    }
    274275    return result;
     276}
     277
     278// FIXME: We could cache the computed fileList if necessary
     279// Currently each access gets a new copy, setData() modifications to the
     280// clipboard are not reflected in any FileList objects the page has accessed and stored
     281PassRefPtr<FileList> ClipboardMac::files() const
     282{
     283    if (policy() != ClipboardReadable)
     284        return FileList::create();
     285
     286    NSArray *absoluteURLs = absoluteURLsFromPasteboard(m_pasteboard.get());
     287    NSUInteger count = [absoluteURLs count];
     288
     289    RefPtr<FileList> fileList = FileList::create();
     290    for (NSUInteger x = 0; x < count; x++) {
     291        NSURL *absoluteURL = [NSURL URLWithString:[absoluteURLs objectAtIndex:x]];
     292        ASSERT([absoluteURL isFileURL]);
     293        fileList->append(File::create([absoluteURL path]));
     294    }
     295    return fileList.release(); // We will always return a FileList, sometimes empty
    275296}
    276297
  • trunk/WebCore/platform/qt/ClipboardQt.cpp

    r44802 r45168  
    179179}
    180180
     181PassRefPtr<FileList> ClipboardQt::files() const
     182{
     183    notImplemented();
     184    return 0;
     185}
     186
    181187void ClipboardQt::setDragImage(CachedImage* image, const IntPoint& point)
    182188{
  • trunk/WebCore/platform/qt/ClipboardQt.h

    r34544 r45168  
    5757   
    5858        // extensions beyond IE's API
    59         HashSet<String> types() const;
    60    
     59        virtual HashSet<String> types() const;
     60        virtual PassRefPtr<FileList> files() const;
     61
    6162        void setDragImage(CachedImage*, const IntPoint&);
    6263        void setDragImageElement(Node*, const IntPoint&);
  • trunk/WebCore/platform/win/ClipboardWin.cpp

    r45087 r45168  
    581581}
    582582
     583PassRefPtr<FileList> ClipboardWin::files() const
     584{
     585    notImplemented();
     586    return 0;
     587}
     588
    583589void ClipboardWin::setDragImage(CachedImage* image, Node *node, const IntPoint &loc)
    584590{
  • trunk/WebCore/platform/win/ClipboardWin.h

    r44995 r45168  
    5858   
    5959        // extensions beyond IE's API
    60         HashSet<String> types() const;
     60        virtual HashSet<String> types() const;
     61        virtual PassRefPtr<FileList> files() const;
    6162   
    6263        void setDragImage(CachedImage*, const IntPoint&);
  • trunk/WebCore/platform/wx/ClipboardWx.cpp

    r29663 r45168  
    7171}
    7272
     73PassRefPtr<FileList> ClipboardWx::files() const
     74{
     75    notImplemented();
     76    return 0;
     77}
     78
    7379IntPoint ClipboardWx::dragLocation() const
    7480{
  • trunk/WebCore/platform/wx/ClipboardWx.h

    r34544 r45168  
    4747   
    4848        // extensions beyond IE's API
    49         HashSet<String> types() const;
     49        virtual HashSet<String> types() const;
     50        virtual PassRefPtr<FileList> files() const;
    5051   
    5152        IntPoint dragLocation() const;
Note: See TracChangeset for help on using the changeset viewer.