OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/glue/plugins/mozilla_extensions.h" | 5 #include "webkit/glue/plugins/mozilla_extensions.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 #include "net/proxy/proxy_service.h" | |
14 #include "net/proxy/proxy_resolver_winhttp.h" | |
15 #include "third_party/npapi/bindings/npapi.h" | 13 #include "third_party/npapi/bindings/npapi.h" |
16 #include "webkit/glue/webkit_glue.h" | 14 #include "webkit/glue/webkit_glue.h" |
17 #include "webkit/glue/plugins/plugin_instance.h" | 15 #include "webkit/glue/plugins/plugin_instance.h" |
18 | 16 |
19 #define QI_SUPPORTS_IID(iid, iface) \ | 17 #define QI_SUPPORTS_IID(iid, iface) \ |
20 QI_SUPPORTS_IID_(iid, iface::GetIID(), iface) | 18 QI_SUPPORTS_IID_(iid, iface::GetIID(), iface) |
21 | 19 |
22 #define QI_SUPPORTS_IID_(src_iid, iface_iid, iface) \ | 20 #define QI_SUPPORTS_IID_(src_iid, iface_iid, iface) \ |
23 if (iid.Equals(iface_iid)) { \ | 21 if (iid.Equals(iface_iid)) { \ |
24 AddRef(); \ | 22 AddRef(); \ |
25 *result = static_cast<iface*>(this); \ | 23 *result = static_cast<iface*>(this); \ |
26 return NS_OK; \ | 24 return NS_OK; \ |
27 } | 25 } |
28 | 26 |
29 namespace NPAPI | 27 namespace NPAPI |
30 { | 28 { |
31 | 29 |
32 void MozillaExtensionApi::DetachFromInstance() { | 30 void MozillaExtensionApi::DetachFromInstance() { |
33 plugin_instance_ = NULL; | 31 plugin_instance_ = NULL; |
34 } | 32 } |
35 | 33 |
36 bool MozillaExtensionApi::FindProxyForUrl(const char* url, | 34 bool MozillaExtensionApi::FindProxyForUrl(const char* url, |
37 std::string* proxy) { | 35 std::string* proxy) { |
38 bool result = false; | |
39 | |
40 if ((!url) || (!proxy)) { | 36 if ((!url) || (!proxy)) { |
41 NOTREACHED(); | 37 NOTREACHED(); |
42 return result; | 38 return false; |
43 } | 39 } |
44 | 40 |
45 scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::Create(NULL)); | 41 return webkit_glue::FindProxyForUrl(GURL(std::string(url)), proxy); |
46 if (!proxy_service.get()) { | |
47 NOTREACHED(); | |
48 return result; | |
49 } | |
50 | |
51 net::ProxyInfo proxy_info; | |
52 if (proxy_service->ResolveProxy(GURL(std::string(url)), | |
53 &proxy_info, | |
54 NULL, | |
55 NULL) == net::OK) { | |
56 if (!proxy_info.is_direct()) { | |
57 std::string winhttp_proxy = proxy_info.proxy_server(); | |
58 | |
59 // Winhttp returns proxy in the the following format: | |
60 // - HTTP proxy: "111.111.111.111:11" | |
61 // -.SOCKS proxy: "socks=111.111.111.111:11" | |
62 // - Mixed proxy: "http=111.111.111.111:11; socks=222.222.222.222:22" | |
63 // | |
64 // We need to translate this into the following format: | |
65 // i) "DIRECT" -- no proxy | |
66 // ii) "PROXY xxx.xxx.xxx.xxx" -- use proxy | |
67 // iii) "SOCKS xxx.xxx.xxx.xxx" -- use SOCKS | |
68 // iv) Mixed. e.g. "PROXY 111.111.111.111;PROXY 112.112.112.112", | |
69 // "PROXY 111.111.111.111;SOCKS 112.112.112.112".... | |
70 StringToLowerASCII(winhttp_proxy); | |
71 if (std::string::npos == winhttp_proxy.find('=')) { | |
72 // Proxy is in the form: "111.111.111.111:11" | |
73 winhttp_proxy.insert(0, "http "); | |
74 } else { | |
75 // Proxy is in the following form. | |
76 // -.SOCKS proxy: "socks=111.111.111.111:11" | |
77 // - Mixed proxy: "http=111.111.111.111:11; socks=222.222.222.222:22" | |
78 // in this case just replace the '=' with a space | |
79 std::replace_if(winhttp_proxy.begin(), | |
80 winhttp_proxy.end(), | |
81 std::bind2nd(std::equal_to<char>(), '='), ' '); | |
82 } | |
83 | |
84 *proxy = winhttp_proxy; | |
85 result = true; | |
86 } | |
87 } | |
88 | |
89 return result; | |
90 } | 42 } |
91 | 43 |
92 // nsISupports implementation | 44 // nsISupports implementation |
93 NS_IMETHODIMP MozillaExtensionApi::QueryInterface(REFNSIID iid, | 45 NS_IMETHODIMP MozillaExtensionApi::QueryInterface(REFNSIID iid, |
94 void** result) { | 46 void** result) { |
95 static const nsIID knsISupportsIID = NS_ISUPPORTS_IID; | 47 static const nsIID knsISupportsIID = NS_ISUPPORTS_IID; |
96 QI_SUPPORTS_IID_(iid, knsISupportsIID, nsIServiceManager) | 48 QI_SUPPORTS_IID_(iid, knsISupportsIID, nsIServiceManager) |
97 QI_SUPPORTS_IID(iid, nsIServiceManager) | 49 QI_SUPPORTS_IID(iid, nsIServiceManager) |
98 QI_SUPPORTS_IID(iid, nsIPluginManager) | 50 QI_SUPPORTS_IID(iid, nsIPluginManager) |
99 QI_SUPPORTS_IID(iid, nsIPluginManager2) | 51 QI_SUPPORTS_IID(iid, nsIPluginManager2) |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 GURL cookies_url((std::string(url))); | 314 GURL cookies_url((std::string(url))); |
363 webplugin->SetCookie(cookies_url, | 315 webplugin->SetCookie(cookies_url, |
364 cookies_url, | 316 cookies_url, |
365 cookie); | 317 cookie); |
366 return NS_OK; | 318 return NS_OK; |
367 } | 319 } |
368 | 320 |
369 | 321 |
370 } // namespace NPAPI | 322 } // namespace NPAPI |
371 | 323 |
OLD | NEW |