From 4be41f25715d1bda0c8dd639f6f99dea47048523 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 7 Dec 2020 10:10:32 -0800 Subject: [PATCH] browser(webkit): build fix, switch to the new download API (#4621) --- browser_patches/webkit/BUILD_NUMBER | 4 +-- .../embedder/Playwright/mac/AppDelegate.h | 2 +- .../embedder/Playwright/mac/AppDelegate.m | 25 +++++++++++++------ .../Playwright/mac/BrowserWindowController.m | 2 +- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/browser_patches/webkit/BUILD_NUMBER b/browser_patches/webkit/BUILD_NUMBER index 9af656eca1..b7067fcce4 100644 --- a/browser_patches/webkit/BUILD_NUMBER +++ b/browser_patches/webkit/BUILD_NUMBER @@ -1,2 +1,2 @@ -1398 -Changed: yurys@chromium.org Fri 04 Dec 2020 05:44:45 PM PST +1399 +Changed: yurys@chromium.org Mon Dec 7 10:04:55 PST 2020 diff --git a/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.h b/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.h index 92872987f4..4fb6229fa3 100644 --- a/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.h +++ b/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.h @@ -31,7 +31,7 @@ @property (nonatomic, copy) void (^completionHandler)(BOOL accept, NSString* value); @end -@interface BrowserAppDelegate : NSObject { +@interface BrowserAppDelegate : NSObject { NSMutableSet *_headlessWindows; NSMutableSet *_browserContexts; bool _headless; diff --git a/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.m b/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.m index 682d78e29a..b65e6b5c3a 100644 --- a/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.m +++ b/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.m @@ -335,7 +335,6 @@ const NSActivityOptions ActivityOptions = [dataStoreConfiguration setProxyConfiguration:[self proxyConfiguration:proxyServer WithBypassList:proxyBypassList]]; browserContext.dataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:dataStoreConfiguration] autorelease]; browserContext.processPool = [[[WKProcessPool alloc] _initWithConfiguration:processConfiguration] autorelease]; - [browserContext.processPool _setDownloadDelegate:self]; [_browserContexts addObject:browserContext]; return browserContext; } @@ -434,8 +433,8 @@ const NSActivityOptions ActivityOptions = { LOG(@"decidePolicyForNavigationAction"); - if (navigationAction._shouldPerformDownload) { - decisionHandler(_WKNavigationActionPolicyDownload); + if (navigationAction.downloadAttribute) { + decisionHandler(WKNavigationActionPolicyBecomeDownload); return; } if (navigationAction._canHandleRequest) { @@ -455,17 +454,27 @@ const NSActivityOptions ActivityOptions = NSString *disposition = [[httpResponse allHeaderFields] objectForKey:@"Content-Disposition"]; if (disposition && [disposition hasPrefix:@"attachment"]) { - decisionHandler(_WKNavigationResponsePolicyBecomeDownload); + decisionHandler(WKNavigationResponsePolicyBecomeDownload); return; } decisionHandler(WKNavigationResponsePolicyAllow); } -#pragma mark _WKDownloadDelegate - -- (void)_download:(_WKDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename completionHandler:(void (^)(BOOL allowOverwrite, NSString *destination))completionHandler +- (void)webView:(WKWebView *)webView navigationAction:(WKNavigationAction *)navigationAction didBecomeDownload:(WKDownload *)download { - completionHandler(NO, @""); + download.delegate = self; +} + +- (void)webView:(WKWebView *)webView navigationResponse:(WKNavigationResponse *)navigationResponse didBecomeDownload:(WKDownload *)download +{ + download.delegate = self; +} + +#pragma mark WKDownloadDelegate + +- (void)download:(WKDownload *)download decideDestinationWithResponse:(NSURLResponse *)response suggestedFilename:(NSString *)suggestedFilename completionHandler:(void (^)(NSURL * _Nullable destination))completionHandler +{ + completionHandler(nil); } @end diff --git a/browser_patches/webkit/embedder/Playwright/mac/BrowserWindowController.m b/browser_patches/webkit/embedder/Playwright/mac/BrowserWindowController.m index 4856e09e28..dd4bf528d4 100644 --- a/browser_patches/webkit/embedder/Playwright/mac/BrowserWindowController.m +++ b/browser_patches/webkit/embedder/Playwright/mac/BrowserWindowController.m @@ -687,7 +687,7 @@ static NSSet *dataTypes() NSString *disposition = [[httpResponse allHeaderFields] objectForKey:@"Content-Disposition"]; if (disposition && [disposition hasPrefix:@"attachment"]) { - decisionHandler(_WKNavigationResponsePolicyBecomeDownload); + decisionHandler(WKNavigationResponsePolicyBecomeDownload); return; } decisionHandler(WKNavigationResponsePolicyAllow);