Skip to content

Commit f3d0ed8

Browse files
committed
Revert "Fix nwjs#916: support pac_url and auto proxy detection"
This reverts commit 206df0d.
1 parent ca3c108 commit f3d0ed8

File tree

7 files changed

+26
-117
lines changed

7 files changed

+26
-117
lines changed

docs/References/App.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,11 @@ These 2 functions crashes the browser process and the renderer process respectiv
6262

6363
Query the proxy to be used for loading `url` in DOM. The return value is in the same format used in [PAC](http://en.wikipedia.org/wiki/Proxy_auto-config) (e.g. "DIRECT", "PROXY localhost:8080").
6464

65-
## App.setProxyConfig(config, pac_url)
65+
## App.setProxyConfig(config)
6666

6767
* `config` `{String}` Proxy rules
68-
* `pac_url` `{String}` PAC url
6968

70-
Set the proxy config which the web engine will be used to request network resources or PAC url to detect proxy automatically.
69+
Set the proxy config which the web engine will be used to request network resources.
7170

7271
Rule (copied from [`net/proxy/proxy_config.h`](https://github.com/nwjs/chromium.src/blob/nw13/net/proxy/proxy_config.h))
7372

src/api/nw_app.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace nw.App {
1919
static void closeAllWindows();
2020
static void clearCache();
2121
static void clearAppCache(DOMString manifest_url);
22-
static void setProxyConfig(DOMString config, optional DOMString pac_url);
22+
static void setProxyConfig(DOMString config);
2323
[nocompile] static DOMString getProxyForURL(DOMString url);
2424
[nocompile] static void addOriginAccessWhitelistEntry(DOMString sourceOrigin, DOMString destinationProtocol, DOMString destinationHost, boolean allowDestinationSubdomains);
2525
[nocompile] static void removeOriginAccessWhitelistEntry(DOMString sourceOrigin, DOMString destinationProtocol, DOMString destinationHost, boolean allowDestinationSubdomains);

src/api/nw_app_api.cc

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "chrome/browser/devtools/devtools_window.h"
99
#include "chrome/browser/extensions/devtools_util.h"
1010
#include "chrome/browser/extensions/extension_service.h"
11-
#include "content/nw/src/api/nw_app.h"
1211
#include "content/nw/src/nw_base.h"
1312
#include "content/public/browser/render_process_host.h"
1413
#include "content/public/browser/render_view_host.h"
@@ -25,8 +24,6 @@
2524
#include "net/url_request/url_request_context.h"
2625
#include "net/url_request/url_request_context_getter.h"
2726

28-
using namespace extensions::nwapi::nw__app;
29-
3027
namespace {
3128
void SetProxyConfigCallback(
3229
base::WaitableEvent* done,
@@ -153,27 +150,13 @@ NwAppSetProxyConfigFunction::~NwAppSetProxyConfigFunction() {
153150
}
154151

155152
bool NwAppSetProxyConfigFunction::RunNWSync(base::ListValue* response, std::string* error) {
156-
net::ProxyConfig config;
157-
std::unique_ptr<nwapi::nw__app::SetProxyConfig::Params> params(
158-
nwapi::nw__app::SetProxyConfig::Params::Create(*args_));
159-
EXTENSION_FUNCTION_VALIDATE(params.get());
160-
161-
std::string pac_url = params->pac_url.get() ? *params->pac_url : "";
162-
if (!pac_url.empty()) {
163-
if (pac_url == "<direct>")
164-
config = net::ProxyConfig::CreateDirect();
165-
else if (pac_url == "<auto>")
166-
config = net::ProxyConfig::CreateAutoDetect();
167-
else
168-
config = net::ProxyConfig::CreateFromCustomPacURL(GURL(pac_url));
169-
} else {
170-
std::string proxy_config;
171-
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &proxy_config));
172-
config.proxy_rules().ParseFromString(proxy_config);
173-
}
153+
std::string proxy_config;
154+
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &proxy_config));
174155

175156
base::ThreadRestrictions::ScopedAllowWait allow_wait;
176157

158+
net::ProxyConfig config;
159+
config.proxy_rules().ParseFromString(proxy_config);
177160
content::RenderProcessHost* render_process_host = GetSenderWebContents()->GetRenderProcessHost();
178161
net::URLRequestContextGetter* context_getter =
179162
render_process_host->GetStoragePartition()->GetURLRequestContext();

test/sanity/app-getproxyforurl/bg.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,20 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<meta charset="utf-8">
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6-
<title>App.getProxyForURL</title>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<title>App.getProxyForURL</title>
77
</head>
88
<body>
9-
<button id="pac" onclick="requestPac()">Request pac</button>
10-
<script>
11-
nw.App.setProxyConfig('dummy:8080');
12-
var proxy = nw.App.getProxyForURL('http://www.example.com/');
13-
var expect = 'PROXY dummy:8080';
14-
if (proxy === expect) {
15-
document.write('<h1 id="result">success</h1>');
16-
} else {
17-
document.write('<h1 id="result">failure: expect "' + expect + '" but get ' + proxy +'</h1>');
18-
}
19-
20-
// Reset Proxy
21-
nw.App.setProxyConfig("", "<direct>");
22-
23-
function requestPac() {
24-
nw.App.setProxyConfig('dummy:8080', `http://localhost:${nw.App.manifest.port}/`);
25-
26-
setTimeout(function() {
27-
var proxy = nw.App.getProxyForURL('http://www.port3128.com/');
28-
var expect = 'PROXY localhost:3128';
29-
if (proxy === expect) {
30-
document.write('<h1 id="result2">success</h1>');
31-
} else {
32-
document.write('<h1 id="result2">failure: expect "' + expect + '" but get ' + proxy +'</h1>');
33-
}
34-
var proxy = nw.App.getProxyForURL('http://www.port4040.com/');
35-
var expect = 'PROXY localhost:4040';
36-
if (proxy === expect) {
37-
document.write('<h1 id="result3">success</h1>');
38-
} else {
39-
document.write('<h1 id="result3">failure: expect "' + expect + '" but get ' + proxy +'</h1>');
40-
}
41-
}, 100);
42-
}
43-
44-
</script>
9+
<script>
10+
nw.App.setProxyConfig('dummy:8080');
11+
var proxy = nw.App.getProxyForURL('http://www.example.com/');
12+
var expect = 'PROXY dummy:8080';
13+
if (proxy === expect) {
14+
document.write('<h1 id="result">success</h1>');
15+
} else {
16+
document.write('<h1 id="result">failure: expect "' + expect + '" but get ' + proxy +'</h1>');
17+
}
18+
</script>
4519
</body>
46-
</html>
20+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "app-getproxyforurl",
3+
"main": "index.html"
4+
}
Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,17 @@
11
import time
22
import os
3-
import sys
4-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
5-
from nw_util import *
63

74
from selenium import webdriver
85
from selenium.webdriver.chrome.options import Options
9-
from selenium.webdriver.common import utils
10-
11-
test_dir = os.path.dirname(os.path.abspath(__file__))
126
chrome_options = Options()
13-
chrome_options.add_argument("nwapp=" + test_dir)
14-
15-
port = str(utils.free_port())
16-
17-
pkgjson = '''
18-
{
19-
"name": "app-getproxyforurl",
20-
"main": "index.html",
21-
"bg-script": "bg.js",
22-
"port": "%s"
23-
}
24-
''' % port
25-
26-
with open(os.path.join(test_dir, 'package.json'), 'w') as bg:
27-
bg.write(pkgjson)
7+
chrome_options.add_argument("nwapp=" + os.path.dirname(os.path.abspath(__file__)))
288

299
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
30-
driver.implicitly_wait(2)
31-
time.sleep(1)
3210
try:
3311
print driver.current_url
34-
3512
time.sleep(1)
3613
result = driver.find_element_by_id('result')
3714
print result.get_attribute('innerHTML')
3815
assert("success" in result.get_attribute('innerHTML'))
39-
40-
wait_window_handles(driver, 1)
41-
switch_to_app(driver)
42-
driver.find_element_by_id('pac').click()
43-
wait_window_handles(driver, 1)
44-
result2 = driver.find_element_by_id('result2')
45-
assert("success" in result2.get_attribute('innerHTML'))
46-
wait_window_handles(driver, 1)
47-
result3 = driver.find_element_by_id('result3')
48-
assert("success" in result3.get_attribute('innerHTML'))
4916
finally:
5017
driver.quit()

0 commit comments

Comments
 (0)