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