Diff
Modified: branches/safari-608-branch/Source/WebKit/ChangeLog (250245 => 250246)
--- branches/safari-608-branch/Source/WebKit/ChangeLog 2019-09-23 18:23:24 UTC (rev 250245)
+++ branches/safari-608-branch/Source/WebKit/ChangeLog 2019-09-23 18:38:35 UTC (rev 250246)
@@ -1,3 +1,50 @@
+2019-09-23 Kocsen Chung <[email protected]>
+
+ Cherry-pick r250015. rdar://problem/55579794
+
+ Remove the "Show Link Previews" and "Hide Link Previews" action menus in the preview platter
+ https://bugs.webkit.org/show_bug.cgi?id=201864
+ <rdar://55190038>
+
+ Reviewed by Simon Fraser.
+
+ Source/WebKit:
+
+ * UIProcess/ios/WKActionSheetAssistant.mm: Remove the toggle action from the
+ default values.
+ (-[WKActionSheetAssistant defaultActionsForLinkSheet:]):
+ * UIProcess/ios/WKContentViewInteraction.mm: No longer try to add a toggle when
+ it isn't there.
+ (-[WKContentView assignLegacyDataForContextMenuInteraction]):
+ (menuWithShowLinkPreviewAction): Deleted.
+
+ Tools:
+
+ Test for the suggested actions.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm:
+ (-[TestContextMenuSuggestedActionsUIDelegate webView:contextMenuConfigurationForElement:completionHandler:]):
+ (-[TestContextMenuSuggestedActionsUIDelegate webView:contextMenuWillPresentForElement:]):
+ (TEST):
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250015 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-09-17 Dean Jackson <[email protected]>
+
+ Remove the "Show Link Previews" and "Hide Link Previews" action menus in the preview platter
+ https://bugs.webkit.org/show_bug.cgi?id=201864
+ <rdar://55190038>
+
+ Reviewed by Simon Fraser.
+
+ * UIProcess/ios/WKActionSheetAssistant.mm: Remove the toggle action from the
+ default values.
+ (-[WKActionSheetAssistant defaultActionsForLinkSheet:]):
+ * UIProcess/ios/WKContentViewInteraction.mm: No longer try to add a toggle when
+ it isn't there.
+ (-[WKContentView assignLegacyDataForContextMenuInteraction]):
+ (menuWithShowLinkPreviewAction): Deleted.
+
2019-09-17 Alan Coon <[email protected]>
Cherry-pick r249936. rdar://problem/55461414
Modified: branches/safari-608-branch/Source/WebKit/UIProcess/API/Cocoa/_WKElementAction.mm (250245 => 250246)
--- branches/safari-608-branch/Source/WebKit/UIProcess/API/Cocoa/_WKElementAction.mm 2019-09-23 18:23:24 UTC (rev 250245)
+++ branches/safari-608-branch/Source/WebKit/UIProcess/API/Cocoa/_WKElementAction.mm 2019-09-23 18:38:35 UTC (rev 250246)
@@ -121,8 +121,8 @@
+ (instancetype)_elementActionWithType:(_WKElementActionType)type customTitle:(NSString *)customTitle assistant:(WKActionSheetAssistant *)assistant
{
- NSString *title;
- WKElementActionHandlerInternal handler;
+ NSString *title = @"";
+ WKElementActionHandlerInternal handler = nil;
switch (type) {
case _WKElementActionTypeCopy:
title = WEB_UI_STRING_KEY("Copy", "Copy (ActionSheet)", "Title for Copy Link or Image action button");
@@ -164,17 +164,9 @@
[assistant.delegate actionSheetAssistant:assistant shareElementWithURL:actionInfo.URL ?: actionInfo.imageURL rect:actionInfo.boundingRect];
};
break;
- case _WKElementActionToggleShowLinkPreviews: {
- bool showingLinkPreviews = true;
- if (NSNumber *value = [[NSUserDefaults standardUserDefaults] objectForKey:webkitShowLinkPreviewsPreferenceKey])
- showingLinkPreviews = value.boolValue;
-
- title = showingLinkPreviews ? WEB_UI_STRING("Hide Link Previews", "Title for Hide Link Previews action button") : WEB_UI_STRING("Show Link Previews", "Title for Show Link Previews action button");
- handler = ^(WKActionSheetAssistant *, _WKActivatedElementInfo *) {
- [[NSUserDefaults standardUserDefaults] setBool:!showingLinkPreviews forKey:webkitShowLinkPreviewsPreferenceKey];
- };
+ case _WKElementActionToggleShowLinkPreviews:
+ // This action must still exist for compatibility, but doesn't do anything.
break;
- }
default:
[NSException raise:NSInvalidArgumentException format:@"There is no standard web element action of type %ld.", (long)type];
return nil;
Modified: branches/safari-608-branch/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm (250245 => 250246)
--- branches/safari-608-branch/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm 2019-09-23 18:23:24 UTC (rev 250245)
+++ branches/safari-608-branch/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm 2019-09-23 18:38:35 UTC (rev 250246)
@@ -558,8 +558,6 @@
[defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeShare assistant:self]];
}
- [defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionToggleShowLinkPreviews assistant:self]];
-
return defaultActions;
}
Modified: branches/safari-608-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (250245 => 250246)
--- branches/safari-608-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2019-09-23 18:23:24 UTC (rev 250245)
+++ branches/safari-608-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2019-09-23 18:38:35 UTC (rev 250246)
@@ -7841,32 +7841,6 @@
return [UIMenu menuWithTitle:title children:actions];
}
-static UIMenu *menuWithShowLinkPreviewAction(UIMenu *originalMenu)
-{
- if (!originalMenu)
- return nil;
-
- // Look for a UIAction that has the WKElementActionTypeToggleShowLinkPreviewsIdentifier.
- NSUInteger result = [originalMenu.children indexOfObjectPassingTest:^BOOL(UIMenuElement *element, NSUInteger index, BOOL *stop) {
- if (![element isKindOfClass:[UIAction class]])
- return NO;
- if ([(UIAction *)element identifier] == WKElementActionTypeToggleShowLinkPreviewsIdentifier) {
- *stop = YES;
- return YES;
- }
- return NO;
- }];
- if (result != NSNotFound)
- return originalMenu;
-
- // We didn't find one, so make a new UIMenu with the toggle action.
- NSMutableArray<UIMenuElement *> *menuElements = [NSMutableArray arrayWithCapacity:(originalMenu.children.count + 1)];
- [menuElements addObjectsFromArray:originalMenu.children];
- _WKElementAction *toggleAction = [_WKElementAction elementActionWithType:_WKElementActionToggleShowLinkPreviews];
- [menuElements addObject:[toggleAction uiActionForElementInfo:nil]];
- return [originalMenu menuByReplacingChildren:menuElements];
-}
-
- (void)assignLegacyDataForContextMenuInteraction
{
ASSERT(!_contextMenuHasRequestedLegacyData);
@@ -7919,7 +7893,7 @@
_contextMenuLegacyPreviewController = dataDetectorsResult.get().previewProvider();
if (dataDetectorsResult && dataDetectorsResult.get().actionProvider) {
auto menuElements = menuElementsFromDefaultActions(defaultActionsFromAssistant, elementInfo);
- _contextMenuLegacyMenu = menuWithShowLinkPreviewAction(dataDetectorsResult.get().actionProvider(menuElements));
+ _contextMenuLegacyMenu = dataDetectorsResult.get().actionProvider(menuElements);
}
END_BLOCK_OBJC_EXCEPTIONS;
}
Modified: branches/safari-608-branch/Tools/ChangeLog (250245 => 250246)
--- branches/safari-608-branch/Tools/ChangeLog 2019-09-23 18:23:24 UTC (rev 250245)
+++ branches/safari-608-branch/Tools/ChangeLog 2019-09-23 18:38:35 UTC (rev 250246)
@@ -1,3 +1,49 @@
+2019-09-23 Kocsen Chung <[email protected]>
+
+ Cherry-pick r250015. rdar://problem/55579794
+
+ Remove the "Show Link Previews" and "Hide Link Previews" action menus in the preview platter
+ https://bugs.webkit.org/show_bug.cgi?id=201864
+ <rdar://55190038>
+
+ Reviewed by Simon Fraser.
+
+ Source/WebKit:
+
+ * UIProcess/ios/WKActionSheetAssistant.mm: Remove the toggle action from the
+ default values.
+ (-[WKActionSheetAssistant defaultActionsForLinkSheet:]):
+ * UIProcess/ios/WKContentViewInteraction.mm: No longer try to add a toggle when
+ it isn't there.
+ (-[WKContentView assignLegacyDataForContextMenuInteraction]):
+ (menuWithShowLinkPreviewAction): Deleted.
+
+ Tools:
+
+ Test for the suggested actions.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm:
+ (-[TestContextMenuSuggestedActionsUIDelegate webView:contextMenuConfigurationForElement:completionHandler:]):
+ (-[TestContextMenuSuggestedActionsUIDelegate webView:contextMenuWillPresentForElement:]):
+ (TEST):
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250015 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-09-17 Dean Jackson <[email protected]>
+
+ Remove the "Show Link Previews" and "Hide Link Previews" action menus in the preview platter
+ https://bugs.webkit.org/show_bug.cgi?id=201864
+ <rdar://55190038>
+
+ Reviewed by Simon Fraser.
+
+ Test for the suggested actions.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm:
+ (-[TestContextMenuSuggestedActionsUIDelegate webView:contextMenuConfigurationForElement:completionHandler:]):
+ (-[TestContextMenuSuggestedActionsUIDelegate webView:contextMenuWillPresentForElement:]):
+ (TEST):
+
2019-09-17 Kocsen Chung <[email protected]>
Cherry-pick r249701. rdar://problem/55291696
Modified: branches/safari-608-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm (250245 => 250246)
--- branches/safari-608-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm 2019-09-23 18:23:24 UTC (rev 250245)
+++ branches/safari-608-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm 2019-09-23 18:38:35 UTC (rev 250246)
@@ -51,7 +51,7 @@
contextMenuRequested = true;
UIContextMenuContentPreviewProvider previewProvider = ^UIViewController * ()
{
- return [UIViewController new];
+ return [[[UIViewController alloc] init] autorelease];
};
UIContextMenuActionProvider actionProvider = ^UIMenu *(NSArray<UIMenuElement *> *suggestedActions)
{
@@ -121,4 +121,177 @@
EXPECT_FALSE(willCommitCalled);
EXPECT_TRUE(didEndCalled);
}
+
+@interface TestContextMenuImageUIDelegate : NSObject <WKUIDelegate>
+@end
+
+@implementation TestContextMenuImageUIDelegate
+
+- (void)_webView:(WKWebView *)webView contextMenuConfigurationForElement:(WKContextMenuElementInfo *)elementInfo completionHandler:(void(^)(UIContextMenuConfiguration * _Nullable))completionHandler
+{
+ contextMenuRequested = true;
+ completionHandler(nil);
+}
+
+- (NSURL *)_webView:(WKWebView *)webView alternateURLFromImage:(UIImage *)image userInfo:(NSDictionary **)userInfo
+{
+ alternateURLRequested = true;
+ return linkURL.get();
+}
+
+- (void)webView:(WKWebView *)webView contextMenuWillPresentForElement:(WKContextMenuElementInfo *)elementInfo
+{
+ willPresentCalled = true;
+ EXPECT_TRUE([elementInfo.linkURL.absoluteString isEqualToString:[linkURL absoluteString]]);
+}
+
+- (void)webView:(WKWebView *)webView contextMenuForElement:(WKContextMenuElementInfo *)elementInfo willCommitWithAnimator:(id<UIContextMenuInteractionCommitAnimating>)animator
+{
+ willCommitCalled = true;
+}
+
+- (void)webView:(WKWebView *)webView contextMenuDidEndForElement:(WKContextMenuElementInfo *)elementInfo
+{
+ didEndCalled = true;
+}
+
+@end
+
+TEST(WebKit, ContextMenuImage)
+{
+ linkURL = [NSURL URLWithString:@"http://127.0.0.1/image"];
+ auto driver = contextMenuWebViewDriver([TestContextMenuImageUIDelegate class], @"<img style='width:400px;height:400px' src=''>");
+ [driver begin:^(BOOL result) {
+ EXPECT_TRUE(result);
+ [driver clickDown];
+ [driver clickUp];
+ }];
+ TestWebKitAPI::Util::run(&willPresentCalled);
+ EXPECT_TRUE(contextMenuRequested);
+ EXPECT_TRUE(alternateURLRequested);
+ EXPECT_TRUE(willPresentCalled);
+ EXPECT_FALSE(willCommitCalled);
+ EXPECT_FALSE(didEndCalled);
+}
+
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#pragma clang diagnostic ignored "-Wdeprecated-implementations"
+
+@interface LegacyPreviewViewController : UIViewController
+@end
+
+@implementation LegacyPreviewViewController
+
+- (NSArray<UIPreviewAction *> *)previewActionItems
+{
+ previewActionItemsCalled = true;
+ return @[
+ [UIPreviewAction actionWithTitle:@"Action" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *, UIViewController *) { }]
+ ];
+}
+
+@end
+
+@interface LegacyContextMenuUIDelegate : NSObject <WKUIDelegate>
+@end
+
+@implementation LegacyContextMenuUIDelegate
+
+- (BOOL)webView:(WKWebView *)webView shouldPreviewElement:(WKPreviewElementInfo *)elementInfo
+{
+ EXPECT_TRUE([elementInfo.linkURL.absoluteString isEqualToString:[linkURL absoluteString]]);
+ contextMenuRequested = true;
+ return YES;
+}
+
+- (UIViewController *)webView:(WKWebView *)webView previewingViewControllerForElement:(WKPreviewElementInfo *)elementInfo defaultActions:(NSArray<id <WKPreviewActionItem>> *)previewActions
+{
+ EXPECT_TRUE(previewActions.count);
+ previewingViewControllerCalled = true;
+ return [LegacyPreviewViewController new];
+}
+
+/* Even though this is non-legacy API, it should not be enough to trigger the non-legacy flow. */
+- (void)webView:(WKWebView *)webView contextMenuWillPresentForElement:(WKContextMenuElementInfo *)elementInfo
+{
+ willPresentCalled = true;
+}
+
+/* Even though this is non-legacy API, it should not be enough to trigger the non-legacy flow. */
+- (void)_webView:(WKWebView *)webView contextMenuDidEndForElement:(WKContextMenuElementInfo *)elementInfo
+{
+}
+
+@end
+
+TEST(WebKit, ContextMenuLegacy)
+{
+ auto driver = contextMenuWebViewDriver([LegacyContextMenuUIDelegate class]);
+ [driver begin:^(BOOL result) {
+ EXPECT_TRUE(result);
+ [driver clickDown];
+ [driver clickUp];
+ }];
+ TestWebKitAPI::Util::run(&previewActionItemsCalled);
+ EXPECT_TRUE(contextMenuRequested);
+ EXPECT_TRUE(previewingViewControllerCalled);
+ EXPECT_TRUE(willPresentCalled);
+}
+
+#pragma clang diagnostic pop
+
+@interface TestContextMenuSuggestedActionsUIDelegate : NSObject <WKUIDelegate>
+@end
+
+@implementation TestContextMenuSuggestedActionsUIDelegate
+
+- (void)webView:(WKWebView *)webView contextMenuConfigurationForElement:(WKContextMenuElementInfo *)elementInfo completionHandler:(void(^)(UIContextMenuConfiguration * _Nullable))completionHandler
+{
+ EXPECT_TRUE([elementInfo.linkURL.absoluteString isEqualToString:[linkURL absoluteString]]);
+ contextMenuRequested = true;
+ UIContextMenuContentPreviewProvider previewProvider = ^UIViewController * ()
+ {
+ return [[[UIViewController alloc] init] autorelease];
+ };
+ UIContextMenuActionProvider actionProvider = ^UIMenu *(NSArray<UIMenuElement *> *suggestedActions)
+ {
+ NSArray<NSString *> *expectedIdentifiers = @[
+ @"WKElementActionTypeOpen",
+ @"WKElementActionTypeAddToReadingList",
+ @"WKElementActionTypeCopy",
+ @"WKElementActionTypeShare"
+ ];
+ EXPECT_TRUE(expectedIdentifiers.count == suggestedActions.count);
+
+ [suggestedActions enumerateObjectsUsingBlock:^(UIMenuElement *menuElement, NSUInteger index, BOOL *) {
+ EXPECT_TRUE([menuElement isKindOfClass:[UIAction class]]);
+ EXPECT_TRUE([[(UIAction *)menuElement identifier] isEqualToString:expectedIdentifiers[index]]);
+ }];
+ return [UIMenu menuWithTitle:@"" children:suggestedActions];
+ };
+ completionHandler([UIContextMenuConfiguration configurationWithIdentifier:nil previewProvider:previewProvider actionProvider:actionProvider]);
+}
+
+- (void)webView:(WKWebView *)webView contextMenuWillPresentForElement:(WKContextMenuElementInfo *)elementInfo
+{
+ willPresentCalled = true;
+}
+
+@end
+
+TEST(WebKit, ContextMenuSuggestedActions)
+{
+ auto driver = contextMenuWebViewDriver([TestContextMenuSuggestedActionsUIDelegate class]);
+ [driver begin:^(BOOL result) {
+ EXPECT_TRUE(result);
+ [driver clickDown];
+ [driver clickUp];
+ }];
+ TestWebKitAPI::Util::run(&willPresentCalled);
+ EXPECT_TRUE(contextMenuRequested);
+ EXPECT_TRUE(willPresentCalled);
+}
+
#endif // PLATFORM(IOS) && USE(UICONTEXTMENU)