|
44 | 44 | #include "content/nw/src/nw_shell.h" |
45 | 45 | #include "content/nw/src/shell_browser_context.h" |
46 | 46 | #include "content/common/view_messages.h" |
| 47 | +#include "content/public/browser/browser_thread.h" |
47 | 48 | #include "content/public/browser/web_contents.h" |
48 | 49 | #include "content/public/browser/render_process_host.h" |
| 50 | +#include "net/proxy/proxy_config.h" |
| 51 | +#include "net/proxy/proxy_config_service_fixed.h" |
| 52 | +#include "net/proxy/proxy_service.h" |
| 53 | +#include "net/url_request/url_request_context.h" |
| 54 | +#include "net/url_request/url_request_context_getter.h" |
49 | 55 |
|
50 | 56 | using base::MessageLoop; |
| 57 | +using content::BrowserThread; |
51 | 58 | using content::Shell; |
52 | 59 | using content::ShellBrowserContext; |
53 | 60 | using content::RenderProcessHost; |
@@ -81,6 +88,17 @@ void GetRenderProcessHosts(std::set<RenderProcessHost*>& rphs) { |
81 | 88 | } |
82 | 89 | } |
83 | 90 |
|
| 91 | +void SetProxyConfigCallback( |
| 92 | + base::WaitableEvent* done, |
| 93 | + net::URLRequestContextGetter* url_request_context_getter, |
| 94 | + const net::ProxyConfig& proxy_config) { |
| 95 | + net::ProxyService* proxy_service = |
| 96 | + url_request_context_getter->GetURLRequestContext()->proxy_service(); |
| 97 | + proxy_service->ResetConfigService( |
| 98 | + new net::ProxyConfigServiceFixed(proxy_config)); |
| 99 | + done->Signal(); |
| 100 | +} |
| 101 | + |
84 | 102 | } // namespace |
85 | 103 |
|
86 | 104 | // static |
@@ -133,16 +151,16 @@ void App::Call(Shell* shell, |
133 | 151 | #if defined(OS_WIN) |
134 | 152 | base::string16 path; |
135 | 153 | arguments.GetString(0, &path); |
136 | | - |
137 | | - base::win::ShortcutProperties props; |
138 | | - base::string16 appID; |
139 | | - if (content::Shell::GetPackage()->root()->GetString("app-id", &appID) == false) |
140 | | - content::Shell::GetPackage()->root()->GetString(switches::kmName, &appID); |
141 | | - const std::wstring appName = base::UTF8ToWide(content::Shell::GetPackage()->GetName()); |
142 | | - props.set_app_id(appID); |
143 | | - |
144 | | - base::FilePath processPath; |
145 | | - PathService::Get(base::FILE_EXE, &processPath); |
| 154 | + |
| 155 | + base::win::ShortcutProperties props; |
| 156 | + base::string16 appID; |
| 157 | + if (content::Shell::GetPackage()->root()->GetString("app-id", &appID) == false) |
| 158 | + content::Shell::GetPackage()->root()->GetString(switches::kmName, &appID); |
| 159 | + const std::wstring appName = base::UTF8ToWide(content::Shell::GetPackage()->GetName()); |
| 160 | + props.set_app_id(appID); |
| 161 | + |
| 162 | + base::FilePath processPath; |
| 163 | + PathService::Get(base::FILE_EXE, &processPath); |
146 | 164 | props.set_target(processPath); |
147 | 165 | result->AppendBoolean(base::win::CreateOrUpdateShortcutLink(base::FilePath(path), props, base::win::SHORTCUT_CREATE_ALWAYS)); |
148 | 166 | #else |
@@ -177,6 +195,11 @@ void App::Call(Shell* shell, |
177 | 195 | GlobalShortcutListener::GetInstance()->UnregisterAccelerator( |
178 | 196 | shortcut->GetAccelerator(), shortcut); |
179 | 197 | return; |
| 198 | + } else if (method == "SetProxyConfig") { |
| 199 | + std::string proxy_config; |
| 200 | + arguments.GetString(0, &proxy_config); |
| 201 | + SetProxyConfig(GetRenderProcessHost(), proxy_config); |
| 202 | + return; |
180 | 203 | } |
181 | 204 |
|
182 | 205 | NOTREACHED() << "Calling unknown sync method " << method << " of App"; |
@@ -266,4 +289,20 @@ void App::ClearCache(content::RenderProcessHost* render_process_host) { |
266 | 289 | render_process_host->GetID()); |
267 | 290 | } |
268 | 291 |
|
| 292 | +void App::SetProxyConfig(content::RenderProcessHost* render_process_host, |
| 293 | + const std::string& proxy_config) { |
| 294 | + net::ProxyConfig config; |
| 295 | + config.proxy_rules().ParseFromString(proxy_config); |
| 296 | + net::URLRequestContextGetter* context_getter = |
| 297 | + render_process_host->GetBrowserContext()-> |
| 298 | + GetRequestContextForRenderProcess(render_process_host->GetID()); |
| 299 | + |
| 300 | + base::WaitableEvent done(false, false); |
| 301 | + BrowserThread::PostTask( |
| 302 | + BrowserThread::IO, FROM_HERE, |
| 303 | + base::Bind(&SetProxyConfigCallback, &done, |
| 304 | + make_scoped_refptr(context_getter), config)); |
| 305 | + done.Wait(); |
| 306 | + |
| 307 | +} |
269 | 308 | } // namespace nwapi |
0 commit comments