Changeset 236822 in webkit


Ignore:
Timestamp:
Oct 3, 2018, 7:04:08 PM (8 years ago)
Author:
mitz@apple.com
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):

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r236821 r236822  
     12018-10-03  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] Let clients specify an NSFileWrapper subclassed to be used for _WKAttachment
     4        https://bugs.webkit.org/show_bug.cgi?id=190270
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
     9        (-[WKWebViewConfiguration copyWithZone:]): Copy new _attachmentFileWrapperClass ivar.
     10        (-[WKWebViewConfiguration _attachmentFileWrapperClass]): Added this getter.
     11        (-[WKWebViewConfiguration _setAttachmentFileWrapperClass:]): Added this setter, which raises
     12          an exception if the argument is not an NSFileWrapper subclass.
     13
     14        * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h: Declared new property.
     15
     16        * UIProcess/Cocoa/PageClientImplCocoa.h:
     17        * UIProcess/Cocoa/PageClientImplCocoa.mm:
     18        (WebKit::PageClientImplCocoa::allocFileWrapperInstance): Added. Allocates an instance of
     19          the class specified in the configuration, or NSFileWrapper if no custom class is specified.
     20
     21        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
     22        (WebKit::WebPageProxy::platformRegisterAttachment): Use PageClient::allocFileWrapperInstance
     23          instead of allocating an NSFileWrapper instance.
     24
     25        * UIProcess/PageClient.h:
     26        (WebKit::PageClient::allocFileWrapperInstance): Defined new function. The default
     27          implementation returns nil.
     28
    1292018-10-03  Youenn Fablet  <youenn@apple.com>
    230
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm

    r235935 r236822  
    137137    BOOL _mediaDataLoadsAutomatically;
    138138    BOOL _attachmentElementEnabled;
     139    Class _attachmentFileWrapperClass;
    139140    BOOL _mainContentUserGestureOverrideEnabled;
    140141
     
    356357    configuration->_mediaDataLoadsAutomatically = self->_mediaDataLoadsAutomatically;
    357358    configuration->_attachmentElementEnabled = self->_attachmentElementEnabled;
     359    configuration->_attachmentFileWrapperClass = self->_attachmentFileWrapperClass;
    358360    configuration->_mediaTypesRequiringUserActionForPlayback = self->_mediaTypesRequiringUserActionForPlayback;
    359361    configuration->_mainContentUserGestureOverrideEnabled = self->_mainContentUserGestureOverrideEnabled;
     
    747749}
    748750
     751- (Class)_attachmentFileWrapperClass
     752{
     753    return _attachmentFileWrapperClass;
     754}
     755
     756- (void)_setAttachmentFileWrapperClass:(Class)attachmentFileWrapperClass
     757{
     758    if (attachmentFileWrapperClass && ![attachmentFileWrapperClass isSubclassOfClass:[NSFileWrapper self]])
     759        [NSException raise:NSInvalidArgumentException format:@"Class %@ does not inherit from NSFileWrapper", attachmentFileWrapperClass];
     760
     761    _attachmentFileWrapperClass = attachmentFileWrapperClass;
     762}
     763
    749764- (BOOL)_colorFilterEnabled
    750765{
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h

    r235961 r236822  
    6666@property (nonatomic, setter=_setMediaDataLoadsAutomatically:) BOOL _mediaDataLoadsAutomatically WK_API_AVAILABLE(macosx(10.12), ios(10.0));
    6767@property (nonatomic, setter=_setAttachmentElementEnabled:) BOOL _attachmentElementEnabled WK_API_AVAILABLE(macosx(10.12), ios(10.0));
     68@property (nonatomic, setter=_setAttachmentFileWrapperClass:) Class _attachmentFileWrapperClass WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    6869@property (nonatomic, setter=_setInitialCapitalizationEnabled:) BOOL _initialCapitalizationEnabled WK_API_AVAILABLE(macosx(10.12), ios(10.0));
    6970@property (nonatomic, setter=_setApplePayEnabled:) BOOL _applePayEnabled WK_API_AVAILABLE(macosx(10.12), ios(10.0));
  • trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h

    r235156 r236822  
    4646    void didInsertAttachment(API::Attachment&, const String& source) final;
    4747    void didRemoveAttachment(API::Attachment&) final;
     48    NSFileWrapper *allocFileWrapperInstance() final;
    4849#endif
    4950
  • trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm

    r235156 r236822  
    2727#import "PageClientImplCocoa.h"
    2828
     29#import "WKWebViewConfigurationPrivate.h"
    2930#import "WKWebViewInternal.h"
    3031
     
    6667}
    6768
     69NSFileWrapper *PageClientImplCocoa::allocFileWrapperInstance()
     70{
     71#if WK_API_ENABLED
     72    Class cls = m_webView.configuration._attachmentFileWrapperClass ?: [NSFileWrapper self];
     73    return [cls alloc];
     74#else
     75    return nil;
     76#endif
     77}
     78
    6879#endif
    6980   
  • trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm

    r236634 r236822  
    169169
    170170    auto buffer = SharedBuffer::create(dataReference.data(), dataReference.size());
    171     auto fileWrapper = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:buffer->createNSData().autorelease()]);
     171    auto fileWrapper = adoptNS([pageClient().allocFileWrapperInstance() initRegularFileWithContents:buffer->createNSData().autorelease()]);
    172172    [fileWrapper setPreferredFilename:preferredFileName];
    173173    attachment->setFileWrapper(fileWrapper.get());
     
    179179        return;
    180180
    181     auto fileWrapper = adoptNS([[NSFileWrapper alloc] initWithURL:[NSURL fileURLWithPath:filePath] options:0 error:nil]);
     181    auto fileWrapper = adoptNS([pageClient().allocFileWrapperInstance() initWithURL:[NSURL fileURLWithPath:filePath] options:0 error:nil]);
    182182    attachment->setFileWrapper(fileWrapper.get());
    183183}
  • trunk/Source/WebKit/UIProcess/PageClient.h

    r236257 r236822  
    4545
    4646OBJC_CLASS CALayer;
     47OBJC_CLASS NSFileWrapper;
    4748OBJC_CLASS _WKRemoteObjectRegistry;
    4849
     
    444445    virtual void didInsertAttachment(API::Attachment&, const String& source) { }
    445446    virtual void didRemoveAttachment(API::Attachment&) { }
     447    virtual NSFileWrapper *allocFileWrapperInstance() { return nullptr; }
    446448#endif
    447449};
  • trunk/Tools/ChangeLog

    r236788 r236822  
     12018-10-03  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] Let clients specify an NSFileWrapper subclassed to be used for _WKAttachment
     4        https://bugs.webkit.org/show_bug.cgi?id=190270
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
     9        (TestWebKitAPI::TEST):
     10
    1112018-10-03  Ryosuke Niwa  <rniwa@webkit.org>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm

    r236634 r236822  
    567567}
    568568
     569@interface FileWrapper : NSFileWrapper
     570@end
     571
     572@implementation FileWrapper
     573@end
     574
    569575namespace TestWebKitAPI {
    570576
     
    14321438}
    14331439
     1440TEST(WKAttachmentTests, CustomFileWrapperSubclass)
     1441{
     1442    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1443    [configuration _setAttachmentElementEnabled:YES];
     1444    RetainPtr<NSException> exception;
     1445    @try {
     1446        [configuration _setAttachmentFileWrapperClass:[NSArray self]];
     1447    } @catch(NSException *caught) {
     1448        exception = caught;
     1449    }
     1450    EXPECT_TRUE(exception);
     1451
     1452    [configuration _setAttachmentFileWrapperClass:[FileWrapper self]];
     1453
     1454    auto webView = webViewForTestingAttachments(CGSizeZero, configuration.get());
     1455
     1456    ObserveAttachmentUpdatesForScope observer(webView.get());
     1457    platformCopyPNG();
     1458    [webView _synchronouslyExecuteEditCommand:@"Paste" argument:nil];
     1459    NSArray<_WKAttachment *> * insertedAttachments = observer.observer().inserted;
     1460
     1461    EXPECT_EQ(1U, insertedAttachments.count);
     1462    EXPECT_EQ([FileWrapper self], [insertedAttachments.firstObject.info.fileWrapper class]);
     1463}
     1464
    14341465#pragma mark - Platform-specific tests
    14351466
Note: See TracChangeset for help on using the changeset viewer.