Changeset 181760 in webkit


Ignore:
Timestamp:
Mar 19, 2015 2:59:23 PM (9 years ago)
Author:
enrica@apple.com
Message:

<attachment> should put URLs on the pasteboard so that Finder can accept drops.
https://bugs.webkit.org/show_bug.cgi?id=142801
rdar://problem/19982527

Reviewed by Tim Horton.

Source/WebCore:

Test: editing/pasteboard/drag-and-drop-attachment-contenteditable.html

This patch adds all the necessary support to write attachment elements into
the pasteboard, including the promised type.

  • WebCore.xcodeproj/project.pbxproj:
  • page/DragActions.h:
  • page/DragClient.h:

(WebCore::DragClient::declareAndWriteAttachment):

  • page/DragController.cpp:

(WebCore::DragController::draggableElement):
(WebCore::DragController::startDrag):

  • page/DragController.h:

(WebCore::DragController::draggingAttachmentURL):

  • page/EventHandler.cpp:

(WebCore::EventHandler::dragHysteresisExceeded):
(WebCore::EventHandler::handleDrag):

  • page/mac/DragControllerMac.mm:

(WebCore::DragController::declareAndWriteAttachment):

  • page/win/DragControllerWin.cpp:

(WebCore::DragController::declareAndWriteAttachment):

  • platform/URL.cpp:

(WebCore::URL::fileURLWithFileSystemPath):

  • platform/URL.h:
  • rendering/HitTestResult.cpp:

(WebCore::HitTestResult::absoluteAttachmentURL):

  • rendering/HitTestResult.h:

Source/WebKit/mac:

This patch adds all the necessary support to write attachment elements into
the pasteboard, including the promised type in WK1.

  • Misc/WebNSPasteboardExtras.mm:

(-[NSPasteboard _web_declareAndWriteDragImageForElement:URL:title:archive:source:]):

  • WebCoreSupport/WebDragClient.h:
  • WebCoreSupport/WebDragClient.mm:

(WebDragClient::declareAndWriteAttachment):

  • WebView/WebHTMLView.mm:

(-[WebHTMLView namesOfPromisedFilesDroppedAtDestination:]):

  • WebView/WebUIDelegate.h:

Source/WebKit2:

This patch adds all the necessary support to write attachment elements into
the pasteboard, including the promised type in WK2.

  • UIProcess/API/mac/WKView.mm:

(-[WKView _setPromisedDataForImage:withFileName:withExtension:withTitle:withURL:withVisibleURL:withArchive:forPasteboard:]):
(-[WKView _setPromisedDataForAttachment:withExtension:withTitle:withURL:withVisibleURL:forPasteboard:]):
(-[WKView namesOfPromisedFilesDroppedAtDestination:]):
(-[WKView _setPromisedData:withFileName:withExtension:withTitle:withURL:withVisibleURL:withArchive:forPasteboard:]): Deleted.

  • UIProcess/API/mac/WKViewInternal.h:
  • UIProcess/PageClient.h:
  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • UIProcess/mac/PageClientImpl.h:
  • UIProcess/mac/PageClientImpl.mm:

(WebKit::PageClientImpl::setPromisedDataForImage):
(WebKit::PageClientImpl::setPromisedDataForAttachment):
(WebKit::PageClientImpl::setPromisedData): Deleted.

  • UIProcess/mac/WebPageProxyMac.mm:

(WebKit::WebPageProxy::setPromisedDataForImage):
(WebKit::WebPageProxy::setPromisedDataForAttachment):
(WebKit::WebPageProxy::setPromisedData): Deleted.

  • WebProcess/WebCoreSupport/WebDragClient.h:
  • WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:

(WebKit::WebDragClient::declareAndWriteAttachment):
(WebKit::WebDragClient::declareAndWriteDragImage):

LayoutTests:

  • editing/pasteboard/drag-and-drop-attachment-contenteditable-expected.txt: Added.
  • editing/pasteboard/drag-and-drop-attachment-contenteditable.html: Added.
  • platform/mac-wk2/TestExpectations: Skipping new test on WK2 since it uses eventSender.
Location:
trunk
Files:
2 added
32 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r181749 r181760  
     12015-03-19  Enrica Casucci  <enrica@apple.com>
     2
     3        <attachment> should put URLs on the pasteboard so that Finder can accept drops.
     4        https://bugs.webkit.org/show_bug.cgi?id=142801
     5        rdar://problem/19982527
     6
     7        Reviewed by Tim Horton.
     8
     9        * editing/pasteboard/drag-and-drop-attachment-contenteditable-expected.txt: Added.
     10        * editing/pasteboard/drag-and-drop-attachment-contenteditable.html: Added.
     11        * platform/mac-wk2/TestExpectations: Skipping new test on WK2 since it uses eventSender.
     12
    1132015-03-19  Dean Jackson  <dino@apple.com>
    214
     
    123135        * fast/repaint/multiple-backgrounds-style-change.html: Added.
    124136
     137>>>>>>> .r181712
    1251382015-03-18  Marcos Chavarría Teijeiro  <chavarria1991@gmail.com>
    126139
  • trunk/LayoutTests/platform/mac-wk2/TestExpectations

    r181684 r181760  
    2424editing/pasteboard/drag-and-drop-inputimage-contenteditable.html
    2525editing/pasteboard/drag-and-drop-objectimage-contenteditable.html
     26editing/pasteboard/drag-and-drop-attachment-contenteditable.html
    2627editing/pasteboard/drag-drop-dead-frame.html
    2728editing/pasteboard/drag-drop-input-textarea.html
  • trunk/Source/WebCore/ChangeLog

    r181757 r181760  
     12015-03-19  Enrica Casucci  <enrica@apple.com>
     2
     3        <attachment> should put URLs on the pasteboard so that Finder can accept drops.
     4        https://bugs.webkit.org/show_bug.cgi?id=142801
     5        rdar://problem/19982527
     6
     7        Reviewed by Tim Horton.
     8
     9        Test: editing/pasteboard/drag-and-drop-attachment-contenteditable.html
     10
     11        This patch adds all the necessary support to write attachment elements into
     12        the pasteboard, including the promised type.
     13
     14        * WebCore.xcodeproj/project.pbxproj:
     15        * page/DragActions.h:
     16        * page/DragClient.h:
     17        (WebCore::DragClient::declareAndWriteAttachment):
     18        * page/DragController.cpp:
     19        (WebCore::DragController::draggableElement):
     20        (WebCore::DragController::startDrag):
     21        * page/DragController.h:
     22        (WebCore::DragController::draggingAttachmentURL):
     23        * page/EventHandler.cpp:
     24        (WebCore::EventHandler::dragHysteresisExceeded):
     25        (WebCore::EventHandler::handleDrag):
     26        * page/mac/DragControllerMac.mm:
     27        (WebCore::DragController::declareAndWriteAttachment):
     28        * page/win/DragControllerWin.cpp:
     29        (WebCore::DragController::declareAndWriteAttachment):
     30        * platform/URL.cpp:
     31        (WebCore::URL::fileURLWithFileSystemPath):
     32        * platform/URL.h:
     33        * rendering/HitTestResult.cpp:
     34        (WebCore::HitTestResult::absoluteAttachmentURL):
     35        * rendering/HitTestResult.h:
     36
    1372015-03-19  Chris Dumez  <cdumez@apple.com>
    238
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r181726 r181760  
    25282528                7CC7E3D717208C0F003C5277 /* IDNScriptWhiteList.txt in Resources */ = {isa = PBXBuildFile; fileRef = 7CC7E3D617208C0F003C5277 /* IDNScriptWhiteList.txt */; };
    25292529                7CD494CC1A86EB1D000A87EC /* RenderAttachment.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CD494CA1A86EB1D000A87EC /* RenderAttachment.cpp */; };
    2530                 7CD494CD1A86EB1D000A87EC /* RenderAttachment.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD494CB1A86EB1D000A87EC /* RenderAttachment.h */; };
     2530                7CD494CD1A86EB1D000A87EC /* RenderAttachment.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD494CB1A86EB1D000A87EC /* RenderAttachment.h */; settings = {ATTRIBUTES = (Private, ); }; };
    25312531                7CDEEE1E197610D700E352CD /* ViewStateChangeObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CDEEE1D197610D700E352CD /* ViewStateChangeObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
    25322532                7CE68344192143A800F4D928 /* UserMessageHandlerDescriptor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CE68342192143A800F4D928 /* UserMessageHandlerDescriptor.cpp */; };
  • trunk/Source/WebCore/page/DragActions.h

    r165676 r181760  
    4747        DragSourceActionLink         = 4,
    4848        DragSourceActionSelection    = 8,
     49#if ENABLE(ATTACHMENT_ELEMENT)
     50        DragSourceActionAttachment   = 16,
     51#endif
    4952        DragSourceActionAny          = UINT_MAX
    5053    } DragSourceAction;
  • trunk/Source/WebCore/page/DragClient.h

    r166965 r181760  
    5656    // This is not abstract as that would require another #if PLATFORM(COCOA) for the SVGImage client empty implentation.
    5757    virtual void declareAndWriteDragImage(const String&, Element&, const URL&, const String&, Frame*) { }
     58#if ENABLE(ATTACHMENT_ELEMENT)
     59    virtual void declareAndWriteAttachment(const String&, Element&, const URL&, const String&, Frame*) { }
     60#endif
    5861#endif
    5962
  • trunk/Source/WebCore/page/DragController.cpp

    r181115 r181760  
    5050#include "FrameView.h"
    5151#include "HTMLAnchorElement.h"
     52#include "HTMLAttachmentElement.h"
    5253#include "HTMLImageElement.h"
    5354#include "HTMLInputElement.h"
     
    624625    if (!startElement)
    625626        return nullptr;
     627#if ENABLE(ATTACHMENT_ELEMENT)
     628    // Unlike image elements, attachment elements are immediately selected upon mouse down,
     629    // but for those elements we still want to use the single element drag behavior as long as
     630    // the element is the only content of the selection.
     631    const VisibleSelection& selection = sourceFrame->selection().selection();
     632    if (selection.isRange() && is<HTMLAttachmentElement>(selection.start().anchorNode()) && selection.start().anchorNode() == selection.end().anchorNode())
     633        state.type = DragSourceActionNone;
     634#endif
    626635
    627636    for (auto renderer = startElement->renderer(); renderer; renderer = renderer->parent()) {
     
    650659                return element;
    651660            }
     661#if ENABLE(ATTACHMENT_ELEMENT)
     662            if ((m_dragSourceAction & DragSourceActionAttachment)
     663                && is<HTMLAttachmentElement>(*element)
     664                && downcast<HTMLAttachmentElement>(*element).file()) {
     665                state.type = static_cast<DragSourceAction>(state.type | DragSourceActionAttachment);
     666                return element;
     667            }
     668#endif
    652669        }
    653670    }
     
    739756    URL linkURL = hitTestResult.absoluteLinkURL();
    740757    URL imageURL = hitTestResult.absoluteImageURL();
     758#if ENABLE(ATTACHMENT_ELEMENT)
     759    URL attachmentURL = hitTestResult.absoluteAttachmentURL();
     760    m_draggingAttachmentURL = URL();
     761#endif
    741762
    742763    IntPoint mouseDraggedPoint = src.view()->windowToContents(dragEvent.position());
     
    854875        }
    855876        doSystemDrag(dragImage, dragLoc, mouseDraggedPoint, dataTransfer, src, true);
     877#if ENABLE(ATTACHMENT_ELEMENT)
     878    } else if (!attachmentURL.isEmpty() && (m_dragSourceAction & DragSourceActionAttachment)) {
     879        if (!dataTransfer.pasteboard().hasData()) {
     880            m_draggingAttachmentURL = attachmentURL;
     881            selectElement(element);
     882            declareAndWriteAttachment(dataTransfer, element, attachmentURL);
     883        }
     884       
     885        m_client.willPerformDragSourceAction(DragSourceActionAttachment, dragOrigin, dataTransfer);
     886       
     887        if (!dragImage) {
     888            dragImage = dissolveDragImageToFraction(createDragImageForSelection(src), DragImageAlpha);
     889            dragLoc = dragLocForSelectionDrag(src);
     890            m_dragOffset = IntPoint(dragOrigin.x() - dragLoc.x(), dragOrigin.y() - dragLoc.y());
     891        }
     892        doSystemDrag(dragImage, dragLoc, dragOrigin, dataTransfer, src, false);
     893#endif
    856894    } else if (state.type == DragSourceActionDHTML) {
    857895        if (dragImage) {
  • trunk/Source/WebCore/page/DragController.h

    r181115 r181760  
    7474        DragOperation sourceDragOperation() const { return m_sourceDragOperation; }
    7575        const URL& draggingImageURL() const { return m_draggingImageURL; }
     76#if ENABLE(ATTACHMENT_ELEMENT)
     77        const URL& draggingAttachmentURL() const { return m_draggingAttachmentURL; }
     78#endif
    7679        void setDragOffset(const IntPoint& offset) { m_dragOffset = offset; }
    7780        const IntPoint& dragOffset() const { return m_dragOffset; }
     
    115118        void cleanupAfterSystemDrag();
    116119        void declareAndWriteDragImage(DataTransfer&, Element&, const URL&, const String& label);
    117 
     120#if ENABLE(ATTACHMENT_ELEMENT)
     121        void declareAndWriteAttachment(DataTransfer&, Element&, const URL&);
     122#endif
    118123        Page& m_page;
    119124        DragClient& m_client;
     
    131136        IntPoint m_dragOffset;
    132137        URL m_draggingImageURL;
     138#if ENABLE(ATTACHMENT_ELEMENT)
     139        URL m_draggingAttachmentURL;
     140#endif
    133141    };
    134142
  • trunk/Source/WebCore/page/EventHandler.cpp

    r181687 r181760  
    33093309        break;
    33103310    case DragSourceActionImage:
     3311#if ENABLE(ATTACHMENT_ELEMENT)
     3312    case DragSourceActionAttachment:
     3313#endif
    33113314        threshold = ImageDragHysteresis;
    33123315        break;
     
    34313434        ASSERT((dragState().type & ~DragSourceActionSelection) == DragSourceActionDHTML
    34323435            || (dragState().type & ~DragSourceActionSelection) == DragSourceActionImage
     3436#if ENABLE(ATTACHMENT_ELEMENT)
     3437            || (dragState().type & ~DragSourceActionSelection) == DragSourceActionAttachment
     3438#endif
    34333439            || (dragState().type & ~DragSourceActionSelection) == DragSourceActionLink);
    34343440        dragState().type = DragSourceActionSelection;
  • trunk/Source/WebCore/page/mac/DragControllerMac.mm

    r174314 r181760  
    3737#import "EditorClient.h"
    3838#import "Element.h"
     39#import "File.h"
    3940#import "FrameView.h"
     41#import "HTMLAttachmentElement.h"
    4042#import "MainFrame.h"
    4143#import "Page.h"
     
    8890}
    8991
     92#if ENABLE(ATTACHMENT_ELEMENT)
     93void DragController::declareAndWriteAttachment(DataTransfer& dataTransfer, Element& element, const URL& url)
     94{
     95    const HTMLAttachmentElement& attachment = downcast<HTMLAttachmentElement>(element);
     96    m_client.declareAndWriteAttachment(dataTransfer.pasteboard().name(), element, url, attachment.file()->path(), element.document().frame());
     97}
     98#endif
     99   
    90100void DragController::declareAndWriteDragImage(DataTransfer& dataTransfer, Element& element, const URL& url, const String& label)
    91101{
  • trunk/Source/WebCore/page/win/DragControllerWin.cpp

    r174314 r181760  
    7070}
    7171
     72#if ENABLE(ATTACHMENT_ELEMENT)
     73void DragController::declareAndWriteAttachment(DataTransfer&, Element&, const URL&)
     74{
     75}
     76#endif
     77
    7278void DragController::declareAndWriteDragImage(DataTransfer& dataTransfer, Element& element, const URL& url, const String& label)
    7379{
  • trunk/Source/WebCore/platform/URL.cpp

    r179933 r181760  
    21202120}
    21212121
    2122 }
     2122URL URL::fileURLWithFileSystemPath(const String& filePath)
     2123{
     2124    return URL(URL(), "file:///" + filePath);
     2125}
     2126
     2127}
  • trunk/Source/WebCore/platform/URL.h

    r180301 r181760  
    7474
    7575    static URL fakeURLWithRelativePart(const String&);
     76    static URL fileURLWithFileSystemPath(const String&);
    7677
    7778    String strippedForUseAsReferrer() const;
  • trunk/Source/WebCore/rendering/HitTestResult.cpp

    r176999 r181760  
    2626#include "DocumentMarkerController.h"
    2727#include "Editor.h"
     28#include "File.h"
    2829#include "Frame.h"
    2930#include "FrameSelection.h"
     
    3132#include "HTMLAnchorElement.h"
    3233#include "HTMLAreaElement.h"
     34#include "HTMLAttachmentElement.h"
    3335#include "HTMLAudioElement.h"
    3436#include "HTMLImageElement.h"
     
    311313}
    312314
     315#if ENABLE(ATTACHMENT_ELEMENT)
     316URL HitTestResult::absoluteAttachmentURL() const
     317{
     318    if (!m_innerNonSharedNode)
     319        return URL();
     320   
     321    if (!(m_innerNonSharedNode->renderer() && m_innerNonSharedNode->renderer()->isAttachment()))
     322        return URL();
     323   
     324    if (!is<HTMLAttachmentElement>(*m_innerNonSharedNode))
     325        return URL();
     326    File* attachmentFile = downcast<HTMLAttachmentElement>(*m_innerNonSharedNode).file();
     327    if (!attachmentFile)
     328        return URL();
     329   
     330    return URL::fileURLWithFileSystemPath(attachmentFile->path());
     331}
     332#endif
     333
    313334URL HitTestResult::absoluteImageURL() const
    314335{
  • trunk/Source/WebCore/rendering/HitTestResult.h

    r179861 r181760  
    107107    WEBCORE_EXPORT URL absoluteMediaURL() const;
    108108    WEBCORE_EXPORT URL absoluteLinkURL() const;
     109#if ENABLE(ATTACHMENT_ELEMENT)
     110    WEBCORE_EXPORT URL absoluteAttachmentURL() const;
     111#endif
    109112    WEBCORE_EXPORT String textContent() const;
    110113    WEBCORE_EXPORT bool isLiveLink() const;
  • trunk/Source/WebKit/mac/ChangeLog

    r181753 r181760  
     12015-03-19  Enrica Casucci  <enrica@apple.com>
     2
     3        <attachment> should put URLs on the pasteboard so that Finder can accept drops.
     4        https://bugs.webkit.org/show_bug.cgi?id=142801
     5        rdar://problem/19982527
     6
     7        Reviewed by Tim Horton.
     8
     9        This patch adds all the necessary support to write attachment elements into
     10        the pasteboard, including the promised type in WK1.
     11
     12        * Misc/WebNSPasteboardExtras.mm:
     13        (-[NSPasteboard _web_declareAndWriteDragImageForElement:URL:title:archive:source:]):
     14        * WebCoreSupport/WebDragClient.h:
     15        * WebCoreSupport/WebDragClient.mm:
     16        (WebDragClient::declareAndWriteAttachment):
     17        * WebView/WebHTMLView.mm:
     18        (-[WebHTMLView namesOfPromisedFilesDroppedAtDestination:]):
     19        * WebView/WebUIDelegate.h:
     20
    1212015-03-19  Chris Dumez  <cdumez@apple.com>
    222
  • trunk/Source/WebKit/mac/Misc/WebNSPasteboardExtras.mm

    r174676 r181760  
    4343#import <WebCore/Image.h>
    4444#import <WebCore/MIMETypeRegistry.h>
     45#import <WebCore/RenderAttachment.h>
    4546#import <WebCore/RenderImage.h>
    4647#import <WebKitLegacy/DOMExtensions.h>
     
    272273
    273274    NSString *extension = @"";
     275    RetainPtr<NSMutableArray> types = adoptNS([[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil]);
    274276    if (auto* renderer = core(element)->renderer()) {
    275277        if (is<RenderImage>(*renderer)) {
     
    278280                if (![extension length])
    279281                    return nullptr;
     282                [types addObjectsFromArray:[NSPasteboard _web_writableTypesForImageIncludingArchive:(archive != nil)]];
     283                [self declareTypes:types.get() owner:source];
    280284            }
    281285        }
    282     }
    283 
    284     NSMutableArray *types = [[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil];
    285     [types addObjectsFromArray:[NSPasteboard _web_writableTypesForImageIncludingArchive:(archive != nil)]];
    286     [self declareTypes:types owner:source];   
    287     [self _web_writeImage:nil element:element URL:URL title:title archive:archive types:types source:source];
    288     [types release];
     286#if ENABLE(ATTACHMENT_ELEMENT)
     287        else if (is<RenderAttachment>(*renderer)) {
     288            extension = URL.pathExtension;
     289            [types addObjectsFromArray:[NSPasteboard _web_dragTypesForURL]];
     290            [self declareTypes:types.get() owner:source];
     291            RetainPtr<NSMutableArray> paths = adoptNS([[NSMutableArray alloc] init]);
     292            [paths.get() addObject:title];
     293            [self setPropertyList:paths.get() forType:NSFilenamesPboardType];
     294        }
     295#endif
     296    }
     297
     298    [self _web_writeImage:nil element:element URL:URL title:title archive:archive types:types.get() source:source];
    289299
    290300    NSArray *extensions = [[NSArray alloc] initWithObjects:extension, nil];
  • trunk/Source/WebKit/mac/WebCoreSupport/WebDragClient.h

    r166965 r181760  
    4040    virtual void startDrag(WebCore::DragImageRef, const WebCore::IntPoint& dragPos, const WebCore::IntPoint& eventPos, WebCore::DataTransfer&, WebCore::Frame&, bool linkDrag) override;
    4141    virtual void declareAndWriteDragImage(const String& pasteboardName, WebCore::Element&, const WebCore::URL&, const String&, WebCore::Frame*) override;
     42#if ENABLE(ATTACHMENT_ELEMENT)
     43    virtual void declareAndWriteAttachment(const String& pasteboardName, WebCore::Element&, const WebCore::URL&, const String& path, WebCore::Frame*) override;
     44#endif
    4245private:
    4346    WebView* m_webView;
  • trunk/Source/WebKit/mac/WebCoreSupport/WebDragClient.mm

    r167403 r181760  
    128128{
    129129    ASSERT(pasteboardName);
    130     WebHTMLView *source = getTopHTMLView(frame);
    131     WebArchive *archive = [kit(&element) webArchive];
     130    [[NSPasteboard pasteboardWithName:pasteboardName] _web_declareAndWriteDragImageForElement:kit(&element) URL:url title:title archive:[kit(&element) webArchive] source:getTopHTMLView(frame)];
     131}
     132
     133#if ENABLE(ATTACHMENT_ELEMENT)
     134void WebDragClient::declareAndWriteAttachment(const String& pasteboardName, Element& element, const URL& url, const String& path, WebCore::Frame* frame)
     135{
     136    ASSERT(pasteboardName);
    132137   
    133     [[NSPasteboard pasteboardWithName:pasteboardName] _web_declareAndWriteDragImageForElement:kit(&element) URL:url title:title archive:archive source:source];
     138    [[NSPasteboard pasteboardWithName:pasteboardName] _web_declareAndWriteDragImageForElement:kit(&element) URL:url title:path archive:nil source:getTopHTMLView(frame)];
    134139}
     140#endif
    135141
    136142void WebDragClient::dragControllerDestroyed()
  • trunk/Source/WebKit/mac/WebView/WebHTMLView.mm

    r181679 r181760  
    39633963{
    39643964    NSFileWrapper *wrapper = nil;
    3965     NSURL *draggingImageURL = nil;
     3965    NSURL *draggingElementURL = nil;
    39663966   
    39673967    if (WebCore::CachedImage* tiffResource = [self promisedDragTIFFDataSource]) {
    39683968        if (auto* buffer = tiffResource->resourceBuffer()) {
    39693969            NSURLResponse *response = tiffResource->response().nsURLResponse();
    3970             draggingImageURL = [response URL];
     3970            draggingElementURL = [response URL];
    39713971            wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:buffer->createNSData().get()] autorelease];
    39723972            NSString* filename = [response suggestedFilename];
     
    39893989       
    39903990        const URL& imageURL = page->dragController().draggingImageURL();
    3991         ASSERT(!imageURL.isEmpty());
    3992         draggingImageURL = imageURL;
    3993 
    3994         wrapper = [[self _dataSource] _fileWrapperForURL:draggingImageURL];
     3991        if (!imageURL.isEmpty())
     3992            draggingElementURL = imageURL;
     3993#if ENABLE(ATTACHMENT_ELEMENT)
     3994        else
     3995            draggingElementURL = page->dragController().draggingAttachmentURL();
     3996#endif
     3997
     3998        wrapper = [[self _dataSource] _fileWrapperForURL:draggingElementURL];
    39953999    }
    39964000   
     
    40064010        LOG_ERROR("Failed to create image file via -[NSFileWrapper writeToURL:options:originalContentsURL:error:]");
    40074011   
    4008     if (draggingImageURL)
    4009         [[NSFileManager defaultManager] _webkit_setMetadataURL:[draggingImageURL absoluteString] referrer:nil atPath:path];
     4012    if (draggingElementURL)
     4013        [[NSFileManager defaultManager] _webkit_setMetadataURL:[draggingElementURL absoluteString] referrer:nil atPath:path];
    40104014   
    40114015    return [NSArray arrayWithObject:[path lastPathComponent]];
  • trunk/Source/WebKit/mac/WebView/WebUIDelegate.h

    r179183 r181760  
    113113    WebDragSourceActionLink         = 4,
    114114    WebDragSourceActionSelection    = 8,
     115    WebDragSourceActionAttachment   = 16,
    115116    WebDragSourceActionAny          = UINT_MAX
    116117};
  • trunk/Source/WebKit2/ChangeLog

    r181756 r181760  
     12015-03-19  Enrica Casucci  <enrica@apple.com>
     2
     3        <attachment> should put URLs on the pasteboard so that Finder can accept drops.
     4        https://bugs.webkit.org/show_bug.cgi?id=142801
     5        rdar://problem/19982527
     6
     7        Reviewed by Tim Horton.
     8
     9        This patch adds all the necessary support to write attachment elements into
     10        the pasteboard, including the promised type in WK2.
     11
     12        * UIProcess/API/mac/WKView.mm:
     13        (-[WKView _setPromisedDataForImage:withFileName:withExtension:withTitle:withURL:withVisibleURL:withArchive:forPasteboard:]):
     14        (-[WKView _setPromisedDataForAttachment:withExtension:withTitle:withURL:withVisibleURL:forPasteboard:]):
     15        (-[WKView namesOfPromisedFilesDroppedAtDestination:]):
     16        (-[WKView _setPromisedData:withFileName:withExtension:withTitle:withURL:withVisibleURL:withArchive:forPasteboard:]): Deleted.
     17        * UIProcess/API/mac/WKViewInternal.h:
     18        * UIProcess/PageClient.h:
     19        * UIProcess/WebPageProxy.h:
     20        * UIProcess/WebPageProxy.messages.in:
     21        * UIProcess/mac/PageClientImpl.h:
     22        * UIProcess/mac/PageClientImpl.mm:
     23        (WebKit::PageClientImpl::setPromisedDataForImage):
     24        (WebKit::PageClientImpl::setPromisedDataForAttachment):
     25        (WebKit::PageClientImpl::setPromisedData): Deleted.
     26        * UIProcess/mac/WebPageProxyMac.mm:
     27        (WebKit::WebPageProxy::setPromisedDataForImage):
     28        (WebKit::WebPageProxy::setPromisedDataForAttachment):
     29        (WebKit::WebPageProxy::setPromisedData): Deleted.
     30        * WebProcess/WebCoreSupport/WebDragClient.h:
     31        * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
     32        (WebKit::WebDragClient::declareAndWriteAttachment):
     33        (WebKit::WebDragClient::declareAndWriteDragImage):
     34
    1352015-03-19  Anders Carlsson  <andersca@apple.com>
    236
  • trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm

    r181705 r181760  
    33803380}
    33813381
    3382 - (void)_setPromisedData:(WebCore::Image *)image withFileName:(NSString *)filename withExtension:(NSString *)extension withTitle:(NSString *)title withURL:(NSString *)url withVisibleURL:(NSString *)visibleUrl withArchive:(WebCore::SharedBuffer*) archiveBuffer forPasteboard:(NSString *)pasteboardName
    3383 
    3384 {
    3385     NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:pasteboardName];
    3386     RetainPtr<NSMutableArray> types = adoptNS([[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil]);
    3387    
    3388     [types addObjectsFromArray:archiveBuffer ? PasteboardTypes::forImagesWithArchive() : PasteboardTypes::forImages()];
    3389     [pasteboard declareTypes:types.get() owner:self];
     3382- (void)_setFileAndURLTypes:(NSString *)filename withExtension:(NSString *)extension withTitle:(NSString *)title withURL:(NSString *)url withVisibleURL:(NSString *)visibleUrl forPasteboard:(NSPasteboard *)pasteboard
     3383{
    33903384    if (!matchesExtensionOrEquivalent(filename, extension))
    33913385        filename = [[filename stringByAppendingString:@"."] stringByAppendingString:extension];
    3392 
     3386   
    33933387    [pasteboard setString:visibleUrl forType:NSStringPboardType];
    33943388    [pasteboard setString:visibleUrl forType:PasteboardTypes::WebURLPboardType];
     
    33963390    [pasteboard setPropertyList:[NSArray arrayWithObjects:[NSArray arrayWithObject:visibleUrl], [NSArray arrayWithObject:title], nil] forType:PasteboardTypes::WebURLsWithTitlesPboardType];
    33973391    [pasteboard setPropertyList:[NSArray arrayWithObject:extension] forType:NSFilesPromisePboardType];
     3392    _data->_promisedFilename = filename;
     3393    _data->_promisedURL = url;
     3394}
     3395
     3396- (void)_setPromisedDataForImage:(WebCore::Image *)image withFileName:(NSString *)filename withExtension:(NSString *)extension withTitle:(NSString *)title withURL:(NSString *)url withVisibleURL:(NSString *)visibleUrl withArchive:(WebCore::SharedBuffer*) archiveBuffer forPasteboard:(NSString *)pasteboardName
     3397
     3398{
     3399    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:pasteboardName];
     3400    RetainPtr<NSMutableArray> types = adoptNS([[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil]);
     3401   
     3402    [types addObjectsFromArray:archiveBuffer ? PasteboardTypes::forImagesWithArchive() : PasteboardTypes::forImages()];
     3403    [pasteboard declareTypes:types.get() owner:self];
     3404    [self _setFileAndURLTypes:filename withExtension:extension withTitle:title withURL:url withVisibleURL:visibleUrl forPasteboard:pasteboard];
    33983405
    33993406    if (archiveBuffer)
     
    34013408
    34023409    _data->_promisedImage = image;
    3403     _data->_promisedFilename = filename;
    3404     _data->_promisedURL = url;
    3405 }
     3410}
     3411
     3412#if ENABLE(ATTACHMENT_ELEMENT)
     3413- (void)_setPromisedDataForAttachment:(NSString *)filename withExtension:(NSString *)extension withTitle:(NSString *)title withURL:(NSString *)url withVisibleURL:(NSString *)visibleUrl forPasteboard:(NSString *)pasteboardName
     3414
     3415{
     3416    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:pasteboardName];
     3417    RetainPtr<NSMutableArray> types = adoptNS([[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil]);
     3418    [types addObjectsFromArray:PasteboardTypes::forURL()];
     3419    [pasteboard declareTypes:types.get() owner:self];
     3420    [self _setFileAndURLTypes:filename withExtension:extension withTitle:title withURL:url withVisibleURL:visibleUrl forPasteboard:pasteboard];
     3421
     3422    RetainPtr<NSMutableArray> paths = adoptNS([[NSMutableArray alloc] init]);
     3423    [paths addObject:title];
     3424    [pasteboard setPropertyList:paths.get() forType:NSFilenamesPboardType];
     3425
     3426    _data->_promisedImage = nullptr;
     3427}
     3428#endif
    34063429
    34073430- (void)pasteboardChangedOwner:(NSPasteboard *)pasteboard
     
    34683491        data = _data->_promisedImage->data()->createNSData();
    34693492        wrapper = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:data.get()]);
     3493    } else
     3494        wrapper = adoptNS([[NSFileWrapper alloc] initWithURL:[NSURL URLWithString:_data->_promisedURL] options:NSFileWrapperReadingImmediate error:nil]);
     3495   
     3496    if (wrapper)
    34703497        [wrapper setPreferredFilename:_data->_promisedFilename];
    3471     }
    3472    
    3473     if (!wrapper) {
     3498    else {
    34743499        LOG_ERROR("Failed to create image file.");
    34753500        return nil;
  • trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h

    r180465 r181760  
    102102
    103103- (void)_setDragImage:(NSImage *)image at:(NSPoint)clientPoint linkDrag:(BOOL)linkDrag;
    104 - (void)_setPromisedData:(WebCore::Image *)image withFileName:(NSString *)filename withExtension:(NSString *)extension withTitle:(NSString *)title withURL:(NSString *)url withVisibleURL:(NSString *)visibleUrl withArchive:(WebCore::SharedBuffer*) archiveBuffer forPasteboard:(NSString *)pasteboardName;
     104- (void)_setPromisedDataForImage:(WebCore::Image *)image withFileName:(NSString *)filename withExtension:(NSString *)extension withTitle:(NSString *)title withURL:(NSString *)url withVisibleURL:(NSString *)visibleUrl withArchive:(WebCore::SharedBuffer*) archiveBuffer forPasteboard:(NSString *)pasteboardName;
     105#if ENABLE(ATTACHMENT_ELEMENT)
     106- (void)_setPromisedDataForAttachment:(NSString *)filename withExtension:(NSString *)extension withTitle:(NSString *)title withURL:(NSString *)url withVisibleURL:(NSString *)visibleUrl forPasteboard:(NSString *)pasteboardName;
     107#endif
    105108- (void)_updateSecureInputState;
    106109- (void)_resetSecureInputState;
  • trunk/Source/WebKit2/UIProcess/PageClient.h

    r181423 r181760  
    192192
    193193#if USE(APPKIT)
    194     virtual void setPromisedData(const String& pasteboardName, PassRefPtr<WebCore::SharedBuffer> imageBuffer, const String& filename, const String& extension, const String& title,
     194    virtual void setPromisedDataForImage(const String& pasteboardName, PassRefPtr<WebCore::SharedBuffer> imageBuffer, const String& filename, const String& extension, const String& title,
    195195                                 const String& url, const String& visibleUrl, PassRefPtr<WebCore::SharedBuffer> archiveBuffer) = 0;
     196#if ENABLE(ATTACHMENT_ELEMENT)
     197    virtual void setPromisedDataForAttachment(const String& pasteboardName, const String& filename, const String& extension, const String& title,
     198                                         const String& url, const String& visibleUrl) = 0;
     199
     200#endif
    196201#endif
    197202
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r181660 r181760  
    770770#if PLATFORM(COCOA)
    771771    void setDragImage(const WebCore::IntPoint& clientPosition, const ShareableBitmap::Handle& dragImageHandle, bool isLinkDrag);
    772     void setPromisedData(const String& pasteboardName, const SharedMemory::Handle& imageHandle, uint64_t imageSize, const String& filename, const String& extension,
     772    void setPromisedDataForImage(const String& pasteboardName, const SharedMemory::Handle& imageHandle, uint64_t imageSize, const String& filename, const String& extension,
    773773                         const String& title, const String& url, const String& visibleURL, const SharedMemory::Handle& archiveHandle, uint64_t archiveSize);
     774#if ENABLE(ATTACHMENT_ELEMENT)
     775    void setPromisedDataForAttachment(const String& pasteboardName, const String& filename, const String& extension, const String& title, const String& url, const String& visibleURL);
     776#endif
    774777#endif
    775778#if PLATFORM(GTK)
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in

    r181423 r181760  
    298298#if PLATFORM(COCOA) && ENABLE(DRAG_SUPPORT)
    299299    SetDragImage(WebCore::IntPoint clientPosition, WebKit::ShareableBitmap::Handle dragImage, bool linkDrag)
    300     SetPromisedData(String pasteboardName, WebKit::SharedMemory::Handle imageHandle, uint64_t imageSize, String filename, String extension, String title, String url, String visibleURL, WebKit::SharedMemory::Handle archiveHandle, uint64_t archiveSize)
     300    SetPromisedDataForImage(String pasteboardName, WebKit::SharedMemory::Handle imageHandle, uint64_t imageSize, String filename, String extension, String title, String url, String visibleURL, WebKit::SharedMemory::Handle archiveHandle, uint64_t archiveSize)
     301#if ENABLE(ATTACHMENT_ELEMENT)
     302    SetPromisedDataForAttachment(String pasteboardName, String filename, String extension, String title, String url, String visibleURL)
     303#endif
    301304#endif
    302305#if PLATFORM(GTK) && ENABLE(DRAG_SUPPORT)
  • trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h

    r181442 r181760  
    9595    virtual bool executeSavedCommandBySelector(const String& selector) override;
    9696    virtual void setDragImage(const WebCore::IntPoint& clientPosition, PassRefPtr<ShareableBitmap> dragImage, bool isLinkDrag) override;
    97     virtual void setPromisedData(const String& pasteboardName, PassRefPtr<WebCore::SharedBuffer> imageBuffer, const String& filename, const String& extension, const String& title,
     97    virtual void setPromisedDataForImage(const String& pasteboardName, PassRefPtr<WebCore::SharedBuffer> imageBuffer, const String& filename, const String& extension, const String& title,
    9898        const String& url, const String& visibleUrl, PassRefPtr<WebCore::SharedBuffer> archiveBuffer) override;
     99#if ENABLE(ATTACHMENT_ELEMENT)
     100    virtual void setPromisedDataForAttachment(const String& pasteboardName, const String& filename, const String& extension, const String& title, const String& url, const String& visibleUrl) override;
     101#endif
    99102    virtual void updateSecureInputState() override;
    100103    virtual void resetSecureInputState() override;
  • trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm

    r181442 r181760  
    408408}
    409409
    410 void PageClientImpl::setPromisedData(const String& pasteboardName, PassRefPtr<SharedBuffer> imageBuffer, const String& filename, const String& extension, const String& title, const String& url, const String& visibleUrl, PassRefPtr<SharedBuffer> archiveBuffer)
     410void PageClientImpl::setPromisedDataForImage(const String& pasteboardName, PassRefPtr<SharedBuffer> imageBuffer, const String& filename, const String& extension, const String& title, const String& url, const String& visibleUrl, PassRefPtr<SharedBuffer> archiveBuffer)
    411411{
    412412    RefPtr<Image> image = BitmapImage::create();
    413413    image->setData(imageBuffer.get(), true);
    414     [m_wkView _setPromisedData:image.get() withFileName:filename withExtension:extension withTitle:title withURL:url withVisibleURL:visibleUrl withArchive:archiveBuffer.get() forPasteboard:pasteboardName];
    415 }
     414    [m_wkView _setPromisedDataForImage:image.get() withFileName:filename withExtension:extension withTitle:title withURL:url withVisibleURL:visibleUrl withArchive:archiveBuffer.get() forPasteboard:pasteboardName];
     415}
     416
     417#if ENABLE(ATTACHMENT_ELEMENT)
     418void PageClientImpl::setPromisedDataForAttachment(const String& pasteboardName, const String& filename, const String& extension, const String& title, const String& url, const String& visibleUrl)
     419{
     420    [m_wkView _setPromisedDataForAttachment:filename withExtension:extension withTitle:title withURL:url withVisibleURL:visibleUrl forPasteboard:pasteboardName];
     421}
     422#endif
    416423
    417424void PageClientImpl::updateSecureInputState()
  • trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm

    r180768 r181760  
    6161
    6262#define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, process().connection())
     63#define MESSAGE_CHECK_URL(url) MESSAGE_CHECK_BASE(m_process->checkURLReceivedFromWebProcess(url), m_process->connection())
    6364
    6465using namespace WebCore;
     
    408409}
    409410
    410 void WebPageProxy::setPromisedData(const String& pasteboardName, const SharedMemory::Handle& imageHandle, uint64_t imageSize, const String& filename, const String& extension,
     411void WebPageProxy::setPromisedDataForImage(const String& pasteboardName, const SharedMemory::Handle& imageHandle, uint64_t imageSize, const String& filename, const String& extension,
    411412                                   const String& title, const String& url, const String& visibleURL, const SharedMemory::Handle& archiveHandle, uint64_t archiveSize)
    412413{
     414    MESSAGE_CHECK_URL(url);
     415    MESSAGE_CHECK_URL(visibleURL);
    413416    RefPtr<SharedMemory> sharedMemoryImage = SharedMemory::create(imageHandle, SharedMemory::ReadOnly);
    414417    RefPtr<SharedBuffer> imageBuffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryImage->data()), imageSize);
     
    419422        archiveBuffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryArchive->data()), archiveSize);
    420423    }
    421     m_pageClient.setPromisedData(pasteboardName, imageBuffer, filename, extension, title, url, visibleURL, archiveBuffer);
    422 }
     424    m_pageClient.setPromisedDataForImage(pasteboardName, imageBuffer, filename, extension, title, url, visibleURL, archiveBuffer);
     425}
     426
     427#if ENABLE(ATTACHMENT_ELEMENT)
     428void WebPageProxy::setPromisedDataForAttachment(const String& pasteboardName, const String& filename, const String& extension, const String& title, const String& url, const String& visibleURL)
     429{
     430    MESSAGE_CHECK_URL(url);
     431    MESSAGE_CHECK_URL(visibleURL);
     432    m_pageClient.setPromisedDataForAttachment(pasteboardName, filename, extension, title, url, visibleURL);
     433}
     434#endif
    423435#endif
    424436
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.h

    r166965 r181760  
    5252#if PLATFORM(COCOA)
    5353    virtual void declareAndWriteDragImage(const String& pasteboardName, WebCore::Element&, const WebCore::URL&, const String&, WebCore::Frame*) override;
     54#if ENABLE(ATTACHMENT_ELEMENT)
     55    virtual void declareAndWriteAttachment(const String& pasteboardName, WebCore::Element&, const WebCore::URL&, const String& path, WebCore::Frame*) override;
     56#endif
    5457#endif
    5558
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm

    r176687 r181760  
    9898}
    9999
     100#if ENABLE(ATTACHMENT_ELEMENT)
     101void WebDragClient::declareAndWriteAttachment(const String& pasteboardName, Element& element, const URL& url, const String& path, WebCore::Frame* frame)
     102{
     103    ASSERT(pasteboardName == String(NSDragPboard));
     104   
     105    NSURL* nsURL = (NSURL *)url;
     106    m_page->send(Messages::WebPageProxy::SetPromisedDataForAttachment(pasteboardName, String(nsURL.lastPathComponent), String(nsURL.pathExtension), path, String(nsURL.absoluteString), userVisibleString(nsURL)));
     107}
     108#endif
     109
    100110void WebDragClient::declareAndWriteDragImage(const String& pasteboardName, Element& element, const URL& url, const String& label, Frame*)
    101111{
     
    144154        archiveSharedMemoryBuffer->createHandle(archiveHandle, SharedMemory::ReadOnly);
    145155    }
    146     m_page->send(Messages::WebPageProxy::SetPromisedData(pasteboardName, imageHandle, imageSize, String([response suggestedFilename]), extension, title, String([[response URL] absoluteString]), userVisibleString((NSURL *)url), archiveHandle, archiveSize));
     156    m_page->send(Messages::WebPageProxy::SetPromisedDataForImage(pasteboardName, imageHandle, imageSize, String([response suggestedFilename]), extension, title, String([[response URL] absoluteString]), userVisibleString((NSURL *)url), archiveHandle, archiveSize));
    147157}
    148158
Note: See TracChangeset for help on using the changeset viewer.