Changeset 252309 in webkit
- Timestamp:
- Nov 9, 2019 12:14:37 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r252303 r252309 1 2019-11-09 Dean Jackson <dino@apple.com> 2 3 Clicky Orbing support.apple.com categories shows a PNG instead of the web page preview, tapping loads image asset only instead of web page 4 https://bugs.webkit.org/show_bug.cgi?id=204037 5 <rdar://55614939> 6 7 Reviewed by Simon Fraser. 8 9 When Safari adopted the ContextMenu API they began providing a PreviewViewController that 10 showed the image rather than the link, for the case of <a><img></a>. 11 12 This could be fixed in Safari, but I noticed that we actually tell the delegate that the 13 type of the activated element is an image, which is why they treat it as such. It's not 14 clear that because the image also has a link attached, a client should defer to the link. 15 16 Instead, I think it makes more sense to identify this as a link, because that is the more 17 important information in this API. 18 19 While here I also changed the logic to make sure we call the API if both the API and SPI 20 are available. 21 22 New ContextMenus and WKRequestActivatedElementInfo API tests. 23 24 * UIProcess/API/Cocoa/_WKActivatedElementInfo.mm: Identify as a link if you have a link. 25 (-[_WKActivatedElementInfo _initWithInteractionInformationAtPosition:userInfo:]): 26 * UIProcess/ios/WKContentViewInteraction.mm: Look for the API before the SPI. 27 (-[WKContentView continueContextMenuInteraction:]): 28 1 29 2019-11-08 Brady Eidson <beidson@apple.com> 2 30 -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm
r249171 r252309 74 74 if (information.isAttachment) 75 75 _type = _WKActivatedElementTypeAttachment; 76 else if (information.isLink) 77 _type = _WKActivatedElementTypeLink; 76 78 else if (information.isImage) 77 79 _type = _WKActivatedElementTypeImage; 78 else if (information.isLink)79 _type = _WKActivatedElementTypeLink;80 80 else 81 81 _type = _WKActivatedElementTypeUnspecified; -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
r251847 r252309 8383 8383 _contextMenuActionProviderDelegateNeedsOverride = NO; 8384 8384 _contextMenuElementInfo = wrapper(API::ContextMenuElementInfo::create(_positionInformation, nil)); 8385 if ([uiDelegate respondsToSelector:@selector(_webView:contextMenuConfigurationForElement:completionHandler:)]) { 8386 if (_positionInformation.isImage && _positionInformation.url.isNull() && [uiDelegate respondsToSelector:@selector(_webView:alternateURLFromImage:userInfo:)]) { 8387 UIImage *uiImage = [[_contextMenuElementInfo _activatedElementInfo] image]; 8388 NSDictionary *userInfo = nil; 8389 NSURL *nsURL = [uiDelegate _webView:_webView alternateURLFromImage:uiImage userInfo:&userInfo]; 8390 _positionInformation.url = nsURL; 8391 _contextMenuElementInfo = wrapper(API::ContextMenuElementInfo::create(_positionInformation, userInfo)); 8392 } 8393 8394 auto checker = WebKit::CompletionHandlerCallChecker::create(uiDelegate, @selector(_webView:contextMenuConfigurationForElement:completionHandler:)); 8395 [uiDelegate _webView:_webView contextMenuConfigurationForElement:_contextMenuElementInfo.get() completionHandler:makeBlockPtr([completionBlock = WTFMove(completionBlock), checker = WTFMove(checker)] (UIContextMenuConfiguration *configuration) { 8385 8386 if (_positionInformation.isImage && _positionInformation.url.isNull() && [uiDelegate respondsToSelector:@selector(_webView:alternateURLFromImage:userInfo:)]) { 8387 UIImage *uiImage = [[_contextMenuElementInfo _activatedElementInfo] image]; 8388 NSDictionary *userInfo = nil; 8389 NSURL *nsURL = [uiDelegate _webView:_webView alternateURLFromImage:uiImage userInfo:&userInfo]; 8390 _positionInformation.url = nsURL; 8391 _contextMenuElementInfo = wrapper(API::ContextMenuElementInfo::create(_positionInformation, userInfo)); 8392 } 8393 8394 if (_positionInformation.isLink && [uiDelegate respondsToSelector:@selector(webView:contextMenuConfigurationForElement:completionHandler:)]) { 8395 auto checker = WebKit::CompletionHandlerCallChecker::create(uiDelegate, @selector(webView:contextMenuConfigurationForElement:completionHandler:)); 8396 [uiDelegate webView:_webView contextMenuConfigurationForElement:_contextMenuElementInfo.get() completionHandler:makeBlockPtr([completionBlock = WTFMove(completionBlock), checker = WTFMove(checker)] (UIContextMenuConfiguration *configuration) { 8396 8397 if (checker->completionHandlerHasBeenCalled()) 8397 8398 return; … … 8399 8400 completionBlock(configuration); 8400 8401 }).get()]; 8401 } else if ( _positionInformation.isLink && [uiDelegate respondsToSelector:@selector(webView:contextMenuConfigurationForElement:completionHandler:)]) {8402 auto checker = WebKit::CompletionHandlerCallChecker::create(uiDelegate, @selector( webView:contextMenuConfigurationForElement:completionHandler:));8403 [uiDelegate webView:_webView contextMenuConfigurationForElement:_contextMenuElementInfo.get() completionHandler:makeBlockPtr([completionBlock = WTFMove(completionBlock), checker = WTFMove(checker)] (UIContextMenuConfiguration *configuration) {8402 } else if ([uiDelegate respondsToSelector:@selector(_webView:contextMenuConfigurationForElement:completionHandler:)]) { 8403 auto checker = WebKit::CompletionHandlerCallChecker::create(uiDelegate, @selector(_webView:contextMenuConfigurationForElement:completionHandler:)); 8404 [uiDelegate _webView:_webView contextMenuConfigurationForElement:_contextMenuElementInfo.get() completionHandler:makeBlockPtr([completionBlock = WTFMove(completionBlock), checker = WTFMove(checker)] (UIContextMenuConfiguration *configuration) { 8404 8405 if (checker->completionHandlerHasBeenCalled()) 8405 8406 return; -
trunk/Tools/ChangeLog
r252303 r252309 1 2019-11-09 Dean Jackson <dino@apple.com> 2 3 Clicky Orbing support.apple.com categories shows a PNG instead of the web page preview, tapping loads image asset only instead of web page 4 https://bugs.webkit.org/show_bug.cgi?id=204037 5 <rdar://55614939> 6 7 Reviewed by Simon Fraser. 8 9 New tests for a link wrapping an image, and the ordering of API and SPI. 10 11 Rename these tests so that they are much easier to filter on the command line. 12 13 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 14 * TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm: 15 (TEST): 16 (-[TestContextMenuAPIBeforeSPIUIDelegate webView:contextMenuConfigurationForElement:completionHandler:]): 17 (-[TestContextMenuAPIBeforeSPIUIDelegate _webView:contextMenuConfigurationForElement:completionHandler:]): 18 (-[TestContextMenuAPIBeforeSPIUIDelegate webView:contextMenuWillPresentForElement:]): 19 * TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm: 20 (TestWebKitAPI::TEST): 21 * TestWebKitAPI/Tests/WebKitCocoa/image.html: Added. 22 * TestWebKitAPI/Tests/WebKitCocoa/link-with-image.html: Added. 23 1 24 2019-11-08 Brady Eidson <beidson@apple.com> 2 25 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r252303 r252309 178 178 2EFF06CD1D8A429A0004BB30 /* input-field-in-scrollable-document.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06CC1D8A42910004BB30 /* input-field-in-scrollable-document.html */; }; 179 179 2EFF06D71D8AF34A0004BB30 /* WKWebViewCandidateTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2EFF06D61D8AF34A0004BB30 /* WKWebViewCandidateTests.mm */; }; 180 3128A81323763FAC00D90D40 /* link-with-image.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 3128A81223763F0B00D90D40 /* link-with-image.html */; }; 181 3128A8152376413300D90D40 /* image.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 3128A814237640FD00D90D40 /* image.html */; }; 180 182 313C3A0221E567C300DBA86E /* SystemPreviewBlobNaming.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 313C3A0121E5677A00DBA86E /* SystemPreviewBlobNaming.html */; }; 181 183 315118101DB1AE4000176304 /* ExtendedColor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3151180F1DB1ADD500176304 /* ExtendedColor.cpp */; }; … … 1287 1289 F4DEF6ED1E9B4DB60048EF61 /* image-in-link-and-input.html in Copy Resources */, 1288 1290 F45B63FB1F197F4A009D38B9 /* image-map.html in Copy Resources */, 1291 3128A8152376413300D90D40 /* image.html in Copy Resources */, 1289 1292 7283A9D022FA754900B21C7D /* img-with-rotated-image.html in Copy Resources */, 1290 1293 935786CD20F6A2910000CDFC /* IndexedDB.sqlite3 in Copy Resources */, … … 1345 1348 8361F1781E610B4E00759B25 /* link-with-download-attribute-with-slashes.html in Copy Resources */, 1346 1349 8349D3C41DB9728E004A9F65 /* link-with-download-attribute.html in Copy Resources */, 1350 3128A81323763FAC00D90D40 /* link-with-image.html in Copy Resources */, 1347 1351 378E64791632707400B6C676 /* link-with-title.html in Copy Resources */, 1348 1352 573255A622139BC700396AE8 /* load-web-archive-1.html in Copy Resources */, … … 1678 1682 2EFF06D31D8AEDBB0004BB30 /* TestWKWebView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TestWKWebView.mm; path = cocoa/TestWKWebView.mm; sourceTree = "<group>"; }; 1679 1683 2EFF06D61D8AF34A0004BB30 /* WKWebViewCandidateTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewCandidateTests.mm; sourceTree = "<group>"; }; 1684 3128A81223763F0B00D90D40 /* link-with-image.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "link-with-image.html"; sourceTree = "<group>"; }; 1685 3128A814237640FD00D90D40 /* image.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = image.html; sourceTree = "<group>"; }; 1680 1686 313C3A0121E5677A00DBA86E /* SystemPreviewBlobNaming.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = SystemPreviewBlobNaming.html; sourceTree = "<group>"; }; 1681 1687 3151180F1DB1ADD500176304 /* ExtendedColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtendedColor.cpp; sourceTree = "<group>"; }; … … 3335 3341 F4DEF6EC1E9B4D950048EF61 /* image-in-link-and-input.html */, 3336 3342 F45B63FA1F197F33009D38B9 /* image-map.html */, 3343 3128A814237640FD00D90D40 /* image.html */, 3337 3344 7283A9CE22FA6BBE00B21C7D /* img-with-rotated-image.html */, 3338 3345 934FA5C720F69FEE0040DC1B /* IndexedDB.sqlite3 */, … … 3383 3390 F41AB99D1EF4692C0083FA08 /* link-and-target-div.html */, 3384 3391 F46128D1211E2D2500D9FADB /* link-in-iframe-and-input.html */, 3392 3128A81223763F0B00D90D40 /* link-with-image.html */, 3385 3393 CA7787FE228CEFC700E50463 /* local-storage-process-crashes.html */, 3386 3394 9368A25D229EFB3A00A829CA /* local-storage-process-suspends-1.html */, -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm
r250403 r252309 36 36 37 37 static bool contextMenuRequested; 38 static bool contextMenuSPIRequested; 38 39 static bool willPresentCalled; 39 40 static bool willCommitCalled; … … 100 101 @end 101 102 102 TEST( WebKit, ContextMenuClick)103 TEST(ContextMenu, Click) 103 104 { 104 105 auto driver = contextMenuWebViewDriver([TestContextMenuUIDelegate class]); … … 115 116 } 116 117 117 TEST( WebKit, ContextMenuEnd)118 TEST(ContextMenu, End) 118 119 { 119 120 auto driver = contextMenuWebViewDriver([TestContextMenuUIDelegate class]); … … 129 130 } 130 131 132 @interface TestContextMenuAPIBeforeSPIUIDelegate : NSObject <WKUIDelegate> 133 @end 134 135 @implementation TestContextMenuAPIBeforeSPIUIDelegate 136 137 - (void)webView:(WKWebView *)webView contextMenuConfigurationForElement:(WKContextMenuElementInfo *)elementInfo completionHandler:(void(^)(UIContextMenuConfiguration * _Nullable))completionHandler 138 { 139 contextMenuRequested = true; 140 UIContextMenuContentPreviewProvider previewProvider = ^UIViewController * () 141 { 142 return [[[UIViewController alloc] init] autorelease]; 143 }; 144 UIContextMenuActionProvider actionProvider = ^UIMenu *(NSArray<UIMenuElement *> *suggestedActions) 145 { 146 return [UIMenu menuWithTitle:@"" children:suggestedActions]; 147 }; 148 completionHandler([UIContextMenuConfiguration configurationWithIdentifier:nil previewProvider:previewProvider actionProvider:actionProvider]); 149 } 150 151 - (void)_webView:(WKWebView *)webView contextMenuConfigurationForElement:(WKContextMenuElementInfo *)elementInfo completionHandler:(void(^)(UIContextMenuConfiguration * _Nullable))completionHandler 152 { 153 contextMenuSPIRequested = true; 154 completionHandler(nil); 155 } 156 157 - (void)webView:(WKWebView *)webView contextMenuWillPresentForElement:(WKContextMenuElementInfo *)elementInfo 158 { 159 willPresentCalled = true; 160 } 161 162 @end 163 164 TEST(ContextMenu, APIBeforeSPI) 165 { 166 auto driver = contextMenuWebViewDriver([TestContextMenuAPIBeforeSPIUIDelegate class]); 167 [driver begin:^(BOOL result) { 168 EXPECT_TRUE(result); 169 [driver clickDown]; 170 [driver clickUp]; 171 }]; 172 TestWebKitAPI::Util::run(&willPresentCalled); 173 EXPECT_TRUE(contextMenuRequested); 174 EXPECT_FALSE(contextMenuSPIRequested); 175 } 176 131 177 @interface TestContextMenuImageUIDelegate : NSObject <WKUIDelegate> 132 178 @end … … 164 210 @end 165 211 166 TEST( WebKit, ContextMenuImage)212 TEST(ContextMenu, Image) 167 213 { 168 214 linkURL = [NSURL URLWithString:@"http://127.0.0.1/image"]; … … 232 278 @end 233 279 234 TEST( WebKit, ContextMenuLegacy)280 TEST(ContextMenu, Legacy) 235 281 { 236 282 auto driver = contextMenuWebViewDriver([LegacyContextMenuUIDelegate class]); … … 287 333 @end 288 334 289 TEST( WebKit, ContextMenuSuggestedActions)335 TEST(ContextMenu, SuggestedActions) 290 336 { 291 337 auto driver = contextMenuWebViewDriver([TestContextMenuSuggestedActionsUIDelegate class]); -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm
r248701 r252309 50 50 } 51 51 52 TEST( WebKit, RequestActivatedElementInfoForLink)53 { 54 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 55 [webView loadHTMLString:@"<html><head><meta name='viewport' content='initial-scale=1'></head><body style ='margin: 0px;'><a href='testURL.test' style='display: block; height: 100%;' title='HitTestLinkTitle' id='testID'></a></body></html>" baseURL:nil];52 TEST(_WKActivatedElementInfo, InfoForLink) 53 { 54 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 55 [webView loadHTMLString:@"<html><head><meta name='viewport' content='initial-scale=1'></head><body style='margin: 0px;'><a href='testURL.test' style='display: block; height: 100%;' title='HitTestLinkTitle' id='testID'></a></body></html>" baseURL:nil]; 56 56 [webView _test_waitForDidFinishNavigation]; 57 57 … … 74 74 TestWebKitAPI::Util::run(&finished); 75 75 } 76 77 TEST(WebKit, RequestActivatedElementInfoForImage) 76 77 TEST(_WKActivatedElementInfo, InfoForImage) 78 { 79 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 215, 174)]); 80 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"image" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 81 [webView loadRequest:request]; 82 [webView _test_waitForDidFinishNavigation]; 83 84 __block bool finished = false; 85 [webView _requestActivatedElementAtPosition:CGPointMake(50, 50) completionBlock: ^(_WKActivatedElementInfo *elementInfo) { 86 87 EXPECT_TRUE(elementInfo.type == _WKActivatedElementTypeImage); 88 EXPECT_WK_STREQ(elementInfo.imageURL.lastPathComponent, "large-red-square.png"); 89 EXPECT_NOT_NULL(elementInfo.image); 90 91 finished = true; 92 }]; 93 94 TestWebKitAPI::Util::run(&finished); 95 } 96 97 TEST(_WKActivatedElementInfo, InfoForMediaDocument) 78 98 { 79 99 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 215, 174)]); … … 99 119 } 100 120 101 TEST(WebKit, RequestActivatedElementInfoForRotatedImage) 121 TEST(_WKActivatedElementInfo, InfoForLinkAroundImage) 122 { 123 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 124 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"link-with-image" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 125 [webView loadRequest:request]; 126 [webView _test_waitForDidFinishNavigation]; 127 128 __block bool finished = false; 129 [webView _requestActivatedElementAtPosition:CGPointMake(50, 50) completionBlock: ^(_WKActivatedElementInfo *elementInfo) { 130 131 EXPECT_TRUE(elementInfo.type == _WKActivatedElementTypeLink); 132 EXPECT_WK_STREQ(elementInfo.URL.lastPathComponent, "testURL.test"); 133 EXPECT_WK_STREQ(elementInfo.title, "HitTestImageTitle"); 134 EXPECT_WK_STREQ(elementInfo.ID, @"testID"); 135 EXPECT_NOT_NULL(elementInfo.image); 136 EXPECT_EQ(elementInfo.boundingRect.size.width, 320); 137 EXPECT_EQ(elementInfo.boundingRect.size.height, 500); 138 EXPECT_EQ(elementInfo.image.size.width, 1668); 139 EXPECT_EQ(elementInfo.image.size.height, 1668); 140 141 finished = true; 142 }]; 143 144 TestWebKitAPI::Util::run(&finished); 145 } 146 147 148 TEST(_WKActivatedElementInfo, InfoForRotatedImage) 102 149 { 103 150 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 104 151 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"img-with-rotated-image" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 105 106 152 [webView loadRequest:request]; 107 153 [webView _test_waitForDidFinishNavigation]; … … 156 202 } 157 203 158 TEST( WebKit, RequestActivatedElementInfoForBlank)159 { 160 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 161 [webView loadHTMLString:@"<html><head><meta name='viewport' content='initial-scale=1'></head><body style ='margin: 0px;'></body></html>" baseURL:nil];204 TEST(_WKActivatedElementInfo, InfoForBlank) 205 { 206 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 207 [webView loadHTMLString:@"<html><head><meta name='viewport' content='initial-scale=1'></head><body style='margin: 0px;'></body></html>" baseURL:nil]; 162 208 [webView _test_waitForDidFinishNavigation]; 163 209 … … 175 221 } 176 222 177 TEST( WebKit, RequestActivatedElementInfoForBrokenImage)178 { 179 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 180 [webView loadHTMLString:@"<html><head><meta name='viewport' content='initial-scale=1'></head><body style ='margin: 0px;'><img src='missing.gif' height='100' width='100'></body></html>" baseURL:nil];223 TEST(_WKActivatedElementInfo, InfoForBrokenImage) 224 { 225 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 226 [webView loadHTMLString:@"<html><head><meta name='viewport' content='initial-scale=1'></head><body style='margin: 0px;'><img src='missing.gif' height='100' width='100'></body></html>" baseURL:nil]; 181 227 [webView _test_waitForDidFinishNavigation]; 182 228 … … 194 240 } 195 241 196 TEST( WebKit, RequestActivatedElementInfoForAttachment)242 TEST(_WKActivatedElementInfo, InfoForAttachment) 197 243 { 198 244 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); … … 213 259 } 214 260 215 TEST( WebKit, RequestActivatedElementInfoWithNestedSynchronousUpdates)261 TEST(_WKActivatedElementInfo, InfoWithNestedSynchronousUpdates) 216 262 { 217 263 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); … … 237 283 } 238 284 239 TEST( WebKit, RequestActivatedElementInfoWithNestedRequests)285 TEST(_WKActivatedElementInfo, InfoWithNestedRequests) 240 286 { 241 287 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
Note: See TracChangeset
for help on using the changeset viewer.