Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
browser(webkit): build fix, switch to the new download API (#4621)
  • Loading branch information
yury-s committed Dec 7, 2020
1 parent d8520f0 commit 4be41f2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions 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
Expand Up @@ -31,7 +31,7 @@
@property (nonatomic, copy) void (^completionHandler)(BOOL accept, NSString* value);
@end

@interface BrowserAppDelegate : NSObject <NSApplicationDelegate, WKNavigationDelegate, WKUIDelegate, _WKBrowserInspectorDelegate, _WKDownloadDelegate> {
@interface BrowserAppDelegate : NSObject <NSApplicationDelegate, WKNavigationDelegate, WKUIDelegate, _WKBrowserInspectorDelegate, WKDownloadDelegate> {
NSMutableSet *_headlessWindows;
NSMutableSet *_browserContexts;
bool _headless;
Expand Down
23 changes: 16 additions & 7 deletions browser_patches/webkit/embedder/Playwright/mac/AppDelegate.m
Expand Up @@ -335,7 +335,6 @@ - (_WKBrowserContext *)createBrowserContext:(NSString *)proxyServer WithBypassLi
[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;
}
Expand Down Expand Up @@ -434,8 +433,8 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati
{
LOG(@"decidePolicyForNavigationAction");

if (navigationAction._shouldPerformDownload) {
decisionHandler(_WKNavigationActionPolicyDownload);
if (navigationAction.downloadAttribute) {
decisionHandler(WKNavigationActionPolicyBecomeDownload);
return;
}
if (navigationAction._canHandleRequest) {
Expand All @@ -455,17 +454,27 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNaviga

NSString *disposition = [[httpResponse allHeaderFields] objectForKey:@"Content-Disposition"];
if (disposition && [disposition hasPrefix:@"attachment"]) {
decisionHandler(_WKNavigationResponsePolicyBecomeDownload);
decisionHandler(WKNavigationResponsePolicyBecomeDownload);
return;
}
decisionHandler(WKNavigationResponsePolicyAllow);
}

#pragma mark _WKDownloadDelegate
- (void)webView:(WKWebView *)webView navigationAction:(WKNavigationAction *)navigationAction didBecomeDownload:(WKDownload *)download
{
download.delegate = self;
}

- (void)webView:(WKWebView *)webView navigationResponse:(WKNavigationResponse *)navigationResponse didBecomeDownload:(WKDownload *)download
{
download.delegate = self;
}

#pragma mark WKDownloadDelegate

- (void)_download:(_WKDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename completionHandler:(void (^)(BOOL allowOverwrite, NSString *destination))completionHandler
- (void)download:(WKDownload *)download decideDestinationWithResponse:(NSURLResponse *)response suggestedFilename:(NSString *)suggestedFilename completionHandler:(void (^)(NSURL * _Nullable destination))completionHandler
{
completionHandler(NO, @"");
completionHandler(nil);
}

@end
Expand Up @@ -687,7 +687,7 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNaviga

NSString *disposition = [[httpResponse allHeaderFields] objectForKey:@"Content-Disposition"];
if (disposition && [disposition hasPrefix:@"attachment"]) {
decisionHandler(_WKNavigationResponsePolicyBecomeDownload);
decisionHandler(WKNavigationResponsePolicyBecomeDownload);
return;
}
decisionHandler(WKNavigationResponsePolicyAllow);
Expand Down

0 comments on commit 4be41f2

Please sign in to comment.