Source/WebCore: WebKit2: remove NSPasteboard access for promised data from the WebProcess
authorenrica@apple.com <enrica@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Mar 2012 22:45:47 +0000 (22:45 +0000)
committerenrica@apple.com <enrica@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Mar 2012 22:45:47 +0000 (22:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=80073

Reviewed by Alexey Proskuryakov.

* WebCore.exp.in: Added two exported methods.
* platform/mac/FileSystemMac.mm:
(WebCore::setMetaData): Last parameter in the call to wkSetMetadataURL
needs to be wrapped in String before casting to NSString.

Source/WebKit2: WebKit2: remove NSPasteboard access for promised data from the WebProcess
https://bugs.webkit.org/show_bug.cgi?id=80073

Reviewed by Alexey Proskuryakov.

This patch removes the last remaining access to NSPasteboard from the WebProcess.
The code in WebDragClient::declareAndWriteDragImage now packages all the data
required for the drag and the promised drag types and sends one request to the UI
process that will place the data in the NSPasteboard when appropriate.

* UIProcess/API/mac/PageClientImpl.h: Added setPromisedData method.
* UIProcess/API/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::setPromisedData):
* UIProcess/API/mac/WKView.mm:
(matchesExtensionOrEquivalent): Added.
(fileExists): Added.
(pathWithUniqueFilenameForPath): Added.
(-[WKView _setPromisedData:WebCore::withFileName:withExtension:withTitle:withURL:withVisibleURL:withArchive:WebCore::forPasteboard:]):
(-[WKView pasteboardChangedOwner:]):
(-[WKView pasteboard:provideDataForType:]):
(-[WKView namesOfPromisedFilesDroppedAtDestination:]):
* UIProcess/API/mac/WKViewInternal.h: Added _setPromisedData.
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.h: Added method for the new message.
* UIProcess/WebPageProxy.messages.in: Added setPromisedData message.
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::setPromisedData):
* WebProcess/WebCoreSupport/WebDragClient.cpp:
* WebProcess/WebCoreSupport/WebDragClient.h:
* WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
(WebKit::WebDragClient::declareAndWriteDragImage):
* WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
(InitWebCoreSystemInterface): Added SetMetadataURL.

WebKitLibraries: WebKit2: remove NSPasteboard access for promised data from the WebProcess
https://bugs.webkit.org/show_bug.cgi?id=80073

* WebKitSystemInterface.h: Touched the file to make build system happy.
* libWebKitSystemInterfaceLeopard.a:
* libWebKitSystemInterfaceLion.a:
* libWebKitSystemInterfaceSnowLeopard.a:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@110494 268f45cc-cd09-0410-ab3c-d52691b4dbfc

21 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/platform/mac/FileSystemMac.mm
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/mac/PageClientImpl.h
Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/API/mac/WKViewInternal.h
Source/WebKit2/UIProcess/PageClient.h
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm
Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.h
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm
WebKitLibraries/ChangeLog
WebKitLibraries/WebKitSystemInterface.h
WebKitLibraries/libWebKitSystemInterfaceLeopard.a
WebKitLibraries/libWebKitSystemInterfaceLion.a
WebKitLibraries/libWebKitSystemInterfaceSnowLeopard.a

index 5a79f75..f4b0044 100644 (file)
@@ -1,3 +1,15 @@
+2012-03-12  Enrica Casucci  <enrica@apple.com>
+
+        WebKit2: remove NSPasteboard access for promised data from the WebProcess
+        https://bugs.webkit.org/show_bug.cgi?id=80073
+        
+        Reviewed by Alexey Proskuryakov.
+
+        * WebCore.exp.in: Added two exported methods.
+        * platform/mac/FileSystemMac.mm:
+        (WebCore::setMetaData): Last parameter in the call to wkSetMetadataURL
+        needs to be wrapped in String before casting to NSString.
+
 2012-03-12  Alexey Proskuryakov  <ap@apple.com>
 
         clang build fix
index 590b7c5..a710604 100644 (file)
@@ -1153,6 +1153,8 @@ __ZN7WebCore9pageCacheEv
 __ZN7WebCore9plainTextEPKNS_5RangeENS_20TextIteratorBehaviorE
 __ZN7WebCore9toElementEN3JSC7JSValueE
 __ZN7WebCore9unionRectERKN3WTF6VectorINS_9FloatRectELm0EEE
+__ZN7WebCore11BitmapImageC1EPNS_13ImageObserverE
+__ZN7WebCore5Image7setDataEN3WTF10PassRefPtrINS_12SharedBufferEEEb
 __ZNK3JSC8Bindings10RootObject12globalObjectEv
 __ZNK3WTF6String14createCFStringEv
 __ZNK7WebCore10Credential11hasPasswordEv
index efb7d45..f9a0343 100644 (file)
@@ -78,7 +78,7 @@ typedef struct MetaDataInfo
 static void* setMetaData(void* context)
 {
     MetaDataInfo *info = (MetaDataInfo *)context;
-    wkSetMetadataURL((NSString *)info->URLString, (NSString *)info->referrer, (NSString *)fileSystemRepresentation(info->path).data());
+    wkSetMetadataURL((NSString *)info->URLString, (NSString *)info->referrer, (NSString *)String(fileSystemRepresentation(info->path).data()));
     
     delete info;
     
index d902bd8..24c64d5 100644 (file)
@@ -1,3 +1,39 @@
+2012-03-12  Enrica Casucci  <enrica@apple.com>
+
+        WebKit2: remove NSPasteboard access for promised data from the WebProcess
+        https://bugs.webkit.org/show_bug.cgi?id=80073
+
+        Reviewed by Alexey Proskuryakov.
+
+        This patch removes the last remaining access to NSPasteboard from the WebProcess.
+        The code in WebDragClient::declareAndWriteDragImage now packages all the data
+        required for the drag and the promised drag types and sends one request to the UI
+        process that will place the data in the NSPasteboard when appropriate.
+        
+        * UIProcess/API/mac/PageClientImpl.h: Added setPromisedData method.
+        * UIProcess/API/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::setPromisedData):
+        * UIProcess/API/mac/WKView.mm:
+        (matchesExtensionOrEquivalent): Added.
+        (fileExists): Added.
+        (pathWithUniqueFilenameForPath): Added.
+        (-[WKView _setPromisedData:WebCore::withFileName:withExtension:withTitle:withURL:withVisibleURL:withArchive:WebCore::forPasteboard:]):
+        (-[WKView pasteboardChangedOwner:]):
+        (-[WKView pasteboard:provideDataForType:]):
+        (-[WKView namesOfPromisedFilesDroppedAtDestination:]):
+        * UIProcess/API/mac/WKViewInternal.h: Added _setPromisedData.
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.h: Added method for the new message.
+        * UIProcess/WebPageProxy.messages.in: Added setPromisedData message.
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::setPromisedData):
+        * WebProcess/WebCoreSupport/WebDragClient.cpp:
+        * WebProcess/WebCoreSupport/WebDragClient.h:
+        * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
+        (WebKit::WebDragClient::declareAndWriteDragImage):
+        * WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface): Added SetMetadataURL.
+
 2012-03-12  Andras Becsi  <andras.becsi@nokia.com>
 
         [Qt][WK2] Add support for rudimentary scroll indicators in MiniBrowser
index dbe947a..ba7c053 100644 (file)
@@ -72,6 +72,8 @@ private:
     virtual bool interpretKeyEvent(const NativeWebKeyboardEvent&, Vector<WebCore::KeypressCommand>&);
     virtual bool executeSavedCommandBySelector(const String& selector);
     virtual void setDragImage(const WebCore::IntPoint& clientPosition, PassRefPtr<ShareableBitmap> dragImage, bool isLinkDrag);
+    virtual void setPromisedData(const String& pasteboardName, PassRefPtr<WebCore::SharedBuffer> imageBuffer, const String& filename, const String& extension, const String& title,
+                                 const String& url, const String& visibleUrl, PassRefPtr<WebCore::SharedBuffer> archiveBuffer);
     virtual void updateTextInputState(bool updateSecureInputState);
     virtual void resetTextInputState();
 
index 71a1a50..3819392 100644 (file)
 #import "WebContextMenuProxyMac.h"
 #import "WebEditCommandProxy.h"
 #import "WebPopupMenuProxyMac.h"
+#import <WebCore/BitmapImage.h>
 #import <WebCore/Cursor.h>
 #import <WebCore/FloatRect.h>
 #import <WebCore/FoundationExtras.h>
 #import <WebCore/GraphicsContext.h>
+#import <WebCore/Image.h>
 #import <WebCore/KeyboardEvent.h>
 #import <WebCore/NotImplemented.h>
+#import <WebCore/SharedBuffer.h>
 #import <wtf/PassOwnPtr.h>
 #import <wtf/text/CString.h>
 #import <wtf/text/WTFString.h>
@@ -278,6 +281,13 @@ void PageClientImpl::setDragImage(const IntPoint& clientPosition, PassRefPtr<Sha
     [m_wkView _setDragImage:dragNSImage.get() at:clientPosition linkDrag:isLinkDrag];
 }
 
+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)
+{
+    RefPtr<Image> image = BitmapImage::create();
+    image->setData(imageBuffer.get(), true);
+    [m_wkView _setPromisedData:image.get() withFileName:filename withExtension:extension withTitle:title withURL:url withVisibleURL:visibleUrl withArchive:archiveBuffer.get() forPasteboard:pasteboardName];
+}
+
 void PageClientImpl::updateTextInputState(bool updateSecureInputState)
 {
     [m_wkView _updateTextInputStateIncludingSecureInputState:updateSecureInputState];
index a326dd0..f52071b 100644 (file)
@@ -64,6 +64,7 @@
 #import <WebCore/DragData.h>
 #import <WebCore/DragSession.h>
 #import <WebCore/FloatRect.h>
+#import <WebCore/Image.h>
 #import <WebCore/IntRect.h>
 #import <WebCore/KeyboardEvent.h>
 #import <WebCore/LocalizedStrings.h>
 #import <WebCore/PlatformScreen.h>
 #import <WebCore/Region.h>
 #import <WebCore/RunLoop.h>
+#import <WebCore/SharedBuffer.h>
+#import <WebCore/WebCoreNSStringExtras.h>
+#import <WebCore/FileSystem.h>
 #import <WebKitSystemInterface.h>
+#import <sys/stat.h>
 #import <wtf/RefPtr.h>
 #import <wtf/RetainPtr.h>
 
@@ -194,6 +199,9 @@ struct WKViewInterpretKeyEventsParameters {
     // We use this flag to determine when we need to paint the background (white or clear)
     // when the web process is unresponsive or takes too long to paint.
     BOOL _windowHasValidBackingStore;
+    RefPtr<WebCore::Image> _promisedImage;
+    String _promisedFilename;
+    String _promisedURL;
 }
 
 @end
@@ -2588,6 +2596,121 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
     _data->_dragHasStarted = NO;
 }
 
+static bool matchesExtensionOrEquivalent(NSString *filename, NSString *extension)
+{
+    NSString *extensionAsSuffix = [@"." stringByAppendingString:extension];
+    return hasCaseInsensitiveSuffix(filename, extensionAsSuffix) || (stringIsCaseInsensitiveEqualToString(extension, @"jpeg")
+                                                                     && hasCaseInsensitiveSuffix(filename, @".jpg"));
+}
+
+- (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
+
+{
+    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:pasteboardName];
+    RetainPtr<NSMutableArray> types(AdoptNS, [[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil]);
+    
+    [types.get() addObjectsFromArray:archiveBuffer ? PasteboardTypes::forImagesWithArchive() : PasteboardTypes::forImages()];
+    [pasteboard declareTypes:types.get() owner:self];
+    if (!matchesExtensionOrEquivalent(filename, extension))
+        filename = [[filename stringByAppendingString:@"."] stringByAppendingString:extension];
+
+    [pasteboard setString:url forType:NSURLPboardType];
+    [pasteboard setString:visibleUrl forType:PasteboardTypes::WebURLPboardType];
+    [pasteboard setString:title forType:PasteboardTypes::WebURLNamePboardType];
+    [pasteboard setPropertyList:[NSArray arrayWithObjects:[NSArray arrayWithObject:url], [NSArray arrayWithObject:title], nil] forType:PasteboardTypes::WebURLsWithTitlesPboardType];
+    [pasteboard setPropertyList:[NSArray arrayWithObject:extension] forType:NSFilesPromisePboardType];
+
+    if (archiveBuffer)
+        [pasteboard setData:[archiveBuffer->createNSData() autorelease] forType:PasteboardTypes::WebArchivePboardType];
+
+    _data->_promisedImage = image;
+    _data->_promisedFilename = filename;
+    _data->_promisedURL = url;
+}
+
+- (void)pasteboardChangedOwner:(NSPasteboard *)pasteboard
+{
+    _data->_promisedImage = 0;
+    _data->_promisedFilename = "";
+    _data->_promisedURL = "";
+}
+
+- (void)pasteboard:(NSPasteboard *)pasteboard provideDataForType:(NSString *)type
+{
+    // FIXME: need to support NSRTFDPboardType
+
+    if ([type isEqual:NSTIFFPboardType] && _data->_promisedImage) {
+        [pasteboard setData:(NSData *)_data->_promisedImage->getTIFFRepresentation() forType:NSTIFFPboardType];
+        _data->_promisedImage = 0;
+    }
+}
+
+static BOOL fileExists(NSString *path)
+{
+    struct stat statBuffer;
+    return !lstat([path fileSystemRepresentation], &statBuffer);
+}
+
+static NSString *pathWithUniqueFilenameForPath(NSString *path)
+{
+    // "Fix" the filename of the path.
+    NSString *filename = filenameByFixingIllegalCharacters([path lastPathComponent]);
+    path = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:filename];
+    
+    if (fileExists(path)) {
+        // Don't overwrite existing file by appending "-n", "-n.ext" or "-n.ext.ext" to the filename.
+        NSString *extensions = nil;
+        NSString *pathWithoutExtensions;
+        NSString *lastPathComponent = [path lastPathComponent];
+        NSRange periodRange = [lastPathComponent rangeOfString:@"."];
+        
+        if (periodRange.location == NSNotFound) {
+            pathWithoutExtensions = path;
+        } else {
+            extensions = [lastPathComponent substringFromIndex:periodRange.location + 1];
+            lastPathComponent = [lastPathComponent substringToIndex:periodRange.location];
+            pathWithoutExtensions = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:lastPathComponent];
+        }
+        
+        for (unsigned i = 1; ; i++) {
+            NSString *pathWithAppendedNumber = [NSString stringWithFormat:@"%@-%d", pathWithoutExtensions, i];
+            path = [extensions length] ? [pathWithAppendedNumber stringByAppendingPathExtension:extensions] : pathWithAppendedNumber;
+            if (!fileExists(path))
+                break;
+        }
+    }
+    
+    return path;
+}
+
+- (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
+{
+    RetainPtr<NSFileWrapper> wrapper;
+    RetainPtr<NSData> data;
+    
+    if (_data->_promisedImage) {
+        data.adoptNS(_data->_promisedImage->data()->createNSData());
+        wrapper.adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:data.get()]);
+        [wrapper.get() setPreferredFilename:_data->_promisedFilename];
+    }
+    
+    if (!wrapper) {
+        LOG_ERROR("Failed to create image file.");
+        return nil;
+    }
+    
+    // FIXME: Report an error if we fail to create a file.
+    NSString *path = [[dropDestination path] stringByAppendingPathComponent:[wrapper.get() preferredFilename]];
+    path = pathWithUniqueFilenameForPath(path);
+    if (![wrapper.get() writeToFile:path atomically:NO updateFilenames:YES])
+        LOG_ERROR("Failed to create image file via -[NSFileWrapper writeToFile:atomically:updateFilenames:]");
+    
+    if (!_data->_promisedURL.isEmpty())
+        WebCore::setMetadataURL(_data->_promisedURL, "", String(path));
+    
+    return [NSArray arrayWithObject:[path lastPathComponent]];
+}
+
 - (void)_updateSecureInputState
 {
     if (![[self window] isKeyWindow] || ![self _isFocused]) {
index 83346d3..ad46d0a 100644 (file)
@@ -35,6 +35,8 @@ namespace CoreIPC {
 
 namespace WebCore {
     struct KeypressCommand;
+    class Image;
+    class SharedBuffer;
 }
 
 namespace WebKit {
@@ -78,6 +80,7 @@ namespace WebKit {
 - (void)_findStringInCustomRepresentation:(NSString *)string withFindOptions:(WebKit::FindOptions)options maxMatchCount:(NSUInteger)count;
 - (void)_countStringMatchesInCustomRepresentation:(NSString *)string withFindOptions:(WebKit::FindOptions)options maxMatchCount:(NSUInteger)count;
 - (void)_setDragImage:(NSImage *)image at:(NSPoint)clientPoint linkDrag:(BOOL)linkDrag;
+- (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;
 - (void)_updateSecureInputState;
 - (void)_updateTextInputStateIncludingSecureInputState:(BOOL)updateSecureInputState;
 - (void)_resetTextInputState;
index f06d827..499901a 100644 (file)
@@ -137,6 +137,8 @@ public:
     virtual void updateTextInputState(bool updateSecureInputState) = 0;
     virtual void resetTextInputState() = 0;
     virtual void makeFirstResponder() = 0;
+    virtual void setPromisedData(const String& pasteboardName, PassRefPtr<WebCore::SharedBuffer> imageBuffer, const String& filename, const String& extension, const String& title,
+                                 const String& url, const String& visibleUrl, PassRefPtr<WebCore::SharedBuffer> archiveBuffer) = 0;
 #endif
 #if PLATFORM(WIN)
     virtual void compositionSelectionChanged(bool) = 0;
index 5049228..fb7802c 100644 (file)
@@ -517,6 +517,8 @@ public:
     void dragEnded(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, uint64_t operation);
 #if PLATFORM(MAC)
     void setDragImage(const WebCore::IntPoint& clientPosition, const ShareableBitmap::Handle& dragImageHandle, bool isLinkDrag);
+    void setPromisedData(const String& pasteboardName, const SharedMemory::Handle& imageHandle, uint64_t imageSize, const String& filename, const String& extension,
+                         const String& title, const String& url, const String& visibleURL, const SharedMemory::Handle& archiveHandle, uint64_t archiveSize);
 #endif
 #if PLATFORM(WIN)
     void startDragDrop(const WebCore::IntPoint& imagePoint, const WebCore::IntPoint& dragPoint, uint64_t okEffect, const HashMap<UINT, Vector<String> >& dataMap, uint64_t fileSize, const String& pathname, const SharedMemory::Handle& fileContentHandle, const WebCore::IntSize& dragImageSize, const SharedMemory::Handle& dragImageHandle, bool isLinkDrag);
index 347aa93..64432d2 100644 (file)
@@ -227,6 +227,7 @@ messages -> WebPageProxy {
     DidPerformDragControllerAction(WebCore::DragSession dragSession)
 #if PLATFORM(MAC)
     SetDragImage(WebCore::IntPoint clientPosition, WebKit::ShareableBitmap::Handle dragImage, bool linkDrag)
+    SetPromisedData(WTF::String pasteboardName, WebKit::SharedMemory::Handle imageHandle, uint64_t imageSize, WTF::String filename, WTF::String extension, WTF::String title, WTF::String url, WTF::String visibleURL, WebKit::SharedMemory::Handle archiveHandle, uint64_t archiveSize)
 #endif
 #if PLATFORM(WIN)
     StartDragDrop(WebCore::IntPoint imagePoint, WebCore::IntPoint dragPoint, uint64_t okEffect, HashMap<UINT,Vector<String> > dataMap, uint64_t fileSize, String pathname, WebKit::SharedMemory::Handle fileContentHandle, WebCore::IntSize dragImageSize, WebKit::SharedMemory::Handle dragImage, bool linkDrag)
index 120dc5d..3584718 100644 (file)
@@ -38,6 +38,7 @@
 #import "TextChecker.h"
 #import "WebPageMessages.h"
 #import "WebProcessProxy.h"
+#import <WebCore/SharedBuffer.h>
 #import <WebKitSystemInterface.h>
 #import <wtf/text/StringConcatenate.h>
 
@@ -287,6 +288,20 @@ void WebPageProxy::setDragImage(const WebCore::IntPoint& clientPosition, const S
     m_pageClient->setDragImage(clientPosition, dragImage.release(), isLinkDrag);
 }
 
+void WebPageProxy::setPromisedData(const String& pasteboardName, const SharedMemory::Handle& imageHandle, uint64_t imageSize, const String& filename, const String& extension,
+                                   const String& title, const String& url, const String& visibleURL, const SharedMemory::Handle& archiveHandle, uint64_t archiveSize)
+{
+    RefPtr<SharedMemory> sharedMemoryImage = SharedMemory::create(imageHandle, SharedMemory::ReadOnly);
+    RefPtr<SharedBuffer> imageBuffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryImage->data()), imageSize);
+    RefPtr<SharedBuffer> archiveBuffer;
+    
+    if (!archiveHandle.isNull()) {
+        RefPtr<SharedMemory> sharedMemoryArchive = SharedMemory::create(archiveHandle, SharedMemory::ReadOnly);;
+        archiveBuffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryArchive->data()), archiveSize);
+    }
+    m_pageClient->setPromisedData(pasteboardName, imageBuffer, filename, extension, title, url, visibleURL, archiveBuffer);
+}
+
 void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint& point)
 {
     if (!isValid())
index 736de21..57ad6a4 100644 (file)
@@ -58,12 +58,6 @@ void WebDragClient::startDrag(DragImageRef, const IntPoint&, const IntPoint&, Cl
 }
 #endif
 
-#if !PLATFORM(MAC)
-void WebDragClient::dragEnded()
-{
-}
-#endif
-
 void WebDragClient::dragControllerDestroyed()
 {
     delete this;
index a9411ac..bcee693 100644 (file)
 
 #include <WebCore/DragClient.h>
 
-#if PLATFORM(MAC)
-OBJC_CLASS WKPasteboardFilePromiseOwner;
-OBJC_CLASS WKPasteboardOwner;
-#endif
-
 namespace WebKit {
 
 class WebPage;
@@ -56,16 +51,9 @@ private:
     virtual void declareAndWriteDragImage(const String& pasteboardName, DOMElement*, NSURL*, NSString*, WebCore::Frame*) OVERRIDE;
 #endif
 
-    virtual void dragEnded() OVERRIDE;
-
     virtual void dragControllerDestroyed() OVERRIDE;
 
     WebPage* m_page;
-    
-#if PLATFORM(MAC)
-    RetainPtr<WKPasteboardFilePromiseOwner> m_filePromiseOwner;
-    RetainPtr<WKPasteboardOwner> m_pasteboardOwner;
-#endif
 };
 
 } // namespace WebKit
index da608dd..1bb209d 100644 (file)
 using namespace WebCore;
 using namespace WebKit;
 
-// Internal AppKit class. If the pasteboard handling was in the same process
-// that called the dragImage method, this would be created automatically.
-// Create it explicitly because dragImage is called in the UI process.
-@interface NSFilePromiseDragSource : NSObject
-{
-    id _dragSource;
-    char _unknownFields[256];
-}
-- (id)initWithSource:(id)dragSource;
-- (void)setTypes:(NSArray *)types onPasteboard:(NSPasteboard *)pasteboard;
-@end
-
-@interface WKPasteboardFilePromiseOwner : NSFilePromiseDragSource
-@end
-
-@interface WKPasteboardOwner : NSObject
-{
-    CachedResourceHandle<WebCore::CachedImage> _image;
-}
-- (id)initWithImage:(WebCore::CachedImage*)image;
-@end
-
 namespace WebKit {
 
 static PassRefPtr<ShareableBitmap> convertImageToBitmap(NSImage *image, const IntSize& size)
@@ -119,12 +97,6 @@ static WebCore::CachedImage* cachedImage(Element* element)
     return image;
 }
 
-static NSArray *arrayForURLsWithTitles(NSURL *URL, NSString *title)
-{
-    return [NSArray arrayWithObjects:[NSArray arrayWithObject:[URL _web_originalDataAsString]],
-        [NSArray arrayWithObject:[title _webkit_stringByTrimmingWhitespace]], nil];
-}
-
 void WebDragClient::declareAndWriteDragImage(const String& pasteboardName, DOMElement *element, NSURL *URL, NSString *title, WebCore::Frame*)
 {
     ASSERT(element);
@@ -149,190 +121,27 @@ void WebDragClient::declareAndWriteDragImage(const String& pasteboardName, DOMEl
 
     RefPtr<LegacyWebArchive> archive = LegacyWebArchive::create(coreElement);
 
-    RetainPtr<NSMutableArray> types(AdoptNS, [[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil]);
-    [types.get() addObjectsFromArray:archive ? PasteboardTypes::forImagesWithArchive() : PasteboardTypes::forImages()];
-
-    m_pasteboardOwner.adoptNS([[WKPasteboardOwner alloc] initWithImage:image]);
-    m_filePromiseOwner.adoptNS([(WKPasteboardFilePromiseOwner *)[WKPasteboardFilePromiseOwner alloc] initWithSource:m_pasteboardOwner.get()]);
-
-    NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:pasteboardName];
-    [pasteboard declareTypes:types.get() owner:m_pasteboardOwner.leakRef()];    
-
-    [pasteboard setPropertyList:[NSArray arrayWithObject:extension] forType:NSFilesPromisePboardType];
-
-    [m_filePromiseOwner.get() setTypes:[pasteboard propertyListForType:NSFilesPromisePboardType] onPasteboard:pasteboard];
-
-    [URL writeToPasteboard:pasteboard];
-
-    [pasteboard setString:[URL _web_originalDataAsString] forType:PasteboardTypes::WebURLPboardType];
-
-    [pasteboard setString:title forType:PasteboardTypes::WebURLNamePboardType];
-
-    [pasteboard setString:[URL _web_userVisibleString] forType:NSStringPboardType];
-
-    [pasteboard setPropertyList:arrayForURLsWithTitles(URL, title) forType:PasteboardTypes::WebURLsWithTitlesPboardType];
-
-    if (archive)
-        [pasteboard setData:(NSData *)archive->rawDataRepresentation().get() forType:PasteboardTypes::WebArchivePboardType];
-}
-
-void WebDragClient::dragEnded()
-{
-    // The draggedImage method releases its responder; we must retain the WKPasteboardFilePromiseOwner an extra time to balance the release
-    // inside of the function.
-    [m_filePromiseOwner.get() retain];
-
-    // The drag source we care about here is NSFilePromiseDragSource, which doesn't look at
-    // the arguments. It's OK to just pass arbitrary constant values, so we just pass all zeroes.
-    [m_filePromiseOwner.get() draggedImage:nil endedAt:NSZeroPoint operation:NSDragOperationNone];
+    NSURLResponse *response = image->response().nsURLResponse();
     
-    m_pasteboardOwner = nullptr;
-    m_filePromiseOwner = nullptr;
-}
-
-} // namespace WebKit
-
-@implementation WKPasteboardFilePromiseOwner
-
-- (id)initWithSource:(id)dragSource
-{
-    self = [super initWithSource:dragSource];
-    if (!self)
-        return nil;
-    [_dragSource retain];
-    return self;
-}
-
-- (void)dealloc
-{
-    [_dragSource release];
-    [super dealloc];
-}
-
-// The AppKit implementation of copyDropDirectory gets the current pasteboard in
-// a way that only works in the process where the drag is initiated. We supply
-// an implementation that gets the pasteboard by name instead.
-- (CFURLRef)copyDropDirectory
-{
-    PasteboardRef pasteboard;
-    OSStatus status = PasteboardCreate((CFStringRef)NSDragPboard, &pasteboard);
-    if (status != noErr || !pasteboard)
-        return 0;
-    CFURLRef location = 0;
-    status = PasteboardCopyPasteLocation(pasteboard, &location);
-    CFRelease(pasteboard);
-    if (status != noErr || !location)
-        return 0;
-    CFMakeCollectable(location);
-    return location;
-}
-
-@end
-
-@implementation WKPasteboardOwner
-
-static CachedImageClient* promisedDataClient()
-{
-    static CachedImageClient* client = new CachedImageClient;
-    return client;
-}
-
-- (void)clearImage
-{
-    if (!_image)
-        return;
-    _image->removeClient(promisedDataClient());
-    _image = 0;
-}
-
-- (id)initWithImage:(WebCore::CachedImage*)image
-{
-    self = [super init];
-    if (!self)
-        return nil;
-
-    _image = image;
-    if (image)
-        image->addClient(promisedDataClient());
-    return self;
-}
-
-- (void)dealloc
-{
-    [self clearImage];
-    [super dealloc];
-}
-
-- (void)finalize
-{
-    [self clearImage];
-    [super finalize];
-}
-
-- (void)pasteboard:(NSPasteboard *)pasteboard provideDataForType:(NSString *)type
-{
-    if ([type isEqual:NSTIFFPboardType]) {
-        if (_image) {
-            if (Image* image = _image->image())
-                [pasteboard setData:(NSData *)image->getTIFFRepresentation() forType:NSTIFFPboardType];
-            [self clearImage];
-        }
-        return;
-    }
-    // FIXME: Handle RTFD here.
-}
-
-- (void)pasteboardChangedOwner:(NSPasteboard *)pasteboard
-{
-    [self clearImage];
-    CFRelease(self); // Balanced by the leakRef that WebDragClient::declareAndWriteDragImage does when making this pasteboard owner.
-}
-
-static bool matchesExtensionOrEquivalent(NSString *filename, NSString *extension)
-{
-    NSString *extensionAsSuffix = [@"." stringByAppendingString:extension];
-    return [filename _webkit_hasCaseInsensitiveSuffix:extensionAsSuffix]
-        || ([extension _webkit_isCaseInsensitiveEqualToString:@"jpeg"]
-            && [filename _webkit_hasCaseInsensitiveSuffix:@".jpg"]);
-}
-
-- (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
-{
-    NSFileWrapper *wrapper = nil;
-    NSURL *draggingImageURL = nil;
+    RefPtr<SharedBuffer> imageBuffer = image->image()->data();
+    size_t imageSize = imageBuffer->size();
+    SharedMemory::Handle imageHandle;
     
-    if (_image) {
-        if (SharedBuffer* buffer = _image->CachedResource::data()) {
-            NSData *data = buffer->createNSData();
-            NSURLResponse *response = _image->response().nsURLResponse();
-            draggingImageURL = [response URL];
-            wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:data] autorelease];
-            NSString* filename = [response suggestedFilename];
-            NSString* trueExtension(_image->image()->filenameExtension());
-            if (!matchesExtensionOrEquivalent(filename, trueExtension))
-                filename = [[filename stringByAppendingString:@"."] stringByAppendingString:trueExtension];
-            [wrapper setPreferredFilename:filename];
-        }
-    }
-
-    // FIXME: Do we need to handle the case where we do not have a CachedImage?
-    // WebKit1 had code for this case.
+    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(imageBuffer->size());
+    memcpy(sharedMemoryBuffer->data(), imageBuffer->data(), imageSize);
+    sharedMemoryBuffer->createHandle(imageHandle, SharedMemory::ReadOnly);
     
-    if (!wrapper) {
-        LOG_ERROR("Failed to create image file.");
-        return nil;
+    RetainPtr<CFDataRef> data = archive ? archive->rawDataRepresentation() : 0;
+    SharedMemory::Handle archiveHandle;
+    size_t archiveSize = 0;
+    if (data) {
+        RefPtr<SharedBuffer> buffer = SharedBuffer::wrapNSData((NSData *)data.get());
+        RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(buffer->size());
+        archiveSize = buffer->size();
+        memcpy(sharedMemoryBuffer->data(), buffer->data(), archiveSize);
+        sharedMemoryBuffer->createHandle(archiveHandle, SharedMemory::ReadOnly);            
     }
-
-    // FIXME: Report an error if we fail to create a file.
-    NSString *path = [[dropDestination path] stringByAppendingPathComponent:[wrapper preferredFilename]];
-    path = [[NSFileManager defaultManager] _webkit_pathWithUniqueFilenameForPath:path];
-    if (![wrapper writeToFile:path atomically:NO updateFilenames:YES])
-        LOG_ERROR("Failed to create image file via -[NSFileWrapper writeToFile:atomically:updateFilenames:] at path %@", path);
-
-    if (draggingImageURL)
-        [[NSFileManager defaultManager] _webkit_setMetadataURL:[draggingImageURL absoluteString] referrer:nil atPath:path];
-
-    return [NSArray arrayWithObject:[path lastPathComponent]];
+    m_page->send(Messages::WebPageProxy::SetPromisedData(pasteboardName, imageHandle, imageSize, String([response suggestedFilename]), String(extension), String(title), String([[response URL] absoluteString]), String([URL _web_userVisibleString]), archiveHandle, archiveSize));
 }
 
-@end
+} // namespace WebKit
index bfc7da5..2030e95 100644 (file)
@@ -115,6 +115,8 @@ void InitWebCoreSystemInterface(void)
         INIT(SetHTTPCookiesForURL);
         INIT(DeleteHTTPCookie);
 
+        INIT(SetMetadataURL);
+        
 #if !defined(BUILDING_ON_SNOW_LEOPARD)
         INIT(IOSurfaceContextCreate);
         INIT(IOSurfaceContextCreateImage);
index 2401371..beeaf66 100644 (file)
@@ -1,3 +1,13 @@
+2012-03-12  Enrica Casucci  <enrica@apple.com>
+
+        WebKit2: remove NSPasteboard access for promised data from the WebProcess
+        https://bugs.webkit.org/show_bug.cgi?id=80073
+
+        * WebKitSystemInterface.h: Touched the file to make build system happy.
+        * libWebKitSystemInterfaceLeopard.a:
+        * libWebKitSystemInterfaceLion.a:
+        * libWebKitSystemInterfaceSnowLeopard.a:
+
 2012-03-09  Jon Lee  <jonlee@apple.com>
 
         Add support for ENABLE(LEGACY_NOTIFICATIONS)
index ef47e2a..fbd43df 100644 (file)
@@ -1,6 +1,6 @@
 /*      
     WebKitSystemInterface.h
-    Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
+    Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
 
     Public header file.
 */
index 6c5bf40..e6664f7 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceLeopard.a and b/WebKitLibraries/libWebKitSystemInterfaceLeopard.a differ
index 69cd4c3..545a67a 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceLion.a and b/WebKitLibraries/libWebKitSystemInterfaceLion.a differ
index c33e96c..626c416 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceSnowLeopard.a and b/WebKitLibraries/libWebKitSystemInterfaceSnowLeopard.a differ