Skip to content
Permalink
Browse files
Implement async paste method on UIWKInteractionViewProtocol
https://bugs.webkit.org/show_bug.cgi?id=196267
<rdar://problem/49236346>

Reviewed by Tim Horton.

Source/WebKit:

Implement a new UIWKInteractionViewProtocol hook to perform a paste command, and invoke the given completion
handler when pasting is finished.

Test: UIPasteboardTests.PasteWithCompletionHandler

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView pasteWithCompletionHandler:]):

Tools:

Add a new test to exercise the new SPI. Additionally, add staging forward declarations for
-pasteWithCompletionHandler:, and remove some old existing staging declarations for other bits of UIKit SPI that
are now a part of all iOS 12 internal SDKs.

* TestWebKitAPI/Tests/ios/UIPasteboardTests.mm:

While we're here, also change a few iOS 11.3 checks to just be about PLATFORM(IOS) (since we don't build for iOS
prior to 12, these version checks are effectively only about iOS vs. tvOS or watchOS).

* TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm:
* TestWebKitAPI/ios/DragAndDropSimulatorIOS.mm:
(-[DragAndDropSimulator _sendQueuedAdditionalItemRequest]):
* TestWebKitAPI/ios/UIKitSPI.h:


Canonical link: https://commits.webkit.org/210574@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243519 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
whsieh committed Mar 26, 2019
1 parent 77f74ce commit b7e668b05cd8716e6318321383d91ba297af37ae
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 18 deletions.
@@ -1,3 +1,19 @@
2019-03-26 Wenson Hsieh <wenson_hsieh@apple.com>

Implement async paste method on UIWKInteractionViewProtocol
https://bugs.webkit.org/show_bug.cgi?id=196267
<rdar://problem/49236346>

Reviewed by Tim Horton.

Implement a new UIWKInteractionViewProtocol hook to perform a paste command, and invoke the given completion
handler when pasting is finished.

Test: UIPasteboardTests.PasteWithCompletionHandler

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView pasteWithCompletionHandler:]):

2019-03-26 Per Arne Vollan <pvollan@apple.com>

[macOS] Fix sandbox violations
@@ -2382,6 +2382,14 @@ - (void)setUpTextSelectionAssistant
}
}

- (void)pasteWithCompletionHandler:(void (^)(void))completionHandler
{
_page->executeEditCommand("Paste"_s, { }, [completion = makeBlockPtr(completionHandler)] (auto) {
if (completion)
completion();
});
}

- (void)clearSelection
{
[self _elementDidBlur];
@@ -1,3 +1,25 @@
2019-03-26 Wenson Hsieh <wenson_hsieh@apple.com>

Implement async paste method on UIWKInteractionViewProtocol
https://bugs.webkit.org/show_bug.cgi?id=196267
<rdar://problem/49236346>

Reviewed by Tim Horton.

Add a new test to exercise the new SPI. Additionally, add staging forward declarations for
-pasteWithCompletionHandler:, and remove some old existing staging declarations for other bits of UIKit SPI that
are now a part of all iOS 12 internal SDKs.

* TestWebKitAPI/Tests/ios/UIPasteboardTests.mm:

While we're here, also change a few iOS 11.3 checks to just be about PLATFORM(IOS) (since we don't build for iOS
prior to 12, these version checks are effectively only about iOS vs. tvOS or watchOS).

* TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm:
* TestWebKitAPI/ios/DragAndDropSimulatorIOS.mm:
(-[DragAndDropSimulator _sendQueuedAdditionalItemRequest]):
* TestWebKitAPI/ios/UIKitSPI.h:

2019-03-26 Aakash Jain <aakash_jain@apple.com>

[ews-build] Use PostgreSQL for ews.webkit.org database
@@ -38,7 +38,7 @@

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

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300
#if PLATFORM(IOS)

static void checkJSONWithLogging(NSString *jsonString, NSDictionary *expected)
{
@@ -48,7 +48,7 @@ static void checkJSONWithLogging(NSString *jsonString, NSDictionary *expected)
NSLog(@"Expected JSON: %@ to match values: %@", jsonString, expected);
}

#endif // __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300
#endif // PLATFORM(IOS)

namespace TestWebKitAPI {

@@ -145,7 +145,26 @@ static void checkJSONWithLogging(NSString *jsonString, NSDictionary *expected)
EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!!rich.querySelector('a')"].boolValue);
}

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300
TEST(UIPasteboardTests, PasteWithCompletionHandler)
{
auto webView = setUpWebViewForPasteboardTests(@"DataTransfer");
[UIPasteboard generalPasteboard].URL = [NSURL URLWithString:@"https://www.apple.com/"];

bool done = false;
[(id <UIWKInteractionViewProtocol_Staging_49236384>)[webView textInputContentView] pasteWithCompletionHandler:[webView, &done] {
[UIPasteboard generalPasteboard].items = @[ ];
done = true;
}];

Util::run(&done);

EXPECT_WK_STREQ("text/uri-list, text/plain", [webView stringByEvaluatingJavaScript:@"types.textContent"]);
EXPECT_WK_STREQ("(STRING, text/uri-list), (STRING, text/plain)", [webView stringByEvaluatingJavaScript:@"items.textContent"]);
EXPECT_WK_STREQ("https://www.apple.com/", [webView stringByEvaluatingJavaScript:@"urlData.textContent"]);
EXPECT_WK_STREQ("https://www.apple.com/", [webView stringByEvaluatingJavaScript:@"textData.textContent"]);
}

#if PLATFORM(IOS)

TEST(UIPasteboardTests, DataTransferGetDataWhenPastingURL)
{
@@ -283,7 +302,7 @@ static void checkJSONWithLogging(NSString *jsonString, NSDictionary *expected)
EXPECT_WK_STREQ("https://www.apple.com/", [webView stringByEvaluatingJavaScript:@"textData.textContent"]);
}

#endif // __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300
#endif // PLATFORM(IOS)

} // namespace TestWebKitAPI

@@ -35,7 +35,7 @@
#import <WebKit/WKWebViewPrivate.h>
#import <wtf/BlockPtr.h>

typedef UIView <UITextInputTraits_Private_Proposed_SPI_34583628> AutofillInputView;
typedef UIView <UITextInputPrivate> AutofillInputView;

@interface AutofillTestView : TestWKWebView
@end
@@ -504,7 +504,7 @@ - (BOOL)_sendQueuedAdditionalItemRequest
[_queuedAdditionalItemRequestLocations removeObjectAtIndex:0];

auto requestLocation = [[_webView window] convertPoint:[requestLocationValue CGPointValue] toView:_webView.get()];
[(id <UIDragInteractionDelegate_Proposed_SPI_33146803>)[_webView dragInteractionDelegate] _dragInteraction:[_webView dragInteraction] itemsForAddingToSession:_dragSession.get() withTouchAtPoint:requestLocation completion:[dragSession = _dragSession, dropSession = _dropSession] (NSArray *items) {
[(id <UIDragInteractionDelegate_ForWebKitOnly>)[_webView dragInteractionDelegate] _dragInteraction:[_webView dragInteraction] itemsForAddingToSession:_dragSession.get() withTouchAtPoint:requestLocation completion:[dragSession = _dragSession, dropSession = _dropSession] (NSArray *items) {
[dragSession addItems:items];
[dropSession addItems:items];
}];
@@ -39,13 +39,13 @@
#import <UIKit/UIViewController_Private.h>
#import <UIKit/UIWKTextInteractionAssistant.h>

#if ENABLE(DRAG_SUPPORT)
#if PLATFORM(IOS)
@protocol UIDragSession;
@class UIDragInteraction;
@class UIDragItem;
#import <UIKit/NSItemProvider+UIKitAdditions_Private.h>
#import <UIKit/UIDragInteraction_Private.h>
#endif // ENABLE(DRAG_SUPPORT)
#endif // PLATFORM(IOS)

#else

@@ -65,6 +65,7 @@ WTF_EXTERN_C_END
@protocol UIDragInteractionDelegate_ForWebKitOnly <UIDragInteractionDelegate>
@optional
- (void)_dragInteraction:(UIDragInteraction *)interaction prepareForSession:(id<UIDragSession>)session completion:(void(^)(void))completion;
- (void)_dragInteraction:(UIDragInteraction *)interaction itemsForAddingToSession:(id <UIDragSession>)session withTouchAtPoint:(CGPoint)point completion:(void(^)(NSArray<UIDragItem *> *))completion;
@end

@protocol UITextInputTraits_Private <NSObject, UITextInputTraits>
@@ -79,6 +80,7 @@ WTF_EXTERN_C_END
- (void)insertTextSuggestion:(UITextSuggestion *)textSuggestion;
- (void)handleKeyWebEvent:(WebEvent *)theEvent withCompletionHandler:(void (^)(WebEvent *, BOOL))completionHandler;
- (BOOL)_shouldSuppressSelectionCommands;
- (NSDictionary *)_autofillContext;
@end

@protocol UITextInputMultiDocument <NSObject>
@@ -133,16 +135,6 @@ typedef NS_OPTIONS(NSInteger, UIWKDocumentRequestFlags) {

#endif

@protocol UITextInputTraits_Private_Proposed_SPI_34583628 <UITextInputPrivate>
- (NSDictionary *)_autofillContext;
@end

#if ENABLE(DRAG_SUPPORT)
@protocol UIDragInteractionDelegate_Proposed_SPI_33146803 <UIDragInteractionDelegate>
- (void)_dragInteraction:(UIDragInteraction *)interaction itemsForAddingToSession:(id <UIDragSession>)session withTouchAtPoint:(CGPoint)point completion:(void(^)(NSArray<UIDragItem *> *))completion;
@end
#endif

#if __has_include(<UIKit/UITextAutofillSuggestion.h>)
// FIXME: Move this import under USE(APPLE_INTERNAL_SDK) once <rdar://problem/34583628> lands in the SDK.
#import <UIKit/UITextAutofillSuggestion.h>
@@ -174,4 +166,8 @@ typedef NS_OPTIONS(NSInteger, UIWKDocumentRequestFlags) {
+ (BOOL)isInHardwareKeyboardMode;
@end

@protocol UIWKInteractionViewProtocol_Staging_49236384
- (void)pasteWithCompletionHandler:(void (^)(void))completionHandler;
@end

#endif // PLATFORM(IOS_FAMILY)

0 comments on commit b7e668b

Please sign in to comment.