- Revision
- 222761
- Author
- [email protected]
- Date
- 2017-10-02 17:22:17 -0700 (Mon, 02 Oct 2017)
Log Message
Move more code into PasteboardCustomData
https://bugs.webkit.org/show_bug.cgi?id=177795
Reviewed by Wenson Hsieh.
Source/WebCore:
Moved sharedBufferFromCustomData, customDataFromSharedBuffer, and customWebKitPasteboardDataType into
PasteboardCustomData as createSharedBuffer, fromSharedBuffer, and cocoaType respectively.
* platform/Pasteboard.cpp:
(WebCore::PasteboardCustomData::createSharedBuffer const): Renamed from sharedBufferFromCustomData.
(WebCore::PasteboardCustomData::fromSharedBuffer): Renamed from customDataFromSharedBuffer.
* platform/Pasteboard.h:
* platform/StaticPasteboard.cpp:
(WebCore::StaticPasteboard::commitToPasteboard): Now initializes with an empty origin string.
* platform/cocoa/PasteboardCocoa.mm:
(WebCore::PasteboardCustomData::cocoaType): Moved here from Pasteboard.h
(WebCore::Pasteboard::readStringInCustomData):
* platform/ios/PlatformPasteboardIOS.mm:
(WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const):
(WebCore::PlatformPasteboard::write):
* platform/ios/WebItemProviderPasteboard.mm:
(-[WebItemProviderPasteboard typeIdentifiersToLoadForRegisteredTypeIdentfiers:]):
* platform/mac/PlatformPasteboardMac.mm:
(WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const):
(WebCore::PlatformPasteboard::write):
Source/WebKit:
Added the support for encoding and decoding the origin string in PasteboardCustomData.
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<PasteboardCustomData>::encode):
(IPC::ArgumentCoder<PasteboardCustomData>::decode):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (222760 => 222761)
--- trunk/Source/WebCore/ChangeLog 2017-10-03 00:13:13 UTC (rev 222760)
+++ trunk/Source/WebCore/ChangeLog 2017-10-03 00:22:17 UTC (rev 222761)
@@ -1,3 +1,31 @@
+2017-10-02 Ryosuke Niwa <[email protected]>
+
+ Move more code into PasteboardCustomData
+ https://bugs.webkit.org/show_bug.cgi?id=177795
+
+ Reviewed by Wenson Hsieh.
+
+ Moved sharedBufferFromCustomData, customDataFromSharedBuffer, and customWebKitPasteboardDataType into
+ PasteboardCustomData as createSharedBuffer, fromSharedBuffer, and cocoaType respectively.
+
+ * platform/Pasteboard.cpp:
+ (WebCore::PasteboardCustomData::createSharedBuffer const): Renamed from sharedBufferFromCustomData.
+ (WebCore::PasteboardCustomData::fromSharedBuffer): Renamed from customDataFromSharedBuffer.
+ * platform/Pasteboard.h:
+ * platform/StaticPasteboard.cpp:
+ (WebCore::StaticPasteboard::commitToPasteboard): Now initializes with an empty origin string.
+ * platform/cocoa/PasteboardCocoa.mm:
+ (WebCore::PasteboardCustomData::cocoaType): Moved here from Pasteboard.h
+ (WebCore::Pasteboard::readStringInCustomData):
+ * platform/ios/PlatformPasteboardIOS.mm:
+ (WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const):
+ (WebCore::PlatformPasteboard::write):
+ * platform/ios/WebItemProviderPasteboard.mm:
+ (-[WebItemProviderPasteboard typeIdentifiersToLoadForRegisteredTypeIdentfiers:]):
+ * platform/mac/PlatformPasteboardMac.mm:
+ (WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const):
+ (WebCore::PlatformPasteboard::write):
+
2017-10-02 Brent Fulgham <[email protected]>
[Mac] Use safer decoding practices for NSKeyedUnarchiver
Modified: trunk/Source/WebCore/platform/Pasteboard.cpp (222760 => 222761)
--- trunk/Source/WebCore/platform/Pasteboard.cpp 2017-10-03 00:13:13 UTC (rev 222760)
+++ trunk/Source/WebCore/platform/Pasteboard.cpp 2017-10-03 00:22:17 UTC (rev 222761)
@@ -44,20 +44,19 @@
return type == "text/plain" || type == "text/html" || type == "text/uri-list";
}
-Ref<SharedBuffer> sharedBufferFromCustomData(const PasteboardCustomData& data)
+Ref<SharedBuffer> PasteboardCustomData::createSharedBuffer() const
{
const static unsigned currentCustomDataSerializationVersion = 1;
WTF::Persistence::Encoder encoder;
encoder << currentCustomDataSerializationVersion;
- // FIXME: Replace with origin information from PasteboardCustomData once same origin restrictions are implemented.
- encoder << emptyString();
- encoder << data.sameOriginCustomData;
- encoder << data.orderedTypes;
+ encoder << origin;
+ encoder << sameOriginCustomData;
+ encoder << orderedTypes;
return SharedBuffer::create(encoder.buffer(), encoder.bufferSize());
}
-PasteboardCustomData customDataFromSharedBuffer(const SharedBuffer& buffer)
+PasteboardCustomData PasteboardCustomData::fromSharedBuffer(const SharedBuffer& buffer)
{
const static unsigned maxSupportedDataSerializationVersionNumber = 1;
@@ -67,8 +66,7 @@
if (!decoder.decode(version) || version > maxSupportedDataSerializationVersionNumber)
return { };
- String origin;
- if (!decoder.decode(origin))
+ if (!decoder.decode(result.origin))
return { };
if (!decoder.decode(result.sameOriginCustomData))
Modified: trunk/Source/WebCore/platform/Pasteboard.h (222760 => 222761)
--- trunk/Source/WebCore/platform/Pasteboard.h 2017-10-03 00:13:13 UTC (rev 222760)
+++ trunk/Source/WebCore/platform/Pasteboard.h 2017-10-03 00:22:17 UTC (rev 222761)
@@ -156,17 +156,18 @@
// FIXME: We need to ensure that the contents of sameOriginCustomData are not accessible across different origins.
struct PasteboardCustomData {
+ String origin;
Vector<String> orderedTypes;
HashMap<String, String> platformData;
HashMap<String, String> sameOriginCustomData;
-};
-WEBCORE_EXPORT Ref<SharedBuffer> sharedBufferFromCustomData(const PasteboardCustomData&);
-WEBCORE_EXPORT PasteboardCustomData customDataFromSharedBuffer(const SharedBuffer&);
+ WEBCORE_EXPORT Ref<SharedBuffer> createSharedBuffer() const;
+ WEBCORE_EXPORT static PasteboardCustomData fromSharedBuffer(const SharedBuffer&);
#if PLATFORM(COCOA)
-const char customWebKitPasteboardDataType[] = "com.apple.WebKit.custom-pasteboard-data";
+ static const char* cocoaType();
#endif
+};
class Pasteboard {
WTF_MAKE_NONCOPYABLE(Pasteboard); WTF_MAKE_FAST_ALLOCATED;
Modified: trunk/Source/WebCore/platform/StaticPasteboard.cpp (222760 => 222761)
--- trunk/Source/WebCore/platform/StaticPasteboard.cpp 2017-10-03 00:13:13 UTC (rev 222760)
+++ trunk/Source/WebCore/platform/StaticPasteboard.cpp 2017-10-03 00:22:17 UTC (rev 222761)
@@ -83,7 +83,7 @@
return;
if (Settings::customPasteboardDataEnabled()) {
- pasteboard.writeCustomData({ WTFMove(m_types), WTFMove(m_platformData), WTFMove(m_customData) });
+ pasteboard.writeCustomData({ { }, WTFMove(m_types), WTFMove(m_platformData), WTFMove(m_customData) });
return;
}
Modified: trunk/Source/WebCore/platform/cocoa/PasteboardCocoa.mm (222760 => 222761)
--- trunk/Source/WebCore/platform/cocoa/PasteboardCocoa.mm 2017-10-03 00:13:13 UTC (rev 222760)
+++ trunk/Source/WebCore/platform/cocoa/PasteboardCocoa.mm 2017-10-03 00:22:17 UTC (rev 222761)
@@ -43,6 +43,11 @@
PasteboardWebContent::PasteboardWebContent() = default;
PasteboardWebContent::~PasteboardWebContent() = default;
+const char* PasteboardCustomData::cocoaType()
+{
+ return "com.apple.WebKit.custom-pasteboard-data";
+}
+
enum class ImageType {
Invalid = 0,
TIFF,
@@ -210,7 +215,7 @@
String Pasteboard::readStringInCustomData(const String& type)
{
- auto buffer = readBufferForTypeWithSecurityCheck(customWebKitPasteboardDataType);
+ auto buffer = readBufferForTypeWithSecurityCheck(PasteboardCustomData::cocoaType());
if (!buffer)
return { };
@@ -219,7 +224,7 @@
if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName))
return { };
- return customDataFromSharedBuffer(*buffer).sameOriginCustomData.get(type);
+ return PasteboardCustomData::fromSharedBuffer(*buffer).sameOriginCustomData.get(type);
}
void Pasteboard::writeCustomData(const PasteboardCustomData& data)
Modified: trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm (222760 => 222761)
--- trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm 2017-10-03 00:13:13 UTC (rev 222760)
+++ trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm 2017-10-03 00:22:17 UTC (rev 222761)
@@ -354,7 +354,7 @@
if (!teamDataObject || ![teamDataObject isKindOfClass:[NSDictionary class]])
continue;
- id customTypes = [(NSDictionary *)teamDataObject objectForKey:@(customWebKitPasteboardDataType)];
+ id customTypes = [(NSDictionary *)teamDataObject objectForKey:@(PasteboardCustomData::cocoaType())];
if (![customTypes isKindOfClass:[NSArray class]])
continue;
@@ -362,14 +362,14 @@
domPasteboardTypes.add(type);
}
- if (NSData *serializedCustomData = [m_pasteboard dataForPasteboardType:@(customWebKitPasteboardDataType)]) {
+ if (NSData *serializedCustomData = [m_pasteboard dataForPasteboardType:@(PasteboardCustomData::cocoaType())]) {
auto buffer = SharedBuffer::create(serializedCustomData);
- for (auto& type : customDataFromSharedBuffer(buffer.get()).orderedTypes)
+ for (auto& type : PasteboardCustomData::fromSharedBuffer(buffer.get()).orderedTypes)
domPasteboardTypes.add(type);
}
for (NSString *type in [m_pasteboard pasteboardTypes]) {
- if ([type isEqualToString:@(customWebKitPasteboardDataType)])
+ if ([type isEqualToString:@(PasteboardCustomData::cocoaType())])
continue;
if (Pasteboard::isSafeTypeForDOMToReadAndWrite(type)) {
@@ -392,7 +392,7 @@
[representationsToRegister setPreferredPresentationStyle:WebPreferredPresentationStyleInline];
if (data.sameOriginCustomData.size()) {
- if (auto serializedSharedBuffer = sharedBufferFromCustomData(data)->createNSData()) {
+ if (auto serializedSharedBuffer = data.createSharedBuffer()->createNSData()) {
// We stash the list of supplied pasteboard types in teamData here for compatibility with drag and drop.
// Since the contents of item providers cannot be loaded prior to drop, but the pasteboard types are
// contained within the custom data blob and we need to vend them to the page when firing `dragover`
@@ -402,8 +402,8 @@
NSMutableArray<NSString *> *typesAsNSArray = [NSMutableArray array];
for (auto& type : data.orderedTypes)
[typesAsNSArray addObject:type];
- [representationsToRegister setTeamData:[NSKeyedArchiver archivedDataWithRootObject:@{ @(customWebKitPasteboardDataType) : typesAsNSArray }]];
- [representationsToRegister addData:serializedSharedBuffer.get() forType:@(customWebKitPasteboardDataType)];
+ [representationsToRegister setTeamData:[NSKeyedArchiver archivedDataWithRootObject:@{ @(PasteboardCustomData::cocoaType()) : typesAsNSArray }]];
+ [representationsToRegister addData:serializedSharedBuffer.get() forType:@(PasteboardCustomData::cocoaType())];
}
}
Modified: trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm (222760 => 222761)
--- trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm 2017-10-03 00:13:13 UTC (rev 222760)
+++ trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm 2017-10-03 00:22:17 UTC (rev 222761)
@@ -554,7 +554,7 @@
// For compatibility with DataTransfer APIs, additionally load web-exposed types. Since this is the only chance to
// fault in any data at all, we need to load up front any information that the page may ask for later down the line.
- NSString *customPasteboardDataUTI = @(customWebKitPasteboardDataType);
+ NSString *customPasteboardDataUTI = @(PasteboardCustomData::cocoaType());
for (NSString *registeredTypeIdentifier in registeredTypeIdentifiers) {
if ([typesToLoad containsObject:registeredTypeIdentifier])
continue;
Modified: trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm (222760 => 222761)
--- trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm 2017-10-03 00:13:13 UTC (rev 222760)
+++ trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm 2017-10-03 00:22:17 UTC (rev 222761)
@@ -110,15 +110,15 @@
Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite() const
{
ListHashSet<String> domPasteboardTypes;
- if (NSData *serializedCustomData = [m_pasteboard dataForType:@(customWebKitPasteboardDataType)]) {
+ if (NSData *serializedCustomData = [m_pasteboard dataForType:@(PasteboardCustomData::cocoaType())]) {
auto buffer = SharedBuffer::create(serializedCustomData);
- for (auto& type : customDataFromSharedBuffer(buffer.get()).orderedTypes)
+ for (auto& type : PasteboardCustomData::fromSharedBuffer(buffer.get()).orderedTypes)
domPasteboardTypes.add(type);
}
NSArray<NSString *> *allTypes = [m_pasteboard types];
for (NSString *type in allTypes) {
- if ([type isEqualToString:@(customWebKitPasteboardDataType)])
+ if ([type isEqualToString:@(PasteboardCustomData::cocoaType())])
continue;
if (Pasteboard::isSafeTypeForDOMToReadAndWrite(type))
@@ -138,7 +138,7 @@
for (auto& entry : data.platformData)
[types addObject:platformPasteboardTypeForSafeTypeForDOMToReadAndWrite(entry.key)];
if (data.sameOriginCustomData.size())
- [types addObject:@(customWebKitPasteboardDataType)];
+ [types addObject:@(PasteboardCustomData::cocoaType())];
[m_pasteboard declareTypes:types owner:nil];
@@ -150,8 +150,8 @@
}
if (data.sameOriginCustomData.size()) {
- if (auto serializedCustomData = sharedBufferFromCustomData(data)->createNSData())
- [m_pasteboard setData:serializedCustomData.get() forType:@(customWebKitPasteboardDataType)];
+ if (auto serializedCustomData = data.createSharedBuffer()->createNSData())
+ [m_pasteboard setData:serializedCustomData.get() forType:@(PasteboardCustomData::cocoaType())];
}
return changeCount();
Modified: trunk/Source/WebKit/ChangeLog (222760 => 222761)
--- trunk/Source/WebKit/ChangeLog 2017-10-03 00:13:13 UTC (rev 222760)
+++ trunk/Source/WebKit/ChangeLog 2017-10-03 00:22:17 UTC (rev 222761)
@@ -1,3 +1,16 @@
+2017-10-02 Ryosuke Niwa <[email protected]>
+
+ Move more code into PasteboardCustomData
+ https://bugs.webkit.org/show_bug.cgi?id=177795
+
+ Reviewed by Wenson Hsieh.
+
+ Added the support for encoding and decoding the origin string in PasteboardCustomData.
+
+ * Shared/WebCoreArgumentCoders.cpp:
+ (IPC::ArgumentCoder<PasteboardCustomData>::encode):
+ (IPC::ArgumentCoder<PasteboardCustomData>::decode):
+
2017-10-02 Adrian Perez de Castro <[email protected]>
[GTK] Do not hardcode font family in served remote inspector HTML snippets
Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (222760 => 222761)
--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2017-10-03 00:13:13 UTC (rev 222760)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2017-10-03 00:22:17 UTC (rev 222761)
@@ -1580,6 +1580,7 @@
void ArgumentCoder<PasteboardCustomData>::encode(Encoder& encoder, const PasteboardCustomData& data)
{
+ encoder << data.origin;
encoder << data.orderedTypes;
encoder << data.platformData;
encoder << data.sameOriginCustomData;
@@ -1587,6 +1588,9 @@
bool ArgumentCoder<PasteboardCustomData>::decode(Decoder& decoder, PasteboardCustomData& data)
{
+ if (!decoder.decode(data.origin))
+ return false;
+
if (!decoder.decode(data.orderedTypes))
return false;