2010-11-16 Andreas Kling <kling@webkit.org>
authorandreas.kling@nokia.com <andreas.kling@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Nov 2010 12:06:18 +0000 (12:06 +0000)
committerandreas.kling@nokia.com <andreas.kling@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Nov 2010 12:06:18 +0000 (12:06 +0000)
        Reviewed by Kenneth Rohde Christiansen.

        [Qt][WK2] Get proxy settings from environment (http[s]_proxy)

        If http_proxy and/or https_proxy are set in the environment,
        pass those in to QNetworkAccessManager.

        * WebProcess/qt/WebProcessMainQt.cpp:
        (WebKit::EnvHttpProxyFactory::EnvHttpProxyFactory):
        (WebKit::EnvHttpProxyFactory::initializeFromEnvironment):
        (WebKit::EnvHttpProxyFactory::queryProxy):
        (WebKit::initializeProxy):
        (WebKit::WebProcessMainQt):

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

WebKit2/ChangeLog
WebKit2/WebProcess/qt/WebProcessMainQt.cpp

index d67bb52b592e47a47d92930403ccdadbaa152667..1ce36157289cae4293c5c903d517bda25f0508cf 100644 (file)
@@ -1,3 +1,19 @@
+2010-11-16  Andreas Kling  <kling@webkit.org>
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        [Qt][WK2] Get proxy settings from environment (http[s]_proxy)
+
+        If http_proxy and/or https_proxy are set in the environment,
+        pass those in to QNetworkAccessManager.
+
+        * WebProcess/qt/WebProcessMainQt.cpp:
+        (WebKit::EnvHttpProxyFactory::EnvHttpProxyFactory):
+        (WebKit::EnvHttpProxyFactory::initializeFromEnvironment):
+        (WebKit::EnvHttpProxyFactory::queryProxy):
+        (WebKit::initializeProxy):
+        (WebKit::WebProcessMainQt):
+
 2010-11-16  Andreas Kling  <kling@webkit.org>
 
         Reviewed by Kenneth Rohde Christiansen.
index 36957140ae1e9e31cf7b7b8073cd7866723552b9..cb15c535cef8b3d47419708fc268ee01b0fbe08b 100644 (file)
 #include <wtf/Threading.h>
 
 #include <QApplication>
+#include <QList>
+#include <QNetworkProxyFactory>
 #include <QString>
 #include <QStringList>
+#include <QUrl>
 #include <QtGlobal>
 
 #if USE(MEEGOTOUCH)
@@ -61,6 +64,71 @@ static void sleep(unsigned seconds)
 #endif
 #endif
 
+class EnvHttpProxyFactory : public QNetworkProxyFactory
+{
+public:
+    EnvHttpProxyFactory() { }
+
+    bool initializeFromEnvironment();
+
+    QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery& query = QNetworkProxyQuery());
+
+private:
+    QList<QNetworkProxy> m_httpProxy;
+    QList<QNetworkProxy> m_httpsProxy;
+};
+
+bool EnvHttpProxyFactory::initializeFromEnvironment()
+{
+    bool wasSetByEnvironment = false;
+
+    QUrl proxyUrl = QUrl::fromUserInput(qgetenv("http_proxy"));
+    if (proxyUrl.isValid() && !proxyUrl.host().isEmpty()) {
+        int proxyPort = (proxyUrl.port() > 0) ? proxyUrl.port() : 8080;
+        m_httpProxy << QNetworkProxy(QNetworkProxy::HttpProxy, proxyUrl.host(), proxyPort);
+        wasSetByEnvironment = true;
+    } else
+        m_httpProxy << QNetworkProxy::NoProxy;
+
+    proxyUrl = QUrl::fromUserInput(qgetenv("https_proxy"));
+    if (proxyUrl.isValid() && !proxyUrl.host().isEmpty()) {
+        int proxyPort = (proxyUrl.port() > 0) ? proxyUrl.port() : 8080;
+        m_httpsProxy << QNetworkProxy(QNetworkProxy::HttpProxy, proxyUrl.host(), proxyPort);
+        wasSetByEnvironment = true;
+    } else
+        m_httpsProxy << QNetworkProxy::NoProxy;
+
+    return wasSetByEnvironment;
+}
+
+QList<QNetworkProxy> EnvHttpProxyFactory::queryProxy(const QNetworkProxyQuery& query)
+{
+    QString protocol = query.protocolTag().toLower();
+    if (protocol == QLatin1String("http"))
+        return m_httpProxy;
+    else if (protocol == QLatin1String("https"))
+        return m_httpsProxy;
+
+    QList<QNetworkProxy> proxies;
+    proxies << QNetworkProxy::NoProxy;
+    return proxies;
+}
+
+static void initializeProxy()
+{
+    QList<QNetworkProxy> proxylist = QNetworkProxyFactory::systemProxyForQuery();
+    if (proxylist.count() == 1) {
+        QNetworkProxy proxy = proxylist.first();
+        if (proxy == QNetworkProxy::NoProxy || proxy == QNetworkProxy::DefaultProxy) {
+            EnvHttpProxyFactory* proxyFactory = new EnvHttpProxyFactory();
+            if (proxyFactory->initializeFromEnvironment()) {
+                QNetworkProxyFactory::setApplicationProxyFactory(proxyFactory);
+                return;
+            }
+        }
+    }
+    QNetworkProxyFactory::setUseSystemConfiguration(true);
+}
 
 QWEBKIT_EXPORT int WebProcessMainQt(int argc, char** argv)
 {
@@ -77,6 +145,8 @@ QWEBKIT_EXPORT int WebProcessMainQt(int argc, char** argv)
     new MComponentData(argc, argv);
 #endif
 
+    initializeProxy();
+
     srandom(time(0));
 
     JSC::initializeThreading();