Skip to content

Commit c45f686

Browse files
committed
Fix nwjs#916: support pac_url and auto proxy detection
1 parent 98b1ef8 commit c45f686

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/api/app/app.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,10 @@ void App::Call(Shell* shell,
202202
shortcut->GetAccelerator(), shortcut);
203203
return;
204204
} else if (method == "SetProxyConfig") {
205-
std::string proxy_config;
205+
std::string proxy_config, pac_url;
206206
arguments.GetString(0, &proxy_config);
207-
SetProxyConfig(GetRenderProcessHost(), proxy_config);
207+
arguments.GetString(1, &pac_url);
208+
SetProxyConfig(GetRenderProcessHost(), proxy_config, pac_url);
208209
return;
209210
} else if (method == "DoneMenuShow") {
210211
dispatcher_host->quit_run_loop();
@@ -299,9 +300,18 @@ void App::ClearCache(content::RenderProcessHost* render_process_host) {
299300
}
300301

301302
void App::SetProxyConfig(content::RenderProcessHost* render_process_host,
302-
const std::string& proxy_config) {
303+
const std::string& proxy_config,
304+
const std::string& pac_url) {
303305
net::ProxyConfig config;
304-
config.proxy_rules().ParseFromString(proxy_config);
306+
if (!pac_url.empty()) {
307+
if (pac_url == "<direct>")
308+
config = net::ProxyConfig::CreateDirect();
309+
else if (pac_url == "<auto>")
310+
config = net::ProxyConfig::CreateAutoDetect();
311+
else
312+
config = net::ProxyConfig::CreateFromCustomPacURL(GURL(pac_url));
313+
} else
314+
config.proxy_rules().ParseFromString(proxy_config);
305315
net::URLRequestContextGetter* context_getter =
306316
render_process_host->GetBrowserContext()->
307317
GetRequestContextForRenderProcess(render_process_host->GetID());

src/api/app/app.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class App {
6363

6464
static void ClearCache(content::RenderProcessHost* render_view_host);
6565
static void SetProxyConfig(content::RenderProcessHost* render_process_host,
66-
const std::string& proxy_config);
66+
const std::string& proxy_config,
67+
const std::string& pac_url);
6768

6869
private:
6970
App();

src/api/app/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ App.prototype.getProxyForURL = function (url) {
6969
return nw.callStaticMethodSync('App', 'getProxyForURL', [ url ]);
7070
}
7171

72-
App.prototype.setProxyConfig = function (proxy_config) {
73-
return nw.callStaticMethodSync('App', 'SetProxyConfig', [ proxy_config ]);
72+
App.prototype.setProxyConfig = function (proxy_config, pac_url) {
73+
return nw.callStaticMethodSync('App', 'SetProxyConfig', [ proxy_config, pac_url ]);
7474
}
7575

7676
App.prototype.addOriginAccessWhitelistEntry = function(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains) {

0 commit comments

Comments
 (0)