Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsISystemProxySettings.h"
7 #include "mozilla/ModuleUtils.h"
8 #include "nsIServiceManager.h"
9 #include "nsIURI.h"
10 #include "nsString.h"
11 #include "nsNetUtil.h"
12 #include "nsCOMPtr.h"
13 #include "nspr.h"
15 extern "C" {
16 #include <proxy.h>
17 }
19 class nsUnixSystemProxySettings : public nsISystemProxySettings {
20 public:
21 NS_DECL_THREADSAFE_ISUPPORTS
22 NS_DECL_NSISYSTEMPROXYSETTINGS
24 nsUnixSystemProxySettings() { mProxyFactory = nullptr; }
25 nsresult Init();
27 private:
28 ~nsUnixSystemProxySettings() {
29 if (mProxyFactory)
30 px_proxy_factory_free(mProxyFactory);
31 }
33 pxProxyFactory *mProxyFactory;
34 };
36 NS_IMPL_ISUPPORTS(nsUnixSystemProxySettings, nsISystemProxySettings)
38 NS_IMETHODIMP
39 nsUnixSystemProxySettings::GetMainThreadOnly(bool *aMainThreadOnly)
40 {
41 *aMainThreadOnly = false;
42 return NS_OK;
43 }
45 nsresult
46 nsUnixSystemProxySettings::Init()
47 {
48 return NS_OK;
49 }
51 nsresult
52 nsUnixSystemProxySettings::GetPACURI(nsACString& aResult)
53 {
54 // Make sure we return an empty result.
55 aResult.Truncate();
56 return NS_OK;
57 }
59 nsresult
60 nsUnixSystemProxySettings::GetProxyForURI(const nsACString & aSpec,
61 const nsACString & aScheme,
62 const nsACString & aHost,
63 const int32_t aPort,
64 nsACString & aResult)
65 {
66 nsresult rv;
68 if (!mProxyFactory) {
69 mProxyFactory = px_proxy_factory_new();
70 }
71 NS_ENSURE_TRUE(mProxyFactory, NS_ERROR_NOT_AVAILABLE);
73 char **proxyArray = nullptr;
74 proxyArray = px_proxy_factory_get_proxies(mProxyFactory,
75 PromiseFlatCString(aSpec).get());
76 NS_ENSURE_TRUE(proxyArray, NS_ERROR_NOT_AVAILABLE);
78 // Translate libproxy's output to PAC string as expected
79 // libproxy returns an array of proxies in the format:
80 // <procotol>://[username:password@]proxy:port
81 // or
82 // direct://
83 //
84 // PAC format: "PROXY proxy1.foo.com:8080; PROXY proxy2.foo.com:8080; DIRECT"
85 // but nsISystemProxySettings allows "PROXY http://proxy.foo.com:8080" as well.
87 int c = 0;
88 while (proxyArray[c] != nullptr) {
89 if (!aResult.IsEmpty()) {
90 aResult.AppendLiteral("; ");
91 }
93 // figure out the scheme, and we can't use nsIIOService::NewURI because
94 // this is not the main thread.
95 char *colon = strchr (proxyArray[c], ':');
96 uint32_t schemelen = colon ? colon - proxyArray[c] : 0;
97 if (schemelen < 1) {
98 c++;
99 continue;
100 }
102 if (schemelen == 6 && !strncasecmp(proxyArray[c], "direct", 6)) {
103 aResult.AppendLiteral("DIRECT");
104 }
105 else {
106 aResult.AppendLiteral("PROXY ");
107 aResult.Append(proxyArray[c]);
108 }
110 c++;
111 }
113 PR_Free(proxyArray);
114 return NS_OK;
115 }
117 #define NS_UNIXSYSTEMPROXYSERVICE_CID /* 0fa3158c-d5a7-43de-9181-a285e74cf1d4 */\
118 { 0x0fa3158c, 0xd5a7, 0x43de, \
119 {0x91, 0x81, 0xa2, 0x85, 0xe7, 0x4c, 0xf1, 0xd4 } }
121 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsUnixSystemProxySettings, Init)
122 NS_DEFINE_NAMED_CID(NS_UNIXSYSTEMPROXYSERVICE_CID);
124 static const mozilla::Module::CIDEntry kUnixProxyCIDs[] = {
125 { &kNS_UNIXSYSTEMPROXYSERVICE_CID, false, nullptr, nsUnixSystemProxySettingsConstructor },
126 { nullptr }
127 };
129 static const mozilla::Module::ContractIDEntry kUnixProxyContracts[] = {
130 { NS_SYSTEMPROXYSETTINGS_CONTRACTID, &kNS_UNIXSYSTEMPROXYSERVICE_CID },
131 { nullptr }
132 };
134 static const mozilla::Module kUnixProxyModule = {
135 mozilla::Module::kVersion,
136 kUnixProxyCIDs,
137 kUnixProxyContracts
138 };
140 NSMODULE_DEFN(nsUnixProxyModule) = &kUnixProxyModule;