- Revision
- 291491
- Author
- [email protected]
- Date
- 2022-03-18 12:11:11 -0700 (Fri, 18 Mar 2022)
Log Message
Trigger PDF download in captive portal mode instead of using PDF viewer
https://bugs.webkit.org/show_bug.cgi?id=237245
rdar://problem/89525531
Reviewed by Chris Dumez.
Source/WebKit:
This is a stopgap solution since PDF.js needs more cycles to polish.
Added API test WKDownload.CaptivePortalPDF.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::decidePolicyForResponseShared):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):
Tools:
Add API test for captive portal pdf behavior.
* TestWebKitAPI/Tests/WebKitCocoa/Download.mm:
(tempPDFThatDoesNotExist):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (291490 => 291491)
--- trunk/Source/WebKit/ChangeLog 2022-03-18 18:48:50 UTC (rev 291490)
+++ trunk/Source/WebKit/ChangeLog 2022-03-18 19:11:11 UTC (rev 291491)
@@ -1,3 +1,20 @@
+2022-03-18 J Pascoe <[email protected]>
+
+ Trigger PDF download in captive portal mode instead of using PDF viewer
+ https://bugs.webkit.org/show_bug.cgi?id=237245
+ rdar://problem/89525531
+
+ Reviewed by Chris Dumez.
+
+ This is a stopgap solution since PDF.js needs more cycles to polish.
+
+ Added API test WKDownload.CaptivePortalPDF.
+
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::decidePolicyForResponseShared):
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::updatePreferences):
+
2022-03-18 Kimmo Kinnunen <[email protected]>
Recycling a webgl context when it has been lost and restored causes a crash
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (291490 => 291491)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2022-03-18 18:48:50 UTC (rev 291490)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2022-03-18 19:11:11 UTC (rev 291491)
@@ -5731,6 +5731,8 @@
auto sender = PolicyDecisionSender::create(identifier, [webPageID, frameID, listenerID, process] (const auto& policyDecision) {
process->send(Messages::WebPage::DidReceivePolicyDecision(frameID, listenerID, policyDecision, createNetworkExtensionsSandboxExtensions(process)), webPageID);
});
+ if (process->captivePortalMode() == WebProcessProxy::CaptivePortalMode::Enabled && MIMETypeRegistry::isPDFOrPostScriptMIMEType(navigationResponse->response().mimeType()))
+ policyAction = PolicyAction::Download;
receivedPolicyDecision(policyAction, navigation.get(), nullptr, WTFMove(navigationResponse), WTFMove(sender));
}, ShouldExpectSafeBrowsingResult::No, ShouldExpectAppBoundDomainResult::No);
Modified: trunk/Tools/ChangeLog (291490 => 291491)
--- trunk/Tools/ChangeLog 2022-03-18 18:48:50 UTC (rev 291490)
+++ trunk/Tools/ChangeLog 2022-03-18 19:11:11 UTC (rev 291491)
@@ -1,3 +1,16 @@
+2022-03-18 J Pascoe <[email protected]>
+
+ Trigger PDF download in captive portal mode instead of using PDF viewer
+ https://bugs.webkit.org/show_bug.cgi?id=237245
+ rdar://problem/89525531
+
+ Reviewed by Chris Dumez.
+
+ Add API test for captive portal pdf behavior.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/Download.mm:
+ (tempPDFThatDoesNotExist):
+
2022-03-18 Jonathan Bedard <[email protected]>
[git-webkit] Make radar conditional on authentication
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm (291490 => 291491)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm 2022-03-18 18:48:50 UTC (rev 291490)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm 2022-03-18 19:11:11 UTC (rev 291491)
@@ -45,6 +45,8 @@
#import <WebKit/WKWebView.h>
#import <WebKit/WKWebViewConfiguration.h>
#import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <WebKit/WKWebpagePreferences.h>
+#import <WebKit/WKWebpagePreferencesPrivate.h>
#import <WebKit/WKWebsiteDataStorePrivate.h>
#import <WebKit/_WKDownload.h>
#import <WebKit/_WKDownloadDelegate.h>
@@ -1264,6 +1266,15 @@
return file;
}
+static NSURL *tempPDFThatDoesNotExist()
+{
+ NSURL *tempDir = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"DownloadTest"] isDirectory:YES];
+ [[NSFileManager defaultManager] createDirectoryAtURL:tempDir withIntermediateDirectories:YES attributes:nil error:nil];
+ NSURL *file = [tempDir URLByAppendingPathComponent:@"example.pdf"];
+ [[NSFileManager defaultManager] removeItemAtURL:file error:nil];
+ return file;
+}
+
TEST(_WKDownload, Resume)
{
using namespace TestWebKitAPI;
@@ -2617,4 +2628,53 @@
});
}
+
+static TestWebKitAPI::HTTPServer simplePDFTestServer()
+{
+ return { [](TestWebKitAPI::Connection connection) {
+ connection.receiveHTTPRequest([connection](Vector<char>&&) {
+ connection.send(makeString(
+ "HTTP/1.1 200 OK\r\n"
+ "content-type: application/pdf\r\n"
+ "Content-Length: 5000\r\n"
+ "\r\n", longString<5000>('a')
+ ));
+ });
+ } };
}
+
+TEST(WKDownload, CaptivePortalPDF)
+{
+ auto webViewConfiguration = adoptNS([WKWebViewConfiguration new]);
+ [webViewConfiguration.get().defaultWebpagePreferences _setCaptivePortalModeEnabled:YES];
+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
+ auto delegate = adoptNS([TestDownloadDelegate new]);
+ [webView setNavigationDelegate:delegate.get()];
+ auto server = simplePDFTestServer();
+ NSURL *expectedDownloadFile = tempPDFThatDoesNotExist();
+
+ delegate.get().navigationResponseDidBecomeDownload = ^(WKWebView *, WKNavigationResponse *, WKDownload *download) {
+ download.delegate = delegate.get();
+ delegate.get().decideDestinationUsingResponse = ^(WKDownload *download, NSURLResponse *, NSString *, void (^completionHandler)(NSURL *)) {
+ EXPECT_NULL(download.progress.fileURL);
+ completionHandler(expectedDownloadFile);
+ EXPECT_NOT_NULL(download.progress.fileURL);
+ EXPECT_WK_STREQ(download.progress.fileURL.absoluteString, expectedDownloadFile.absoluteString);
+ };
+ };
+
+ [webView loadRequest:server.request()];
+ [delegate waitForDownloadDidFinish];
+
+ checkFileContents(expectedDownloadFile, longString<5000>('a'));
+
+ checkCallbackRecord(delegate.get(), {
+ DownloadCallback::NavigationAction,
+ DownloadCallback::NavigationResponse,
+ DownloadCallback::NavigationResponseBecameDownload,
+ DownloadCallback::DecideDestination,
+ DownloadCallback::DidFinish
+ });
+}
+
+}