}
};
+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 atom {
}
void SetProxyInIO(net::URLRequestContextGetter* getter,
- const std::string& proxy,
+ const net::ProxyConfig& config,
const base::Closure& callback) {
- net::ProxyConfig config;
- config.proxy_rules().ParseFromString(proxy);
auto proxy_service = getter->GetURLRequestContext()->proxy_service();
proxy_service->ResetConfigService(new net::ProxyConfigServiceFixed(config));
+ // Refetches and applies the new pac script if provided.
+ proxy_service->ForceReloadProxyConfig();
RunCallbackInUI(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) {
auto getter = browser_context_->GetRequestContext();
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) {
class Dictionary;
}
+namespace net {
+class ProxyConfig;
+}
+
namespace atom {
class AtomBrowserContext;
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
void ClearCache(const net::CompletionCallback& callback);
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 EnableNetworkEmulation(const mate::Dictionary& options);
void DisableNetworkEmulation();
* `config` String
* `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>]