Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
WebKit2: implement platform strategy to access Pasteboard in the UI p…
…rocess.

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):



Canonical link: https://commits.webkit.org/96789@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@109022 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Enrica Casucci committed Feb 27, 2012
1 parent 2481c68 commit 7940383
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 14 deletions.
15 changes: 15 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,18 @@
2012-02-27 Enrica Casucci <enrica@apple.com>

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.

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.

2012-02-27 Adrienne Walker <enne@google.com>

[chromium] Unreviewed speculative Chromium win build fix.
Expand Down
5 changes: 4 additions & 1 deletion Source/WebCore/platform/mac/PlatformPasteboardMac.mm
Expand Up @@ -45,7 +45,10 @@

PassRefPtr<SharedBuffer> PlatformPasteboard::bufferForType(const String& pasteboardType)
{
return SharedBuffer::wrapNSData([[[m_pasteboard.get() dataForType:pasteboardType] copy] autorelease]);
NSData *data = [m_pasteboard.get() dataForType:pasteboardType];
if (!data)
return 0;
return SharedBuffer::wrapNSData([[data copy] autorelease]);
}

void PlatformPasteboard::getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType)
Expand Down
40 changes: 40 additions & 0 deletions Source/WebKit2/ChangeLog
@@ -1,3 +1,43 @@
2012-02-27 Enrica Casucci <enrica@apple.com>

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.

* 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):

2012-02-27 Dan Bernstein <mitz@apple.com>

<rdar://problem/9557598> REGRESSION (WebKit2): Non-activating links sometimes don’t work
Expand Down
17 changes: 16 additions & 1 deletion Source/WebKit2/UIProcess/WebContext.h
Expand Up @@ -224,7 +224,22 @@ class WebContext : public APIObject {
void didGetSitesWithPluginData(const Vector<String>& sites, uint64_t callbackID);
void didClearPluginSiteData(uint64_t callbackID);
#endif


#if PLATFORM(MAC)
void getPasteboardTypes(const String& pasteboardName, Vector<String>& pasteboardTypes);
void getPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, Vector<String>& pathnames);
void getPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, String&);
void getPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, SharedMemory::Handle&, uint64_t& size);
void pasteboardCopy(const String& fromPasteboard, const String& toPasteboard);
void getPasteboardChangeCount(const String& pasteboardName, uint64_t& changeCount);
void getPasteboardUniqueName(String& pasteboardName);
void getPasteboardColor(const String& pasteboardName, WebCore::Color&);
void setPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes);
void setPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, const Vector<String>& pathnames);
void setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String&);
void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size);
#endif

void didGetWebCoreStatistics(const StatisticsData&, uint64_t callbackID);

// Implemented in generated WebContextMessageReceiver.cpp
Expand Down
16 changes: 16 additions & 0 deletions Source/WebKit2/UIProcess/WebContext.messages.in
Expand Up @@ -42,4 +42,20 @@ messages -> WebContext {

DidGetWebCoreStatistics(WebKit::StatisticsData statisticsData, uint64_t callbackID)

#if PLATFORM(MAC)
# Pasteboard messages.

GetPasteboardTypes(WTF::String pasteboardName) -> (Vector<WTF::String> types)
GetPasteboardPathnamesForType(WTF::String pasteboardName, WTF::String pasteboardType) -> (Vector<WTF::String> pathnames)
GetPasteboardStringForType(WTF::String pasteboardName, WTF::String pasteboardType) -> (WTF::String string)
GetPasteboardBufferForType(WTF::String pasteboardName, WTF::String pasteboardType) -> (WebKit::SharedMemory::Handle handle, uint64_t size)
PasteboardCopy(WTF::String fromPasteboard, WTF::String toPasteboard)
GetPasteboardChangeCount(WTF::String pasteboardName) -> (uint64_t changeCount)
GetPasteboardUniqueName() -> (WTF::String pasteboardName)
GetPasteboardColor(WTF::String pasteboardName) -> (WebCore::Color color)
SetPasteboardTypes(WTF::String pasteboardName, Vector<WTF::String> pasteboardTypes)
SetPasteboardPathnamesForType(WTF::String pasteboardName, WTF::String pasteboardType, Vector<WTF::String> pathnames)
SetPasteboardStringForType(WTF::String pasteboardName, WTF::String pasteboardType, WTF::String string)
SetPasteboardBufferForType(WTF::String pasteboardName, WTF::String pasteboardType, WebKit::SharedMemory::Handle handle, uint64_t size)
#endif
}
74 changes: 74 additions & 0 deletions Source/WebKit2/UIProcess/mac/WebContextMac.mm
Expand Up @@ -28,7 +28,9 @@

#import "WebKitSystemInterface.h"
#import "WebProcessCreationParameters.h"
#import <WebCore/Color.h>
#import <WebCore/FileSystem.h>
#import <WebCore/PlatformPasteboard.h>
#import <sys/param.h>

#if !defined(BUILDING_ON_SNOW_LEOPARD)
Expand Down Expand Up @@ -155,5 +157,77 @@
return [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitOmitPDFSupport"];
}

void WebContext::getPasteboardTypes(const String& pasteboardName, Vector<String>& pasteboardTypes)
{
PlatformPasteboard(pasteboardName).getTypes(pasteboardTypes);
}

void WebContext::getPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, Vector<String>& pathnames)
{
PlatformPasteboard(pasteboardName).getPathnamesForType(pathnames, pasteboardType);
}

void WebContext::getPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, String& string)
{
string = PlatformPasteboard(pasteboardName).stringForType(pasteboardType);
}

void WebContext::getPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, SharedMemory::Handle& handle, uint64_t& size)
{
RefPtr<SharedBuffer> buffer = PlatformPasteboard(pasteboardName).bufferForType(pasteboardType);
if (!buffer)
return;
size = buffer->size();
RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(size);
memcpy(sharedMemoryBuffer->data(), buffer->data(), size);
sharedMemoryBuffer->createHandle(handle, SharedMemory::ReadOnly);
}

void WebContext::pasteboardCopy(const String& fromPasteboard, const String& toPasteboard)
{
PlatformPasteboard(toPasteboard).copy(fromPasteboard);
}

void WebContext::getPasteboardChangeCount(const String& pasteboardName, uint64_t& changeCount)
{
changeCount = PlatformPasteboard(pasteboardName).changeCount();
}

void WebContext::getPasteboardUniqueName(String& pasteboardName)
{
pasteboardName = PlatformPasteboard::uniqueName();
}

void WebContext::getPasteboardColor(const String& pasteboardName, WebCore::Color& color)
{
color = PlatformPasteboard(pasteboardName).color();
}

void WebContext::setPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes)
{
PlatformPasteboard(pasteboardName).setTypes(pasteboardTypes);
}

void WebContext::setPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, const Vector<String>& pathnames)
{
PlatformPasteboard(pasteboardName).setPathnamesForType(pathnames, pasteboardType);
}

void WebContext::setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String& string)
{
PlatformPasteboard(pasteboardName).setStringForType(string, pasteboardType);
}

void WebContext::setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle& handle, uint64_t size)
{
if (handle.isNull()) {
PlatformPasteboard(pasteboardName).setBufferForType(0, pasteboardType);
return;
}
RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(handle, SharedMemory::ReadOnly);
RefPtr<SharedBuffer> buffer = SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), size);
PlatformPasteboard(pasteboardName).setBufferForType(buffer, pasteboardType);
}

} // namespace WebKit

51 changes: 39 additions & 12 deletions Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp
Expand Up @@ -137,62 +137,89 @@ void WebPlatformStrategies::addVisitedLink(Page*, LinkHash linkHash)

void WebPlatformStrategies::getTypes(Vector<String>& types, const String& pasteboardName)
{
PlatformPasteboard(pasteboardName).getTypes(types);
WebProcess::shared().connection()->sendSync(Messages::WebContext::GetPasteboardTypes(pasteboardName),
Messages::WebContext::GetPasteboardTypes::Reply(types), 0);
}

PassRefPtr<WebCore::SharedBuffer> WebPlatformStrategies::bufferForType(const String& pasteboardType, const String& pasteboardName)
{
return PlatformPasteboard(pasteboardName).bufferForType(pasteboardType);
SharedMemory::Handle handle;
uint64_t size = 0;
WebProcess::shared().connection()->sendSync(Messages::WebContext::GetPasteboardBufferForType(pasteboardName, pasteboardType),
Messages::WebContext::GetPasteboardBufferForType::Reply(handle, size), 0);
if (handle.isNull())
return 0;
RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(handle, SharedMemory::ReadOnly);
return SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), size);
}

void WebPlatformStrategies::getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName)
{
PlatformPasteboard(pasteboardName).getPathnamesForType(pathnames, pasteboardType);
WebProcess::shared().connection()->sendSync(Messages::WebContext::GetPasteboardPathnamesForType(pasteboardName, pasteboardType),
Messages::WebContext::GetPasteboardPathnamesForType::Reply(pathnames), 0);
}

String WebPlatformStrategies::stringForType(const String& pasteboardType, const String& pasteboardName)
{
return PlatformPasteboard(pasteboardName).stringForType(pasteboardType);
String value;
WebProcess::shared().connection()->sendSync(Messages::WebContext::GetPasteboardStringForType(pasteboardName, pasteboardType),
Messages::WebContext::GetPasteboardStringForType::Reply(value), 0);
return value;
}

void WebPlatformStrategies::copy(const String& fromPasteboard, const String& toPasteboard)
{
PlatformPasteboard(toPasteboard).copy(fromPasteboard);
WebProcess::shared().connection()->send(Messages::WebContext::PasteboardCopy(fromPasteboard, toPasteboard), 0);
}

int WebPlatformStrategies::changeCount(const WTF::String &pasteboardName)
{
return PlatformPasteboard(pasteboardName).changeCount();
uint64_t changeCount;
WebProcess::shared().connection()->sendSync(Messages::WebContext::GetPasteboardChangeCount(pasteboardName),
Messages::WebContext::GetPasteboardChangeCount::Reply(changeCount), 0);
return changeCount;
}

String WebPlatformStrategies::uniqueName()
{
return PlatformPasteboard::uniqueName();
String pasteboardName;
WebProcess::shared().connection()->sendSync(Messages::WebContext::GetPasteboardUniqueName(),
Messages::WebContext::GetPasteboardUniqueName::Reply(pasteboardName), 0);
return pasteboardName;
}

Color WebPlatformStrategies::color(const String& pasteboardName)
{
return PlatformPasteboard(pasteboardName).color();
Color color;
WebProcess::shared().connection()->sendSync(Messages::WebContext::GetPasteboardColor(pasteboardName),
Messages::WebContext::GetPasteboardColor::Reply(color), 0);
return color;
}

void WebPlatformStrategies::setTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName)
{
PlatformPasteboard(pasteboardName).setTypes(pasteboardTypes);
WebProcess::shared().connection()->send(Messages::WebContext::SetPasteboardTypes(pasteboardName, pasteboardTypes), 0);
}

void WebPlatformStrategies::setBufferForType(PassRefPtr<SharedBuffer> buffer, const String& pasteboardType, const String& pasteboardName)
{
PlatformPasteboard(pasteboardName).setBufferForType(buffer, pasteboardType);
SharedMemory::Handle handle;
if (buffer) {
RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(buffer->size());
memcpy(sharedMemoryBuffer->data(), buffer->data(), buffer->size());
sharedMemoryBuffer->createHandle(handle, SharedMemory::ReadOnly);
}
WebProcess::shared().connection()->send(Messages::WebContext::SetPasteboardBufferForType(pasteboardName, pasteboardType, handle, buffer ? buffer->size() : 0), 0);
}

void WebPlatformStrategies::setPathnamesForType(const Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName)
{
PlatformPasteboard(pasteboardName).setPathnamesForType(pathnames, pasteboardType);
WebProcess::shared().connection()->send(Messages::WebContext::SetPasteboardPathnamesForType(pasteboardName, pasteboardType, pathnames), 0);
}

void WebPlatformStrategies::setStringForType(const String& string, const String& pasteboardType, const String& pasteboardName)
{
PlatformPasteboard(pasteboardName).setStringForType(string, pasteboardType);
WebProcess::shared().connection()->send(Messages::WebContext::SetPasteboardStringForType(pasteboardName, pasteboardType, string), 0);
}
#endif

Expand Down

0 comments on commit 7940383

Please sign in to comment.