Title: [292888] trunk
Revision
292888
Author
[email protected]
Date
2022-04-14 13:58:47 -0700 (Thu, 14 Apr 2022)

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/PAL/ChangeLog (292887 => 292888)


--- trunk/Source/WebCore/PAL/ChangeLog	2022-04-14 20:35:15 UTC (rev 292887)
+++ trunk/Source/WebCore/PAL/ChangeLog	2022-04-14 20:58:47 UTC (rev 292888)
@@ -1,3 +1,15 @@
+2022-04-14  Wenson Hsieh  <[email protected]>
+
+        [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  <[email protected]>
 
         Revert r291846 because it caused a 3% performance regression

Modified: trunk/Source/WebCore/PAL/pal/spi/ios/ManagedConfigurationSPI.h (292887 => 292888)


--- trunk/Source/WebCore/PAL/pal/spi/ios/ManagedConfigurationSPI.h	2022-04-14 20:35:15 UTC (rev 292887)
+++ trunk/Source/WebCore/PAL/pal/spi/ios/ManagedConfigurationSPI.h	2022-04-14 20:58:47 UTC (rev 292888)
@@ -56,9 +56,12 @@
 @interface MCProfileConnection : NSObject
 @end
 
+@class NSURL;
+
 @interface MCProfileConnection ()
 + (MCProfileConnection *)sharedConnection;
 - (MCRestrictedBoolType)effectiveBoolValueForSetting:(NSString *)feature;
+- (BOOL)isURLManaged:(NSURL *)url;
 @end
 
 #endif

Modified: trunk/Source/WebKit/ChangeLog (292887 => 292888)


--- trunk/Source/WebKit/ChangeLog	2022-04-14 20:35:15 UTC (rev 292887)
+++ trunk/Source/WebKit/ChangeLog	2022-04-14 20:58:47 UTC (rev 292888)
@@ -1,3 +1,26 @@
+2022-04-14  Wenson Hsieh  <[email protected]>
+
+        [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  <[email protected]>
 
         [WebAuthn] Clean up WebAuthenticationModern and WebAuthnProcess

Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (292887 => 292888)


--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2022-04-14 20:35:15 UTC (rev 292887)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2022-04-14 20:58:47 UTC (rev 292888)
@@ -168,6 +168,13 @@
     UIPreviewItemTypeAttachment,
 };
 
+typedef NS_ENUM(NSInteger, _UIDataOwner) {
+    _UIDataOwnerUndefined,
+    _UIDataOwnerUser,
+    _UIDataOwnerEnterprise,
+    _UIDataOwnerShared,
+};
+
 @class UIPreviewItemController;
 
 @protocol UIPreviewItemDelegate <NSObject>
@@ -490,7 +497,10 @@
 - (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;
@@ -1372,15 +1382,6 @@
 
 #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;

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (292887 => 292888)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-04-14 20:35:15 UTC (rev 292887)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-04-14 20:58:47 UTC (rev 292888)
@@ -8202,18 +8202,23 @@
 
 - (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;
 }
 

Modified: trunk/Tools/ChangeLog (292887 => 292888)


--- trunk/Tools/ChangeLog	2022-04-14 20:35:15 UTC (rev 292887)
+++ trunk/Tools/ChangeLog	2022-04-14 20:58:47 UTC (rev 292888)
@@ -1,3 +1,20 @@
+2022-04-14  Wenson Hsieh  <[email protected]>
+
+        [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  <[email protected]>
 
         [WebAuthn] Clean up WebAuthenticationModern and WebAuthnProcess

Modified: trunk/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm (292887 => 292888)


--- trunk/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm	2022-04-14 20:35:15 UTC (rev 292887)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm	2022-04-14 20:58:47 UTC (rev 292888)
@@ -28,6 +28,7 @@
 #if PLATFORM(IOS_FAMILY)
 
 #import "ClassMethodSwizzler.h"
+#import "InstanceMethodSwizzler.h"
 #import "PlatformUtilities.h"
 #import "TestWKWebView.h"
 #import "UIKitSPI.h"
@@ -35,7 +36,7 @@
 #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 *);
 
@@ -67,6 +68,18 @@
 
 @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)
@@ -411,6 +424,36 @@
     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)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to