⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 292888 in webkit


Ignore:
Timestamp:
Apr 14, 2022, 1:58:47 PM (4 years ago)
Author:
Wenson Hsieh
Message:

[iOS] [WK2] Managed pasteboard should function for all managed domains
https://bugs.webkit.org/show_bug.cgi?id=239319
rdar://80059355

Reviewed by Kate Cheney.

Source/WebCore/PAL:

Add an SPI method on MCProfileConnection.

  • pal/spi/ios/ManagedConfigurationSPI.h:

Source/WebKit:

Unless a WebKit client has specified a data owner for the web view that is not _UIDataOwnerUndefined, fall back
to _UIDataOwnerEnterprise when the current domain of the WKWebView is managed (that is, `-[MCProfileConnection
isURLManaged:]` returns YES for the web view's current URL). This allows managed pasteboard to work for all
WebKit clients, if the current URL is managed.

Test: UIPasteboardTests.PerformAsDataOwnerWithManagedURL

  • Platform/spi/ios/UIKitSPI.h:

Drive-by fix: move the staged declarations of -_dataOwnerForCopy and -_dataOwnerForPaste out of the IPI
section, and into the non-internal SDK section.

  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView _dataOwnerForPasteboard:]):

Tools:

Add a new API test to verify that we fall back to consulting -[MCProfileConnection isURLManaged:] when
determining the data owner for copy and paste, unless a data owner is already explicitly set on a view in the
responder chain (specifically, the WKWebView).

  • TestWebKitAPI/Tests/ios/UIPasteboardTests.mm:

(+[TestUIPasteboard _performAsDataOwner:block:]):
(-[TestMCProfileConnection isURLManaged:]):
(TestWebKitAPI::TEST):

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/PAL/ChangeLog

    r292859 r292888  
     12022-04-14  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] [WK2] Managed pasteboard should function for all managed domains
     4        https://bugs.webkit.org/show_bug.cgi?id=239319
     5        rdar://80059355
     6
     7        Reviewed by Kate Cheney.
     8
     9        Add an SPI method on `MCProfileConnection`.
     10
     11        * pal/spi/ios/ManagedConfigurationSPI.h:
     12
    1132022-04-13  Myles C. Maxfield  <mmaxfield@apple.com>
    214
  • trunk/Source/WebCore/PAL/pal/spi/ios/ManagedConfigurationSPI.h

    r259373 r292888  
    5757@end
    5858
     59@class NSURL;
     60
    5961@interface MCProfileConnection ()
    6062+ (MCProfileConnection *)sharedConnection;
    6163- (MCRestrictedBoolType)effectiveBoolValueForSetting:(NSString *)feature;
     64- (BOOL)isURLManaged:(NSURL *)url;
    6265@end
    6366
  • trunk/Source/WebKit/ChangeLog

    r292882 r292888  
     12022-04-14  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] [WK2] Managed pasteboard should function for all managed domains
     4        https://bugs.webkit.org/show_bug.cgi?id=239319
     5        rdar://80059355
     6
     7        Reviewed by Kate Cheney.
     8
     9        Unless a WebKit client has specified a data owner for the web view that is not _UIDataOwnerUndefined, fall back
     10        to _UIDataOwnerEnterprise when the current domain of the WKWebView is managed (that is, `-[MCProfileConnection
     11        isURLManaged:]` returns YES for the web view's current URL). This allows managed pasteboard to work for all
     12        WebKit clients, if the current URL is managed.
     13
     14        Test: UIPasteboardTests.PerformAsDataOwnerWithManagedURL
     15
     16        * Platform/spi/ios/UIKitSPI.h:
     17
     18        Drive-by fix: move the staged declarations of `-_dataOwnerForCopy` and `-_dataOwnerForPaste` out of the IPI
     19        section, and into the non-internal SDK section.
     20
     21        * UIProcess/ios/WKContentViewInteraction.mm:
     22        (-[WKContentView _dataOwnerForPasteboard:]):
     23
    1242022-04-14  J Pascoe  <j_pascoe@apple.com>
    225
  • trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h

    r292715 r292888  
    169169};
    170170
     171typedef NS_ENUM(NSInteger, _UIDataOwner) {
     172    _UIDataOwnerUndefined,
     173    _UIDataOwnerUser,
     174    _UIDataOwnerEnterprise,
     175    _UIDataOwnerShared,
     176};
     177
    171178@class UIPreviewItemController;
    172179
     
    491498- (void)_beginPinningInputViews;
    492499- (void)_endPinningInputViews;
    493 
     500#if HAVE(PASTEBOARD_DATA_OWNER)
     501@property (nonatomic, setter=_setDataOwnerForCopy:) _UIDataOwner _dataOwnerForCopy;
     502@property (nonatomic, setter=_setDataOwnerForPaste:) _UIDataOwner _dataOwnerForPaste;
     503#endif
    494504@end
    495505
     
    13731383#endif // USE(APPLE_INTERNAL_SDK)
    13741384
    1375 #if HAVE(PASTEBOARD_DATA_OWNER)
    1376 
    1377 @interface UIResponder (Staging_73852335)
    1378 @property (nonatomic, setter=_setDataOwnerForCopy:) _UIDataOwner _dataOwnerForCopy;
    1379 @property (nonatomic, setter=_setDataOwnerForPaste:) _UIDataOwner _dataOwnerForPaste;
    1380 @end
    1381 
    1382 #endif
    1383 
    13841385@interface UITextInteractionAssistant (IPI)
    13851386@property (nonatomic, readonly) BOOL inGesture;
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r292880 r292888  
    82038203- (WebCore::DataOwnerType)_dataOwnerForPasteboard:(WebKit::PasteboardAccessIntent)intent
    82048204{
    8205     if (![self respondsToSelector:@selector(_dataOwnerForPaste)]) {
    8206         // FIXME: Remove this once the relevant bots have fix for <rdar://problem/73852335>.
     8205    auto specifiedType = [&] {
     8206        if (intent == WebKit::PasteboardAccessIntent::Read)
     8207            return coreDataOwnerType(self._dataOwnerForPaste);
     8208
     8209        if (intent == WebKit::PasteboardAccessIntent::Write)
     8210            return coreDataOwnerType(self._dataOwnerForCopy);
     8211
     8212        ASSERT_NOT_REACHED();
    82078213        return WebCore::DataOwnerType::Undefined;
    8208     }
    8209 
    8210     if (intent == WebKit::PasteboardAccessIntent::Read)
    8211         return coreDataOwnerType(self._dataOwnerForPaste);
    8212 
    8213     if (intent == WebKit::PasteboardAccessIntent::Write)
    8214         return coreDataOwnerType(self._dataOwnerForCopy);
    8215 
    8216     ASSERT_NOT_REACHED();
     8214    }();
     8215
     8216    if (specifiedType != WebCore::DataOwnerType::Undefined)
     8217        return specifiedType;
     8218
     8219    if ([[PAL::getMCProfileConnectionClass() sharedConnection] isURLManaged:[_webView URL]])
     8220        return WebCore::DataOwnerType::Enterprise;
     8221
    82178222    return WebCore::DataOwnerType::Undefined;
    82188223}
  • trunk/Tools/ChangeLog

    r292882 r292888  
     12022-04-14  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] [WK2] Managed pasteboard should function for all managed domains
     4        https://bugs.webkit.org/show_bug.cgi?id=239319
     5        rdar://80059355
     6
     7        Reviewed by Kate Cheney.
     8
     9        Add a new API test to verify that we fall back to consulting `-[MCProfileConnection isURLManaged:]` when
     10        determining the data owner for copy and paste, unless a data owner is already explicitly set on a view in the
     11        responder chain (specifically, the WKWebView).
     12
     13        * TestWebKitAPI/Tests/ios/UIPasteboardTests.mm:
     14        (+[TestUIPasteboard _performAsDataOwner:block:]):
     15        (-[TestMCProfileConnection isURLManaged:]):
     16        (TestWebKitAPI::TEST):
     17
    1182022-04-14  J Pascoe  <j_pascoe@apple.com>
    219
  • trunk/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm

    r273184 r292888  
    2929
    3030#import "ClassMethodSwizzler.h"
     31#import "InstanceMethodSwizzler.h"
    3132#import "PlatformUtilities.h"
    3233#import "TestWKWebView.h"
     
    3637#import <WebKit/WKPreferencesPrivate.h>
    3738#import <WebKit/WKWebViewPrivate.h>
    38 #import <wtf/SoftLinking.h>
     39#import <pal/ios/ManagedConfigurationSoftLink.h>
    3940
    4041typedef void (^DataLoadCompletionBlock)(NSData *, NSError *);
     
    6465    block();
    6566    gLastKnownDataOwner = owner;
     67}
     68
     69@end
     70
     71@interface TestMCProfileConnection : NSObject
     72@end
     73
     74@implementation TestMCProfileConnection
     75
     76- (BOOL)isURLManaged:(NSURL *)url
     77{
     78    return [url.lastPathComponent isEqualToString:@"simple.html"];
    6679}
    6780
     
    412425}
    413426
     427TEST(UIPasteboardTests, PerformAsDataOwnerWithManagedURL)
     428{
     429    auto pasteboardSwizzler = ClassMethodSwizzler {
     430        UIPasteboard.class,
     431        @selector(_performAsDataOwner:block:),
     432        [TestUIPasteboard methodForSelector:@selector(_performAsDataOwner:block:)]
     433    };
     434
     435    auto managedConfigurationSwizzler = InstanceMethodSwizzler {
     436        PAL::getMCProfileConnectionClass(),
     437        @selector(isURLManaged:),
     438        [TestMCProfileConnection instanceMethodForSelector:@selector(isURLManaged:)]
     439    };
     440
     441    {
     442        auto source = setUpWebViewForPasteboardTests(@"simple");
     443        [source selectAll:nil];
     444        [source copy:nil];
     445        [source waitForNextPresentationUpdate];
     446        EXPECT_EQ(gLastKnownDataOwner, _UIDataOwnerEnterprise);
     447    }
     448    {
     449        auto destination = setUpWebViewForPasteboardTests(@"autofocus-contenteditable");
     450        [destination _setDataOwnerForPaste:_UIDataOwnerUser];
     451        [destination paste:nil];
     452        [destination waitForNextPresentationUpdate];
     453        EXPECT_EQ(gLastKnownDataOwner, _UIDataOwnerUser);
     454    }
     455}
     456
    414457#endif // HAVE(PASTEBOARD_DATA_OWNER)
    415458
Note: See TracChangeset for help on using the changeset viewer.