Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
34 changed files
with
822 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -1,4 +1,5 @@ | ||
set(PAL_SOURCES | ||
FileSizeFormatter.cpp | ||
Logging.cpp | ||
SessionID.cpp | ||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.