Skip to content

Commit

Permalink
AR View closes instead of showing 3D asset - MobileSafari Crashing at…
Browse files Browse the repository at this point in the history
… -[_WKSystemPreviewDataTaskDelegate dataTask:didCompleteWithError:] + 32

https://bugs.webkit.org/show_bug.cgi?id=258957
rdar://110671973

Reviewed by Tim Horton.

When we try to load a `blob:` URL, the WKDataTask instantly fails. This
causes us to try to close a file handle that hasn't been initialised.
Add a check to make sure that doesn't happen.

There is still the bigger bug of needing to actually load blob URLs.

* Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/SystemPreview.mm:
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/system-preview.html:

Canonical link: https://commits.webkit.org/266048@main
  • Loading branch information
grorg authored and mwyrzykowski committed Jul 13, 2023
1 parent 127b86b commit c7ca298
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ - (id)initWithSystemPreviewController:(WebKit::SystemPreviewController*)previewC
return nil;

_previewController = previewController;
_fileHandle = FileSystem::invalidPlatformFileHandle;
return self;
}

Expand Down Expand Up @@ -346,6 +347,7 @@ - (void)dataTask:(_WKDataTask *)dataTask didCompleteWithError:(NSError *)error

- (void)completeLoad
{
ASSERT(_fileHandle != FileSystem::invalidPlatformFileHandle);
size_t byteCount = FileSystem::writeToFile(_fileHandle, [_data bytes], [_data length]);
FileSystem::closeFile(_fileHandle);

Expand Down
24 changes: 24 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebKitCocoa/SystemPreview.mm
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,30 @@ - (UIViewController *)_presentingViewControllerForWebView:(WKWebView *)webView
Util::run(&wasTriggered);
}

TEST(WebKit, SystemPreviewBlob)
{
auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
[configuration _setSystemPreviewEnabled:YES];

auto viewController = adoptNS([[UIViewController alloc] init]);
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
auto uiDelegate = adoptNS([[TestSystemPreviewUIDelegate alloc] init]);
uiDelegate.get().viewController = viewController.get();
[webView setUIDelegate:uiDelegate.get()];
[viewController setView:webView.get()];

[webView synchronouslyLoadTestPageNamed:@"system-preview"];

[webView _setSystemPreviewCompletionHandlerForLoadTesting:^(bool success) {
EXPECT_FALSE(success);
wasTriggered = true;
}];

[webView evaluateJavaScript:@"bloblink.click()" completionHandler:nil];

Util::run(&wasTriggered);
}

TEST(WebKit, SystemPreviewTriggered)
{
auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
Expand Down
3 changes: 3 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebKitCocoa/system-preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
<a id="badlink" rel="ar" href="BadLink.usdz">
<img>
</a>
<a id="bloblink" rel="ar" href="blob:foo">
<img>
</a>

0 comments on commit c7ca298

Please sign in to comment.