Title: [236822] trunk
Revision
236822
Author
[email protected]
Date
2018-10-03 19:04:08 -0700 (Wed, 03 Oct 2018)

Log Message

[Cocoa] Let clients specify an NSFileWrapper subclassed to be used for _WKAttachment
https://bugs.webkit.org/show_bug.cgi?id=190270

Reviewed by Wenson Hsieh.

Source/WebKit:

* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(-[WKWebViewConfiguration copyWithZone:]): Copy new _attachmentFileWrapperClass ivar.
(-[WKWebViewConfiguration _attachmentFileWrapperClass]): Added this getter.
(-[WKWebViewConfiguration _setAttachmentFileWrapperClass:]): Added this setter, which raises
  an exception if the argument is not an NSFileWrapper subclass.

* UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h: Declared new property.

* UIProcess/Cocoa/PageClientImplCocoa.h:
* UIProcess/Cocoa/PageClientImplCocoa.mm:
(WebKit::PageClientImplCocoa::allocFileWrapperInstance): Added. Allocates an instance of
  the class specified in the configuration, or NSFileWrapper if no custom class is specified.

* UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::platformRegisterAttachment): Use PageClient::allocFileWrapperInstance
  instead of allocating an NSFileWrapper instance.

* UIProcess/PageClient.h:
(WebKit::PageClient::allocFileWrapperInstance): Defined new function. The default
  implementation returns nil.

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (236821 => 236822)


--- trunk/Source/WebKit/ChangeLog	2018-10-04 01:53:27 UTC (rev 236821)
+++ trunk/Source/WebKit/ChangeLog	2018-10-04 02:04:08 UTC (rev 236822)
@@ -1,3 +1,31 @@
+2018-10-03  Dan Bernstein  <[email protected]>
+
+        [Cocoa] Let clients specify an NSFileWrapper subclassed to be used for _WKAttachment
+        https://bugs.webkit.org/show_bug.cgi?id=190270
+
+        Reviewed by Wenson Hsieh.
+
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+        (-[WKWebViewConfiguration copyWithZone:]): Copy new _attachmentFileWrapperClass ivar.
+        (-[WKWebViewConfiguration _attachmentFileWrapperClass]): Added this getter.
+        (-[WKWebViewConfiguration _setAttachmentFileWrapperClass:]): Added this setter, which raises
+          an exception if the argument is not an NSFileWrapper subclass.
+
+        * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h: Declared new property.
+
+        * UIProcess/Cocoa/PageClientImplCocoa.h:
+        * UIProcess/Cocoa/PageClientImplCocoa.mm:
+        (WebKit::PageClientImplCocoa::allocFileWrapperInstance): Added. Allocates an instance of
+          the class specified in the configuration, or NSFileWrapper if no custom class is specified.
+
+        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
+        (WebKit::WebPageProxy::platformRegisterAttachment): Use PageClient::allocFileWrapperInstance
+          instead of allocating an NSFileWrapper instance.
+
+        * UIProcess/PageClient.h:
+        (WebKit::PageClient::allocFileWrapperInstance): Defined new function. The default
+          implementation returns nil.
+
 2018-10-03  Youenn Fablet  <[email protected]>
 
         Add VP8 support to WebRTC

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm (236821 => 236822)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm	2018-10-04 01:53:27 UTC (rev 236821)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm	2018-10-04 02:04:08 UTC (rev 236822)
@@ -136,6 +136,7 @@
     BOOL _invisibleAutoplayNotPermitted;
     BOOL _mediaDataLoadsAutomatically;
     BOOL _attachmentElementEnabled;
+    Class _attachmentFileWrapperClass;
     BOOL _mainContentUserGestureOverrideEnabled;
 
 #if PLATFORM(MAC)
@@ -355,6 +356,7 @@
     configuration->_invisibleAutoplayNotPermitted = self->_invisibleAutoplayNotPermitted;
     configuration->_mediaDataLoadsAutomatically = self->_mediaDataLoadsAutomatically;
     configuration->_attachmentElementEnabled = self->_attachmentElementEnabled;
+    configuration->_attachmentFileWrapperClass = self->_attachmentFileWrapperClass;
     configuration->_mediaTypesRequiringUserActionForPlayback = self->_mediaTypesRequiringUserActionForPlayback;
     configuration->_mainContentUserGestureOverrideEnabled = self->_mainContentUserGestureOverrideEnabled;
     configuration->_waitsForPaintAfterViewDidMoveToWindow = self->_waitsForPaintAfterViewDidMoveToWindow;
@@ -746,6 +748,19 @@
     _attachmentElementEnabled = attachmentElementEnabled;
 }
 
+- (Class)_attachmentFileWrapperClass
+{
+    return _attachmentFileWrapperClass;
+}
+
+- (void)_setAttachmentFileWrapperClass:(Class)attachmentFileWrapperClass
+{
+    if (attachmentFileWrapperClass && ![attachmentFileWrapperClass isSubclassOfClass:[NSFileWrapper self]])
+        [NSException raise:NSInvalidArgumentException format:@"Class %@ does not inherit from NSFileWrapper", attachmentFileWrapperClass];
+
+    _attachmentFileWrapperClass = attachmentFileWrapperClass;
+}
+
 - (BOOL)_colorFilterEnabled
 {
     return _colorFilterEnabled;

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h (236821 => 236822)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h	2018-10-04 01:53:27 UTC (rev 236821)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h	2018-10-04 02:04:08 UTC (rev 236822)
@@ -65,6 +65,7 @@
 @property (nonatomic, setter=_setInvisibleAutoplayNotPermitted:) BOOL _invisibleAutoplayNotPermitted WK_API_AVAILABLE(macosx(10.12), ios(10.0));
 @property (nonatomic, setter=_setMediaDataLoadsAutomatically:) BOOL _mediaDataLoadsAutomatically WK_API_AVAILABLE(macosx(10.12), ios(10.0));
 @property (nonatomic, setter=_setAttachmentElementEnabled:) BOOL _attachmentElementEnabled WK_API_AVAILABLE(macosx(10.12), ios(10.0));
+@property (nonatomic, setter=_setAttachmentFileWrapperClass:) Class _attachmentFileWrapperClass WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 @property (nonatomic, setter=_setInitialCapitalizationEnabled:) BOOL _initialCapitalizationEnabled WK_API_AVAILABLE(macosx(10.12), ios(10.0));
 @property (nonatomic, setter=_setApplePayEnabled:) BOOL _applePayEnabled WK_API_AVAILABLE(macosx(10.12), ios(10.0));
 @property (nonatomic, setter=_setWaitsForPaintAfterViewDidMoveToWindow:) BOOL _waitsForPaintAfterViewDidMoveToWindow WK_API_AVAILABLE(macosx(10.12.3), ios(10.3));

Modified: trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h (236821 => 236822)


--- trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h	2018-10-04 01:53:27 UTC (rev 236821)
+++ trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h	2018-10-04 02:04:08 UTC (rev 236822)
@@ -45,6 +45,7 @@
 #if ENABLE(ATTACHMENT_ELEMENT)
     void didInsertAttachment(API::Attachment&, const String& source) final;
     void didRemoveAttachment(API::Attachment&) final;
+    NSFileWrapper *allocFileWrapperInstance() final;
 #endif
 
 protected:

Modified: trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm (236821 => 236822)


--- trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm	2018-10-04 01:53:27 UTC (rev 236821)
+++ trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm	2018-10-04 02:04:08 UTC (rev 236822)
@@ -26,6 +26,7 @@
 #import "config.h"
 #import "PageClientImplCocoa.h"
 
+#import "WKWebViewConfigurationPrivate.h"
 #import "WKWebViewInternal.h"
 
 namespace WebKit {
@@ -65,6 +66,16 @@
 #endif
 }
 
+NSFileWrapper *PageClientImplCocoa::allocFileWrapperInstance()
+{
+#if WK_API_ENABLED
+    Class cls = m_webView.configuration._attachmentFileWrapperClass ?: [NSFileWrapper self];
+    return [cls alloc];
+#else
+    return nil;
 #endif
+}
+
+#endif
     
 }

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (236821 => 236822)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2018-10-04 01:53:27 UTC (rev 236821)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2018-10-04 02:04:08 UTC (rev 236822)
@@ -168,7 +168,7 @@
         return;
 
     auto buffer = SharedBuffer::create(dataReference.data(), dataReference.size());
-    auto fileWrapper = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:buffer->createNSData().autorelease()]);
+    auto fileWrapper = adoptNS([pageClient().allocFileWrapperInstance() initRegularFileWithContents:buffer->createNSData().autorelease()]);
     [fileWrapper setPreferredFilename:preferredFileName];
     attachment->setFileWrapper(fileWrapper.get());
 }
@@ -178,7 +178,7 @@
     if (!filePath)
         return;
 
-    auto fileWrapper = adoptNS([[NSFileWrapper alloc] initWithURL:[NSURL fileURLWithPath:filePath] options:0 error:nil]);
+    auto fileWrapper = adoptNS([pageClient().allocFileWrapperInstance() initWithURL:[NSURL fileURLWithPath:filePath] options:0 error:nil]);
     attachment->setFileWrapper(fileWrapper.get());
 }
 

Modified: trunk/Source/WebKit/UIProcess/PageClient.h (236821 => 236822)


--- trunk/Source/WebKit/UIProcess/PageClient.h	2018-10-04 01:53:27 UTC (rev 236821)
+++ trunk/Source/WebKit/UIProcess/PageClient.h	2018-10-04 02:04:08 UTC (rev 236822)
@@ -44,6 +44,7 @@
 #include "WKFoundation.h"
 
 OBJC_CLASS CALayer;
+OBJC_CLASS NSFileWrapper;
 OBJC_CLASS _WKRemoteObjectRegistry;
 
 #if USE(APPKIT)
@@ -443,6 +444,7 @@
 #if ENABLE(ATTACHMENT_ELEMENT)
     virtual void didInsertAttachment(API::Attachment&, const String& source) { }
     virtual void didRemoveAttachment(API::Attachment&) { }
+    virtual NSFileWrapper *allocFileWrapperInstance() { return nullptr; }
 #endif
 };
 

Modified: trunk/Tools/ChangeLog (236821 => 236822)


--- trunk/Tools/ChangeLog	2018-10-04 01:53:27 UTC (rev 236821)
+++ trunk/Tools/ChangeLog	2018-10-04 02:04:08 UTC (rev 236822)
@@ -1,3 +1,13 @@
+2018-10-03  Dan Bernstein  <[email protected]>
+
+        [Cocoa] Let clients specify an NSFileWrapper subclassed to be used for _WKAttachment
+        https://bugs.webkit.org/show_bug.cgi?id=190270
+
+        Reviewed by Wenson Hsieh.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+        (TestWebKitAPI::TEST):
+
 2018-10-03  Ryosuke Niwa  <[email protected]>
 
         Enable selectionAcrossShadowBoundariesEnabled by default in WebKitLegacy

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm (236821 => 236822)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2018-10-04 01:53:27 UTC (rev 236821)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2018-10-04 02:04:08 UTC (rev 236822)
@@ -566,6 +566,12 @@
 #endif
 }
 
+@interface FileWrapper : NSFileWrapper
+@end
+
+@implementation FileWrapper
+@end
+
 namespace TestWebKitAPI {
 
 #pragma mark - Platform-agnostic tests
@@ -1431,6 +1437,31 @@
     [webView waitForImageElementSizeToBecome:CGSizeMake(52, 64)];
 }
 
+TEST(WKAttachmentTests, CustomFileWrapperSubclass)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration _setAttachmentElementEnabled:YES];
+    RetainPtr<NSException> exception;
+    @try {
+        [configuration _setAttachmentFileWrapperClass:[NSArray self]];
+    } @catch(NSException *caught) {
+        exception = caught;
+    }
+    EXPECT_TRUE(exception);
+
+    [configuration _setAttachmentFileWrapperClass:[FileWrapper self]];
+
+    auto webView = webViewForTestingAttachments(CGSizeZero, configuration.get());
+
+    ObserveAttachmentUpdatesForScope observer(webView.get());
+    platformCopyPNG();
+    [webView _synchronouslyExecuteEditCommand:@"Paste" argument:nil];
+    NSArray<_WKAttachment *> * insertedAttachments = observer.observer().inserted;
+
+    EXPECT_EQ(1U, insertedAttachments.count);
+    EXPECT_EQ([FileWrapper self], [insertedAttachments.firstObject.info.fileWrapper class]);
+}
+
 #pragma mark - Platform-specific tests
 
 #if PLATFORM(MAC)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to