Title: [266743] trunk
Revision
266743
Author
[email protected]
Date
2020-09-08 12:47:05 -0700 (Tue, 08 Sep 2020)

Log Message

iOS: <attachment>'s QuickLook thumbnails can appear squished
https://bugs.webkit.org/show_bug.cgi?id=216209
<rdar://problem/67817706>

Reviewed by Wenson Hsieh.

Source/WebCore:

Test: fast/attachment/attachment-thumbnail-preserves-aspect-ratio.html

* html/HTMLAttachmentElement.idl:
* testing/Internals.cpp:
(WebCore::Internals::attachmentThumbnailInfo):
* testing/Internals.h:
* testing/Internals.idl:
Expose the attachment thumbnail size via Internals.

* rendering/RenderThemeIOS.mm:
(WebCore::RenderAttachmentInfo::RenderAttachmentInfo):
Allow the thumbnail aspect ratio to vary, instead of assuming it is always square.

Source/WebKit:

* UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::convertPlatformImageToBitmap):
Propagate an image of the same aspect ratio that QuickLook provided,
instead of squishing it to square.

* UIProcess/QuickLookThumbnailLoader.mm:
(-[WKQLThumbnailLoadOperation start]):
Only request full thumbnails; we do not want the icon form, since <attachment>
already has one without QuickLook's help; if we can't get a full thumbnail,
we'll just leave it alone.

Tools:

* TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
* TestRunnerShared/UIScriptContext/UIScriptController.h:
(WTR::UIScriptController::insertAttachmentForFilePath):
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::currentTestURL const):
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/cocoa/UIScriptControllerCocoa.h:
* WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm:
(WTR::UIScriptControllerCocoa::insertAttachmentForFilePath):
Make it possible to insert an attachment wrapping a file on disk
via UIScriptController.

LayoutTests:

* fast/attachment/attachment-thumbnail-preserves-aspect-ratio-expected.txt: Added.
* fast/attachment/attachment-thumbnail-preserves-aspect-ratio.html: Added.
* fast/attachment/resources/400x200-circle.png: Added.
* platform/ios/fast/attachment/attachment-thumbnail-preserves-aspect-ratio-expected.txt: Added.
* resources/ui-helper.js:
(window.UIHelper.insertAttachmentForFilePath):
Add a test that dumps the thumbnail size for a 400x200 attachment.
We only run it on iOS, because on macOS, QuickLook always returns
an image of the size we ask for (400x400), padded with whitespace,
so the problem does not reproduce and the test doesn't work right there.
On iOS, the result used to be 400x400 and now is 400x200.

I tried and failed to make a more useful test (a ref test, actually
testing the presentation) because it's quite hard to match the
native <attachment> painting.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (266742 => 266743)


--- trunk/LayoutTests/ChangeLog	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/LayoutTests/ChangeLog	2020-09-08 19:47:05 UTC (rev 266743)
@@ -1,3 +1,27 @@
+2020-09-08  Tim Horton  <[email protected]>
+
+        iOS: <attachment>'s QuickLook thumbnails can appear squished
+        https://bugs.webkit.org/show_bug.cgi?id=216209
+        <rdar://problem/67817706>
+
+        Reviewed by Wenson Hsieh.
+
+        * fast/attachment/attachment-thumbnail-preserves-aspect-ratio-expected.txt: Added.
+        * fast/attachment/attachment-thumbnail-preserves-aspect-ratio.html: Added.
+        * fast/attachment/resources/400x200-circle.png: Added.
+        * platform/ios/fast/attachment/attachment-thumbnail-preserves-aspect-ratio-expected.txt: Added.
+        * resources/ui-helper.js:
+        (window.UIHelper.insertAttachmentForFilePath):
+        Add a test that dumps the thumbnail size for a 400x200 attachment.
+        We only run it on iOS, because on macOS, QuickLook always returns
+        an image of the size we ask for (400x400), padded with whitespace,
+        so the problem does not reproduce and the test doesn't work right there.
+        On iOS, the result used to be 400x400 and now is 400x200.
+        
+        I tried and failed to make a more useful test (a ref test, actually
+        testing the presentation) because it's quite hard to match the
+        native <attachment> painting.
+
 2020-09-08  Frank Yang  <[email protected]>
 
         CoreImage Implementation of CSS Filters invert(), opacity(), brightness(), contrast()

Modified: trunk/LayoutTests/TestExpectations (266742 => 266743)


--- trunk/LayoutTests/TestExpectations	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/LayoutTests/TestExpectations	2020-09-08 19:47:05 UTC (rev 266743)
@@ -183,6 +183,7 @@
 fast/attachment/attachment-wrapping-action.html [ Skip ]
 fast/attachment/attachment-borderless.html [ Skip ]
 fast/attachment/attachment-dynamic-type.html [ Skip ]
+fast/attachment/attachment-thumbnail-preserves-aspect-ratio.html [ Skip ]
 editing/selection/character-granularity-selected-range-after-dismissing-selection.html [ Skip ]
 editing/selection/character-granularity-select-text-with-click-handler.html [ Skip ]
 editing/selection/caret-after-tap-in-editable-selection.html [ Skip ]

Added: trunk/LayoutTests/fast/attachment/attachment-thumbnail-preserves-aspect-ratio-expected.txt (0 => 266743)


--- trunk/LayoutTests/fast/attachment/attachment-thumbnail-preserves-aspect-ratio-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/attachment/attachment-thumbnail-preserves-aspect-ratio-expected.txt	2020-09-08 19:47:05 UTC (rev 266743)
@@ -0,0 +1 @@
+Attachment Thumbnail: 400x200

Added: trunk/LayoutTests/fast/attachment/attachment-thumbnail-preserves-aspect-ratio.html (0 => 266743)


--- trunk/LayoutTests/fast/attachment/attachment-thumbnail-preserves-aspect-ratio.html	                        (rev 0)
+++ trunk/LayoutTests/fast/attachment/attachment-thumbnail-preserves-aspect-ratio.html	2020-09-08 19:47:05 UTC (rev 266743)
@@ -0,0 +1,36 @@
+<!DOCTYPE html><!-- webkit-test-runner [ enableAttachmentElement=true ] -->
+<html>
+<body contenteditable>
+<script src=""
+<script src=""
+<script>
+async function runTest() {
+    await UIHelper.activateAt(10, 10);
+    await UIHelper.insertAttachmentForFilePath("resources/400x200-circle.png", "image/png");
+
+    function attachmentThumbnailInfo() {
+        return window.internals.attachmentThumbnailInfo(document.getElementsByTagName("attachment")[0]);
+    }
+
+    try {
+        attachmentThumbnailInfo();
+    } catch (e) {
+        if (e.name == "InvalidAccessError")
+            document.body.innerText = `Attachment thumbnails not supported.`;
+        else
+            document.body.innerText = e.name;
+    }
+
+    shouldBecomeDifferent('attachmentThumbnailInfo().width', '0', function () {
+        let info = attachmentThumbnailInfo();
+        document.body.innerText = `Attachment Thumbnail: ${info.width}x${info.height}`;
+        testRunner.notifyDone();
+    });
+}
+
+testRunner.dumpAsText();
+testRunner.waitUntilDone();
+addEventListener("load", runTest);
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/fast/attachment/resources/400x200-circle.png


(Binary files differ)
Index: trunk/LayoutTests/fast/attachment/resources/400x200-circle.png =================================================================== --- trunk/LayoutTests/fast/attachment/resources/400x200-circle.png 2020-09-08 19:37:42 UTC (rev 266742) +++ trunk/LayoutTests/fast/attachment/resources/400x200-circle.png 2020-09-08 19:47:05 UTC (rev 266743) Property changes on: trunk/LayoutTests/fast/attachment/resources/400x200-circle.png ___________________________________________________________________

Added: svn:mime-type

+image/png \ No newline at end of property

Modified: trunk/LayoutTests/platform/ios/TestExpectations (266742 => 266743)


--- trunk/LayoutTests/platform/ios/TestExpectations	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/LayoutTests/platform/ios/TestExpectations	2020-09-08 19:47:05 UTC (rev 266743)
@@ -2523,6 +2523,7 @@
 fast/attachment/attachment-wrapping-action.html [ Pass ]
 fast/attachment/attachment-borderless.html [ Pass ]
 fast/attachment/attachment-dynamic-type.html [ Pass ]
+fast/attachment/attachment-thumbnail-preserves-aspect-ratio.html [ Pass ]
 fast/images/pdf-as-image-dest-rect-change.html [ Pass ]
 
 fast/events/page-visibility-iframe-move-test.html [ Skip ]

Modified: trunk/LayoutTests/resources/ui-helper.js (266742 => 266743)


--- trunk/LayoutTests/resources/ui-helper.js	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/LayoutTests/resources/ui-helper.js	2020-09-08 19:47:05 UTC (rev 266743)
@@ -1002,6 +1002,19 @@
         });
     }
 
+    static insertAttachmentForFilePath(path, contentType)
+    {
+        if (!this.isWebKit2())
+            return Promise.resolve();
+
+        return new Promise(resolve => {
+            testRunner.runUIScript(`
+                uiController.insertAttachmentForFilePath('${path}', '${contentType}', function() {
+                    uiController.uiScriptComplete();
+                });`, resolve);
+        });
+    }
+
     static setMinimumEffectiveWidth(effectiveWidth)
     {
         if (!this.isWebKit2())

Modified: trunk/Source/WebCore/ChangeLog (266742 => 266743)


--- trunk/Source/WebCore/ChangeLog	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Source/WebCore/ChangeLog	2020-09-08 19:47:05 UTC (rev 266743)
@@ -1,3 +1,24 @@
+2020-09-08  Tim Horton  <[email protected]>
+
+        iOS: <attachment>'s QuickLook thumbnails can appear squished
+        https://bugs.webkit.org/show_bug.cgi?id=216209
+        <rdar://problem/67817706>
+
+        Reviewed by Wenson Hsieh.
+
+        Test: fast/attachment/attachment-thumbnail-preserves-aspect-ratio.html
+
+        * html/HTMLAttachmentElement.idl:
+        * testing/Internals.cpp:
+        (WebCore::Internals::attachmentThumbnailInfo):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+        Expose the attachment thumbnail size via Internals.
+
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::RenderAttachmentInfo::RenderAttachmentInfo):
+        Allow the thumbnail aspect ratio to vary, instead of assuming it is always square.
+
 2020-09-08  Sihui Liu  <[email protected]>
 
         Remove storage WorkQueue in NetworkProcess

Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.idl (266742 => 266743)


--- trunk/Source/WebCore/html/HTMLAttachmentElement.idl	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.idl	2020-09-08 19:47:05 UTC (rev 266743)
@@ -25,6 +25,8 @@
 
 [
     Conditional=ATTACHMENT_ELEMENT,
+    JSGenerateToNativeObject,
+    ExportMacro=WEBCORE_EXPORT,
     EnabledAtRuntime=AttachmentElement,
 ] interface HTMLAttachmentElement : HTMLElement {
     attribute File? file;

Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (266742 => 266743)


--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2020-09-08 19:47:05 UTC (rev 266743)
@@ -1642,10 +1642,11 @@
         FloatSize iconSize;
         icon = iconForAttachment(attachment, iconSize);
         thumbnailIcon = attachment.attachmentElement().thumbnail();
+        if (thumbnailIcon)
+            iconSize = largestRectWithAspectRatioInsideRect(thumbnailIcon->size().aspectRatio(), FloatRect(0, 0, attachmentIconSize, attachmentIconSize)).size();
         
         if (thumbnailIcon || icon) {
-            auto visibleIconSize = thumbnailIcon ? FloatSize(attachmentIconSize, attachmentIconSize) : iconSize;
-            iconRect = FloatRect(FloatPoint((attachmentRect.width() / 2) - (visibleIconSize.width() / 2), 0), visibleIconSize);
+            iconRect = FloatRect(FloatPoint((attachmentRect.width() / 2) - (iconSize.width() / 2), 0), iconSize);
             yOffset += iconRect.height() + attachmentItemMargin;
         }
     } else

Modified: trunk/Source/WebCore/testing/Internals.cpp (266742 => 266743)


--- trunk/Source/WebCore/testing/Internals.cpp	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Source/WebCore/testing/Internals.cpp	2020-09-08 19:47:05 UTC (rev 266743)
@@ -88,6 +88,7 @@
 #include "GridPosition.h"
 #include "HEVCUtilities.h"
 #include "HTMLAnchorElement.h"
+#include "HTMLAttachmentElement.h"
 #include "HTMLCanvasElement.h"
 #include "HTMLIFrameElement.h"
 #include "HTMLImageElement.h"
@@ -6061,4 +6062,24 @@
 #endif
 }
 
+#if ENABLE(ATTACHMENT_ELEMENT)
+
+ExceptionOr<Internals::AttachmentThumbnailInfo> Internals::attachmentThumbnailInfo(const HTMLAttachmentElement& element)
+{
+#if HAVE(QUICKLOOK_THUMBNAILING)
+    AttachmentThumbnailInfo info;
+    if (auto image = element.thumbnail()) {
+        auto size = image->size();
+        info.width = size.width();
+        info.height = size.height();
+    }
+    return info;
+#else
+    UNUSED_PARAM(element);
+    return Exception { InvalidAccessError };
+#endif
+}
+
+#endif
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/testing/Internals.h (266742 => 266743)


--- trunk/Source/WebCore/testing/Internals.h	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Source/WebCore/testing/Internals.h	2020-09-08 19:47:05 UTC (rev 266743)
@@ -69,6 +69,7 @@
 class Frame;
 class GCObservation;
 class HTMLAnchorElement;
+class HTMLAttachmentElement;
 class HTMLImageElement;
 class HTMLInputElement;
 class HTMLLinkElement;
@@ -1058,6 +1059,15 @@
     enum class ContentSizeCategory { L, XXXL };
     void setContentSizeCategory(ContentSizeCategory);
 
+#if ENABLE(ATTACHMENT_ELEMENT)
+    struct AttachmentThumbnailInfo {
+        unsigned width { 0 };
+        unsigned height { 0 };
+    };
+
+    ExceptionOr<AttachmentThumbnailInfo> attachmentThumbnailInfo(const HTMLAttachmentElement&);
+#endif
+
 private:
     explicit Internals(Document&);
     Document* contextDocument() const;

Modified: trunk/Source/WebCore/testing/Internals.idl (266742 => 266743)


--- trunk/Source/WebCore/testing/Internals.idl	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Source/WebCore/testing/Internals.idl	2020-09-08 19:47:05 UTC (rev 266743)
@@ -237,7 +237,16 @@
 
 [
     ExportMacro=WEBCORE_TESTSUPPORT_EXPORT,
+    Conditional=ATTACHMENT_ELEMENT,
     JSGenerateToJSObject,
+] dictionary AttachmentThumbnailInfo {
+    unsigned long width;
+    unsigned long height;
+};
+
+[
+    ExportMacro=WEBCORE_TESTSUPPORT_EXPORT,
+    JSGenerateToJSObject,
 ] dictionary TextIndicatorOptions {
     boolean useBoundingRectAndPaintAllContentForComplexRanges = false;
     boolean computeEstimatedBackgroundColor = false;
@@ -965,4 +974,6 @@
     [Conditional=ENCRYPTED_MEDIA] unsigned long mediaKeySessionInternalInstanceSessionObjectRefCount(MediaKeySession session);
 
     undefined setContentSizeCategory(ContentSizeCategory category);
+
+    [Conditional=ATTACHMENT_ELEMENT, MayThrowException] AttachmentThumbnailInfo attachmentThumbnailInfo(HTMLAttachmentElement element);
 };

Modified: trunk/Source/WebKit/ChangeLog (266742 => 266743)


--- trunk/Source/WebKit/ChangeLog	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Source/WebKit/ChangeLog	2020-09-08 19:47:05 UTC (rev 266743)
@@ -1,3 +1,22 @@
+2020-09-08  Tim Horton  <[email protected]>
+
+        iOS: <attachment>'s QuickLook thumbnails can appear squished
+        https://bugs.webkit.org/show_bug.cgi?id=216209
+        <rdar://problem/67817706>
+
+        Reviewed by Wenson Hsieh.
+
+        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
+        (WebKit::convertPlatformImageToBitmap):
+        Propagate an image of the same aspect ratio that QuickLook provided,
+        instead of squishing it to square.
+
+        * UIProcess/QuickLookThumbnailLoader.mm:
+        (-[WKQLThumbnailLoadOperation start]):
+        Only request full thumbnails; we do not want the icon form, since <attachment>
+        already has one without QuickLook's help; if we can't get a full thumbnail,
+        we'll just leave it alone.
+
 2020-09-08  Sihui Liu  <[email protected]>
 
         Remove storage WorkQueue in NetworkProcess

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (266742 => 266743)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2020-09-08 19:47:05 UTC (rev 266743)
@@ -43,6 +43,7 @@
 #import "WebsiteDataStore.h"
 #import "WKErrorInternal.h"
 #import <WebCore/DragItem.h>
+#import <WebCore/GeometryUtilities.h>
 #import <WebCore/LocalCurrentGraphicsContext.h>
 #import <WebCore/NotImplemented.h>
 #import <WebCore/RunLoopObserver.h>
@@ -437,10 +438,14 @@
 
 #if HAVE(QUICKLOOK_THUMBNAILING)
 
-static RefPtr<WebKit::ShareableBitmap> convertPlatformImageToBitmap(CocoaImage *image, const WebCore::IntSize& size)
+static RefPtr<WebKit::ShareableBitmap> convertPlatformImageToBitmap(CocoaImage *image, const WebCore::IntSize& fittingSize)
 {
+    FloatSize originalThumbnailSize([image size]);
+    auto resultRect = roundedIntRect(largestRectWithAspectRatioInsideRect(originalThumbnailSize.aspectRatio(), { { }, fittingSize }));
+    resultRect.setLocation({ });
+
     WebKit::ShareableBitmap::Configuration bitmapConfiguration;
-    auto bitmap = WebKit::ShareableBitmap::createShareable(size, bitmapConfiguration);
+    auto bitmap = WebKit::ShareableBitmap::createShareable(resultRect.size(), bitmapConfiguration);
     if (!bitmap)
         return nullptr;
 
@@ -450,9 +455,9 @@
 
     LocalCurrentGraphicsContext savedContext(*graphicsContext);
 #if PLATFORM(IOS_FAMILY)
-    [image drawInRect:CGRectMake(0, 0, bitmap->size().width(), bitmap->size().height())];
+    [image drawInRect:resultRect];
 #elif USE(APPKIT)
-    [image drawInRect:NSMakeRect(0, 0, bitmap->size().width(), bitmap->size().height()) fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1 respectFlipped:YES hints:nil];
+    [image drawInRect:resultRect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1 respectFlipped:YES hints:nil];
 #endif
 
     return bitmap;

Modified: trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.mm (266742 => 266743)


--- trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.mm	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.mm	2020-09-08 19:47:05 UTC (rev 266743)
@@ -107,7 +107,7 @@
             return;
     }
 
-    auto request = adoptNS([WebKit::allocQLThumbnailGenerationRequestInstance() initWithFileAtURL:_filePath.get() size:CGSizeMake(400, 400) scale:1 representationTypes:QLThumbnailGenerationRequestRepresentationTypeAll]);
+    auto request = adoptNS([WebKit::allocQLThumbnailGenerationRequestInstance() initWithFileAtURL:_filePath.get() size:CGSizeMake(400, 400) scale:1 representationTypes:QLThumbnailGenerationRequestRepresentationTypeThumbnail]);
     [request setIconMode:YES];
     
     [[WebKit::getQLThumbnailGeneratorClass() sharedGenerator] generateBestRepresentationForRequest:request.get() completionHandler:^(QLThumbnailRepresentation *thumbnail, NSError *error) {

Modified: trunk/Tools/ChangeLog (266742 => 266743)


--- trunk/Tools/ChangeLog	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Tools/ChangeLog	2020-09-08 19:47:05 UTC (rev 266743)
@@ -1,3 +1,23 @@
+2020-09-08  Tim Horton  <[email protected]>
+
+        iOS: <attachment>'s QuickLook thumbnails can appear squished
+        https://bugs.webkit.org/show_bug.cgi?id=216209
+        <rdar://problem/67817706>
+
+        Reviewed by Wenson Hsieh.
+
+        * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
+        * TestRunnerShared/UIScriptContext/UIScriptController.h:
+        (WTR::UIScriptController::insertAttachmentForFilePath):
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::currentTestURL const):
+        * WebKitTestRunner/TestController.h:
+        * WebKitTestRunner/cocoa/UIScriptControllerCocoa.h:
+        * WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm:
+        (WTR::UIScriptControllerCocoa::insertAttachmentForFilePath):
+        Make it possible to insert an attachment wrapping a file on disk
+        via UIScriptController.
+
 2020-09-08  Aakash Jain  <[email protected]>
 
         EWS should set cq- flag when a patch fails to build or introduces layout-test failures

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl (266742 => 266743)


--- trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl	2020-09-08 19:47:05 UTC (rev 266743)
@@ -347,6 +347,7 @@
     undefined setHardwareKeyboardAttached(boolean attached);
 
     object attachmentInfo(DOMString attachmentIdentifier);
+    undefined insertAttachmentForFilePath(DOMString filePath, DOMString contentType, object callback);
 
     readonly attribute DOMString lastUndoLabel;
     readonly attribute DOMString firstRedoLabel;

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h (266742 => 266743)


--- trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h	2020-09-08 19:47:05 UTC (rev 266743)
@@ -275,6 +275,7 @@
     // Attachment Elements
 
     virtual JSObjectRef attachmentInfo(JSStringRef attachmentIdentifier) { notImplemented(); return nullptr; }
+    virtual void insertAttachmentForFilePath(JSStringRef filePath, JSStringRef contentType, JSValueRef callback) { notImplemented(); }
 
     // Callbacks
     

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (266742 => 266743)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2020-09-08 19:47:05 UTC (rev 266743)
@@ -4120,4 +4120,9 @@
     runUntil(callbackContext.done, noTimeout);
 }
 
+WKURLRef TestController::currentTestURL() const
+{
+    return m_currentInvocation ? m_currentInvocation->url() : nullptr;
+}
+
 } // namespace WTR

Modified: trunk/Tools/WebKitTestRunner/TestController.h (266742 => 266743)


--- trunk/Tools/WebKitTestRunner/TestController.h	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Tools/WebKitTestRunner/TestController.h	2020-09-08 19:47:05 UTC (rev 266743)
@@ -359,6 +359,8 @@
 
     void didSetAppBoundDomains() const;
 
+    WKURLRef currentTestURL() const;
+
 private:
     WKRetainPtr<WKPageConfigurationRef> generatePageConfiguration(const TestOptions&);
     WKRetainPtr<WKContextConfigurationRef> generateContextConfiguration(const TestOptions::ContextOptions&) const;

Modified: trunk/Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.h (266742 => 266743)


--- trunk/Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.h	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.h	2020-09-08 19:47:05 UTC (rev 266743)
@@ -57,6 +57,8 @@
 
     void setContinuousSpellCheckingEnabled(bool) override;
 
+    void insertAttachmentForFilePath(JSStringRef filePath, JSStringRef contentType, JSValueRef callback) override;
+
 protected:
     explicit UIScriptControllerCocoa(UIScriptContext&);
     TestRunnerWKWebView *webView() const;

Modified: trunk/Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm (266742 => 266743)


--- trunk/Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm	2020-09-08 19:37:42 UTC (rev 266742)
+++ trunk/Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm	2020-09-08 19:47:05 UTC (rev 266743)
@@ -32,6 +32,7 @@
 #import "TestRunnerWKWebView.h"
 #import "UIScriptContext.h"
 #import <_javascript_Core/_javascript_Core.h>
+#import <WebKit/WKURLCF.h>
 #import <WebKit/WKWebViewPrivate.h>
 #import <WebKit/WKWebViewPrivateForTesting.h>
 
@@ -208,4 +209,19 @@
     [webView() paste:nil];
 }
 
+void UIScriptControllerCocoa::insertAttachmentForFilePath(JSStringRef filePath, JSStringRef contentType, JSValueRef callback)
+{
+    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
+
+    RetainPtr<CFURLRef> testURL = adoptCF(WKURLCopyCFURL(kCFAllocatorDefault, TestController::singleton().currentTestURL()));
+    RetainPtr<NSURL> attachmentURL = [NSURL fileURLWithPath:toWTFString(toWK(filePath)) relativeToURL:(__bridge NSURL *)testURL.get()];
+
+    auto fileWrapper = adoptNS([[NSFileWrapper alloc] initWithURL:attachmentURL.get() options:0 error:nil]);
+    [webView() _insertAttachmentWithFileWrapper:fileWrapper.get() contentType:toWTFString(toWK(contentType)) completion:^(BOOL success) {
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    }];
+}
+
 } // namespace WTR
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to