Skip to content

Commit

Permalink
Revert "Fix #916: support pac_url and auto proxy detection"
Browse files Browse the repository at this point in the history
This reverts commit 206df0d.
  • Loading branch information
rogerwang committed Feb 12, 2017
1 parent ca3c108 commit f3d0ed8
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 117 deletions.
5 changes: 2 additions & 3 deletions docs/References/App.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ These 2 functions crashes the browser process and the renderer process respectiv

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").

## App.setProxyConfig(config, pac_url)
## App.setProxyConfig(config)

* `config` `{String}` Proxy rules
* `pac_url` `{String}` PAC url

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/api/nw_app.idl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace nw.App {
static void closeAllWindows();
static void clearCache();
static void clearAppCache(DOMString manifest_url);
static void setProxyConfig(DOMString config, optional DOMString pac_url);
static void setProxyConfig(DOMString config);
[nocompile] static DOMString getProxyForURL(DOMString url);
[nocompile] static void addOriginAccessWhitelistEntry(DOMString sourceOrigin, DOMString destinationProtocol, DOMString destinationHost, boolean allowDestinationSubdomains);
[nocompile] static void removeOriginAccessWhitelistEntry(DOMString sourceOrigin, DOMString destinationProtocol, DOMString destinationHost, boolean allowDestinationSubdomains);
Expand Down
25 changes: 4 additions & 21 deletions src/api/nw_app_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/extensions/devtools_util.h"
#include "chrome/browser/extensions/extension_service.h"
#include "content/nw/src/api/nw_app.h"
#include "content/nw/src/nw_base.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
Expand All @@ -25,8 +24,6 @@
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"

using namespace extensions::nwapi::nw__app;

namespace {
void SetProxyConfigCallback(
base::WaitableEvent* done,
Expand Down Expand Up @@ -153,27 +150,13 @@ NwAppSetProxyConfigFunction::~NwAppSetProxyConfigFunction() {
}

bool NwAppSetProxyConfigFunction::RunNWSync(base::ListValue* response, std::string* error) {
net::ProxyConfig config;
std::unique_ptr<nwapi::nw__app::SetProxyConfig::Params> params(
nwapi::nw__app::SetProxyConfig::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());

std::string pac_url = params->pac_url.get() ? *params->pac_url : "";
if (!pac_url.empty()) {
if (pac_url == "<direct>")
config = net::ProxyConfig::CreateDirect();
else if (pac_url == "<auto>")
config = net::ProxyConfig::CreateAutoDetect();
else
config = net::ProxyConfig::CreateFromCustomPacURL(GURL(pac_url));
} else {
std::string proxy_config;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &proxy_config));
config.proxy_rules().ParseFromString(proxy_config);
}
std::string proxy_config;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &proxy_config));

base::ThreadRestrictions::ScopedAllowWait allow_wait;

net::ProxyConfig config;
config.proxy_rules().ParseFromString(proxy_config);
content::RenderProcessHost* render_process_host = GetSenderWebContents()->GetRenderProcessHost();
net::URLRequestContextGetter* context_getter =
render_process_host->GetStoragePartition()->GetURLRequestContext();
Expand Down
18 changes: 0 additions & 18 deletions test/sanity/app-getproxyforurl/bg.js

This file was deleted.

54 changes: 14 additions & 40 deletions test/sanity/app-getproxyforurl/index.html
Original file line number Diff line number Diff line change
@@ -1,46 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>App.getProxyForURL</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>App.getProxyForURL</title>
</head>
<body>
<button id="pac" onclick="requestPac()">Request pac</button>
<script>
nw.App.setProxyConfig('dummy:8080');
var proxy = nw.App.getProxyForURL('http://www.example.com/');
var expect = 'PROXY dummy:8080';
if (proxy === expect) {
document.write('<h1 id="result">success</h1>');
} else {
document.write('<h1 id="result">failure: expect "' + expect + '" but get ' + proxy +'</h1>');
}

// Reset Proxy
nw.App.setProxyConfig("", "<direct>");

function requestPac() {
nw.App.setProxyConfig('dummy:8080', `http://localhost:${nw.App.manifest.port}/`);

setTimeout(function() {
var proxy = nw.App.getProxyForURL('http://www.port3128.com/');
var expect = 'PROXY localhost:3128';
if (proxy === expect) {
document.write('<h1 id="result2">success</h1>');
} else {
document.write('<h1 id="result2">failure: expect "' + expect + '" but get ' + proxy +'</h1>');
}
var proxy = nw.App.getProxyForURL('http://www.port4040.com/');
var expect = 'PROXY localhost:4040';
if (proxy === expect) {
document.write('<h1 id="result3">success</h1>');
} else {
document.write('<h1 id="result3">failure: expect "' + expect + '" but get ' + proxy +'</h1>');
}
}, 100);
}

</script>
<script>
nw.App.setProxyConfig('dummy:8080');
var proxy = nw.App.getProxyForURL('http://www.example.com/');
var expect = 'PROXY dummy:8080';
if (proxy === expect) {
document.write('<h1 id="result">success</h1>');
} else {
document.write('<h1 id="result">failure: expect "' + expect + '" but get ' + proxy +'</h1>');
}
</script>
</body>
</html>
</html>
4 changes: 4 additions & 0 deletions test/sanity/app-getproxyforurl/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "app-getproxyforurl",
"main": "index.html"
}
35 changes: 1 addition & 34 deletions test/sanity/app-getproxyforurl/test.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,17 @@
import time
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from nw_util import *

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common import utils

test_dir = os.path.dirname(os.path.abspath(__file__))
chrome_options = Options()
chrome_options.add_argument("nwapp=" + test_dir)

port = str(utils.free_port())

pkgjson = '''
{
"name": "app-getproxyforurl",
"main": "index.html",
"bg-script": "bg.js",
"port": "%s"
}
''' % port

with open(os.path.join(test_dir, 'package.json'), 'w') as bg:
bg.write(pkgjson)
chrome_options.add_argument("nwapp=" + os.path.dirname(os.path.abspath(__file__)))

driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
driver.implicitly_wait(2)
time.sleep(1)
try:
print driver.current_url

time.sleep(1)
result = driver.find_element_by_id('result')
print result.get_attribute('innerHTML')
assert("success" in result.get_attribute('innerHTML'))

wait_window_handles(driver, 1)
switch_to_app(driver)
driver.find_element_by_id('pac').click()
wait_window_handles(driver, 1)
result2 = driver.find_element_by_id('result2')
assert("success" in result2.get_attribute('innerHTML'))
wait_window_handles(driver, 1)
result3 = driver.find_element_by_id('result3')
assert("success" in result3.get_attribute('innerHTML'))
finally:
driver.quit()

0 comments on commit f3d0ed8

Please sign in to comment.