Changeset 239023 in webkit


Ignore:
Timestamp:
Dec 9, 2018 5:56:16 PM (5 years ago)
Author:
sbarati@apple.com
Message:

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.

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):

Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/PAL/ChangeLog

    r238913 r239023  
     12018-12-09  Saam barati  <sbarati@apple.com>
     2
     3        Enable HTTP and HTTPS proxies on iOS and make it a property of the NSURLSession
     4        https://bugs.webkit.org/show_bug.cgi?id=192374
     5        <rdar://problem/46506286>
     6
     7        Reviewed by Alex Christensen.
     8
     9        * pal/spi/cf/CFNetworkSPI.h:
     10        Remove the now-unused SPI declaration.
     11
    1122018-12-05  Don Olmstead  <don.olmstead@sony.com>
    213
  • trunk/Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h

    r238785 r239023  
    3434
    3535#include <CFNetwork/CFHTTPCookiesPriv.h>
     36#include <CFNetwork/CFHTTPStream.h>
    3637#include <CFNetwork/CFProxySupportPriv.h>
    3738#include <CFNetwork/CFURLCachePriv.h>
     
    266267void CFHTTPCookieStorageRemoveObserver(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef, CFHTTPCookieStorageChangedProcPtr, void*);
    267268
    268 void _CFNetworkSetOverrideSystemProxySettings(CFDictionaryRef);
    269269CFURLCredentialStorageRef CFURLCredentialStorageCreate(CFAllocatorRef);
    270270CFURLCredentialRef CFURLCredentialStorageCopyDefaultCredentialForProtectionSpace(CFURLCredentialStorageRef, CFURLProtectionSpaceRef);
  • trunk/Source/WebKit/ChangeLog

    r239022 r239023  
     12018-12-09  Saam barati  <sbarati@apple.com>
     2
     3        Enable HTTP and HTTPS proxies on iOS and make it a property of the NSURLSession
     4        https://bugs.webkit.org/show_bug.cgi?id=192374
     5        <rdar://problem/46506286>
     6
     7        Reviewed by Alex Christensen.
     8
     9        This patch makes it so that we can use HTTP/HTTPS proxies on iOS as well.
     10        To enable on iOS, you can do something like:
     11        $ defaults write -g WebKit2HTTPProxy -string "http://localhost:8080"
     12        $ defaults write -g WebKit2HTTPSProxy -string "http://localhost:8080"
     13       
     14        This patch also changes the Proxy to be enabled on a per NSURLSession
     15        basis instead of a per process basis.
     16
     17        * NetworkProcess/NetworkProcess.cpp:
     18        (WebKit::NetworkProcess::initializeNetworkProcess):
     19        * NetworkProcess/NetworkSessionCreationParameters.cpp:
     20        (WebKit::NetworkSessionCreationParameters::privateSessionParameters):
     21        (WebKit::NetworkSessionCreationParameters::encode const):
     22        (WebKit::NetworkSessionCreationParameters::decode):
     23        * NetworkProcess/NetworkSessionCreationParameters.h:
     24        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
     25        (WebKit::proxyDictionary):
     26        (WebKit::NetworkSessionCocoa::NetworkSessionCocoa):
     27        * NetworkProcess/mac/NetworkProcessMac.mm:
     28        (WebKit::NetworkProcess::platformInitializeNetworkProcess):
     29        (WebKit::overrideSystemProxies): Deleted.
     30        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
     31        (-[WKWebsiteDataStore _initWithConfiguration:]):
     32        * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
     33        * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm:
     34        (-[_WKWebsiteDataStoreConfiguration httpProxy]):
     35        (-[_WKWebsiteDataStoreConfiguration setHTTPProxy:]):
     36        (-[_WKWebsiteDataStoreConfiguration httpsProxy]):
     37        (-[_WKWebsiteDataStoreConfiguration setHTTPSProxy:]):
     38        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
     39        (WebKit::WebProcessPool::platformInitializeNetworkProcess):
     40        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
     41        (WebKit::WebsiteDataStore::parameters):
     42        * UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp:
     43        (WebKit::WebsiteDataStoreConfiguration::copy):
     44        * UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h:
     45        (WebKit::WebsiteDataStoreConfiguration::httpProxy const):
     46        (WebKit::WebsiteDataStoreConfiguration::setHTTPProxy):
     47        (WebKit::WebsiteDataStoreConfiguration::httpsProxy const):
     48        (WebKit::WebsiteDataStoreConfiguration::setHTTPSProxy):
     49
    1502018-12-09  Adrian Perez de Castro  <aperez@igalia.com>
    251
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r239007 r239023  
    300300        NetworkStorageSession::switchToNewTestingSession();
    301301
    302     SessionTracker::setSession(PAL::SessionID::defaultSessionID(), NetworkSession::create(NetworkSessionCreationParameters()));
     302    NetworkSessionCreationParameters sessionCreationParameters { };
     303#if PLATFORM(COCOA)
     304    sessionCreationParameters.httpProxy = URL(URL(), parameters.httpProxy);
     305    sessionCreationParameters.httpsProxy = URL(URL(), parameters.httpsProxy);
     306#endif
     307    SessionTracker::setSession(PAL::SessionID::defaultSessionID(), NetworkSession::create(WTFMove(sessionCreationParameters)));
    303308
    304309#if ENABLE(INDEXED_DATABASE)
  • trunk/Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.cpp

    r238654 r239023  
    4343    return { sessionID, { }, AllowsCellularAccess::Yes
    4444#if PLATFORM(COCOA)
    45         , { }, { }, { }, false, { }
     45        , { }, { }, { }, false, { }, { }, { }
    4646#endif
    4747#if USE(CURL)
     
    6262    encoder << shouldLogCookieInformation;
    6363    encoder << loadThrottleLatency;
     64    encoder << httpProxy;
     65    encoder << httpsProxy;
    6466#endif
    6567#if USE(CURL)
     
    108110    if (!loadThrottleLatency)
    109111        return std::nullopt;
     112   
     113    std::optional<URL> httpProxy;
     114    decoder >> httpProxy;
     115    if (!httpProxy)
     116        return std::nullopt;
     117
     118    std::optional<URL> httpsProxy;
     119    decoder >> httpsProxy;
     120    if (!httpsProxy)
     121        return std::nullopt;
    110122#endif
    111123   
     
    127139        , WTFMove(*shouldLogCookieInformation)
    128140        , WTFMove(*loadThrottleLatency)
     141        , WTFMove(*httpProxy)
     142        , WTFMove(*httpsProxy)
    129143#endif
    130144#if USE(CURL)
  • trunk/Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.h

    r238654 r239023  
    2828#include <pal/SessionID.h>
    2929#include <wtf/Seconds.h>
     30#include <wtf/URL.h>
    3031#include <wtf/text/WTFString.h>
    3132
     
    3940}
    4041
     42#if PLATFORM(COCOA)
     43extern "C" CFStringRef const WebKit2HTTPProxyDefaultsKey;
     44extern "C" CFStringRef const WebKit2HTTPSProxyDefaultsKey;
     45#endif
     46   
    4147namespace WebKit {
    4248
     
    5763    bool shouldLogCookieInformation { false };
    5864    Seconds loadThrottleLatency;
     65    URL httpProxy;
     66    URL httpsProxy;
    5967#endif
    6068#if USE(CURL)
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm

    r238886 r239023  
    5656using namespace WebKit;
    5757
     58CFStringRef const WebKit2HTTPProxyDefaultsKey = static_cast<CFStringRef>(@"WebKit2HTTPProxy");
     59CFStringRef const WebKit2HTTPSProxyDefaultsKey = static_cast<CFStringRef>(@"WebKit2HTTPSProxy");
     60
    5861static NSURLSessionResponseDisposition toNSURLSessionResponseDisposition(WebCore::PolicyAction disposition)
    5962{
     
    605608}
    606609
     610static NSDictionary *proxyDictionary(const URL& httpProxy, const URL& httpsProxy)
     611{
     612    if (!httpProxy.isValid() && !httpsProxy.isValid())
     613        return nil;
     614
     615    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
     616
     617    NSMutableDictionary *dictionary = [[[NSMutableDictionary alloc] init] autorelease];
     618    if (httpProxy.isValid()) {
     619        [dictionary setObject:httpProxy.host().toString() forKey:(NSString *)kCFStreamPropertyHTTPProxyHost];
     620        if (auto port = httpProxy.port())
     621            [dictionary setObject:@(*port) forKey:(NSString *)kCFStreamPropertyHTTPProxyHost];
     622    }
     623    if (httpsProxy.isValid()) {
     624        [dictionary setObject:httpsProxy.host().toString() forKey:(NSString *)kCFStreamPropertyHTTPSProxyHost];
     625        if (auto port = httpsProxy.port())
     626            [dictionary setObject:@(*port) forKey:(NSString *)kCFStreamPropertyHTTPSProxyPort];
     627    }
     628    return dictionary;
     629
     630    ALLOW_DEPRECATED_DECLARATIONS_END
     631}
     632
    607633NetworkSessionCocoa::NetworkSessionCocoa(NetworkSessionCreationParameters&& parameters)
    608634    : NetworkSession(parameters.sessionID)
     
    643669    if (!parameters.sourceApplicationSecondaryIdentifier.isEmpty())
    644670        configuration._sourceApplicationSecondaryIdentifier = parameters.sourceApplicationSecondaryIdentifier;
     671
     672    configuration.connectionProxyDictionary = proxyDictionary(parameters.httpProxy, parameters.httpsProxy);
    645673
    646674#if PLATFORM(IOS_FAMILY)
  • trunk/Source/WebKit/NetworkProcess/mac/NetworkProcessMac.mm

    r236568 r239023  
    6666}
    6767
    68 static void overrideSystemProxies(const String& httpProxy, const String& httpsProxy)
    69 {
    70     NSMutableDictionary *proxySettings = [NSMutableDictionary dictionary];
    71 
    72     if (!httpProxy.isNull()) {
    73         URL httpProxyURL(URL(), httpProxy);
    74         if (httpProxyURL.isValid()) {
    75             [proxySettings setObject:nsStringFromWebCoreString(httpProxyURL.host().toString()) forKey:(NSString *)kCFNetworkProxiesHTTPProxy];
    76             if (httpProxyURL.port()) {
    77                 NSNumber *port = [NSNumber numberWithInt:httpProxyURL.port().value()];
    78                 [proxySettings setObject:port forKey:(NSString *)kCFNetworkProxiesHTTPPort];
    79             }
    80         }
    81         else
    82             NSLog(@"Malformed HTTP Proxy URL '%s'.  Expected 'http://<hostname>[:<port>]'\n", httpProxy.utf8().data());
    83     }
    84 
    85     if (!httpsProxy.isNull()) {
    86         URL httpsProxyURL(URL(), httpsProxy);
    87         if (httpsProxyURL.isValid()) {
    88 #if !PLATFORM(IOSMAC)
    89             [proxySettings setObject:nsStringFromWebCoreString(httpsProxyURL.host().toString()) forKey:(NSString *)kCFNetworkProxiesHTTPSProxy];
    90             if (httpsProxyURL.port()) {
    91                 NSNumber *port = [NSNumber numberWithInt:httpsProxyURL.port().value()];
    92                 [proxySettings setObject:port forKey:(NSString *)kCFNetworkProxiesHTTPSPort];
    93             }
    94 #endif
    95         } else
    96             NSLog(@"Malformed HTTPS Proxy URL '%s'.  Expected 'https://<hostname>[:<port>]'\n", httpsProxy.utf8().data());
    97     }
    98 
    99     if ([proxySettings count] > 0)
    100         _CFNetworkSetOverrideSystemProxySettings((__bridge CFDictionaryRef)proxySettings);
    101 }
    102 
    10368void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters& parameters)
    10469{
     
    10974    initializeSecItemShim(*this);
    11075#endif
    111 
    112     if (!parameters.httpProxy.isNull() || !parameters.httpsProxy.isNull())
    113         overrideSystemProxies(parameters.httpProxy, parameters.httpsProxy);
    11476}
    11577
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm

    r238900 r239023  
    215215    if (configuration.sourceApplicationSecondaryIdentifier)
    216216        config->setSourceApplicationSecondaryIdentifier(configuration.sourceApplicationSecondaryIdentifier);
     217    if (configuration.httpProxy)
     218        config->setHTTPProxy(configuration.httpProxy);
     219    if (configuration.httpsProxy)
     220        config->setHTTPSProxy(configuration.httpsProxy);
    217221
    218222    API::Object::constructInWrapper<API::WebsiteDataStore>(self, WTFMove(config), PAL::SessionID::generatePersistentSessionID());
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h

    r235127 r239023  
    4444@property (nonatomic, nullable, copy) NSString *sourceApplicationBundleIdentifier WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    4545@property (nonatomic, nullable, copy) NSString *sourceApplicationSecondaryIdentifier WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     46@property (nonatomic, nullable, copy, setter=setHTTPProxy:) NSURL *httpProxy WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     47@property (nonatomic, nullable, copy, setter=setHTTPSProxy:) NSURL *httpsProxy WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    4648
    4749@end
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm

    r238900 r239023  
    7070    checkURLArgument(url);
    7171    _configuration->setWebSQLDatabaseDirectory(url.path);
     72}
     73
     74- (NSURL *)httpProxy
     75{
     76    return _configuration->httpProxy();
     77}
     78
     79- (void)setHTTPProxy:(NSURL *)proxy
     80{
     81    _configuration->setHTTPProxy(proxy);
     82}
     83
     84- (NSURL *)httpsProxy
     85{
     86    return _configuration->httpsProxy();
     87}
     88
     89- (void)setHTTPSProxy:(NSURL *)proxy
     90{
     91    _configuration->setHTTPSProxy(proxy);
    7292}
    7393
  • trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm

    r238886 r239023  
    7070#endif
    7171
    72 static NSString * const WebKit2HTTPProxyDefaultsKey = @"WebKit2HTTPProxy";
    73 static NSString * const WebKit2HTTPSProxyDefaultsKey = @"WebKit2HTTPSProxy";
    74 
    7572static NSString * const WebKitNetworkCacheEfficacyLoggingEnabledDefaultsKey = @"WebKitNetworkCacheEfficacyLoggingEnabled";
    7673
     
    260257    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    261258
    262     parameters.httpProxy = [defaults stringForKey:WebKit2HTTPProxyDefaultsKey];
    263     parameters.httpsProxy = [defaults stringForKey:WebKit2HTTPSProxyDefaultsKey];
     259    {
     260        bool isSafari = false;
     261#if PLATFORM(IOS_FAMILY)
     262        isSafari = WebCore::IOSApplication::isMobileSafari();
     263#elif PLATFORM(MAC)
     264        isSafari = WebCore::MacApplication::isSafari();
     265#endif
     266        if (isSafari) {
     267            parameters.httpProxy = [defaults stringForKey:(NSString *)WebKit2HTTPProxyDefaultsKey];
     268            parameters.httpsProxy = [defaults stringForKey:(NSString *)WebKit2HTTPSProxyDefaultsKey];
     269        }
     270    }
     271
    264272    parameters.networkATSContext = adoptCF(_CFNetworkCopyATSContext());
    265273
  • trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm

    r238900 r239023  
    3232#import "WebsiteDataStoreParameters.h"
    3333#import <WebCore/FileSystem.h>
     34#import <WebCore/RuntimeApplicationChecks.h>
    3435#import <WebCore/SearchPopupMenuCocoa.h>
    3536#import <pal/spi/cf/CFNetworkSPI.h>
     
    6869#endif
    6970
     71    URL httpProxy = m_configuration->httpProxy();
     72    URL httpsProxy = m_configuration->httpsProxy();
     73   
     74    bool isSafari = false;
     75#if PLATFORM(IOS_FAMILY)
     76    isSafari = WebCore::IOSApplication::isMobileSafari();
     77#elif PLATFORM(MAC)
     78    isSafari = WebCore::MacApplication::isSafari();
     79#endif
     80    // FIXME: Remove these once Safari adopts _WKWebsiteDataStoreConfiguration.httpProxy and .httpsProxy.
     81    if (!httpProxy.isValid() && isSafari)
     82        httpProxy = URL(URL(), [defaults stringForKey:(NSString *)WebKit2HTTPProxyDefaultsKey]);
     83    if (!httpsProxy.isValid() && isSafari)
     84        httpsProxy = URL(URL(), [defaults stringForKey:(NSString *)WebKit2HTTPSProxyDefaultsKey]);
     85
    7086    WebsiteDataStoreParameters parameters;
    7187    parameters.networkSessionParameters = {
     
    7793        m_configuration->sourceApplicationSecondaryIdentifier(),
    7894        shouldLogCookieInformation,
    79         Seconds { [defaults integerForKey:WebKitNetworkLoadThrottleLatencyMillisecondsDefaultsKey] / 1000. }
     95        Seconds { [defaults integerForKey:WebKitNetworkLoadThrottleLatencyMillisecondsDefaultsKey] / 1000. },
     96        WTFMove(httpProxy),
     97        WTFMove(httpsProxy),
    8098    };
    8199
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp

    r239022 r239023  
    5858    copy->m_sourceApplicationBundleIdentifier = this->m_sourceApplicationBundleIdentifier;
    5959    copy->m_sourceApplicationSecondaryIdentifier = this->m_sourceApplicationSecondaryIdentifier;
     60    copy->m_httpProxy = this->m_httpProxy;
     61    copy->m_httpsProxy = this->m_httpsProxy;
    6062
    6163    return copy;
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h

    r238900 r239023  
    2727
    2828#include "APIObject.h"
     29#include <wtf/URL.h>
    2930#include <wtf/text/WTFString.h>
    3031
     
    8889    void setSourceApplicationSecondaryIdentifier(String&& identifier) { m_sourceApplicationSecondaryIdentifier = WTFMove(identifier); }
    8990
     91    const URL& httpProxy() const { return m_httpProxy; }
     92    void setHTTPProxy(URL&& proxy) { m_httpProxy = WTFMove(proxy); }
     93
     94    const URL& httpsProxy() const { return m_httpsProxy; }
     95    void setHTTPSProxy(URL&& proxy) { m_httpsProxy = WTFMove(proxy); }
     96
    9097    constexpr static uint64_t defaultCacheStoragePerOriginQuota = 50 * 1024 * 1024;
    9198
     
    111118    String m_sourceApplicationBundleIdentifier;
    112119    String m_sourceApplicationSecondaryIdentifier;
     120    URL m_httpProxy;
     121    URL m_httpsProxy;
    113122};
    114123
Note: See TracChangeset for help on using the changeset viewer.