Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use WKDataTask for SystemPreview downloads #13171

Conversation

grorg
Copy link
Contributor

@grorg grorg commented Apr 25, 2023

d55e3ca

Use WKDataTask for SystemPreview downloads
https://bugs.webkit.org/show_bug.cgi?id=255954
rdar://108524222

Reviewed by Tim Horton.

Migrate away from LegacyDownloadClient and instead handle System Previews
directly. This will allow us to remove the horrible code in the download
client, as well eventually allow 3rd-party engines to use ARQL.

The fix is to intercept the HTMLAnchorElement click for a system
preview, and send that directly to the SystemPreviewController in
the UI Process. That object then creates a WKDataTask for the download
and presents ARQL as normal.

A followup patch will remove the old code.

* Source/WebCore/html/HTMLAnchorElement.cpp:
* Source/WebCore/page/ChromeClient.h:
* Source/WebCore/page/Page.cpp:
* Source/WebCore/page/Page.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm:
* Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm:
* Source/WebKit/UIProcess/SystemPreviewController.h:
* Source/WebKit/UIProcess/WebPageProxy.cpp:
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/WebPageProxy.messages.in:
* Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp:
* Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/SystemPreview.mm:
(-[TestSystemPreviewUIDelegate _presentingViewControllerForWebView:]):
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/UnitBox.usdz: Added.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/system-preview-trigger.html:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/system-preview.html: Added.

Canonical link: https://commits.webkit.org/263393@main

65b5f69

Misc iOS, tvOS & watchOS macOS Linux Windows
❌ πŸ§ͺ style   πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe   πŸ›  wincairo
  πŸ§ͺ bindings   πŸ›  ios-sim   πŸ›  mac-AS-debug   πŸ§ͺ wpe-wk2
  πŸ§ͺ webkitperl   πŸ§ͺ ios-wk2   πŸ§ͺ api-mac βœ… πŸ›  gtk
  πŸ§ͺ ios-wk2-wpt   πŸ§ͺ mac-wk1   πŸ§ͺ gtk-wk2
  πŸ§ͺ api-ios   πŸ§ͺ mac-wk2   πŸ§ͺ api-gtk
  πŸ›  tv   πŸ§ͺ mac-AS-debug-wk2
  πŸ›  tv-sim   πŸ§ͺ mac-wk2-stress
  πŸ›  watch
❌ πŸ›  πŸ§ͺ unsafe-merge   πŸ›  watch-sim

@grorg grorg requested review from cdumez and rniwa as code owners April 25, 2023 21:53
@grorg grorg self-assigned this Apr 25, 2023
@grorg grorg added the WebKit Misc. For miscellaneous bugs in the WebKit framework (and not JavaScriptCore or WebCore). label Apr 25, 2023
@grorg grorg requested review from hortont424 and achristensen07 and removed request for rniwa and cdumez April 25, 2023 21:53
return;
}

[_data.get() appendData:data];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no .get()

@@ -59,6 +61,8 @@ + (void)launchPreviewApplicationWithURLs:(NSArray *)urls completion:(void (^)(NS

static NSString * const _WKARQLWebsiteURLParameterKey = @"ARQLWebsiteURLParameterKey";

const int64_t SystemPreviewMaximumSize = 40 * 1024 * 1024;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems awfully tiny

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove the limit.

auto filePath = FileSystem::openTemporaryFile("SystemPreview"_s, fileHandle, ".usdz"_s);
ASSERT(FileSystem::isHandleValid(fileHandle));

size_t byteCount = FileSystem::writeToFile(fileHandle, _data.get().bytes, _data.get().length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would [_data bytes] (etc.), but I know some people like this instead?

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 25, 2023
@interface _WKSystemPreviewDataTaskDelegate : NSObject <_WKDataTaskDelegate> {
WebKit::SystemPreviewController* _previewController;
long long _expectedContentLength;
long long _receivedLength;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this variable used anywhere?

@grorg grorg force-pushed the eng/Use-WKDataTask-for-SystemPreview-downloads branch from 608e61e to f7acd1d Compare April 25, 2023 22:32
@grorg grorg force-pushed the eng/Use-WKDataTask-for-SystemPreview-downloads branch from f7acd1d to adb2bc1 Compare April 25, 2023 22:33
@grorg grorg force-pushed the eng/Use-WKDataTask-for-SystemPreview-downloads branch from adb2bc1 to 65b5f69 Compare April 25, 2023 23:21
@grorg grorg added unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing and removed merging-blocked Applied to prevent a change from being merged labels Apr 25, 2023
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Use-WKDataTask-for-SystemPreview-downloads branch from 65b5f69 to 369b7ba Compare April 25, 2023 23:26
https://bugs.webkit.org/show_bug.cgi?id=255954
rdar://108524222

Reviewed by Tim Horton.

Migrate away from LegacyDownloadClient and instead handle System Previews
directly. This will allow us to remove the horrible code in the download
client, as well eventually allow 3rd-party engines to use ARQL.

The fix is to intercept the HTMLAnchorElement click for a system
preview, and send that directly to the SystemPreviewController in
the UI Process. That object then creates a WKDataTask for the download
and presents ARQL as normal.

A followup patch will remove the old code.

* Source/WebCore/html/HTMLAnchorElement.cpp:
* Source/WebCore/page/ChromeClient.h:
* Source/WebCore/page/Page.cpp:
* Source/WebCore/page/Page.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm:
* Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm:
* Source/WebKit/UIProcess/SystemPreviewController.h:
* Source/WebKit/UIProcess/WebPageProxy.cpp:
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/WebPageProxy.messages.in:
* Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp:
* Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/SystemPreview.mm:
(-[TestSystemPreviewUIDelegate _presentingViewControllerForWebView:]):
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/UnitBox.usdz: Added.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/system-preview-trigger.html:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/system-preview.html: Added.

Canonical link: https://commits.webkit.org/263393@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Use-WKDataTask-for-SystemPreview-downloads branch from 369b7ba to d55e3ca Compare April 25, 2023 23:29
@webkit-commit-queue
Copy link
Collaborator

Committed 263393@main (d55e3ca): https://commits.webkit.org/263393@main

Reviewed commits have been landed. Closing PR #13171 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit d55e3ca into WebKit:main Apr 25, 2023
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Apr 25, 2023
@grorg grorg deleted the eng/Use-WKDataTask-for-SystemPreview-downloads branch April 25, 2023 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebKit Misc. For miscellaneous bugs in the WebKit framework (and not JavaScriptCore or WebCore).
Projects
None yet
6 participants