[Attachment Support] Introduce data structures and IPC support for writing promised...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Jan 2018 02:54:47 +0000 (02:54 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Jan 2018 02:54:47 +0000 (02:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181189

Reviewed by Tim Horton.

Source/WebCore:

Introduces a new header containing structs to be used for writing blob data when dragging. PromisedBlobInfo
represents information needed to declare data on the pasteboard that will eventually be provided via a Blob.
This includes the type and filename of the Blob-backed content. PromisedBlobData represents information needed
to actually deliver the Blob's content to the platform, and is sent some time after its corresponding
PromisedBlobInfo. The content may either be in the form of a file path (as is the case using the previous
declareAndWriteAttachment codepath) or a data buffer (which we would use if the Blob is not already backed by a
file on disk).

No new tests, since there is no observable change in functionality yet.

* WebCore.xcodeproj/project.pbxproj:
* platform/PromisedBlobInfo.h: Added.
(WebCore::PromisedBlobInfo::operator bool const):
(WebCore::PromisedBlobData::hasData const):
(WebCore::PromisedBlobData::hasFile const):
(WebCore::PromisedBlobData::operator bool const):
(WebCore::PromisedBlobData::fulfills const):

Source/WebKit:

Add IPC support for PromisedBlobInfo and PromisedBlobData. See WebCore/ChangeLog for more detail.

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<PromisedBlobData>::encode):
(IPC::ArgumentCoder<PromisedBlobData>::decode):
(IPC::ArgumentCoder<PromisedBlobInfo>::encode):
(IPC::ArgumentCoder<PromisedBlobInfo>::decode):
* Shared/WebCoreArgumentCoders.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226348 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/PromisedBlobInfo.h [new file with mode: 0644]
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebCoreArgumentCoders.cpp
Source/WebKit/Shared/WebCoreArgumentCoders.h

index d3136e8..8506324 100644 (file)
@@ -1,3 +1,28 @@
+2018-01-02  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Attachment Support] Introduce data structures and IPC support for writing promised blobs
+        https://bugs.webkit.org/show_bug.cgi?id=181189
+
+        Reviewed by Tim Horton.
+
+        Introduces a new header containing structs to be used for writing blob data when dragging. PromisedBlobInfo
+        represents information needed to declare data on the pasteboard that will eventually be provided via a Blob.
+        This includes the type and filename of the Blob-backed content. PromisedBlobData represents information needed
+        to actually deliver the Blob's content to the platform, and is sent some time after its corresponding
+        PromisedBlobInfo. The content may either be in the form of a file path (as is the case using the previous
+        declareAndWriteAttachment codepath) or a data buffer (which we would use if the Blob is not already backed by a
+        file on disk).
+
+        No new tests, since there is no observable change in functionality yet.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/PromisedBlobInfo.h: Added.
+        (WebCore::PromisedBlobInfo::operator bool const):
+        (WebCore::PromisedBlobData::hasData const):
+        (WebCore::PromisedBlobData::hasFile const):
+        (WebCore::PromisedBlobData::operator bool const):
+        (WebCore::PromisedBlobData::fulfills const):
+
 2018-01-02  Brady Eidson  <beidson@apple.com>
 
         Make MessagePortChannel::takeAllMessagesFromRemote asynchronous.
index 66a46c5..45bbb0c 100644 (file)
                F46729281E0DE68500ACC3D8 /* ScrollSnapOffsetsInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = F46729251E0DE5AB00ACC3D8 /* ScrollSnapOffsetsInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
                F478755419983AFF0024A287 /* ScrollSnapAnimatorState.h in Headers */ = {isa = PBXBuildFile; fileRef = F478755219983AFF0024A287 /* ScrollSnapAnimatorState.h */; settings = {ATTRIBUTES = (Private, ); }; };
                F47A5E3E195B8C8A00483100 /* StyleScrollSnapPoints.h in Headers */ = {isa = PBXBuildFile; fileRef = F47A5E3B195B8C8A00483100 /* StyleScrollSnapPoints.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               F47A633D1FF6FD500081B3CC /* PromisedBlobInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = F47A633C1FF6FD500081B3CC /* PromisedBlobInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
                F48223101E3869B80066FC79 /* WebItemProviderPasteboard.mm in Sources */ = {isa = PBXBuildFile; fileRef = F482230E1E3869B80066FC79 /* WebItemProviderPasteboard.mm */; };
                F48223111E3869B80066FC79 /* WebItemProviderPasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = F482230F1E3869B80066FC79 /* WebItemProviderPasteboard.h */; settings = {ATTRIBUTES = (Private, ); }; };
                F48223131E386E240066FC79 /* AbstractPasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = F48223121E386E240066FC79 /* AbstractPasteboard.h */; settings = {ATTRIBUTES = (Private, ); }; };
                F478755319983AFF0024A287 /* ScrollSnapAnimatorState.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollSnapAnimatorState.mm; sourceTree = "<group>"; };
                F47A5E3A195B8C8A00483100 /* StyleScrollSnapPoints.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleScrollSnapPoints.cpp; sourceTree = "<group>"; };
                F47A5E3B195B8C8A00483100 /* StyleScrollSnapPoints.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleScrollSnapPoints.h; sourceTree = "<group>"; };
+               F47A633C1FF6FD500081B3CC /* PromisedBlobInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PromisedBlobInfo.h; sourceTree = "<group>"; };
                F482230E1E3869B80066FC79 /* WebItemProviderPasteboard.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebItemProviderPasteboard.mm; sourceTree = "<group>"; };
                F482230F1E3869B80066FC79 /* WebItemProviderPasteboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebItemProviderPasteboard.h; sourceTree = "<group>"; };
                F48223121E386E240066FC79 /* AbstractPasteboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AbstractPasteboard.h; sourceTree = "<group>"; };
                                BC3BE12A0E98092F00835588 /* PopupMenuStyle.h */,
                                51F645D21FECDBC800B54DED /* Process.cpp */,
                                51F645D31FECDBC800B54DED /* Process.h */,
+                               F47A633C1FF6FD500081B3CC /* PromisedBlobInfo.h */,
                                0081FEFD16B0A244008AAA7A /* PublicSuffix.h */,
                                5C97A3361F5F7A6500105207 /* RectEdges.h */,
                                9831AE49154225A200FE2644 /* ReferrerPolicy.h */,
                                A715E653134BBBEC00D8E713 /* ProgressShadowElement.h in Headers */,
                                1A2A68240B5BEDE70002A480 /* ProgressTracker.h in Headers */,
                                1ACADD791880D91C00D8B71D /* ProgressTrackerClient.h in Headers */,
+                               F47A633D1FF6FD500081B3CC /* PromisedBlobInfo.h in Headers */,
                                A578F4351DE00EEB003DFC6A /* PromiseRejectionEvent.h in Headers */,
                                E4BBED0F14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.h in Headers */,
                                37BAAE581980D1DD005DFE71 /* ProtectionSpace.h in Headers */,
diff --git a/Source/WebCore/platform/PromisedBlobInfo.h b/Source/WebCore/platform/PromisedBlobInfo.h
new file mode 100644 (file)
index 0000000..aacdf69
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#import <WebCore/SharedBuffer.h>
+
+namespace WebCore {
+
+enum class PromisedBlobType { DataBacked, FileBacked };
+
+struct PromisedBlobInfo {
+    String blobURL;
+    String contentType;
+    String filename;
+    PromisedBlobType blobType;
+
+    operator bool() const { return !blobURL.isEmpty(); }
+};
+
+struct PromisedBlobData {
+    String blobURL;
+    String filePath;
+    RefPtr<SharedBuffer> data;
+
+    bool hasData() const { return data; }
+    bool hasFile() const { return !filePath.isEmpty(); }
+    operator bool() const { return !blobURL.isEmpty(); }
+    bool fulfills(const PromisedBlobInfo& info) const { return *this && blobURL == info.blobURL; }
+};
+
+} // namespace WebCore
+
+namespace WTF {
+
+template<typename> struct EnumTraits;
+template<typename E, E...> struct EnumValues;
+
+template<> struct EnumTraits<WebCore::PromisedBlobType> {
+    using values = EnumValues<WebCore::PromisedBlobType,
+    WebCore::PromisedBlobType::DataBacked,
+    WebCore::PromisedBlobType::FileBacked
+    >;
+};
+
+} // namespace WTF
index 50feb64..e166f3b 100644 (file)
@@ -1,3 +1,19 @@
+2018-01-02  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Attachment Support] Introduce data structures and IPC support for writing promised blobs
+        https://bugs.webkit.org/show_bug.cgi?id=181189
+
+        Reviewed by Tim Horton.
+
+        Add IPC support for PromisedBlobInfo and PromisedBlobData. See WebCore/ChangeLog for more detail.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<PromisedBlobData>::encode):
+        (IPC::ArgumentCoder<PromisedBlobData>::decode):
+        (IPC::ArgumentCoder<PromisedBlobInfo>::encode):
+        (IPC::ArgumentCoder<PromisedBlobInfo>::decode):
+        * Shared/WebCoreArgumentCoders.h:
+
 2018-01-02  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         REGRESSION(r223253): Broke ResourceLoadStatistics layout tests for non-Cocoa ports
index 8a7d560..7f815ce 100644 (file)
@@ -55,6 +55,7 @@
 #include <WebCore/Pasteboard.h>
 #include <WebCore/Path.h>
 #include <WebCore/PluginData.h>
+#include <WebCore/PromisedBlobInfo.h>
 #include <WebCore/ProtectionSpace.h>
 #include <WebCore/RectEdges.h>
 #include <WebCore/Region.h>
@@ -2802,4 +2803,50 @@ std::optional<MediaSelectionOption> ArgumentCoder<MediaSelectionOption>::decode(
     return {{ WTFMove(*displayName), WTFMove(*type) }};
 }
 
+void ArgumentCoder<PromisedBlobData>::encode(Encoder& encoder, const PromisedBlobData& data)
+{
+    encoder << data.blobURL;
+    encoder << data.filePath;
+    encodeSharedBuffer(encoder, data.data.get());
+}
+
+bool ArgumentCoder<PromisedBlobData>::decode(Decoder& decoder, PromisedBlobData& data)
+{
+    if (!decoder.decode(data.blobURL))
+        return false;
+
+    if (!decoder.decode(data.filePath))
+        return false;
+
+    if (!decodeSharedBuffer(decoder, data.data))
+        return false;
+
+    return true;
+}
+
+void ArgumentCoder<PromisedBlobInfo>::encode(Encoder& encoder, const PromisedBlobInfo& info)
+{
+    encoder << info.blobURL;
+    encoder << info.contentType;
+    encoder << info.filename;
+    encoder.encodeEnum(info.blobType);
+}
+
+bool ArgumentCoder<PromisedBlobInfo>::decode(Decoder& decoder, PromisedBlobInfo& info)
+{
+    if (!decoder.decode(info.blobURL))
+        return false;
+
+    if (!decoder.decode(info.contentType))
+        return false;
+
+    if (!decoder.decode(info.filename))
+        return false;
+
+    if (!decoder.decode(info.blobType))
+        return false;
+
+    return true;
+}
+
 } // namespace IPC
index 22f1f21..5a1fdb5 100644 (file)
@@ -105,6 +105,8 @@ struct PasteboardImage;
 struct PasteboardCustomData;
 struct PasteboardURL;
 struct PluginInfo;
+struct PromisedBlobData;
+struct PromisedBlobInfo;
 struct RecentSearch;
 struct ResourceLoadStatistics;
 struct ScrollableAreaParameters;
@@ -696,6 +698,16 @@ template<> struct ArgumentCoder<WebCore::MediaSelectionOption> {
     static std::optional<WebCore::MediaSelectionOption> decode(Decoder&);
 };
 
+template<> struct ArgumentCoder<WebCore::PromisedBlobData> {
+    static void encode(Encoder&, const WebCore::PromisedBlobData&);
+    static bool decode(Decoder&, WebCore::PromisedBlobData&);
+};
+
+template<> struct ArgumentCoder<WebCore::PromisedBlobInfo> {
+    static void encode(Encoder&, const WebCore::PromisedBlobInfo&);
+    static bool decode(Decoder&, WebCore::PromisedBlobInfo&);
+};
+
 } // namespace IPC
 
 namespace WTF {