Changeset 109022 in webkit


Ignore:
Timestamp:
Feb 27, 2012 2:03:41 PM (12 years ago)
Author:
enrica@apple.com
Message:

WebKit2: implement platform strategy to access Pasteboard in the UI process.
https://bugs.webkit.org/show_bug.cgi?id=79253
<rdar://problem/9971876>

Reviewed by Alexey Proskuryakov.

Source/WebCore:

No new tests. No behavior change.

  • platform/mac/PlatformPasteboardMac.mm:

(WebCore::PlatformPasteboard::bufferForType): There is no need
to create a SharedBuffer object if there is no NSData in the pasteboard
for the given pasteboard type.

Source/WebKit2:

  • UIProcess/WebContext.h:
  • UIProcess/WebContext.messages.in: Added messages to access NSPasteboard

in the UI process.

  • UIProcess/mac/WebContextMac.mm: Added methods corresponding to the

new messages.
(WebKit::WebContext::getPasteboardTypes):
(WebKit::WebContext::getPasteboardPathnamesForType):
(WebKit::WebContext::getPasteboardStringForType):
(WebKit::WebContext::getPasteboardBufferForType):
(WebKit::WebContext::pasteboardCopy):
(WebKit::WebContext::getPasteboardChangeCount):
(WebKit::WebContext::getPasteboardUniqueName):
(WebKit::WebContext::getPasteboardColor):
(WebKit::WebContext::setPasteboardTypes):
(WebKit::WebContext::setPasteboardPathnamesForType):
(WebKit::WebContext::setPasteboardStringForType):
(WebKit::WebContext::setPasteboardBufferForType):

  • WebProcess/WebCoreSupport/WebPlatformStrategies.cpp: New implementation of the PasteboardStrategy using message exchange

with the UI process.
(WebKit::WebPlatformStrategies::getTypes):
(WebKit::WebPlatformStrategies::bufferForType):
(WebKit::WebPlatformStrategies::getPathnamesForType):
(WebKit::WebPlatformStrategies::stringForType):
(WebKit::WebPlatformStrategies::copy):
(WebKit::WebPlatformStrategies::changeCount):
(WebKit::WebPlatformStrategies::uniqueName):
(WebKit::WebPlatformStrategies::color):
(WebKit::WebPlatformStrategies::setTypes):
(WebKit::WebPlatformStrategies::setBufferForType):
(WebKit::WebPlatformStrategies::setPathnamesForType):
(WebKit::WebPlatformStrategies::setStringForType):

Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r109020 r109022  
     12012-02-27  Enrica Casucci  <enrica@apple.com>
     2
     3        WebKit2: implement platform strategy to access Pasteboard in the UI process.
     4        https://bugs.webkit.org/show_bug.cgi?id=79253
     5        <rdar://problem/9971876>
     6
     7        Reviewed by Alexey Proskuryakov.
     8
     9        No new tests. No behavior change.
     10
     11        * platform/mac/PlatformPasteboardMac.mm:
     12        (WebCore::PlatformPasteboard::bufferForType): There is no need
     13        to create a SharedBuffer object if there is no NSData in the pasteboard
     14        for the given pasteboard type.
     15
    1162012-02-27  Adrienne Walker  <enne@google.com>
    217
  • trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm

    r108128 r109022  
    4646PassRefPtr<SharedBuffer> PlatformPasteboard::bufferForType(const String& pasteboardType)
    4747{
    48     return SharedBuffer::wrapNSData([[[m_pasteboard.get() dataForType:pasteboardType] copy] autorelease]);
     48    NSData *data = [m_pasteboard.get() dataForType:pasteboardType];
     49    if (!data)
     50        return 0;
     51    return SharedBuffer::wrapNSData([[data copy] autorelease]);
    4952}
    5053
  • trunk/Source/WebKit2/ChangeLog

    r109004 r109022  
     12012-02-27  Enrica Casucci  <enrica@apple.com>
     2
     3        WebKit2: implement platform strategy to access Pasteboard in the UI process.
     4        https://bugs.webkit.org/show_bug.cgi?id=79253
     5        <rdar://problem/9971876>
     6
     7        Reviewed by Alexey Proskuryakov.
     8
     9        * UIProcess/WebContext.h:
     10        * UIProcess/WebContext.messages.in: Added messages to access NSPasteboard
     11        in the UI process.
     12        * UIProcess/mac/WebContextMac.mm: Added methods corresponding to the
     13        new messages.
     14        (WebKit::WebContext::getPasteboardTypes):
     15        (WebKit::WebContext::getPasteboardPathnamesForType):
     16        (WebKit::WebContext::getPasteboardStringForType):
     17        (WebKit::WebContext::getPasteboardBufferForType):
     18        (WebKit::WebContext::pasteboardCopy):
     19        (WebKit::WebContext::getPasteboardChangeCount):
     20        (WebKit::WebContext::getPasteboardUniqueName):
     21        (WebKit::WebContext::getPasteboardColor):
     22        (WebKit::WebContext::setPasteboardTypes):
     23        (WebKit::WebContext::setPasteboardPathnamesForType):
     24        (WebKit::WebContext::setPasteboardStringForType):
     25        (WebKit::WebContext::setPasteboardBufferForType):
     26        * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp: New implementation of the PasteboardStrategy using message exchange
     27        with the UI process.
     28        (WebKit::WebPlatformStrategies::getTypes):
     29        (WebKit::WebPlatformStrategies::bufferForType):
     30        (WebKit::WebPlatformStrategies::getPathnamesForType):
     31        (WebKit::WebPlatformStrategies::stringForType):
     32        (WebKit::WebPlatformStrategies::copy):
     33        (WebKit::WebPlatformStrategies::changeCount):
     34        (WebKit::WebPlatformStrategies::uniqueName):
     35        (WebKit::WebPlatformStrategies::color):
     36        (WebKit::WebPlatformStrategies::setTypes):
     37        (WebKit::WebPlatformStrategies::setBufferForType):
     38        (WebKit::WebPlatformStrategies::setPathnamesForType):
     39        (WebKit::WebPlatformStrategies::setStringForType):
     40
    1412012-02-27  Dan Bernstein  <mitz@apple.com>
    242
  • trunk/Source/WebKit2/UIProcess/WebContext.h

    r103316 r109022  
    225225    void didClearPluginSiteData(uint64_t callbackID);
    226226#endif
    227    
     227
     228#if PLATFORM(MAC)
     229    void getPasteboardTypes(const String& pasteboardName, Vector<String>& pasteboardTypes);
     230    void getPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, Vector<String>& pathnames);
     231    void getPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, String&);
     232    void getPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, SharedMemory::Handle&, uint64_t& size);
     233    void pasteboardCopy(const String& fromPasteboard, const String& toPasteboard);
     234    void getPasteboardChangeCount(const String& pasteboardName, uint64_t& changeCount);
     235    void getPasteboardUniqueName(String& pasteboardName);
     236    void getPasteboardColor(const String& pasteboardName, WebCore::Color&);
     237    void setPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes);
     238    void setPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, const Vector<String>& pathnames);
     239    void setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String&);
     240    void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size);
     241#endif
     242
    228243    void didGetWebCoreStatistics(const StatisticsData&, uint64_t callbackID);
    229244       
  • trunk/Source/WebKit2/UIProcess/WebContext.messages.in

    r94115 r109022  
    4343    DidGetWebCoreStatistics(WebKit::StatisticsData statisticsData, uint64_t callbackID)
    4444
     45#if PLATFORM(MAC)
     46    # Pasteboard messages.
     47   
     48    GetPasteboardTypes(WTF::String pasteboardName) -> (Vector<WTF::String> types)
     49    GetPasteboardPathnamesForType(WTF::String pasteboardName, WTF::String pasteboardType) -> (Vector<WTF::String> pathnames)
     50    GetPasteboardStringForType(WTF::String pasteboardName, WTF::String pasteboardType) -> (WTF::String string)
     51    GetPasteboardBufferForType(WTF::String pasteboardName, WTF::String pasteboardType) -> (WebKit::SharedMemory::Handle handle, uint64_t size)
     52    PasteboardCopy(WTF::String fromPasteboard, WTF::String toPasteboard)
     53    GetPasteboardChangeCount(WTF::String pasteboardName) -> (uint64_t changeCount)
     54    GetPasteboardUniqueName() -> (WTF::String pasteboardName)
     55    GetPasteboardColor(WTF::String pasteboardName) -> (WebCore::Color color)
     56    SetPasteboardTypes(WTF::String pasteboardName, Vector<WTF::String> pasteboardTypes)
     57    SetPasteboardPathnamesForType(WTF::String pasteboardName, WTF::String pasteboardType, Vector<WTF::String> pathnames)
     58    SetPasteboardStringForType(WTF::String pasteboardName, WTF::String pasteboardType, WTF::String string)
     59    SetPasteboardBufferForType(WTF::String pasteboardName, WTF::String pasteboardType, WebKit::SharedMemory::Handle handle, uint64_t size)
     60#endif
    4561}
  • trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm

    r108946 r109022  
    2929#import "WebKitSystemInterface.h"
    3030#import "WebProcessCreationParameters.h"
     31#import <WebCore/Color.h>
    3132#import <WebCore/FileSystem.h>
     33#import <WebCore/PlatformPasteboard.h>
    3234#import <sys/param.h>
    3335
     
    156158}
    157159
     160void WebContext::getPasteboardTypes(const String& pasteboardName, Vector<String>& pasteboardTypes)
     161{
     162    PlatformPasteboard(pasteboardName).getTypes(pasteboardTypes);
     163}
     164
     165void WebContext::getPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, Vector<String>& pathnames)
     166{
     167    PlatformPasteboard(pasteboardName).getPathnamesForType(pathnames, pasteboardType);
     168}
     169
     170void WebContext::getPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, String& string)
     171{
     172    string = PlatformPasteboard(pasteboardName).stringForType(pasteboardType);
     173}
     174
     175void WebContext::getPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, SharedMemory::Handle& handle, uint64_t& size)
     176{
     177    RefPtr<SharedBuffer> buffer = PlatformPasteboard(pasteboardName).bufferForType(pasteboardType);
     178    if (!buffer)
     179        return;
     180    size = buffer->size();
     181    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(size);
     182    memcpy(sharedMemoryBuffer->data(), buffer->data(), size);
     183    sharedMemoryBuffer->createHandle(handle, SharedMemory::ReadOnly);
     184}
     185
     186void WebContext::pasteboardCopy(const String& fromPasteboard, const String& toPasteboard)
     187{
     188    PlatformPasteboard(toPasteboard).copy(fromPasteboard);
     189}
     190
     191void WebContext::getPasteboardChangeCount(const String& pasteboardName, uint64_t& changeCount)
     192{
     193    changeCount = PlatformPasteboard(pasteboardName).changeCount();
     194}
     195
     196void WebContext::getPasteboardUniqueName(String& pasteboardName)
     197{
     198    pasteboardName = PlatformPasteboard::uniqueName();
     199}
     200
     201void WebContext::getPasteboardColor(const String& pasteboardName, WebCore::Color& color)
     202{
     203    color = PlatformPasteboard(pasteboardName).color();   
     204}
     205
     206void WebContext::setPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes)
     207{
     208    PlatformPasteboard(pasteboardName).setTypes(pasteboardTypes);
     209}
     210
     211void WebContext::setPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, const Vector<String>& pathnames)
     212{
     213    PlatformPasteboard(pasteboardName).setPathnamesForType(pathnames, pasteboardType);
     214}
     215
     216void WebContext::setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String& string)
     217{
     218    PlatformPasteboard(pasteboardName).setStringForType(string, pasteboardType);   
     219}
     220
     221void WebContext::setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle& handle, uint64_t size)
     222{
     223    if (handle.isNull()) {
     224        PlatformPasteboard(pasteboardName).setBufferForType(0, pasteboardType);
     225        return;
     226    }
     227    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(handle, SharedMemory::ReadOnly);
     228    RefPtr<SharedBuffer> buffer = SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), size);
     229    PlatformPasteboard(pasteboardName).setBufferForType(buffer, pasteboardType);
     230}
     231
    158232} // namespace WebKit
    159233
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp

    r108101 r109022  
    138138void WebPlatformStrategies::getTypes(Vector<String>& types, const String& pasteboardName)
    139139{
    140     PlatformPasteboard(pasteboardName).getTypes(types);
     140    WebProcess::shared().connection()->sendSync(Messages::WebContext::GetPasteboardTypes(pasteboardName),
     141                                                Messages::WebContext::GetPasteboardTypes::Reply(types), 0);
    141142}
    142143
    143144PassRefPtr<WebCore::SharedBuffer> WebPlatformStrategies::bufferForType(const String& pasteboardType, const String& pasteboardName)
    144145{
    145     return PlatformPasteboard(pasteboardName).bufferForType(pasteboardType);
     146    SharedMemory::Handle handle;
     147    uint64_t size = 0;
     148    WebProcess::shared().connection()->sendSync(Messages::WebContext::GetPasteboardBufferForType(pasteboardName, pasteboardType),
     149                                                Messages::WebContext::GetPasteboardBufferForType::Reply(handle, size), 0);
     150    if (handle.isNull())
     151        return 0;
     152    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(handle, SharedMemory::ReadOnly);
     153    return SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), size);
    146154}
    147155
    148156void WebPlatformStrategies::getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName)
    149157{
    150     PlatformPasteboard(pasteboardName).getPathnamesForType(pathnames, pasteboardType);
     158    WebProcess::shared().connection()->sendSync(Messages::WebContext::GetPasteboardPathnamesForType(pasteboardName, pasteboardType),
     159                                                Messages::WebContext::GetPasteboardPathnamesForType::Reply(pathnames), 0);
    151160}
    152161
    153162String WebPlatformStrategies::stringForType(const String& pasteboardType, const String& pasteboardName)
    154163{
    155     return PlatformPasteboard(pasteboardName).stringForType(pasteboardType);
     164    String value;
     165    WebProcess::shared().connection()->sendSync(Messages::WebContext::GetPasteboardStringForType(pasteboardName, pasteboardType),
     166                                                Messages::WebContext::GetPasteboardStringForType::Reply(value), 0);
     167    return value;
    156168}
    157169
    158170void WebPlatformStrategies::copy(const String& fromPasteboard, const String& toPasteboard)
    159171{
    160     PlatformPasteboard(toPasteboard).copy(fromPasteboard);
     172    WebProcess::shared().connection()->send(Messages::WebContext::PasteboardCopy(fromPasteboard, toPasteboard), 0);
    161173}
    162174
    163175int WebPlatformStrategies::changeCount(const WTF::String &pasteboardName)
    164176{
    165     return PlatformPasteboard(pasteboardName).changeCount();
     177    uint64_t changeCount;
     178    WebProcess::shared().connection()->sendSync(Messages::WebContext::GetPasteboardChangeCount(pasteboardName),
     179                                                Messages::WebContext::GetPasteboardChangeCount::Reply(changeCount), 0);
     180    return changeCount;
    166181}
    167182
    168183String WebPlatformStrategies::uniqueName()
    169184{
    170     return PlatformPasteboard::uniqueName();
     185    String pasteboardName;
     186    WebProcess::shared().connection()->sendSync(Messages::WebContext::GetPasteboardUniqueName(),
     187                                                Messages::WebContext::GetPasteboardUniqueName::Reply(pasteboardName), 0);
     188    return pasteboardName;
    171189}
    172190
    173191Color WebPlatformStrategies::color(const String& pasteboardName)
    174192{
    175     return PlatformPasteboard(pasteboardName).color();   
     193    Color color;
     194    WebProcess::shared().connection()->sendSync(Messages::WebContext::GetPasteboardColor(pasteboardName),
     195                                                Messages::WebContext::GetPasteboardColor::Reply(color), 0);
     196    return color;
    176197}
    177198
    178199void WebPlatformStrategies::setTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName)
    179200{
    180     PlatformPasteboard(pasteboardName).setTypes(pasteboardTypes);
     201    WebProcess::shared().connection()->send(Messages::WebContext::SetPasteboardTypes(pasteboardName, pasteboardTypes), 0);
    181202}
    182203
    183204void WebPlatformStrategies::setBufferForType(PassRefPtr<SharedBuffer> buffer, const String& pasteboardType, const String& pasteboardName)
    184205{
    185     PlatformPasteboard(pasteboardName).setBufferForType(buffer, pasteboardType);
     206    SharedMemory::Handle handle;
     207    if (buffer) {
     208        RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(buffer->size());
     209        memcpy(sharedMemoryBuffer->data(), buffer->data(), buffer->size());
     210        sharedMemoryBuffer->createHandle(handle, SharedMemory::ReadOnly);
     211    }
     212    WebProcess::shared().connection()->send(Messages::WebContext::SetPasteboardBufferForType(pasteboardName, pasteboardType, handle, buffer ? buffer->size() : 0), 0);
    186213}
    187214
    188215void WebPlatformStrategies::setPathnamesForType(const Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName)
    189216{
    190     PlatformPasteboard(pasteboardName).setPathnamesForType(pathnames, pasteboardType);
     217    WebProcess::shared().connection()->send(Messages::WebContext::SetPasteboardPathnamesForType(pasteboardName, pasteboardType, pathnames), 0);
    191218}
    192219
    193220void WebPlatformStrategies::setStringForType(const String& string, const String& pasteboardType, const String& pasteboardName)
    194221{
    195     PlatformPasteboard(pasteboardName).setStringForType(string, pasteboardType);   
     222    WebProcess::shared().connection()->send(Messages::WebContext::SetPasteboardStringForType(pasteboardName, pasteboardType, string), 0);
    196223}
    197224#endif
Note: See TracChangeset for help on using the changeset viewer.