Title: [139241] trunk/Source/WebKit2
Revision
139241
Author
[email protected]
Date
2013-01-09 14:30:48 -0800 (Wed, 09 Jan 2013)

Log Message

Add user defaults to override system proxy settings for NetworkProcess on Mac
https://bugs.webkit.org/show_bug.cgi?id=104197

Patch by Kiran Muppala <[email protected]> on 2013-01-09
Reviewed by Brady Eidson.

For internal testing and debugging, it is useful to have a defaults write to set the HTTP and HTTPS proxy specific to a
WebKit2 client application and not affect the system proxy settings on Mac.

* NetworkProcess/mac/NetworkProcessMac.mm:
(WebKit::overrideSystemProxies): Add helper method to parse proxy URLs and populate settings dictionary passed
to WKCFNetworkSetOverrideSystemProxySettings.
(WebKit::NetworkProcess::platformInitializeNetworkProcess): Call overrideSystemProxies if process creation parameters for
http proxy or https proxy is set.
* Shared/Network/NetworkProcessCreationParameters.cpp: Add httpProxy and httpsProxy process creation parameters on Mac.
(WebKit::NetworkProcessCreationParameters::encode):
(WebKit::NetworkProcessCreationParameters::decode):
* Shared/Network/NetworkProcessCreationParameters.h:
* UIProcess/mac/WebContextMac.mm:
(WebKit::WebContext::platformInitializeNetworkProcess): Initialize httpProxy and httpsProxy process creation parameters
based on the value of WebKit2HTTPProxyDefaultsKey and WebKit2HTTPSProxyDefaultsKey user default respectively.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (139240 => 139241)


--- trunk/Source/WebKit2/ChangeLog	2013-01-09 22:12:37 UTC (rev 139240)
+++ trunk/Source/WebKit2/ChangeLog	2013-01-09 22:30:48 UTC (rev 139241)
@@ -1,3 +1,26 @@
+2013-01-09  Kiran Muppala  <[email protected]>
+
+        Add user defaults to override system proxy settings for NetworkProcess on Mac
+        https://bugs.webkit.org/show_bug.cgi?id=104197
+
+        Reviewed by Brady Eidson.
+
+        For internal testing and debugging, it is useful to have a defaults write to set the HTTP and HTTPS proxy specific to a
+        WebKit2 client application and not affect the system proxy settings on Mac.
+
+        * NetworkProcess/mac/NetworkProcessMac.mm:
+        (WebKit::overrideSystemProxies): Add helper method to parse proxy URLs and populate settings dictionary passed
+        to WKCFNetworkSetOverrideSystemProxySettings.
+        (WebKit::NetworkProcess::platformInitializeNetworkProcess): Call overrideSystemProxies if process creation parameters for
+        http proxy or https proxy is set.
+        * Shared/Network/NetworkProcessCreationParameters.cpp: Add httpProxy and httpsProxy process creation parameters on Mac.
+        (WebKit::NetworkProcessCreationParameters::encode):
+        (WebKit::NetworkProcessCreationParameters::decode):
+        * Shared/Network/NetworkProcessCreationParameters.h:
+        * UIProcess/mac/WebContextMac.mm:
+        (WebKit::WebContext::platformInitializeNetworkProcess): Initialize httpProxy and httpsProxy process creation parameters
+        based on the value of WebKit2HTTPProxyDefaultsKey and WebKit2HTTPSProxyDefaultsKey user default respectively.
+
 2013-01-09  Alexey Proskuryakov  <[email protected]>
 
         Local builds of NetworkProcess should have a process icon

Modified: trunk/Source/WebKit2/NetworkProcess/mac/NetworkProcessMac.mm (139240 => 139241)


--- trunk/Source/WebKit2/NetworkProcess/mac/NetworkProcessMac.mm	2013-01-09 22:12:37 UTC (rev 139240)
+++ trunk/Source/WebKit2/NetworkProcess/mac/NetworkProcessMac.mm	2013-01-09 22:30:48 UTC (rev 139241)
@@ -31,6 +31,7 @@
 #import "NetworkProcessCreationParameters.h"
 #import "PlatformCertificateInfo.h"
 #import "SandboxExtension.h"
+#import "StringUtilities.h"
 #import <WebCore/FileSystem.h>
 #import <WebCore/LocalizedStrings.h>
 #import <WebKitSystemInterface.h>
@@ -94,6 +95,41 @@
     }
 }
 
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+static void overrideSystemProxies(const String& httpProxy, const String& httpsProxy)
+{
+    NSMutableDictionary *proxySettings = [NSMutableDictionary dictionary];
+
+    if (!httpProxy.isNull()) {
+        KURL httpProxyURL(KURL(), httpProxy);
+        if (httpProxyURL.isValid()) {
+            [proxySettings setObject:nsStringFromWebCoreString(httpProxyURL.host()) forKey:(NSString *)kCFNetworkProxiesHTTPProxy];
+            if (httpProxyURL.hasPort()) {
+                NSNumber *port = [NSNumber numberWithInt:httpProxyURL.port()];
+                [proxySettings setObject:port forKey:(NSString *)kCFNetworkProxiesHTTPPort];
+            }
+        }
+        else
+            NSLog(@"Malformed HTTP Proxy URL '%s'.  Expected 'http://<hostname>[:<port>]'\n", httpProxy.utf8().data());
+    }
+
+    if (!httpsProxy.isNull()) {
+        KURL httpsProxyURL(KURL(), httpsProxy);
+        if (httpsProxyURL.isValid()) {
+            [proxySettings setObject:nsStringFromWebCoreString(httpsProxyURL.host()) forKey:(NSString *)kCFNetworkProxiesHTTPSProxy];
+            if (httpsProxyURL.hasPort()) {
+                NSNumber *port = [NSNumber numberWithInt:httpsProxyURL.port()];
+                [proxySettings setObject:port forKey:(NSString *)kCFNetworkProxiesHTTPSPort];
+            }
+        } else
+            NSLog(@"Malformed HTTPS Proxy URL '%s'.  Expected 'https://<hostname>[:<port>]'\n", httpsProxy.utf8().data());
+    }
+
+    if ([proxySettings count] > 0)
+        WKCFNetworkSetOverrideSystemProxySettings((CFDictionaryRef)proxySettings);
+}
+#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+
 void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters& parameters)
 {
     m_diskCacheDirectory = parameters.diskCacheDirectory;
@@ -110,6 +146,11 @@
 #if USE(SECURITY_FRAMEWORK)
     SecItemShim::shared().initialize(this);
 #endif
+
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+    if (!parameters.httpProxy.isNull() || !parameters.httpsProxy.isNull())
+        overrideSystemProxies(parameters.httpProxy, parameters.httpsProxy);
+#endif
 }
 
 static uint64_t memorySize()

Modified: trunk/Source/WebKit2/Shared/Network/NetworkProcessCreationParameters.cpp (139240 => 139241)


--- trunk/Source/WebKit2/Shared/Network/NetworkProcessCreationParameters.cpp	2013-01-09 22:12:37 UTC (rev 139240)
+++ trunk/Source/WebKit2/Shared/Network/NetworkProcessCreationParameters.cpp	2013-01-09 22:30:48 UTC (rev 139241)
@@ -50,6 +50,8 @@
 #if ENABLE(CUSTOM_PROTOCOLS)
     encoder << urlSchemesRegisteredForCustomProtocols;
 #endif
+    encoder << httpProxy;
+    encoder << httpsProxy;
 #endif
 }
 
@@ -76,6 +78,10 @@
     if (!decoder->decode(result.urlSchemesRegisteredForCustomProtocols))
         return false;
 #endif
+    if (!decoder->decode(result.httpProxy))
+        return false;
+    if (!decoder->decode(result.httpsProxy))
+        return false;
 #endif
 
     return true;

Modified: trunk/Source/WebKit2/Shared/Network/NetworkProcessCreationParameters.h (139240 => 139241)


--- trunk/Source/WebKit2/Shared/Network/NetworkProcessCreationParameters.h	2013-01-09 22:12:37 UTC (rev 139240)
+++ trunk/Source/WebKit2/Shared/Network/NetworkProcessCreationParameters.h	2013-01-09 22:30:48 UTC (rev 139241)
@@ -61,6 +61,9 @@
 #if ENABLE(CUSTOM_PROTOCOLS)
     Vector<String> urlSchemesRegisteredForCustomProtocols;
 #endif
+
+    String httpProxy;
+    String httpsProxy;
 #endif
 };
 

Modified: trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm (139240 => 139241)


--- trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm	2013-01-09 22:12:37 UTC (rev 139240)
+++ trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm	2013-01-09 22:30:48 UTC (rev 139241)
@@ -57,6 +57,9 @@
 // FIXME: <rdar://problem/9138817> - After this "backwards compatibility" radar is removed, this code should be removed to only return an empty String.
 NSString *WebIconDatabaseDirectoryDefaultsKey = @"WebIconDatabaseDirectoryDefaultsKey";
 
+static NSString * const WebKit2HTTPProxyDefaultsKey = @"WebKit2HTTPProxy";
+static NSString * const WebKit2HTTPSProxyDefaultsKey = @"WebKit2HTTPSProxy";
+
 namespace WebKit {
 
 NSString *SchemeForCustomProtocolRegisteredNotificationName = @"WebKitSchemeForCustomProtocolRegisteredNotification";
@@ -155,6 +158,9 @@
 
     for (NSString *scheme in [WKBrowsingContextController customSchemes])
         parameters.urlSchemesRegisteredForCustomProtocols.append(scheme);
+
+    parameters.httpProxy = [[NSUserDefaults standardUserDefaults] stringForKey:WebKit2HTTPProxyDefaultsKey];
+    parameters.httpsProxy = [[NSUserDefaults standardUserDefaults] stringForKey:WebKit2HTTPSProxyDefaultsKey];
 }
 #endif
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to