Title: [115145] trunk/Source
Revision
115145
Author
[email protected]
Date
2012-04-24 17:25:55 -0700 (Tue, 24 Apr 2012)

Log Message

REGRESSION (r109022) Safari not placing service data on pasteboard.
https://bugs.webkit.org/show_bug.cgi?id=84766
<rdar://problem/11085756>
        
The support for OS X services requires that the write operations to
the pasteboard occur synchronously. This behavior was changed with r109022.
This change removes the original synchronous call to the WebProcess to perform
the pasteboard write that had become asynchronous after r109022.
It implements instead a synchronous call to retrive the content to be placed
in the pasteboard.

Reviewed by Alexey Proskuryakov.

Source/WebCore: 

* WebCore.exp.in:
* editing/Editor.h:
* editing/mac/EditorMac.mm:
(WebCore::Editor::writeSelectionToPasteboard):
(WebCore::Editor::stringSelectionForPasteboard): Added.
(WebCore::Editor::dataSelectionForPasteboard): Added.
* platform/Pasteboard.h:
* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::getStringSelection): Added.
(WebCore::Pasteboard::getDataSelection): Added.
(WebCore::Pasteboard::writeSelectionForTypes):
(WebCore::Pasteboard::writeSelection):

Source/WebKit2: 

* UIProcess/API/mac/WKView.mm:
(-[WKView writeSelectionToPasteboard:types:]): Uses new methods.
* UIProcess/WebPageProxy.h:
* UIProcess/mac/WebPageProxyMac.mm: Removed writeSelectionToPasteboard.
(WebKit::WebPageProxy::getStringSelectionForPasteboard): Added.
(WebKit::WebPageProxy::getBufferSelectionForPasteboard): Added.
* WebProcess/WebPage/WebPage.h: Added support for the new messages and
removed old message.
* WebProcess/WebPage/WebPage.messages.in: Ditto.
* WebProcess/WebPage/mac/WebPageMac.mm: Ditto.
(WebKit::WebPage::readSelectionFromPasteboard): Added.
(WebKit::WebPage::getBufferSelectionForPasteboard): Added.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (115144 => 115145)


--- trunk/Source/WebCore/ChangeLog	2012-04-25 00:12:23 UTC (rev 115144)
+++ trunk/Source/WebCore/ChangeLog	2012-04-25 00:25:55 UTC (rev 115145)
@@ -1,3 +1,31 @@
+2012-04-24  Enrica Casucci  <[email protected]>
+
+        REGRESSION (r109022) Safari not placing service data on pasteboard.
+        https://bugs.webkit.org/show_bug.cgi?id=84766
+        <rdar://problem/11085756>
+        
+        The support for OS X services requires that the write operations to
+        the pasteboard occur synchronously. This behavior was changed with r109022.
+        This change removes the original synchronous call to the WebProcess to perform
+        the pasteboard write that had become asynchronous after r109022.
+        It implements instead a synchronous call to retrive the content to be placed
+        in the pasteboard.
+
+        Reviewed by Alexey Proskuryakov.
+
+        * WebCore.exp.in:
+        * editing/Editor.h:
+        * editing/mac/EditorMac.mm:
+        (WebCore::Editor::writeSelectionToPasteboard):
+        (WebCore::Editor::stringSelectionForPasteboard): Added.
+        (WebCore::Editor::dataSelectionForPasteboard): Added.
+        * platform/Pasteboard.h:
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::Pasteboard::getStringSelection): Added.
+        (WebCore::Pasteboard::getDataSelection): Added.
+        (WebCore::Pasteboard::writeSelectionForTypes):
+        (WebCore::Pasteboard::writeSelection):
+
 2012-04-24  Dana Jansens  <[email protected]>
 
         [chromium] Image masks are considered opaque incorrectly

Modified: trunk/Source/WebCore/WebCore.exp.in (115144 => 115145)


--- trunk/Source/WebCore/WebCore.exp.in	2012-04-25 00:12:23 UTC (rev 115144)
+++ trunk/Source/WebCore/WebCore.exp.in	2012-04-25 00:25:55 UTC (rev 115145)
@@ -887,11 +887,13 @@
 __ZN7WebCore6Editor24computeAndSetTypingStyleEPNS_16StylePropertySetENS_10EditActionE
 __ZN7WebCore6Editor24isSelectionUngrammaticalEv
 __ZN7WebCore6Editor24replaceSelectionWithTextERKN3WTF6StringEbb
+__ZN7WebCore6Editor26dataSelectionForPasteboardERKN3WTF6StringE
 __ZN7WebCore6Editor26decreaseSelectionListLevelEv
 __ZN7WebCore6Editor26increaseSelectionListLevelEv
 __ZN7WebCore6Editor26writeSelectionToPasteboardERKN3WTF6StringERKNS1_6VectorIS2_Lm0EEE
 __ZN7WebCore6Editor27readSelectionFromPasteboardERKN3WTF6StringE
 __ZN7WebCore6Editor28replaceSelectionWithFragmentEN3WTF10PassRefPtrINS_16DocumentFragmentEEEbbb
+__ZN7WebCore6Editor28stringSelectionForPasteboardEv
 __ZN7WebCore6Editor29canDecreaseSelectionListLevelEv
 __ZN7WebCore6Editor29canIncreaseSelectionListLevelEv
 __ZN7WebCore6Editor29handleAlternativeTextUIResultERKN3WTF6StringE

Modified: trunk/Source/WebCore/editing/Editor.h (115144 => 115145)


--- trunk/Source/WebCore/editing/Editor.h	2012-04-25 00:12:23 UTC (rev 115144)
+++ trunk/Source/WebCore/editing/Editor.h	2012-04-25 00:25:55 UTC (rev 115145)
@@ -376,6 +376,8 @@
     void takeFindStringFromSelection();
     void writeSelectionToPasteboard(const String& pasteboardName, const Vector<String>& pasteboardTypes);
     void readSelectionFromPasteboard(const String& pasteboardName);
+    String stringSelectionForPasteboard();
+    PassRefPtr<SharedBuffer> dataSelectionForPasteboard(const String& pasteboardName);
 #endif
 
     void replaceSelectionWithFragment(PassRefPtr<DocumentFragment>, bool selectReplacement, bool smartReplace, bool matchStyle);

Modified: trunk/Source/WebCore/editing/mac/EditorMac.mm (115144 => 115145)


--- trunk/Source/WebCore/editing/mac/EditorMac.mm	2012-04-25 00:12:23 UTC (rev 115144)
+++ trunk/Source/WebCore/editing/mac/EditorMac.mm	2012-04-25 00:25:55 UTC (rev 115145)
@@ -30,19 +30,24 @@
 #import "ClipboardMac.h"
 #import "CachedResourceLoader.h"
 #import "DocumentFragment.h"
+#import "DOMRangeInternal.h"
 #import "EditingText.h"
 #import "Editor.h"
 #import "EditorClient.h"
 #import "Frame.h"
 #import "FrameView.h"
+#import "HTMLConverter.h"
 #import "HTMLNames.h"
+#import "LegacyWebArchive.h"
 #import "Pasteboard.h"
 #import "PasteboardStrategy.h"
 #import "PlatformStrategies.h"
+#import "Range.h"
 #import "RenderBlock.h"
 #import "RuntimeApplicationChecks.h"
 #import "Sound.h"
 #import "htmlediting.h"
+#import "WebNSAttributedStringExtras.h"
 
 namespace WebCore {
 
@@ -291,7 +296,7 @@
 void Editor::writeSelectionToPasteboard(const String& pasteboardName, const Vector<String>& pasteboardTypes)
 {
     Pasteboard pasteboard(pasteboardName);
-    pasteboard.writeSelectionForTypes(pasteboardTypes, selectedRange().get(), true, m_frame);
+    pasteboard.writeSelectionForTypes(pasteboardTypes, true, m_frame);
 }
     
 void Editor::readSelectionFromPasteboard(const String& pasteboardName)
@@ -303,4 +308,14 @@
         pasteAsPlainTextWithPasteboard(&pasteboard);   
 }
 
+String Editor::stringSelectionForPasteboard()
+{
+    return Pasteboard::getStringSelection(m_frame);
+}
+
+PassRefPtr<SharedBuffer> Editor::dataSelectionForPasteboard(const String& pasteboardType)
+{
+    return Pasteboard::getDataSelection(m_frame, pasteboardType);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/Pasteboard.h (115144 => 115145)


--- trunk/Source/WebCore/platform/Pasteboard.h	2012-04-25 00:12:23 UTC (rev 115144)
+++ trunk/Source/WebCore/platform/Pasteboard.h	2012-04-25 00:25:55 UTC (rev 115145)
@@ -43,6 +43,7 @@
 // knowledge of the frame and editor or moved into the editing directory.
 
 #if PLATFORM(MAC)
+OBJC_CLASS NSAttributedString;
 OBJC_CLASS NSFileWrapper;
 OBJC_CLASS NSArray;
 #endif
@@ -66,6 +67,7 @@
 extern const char* WebURLsWithTitlesPboardType;
 #endif
 
+    class ArchiveResource;
 class Clipboard;
 class DocumentFragment;
 class Frame;
@@ -73,15 +75,17 @@
 class KURL;
 class Node;
 class Range;
-class ArchiveResource;
+class SharedBuffer;
     
 class Pasteboard {
     WTF_MAKE_NONCOPYABLE(Pasteboard); WTF_MAKE_FAST_ALLOCATED;
 public:
 #if PLATFORM(MAC)
     // This is required to support OS X services.
-    void writeSelectionForTypes(const Vector<String>& pasteboardTypes, Range* selectedRange, bool canSmartCopyOrDelete, Frame*);
+    void writeSelectionForTypes(const Vector<String>& pasteboardTypes, bool canSmartCopyOrDelete, Frame*);
     Pasteboard(const String& pasteboardName);
+    static String getStringSelection(Frame*);
+    static PassRefPtr<SharedBuffer> getDataSelection(Frame*, const String& pasteboardType);
 #endif
     
     static Pasteboard* generalPasteboard();

Modified: trunk/Source/WebCore/platform/mac/PasteboardMac.mm (115144 => 115145)


--- trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2012-04-25 00:12:23 UTC (rev 115144)
+++ trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2012-04-25 00:25:55 UTC (rev 115145)
@@ -133,63 +133,72 @@
     platformStrategies()->pasteboardStrategy()->setTypes(Vector<String>(), m_pasteboardName);
 }
 
-void Pasteboard::writeSelectionForTypes(const Vector<String>& pasteboardTypes, Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
+String Pasteboard::getStringSelection(Frame* frame)
 {
-    if (!WebArchivePboardType)
-        Pasteboard::generalPasteboard(); // Initializes pasteboard types.
-    ASSERT(selectedRange);
-    
-    // If the selection is at the beginning of content inside an anchor tag
-    // we move the selection start to include the anchor.
-    // This way the attributed string will contain the url attribute as well.
-    // See <rdar://problem/9084267>.
+    String text = frame->editor()->selectedText();
+    text.replace(noBreakSpace, ' ');
+    return text;
+}
+
+PassRefPtr<SharedBuffer> Pasteboard::getDataSelection(Frame* frame, const String& pasteboardType)
+{
+    if (pasteboardType == WebArchivePboardType) {
+        RefPtr<LegacyWebArchive> archive = LegacyWebArchive::createFromSelection(frame);
+        RetainPtr<CFDataRef> data = "" ? archive->rawDataRepresentation() : 0;
+        return SharedBuffer::wrapNSData((NSData *)data.get());
+    }
+
     ExceptionCode ec;
-    Node* commonAncestor = selectedRange->commonAncestorContainer(ec);
+    RefPtr<Range> range = frame->editor()->selectedRange();
+    Node* commonAncestor = range->commonAncestorContainer(ec);
     ASSERT(commonAncestor);
     Node* enclosingAnchor = enclosingNodeWithTag(firstPositionInNode(commonAncestor), HTMLNames::aTag);
-    if (enclosingAnchor && comparePositions(firstPositionInOrBeforeNode(selectedRange->startPosition().anchorNode()), selectedRange->startPosition()) >= 0)
-        selectedRange->setStart(enclosingAnchor, 0, ec);
+    if (enclosingAnchor && comparePositions(firstPositionInOrBeforeNode(range->startPosition().anchorNode()), range->startPosition()) >= 0)
+        range->setStart(enclosingAnchor, 0, ec);
+    
+    NSAttributedString* attributedString;
+    RetainPtr<WebHTMLConverter> converter(AdoptNS, [[WebHTMLConverter alloc] initWithDOMRange:kit(range.get())]);
+    if (converter)
+        attributedString = [converter.get() attributedString];
+    
+    if (pasteboardType == String(NSRTFDPboardType)) {
+        NSData *RTFDData = [attributedString RTFDFromRange:NSMakeRange(0, [attributedString length]) documentAttributes:nil];
+        return SharedBuffer::wrapNSData((NSData *)RTFDData);
+    }
+    if (pasteboardType == String(NSRTFPboardType)) {
+        if ([attributedString containsAttachments])
+            attributedString = attributedStringByStrippingAttachmentCharacters(attributedString);
+        NSData *RTFData = [attributedString RTFFromRange:NSMakeRange(0, [attributedString length]) documentAttributes:nil];
+        return SharedBuffer::wrapNSData((NSData *)RTFData);
+    }
+    return 0;
+}
 
-    NSAttributedString *attributedString = nil;
-    RetainPtr<WebHTMLConverter> converter(AdoptNS, [[WebHTMLConverter alloc] initWithDOMRange:kit(selectedRange)]);
+void Pasteboard::writeSelectionForTypes(const Vector<String>& pasteboardTypes, bool canSmartCopyOrDelete, Frame* frame)
+{
+    NSAttributedString* attributedString;
+    RetainPtr<WebHTMLConverter> converter(AdoptNS, [[WebHTMLConverter alloc] initWithDOMRange:kit(frame->editor()->selectedRange().get())]);
     if (converter)
         attributedString = [converter.get() attributedString];
-
+    
     const Vector<String> types = !pasteboardTypes.isEmpty() ? pasteboardTypes : selectionPasteboardTypes(canSmartCopyOrDelete, [attributedString containsAttachments]);
     platformStrategies()->pasteboardStrategy()->setTypes(types, m_pasteboardName);
     frame->editor()->client()->didSetSelectionTypesForPasteboard();
     
     // Put HTML on the pasteboard.
-    if (types.contains(WebArchivePboardType)) {
-        RefPtr<LegacyWebArchive> archive = LegacyWebArchive::createFromSelection(frame);
-        RetainPtr<CFDataRef> data = "" ? archive->rawDataRepresentation() : 0;
-        platformStrategies()->pasteboardStrategy()->setBufferForType(SharedBuffer::wrapNSData((NSData *)data.get()), WebArchivePboardType, m_pasteboardName);
-    }
+    if (types.contains(WebArchivePboardType))
+        platformStrategies()->pasteboardStrategy()->setBufferForType(getDataSelection(frame, WebArchivePboardType), WebArchivePboardType, m_pasteboardName);
     
     // Put the attributed string on the pasteboard (RTF/RTFD format).
-    if (types.contains(String(NSRTFDPboardType))) {
-        NSData *RTFDData = [attributedString RTFDFromRange:NSMakeRange(0, [attributedString length]) documentAttributes:nil];
-        platformStrategies()->pasteboardStrategy()->setBufferForType(SharedBuffer::wrapNSData((NSData *)RTFDData).get(), NSRTFDPboardType, m_pasteboardName);
-    }
-    if (types.contains(String(NSRTFPboardType))) {
-        if ([attributedString containsAttachments])
-            attributedString = attributedStringByStrippingAttachmentCharacters(attributedString);
-        NSData *RTFData = [attributedString RTFFromRange:NSMakeRange(0, [attributedString length]) documentAttributes:nil];
-        platformStrategies()->pasteboardStrategy()->setBufferForType(SharedBuffer::wrapNSData((NSData *)RTFData).get(), NSRTFPboardType, m_pasteboardName);
-    }
+    if (types.contains(String(NSRTFDPboardType)))
+        platformStrategies()->pasteboardStrategy()->setBufferForType(getDataSelection(frame, NSRTFDPboardType), NSRTFDPboardType, m_pasteboardName);
+
+    if (types.contains(String(NSRTFPboardType)))
+        platformStrategies()->pasteboardStrategy()->setBufferForType(getDataSelection(frame, NSRTFPboardType), NSRTFPboardType, m_pasteboardName);
     
     // Put plain string on the pasteboard.
-    if (types.contains(String(NSStringPboardType))) {
-        // Map &nbsp; to a plain old space because this is better for source code, other browsers do it,
-        // and because HTML forces you to do this any time you want two spaces in a row.
-        String text = frame->editor()->selectedText();
-        NSMutableString *s = [[[(NSString*)text copy] autorelease] mutableCopy];
-        
-        NSString *NonBreakingSpaceString = [NSString stringWithCharacters:&noBreakSpace length:1];
-        [s replaceOccurrencesOfString:NonBreakingSpaceString withString:@" " options:0 range:NSMakeRange(0, [s length])];
-        platformStrategies()->pasteboardStrategy()->setStringForType(s, NSStringPboardType, m_pasteboardName);
-        [s release];
-    }
+    if (types.contains(String(NSStringPboardType)))
+        platformStrategies()->pasteboardStrategy()->setStringForType(getStringSelection(frame), NSStringPboardType, m_pasteboardName);
     
     if (types.contains(WebSmartPastePboardType))
         platformStrategies()->pasteboardStrategy()->setBufferForType(0, WebSmartPastePboardType, m_pasteboardName);
@@ -203,9 +212,9 @@
     platformStrategies()->pasteboardStrategy()->setStringForType(text, NSStringPboardType, m_pasteboardName);
 }
     
-void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
+void Pasteboard::writeSelection(Range*, bool canSmartCopyOrDelete, Frame* frame)
 {
-    writeSelectionForTypes(Vector<String>(), selectedRange, canSmartCopyOrDelete, frame);
+    writeSelectionForTypes(Vector<String>(), canSmartCopyOrDelete, frame);
 }
 
 static void writeURLForTypes(const Vector<String>& types, const String& pasteboardName, const KURL& url, const String& titleStr, Frame* frame)

Modified: trunk/Source/WebKit2/ChangeLog (115144 => 115145)


--- trunk/Source/WebKit2/ChangeLog	2012-04-25 00:12:23 UTC (rev 115144)
+++ trunk/Source/WebKit2/ChangeLog	2012-04-25 00:25:55 UTC (rev 115145)
@@ -1,3 +1,31 @@
+2012-04-24  Enrica Casucci  <[email protected]>
+
+        REGRESSION (r109022) Safari not placing service data on pasteboard.
+        https://bugs.webkit.org/show_bug.cgi?id=84766
+        <rdar://problem/11085756>
+        
+        The support for OS X services requires that the write operations to
+        the pasteboard occur synchronously. This behavior was changed with r109022.
+        This change removes the original synchronous call to the WebProcess to perform
+        the pasteboard write that had become asynchronous after r109022.
+        It implements instead a synchronous call to retrive the content to be placed
+        in the pasteboard.
+
+        Reviewed by Alexey Proskuryakov.
+
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView writeSelectionToPasteboard:types:]): Uses new methods.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/mac/WebPageProxyMac.mm: Removed writeSelectionToPasteboard.
+        (WebKit::WebPageProxy::getStringSelectionForPasteboard): Added.
+        (WebKit::WebPageProxy::getBufferSelectionForPasteboard): Added.
+        * WebProcess/WebPage/WebPage.h: Added support for the new messages and
+        removed old message.
+        * WebProcess/WebPage/WebPage.messages.in: Ditto.
+        * WebProcess/WebPage/mac/WebPageMac.mm: Ditto.
+        (WebKit::WebPage::readSelectionFromPasteboard): Added.
+        (WebKit::WebPage::getBufferSelectionForPasteboard): Added.
+
 2012-04-24  Brady Eidson  <[email protected]>
 
         Fix Windows build.

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


--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2012-04-25 00:12:23 UTC (rev 115144)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2012-04-25 00:25:55 UTC (rev 115145)
@@ -537,11 +537,17 @@
 
 - (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pasteboard types:(NSArray *)types
 {
-    Vector<String> pasteboardTypes;
     size_t numTypes = [types count];
-    for (size_t i = 0; i < numTypes; ++i)
-        pasteboardTypes.append([types objectAtIndex:i]);
-    return _data->_page->writeSelectionToPasteboard([pasteboard name], pasteboardTypes);
+    [pasteboard declareTypes:types owner:nil];
+    for (size_t i = 0; i < numTypes; ++i) {
+        if ([[types objectAtIndex:i] isEqualTo:NSStringPboardType])
+            [pasteboard setString:_data->_page->stringSelectionForPasteboard() forType:NSStringPboardType];
+        else {
+            RefPtr<SharedBuffer> buffer = _data->_page->dataSelectionForPasteboard([types objectAtIndex:i]);
+            [pasteboard setData:buffer ? [buffer->createNSData() autorelease] : nil forType:[types objectAtIndex:i]];
+       }
+    }
+    return YES;
 }
 
 - (void)centerSelectionInVisibleArea:(id)sender 

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (115144 => 115145)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2012-04-25 00:12:23 UTC (rev 115144)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2012-04-25 00:25:55 UTC (rev 115145)
@@ -468,8 +468,9 @@
     void registerWebProcessAccessibilityToken(const CoreIPC::DataReference&);
     // Called by the UI process when it is ready to send its tokens to the web process.
     void registerUIProcessAccessibilityTokens(const CoreIPC::DataReference& elemenToken, const CoreIPC::DataReference& windowToken);
-    bool writeSelectionToPasteboard(const String& pasteboardName, const Vector<String>& pasteboardTypes);
     bool readSelectionFromPasteboard(const String& pasteboardName);
+    String stringSelectionForPasteboard();
+    PassRefPtr<WebCore::SharedBuffer> dataSelectionForPasteboard(const String& pasteboardType);
     void makeFirstResponder();
 #endif
 

Modified: trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm (115144 => 115145)


--- trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2012-04-25 00:12:23 UTC (rev 115144)
+++ trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2012-04-25 00:25:55 UTC (rev 115145)
@@ -257,15 +257,30 @@
     return result;
 }
 
-bool WebPageProxy::writeSelectionToPasteboard(const String& pasteboardName, const Vector<String>& pasteboardTypes)
+String WebPageProxy::stringSelectionForPasteboard()
 {
+    String value;
     if (!isValid())
-        return false;
+        return value;
+    
+    const double messageTimeout = 20;
+    process()->sendSync(Messages::WebPage::GetStringSelectionForPasteboard(), Messages::WebPage::GetStringSelectionForPasteboard::Reply(value), m_pageID, messageTimeout);
+    return value;
+}
 
-    bool result = false;
+PassRefPtr<WebCore::SharedBuffer> WebPageProxy::dataSelectionForPasteboard(const String& pasteboardType)
+{
+    if (!isValid())
+        return 0;
+    SharedMemory::Handle handle;
+    uint64_t size = 0;
     const double messageTimeout = 20;
-    process()->sendSync(Messages::WebPage::WriteSelectionToPasteboard(pasteboardName, pasteboardTypes), Messages::WebPage::WriteSelectionToPasteboard::Reply(result), m_pageID, messageTimeout);
-    return result;
+    process()->sendSync(Messages::WebPage::GetDataSelectionForPasteboard(pasteboardType),
+                                                Messages::WebPage::GetDataSelectionForPasteboard::Reply(handle, size), m_pageID, messageTimeout);
+    if (handle.isNull())
+        return 0;
+    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(handle, SharedMemory::ReadOnly);
+    return SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), size);
 }
 
 bool WebPageProxy::readSelectionFromPasteboard(const String& pasteboardName)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (115144 => 115145)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2012-04-25 00:12:23 UTC (rev 115144)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2012-04-25 00:25:55 UTC (rev 115145)
@@ -409,8 +409,9 @@
     void characterIndexForPoint(const WebCore::IntPoint point, uint64_t& result);
     void firstRectForCharacterRange(uint64_t location, uint64_t length, WebCore::IntRect& resultRect);
     void executeKeypressCommands(const Vector<WebCore::KeypressCommand>&, bool& handled, EditorState& newState);
-    void writeSelectionToPasteboard(const WTF::String& pasteboardName, const WTF::Vector<WTF::String>& pasteboardTypes, bool& result);
     void readSelectionFromPasteboard(const WTF::String& pasteboardName, bool& result);
+    void getStringSelectionForPasteboard(WTF::String& stringValue);
+    void getDataSelectionForPasteboard(const WTF::String pasteboardType, SharedMemory::Handle& handle, uint64_t& size);
     void shouldDelayWindowOrderingEvent(const WebKit::WebMouseEvent&, bool& result);
     void acceptsFirstMouse(int eventNumber, const WebKit::WebMouseEvent&, bool& result);
     bool performNonEditingBehaviorForSelector(const String&);

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (115144 => 115145)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2012-04-25 00:12:23 UTC (rev 115144)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2012-04-25 00:25:55 UTC (rev 115145)
@@ -229,7 +229,8 @@
     SetWindowIsVisible(bool windowIsVisible)
     WindowAndViewFramesChanged(WebCore::IntRect windowFrameInScreenCoordinates, WebCore::IntRect viewFrameInWindowCoordinates, WebCore::IntPoint accessibilityViewCoordinates)
     RegisterUIProcessAccessibilityTokens(CoreIPC::DataReference elemenToken, CoreIPC::DataReference windowToken)
-    WriteSelectionToPasteboard(WTF::String pasteboardName, WTF::Vector<WTF::String> pasteboardTypes) -> (bool result)
+    GetStringSelectionForPasteboard() -> (WTF::String stringValue)
+    GetDataSelectionForPasteboard(WTF::String pasteboardType) -> (WebKit::SharedMemory::Handle handle, uint64_t size)
     ReadSelectionFromPasteboard(WTF::String pasteboardName) -> (bool result)
 
     # Text input.

Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (115144 => 115145)


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2012-04-25 00:12:23 UTC (rev 115144)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2012-04-25 00:25:55 UTC (rev 115145)
@@ -608,28 +608,43 @@
     [accessibilityRemoteObject() setRemoteParent:remoteElement];
 }
 
-void WebPage::writeSelectionToPasteboard(const String& pasteboardName, const Vector<String>& pasteboardTypes, bool& result)
+void WebPage::readSelectionFromPasteboard(const String& pasteboardName, bool& result)
 {
     Frame* frame = m_page->focusController()->focusedOrMainFrame();
     if (!frame || frame->selection()->isNone()) {
         result = false;
         return;
     }
-    frame->editor()->writeSelectionToPasteboard(pasteboardName, pasteboardTypes);
+    frame->editor()->readSelectionFromPasteboard(pasteboardName);
     result = true;
 }
 
-void WebPage::readSelectionFromPasteboard(const String& pasteboardName, bool& result)
+void WebPage::getStringSelectionForPasteboard(String& stringValue)
 {
     Frame* frame = m_page->focusController()->focusedOrMainFrame();
-    if (!frame || frame->selection()->isNone()) {
-        result = false;
+    if (!frame || frame->selection()->isNone())
         return;
+
+    stringValue = frame->editor()->stringSelectionForPasteboard();
+}
+
+void WebPage::getDataSelectionForPasteboard(const String pasteboardType, SharedMemory::Handle& handle, uint64_t& size)
+{
+    Frame* frame = m_page->focusController()->focusedOrMainFrame();
+    if (!frame || frame->selection()->isNone())
+        return;
+
+    RefPtr<SharedBuffer> buffer = frame->editor()->dataSelectionForPasteboard(pasteboardType);
+    if (!buffer) {
+        size = 0;
+        return;
     }
-    frame->editor()->readSelectionFromPasteboard(pasteboardName);
-    result = true;
+    size = buffer->size();
+    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(size);
+    memcpy(sharedMemoryBuffer->data(), buffer->data(), size);
+    sharedMemoryBuffer->createHandle(handle, SharedMemory::ReadOnly);
 }
-    
+
 WKAccessibilityWebPageObject* WebPage::accessibilityRemoteObject()
 {
     return m_mockAccessibilityElement.get();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to