Skip to content

Commit

Permalink
[iOS] [WK2] Managed pasteboard should function for all managed domains
Browse files Browse the repository at this point in the history
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):

Canonical link: https://commits.webkit.org/249658@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@292888 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
whsieh committed Apr 14, 2022
1 parent 6d503b9 commit 21a843f
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 19 deletions.
12 changes: 12 additions & 0 deletions Source/WebCore/PAL/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
2022-04-14 Wenson Hsieh <wenson_hsieh@apple.com>

[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.

Add an SPI method on `MCProfileConnection`.

* pal/spi/ios/ManagedConfigurationSPI.h:

2022-04-13 Myles C. Maxfield <mmaxfield@apple.com>

Revert r291846 because it caused a 3% performance regression
Expand Down
3 changes: 3 additions & 0 deletions Source/WebCore/PAL/pal/spi/ios/ManagedConfigurationSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ typedef enum MCRestrictedBoolType {
@interface MCProfileConnection : NSObject
@end

@class NSURL;

@interface MCProfileConnection ()
+ (MCProfileConnection *)sharedConnection;
- (MCRestrictedBoolType)effectiveBoolValueForSetting:(NSString *)feature;
- (BOOL)isURLManaged:(NSURL *)url;
@end

#endif
Expand Down
23 changes: 23 additions & 0 deletions Source/WebKit/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
2022-04-14 Wenson Hsieh <wenson_hsieh@apple.com>

[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.

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:]):

2022-04-14 J Pascoe <j_pascoe@apple.com>

[WebAuthn] Clean up WebAuthenticationModern and WebAuthnProcess
Expand Down
21 changes: 11 additions & 10 deletions Source/WebKit/Platform/spi/ios/UIKitSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ typedef NS_ENUM(NSInteger, UIPreviewItemType) {
UIPreviewItemTypeAttachment,
};

typedef NS_ENUM(NSInteger, _UIDataOwner) {
_UIDataOwnerUndefined,
_UIDataOwnerUser,
_UIDataOwnerEnterprise,
_UIDataOwnerShared,
};

@class UIPreviewItemController;

@protocol UIPreviewItemDelegate <NSObject>
Expand Down Expand Up @@ -490,7 +497,10 @@ typedef enum {
- (void)_wheelChangedWithEvent:(UIEvent *)event;
- (void)_beginPinningInputViews;
- (void)_endPinningInputViews;

#if HAVE(PASTEBOARD_DATA_OWNER)
@property (nonatomic, setter=_setDataOwnerForCopy:) _UIDataOwner _dataOwnerForCopy;
@property (nonatomic, setter=_setDataOwnerForPaste:) _UIDataOwner _dataOwnerForPaste;
#endif
@end

@class FBSDisplayConfiguration;
Expand Down Expand Up @@ -1372,15 +1382,6 @@ typedef NS_ENUM(NSUInteger, _UIContextMenuLayout) {

#endif // USE(APPLE_INTERNAL_SDK)

#if HAVE(PASTEBOARD_DATA_OWNER)

@interface UIResponder (Staging_73852335)
@property (nonatomic, setter=_setDataOwnerForCopy:) _UIDataOwner _dataOwnerForCopy;
@property (nonatomic, setter=_setDataOwnerForPaste:) _UIDataOwner _dataOwnerForPaste;
@end

#endif

@interface UITextInteractionAssistant (IPI)
@property (nonatomic, readonly) BOOL inGesture;
@property (nonatomic, readonly) UITextInteraction *interactions;
Expand Down
21 changes: 13 additions & 8 deletions Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8202,18 +8202,23 @@ - (BOOL)shouldDeferGestureDueToImageAnalysis:(UIGestureRecognizer *)gesture

- (WebCore::DataOwnerType)_dataOwnerForPasteboard:(WebKit::PasteboardAccessIntent)intent
{
if (![self respondsToSelector:@selector(_dataOwnerForPaste)]) {
// FIXME: Remove this once the relevant bots have fix for <rdar://problem/73852335>.
auto specifiedType = [&] {
if (intent == WebKit::PasteboardAccessIntent::Read)
return coreDataOwnerType(self._dataOwnerForPaste);

if (intent == WebKit::PasteboardAccessIntent::Write)
return coreDataOwnerType(self._dataOwnerForCopy);

ASSERT_NOT_REACHED();
return WebCore::DataOwnerType::Undefined;
}
}();

if (intent == WebKit::PasteboardAccessIntent::Read)
return coreDataOwnerType(self._dataOwnerForPaste);
if (specifiedType != WebCore::DataOwnerType::Undefined)
return specifiedType;

if (intent == WebKit::PasteboardAccessIntent::Write)
return coreDataOwnerType(self._dataOwnerForCopy);
if ([[PAL::getMCProfileConnectionClass() sharedConnection] isURLManaged:[_webView URL]])
return WebCore::DataOwnerType::Enterprise;

ASSERT_NOT_REACHED();
return WebCore::DataOwnerType::Undefined;
}

Expand Down
17 changes: 17 additions & 0 deletions Tools/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
2022-04-14 Wenson Hsieh <wenson_hsieh@apple.com>

[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.

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):

2022-04-14 J Pascoe <j_pascoe@apple.com>

[WebAuthn] Clean up WebAuthenticationModern and WebAuthnProcess
Expand Down
45 changes: 44 additions & 1 deletion Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
#if PLATFORM(IOS_FAMILY)

#import "ClassMethodSwizzler.h"
#import "InstanceMethodSwizzler.h"
#import "PlatformUtilities.h"
#import "TestWKWebView.h"
#import "UIKitSPI.h"
#import <MobileCoreServices/MobileCoreServices.h>
#import <UIKit/UIPasteboard.h>
#import <WebKit/WKPreferencesPrivate.h>
#import <WebKit/WKWebViewPrivate.h>
#import <wtf/SoftLinking.h>
#import <pal/ios/ManagedConfigurationSoftLink.h>

typedef void (^DataLoadCompletionBlock)(NSData *, NSError *);

Expand Down Expand Up @@ -67,6 +68,18 @@ + (void)_performAsDataOwner:(_UIDataOwner)owner block:(dispatch_block_t)block

@end

@interface TestMCProfileConnection : NSObject
@end

@implementation TestMCProfileConnection

- (BOOL)isURLManaged:(NSURL *)url
{
return [url.lastPathComponent isEqualToString:@"simple.html"];
}

@end

#endif // HAVE(PASTEBOARD_DATA_OWNER)

#endif // PLATFORM(IOS)
Expand Down Expand Up @@ -411,6 +424,36 @@ + (void)_performAsDataOwner:(_UIDataOwner)owner block:(dispatch_block_t)block
EXPECT_WK_STREQ([webView contentsAsString], "Foo bar\n");
}

TEST(UIPasteboardTests, PerformAsDataOwnerWithManagedURL)
{
auto pasteboardSwizzler = ClassMethodSwizzler {
UIPasteboard.class,
@selector(_performAsDataOwner:block:),
[TestUIPasteboard methodForSelector:@selector(_performAsDataOwner:block:)]
};

auto managedConfigurationSwizzler = InstanceMethodSwizzler {
PAL::getMCProfileConnectionClass(),
@selector(isURLManaged:),
[TestMCProfileConnection instanceMethodForSelector:@selector(isURLManaged:)]
};

{
auto source = setUpWebViewForPasteboardTests(@"simple");
[source selectAll:nil];
[source copy:nil];
[source waitForNextPresentationUpdate];
EXPECT_EQ(gLastKnownDataOwner, _UIDataOwnerEnterprise);
}
{
auto destination = setUpWebViewForPasteboardTests(@"autofocus-contenteditable");
[destination _setDataOwnerForPaste:_UIDataOwnerUser];
[destination paste:nil];
[destination waitForNextPresentationUpdate];
EXPECT_EQ(gLastKnownDataOwner, _UIDataOwnerUser);
}
}

#endif // HAVE(PASTEBOARD_DATA_OWNER)

#endif // PLATFORM(IOS)
Expand Down

0 comments on commit 21a843f

Please sign in to comment.