Merge pull request #3179 from deepak1556/session_api_patch
session: allow setproxy to use external pac script
This commit is contained in:
commit
6182e4ce81
3 changed files with 31 additions and 7 deletions
|
@ -105,6 +105,24 @@ struct Converter<ClearStorageDataOptions> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Converter<net::ProxyConfig> {
|
||||||
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Value> val,
|
||||||
|
net::ProxyConfig* out) {
|
||||||
|
std::string proxy;
|
||||||
|
if (!ConvertFromV8(isolate, val, &proxy))
|
||||||
|
return false;
|
||||||
|
auto pac_url = GURL(proxy);
|
||||||
|
if (pac_url.is_valid()) {
|
||||||
|
out->set_pac_url(pac_url);
|
||||||
|
} else {
|
||||||
|
out->proxy_rules().ParseFromString(proxy);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -209,12 +227,12 @@ void ClearHttpCacheInIO(
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetProxyInIO(net::URLRequestContextGetter* getter,
|
void SetProxyInIO(net::URLRequestContextGetter* getter,
|
||||||
const std::string& proxy,
|
const net::ProxyConfig& config,
|
||||||
const base::Closure& callback) {
|
const base::Closure& callback) {
|
||||||
net::ProxyConfig config;
|
|
||||||
config.proxy_rules().ParseFromString(proxy);
|
|
||||||
auto proxy_service = getter->GetURLRequestContext()->proxy_service();
|
auto proxy_service = getter->GetURLRequestContext()->proxy_service();
|
||||||
proxy_service->ResetConfigService(new net::ProxyConfigServiceFixed(config));
|
proxy_service->ResetConfigService(new net::ProxyConfigServiceFixed(config));
|
||||||
|
// Refetches and applies the new pac script if provided.
|
||||||
|
proxy_service->ForceReloadProxyConfig();
|
||||||
RunCallbackInUI(callback);
|
RunCallbackInUI(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,11 +305,11 @@ void Session::ClearStorageData(mate::Arguments* args) {
|
||||||
base::Time(), base::Time::Max(), callback);
|
base::Time(), base::Time::Max(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::SetProxy(const std::string& proxy,
|
void Session::SetProxy(const net::ProxyConfig& config,
|
||||||
const base::Closure& callback) {
|
const base::Closure& callback) {
|
||||||
auto getter = browser_context_->GetRequestContext();
|
auto getter = browser_context_->GetRequestContext();
|
||||||
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
||||||
base::Bind(&SetProxyInIO, base::Unretained(getter), proxy, callback));
|
base::Bind(&SetProxyInIO, base::Unretained(getter), config, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::SetDownloadPath(const base::FilePath& path) {
|
void Session::SetDownloadPath(const base::FilePath& path) {
|
||||||
|
|
|
@ -23,6 +23,10 @@ class Arguments;
|
||||||
class Dictionary;
|
class Dictionary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace net {
|
||||||
|
class ProxyConfig;
|
||||||
|
}
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
class AtomBrowserContext;
|
class AtomBrowserContext;
|
||||||
|
@ -64,7 +68,7 @@ class Session: public mate::TrackableObject<Session>,
|
||||||
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
|
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
|
||||||
void ClearCache(const net::CompletionCallback& callback);
|
void ClearCache(const net::CompletionCallback& callback);
|
||||||
void ClearStorageData(mate::Arguments* args);
|
void ClearStorageData(mate::Arguments* args);
|
||||||
void SetProxy(const std::string& proxy, const base::Closure& callback);
|
void SetProxy(const net::ProxyConfig& config, const base::Closure& callback);
|
||||||
void SetDownloadPath(const base::FilePath& path);
|
void SetDownloadPath(const base::FilePath& path);
|
||||||
void EnableNetworkEmulation(const mate::Dictionary& options);
|
void EnableNetworkEmulation(const mate::Dictionary& options);
|
||||||
void DisableNetworkEmulation();
|
void DisableNetworkEmulation();
|
||||||
|
|
|
@ -154,7 +154,9 @@ Clears the data of web storages.
|
||||||
* `config` String
|
* `config` String
|
||||||
* `callback` Function - Called when operation is done.
|
* `callback` Function - Called when operation is done.
|
||||||
|
|
||||||
Parses the `config` indicating which proxies to use for the session.
|
If `config` is a PAC url, it is used directly otherwise
|
||||||
|
`config` is parsed based on the following rules indicating which
|
||||||
|
proxies to use for the session.
|
||||||
|
|
||||||
```
|
```
|
||||||
config = scheme-proxies[";"<scheme-proxies>]
|
config = scheme-proxies[";"<scheme-proxies>]
|
||||||
|
|
Loading…
Reference in a new issue