Title: [110494] trunk
Revision
110494
Author
[email protected]
Date
2012-03-12 15:45:47 -0700 (Mon, 12 Mar 2012)

Log Message

Source/WebCore: 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.

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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (110493 => 110494)


--- trunk/Source/WebCore/ChangeLog	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebCore/ChangeLog	2012-03-12 22:45:47 UTC (rev 110494)
@@ -1,3 +1,15 @@
+2012-03-12  Enrica Casucci  <[email protected]>
+
+        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  <[email protected]>
 
         clang build fix

Modified: trunk/Source/WebCore/WebCore.exp.in (110493 => 110494)


--- trunk/Source/WebCore/WebCore.exp.in	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebCore/WebCore.exp.in	2012-03-12 22:45:47 UTC (rev 110494)
@@ -1153,6 +1153,8 @@
 __ZN7WebCore9plainTextEPKNS_5RangeENS_20TextIteratorBehaviorE
 __ZN7WebCore9toElementEN3JSC7JSValueE
 __ZN7WebCore9unionRectERKN3WTF6VectorINS_9FloatRectELm0EEE
+__ZN7WebCore11BitmapImageC1EPNS_13ImageObserverE
+__ZN7WebCore5Image7setDataEN3WTF10PassRefPtrINS_12SharedBufferEEEb
 __ZNK3JSC8Bindings10RootObject12globalObjectEv
 __ZNK3WTF6String14createCFStringEv
 __ZNK7WebCore10Credential11hasPasswordEv

Modified: trunk/Source/WebCore/platform/mac/FileSystemMac.mm (110493 => 110494)


--- trunk/Source/WebCore/platform/mac/FileSystemMac.mm	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebCore/platform/mac/FileSystemMac.mm	2012-03-12 22:45:47 UTC (rev 110494)
@@ -78,7 +78,7 @@
 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;
     

Modified: trunk/Source/WebKit2/ChangeLog (110493 => 110494)


--- trunk/Source/WebKit2/ChangeLog	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebKit2/ChangeLog	2012-03-12 22:45:47 UTC (rev 110494)
@@ -1,3 +1,39 @@
+2012-03-12  Enrica Casucci  <[email protected]>
+
+        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  <[email protected]>
 
         [Qt][WK2] Add support for rudimentary scroll indicators in MiniBrowser

Modified: trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h (110493 => 110494)


--- trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h	2012-03-12 22:45:47 UTC (rev 110494)
@@ -72,6 +72,8 @@
     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();
 

Modified: trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm (110493 => 110494)


--- trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm	2012-03-12 22:45:47 UTC (rev 110494)
@@ -37,12 +37,15 @@
 #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 @@
     [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];

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (110493 => 110494)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2012-03-12 22:45:47 UTC (rev 110494)
@@ -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>
@@ -71,7 +72,11 @@
 #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 @@
     // 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 @@
     _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]) {

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h (110493 => 110494)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h	2012-03-12 22:45:47 UTC (rev 110494)
@@ -35,6 +35,8 @@
 
 namespace WebCore {
     struct KeypressCommand;
+    class Image;
+    class SharedBuffer;
 }
 
 namespace WebKit {
@@ -78,6 +80,7 @@
 - (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;

Modified: trunk/Source/WebKit2/UIProcess/PageClient.h (110493 => 110494)


--- trunk/Source/WebKit2/UIProcess/PageClient.h	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebKit2/UIProcess/PageClient.h	2012-03-12 22:45:47 UTC (rev 110494)
@@ -137,6 +137,8 @@
     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;

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (110493 => 110494)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2012-03-12 22:45:47 UTC (rev 110494)
@@ -517,6 +517,8 @@
     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);

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (110493 => 110494)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2012-03-12 22:45:47 UTC (rev 110494)
@@ -227,6 +227,7 @@
     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)

Modified: trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm (110493 => 110494)


--- trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2012-03-12 22:45:47 UTC (rev 110494)
@@ -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 @@
     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())

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.cpp (110493 => 110494)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.cpp	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.cpp	2012-03-12 22:45:47 UTC (rev 110494)
@@ -58,12 +58,6 @@
 }
 #endif
 
-#if !PLATFORM(MAC)
-void WebDragClient::dragEnded()
-{
-}
-#endif
-
 void WebDragClient::dragControllerDestroyed()
 {
     delete this;

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.h (110493 => 110494)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.h	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.h	2012-03-12 22:45:47 UTC (rev 110494)
@@ -28,11 +28,6 @@
 
 #include <WebCore/DragClient.h>
 
-#if PLATFORM(MAC)
-OBJC_CLASS WKPasteboardFilePromiseOwner;
-OBJC_CLASS WKPasteboardOwner;
-#endif
-
 namespace WebKit {
 
 class WebPage;
@@ -56,16 +51,9 @@
     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

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm (110493 => 110494)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm	2012-03-12 22:45:47 UTC (rev 110494)
@@ -54,28 +54,6 @@
 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 @@
     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 @@
 
     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 = ""
-            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->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

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm (110493 => 110494)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm	2012-03-12 22:45:47 UTC (rev 110494)
@@ -115,6 +115,8 @@
         INIT(SetHTTPCookiesForURL);
         INIT(DeleteHTTPCookie);
 
+        INIT(SetMetadataURL);
+        
 #if !defined(BUILDING_ON_SNOW_LEOPARD)
         INIT(IOSurfaceContextCreate);
         INIT(IOSurfaceContextCreateImage);

Modified: trunk/WebKitLibraries/ChangeLog (110493 => 110494)


--- trunk/WebKitLibraries/ChangeLog	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/WebKitLibraries/ChangeLog	2012-03-12 22:45:47 UTC (rev 110494)
@@ -1,3 +1,13 @@
+2012-03-12  Enrica Casucci  <[email protected]>
+
+        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  <[email protected]>
 
         Add support for ENABLE(LEGACY_NOTIFICATIONS)

Modified: trunk/WebKitLibraries/WebKitSystemInterface.h (110493 => 110494)


--- trunk/WebKitLibraries/WebKitSystemInterface.h	2012-03-12 22:40:02 UTC (rev 110493)
+++ trunk/WebKitLibraries/WebKitSystemInterface.h	2012-03-12 22:45:47 UTC (rev 110494)
@@ -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.
 */

Modified: trunk/WebKitLibraries/libWebKitSystemInterfaceLeopard.a


(Binary files differ)

Modified: trunk/WebKitLibraries/libWebKitSystemInterfaceLion.a


(Binary files differ)

Modified: trunk/WebKitLibraries/libWebKitSystemInterfaceSnowLeopard.a


(Binary files differ)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to