1 From: Wolfgang Rosenauer <wr@rosenauer.org> |
|
2 Subject: Add the option to use libproxy for system proxy settings |
|
3 References: |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=517655 |
|
5 |
|
6 diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in |
|
7 --- a/config/autoconf.mk.in |
|
8 +++ b/config/autoconf.mk.in |
|
9 @@ -541,16 +541,20 @@ FT2_CFLAGS = @FT2_CFLAGS@ |
|
10 FT2_LIBS = @FT2_LIBS@ |
|
11 |
|
12 MOZ_PANGO_CFLAGS = @MOZ_PANGO_CFLAGS@ |
|
13 MOZ_PANGO_LIBS = @MOZ_PANGO_LIBS@ |
|
14 |
|
15 MOZ_XIE_LIBS = @MOZ_XIE_LIBS@ |
|
16 XT_LIBS = @XT_LIBS@ |
|
17 |
|
18 +MOZ_LIBPROXY_CFLAGS = @MOZ_LIBPROXY_CFLAGS@ |
|
19 +MOZ_LIBPROXY_LIBS = @MOZ_LIBPROXY_LIBS@ |
|
20 +MOZ_ENABLE_LIBPROXY = @MOZ_ENABLE_LIBPROXY@ |
|
21 + |
|
22 MOZ_LIBNOTIFY_CFLAGS = @MOZ_LIBNOTIFY_CFLAGS@ |
|
23 MOZ_LIBNOTIFY_LIBS = @MOZ_LIBNOTIFY_LIBS@ |
|
24 MOZ_ENABLE_LIBNOTIFY = @MOZ_ENABLE_LIBNOTIFY@ |
|
25 |
|
26 MOZ_ALSA_LIBS = @MOZ_ALSA_LIBS@ |
|
27 |
|
28 GLIB_CFLAGS = @GLIB_CFLAGS@ |
|
29 GLIB_LIBS = @GLIB_LIBS@ |
|
30 diff --git a/config/system-headers b/config/system-headers |
|
31 --- a/config/system-headers |
|
32 +++ b/config/system-headers |
|
33 @@ -1028,8 +1028,12 @@ gio/gio.h |
|
34 #ifdef MOZ_ENABLE_LIBCONIC |
|
35 conic/conicconnection.h |
|
36 conic/conicconnectionevent.h |
|
37 conic/conicstatisticsevent.h |
|
38 #endif |
|
39 #if MOZ_NATIVE_LIBEVENT==1 |
|
40 event.h |
|
41 #endif |
|
42 +#ifdef MOZ_ENABLE_LIBPROXY |
|
43 +proxy.h |
|
44 +#endif |
|
45 + |
|
46 diff --git a/configure.in b/configure.in |
|
47 --- a/configure.in |
|
48 +++ b/configure.in |
|
49 @@ -5535,16 +5535,39 @@ then |
|
50 fi |
|
51 |
|
52 AC_SUBST(MOZ_ENABLE_GCONF) |
|
53 AC_SUBST(MOZ_GCONF_CFLAGS) |
|
54 AC_SUBST(MOZ_GCONF_LIBS) |
|
55 fi |
|
56 |
|
57 dnl ======================================================== |
|
58 +dnl = libproxy support |
|
59 +dnl ======================================================== |
|
60 + |
|
61 +if test "$MOZ_ENABLE_GTK2" |
|
62 +then |
|
63 + MOZ_ENABLE_LIBPROXY= |
|
64 + |
|
65 + MOZ_ARG_ENABLE_BOOL(libproxy, |
|
66 + [ --enable-libproxy Enable libproxy support ], |
|
67 + MOZ_ENABLE_LIBPROXY=1, |
|
68 + MOZ_ENABLE_LIBPROXY=) |
|
69 + |
|
70 + if test "$MOZ_ENABLE_LIBPROXY" |
|
71 + then |
|
72 + PKG_CHECK_MODULES(MOZ_LIBPROXY, libproxy-1.0) |
|
73 + AC_DEFINE(MOZ_ENABLE_LIBPROXY) |
|
74 + fi |
|
75 +fi |
|
76 +AC_SUBST(MOZ_ENABLE_LIBPROXY) |
|
77 +AC_SUBST(MOZ_LIBPROXY_CFLAGS) |
|
78 +AC_SUBST(MOZ_LIBPROXY_LIBS) |
|
79 + |
|
80 +dnl ======================================================== |
|
81 dnl = libnotify support |
|
82 dnl ======================================================== |
|
83 |
|
84 if test "$MOZ_ENABLE_GTK2" |
|
85 then |
|
86 MOZ_ENABLE_LIBNOTIFY=1 |
|
87 |
|
88 MOZ_ARG_DISABLE_BOOL(libnotify, |
|
89 diff --git a/toolkit/library/Makefile.in b/toolkit/library/Makefile.in |
|
90 --- a/toolkit/library/Makefile.in |
|
91 +++ b/toolkit/library/Makefile.in |
|
92 @@ -222,16 +222,20 @@ endif |
|
93 ifdef MOZ_TREE_FREETYPE |
|
94 EXTRA_DSO_LDOPTS += $(FT2_LIBS) |
|
95 endif |
|
96 |
|
97 ifdef MOZ_ENABLE_STARTUP_NOTIFICATION |
|
98 EXTRA_DSO_LDOPTS += $(MOZ_STARTUP_NOTIFICATION_LIBS) |
|
99 endif |
|
100 |
|
101 +ifdef MOZ_ENABLE_LIBPROXY |
|
102 +EXTRA_DSO_LDOPTS += $(MOZ_LIBPROXY_LIBS) |
|
103 +endif |
|
104 + |
|
105 ifeq ($(OS_ARCH),BeOS) |
|
106 EXTRA_DSO_LDOPTS += -lbe -ltracker |
|
107 endif |
|
108 |
|
109 ifeq ($(OS_ARCH),SunOS) |
|
110 EXTRA_DSO_LDOPTS += -lelf -ldemangle |
|
111 endif |
|
112 |
|
113 diff --git a/toolkit/system/unixproxy/Makefile.in b/toolkit/system/unixproxy/Makefile.in |
|
114 --- a/toolkit/system/unixproxy/Makefile.in |
|
115 +++ b/toolkit/system/unixproxy/Makefile.in |
|
116 @@ -15,16 +15,17 @@ |
|
117 # |
|
118 # The Initial Developer of the Original Code is |
|
119 # IBM Corporation. |
|
120 # Portions created by the Initial Developer are Copyright (C) 2004 |
|
121 # the Initial Developer. All Rights Reserved. |
|
122 # |
|
123 # Contributor(s): |
|
124 # Brian Ryner <bryner@brianryner.com> |
|
125 +# Wolfgang Rosenauer <wr@rosenauer.org> |
|
126 # |
|
127 # Alternatively, the contents of this file may be used under the terms of |
|
128 # either the GNU General Public License Version 2 or later (the "GPL"), or |
|
129 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
|
130 # in which case the provisions of the GPL or the LGPL are applicable instead |
|
131 # of those above. If you wish to allow use of your version of this file only |
|
132 # under the terms of either the GPL or the LGPL, and not to allow others to |
|
133 # use your version of this file under the terms of the MPL, indicate your |
|
134 @@ -46,16 +47,30 @@ MODULE = unixproxy |
|
135 LIBRARY_NAME = unixproxy |
|
136 |
|
137 EXPORT_LIBRARY = 1 |
|
138 IS_COMPONENT = 1 |
|
139 MODULE_NAME = nsUnixProxyModule |
|
140 GRE_MODULE = 1 |
|
141 LIBXUL_LIBRARY = 1 |
|
142 |
|
143 +EXTRA_DSO_LDOPTS += \ |
|
144 + $(MOZ_LIBPROXY_LIBS) \ |
|
145 + $(MOZ_COMPONENT_LIBS) \ |
|
146 + $(NULL) |
|
147 |
|
148 -EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS) |
|
149 +ifdef MOZ_ENABLE_LIBPROXY |
|
150 + |
|
151 +CPPSRCS = \ |
|
152 + nsLibProxySettings.cpp \ |
|
153 + $(NULL) |
|
154 + |
|
155 +CXXFLAGS += $(MOZ_LIBPROXY_CFLAGS) |
|
156 + |
|
157 +else # MOZ_ENABLE_LIBPROXY |
|
158 |
|
159 CPPSRCS = \ |
|
160 nsUnixSystemProxySettings.cpp \ |
|
161 $(NULL) |
|
162 |
|
163 +endif # MOZ_ENABLE_LIBPROXY |
|
164 + |
|
165 include $(topsrcdir)/config/rules.mk |
|
166 diff --git a/toolkit/system/unixproxy/nsLibProxySettings.cpp b/toolkit/system/unixproxy/nsLibProxySettings.cpp |
|
167 new file mode 100644 |
|
168 --- /dev/null |
|
169 +++ b/toolkit/system/unixproxy/nsLibProxySettings.cpp |
|
170 @@ -0,0 +1,178 @@ |
|
171 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
172 +/* ***** BEGIN LICENSE BLOCK ***** |
|
173 + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
|
174 + * |
|
175 + * The contents of this file are subject to the Mozilla Public License Version |
|
176 + * 1.1 (the "License"); you may not use this file except in compliance with |
|
177 + * the License. You may obtain a copy of the License at |
|
178 + * http://www.mozilla.org/MPL/ |
|
179 + * |
|
180 + * Software distributed under the License is distributed on an "AS IS" basis, |
|
181 + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
|
182 + * for the specific language governing rights and limitations under the |
|
183 + * License. |
|
184 + * |
|
185 + * The Original Code is Mozilla libproxy integration code. |
|
186 + * |
|
187 + * The Initial Developer of the Original Code is |
|
188 + * Wolfgang Rosenauer <wr@rosenauer.org>. |
|
189 + * Portions created by the Initial Developer are Copyright (C) 2010 |
|
190 + * the Initial Developer. All Rights Reserved. |
|
191 + * |
|
192 + * Contributor(s): |
|
193 + * |
|
194 + * Alternatively, the contents of this file may be used under the terms of |
|
195 + * either the GNU General Public License Version 2 or later (the "GPL"), or |
|
196 + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
|
197 + * in which case the provisions of the GPL or the LGPL are applicable instead |
|
198 + * of those above. If you wish to allow use of your version of this file only |
|
199 + * under the terms of either the GPL or the LGPL, and not to allow others to |
|
200 + * use your version of this file under the terms of the MPL, indicate your |
|
201 + * decision by deleting the provisions above and replace them with the notice |
|
202 + * and other provisions required by the GPL or the LGPL. If you do not delete |
|
203 + * the provisions above, a recipient may use your version of this file under |
|
204 + * the terms of any one of the MPL, the GPL or the LGPL. |
|
205 + * |
|
206 + * ***** END LICENSE BLOCK ***** */ |
|
207 + |
|
208 +#include "nsISystemProxySettings.h" |
|
209 +#include "mozilla/ModuleUtils.h" |
|
210 +#include "nsIServiceManager.h" |
|
211 +#include "nsIIOService.h" |
|
212 +#include "nsIURI.h" |
|
213 +#include "nsString.h" |
|
214 +#include "nsNetUtil.h" |
|
215 +#include "nsCOMPtr.h" |
|
216 +#include "nspr.h" |
|
217 + |
|
218 +#include <proxy.h> |
|
219 + |
|
220 +class nsUnixSystemProxySettings : public nsISystemProxySettings { |
|
221 +public: |
|
222 + NS_DECL_ISUPPORTS |
|
223 + NS_DECL_NSISYSTEMPROXYSETTINGS |
|
224 + |
|
225 + nsUnixSystemProxySettings() { mProxyFactory = nsnull; } |
|
226 + nsresult Init(); |
|
227 + |
|
228 +private: |
|
229 + ~nsUnixSystemProxySettings() { |
|
230 + if (mProxyFactory) |
|
231 + px_proxy_factory_free(mProxyFactory); |
|
232 + } |
|
233 + |
|
234 + pxProxyFactory *mProxyFactory; |
|
235 +}; |
|
236 + |
|
237 +NS_IMPL_ISUPPORTS1(nsUnixSystemProxySettings, nsISystemProxySettings) |
|
238 + |
|
239 +nsresult |
|
240 +nsUnixSystemProxySettings::Init() |
|
241 +{ |
|
242 + return NS_OK; |
|
243 +} |
|
244 + |
|
245 +nsresult |
|
246 +nsUnixSystemProxySettings::GetPACURI(nsACString& aResult) |
|
247 +{ |
|
248 + // Make sure we return an empty result. |
|
249 + aResult.Truncate(); |
|
250 + return NS_OK; |
|
251 +} |
|
252 + |
|
253 +nsresult |
|
254 +nsUnixSystemProxySettings::GetProxyForURI(nsIURI* aURI, nsACString& aResult) |
|
255 +{ |
|
256 + nsresult rv; |
|
257 + |
|
258 + if (!mProxyFactory) { |
|
259 + mProxyFactory = px_proxy_factory_new(); |
|
260 + } |
|
261 + NS_ENSURE_TRUE(mProxyFactory, NS_ERROR_NOT_AVAILABLE); |
|
262 + |
|
263 + nsCOMPtr<nsIIOService> ios = do_GetIOService(&rv); |
|
264 + NS_ENSURE_SUCCESS(rv, rv); |
|
265 + |
|
266 + nsCAutoString spec; |
|
267 + rv = aURI->GetSpec(spec); |
|
268 + NS_ENSURE_SUCCESS(rv, rv); |
|
269 + |
|
270 + char **proxyArray = nsnull; |
|
271 + proxyArray = px_proxy_factory_get_proxies(mProxyFactory, (char*)(spec.get())); |
|
272 + NS_ENSURE_TRUE(proxyArray, NS_ERROR_NOT_AVAILABLE); |
|
273 + |
|
274 + // Translate libproxy's output to PAC string as expected |
|
275 + // libproxy returns an array of proxies in the format: |
|
276 + // <procotol>://[username:password@]proxy:port |
|
277 + // or |
|
278 + // direct:// |
|
279 + // |
|
280 + // PAC format: "PROXY proxy1.foo.com:8080; PROXY proxy2.foo.com:8080; DIRECT" |
|
281 + int c = 0; |
|
282 + while (proxyArray[c] != NULL) { |
|
283 + if (!aResult.IsEmpty()) { |
|
284 + aResult.AppendLiteral("; "); |
|
285 + } |
|
286 + |
|
287 + PRBool isScheme = PR_FALSE; |
|
288 + nsXPIDLCString schemeString; |
|
289 + nsXPIDLCString hostPortString; |
|
290 + nsCOMPtr<nsIURI> proxyURI; |
|
291 + |
|
292 + rv = ios->NewURI(nsDependentCString(proxyArray[c]), |
|
293 + nsnull, |
|
294 + nsnull, |
|
295 + getter_AddRefs(proxyURI)); |
|
296 + if (NS_FAILED(rv)) { |
|
297 + c++; |
|
298 + continue; |
|
299 + } |
|
300 + |
|
301 + proxyURI->GetScheme(schemeString); |
|
302 + if (NS_SUCCEEDED(proxyURI->SchemeIs("http", &isScheme)) && isScheme) { |
|
303 + schemeString.AssignLiteral("proxy"); |
|
304 + } |
|
305 + aResult.Append(schemeString); |
|
306 + if (NS_SUCCEEDED(proxyURI->SchemeIs("direct", &isScheme)) && !isScheme) { |
|
307 + // Add the proxy URI only if it's not DIRECT |
|
308 + proxyURI->GetHostPort(hostPortString); |
|
309 + aResult.AppendLiteral(" "); |
|
310 + aResult.Append(hostPortString); |
|
311 + } |
|
312 + |
|
313 + c++; |
|
314 + } |
|
315 + |
|
316 +#ifdef DEBUG |
|
317 + printf("returned PAC proxy string: %s\n", PromiseFlatCString(aResult).get()); |
|
318 +#endif |
|
319 + |
|
320 + PR_Free(proxyArray); |
|
321 + return NS_OK; |
|
322 +} |
|
323 + |
|
324 +#define NS_UNIXSYSTEMPROXYSERVICE_CID /* 0fa3158c-d5a7-43de-9181-a285e74cf1d4 */\ |
|
325 + { 0x0fa3158c, 0xd5a7, 0x43de, \ |
|
326 + {0x91, 0x81, 0xa2, 0x85, 0xe7, 0x4c, 0xf1, 0xd4 } } |
|
327 + |
|
328 +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsUnixSystemProxySettings, Init) |
|
329 +NS_DEFINE_NAMED_CID(NS_UNIXSYSTEMPROXYSERVICE_CID); |
|
330 + |
|
331 +static const mozilla::Module::CIDEntry kUnixProxyCIDs[] = { |
|
332 + { &kNS_UNIXSYSTEMPROXYSERVICE_CID, false, NULL, nsUnixSystemProxySettingsConstructor }, |
|
333 + { NULL } |
|
334 +}; |
|
335 + |
|
336 +static const mozilla::Module::ContractIDEntry kUnixProxyContracts[] = { |
|
337 + { NS_SYSTEMPROXYSETTINGS_CONTRACTID, &kNS_UNIXSYSTEMPROXYSERVICE_CID }, |
|
338 + { NULL } |
|
339 +}; |
|
340 + |
|
341 +static const mozilla::Module kUnixProxyModule = { |
|
342 + mozilla::Module::kVersion, |
|
343 + kUnixProxyCIDs, |
|
344 + kUnixProxyContracts |
|
345 +}; |
|
346 + |
|
347 +NSMODULE_DEFN(nsUnixProxyModule) = &kUnixProxyModule; |
|
348 + |
|