Permalink
Browse files

win32: System.set_http_proxy_url complete implementation

  • Loading branch information...
1 parent e1a9b95 commit ea29f7d003a2c298d9b7c588a30efc43e9dd7803 @timashev timashev committed Oct 12, 2012
@@ -484,6 +484,10 @@ HRESULT CRhodesModule::PreMessageLoop(int nShowCmd) throw()
{
if (RHOCONF().isExist("http_proxy_url")) {
parseHttpProxyURI(RHOCONF().getString("http_proxy_url"));
+#if defined(OS_WINDOWS_DESKTOP) || defined(RHODES_EMULATOR)
+ } else {
+ GetAppWindow().setProxy();
+#endif
}
}
@@ -1194,6 +1198,14 @@ void parseHttpProxyURI(const rho::String &http_proxy)
// http://<login>:<passwod>@<host>:<port>
const char *default_port = "8080";
+ if (http_proxy.length() == 0) {
+#if defined(OS_WINDOWS_DESKTOP) || defined(RHODES_EMULATOR)
+ _AtlModule.GetAppWindow().setProxy();
+#else
+ //TODO: implement unsetting proxy for WM/CE
+#endif
+ }
+
if (http_proxy.length() < 8) {
LOG(ERROR) + "invalid http proxy url";
return;
@@ -1295,6 +1307,9 @@ void parseHttpProxyURI(const rho::String &http_proxy)
LOG(INFO) + "HTTP proxy port = " + port;
if (host.length()) {
+#if defined(OS_WINDOWS_DESKTOP) || defined(RHODES_EMULATOR)
+ _AtlModule.GetAppWindow().setProxy(host, port, login, password);
+#endif
RHOCONF().setString ("http_proxy_host", host, false);
if (port.length()){
@@ -42,6 +42,8 @@
#include <QApplication>
#include <QtGui/QAction>
#include <QHash>
+#include <QtNetwork/QNetworkProxy>
+#include <QtNetwork/QNetworkProxyFactory>
#include "qt/rhodes/QtMainWindow.h"
IMPLEMENT_LOGCLASS(CMainWindow,"MainWindow");
@@ -911,3 +913,78 @@ LRESULT CMainWindow::OnDateTimePicker (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
return 0;
}
+
+class CRhodesProxyFactory: public QNetworkProxyFactory
+{
+private:
+ static CRhodesProxyFactory* _instance;
+ QNetworkProxy _proxy;
+ QList<QNetworkProxy>* _proxyList;
+ QList<QNetworkProxy>* _defaultProxyList;
+ bool _useProxy;
+ CRhodesProxyFactory(): QNetworkProxyFactory(), _proxyList(NULL), _useProxy(false)
+ {
+ _defaultProxyList = new QList<QNetworkProxy>();
+ *_defaultProxyList << QNetworkProxy(QNetworkProxy::DefaultProxy);
+ }
+public:
+ static CRhodesProxyFactory* getInstance()
+ {
+ if (_instance == NULL) {
+ _instance = new CRhodesProxyFactory();
+ QNetworkProxyFactory::setUseSystemConfiguration(false);
+ QNetworkProxyFactory::setApplicationProxyFactory(_instance);
+ }
+ return _instance;
+ }
+ virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery& query = QNetworkProxyQuery())
+ {
+ if ((query.peerHostName().compare("localhost", Qt::CaseInsensitive) == 0) ||
+ (query.peerHostName().compare("127.0.0.1") == 0))
+ {
+ return *_defaultProxyList;
+ } else if (_useProxy) {
+ return *_proxyList;
+ } else {
+ return QNetworkProxyFactory::systemProxyForQuery(query);
+ }
+ }
+ void setProxy(QNetworkProxy& proxy)
+ {
+ _useProxy = true;
+ _proxy = proxy;
+ if (_proxyList)
+ delete _proxyList;
+ _proxyList = new QList<QNetworkProxy>();
+ *_proxyList << QNetworkProxy(_proxy);
+ }
+ void unsetProxy()
+ {
+ _useProxy = false;
+ if (_proxyList)
+ delete _proxyList;
+ _proxyList = NULL;
+ }
+};
+CRhodesProxyFactory* CRhodesProxyFactory::_instance = NULL;
+
+void CMainWindow::setProxy(const rho::String& host, const rho::String& port, const rho::String& login, const rho::String& password)
+{
+ if (host.length()) {
+ QNetworkProxy proxy;
+ proxy.setType(QNetworkProxy::HttpCachingProxy);
+ proxy.setHostName(host.c_str());
+ if (port.length())
+ proxy.setPort(atoi(port.c_str()));
+ if (login.length())
+ proxy.setUser(login.c_str());
+ if (password.length())
+ proxy.setPassword(password.c_str());
+ CRhodesProxyFactory::getInstance()->setProxy(proxy);
+ }
+}
+
+void CMainWindow::setProxy()
+{
+ CRhodesProxyFactory::getInstance()->unsetProxy();
+}
@@ -85,6 +85,8 @@ class CMainWindow :
CNativeToolbar& getToolbar(){ return m_toolbar; }
CNativeTabbar& getTabbar(){ return m_tabbar; }
HWND getWebViewHWND(int index);
+ void setProxy();
+ void setProxy(const rho::String& host, const rho::String& port, const rho::String& login, const rho::String& password);
// for 'main_window_closed' System property
static bool mainWindowClosed;

0 comments on commit ea29f7d

Please sign in to comment.