Skip to content
Permalink
Browse files
[Attachment Support] Implement WKWebView SPI for inserting attachment…
… elements

https://bugs.webkit.org/show_bug.cgi?id=179013
<rdar://problem/35249668>

Reviewed by Tim Horton.

Source/WebCore:

Adds Editor helper methods to insert an attachment element at the current selection.

Test: WKAttachmentTests.AttachmentElementInsertion

* editing/Editor.cpp:
(WebCore::Editor::insertAttachment):
(WebCore::Editor::insertAttachmentFromFile):
* editing/Editor.h:

Add two new helpers for inserting attachment elements, either from a filename or a data blob. This is a wrapper
around Editor::replaceSelectionWithFragment.

* html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::HTMLAttachmentElement):
(WebCore::HTMLAttachmentElement::create):
* html/HTMLAttachmentElement.h:

Add a unique identifier string to HTMLAttachmentElement. This unique identifier allows the UI process to
reference and indirectly manipulate attachment elements.

Source/WebCore/PAL:

Add a PAL library function to convert a file size to a human-readable string. On Cocoa platforms, this is a
wrapper around NSLocalizedFileSizeDescription; otherwise, we fall back to a naive platform-agnostic
implementation in FileSizeFormatter.cpp.

* PAL.xcodeproj/project.pbxproj:
* pal/CMakeLists.txt:
* pal/FileSizeFormatter.cpp: Added.
(fileSizeDescription):
* pal/FileSizeFormatter.h: Added.
* pal/cocoa/FileSizeFormatterCocoa.mm: Added.
(fileSizeDescription):
* pal/spi/cocoa/NSFileSizeFormatterSPI.h: Added.

Source/WebKit:

Adds native SPI to insert attachment elements given a filename, an optional MIME type, and a data blob. See
change-by-change comments below for more detail. Covered by a new API test.

* PlatformMac.cmake:
* Shared/API/APIObject.h:
* Shared/API/Cocoa/WebKitPrivate.h:
* UIProcess/API/APIAttachment.cpp: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h.
(API::Attachment::create):
(API::Attachment::Attachment):
(API::Attachment::~Attachment):

Introduce API::Attachment, which represents a platform-agnostic Attachment.

* UIProcess/API/APIAttachment.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h.
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _insertAttachmentWithFilename:contentType:data:options:completion:]):

Adds support for inserting a new attachment element. Calls out to WebPageProxy to insert the attachment from the
given data blob, and creates a new API-object-backed _WKAttachment.

(-[WKWebView _executeEditCommand:argument:completion:]):

Support passing in a nil completion block.

* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/Cocoa/_WKAttachment.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h.
* UIProcess/API/Cocoa/_WKAttachment.mm: Copied from Source/WebCore/html/HTMLAttachmentElement.h.

Introduces _WKAttachment, an Objective C wrapper around the API::Attachment.

(-[_WKAttachment _apiObject]):
(-[_WKAttachment isEqual:]):
(-[_WKAttachment uniqueIdentifier]):
(-[_WKAttachment hash]):

Add _WKAttachment, a WebKit SPI object that wraps an attachment element unique identifier. Also, allow
_WKAttachment to be used as a hashable NSDictionary key.

(-[_WKAttachment description]):
* UIProcess/API/Cocoa/_WKAttachmentInternal.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h.
(API::wrapper):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::insertAttachment):

Implement IPC support for inserting an attachment.

* UIProcess/WebPageProxy.h:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::insertAttachment):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Tools:

Adds a new API test suite to exercise attachment element insertion and manipulation.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm: Added.
(webViewForTestingAttachments):
(testHTMLData):
(testImageData):
(-[TestWKWebView synchronouslyInsertAttachmentWithFilename:contentType:data:options:]):
(-[TestWKWebView valueOfAttribute:forQuerySelector:]):
(TestWebKitAPI::TEST):


Canonical link: https://commits.webkit.org/195194@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224238 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
whsieh committed Oct 31, 2017
1 parent 42db903 commit 1a25b89ee81936ecc20744611f33bdc362052552
Showing 34 changed files with 822 additions and 4 deletions.
@@ -1,3 +1,31 @@
2017-10-31 Wenson Hsieh <wenson_hsieh@apple.com>

[Attachment Support] Implement WKWebView SPI for inserting attachment elements
https://bugs.webkit.org/show_bug.cgi?id=179013
<rdar://problem/35249668>

Reviewed by Tim Horton.

Adds Editor helper methods to insert an attachment element at the current selection.

Test: WKAttachmentTests.AttachmentElementInsertion

* editing/Editor.cpp:
(WebCore::Editor::insertAttachment):
(WebCore::Editor::insertAttachmentFromFile):
* editing/Editor.h:

Add two new helpers for inserting attachment elements, either from a filename or a data blob. This is a wrapper
around Editor::replaceSelectionWithFragment.

* html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::HTMLAttachmentElement):
(WebCore::HTMLAttachmentElement::create):
* html/HTMLAttachmentElement.h:

Add a unique identifier string to HTMLAttachmentElement. This unique identifier allows the UI process to
reference and indirectly manipulate attachment elements.

2017-10-31 Alex Christensen <achristensen@webkit.org>

Fix custom header field setting with reloads and asynchronous navigation action policy decisions
@@ -1,3 +1,24 @@
2017-10-31 Wenson Hsieh <wenson_hsieh@apple.com>

[Attachment Support] Implement WKWebView SPI for inserting attachment elements
https://bugs.webkit.org/show_bug.cgi?id=179013
<rdar://problem/35249668>

Reviewed by Tim Horton.

Add a PAL library function to convert a file size to a human-readable string. On Cocoa platforms, this is a
wrapper around NSLocalizedFileSizeDescription; otherwise, we fall back to a naive platform-agnostic
implementation in FileSizeFormatter.cpp.

* PAL.xcodeproj/project.pbxproj:
* pal/CMakeLists.txt:
* pal/FileSizeFormatter.cpp: Added.
(fileSizeDescription):
* pal/FileSizeFormatter.h: Added.
* pal/cocoa/FileSizeFormatterCocoa.mm: Added.
(fileSizeDescription):
* pal/spi/cocoa/NSFileSizeFormatterSPI.h: Added.

2017-10-27 Keith Miller <keith_miller@apple.com>

Move iOS specific sources to unified sources
@@ -141,6 +141,10 @@
A3AB6E651F3D217F009C14B1 /* SystemSleepListenerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A3AB6E631F3D217F009C14B1 /* SystemSleepListenerMac.mm */; };
A3C66CDC1F462D6A009E6EE9 /* SessionID.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A3C66CDA1F462D6A009E6EE9 /* SessionID.cpp */; };
A3C66CDD1F462D6A009E6EE9 /* SessionID.h in Headers */ = {isa = PBXBuildFile; fileRef = A3C66CDB1F462D6A009E6EE9 /* SessionID.h */; };
F442915E1FA52473002CC93E /* NSFileSizeFormatterSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = F442915D1FA52473002CC93E /* NSFileSizeFormatterSPI.h */; };
F44291601FA5261E002CC93E /* FileSizeFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = F442915F1FA5261E002CC93E /* FileSizeFormatter.h */; settings = {ATTRIBUTES = (Private, ); }; };
F44291641FA52670002CC93E /* FileSizeFormatter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F44291621FA52670002CC93E /* FileSizeFormatter.cpp */; };
F44291681FA52705002CC93E /* FileSizeFormatterCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = F44291661FA52705002CC93E /* FileSizeFormatterCocoa.mm */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
@@ -283,6 +287,10 @@
A3C66CDA1F462D6A009E6EE9 /* SessionID.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SessionID.cpp; sourceTree = "<group>"; };
A3C66CDB1F462D6A009E6EE9 /* SessionID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SessionID.h; sourceTree = "<group>"; };
C2147A4A1EFD0AA600056FA5 /* CopyPALHeaders.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CopyPALHeaders.xcconfig; sourceTree = "<group>"; };
F442915D1FA52473002CC93E /* NSFileSizeFormatterSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSFileSizeFormatterSPI.h; sourceTree = "<group>"; };
F442915F1FA5261E002CC93E /* FileSizeFormatter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FileSizeFormatter.h; sourceTree = "<group>"; };
F44291621FA52670002CC93E /* FileSizeFormatter.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FileSizeFormatter.cpp; sourceTree = "<group>"; };
F44291661FA52705002CC93E /* FileSizeFormatterCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FileSizeFormatterCocoa.mm; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
@@ -362,6 +370,7 @@
0C2DA1311F3BEB4900DBC317 /* NSColorSPI.h */,
0C2DA1321F3BEB4900DBC317 /* NSExtensionSPI.h */,
0C2DA1331F3BEB4900DBC317 /* NSFileManagerSPI.h */,
F442915D1FA52473002CC93E /* NSFileSizeFormatterSPI.h */,
0C2DA1341F3BEB4900DBC317 /* NSStringSPI.h */,
0C2DA1351F3BEB4900DBC317 /* NSTouchBarSPI.h */,
0C2DA1361F3BEB4900DBC317 /* NSURLConnectionSPI.h */,
@@ -471,6 +480,8 @@
A3788E9F1F05B7CE00679425 /* system */,
A30D411D1F0DD0AC00B71954 /* text */,
0C2D9E721EEF5AF600DBC317 /* ExportMacros.h */,
F44291621FA52670002CC93E /* FileSizeFormatter.cpp */,
F442915F1FA5261E002CC93E /* FileSizeFormatter.h */,
A39DE74D1F7C443C007BCB00 /* HysteresisActivity.h */,
0708AC321F4C874A001F788F /* Logger.h */,
07377ADB1F5777D70027F16D /* LoggerHelper.h */,
@@ -517,6 +528,7 @@
1C4876DE1F8D831300CCEEBD /* cocoa */ = {
isa = PBXGroup;
children = (
F44291661FA52705002CC93E /* FileSizeFormatterCocoa.mm */,
1C4876DF1F8D837500CCEEBD /* LoggingCocoa.mm */,
);
path = cocoa;
@@ -612,6 +624,7 @@
0C5AF91A1F43A4C7002EAC02 /* DataDetectorsUISPI.h in Headers */,
A1175B571F6B470500C4B9F0 /* DefaultSearchProvider.h in Headers */,
0C2D9E731EEF5AF600DBC317 /* ExportMacros.h in Headers */,
F44291601FA5261E002CC93E /* FileSizeFormatter.h in Headers */,
A10265871F56746100B4C844 /* FoundationSPI.h in Headers */,
0C5AF91B1F43A4C7002EAC02 /* GraphicsServicesSPI.h in Headers */,
A102658E1F567E9D00B4C844 /* HIServicesSPI.h in Headers */,
@@ -647,6 +660,7 @@
0C77858F1F45130F00F4EBB6 /* NSEventSPI.h in Headers */,
0C2DA14E1F3BEB4900DBC317 /* NSExtensionSPI.h in Headers */,
0C2DA14F1F3BEB4900DBC317 /* NSFileManagerSPI.h in Headers */,
F442915E1FA52473002CC93E /* NSFileSizeFormatterSPI.h in Headers */,
0C7785901F45130F00F4EBB6 /* NSFontSPI.h in Headers */,
A10826FE1F58A433004772AC /* NSGraphicsSPI.h in Headers */,
0C7785911F45130F00F4EBB6 /* NSImmediateActionGestureRecognizerSPI.h in Headers */,
@@ -784,6 +798,8 @@
0CF99CA81F738437007EE793 /* CoreMediaSoftLink.cpp in Sources */,
1C09D0561E31C46500725F18 /* CryptoDigestCommonCrypto.cpp in Sources */,
A1175B581F6B470500C4B9F0 /* DefaultSearchProvider.cpp in Sources */,
F44291641FA52670002CC93E /* FileSizeFormatter.cpp in Sources */,
F44291681FA52705002CC93E /* FileSizeFormatterCocoa.mm in Sources */,
A30D41221F0DD0EA00B71954 /* KillRing.cpp in Sources */,
A30D41251F0DD12D00B71954 /* KillRingMac.mm in Sources */,
1C4876D81F8D7F4E00CCEEBD /* Logging.cpp in Sources */,
@@ -1,4 +1,5 @@
set(PAL_SOURCES
FileSizeFormatter.cpp
Logging.cpp
SessionID.cpp

@@ -0,0 +1,44 @@
/*
* Copyright (C) 2017 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.
*/

#include "config.h"
#include "FileSizeFormatter.h"

#if !PLATFORM(COCOA)

String fileSizeDescription(uint64_t size)
{
// FIXME: These strings should be localized, but that would require bringing LocalizedStrings into PAL.
// See <https://bugs.webkit.org/show_bug.cgi?id=179019> for more details.
if (size < 1000)
return String::format("%tu bytes", size);
if (size < 1000000)
return String::format("%.1f KB", size / 1000.);
if (size < 1000000000)
return String::format("%.1f MB", size / 1000000.);
return String::format("%.1f GB", size / 1000000000.);
}

#endif
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2017 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

#include <wtf/text/WTFString.h>

PAL_EXPORT String fileSizeDescription(uint64_t);
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2017 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.
*/

#include "config.h"
#include "FileSizeFormatter.h"

#import "NSFileSizeFormatterSPI.h"

String fileSizeDescription(uint64_t size)
{
return NSLocalizedFileSizeDescription(size, 0, 0);
}
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2017 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

#if USE(APPLE_INTERNAL_SDK)

#import <Foundation/NSFileSizeFormatter.h>

#else

typedef uint64_t NSFileSizeFormatterOptions;
extern "C" NSString *NSLocalizedFileSizeDescription(uint64_t size, uint64_t maximumDisplayedValue, NSFileSizeFormatterOptions);

#endif
@@ -47,12 +47,14 @@
#include "EditorClient.h"
#include "EventHandler.h"
#include "EventNames.h"
#include "File.h"
#include "FocusController.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameTree.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "HTMLAttachmentElement.h"
#include "HTMLCollection.h"
#include "HTMLFormControlElement.h"
#include "HTMLFrameOwnerElement.h"
@@ -98,6 +100,7 @@
#include "UserTypingGestureIndicator.h"
#include "VisibleUnits.h"
#include "markup.h"
#include <pal/FileSizeFormatter.h>
#include <pal/system/Sound.h>
#include <pal/text/KillRing.h>
#include <wtf/unicode/CharacterNames.h>
@@ -3728,6 +3731,39 @@ RefPtr<Range> Editor::rangeForTextCheckingResult(const TextCheckingResult& resul
return TextIterator::subrange(*contextRange, result.location, result.length);
}

#if ENABLE(ATTACHMENT_ELEMENT)

void Editor::insertAttachment(const String& identifier, const String& filename, const String& filepath, std::optional<String> contentType)
{
if (!contentType)
contentType = File::contentTypeForFile(filename);
insertAttachmentFromFile(identifier, filename, *contentType, File::create(filepath));
}

void Editor::insertAttachment(const String& identifier, const String& filename, Ref<SharedBuffer>&& data, std::optional<String> contentType)
{
if (!contentType)
contentType = File::contentTypeForFile(filename);
insertAttachmentFromFile(identifier, filename, *contentType, File::create(Blob::create(data, *contentType), filename));
}

void Editor::insertAttachmentFromFile(const String& identifier, const String& filename, const String& contentType, Ref<File>&& file)
{
auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document(), identifier);
attachment->setAttribute(HTMLNames::titleAttr, filename);
attachment->setAttribute(HTMLNames::subtitleAttr, fileSizeDescription(file->size()));
attachment->setAttribute(HTMLNames::typeAttr, contentType);
attachment->setUniqueIdentifier(identifier);
attachment->setFile(file.ptr());

auto fragmentToInsert = document().createDocumentFragment();
fragmentToInsert->appendChild(attachment.get());

replaceSelectionWithFragment(fragmentToInsert.get(), false, false, true);
}

#endif // ENABLE(ATTACHMENT_ELEMENT)

void Editor::handleAcceptedCandidate(TextCheckingResult acceptedCandidate)
{
const VisibleSelection& selection = m_frame.selection().selection();
@@ -63,7 +63,9 @@ class EditCommand;
class EditCommandComposition;
class EditorClient;
class EditorInternalCommand;
class File;
class Frame;
class HTMLAttachmentElement;
class HTMLElement;
class HitTestResult;
class KeyboardEvent;
@@ -498,9 +500,18 @@ class Editor {
void setIsGettingDictionaryPopupInfo(bool b) { m_isGettingDictionaryPopupInfo = b; }
bool isGettingDictionaryPopupInfo() const { return m_isGettingDictionaryPopupInfo; }

#if ENABLE(ATTACHMENT_ELEMENT)
WEBCORE_EXPORT void insertAttachment(const String& identifier, const String& filename, const String& filepath, std::optional<String> contentType = std::nullopt);
WEBCORE_EXPORT void insertAttachment(const String& identifier, const String& filename, Ref<SharedBuffer>&& data, std::optional<String> contentType = std::nullopt);
#endif

private:
Document& document() const;

#if ENABLE(ATTACHMENT_ELEMENT)
void insertAttachmentFromFile(const String& identifier, const String& filename, const String& contentType, Ref<File>&&);
#endif

bool canDeleteRange(Range*) const;
bool canSmartReplaceWithPasteboard(Pasteboard&);
void pasteAsPlainTextWithPasteboard(Pasteboard&);

0 comments on commit 1a25b89

Please sign in to comment.