From 616ae5044d356d195e90a873ee648aabdfc60552 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 4 Jun 2020 21:01:38 -0700 Subject: [PATCH] browser(webkit): support bypass list on Mac (#2479) --- browser_patches/webkit/BUILD_NUMBER | 2 +- .../embedder/Playwright/mac/AppDelegate.h | 1 + .../embedder/Playwright/mac/AppDelegate.m | 22 ++++++++++++++----- browser_patches/webkit/patches/bootstrap.diff | 8 +++---- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/browser_patches/webkit/BUILD_NUMBER b/browser_patches/webkit/BUILD_NUMBER index 8e7d494b5f4e2..c686973f9b155 100644 --- a/browser_patches/webkit/BUILD_NUMBER +++ b/browser_patches/webkit/BUILD_NUMBER @@ -1 +1 @@ -1266 +1267 diff --git a/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.h b/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.h index a664c85acad31..92872987f4784 100644 --- a/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.h +++ b/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.h @@ -40,6 +40,7 @@ NSString* _initialURL; NSString* _userDataDir; NSString* _proxyServer; + NSString* _proxyBypassList; IBOutlet NSMenuItem *_newWebKit2WindowItem; } diff --git a/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.m b/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.m index c4412707302f7..53881d97fe58d 100644 --- a/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.m +++ b/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.m @@ -90,6 +90,7 @@ - (id)init _initialURL = nil; _userDataDir = nil; _proxyServer = nil; + _proxyBypassList = nil; NSArray *arguments = [[NSProcessInfo processInfo] arguments]; NSRange subargs = NSMakeRange(1, [arguments count] - 1); NSArray *subArray = [arguments subarrayWithRange:subargs]; @@ -105,6 +106,10 @@ - (id)init NSRange range = NSMakeRange(8, [argument length] - 8); _proxyServer = [[argument substringWithRange:range] copy]; } + if ([argument hasPrefix:@"--proxy-bypass-list="]) { + NSRange range = NSMakeRange(20, [argument length] - 20); + _proxyBypassList = [[argument substringWithRange:range] copy]; + } } _headless = [arguments containsObject: @"--headless"]; @@ -132,9 +137,9 @@ - (void)awakeFromNib } -- (NSDictionary *)proxyConfiguration:(NSString *)proxyServer +- (NSDictionary *)proxyConfiguration:(NSString *)proxyServer WithBypassList:(NSString *)proxyBypassList { - if (!proxyServer) + if (!proxyServer || ![proxyServer length]) return nil; #pragma clang diagnostic push @@ -157,6 +162,11 @@ - (NSDictionary *)proxyConfiguration:(NSString *)proxyServer } } + if (proxyBypassList && [proxyBypassList length]) { + NSArray* bypassList = [proxyBypassList componentsSeparatedByString:@","]; + [dictionary setObject:bypassList forKey:@"ExceptionsList"]; + } + #pragma clang diagnostic pop return dictionary; @@ -202,7 +212,7 @@ - (WKWebsiteDataStore *)persistentDataStore NSURL *webSqlDirectory = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/WebSQL", _userDataDir]]; [configuration _setWebSQLDatabaseDirectory:webSqlDirectory]; } - [configuration setProxyConfiguration:[self proxyConfiguration:_proxyServer]]; + [configuration setProxyConfiguration:[self proxyConfiguration:_proxyServer WithBypassList:_proxyBypassList]]; dataStore = [[WKWebsiteDataStore alloc] _initWithConfiguration:configuration]; } @@ -312,7 +322,7 @@ - (WKWebView *)createHeadlessPage:(WKWebViewConfiguration *)configuration withUR return [webView autorelease]; } -- (_WKBrowserContext *)createBrowserContext:(NSString *)proxyServer +- (_WKBrowserContext *)createBrowserContext:(NSString *)proxyServer WithBypassList:(NSString *) proxyBypassList { _WKBrowserContext *browserContext = [[_WKBrowserContext alloc] init]; _WKProcessPoolConfiguration *processConfiguration = [[[_WKProcessPoolConfiguration alloc] init] autorelease]; @@ -320,7 +330,9 @@ - (_WKBrowserContext *)createBrowserContext:(NSString *)proxyServer _WKWebsiteDataStoreConfiguration *dataStoreConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] initNonPersistentConfiguration] autorelease]; if (!proxyServer || ![proxyServer length]) proxyServer = _proxyServer; - [dataStoreConfiguration setProxyConfiguration:[self proxyConfiguration:proxyServer]]; + if (!proxyBypassList || ![proxyBypassList length]) + proxyBypassList = _proxyBypassList; + [dataStoreConfiguration setProxyConfiguration:[self proxyConfiguration:proxyServer WithBypassList:proxyBypassList]]; browserContext.dataStore = [[WKWebsiteDataStore alloc] _initWithConfiguration:dataStoreConfiguration]; browserContext.processPool = [[[WKProcessPool alloc] _initWithConfiguration:processConfiguration] autorelease]; [browserContext.processPool _setDownloadDelegate:self]; diff --git a/browser_patches/webkit/patches/bootstrap.diff b/browser_patches/webkit/patches/bootstrap.diff index 8c1dc480d9349..d3dfac9638653 100644 --- a/browser_patches/webkit/patches/bootstrap.diff +++ b/browser_patches/webkit/patches/bootstrap.diff @@ -7419,7 +7419,7 @@ index 591428f7f579e76ff01bc94b83f5994af8e48e00..03fc6cf2d3074d9227d7815ac5c72fdb Vector result; diff --git a/Source/WebKit/UIProcess/API/Cocoa/_WKBrowserInspector.h b/Source/WebKit/UIProcess/API/Cocoa/_WKBrowserInspector.h new file mode 100644 -index 0000000000000000000000000000000000000000..2d7788193f85ce53860d2996650560a7dcc73457 +index 0000000000000000000000000000000000000000..5fabe06a3289689246c36dfd96eb9900a48b2b0f --- /dev/null +++ b/Source/WebKit/UIProcess/API/Cocoa/_WKBrowserInspector.h @@ -0,0 +1,55 @@ @@ -7465,7 +7465,7 @@ index 0000000000000000000000000000000000000000..2d7788193f85ce53860d2996650560a7 + +@protocol _WKBrowserInspectorDelegate +- (WKWebView *)createNewPage:(uint64_t)sessionID; -+- (_WKBrowserContext *)createBrowserContext:(NSString *)proxyServer; ++- (_WKBrowserContext *)createBrowserContext:(NSString *)proxyServer WithBypassList:(NSString *)proxyBypassList; +- (void)deleteBrowserContext:(uint64_t)sessionID; +- (void)quit; +@end @@ -13318,7 +13318,7 @@ index 0000000000000000000000000000000000000000..bce31b16fe37dc2a981389a6160e4094 +} // namespace API diff --git a/Source/WebKit/UIProcess/mac/InspectorPlaywrightAgentClientMac.mm b/Source/WebKit/UIProcess/mac/InspectorPlaywrightAgentClientMac.mm new file mode 100644 -index 0000000000000000000000000000000000000000..b20118cb4bcd3bc962d5b5b052e408c2a0881aae +index 0000000000000000000000000000000000000000..600a1687094f5a209f24dc951206ba7faf4de991 --- /dev/null +++ b/Source/WebKit/UIProcess/mac/InspectorPlaywrightAgentClientMac.mm @@ -0,0 +1,77 @@ @@ -13386,7 +13386,7 @@ index 0000000000000000000000000000000000000000..b20118cb4bcd3bc962d5b5b052e408c2 + +BrowserContext InspectorPlaywrightAgentClientMac::createBrowserContext(WTF::String& error, const WTF::String& proxyServer, const WTF::String& proxyBypassList) +{ -+ _WKBrowserContext* wkBrowserContext = [[delegate_ createBrowserContext:proxyServer] autorelease]; ++ _WKBrowserContext* wkBrowserContext = [[delegate_ createBrowserContext:proxyServer WithBypassList:proxyBypassList] autorelease]; + BrowserContext browserContext; + browserContext.processPool = &static_cast([[wkBrowserContext processPool] _apiObject]); + browserContext.dataStore = &static_cast([[wkBrowserContext dataStore] _apiObject]);