Enable HTTP and HTTPS proxies on iOS and make it a property of the NSURLSession
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Dec 2018 06:33:58 +0000 (06:33 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Dec 2018 06:33:58 +0000 (06:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192374
<rdar://problem/46506286>

Reviewed by Alex Christensen.

Source/WebCore/PAL:

* pal/spi/cf/CFNetworkSPI.h:
Remove the now-unused SPI declaration.

Source/WebKit:

This patch makes it so that we can use HTTP/HTTPS proxies on iOS as well.
To enable on iOS, you can do something like:
$ defaults write -g WebKit2HTTPProxy -string "http://localhost:8080"
$ defaults write -g WebKit2HTTPSProxy -string "http://localhost:8080"

This patch also changes the Proxy to be enabled on a per NSURLSession
basis instead of a per process basis.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::initializeNetworkProcess):
* NetworkProcess/NetworkSessionCreationParameters.cpp:
(WebKit::NetworkSessionCreationParameters::privateSessionParameters):
(WebKit::NetworkSessionCreationParameters::encode const):
(WebKit::NetworkSessionCreationParameters::decode):
* NetworkProcess/NetworkSessionCreationParameters.h:
* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(WebKit::proxyDictionary):
(WebKit::NetworkSessionCocoa::NetworkSessionCocoa):
* NetworkProcess/mac/NetworkProcessMac.mm:
(WebKit::NetworkProcess::platformInitializeNetworkProcess):
(WebKit::overrideSystemProxies): Deleted.
* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(-[WKWebsiteDataStore _initWithConfiguration:]):
* UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
* UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm:
(-[_WKWebsiteDataStoreConfiguration httpProxy]):
(-[_WKWebsiteDataStoreConfiguration setHTTPProxy:]):
(-[_WKWebsiteDataStoreConfiguration httpsProxy]):
(-[_WKWebsiteDataStoreConfiguration setHTTPSProxy:]):
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeNetworkProcess):
* UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
(WebKit::WebsiteDataStore::parameters):
* UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp:
(WebKit::WebsiteDataStoreConfiguration::copy):
* UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h:
(WebKit::WebsiteDataStoreConfiguration::httpProxy const):
(WebKit::WebsiteDataStoreConfiguration::setHTTPProxy):
(WebKit::WebsiteDataStoreConfiguration::httpsProxy const):
(WebKit::WebsiteDataStoreConfiguration::setHTTPSProxy):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239322 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.cpp
Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.h
Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm
Source/WebKit/NetworkProcess/mac/NetworkProcessMac.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h
Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm
Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm
Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h

index fcf8076..ca7b062 100644 (file)
@@ -1,3 +1,14 @@
+2018-12-17  Saam barati  <sbarati@apple.com>
+
+        Enable HTTP and HTTPS proxies on iOS and make it a property of the NSURLSession
+        https://bugs.webkit.org/show_bug.cgi?id=192374
+        <rdar://problem/46506286>
+
+        Reviewed by Alex Christensen.
+
+        * pal/spi/cf/CFNetworkSPI.h:
+        Remove the now-unused SPI declaration.
+
 2018-12-17  Simon Fraser  <simon.fraser@apple.com>
 
         Don't use more expensive layer backing store formats when subpixel text antialiasing is not enabled
index 876b1ea..aa26ecf 100644 (file)
@@ -33,6 +33,7 @@
 #if PLATFORM(WIN) || USE(APPLE_INTERNAL_SDK)
 
 #include <CFNetwork/CFHTTPCookiesPriv.h>
+#include <CFNetwork/CFHTTPStream.h>
 #include <CFNetwork/CFProxySupportPriv.h>
 #include <CFNetwork/CFURLCachePriv.h>
 #include <CFNetwork/CFURLConnectionPriv.h>
@@ -265,7 +266,6 @@ typedef void (*CFHTTPCookieStorageChangedProcPtr)(CFHTTPCookieStorageRef, void*)
 void CFHTTPCookieStorageAddObserver(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef, CFHTTPCookieStorageChangedProcPtr, void*);
 void CFHTTPCookieStorageRemoveObserver(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef, CFHTTPCookieStorageChangedProcPtr, void*);
 
-void _CFNetworkSetOverrideSystemProxySettings(CFDictionaryRef);
 CFURLCredentialStorageRef CFURLCredentialStorageCreate(CFAllocatorRef);
 CFURLCredentialRef CFURLCredentialStorageCopyDefaultCredentialForProtectionSpace(CFURLCredentialStorageRef, CFURLProtectionSpaceRef);
 CFURLRequestPriority CFURLRequestGetRequestPriority(CFURLRequestRef);
index 8870286..d36ae2e 100644 (file)
@@ -1,3 +1,52 @@
+2018-12-17  Saam barati  <sbarati@apple.com>
+
+        Enable HTTP and HTTPS proxies on iOS and make it a property of the NSURLSession
+        https://bugs.webkit.org/show_bug.cgi?id=192374
+        <rdar://problem/46506286>
+
+        Reviewed by Alex Christensen.
+
+        This patch makes it so that we can use HTTP/HTTPS proxies on iOS as well.
+        To enable on iOS, you can do something like:
+        $ defaults write -g WebKit2HTTPProxy -string "http://localhost:8080"
+        $ defaults write -g WebKit2HTTPSProxy -string "http://localhost:8080"
+        
+        This patch also changes the Proxy to be enabled on a per NSURLSession
+        basis instead of a per process basis.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::initializeNetworkProcess):
+        * NetworkProcess/NetworkSessionCreationParameters.cpp:
+        (WebKit::NetworkSessionCreationParameters::privateSessionParameters):
+        (WebKit::NetworkSessionCreationParameters::encode const):
+        (WebKit::NetworkSessionCreationParameters::decode):
+        * NetworkProcess/NetworkSessionCreationParameters.h:
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (WebKit::proxyDictionary):
+        (WebKit::NetworkSessionCocoa::NetworkSessionCocoa):
+        * NetworkProcess/mac/NetworkProcessMac.mm:
+        (WebKit::NetworkProcess::platformInitializeNetworkProcess):
+        (WebKit::overrideSystemProxies): Deleted.
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+        (-[WKWebsiteDataStore _initWithConfiguration:]):
+        * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
+        * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm:
+        (-[_WKWebsiteDataStoreConfiguration httpProxy]):
+        (-[_WKWebsiteDataStoreConfiguration setHTTPProxy:]):
+        (-[_WKWebsiteDataStoreConfiguration httpsProxy]):
+        (-[_WKWebsiteDataStoreConfiguration setHTTPSProxy:]):
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::platformInitializeNetworkProcess):
+        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
+        (WebKit::WebsiteDataStore::parameters):
+        * UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp:
+        (WebKit::WebsiteDataStoreConfiguration::copy):
+        * UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h:
+        (WebKit::WebsiteDataStoreConfiguration::httpProxy const):
+        (WebKit::WebsiteDataStoreConfiguration::setHTTPProxy):
+        (WebKit::WebsiteDataStoreConfiguration::httpsProxy const):
+        (WebKit::WebsiteDataStoreConfiguration::setHTTPSProxy):
+
 2018-12-17  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Tap highlights should not be shown on iOSMac
index 0b31ff7..d7d660a 100644 (file)
@@ -299,7 +299,12 @@ void NetworkProcess::initializeNetworkProcess(NetworkProcessCreationParameters&&
     if (parameters.shouldUseTestingNetworkSession)
         NetworkStorageSession::switchToNewTestingSession();
 
-    SessionTracker::setSession(PAL::SessionID::defaultSessionID(), NetworkSession::create(NetworkSessionCreationParameters()));
+    NetworkSessionCreationParameters sessionCreationParameters { };
+#if PLATFORM(COCOA)
+    sessionCreationParameters.httpProxy = URL(URL(), parameters.httpProxy);
+    sessionCreationParameters.httpsProxy = URL(URL(), parameters.httpsProxy);
+#endif
+    SessionTracker::setSession(PAL::SessionID::defaultSessionID(), NetworkSession::create(WTFMove(sessionCreationParameters)));
 
 #if ENABLE(INDEXED_DATABASE)
     addIndexedDatabaseSession(PAL::SessionID::defaultSessionID(), parameters.indexedDatabaseDirectory, parameters.indexedDatabaseDirectoryExtensionHandle);
index b5a4484..2cb6190 100644 (file)
@@ -42,7 +42,7 @@ NetworkSessionCreationParameters NetworkSessionCreationParameters::privateSessio
 {
     return { sessionID, { }, AllowsCellularAccess::Yes
 #if PLATFORM(COCOA)
-        , { }, { }, { }, false, { }
+        , { }, { }, { }, false, { }, { }, { }
 #endif
 #if USE(CURL)
         , { }
@@ -61,6 +61,8 @@ void NetworkSessionCreationParameters::encode(IPC::Encoder& encoder) const
     encoder << sourceApplicationSecondaryIdentifier;
     encoder << shouldLogCookieInformation;
     encoder << loadThrottleLatency;
+    encoder << httpProxy;
+    encoder << httpsProxy;
 #endif
 #if USE(CURL)
     encoder << proxySettings;
@@ -107,6 +109,16 @@ std::optional<NetworkSessionCreationParameters> NetworkSessionCreationParameters
     decoder >> loadThrottleLatency;
     if (!loadThrottleLatency)
         return std::nullopt;
+    
+    std::optional<URL> httpProxy;
+    decoder >> httpProxy;
+    if (!httpProxy)
+        return std::nullopt;
+
+    std::optional<URL> httpsProxy;
+    decoder >> httpsProxy;
+    if (!httpsProxy)
+        return std::nullopt;
 #endif
     
 #if USE(CURL)
@@ -126,6 +138,8 @@ std::optional<NetworkSessionCreationParameters> NetworkSessionCreationParameters
         , WTFMove(*sourceApplicationSecondaryIdentifier)
         , WTFMove(*shouldLogCookieInformation)
         , WTFMove(*loadThrottleLatency)
+        , WTFMove(*httpProxy)
+        , WTFMove(*httpsProxy)
 #endif
 #if USE(CURL)
         , WTFMove(*proxySettings)
index 27ce7b8..3227f7c 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <pal/SessionID.h>
 #include <wtf/Seconds.h>
+#include <wtf/URL.h>
 #include <wtf/text/WTFString.h>
 
 #if USE(CURL)
@@ -38,6 +39,11 @@ class Encoder;
 class Decoder;
 }
 
+#if PLATFORM(COCOA)
+extern "C" CFStringRef const WebKit2HTTPProxyDefaultsKey;
+extern "C" CFStringRef const WebKit2HTTPSProxyDefaultsKey;
+#endif
+    
 namespace WebKit {
 
 enum class AllowsCellularAccess : bool { No, Yes };
@@ -56,6 +62,8 @@ struct NetworkSessionCreationParameters {
     String sourceApplicationSecondaryIdentifier;
     bool shouldLogCookieInformation { false };
     Seconds loadThrottleLatency;
+    URL httpProxy;
+    URL httpsProxy;
 #endif
 #if USE(CURL)
     WebCore::CurlProxySettings proxySettings;
index 65ff761..e4ff173 100644 (file)
@@ -55,6 +55,9 @@
 
 using namespace WebKit;
 
+CFStringRef const WebKit2HTTPProxyDefaultsKey = static_cast<CFStringRef>(@"WebKit2HTTPProxy");
+CFStringRef const WebKit2HTTPSProxyDefaultsKey = static_cast<CFStringRef>(@"WebKit2HTTPSProxy");
+
 static NSURLSessionResponseDisposition toNSURLSessionResponseDisposition(WebCore::PolicyAction disposition)
 {
     switch (disposition) {
@@ -601,6 +604,29 @@ Ref<NetworkSession> NetworkSessionCocoa::create(NetworkSessionCreationParameters
     return adoptRef(*new NetworkSessionCocoa(WTFMove(parameters)));
 }
 
+static NSDictionary *proxyDictionary(const URL& httpProxy, const URL& httpsProxy)
+{
+    if (!httpProxy.isValid() && !httpsProxy.isValid())
+        return nil;
+
+    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
+
+    NSMutableDictionary *dictionary = [[[NSMutableDictionary alloc] init] autorelease];
+    if (httpProxy.isValid()) {
+        [dictionary setObject:httpProxy.host().toString() forKey:(NSString *)kCFStreamPropertyHTTPProxyHost];
+        if (auto port = httpProxy.port())
+            [dictionary setObject:@(*port) forKey:(NSString *)kCFStreamPropertyHTTPProxyPort];
+    }
+    if (httpsProxy.isValid()) {
+        [dictionary setObject:httpsProxy.host().toString() forKey:(NSString *)kCFStreamPropertyHTTPSProxyHost];
+        if (auto port = httpsProxy.port())
+            [dictionary setObject:@(*port) forKey:(NSString *)kCFStreamPropertyHTTPSProxyPort];
+    }
+    return dictionary;
+
+    ALLOW_DEPRECATED_DECLARATIONS_END
+}
+
 NetworkSessionCocoa::NetworkSessionCocoa(NetworkSessionCreationParameters&& parameters)
     : NetworkSession(parameters.sessionID)
     , m_boundInterfaceIdentifier(parameters.boundInterfaceIdentifier)
@@ -640,6 +666,8 @@ NetworkSessionCocoa::NetworkSessionCocoa(NetworkSessionCreationParameters&& para
     if (!parameters.sourceApplicationSecondaryIdentifier.isEmpty())
         configuration._sourceApplicationSecondaryIdentifier = parameters.sourceApplicationSecondaryIdentifier;
 
+    configuration.connectionProxyDictionary = proxyDictionary(parameters.httpProxy, parameters.httpsProxy);
+
 #if PLATFORM(IOS_FAMILY)
     auto& ctDataConnectionServiceType = globalCTDataConnectionServiceType();
     if (!ctDataConnectionServiceType.isEmpty())
index 2ae235c..37f3b7f 100644 (file)
@@ -64,41 +64,6 @@ void NetworkProcess::initializeProcessName(const ChildProcessInitializationParam
 #endif
 }
 
-static void overrideSystemProxies(const String& httpProxy, const String& httpsProxy)
-{
-    NSMutableDictionary *proxySettings = [NSMutableDictionary dictionary];
-
-    if (!httpProxy.isNull()) {
-        URL httpProxyURL(URL(), httpProxy);
-        if (httpProxyURL.isValid()) {
-            [proxySettings setObject:nsStringFromWebCoreString(httpProxyURL.host().toString()) forKey:(NSString *)kCFNetworkProxiesHTTPProxy];
-            if (httpProxyURL.port()) {
-                NSNumber *port = [NSNumber numberWithInt:httpProxyURL.port().value()];
-                [proxySettings setObject:port forKey:(NSString *)kCFNetworkProxiesHTTPPort];
-            }
-        }
-        else
-            NSLog(@"Malformed HTTP Proxy URL '%s'.  Expected 'http://<hostname>[:<port>]'\n", httpProxy.utf8().data());
-    }
-
-    if (!httpsProxy.isNull()) {
-        URL httpsProxyURL(URL(), httpsProxy);
-        if (httpsProxyURL.isValid()) {
-#if !PLATFORM(IOSMAC)
-            [proxySettings setObject:nsStringFromWebCoreString(httpsProxyURL.host().toString()) forKey:(NSString *)kCFNetworkProxiesHTTPSProxy];
-            if (httpsProxyURL.port()) {
-                NSNumber *port = [NSNumber numberWithInt:httpsProxyURL.port().value()];
-                [proxySettings setObject:port forKey:(NSString *)kCFNetworkProxiesHTTPSPort];
-            }
-#endif
-        } else
-            NSLog(@"Malformed HTTPS Proxy URL '%s'.  Expected 'https://<hostname>[:<port>]'\n", httpsProxy.utf8().data());
-    }
-
-    if ([proxySettings count] > 0)
-        _CFNetworkSetOverrideSystemProxySettings((__bridge CFDictionaryRef)proxySettings);
-}
-
 void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters& parameters)
 {
     platformInitializeNetworkProcessCocoa(parameters);
@@ -107,9 +72,6 @@ void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreati
     // SecItemShim is needed for CFNetwork APIs that query Keychains beneath us.
     initializeSecItemShim(*this);
 #endif
-
-    if (!parameters.httpProxy.isNull() || !parameters.httpsProxy.isNull())
-        overrideSystemProxies(parameters.httpProxy, parameters.httpsProxy);
 }
 
 void NetworkProcess::allowSpecificHTTPSCertificateForHost(const CertificateInfo& certificateInfo, const String& host)
index 74bf659..2d160ea 100644 (file)
@@ -214,6 +214,10 @@ static Vector<WebKit::WebsiteDataRecord> toWebsiteDataRecords(NSArray *dataRecor
         config->setSourceApplicationBundleIdentifier(configuration.sourceApplicationBundleIdentifier);
     if (configuration.sourceApplicationSecondaryIdentifier)
         config->setSourceApplicationSecondaryIdentifier(configuration.sourceApplicationSecondaryIdentifier);
+    if (configuration.httpProxy)
+        config->setHTTPProxy(configuration.httpProxy);
+    if (configuration.httpsProxy)
+        config->setHTTPSProxy(configuration.httpsProxy);
 
     API::Object::constructInWrapper<API::WebsiteDataStore>(self, WTFMove(config), PAL::SessionID::generatePersistentSessionID());
 
index d08ddac..4ec65cf 100644 (file)
@@ -43,6 +43,8 @@ WK_CLASS_AVAILABLE(macosx(10.13), ios(11.0))
 @property (nonatomic, copy, setter=_setServiceWorkerRegistrationDirectory:) NSURL *_serviceWorkerRegistrationDirectory WK_API_AVAILABLE(macosx(10.13.4), ios(11.3));
 @property (nonatomic, nullable, copy) NSString *sourceApplicationBundleIdentifier WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 @property (nonatomic, nullable, copy) NSString *sourceApplicationSecondaryIdentifier WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic, nullable, copy, setter=setHTTPProxy:) NSURL *httpProxy WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic, nullable, copy, setter=setHTTPSProxy:) NSURL *httpsProxy WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @end
 
index 1747bb1..a9dcd25 100644 (file)
@@ -71,6 +71,26 @@ static void checkURLArgument(NSURL *url)
     _configuration->setWebSQLDatabaseDirectory(url.path);
 }
 
+- (NSURL *)httpProxy
+{
+    return _configuration->httpProxy();
+}
+
+- (void)setHTTPProxy:(NSURL *)proxy
+{
+    _configuration->setHTTPProxy(proxy);
+}
+
+- (NSURL *)httpsProxy
+{
+    return _configuration->httpsProxy();
+}
+
+- (void)setHTTPSProxy:(NSURL *)proxy
+{
+    _configuration->setHTTPSProxy(proxy);
+}
+
 - (NSURL *)_cookieStorageFile
 {
     return [NSURL fileURLWithPath:_configuration->cookieStorageFile() isDirectory:NO];
index d26406b..d70286b 100644 (file)
@@ -69,9 +69,6 @@ NSString *WebKitJSCFTLJITEnabledDefaultsKey = @"WebKitJSCFTLJITEnabledDefaultsKe
 static NSString *WebKitApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification = @"NSApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification";
 #endif
 
-static NSString * const WebKit2HTTPProxyDefaultsKey = @"WebKit2HTTPProxy";
-static NSString * const WebKit2HTTPSProxyDefaultsKey = @"WebKit2HTTPSProxy";
-
 static NSString * const WebKitNetworkCacheEfficacyLoggingEnabledDefaultsKey = @"WebKitNetworkCacheEfficacyLoggingEnabled";
 
 static NSString * const WebKitSuppressMemoryPressureHandlerDefaultsKey = @"WebKitSuppressMemoryPressureHandler";
@@ -259,8 +256,19 @@ void WebProcessPool::platformInitializeNetworkProcess(NetworkProcessCreationPara
 
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 
-    parameters.httpProxy = [defaults stringForKey:WebKit2HTTPProxyDefaultsKey];
-    parameters.httpsProxy = [defaults stringForKey:WebKit2HTTPSProxyDefaultsKey];
+    {
+        bool isSafari = false;
+#if PLATFORM(IOS_FAMILY)
+        isSafari = WebCore::IOSApplication::isMobileSafari();
+#elif PLATFORM(MAC)
+        isSafari = WebCore::MacApplication::isSafari();
+#endif
+        if (isSafari) {
+            parameters.httpProxy = [defaults stringForKey:(NSString *)WebKit2HTTPProxyDefaultsKey];
+            parameters.httpsProxy = [defaults stringForKey:(NSString *)WebKit2HTTPSProxyDefaultsKey];
+        }
+    }
+
     parameters.networkATSContext = adoptCF(_CFNetworkCopyATSContext());
 
     parameters.shouldEnableNetworkCacheEfficacyLogging = [defaults boolForKey:WebKitNetworkCacheEfficacyLoggingEnabledDefaultsKey];
index 4ded753..877edd4 100644 (file)
@@ -31,6 +31,7 @@
 #import "WebResourceLoadStatisticsStore.h"
 #import "WebsiteDataStoreParameters.h"
 #import <WebCore/FileSystem.h>
+#import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/SearchPopupMenuCocoa.h>
 #import <pal/spi/cf/CFNetworkSPI.h>
 #import <wtf/NeverDestroyed.h>
@@ -67,6 +68,21 @@ WebsiteDataStoreParameters WebsiteDataStore::parameters()
     bool shouldLogCookieInformation = false;
 #endif
 
+    URL httpProxy = m_configuration->httpProxy();
+    URL httpsProxy = m_configuration->httpsProxy();
+    
+    bool isSafari = false;
+#if PLATFORM(IOS_FAMILY)
+    isSafari = WebCore::IOSApplication::isMobileSafari();
+#elif PLATFORM(MAC)
+    isSafari = WebCore::MacApplication::isSafari();
+#endif
+    // FIXME: Remove these once Safari adopts _WKWebsiteDataStoreConfiguration.httpProxy and .httpsProxy.
+    if (!httpProxy.isValid() && isSafari)
+        httpProxy = URL(URL(), [defaults stringForKey:(NSString *)WebKit2HTTPProxyDefaultsKey]);
+    if (!httpsProxy.isValid() && isSafari)
+        httpsProxy = URL(URL(), [defaults stringForKey:(NSString *)WebKit2HTTPSProxyDefaultsKey]);
+
     WebsiteDataStoreParameters parameters;
     parameters.networkSessionParameters = {
         m_sessionID,
@@ -76,7 +92,9 @@ WebsiteDataStoreParameters WebsiteDataStore::parameters()
         m_configuration->sourceApplicationBundleIdentifier(),
         m_configuration->sourceApplicationSecondaryIdentifier(),
         shouldLogCookieInformation,
-        Seconds { [defaults integerForKey:WebKitNetworkLoadThrottleLatencyMillisecondsDefaultsKey] / 1000. }
+        Seconds { [defaults integerForKey:WebKitNetworkLoadThrottleLatencyMillisecondsDefaultsKey] / 1000. },
+        WTFMove(httpProxy),
+        WTFMove(httpsProxy),
     };
 
     auto cookieFile = resolvedCookieStorageFile();
index 3c09ddd..d876733 100644 (file)
@@ -57,6 +57,8 @@ Ref<WebsiteDataStoreConfiguration> WebsiteDataStoreConfiguration::copy()
     copy->m_cookieStorageFile = this->m_cookieStorageFile;
     copy->m_sourceApplicationBundleIdentifier = this->m_sourceApplicationBundleIdentifier;
     copy->m_sourceApplicationSecondaryIdentifier = this->m_sourceApplicationSecondaryIdentifier;
+    copy->m_httpProxy = this->m_httpProxy;
+    copy->m_httpsProxy = this->m_httpsProxy;
 
     return copy;
 }
index ebfaf5f..832c3ec 100644 (file)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "APIObject.h"
+#include <wtf/URL.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebKit {
@@ -87,6 +88,12 @@ public:
     const String& sourceApplicationSecondaryIdentifier() const { return m_sourceApplicationSecondaryIdentifier; }
     void setSourceApplicationSecondaryIdentifier(String&& identifier) { m_sourceApplicationSecondaryIdentifier = WTFMove(identifier); }
 
+    const URL& httpProxy() const { return m_httpProxy; }
+    void setHTTPProxy(URL&& proxy) { m_httpProxy = WTFMove(proxy); }
+
+    const URL& httpsProxy() const { return m_httpsProxy; }
+    void setHTTPSProxy(URL&& proxy) { m_httpsProxy = WTFMove(proxy); }
+
     constexpr static uint64_t defaultCacheStoragePerOriginQuota = 50 * 1024 * 1024;
 
 private:
@@ -110,6 +117,8 @@ private:
     String m_cookieStorageFile;
     String m_sourceApplicationBundleIdentifier;
     String m_sourceApplicationSecondaryIdentifier;
+    URL m_httpProxy;
+    URL m_httpsProxy;
 };
 
 }