Skip to content

Commit

Permalink
AR issues. Right after opening the USDZ and GLB file in the browser, …
Browse files Browse the repository at this point in the history
…it closes itself

https://bugs.webkit.org/show_bug.cgi?id=259670
rdar://110978209

Reviewed by Tim Horton.

We tightened the list of MIME types we accepted in ARQL during
the past year. Unfortunately still many servers are not configured
to send USD with the correct type, so we need to relax the list
a bit. For now, we'll add "application/octet-stream".

Added a new API test for this case.

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

Canonical link: https://commits.webkit.org/266462@main
  • Loading branch information
grorg committed Aug 1, 2023
1 parent 7e04799 commit 416f234
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ - (id)initWithSystemPreviewController:(WebKit::SystemPreviewController*)previewC

- (BOOL)isValidMIMEType:(NSString *)MIMEType
{
return WebCore::MIMETypeRegistry::isUSDMIMEType(MIMEType);
// We need to be liberal in which MIME types we accept, because some servers are not configured for USD.
return WebCore::MIMETypeRegistry::isUSDMIMEType(MIMEType) || [MIMEType isEqualToString:@"application/octet-stream"];
}

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

TEST(WebKit, SystemPreviewUnknownMIMEType)
{
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()];

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"UnitBox" withExtension:@"usdz" subdirectory:@"TestWebKitAPI.resources"];
NSData *modelData = [NSData dataWithContentsOfURL:modelURL];
NSString *modelBase64 = [modelData base64EncodedStringWithOptions:0];
NSString *html = [NSString stringWithFormat:@"<script>let base64URL = 'data:application/octet-stream;base64,%@';"
"fetch(base64URL)"
" .then((response) => response.blob())"
" .then((blob) => {"
" const blobURL = URL.createObjectURL(blob);"
" var a = document.createElement('a');"
" a.href = blobURL;"
" a.rel = 'ar';"
" document.body.appendChild(a);"
" var i = document.createElement('img');"
" a.appendChild(i);"
" a.click();"
" });</script>", modelBase64];

[webView loadHTMLString:html baseURL:nil];

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

Util::run(&wasTriggered);
}

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

0 comments on commit 416f234

Please sign in to comment.