diff --git a/extensions/cookie/nsCookieModule.cpp b/extensions/cookie/nsCookieModule.cpp index 365cd20717a4..9a0b2db85435 100644 --- a/extensions/cookie/nsCookieModule.cpp +++ b/extensions/cookie/nsCookieModule.cpp @@ -49,7 +49,7 @@ // Define the constructor function for the objects NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPermissionManager, Init) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPopupWindowManager, Init) -NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCookiePermission, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsCookiePermission) NS_GENERIC_FACTORY_CONSTRUCTOR(nsCookiePromptService) // The list of components we register diff --git a/extensions/cookie/nsCookiePermission.cpp b/extensions/cookie/nsCookiePermission.cpp index 6548d8c6d6fb..fce58b4d8005 100644 --- a/extensions/cookie/nsCookiePermission.cpp +++ b/extensions/cookie/nsCookiePermission.cpp @@ -111,12 +111,15 @@ NS_IMPL_ISUPPORTS2(nsCookiePermission, nsICookiePermission, nsIObserver) -nsresult +bool nsCookiePermission::Init() { + // Initialize nsIPermissionManager and fetch relevant prefs. This is only + // required for some methods on nsICookiePermission, so it should be done + // lazily. nsresult rv; mPermMgr = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) return false; // failure to access the pref service is non-fatal... nsCOMPtr prefBranch = @@ -155,7 +158,7 @@ nsCookiePermission::Init() } } - return NS_OK; + return true; } void @@ -184,6 +187,10 @@ NS_IMETHODIMP nsCookiePermission::SetAccess(nsIURI *aURI, nsCookieAccess aAccess) { + // Lazily initialize ourselves + if (!EnsureInitialized()) + return NS_ERROR_UNEXPECTED; + // // NOTE: nsCookieAccess values conveniently match up with // the permission codes used by nsIPermissionManager. @@ -206,7 +213,11 @@ nsCookiePermission::CanAccess(nsIURI *aURI, return NS_OK; } #endif // MOZ_MAIL_NEWS - + + // Lazily initialize ourselves + if (!EnsureInitialized()) + return NS_ERROR_UNEXPECTED; + // finally, check with permission manager... nsresult rv = mPermMgr->TestPermission(aURI, kPermissionType, (PRUint32 *) aResult); if (NS_SUCCEEDED(rv)) { @@ -244,6 +255,10 @@ nsCookiePermission::CanSetCookie(nsIURI *aURI, *aResult = kDefaultPolicy; + // Lazily initialize ourselves + if (!EnsureInitialized()) + return NS_ERROR_UNEXPECTED; + PRUint32 perm; mPermMgr->TestPermission(aURI, kPermissionType, &perm); switch (perm) { @@ -507,7 +522,7 @@ nsCookiePermission::Observe(nsISupports *aSubject, return NS_OK; } -PRBool +bool nsCookiePermission::InPrivateBrowsing() { PRBool inPrivateBrowsingMode = PR_FALSE; diff --git a/extensions/cookie/nsCookiePermission.h b/extensions/cookie/nsCookiePermission.h index 4addc15f6d97..84421c373292 100644 --- a/extensions/cookie/nsCookiePermission.h +++ b/extensions/cookie/nsCookiePermission.h @@ -62,11 +62,12 @@ public: {} virtual ~nsCookiePermission() {} - nsresult Init(); - void PrefChanged(nsIPrefBranch *, const char *); + bool Init(); + void PrefChanged(nsIPrefBranch *, const char *); private: - PRBool InPrivateBrowsing(); + bool EnsureInitialized() { return mPermMgr != NULL || Init(); }; + bool InPrivateBrowsing(); nsCOMPtr mPermMgr; nsCOMPtr mPBService; diff --git a/ipc/ipdl/Makefile.in b/ipc/ipdl/Makefile.in index 8530f1027327..0dfa95691516 100644 --- a/ipc/ipdl/Makefile.in +++ b/ipc/ipdl/Makefile.in @@ -58,6 +58,7 @@ IPDLDIRS = \ dom/ipc \ netwerk/ipc \ netwerk/protocol/http/src \ + netwerk/cookie/src \ ipc/ipdl/test/cxx \ ipc/testshell \ js/src/ipc \ diff --git a/netwerk/build/nsNetModule.cpp b/netwerk/build/nsNetModule.cpp index fd845ef2ae2c..dcdc335f7c48 100644 --- a/netwerk/build/nsNetModule.cpp +++ b/netwerk/build/nsNetModule.cpp @@ -175,10 +175,10 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsStreamListenerTee) #ifdef NECKO_COOKIES #include "nsCookieService.h" -NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsCookieService, nsCookieService::GetSingleton) +NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsICookieService, + nsCookieService::GetXPCOMSingleton) #endif - /////////////////////////////////////////////////////////////////////////////// #ifdef NECKO_WIFI @@ -1111,13 +1111,13 @@ static const nsModuleComponentInfo gNetModuleInfo[] = { { NS_COOKIEMANAGER_CLASSNAME, NS_COOKIEMANAGER_CID, NS_COOKIEMANAGER_CONTRACTID, - nsCookieServiceConstructor + nsICookieServiceConstructor }, { NS_COOKIESERVICE_CLASSNAME, NS_COOKIESERVICE_CID, NS_COOKIESERVICE_CONTRACTID, - nsCookieServiceConstructor + nsICookieServiceConstructor }, #endif diff --git a/netwerk/cookie/src/CookieServiceChild.cpp b/netwerk/cookie/src/CookieServiceChild.cpp new file mode 100644 index 000000000000..f39e855faa62 --- /dev/null +++ b/netwerk/cookie/src/CookieServiceChild.cpp @@ -0,0 +1,203 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * The Mozilla Foundation . + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Daniel Witte + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "mozilla/net/CookieServiceChild.h" +#include "mozilla/net/NeckoChild.h" +#include "nsIURI.h" + +namespace mozilla { +namespace net { + +static CookieServiceChild *gCookieService; + +CookieServiceChild* +CookieServiceChild::GetSingleton() +{ + if (!gCookieService) + gCookieService = new CookieServiceChild(); + + NS_ADDREF(gCookieService); + return gCookieService; +} + +NS_IMPL_ISUPPORTS1(CookieServiceChild, nsICookieService) + +CookieServiceChild::CookieServiceChild() +{ + NS_ASSERTION(IsNeckoChild(), "not a child process"); + + // This corresponds to Release() in DeallocPCookieService. + NS_ADDREF_THIS(); + + // Create a child PCookieService actor. + NeckoChild::InitNeckoChild(); + gNeckoChild->SendPCookieServiceConstructor(this); + + mPermissionService = do_GetService(NS_COOKIEPERMISSION_CONTRACTID); + if (!mPermissionService) + NS_WARNING("couldn't get nsICookiePermission in child"); +} + +CookieServiceChild::~CookieServiceChild() +{ + gCookieService = nsnull; +} + +void +CookieServiceChild::SerializeURIs(nsIURI *aHostURI, + nsIChannel *aChannel, + nsCString &aHostSpec, + nsCString &aHostCharset, + nsCString &aOriginatingSpec, + nsCString &aOriginatingCharset) +{ + // Serialize the host URI. + // TODO: The cookieservice deals exclusively with ASCII hosts, but not paths. + // We should fix that, and then we can just serialize the spec as ASCII here. + aHostURI->GetSpec(aHostSpec); + aHostURI->GetOriginCharset(aHostCharset); + + // Determine and serialize the originating URI. Failure is acceptable. + if (!mPermissionService) { + NS_WARNING("nsICookiePermission unavailable! Cookie may be rejected"); + return; + } + + nsCOMPtr originatingURI; + mPermissionService->GetOriginatingURI(aChannel, + getter_AddRefs(originatingURI)); + if (originatingURI) { + originatingURI->GetSpec(aOriginatingSpec); + originatingURI->GetOriginCharset(aOriginatingSpec); + } +} + +nsresult +CookieServiceChild::GetCookieStringInternal(nsIURI *aHostURI, + nsIChannel *aChannel, + char **aCookieString, + bool aFromHttp) +{ + NS_ENSURE_ARG(aHostURI); + NS_ENSURE_ARG_POINTER(aCookieString); + + *aCookieString = NULL; + + nsCAutoString hostSpec, hostCharset, originatingSpec, originatingCharset; + SerializeURIs(aHostURI, aChannel, hostSpec, hostCharset, + originatingSpec, originatingCharset); + + // Synchronously call the parent. + nsCAutoString result; + SendGetCookieString(hostSpec, hostCharset, + originatingSpec, originatingCharset, + aFromHttp, &result); + if (!result.IsEmpty()) + *aCookieString = ToNewCString(result); + + return NS_OK; +} + +nsresult +CookieServiceChild::SetCookieStringInternal(nsIURI *aHostURI, + nsIChannel *aChannel, + const char *aCookieString, + const char *aServerTime, + bool aFromHttp) +{ + NS_ENSURE_ARG(aHostURI); + NS_ENSURE_ARG_POINTER(aCookieString); + + nsCAutoString hostSpec, hostCharset, originatingSpec, originatingCharset; + SerializeURIs(aHostURI, aChannel, hostSpec, hostCharset, + originatingSpec, originatingCharset); + + nsDependentCString cookieString(aCookieString); + nsDependentCString serverTime; + if (aServerTime) + serverTime.Rebind(aServerTime); + + // Synchronously call the parent. + SendSetCookieString(hostSpec, hostCharset, + originatingSpec, originatingCharset, + cookieString, serverTime, aFromHttp); + return NS_OK; +} + +NS_IMETHODIMP +CookieServiceChild::GetCookieString(nsIURI *aHostURI, + nsIChannel *aChannel, + char **aCookieString) +{ + return GetCookieStringInternal(aHostURI, aChannel, aCookieString, false); +} + +NS_IMETHODIMP +CookieServiceChild::GetCookieStringFromHttp(nsIURI *aHostURI, + nsIURI *aFirstURI, + nsIChannel *aChannel, + char **aCookieString) +{ + return GetCookieStringInternal(aHostURI, aChannel, aCookieString, true); +} + +NS_IMETHODIMP +CookieServiceChild::SetCookieString(nsIURI *aHostURI, + nsIPrompt *aPrompt, + const char *aCookieString, + nsIChannel *aChannel) +{ + return SetCookieStringInternal(aHostURI, aChannel, aCookieString, + nsnull, false); +} + +NS_IMETHODIMP +CookieServiceChild::SetCookieStringFromHttp(nsIURI *aHostURI, + nsIURI *aFirstURI, + nsIPrompt *aPrompt, + const char *aCookieString, + const char *aServerTime, + nsIChannel *aChannel) +{ + return SetCookieStringInternal(aHostURI, aChannel, aCookieString, + aServerTime, true); +} + +} +} + diff --git a/netwerk/cookie/src/CookieServiceChild.h b/netwerk/cookie/src/CookieServiceChild.h new file mode 100644 index 000000000000..8bc5e6a7a0b3 --- /dev/null +++ b/netwerk/cookie/src/CookieServiceChild.h @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * The Mozilla Foundation . + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Daniel Witte + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef mozilla_net_CookieServiceChild_h__ +#define mozilla_net_CookieServiceChild_h__ + +#include "mozilla/net/PCookieServiceChild.h" +#include "nsICookieService.h" +#include "nsICookiePermission.h" + +namespace mozilla { +namespace net { + +class CookieServiceChild : public PCookieServiceChild + , public nsICookieService +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSICOOKIESERVICE + + CookieServiceChild(); + virtual ~CookieServiceChild(); + + static CookieServiceChild* GetSingleton(); + +protected: + void SerializeURIs(nsIURI *aHostURI, + nsIChannel *aChannel, + nsCString &aHostSpec, + nsCString &aHostCharset, + nsCString &aOriginatingSpec, + nsCString &aOriginatingCharset); + + nsresult GetCookieStringInternal(nsIURI *aHostURI, + nsIChannel *aChannel, + char **aCookieString, + bool aFromHttp); + + nsresult SetCookieStringInternal(nsIURI *aHostURI, + nsIChannel *aChannel, + const char *aCookieString, + const char *aServerTime, + bool aFromHttp); + + nsCOMPtr mPermissionService; +}; + +} +} + +#endif // mozilla_net_CookieServiceChild_h__ + diff --git a/netwerk/cookie/src/CookieServiceParent.cpp b/netwerk/cookie/src/CookieServiceParent.cpp new file mode 100644 index 000000000000..8ac1006fec6e --- /dev/null +++ b/netwerk/cookie/src/CookieServiceParent.cpp @@ -0,0 +1,125 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * The Mozilla Foundation . + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Daniel Witte + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "mozilla/net/CookieServiceParent.h" +#include "nsCookieService.h" +#include "nsNetUtil.h" + +namespace mozilla { +namespace net { + +CookieServiceParent::CookieServiceParent() +{ + // Instantiate the cookieservice via the service manager, so it sticks around + // until shutdown. + nsCOMPtr cs = do_GetService(NS_COOKIESERVICE_CONTRACTID); + + // Get the nsCookieService instance directly, so we can call internal methods. + mCookieService = + already_AddRefed(nsCookieService::GetSingleton()); + NS_ASSERTION(mCookieService, "couldn't get nsICookieService"); + + mIOService = do_GetService(NS_IOSERVICE_CONTRACTID); + NS_ASSERTION(mIOService, "couldn't get nsIIOService"); +} + +CookieServiceParent::~CookieServiceParent() +{ +} + +bool +CookieServiceParent::RecvGetCookieString(const nsCString& aHostSpec, + const nsCString& aHostCharset, + const nsCString& aOriginatingSpec, + const nsCString& aOriginatingCharset, + const bool& aFromHttp, + nsCString* aResult) +{ + if (!mCookieService) + return true; + + // Deserialize URIs. Having a host URI is mandatory and should always be + // provided by the child; thus we consider failure fatal. + nsCOMPtr hostURI, originatingURI; + NS_NewURI(getter_AddRefs(hostURI), + aHostSpec, aHostCharset.get(), + nsnull, mIOService); + NS_NewURI(getter_AddRefs(originatingURI), + aOriginatingSpec, aOriginatingCharset.get(), + nsnull, mIOService); + if (!hostURI) + return false; + + mCookieService->GetCookieInternal(hostURI, originatingURI, + aFromHttp, *aResult); + return true; +} + +bool +CookieServiceParent::RecvSetCookieString(const nsCString& aHostSpec, + const nsCString& aHostCharset, + const nsCString& aOriginatingSpec, + const nsCString& aOriginatingCharset, + const nsCString& aCookieString, + const nsCString& aServerTime, + const bool& aFromHttp) +{ + if (!mCookieService) + return true; + + // Deserialize URIs. Having a host URI is mandatory and should always be + // provided by the child; thus we consider failure fatal. + nsCOMPtr hostURI, originatingURI; + NS_NewURI(getter_AddRefs(hostURI), + aHostSpec, aHostCharset.get(), + nsnull, mIOService); + NS_NewURI(getter_AddRefs(originatingURI), + aOriginatingSpec, aOriginatingCharset.get(), + nsnull, mIOService); + if (!hostURI) + return false; + + mCookieService->SetCookieStringInternal(hostURI, originatingURI, + aCookieString, aServerTime, + aFromHttp); + return true; +} + +} +} + diff --git a/netwerk/cookie/src/CookieServiceParent.h b/netwerk/cookie/src/CookieServiceParent.h new file mode 100644 index 000000000000..c7886400ea42 --- /dev/null +++ b/netwerk/cookie/src/CookieServiceParent.h @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * The Mozilla Foundation . + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Daniel Witte + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef mozilla_net_CookieServiceParent_h +#define mozilla_net_CookieServiceParent_h + +#include "mozilla/net/PCookieServiceParent.h" + +class nsCookieService; +class nsIIOService; + +namespace mozilla { +namespace net { + +class CookieServiceParent : public PCookieServiceParent +{ +public: + CookieServiceParent(); + virtual ~CookieServiceParent(); + +protected: + virtual bool RecvGetCookieString(const nsCString& aHostSpec, + const nsCString& aHostCharset, + const nsCString& aOriginatingSpec, + const nsCString& aOriginatingCharset, + const bool& aFromHttp, + nsCString* aResult); + + virtual bool RecvSetCookieString(const nsCString& aHostSpec, + const nsCString& aHostCharset, + const nsCString& aOriginatingSpec, + const nsCString& aOriginatingCharset, + const nsCString& aCookieString, + const nsCString& aServerTime, + const bool& aFromHttp); + + nsRefPtr mCookieService; + nsCOMPtr mIOService; +}; + +} +} + +#endif // mozilla_net_CookieServiceParent_h + diff --git a/netwerk/cookie/src/Makefile.in b/netwerk/cookie/src/Makefile.in index 7bea25175118..abc55b262050 100644 --- a/netwerk/cookie/src/Makefile.in +++ b/netwerk/cookie/src/Makefile.in @@ -46,12 +46,27 @@ LIBRARY_NAME = neckocookie_s FORCE_STATIC_LIB = 1 LIBXUL_LIBRARY = 1 - CPPSRCS = \ nsCookie.cpp \ nsCookieService.cpp \ $(NULL) +ifdef MOZ_IPC +EXPORTS_NAMESPACES = mozilla/net + +EXPORTS_mozilla/net = \ + CookieServiceParent.h \ + CookieServiceChild.h \ + $(NULL) + +CPPSRCS += \ + CookieServiceParent.cpp \ + CookieServiceChild.cpp \ + $(NULL) +endif + +include $(topsrcdir)/config/config.mk +include $(topsrcdir)/ipc/chromium/chromium-config.mk include $(topsrcdir)/config/rules.mk DEFINES += -DIMPL_NS_NET diff --git a/netwerk/cookie/src/PCookieService.ipdl b/netwerk/cookie/src/PCookieService.ipdl new file mode 100644 index 000000000000..a67d06440e0d --- /dev/null +++ b/netwerk/cookie/src/PCookieService.ipdl @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set sw=2 ts=8 et tw=80 ft=cpp : */ + +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * The Mozilla Foundation + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Daniel Witte + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +include protocol "PNecko.ipdl"; + +namespace mozilla { +namespace net { + +sync protocol PCookieService +{ + manager PNecko; + +parent: + sync GetCookieString(nsCString hostSpec, + nsCString hostCharset, + nsCString originatingSpec, + nsCString originatingCharset, + bool fromHttp) + returns (nsCString result); + + SetCookieString(nsCString hostSpec, + nsCString hostCharset, + nsCString originatingSpec, + nsCString originatingCharset, + nsCString cookieString, + nsCString serverTime, + bool fromHttp); + + __delete__(); +}; + +} +} + diff --git a/netwerk/cookie/src/ipdl.mk b/netwerk/cookie/src/ipdl.mk new file mode 100644 index 000000000000..073349bd26da --- /dev/null +++ b/netwerk/cookie/src/ipdl.mk @@ -0,0 +1,41 @@ +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is Mozilla Firefox. +# +# The Initial Developer of the Original Code is +# The Mozilla Foundation . +# Portions created by the Initial Developer are Copyright (C) 2010 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Daniel Witte +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +IPDLSRCS = \ + PCookieService.ipdl \ + $(NULL) + diff --git a/netwerk/cookie/src/nsCookieService.cpp b/netwerk/cookie/src/nsCookieService.cpp index 8958d0c33631..dcb38e8c7a48 100644 --- a/netwerk/cookie/src/nsCookieService.cpp +++ b/netwerk/cookie/src/nsCookieService.cpp @@ -39,6 +39,11 @@ * * ***** END LICENSE BLOCK ***** */ +#ifdef MOZ_IPC +#include "mozilla/net/CookieServiceChild.h" +#include "mozilla/net/NeckoCommon.h" +#endif + #include "nsCookieService.h" #include "nsIServiceManager.h" @@ -73,6 +78,8 @@ #include "nsNetCID.h" #include "mozilla/storage.h" +using namespace mozilla::net; + /****************************************************************************** * nsCookieService impl: * useful types & constants @@ -467,11 +474,26 @@ static RemoveCookieDBListener sRemoveCookieDBListener; * singleton instance ctor/dtor methods ******************************************************************************/ -nsCookieService *nsCookieService::gCookieService = nsnull; +static nsCookieService *gCookieService; + +nsICookieService* +nsCookieService::GetXPCOMSingleton() +{ +#ifdef MOZ_IPC + if (IsNeckoChild()) + return CookieServiceChild::GetSingleton(); +#endif + + return GetSingleton(); +} nsCookieService* nsCookieService::GetSingleton() { +#ifdef MOZ_IPC + NS_ASSERTION(!IsNeckoChild(), "not a parent process"); +#endif + if (gCookieService) { NS_ADDREF(gCookieService); return gCookieService; @@ -886,8 +908,15 @@ nsCookieService::GetCookieString(nsIURI *aHostURI, nsIChannel *aChannel, char **aCookie) { - GetCookieInternal(aHostURI, aChannel, PR_FALSE, aCookie); - + NS_ENSURE_ARG(aHostURI); + NS_ENSURE_ARG(aCookie); + + nsCOMPtr originatingURI; + GetOriginatingURI(aChannel, getter_AddRefs(originatingURI)); + + nsCAutoString result; + GetCookieInternal(aHostURI, originatingURI, PR_FALSE, result); + *aCookie = result.IsEmpty() ? nsnull : ToNewCString(result); return NS_OK; } @@ -897,8 +926,15 @@ nsCookieService::GetCookieStringFromHttp(nsIURI *aHostURI, nsIChannel *aChannel, char **aCookie) { - GetCookieInternal(aHostURI, aChannel, PR_TRUE, aCookie); + NS_ENSURE_ARG(aHostURI); + NS_ENSURE_ARG(aCookie); + nsCOMPtr originatingURI; + GetOriginatingURI(aChannel, getter_AddRefs(originatingURI)); + + nsCAutoString result; + GetCookieInternal(aHostURI, originatingURI, PR_TRUE, result); + *aCookie = result.IsEmpty() ? nsnull : ToNewCString(result); return NS_OK; } @@ -908,7 +944,16 @@ nsCookieService::SetCookieString(nsIURI *aHostURI, const char *aCookieHeader, nsIChannel *aChannel) { - return SetCookieStringInternal(aHostURI, aPrompt, aCookieHeader, nsnull, aChannel, PR_FALSE); + NS_ENSURE_ARG(aHostURI); + NS_ENSURE_ARG(aCookieHeader); + + nsCOMPtr originatingURI; + GetOriginatingURI(aChannel, getter_AddRefs(originatingURI)); + + nsDependentCString cookieString(aCookieHeader); + SetCookieStringInternal(aHostURI, originatingURI, + cookieString, EmptyCString(), PR_FALSE); + return NS_OK; } NS_IMETHODIMP @@ -919,22 +964,26 @@ nsCookieService::SetCookieStringFromHttp(nsIURI *aHostURI, const char *aServerTime, nsIChannel *aChannel) { - return SetCookieStringInternal(aHostURI, aPrompt, aCookieHeader, aServerTime, aChannel, PR_TRUE); + NS_ENSURE_ARG(aHostURI); + NS_ENSURE_ARG(aCookieHeader); + + nsCOMPtr originatingURI; + GetOriginatingURI(aChannel, getter_AddRefs(originatingURI)); + + nsDependentCString cookieString(aCookieHeader); + nsDependentCString serverTime(aServerTime ? aServerTime : ""); + SetCookieStringInternal(aHostURI, originatingURI, cookieString, + serverTime, PR_TRUE); + return NS_OK; } -nsresult -nsCookieService::SetCookieStringInternal(nsIURI *aHostURI, - nsIPrompt *aPrompt, - const char *aCookieHeader, - const char *aServerTime, - nsIChannel *aChannel, - PRBool aFromHttp) +void +nsCookieService::SetCookieStringInternal(nsIURI *aHostURI, + nsIURI *aOriginatingURI, + const nsCString &aCookieHeader, + const nsCString &aServerTime, + PRBool aFromHttp) { - if (!aHostURI) { - COOKIE_LOGFAILURE(SET_COOKIE, nsnull, aCookieHeader, "host URI is null"); - return NS_OK; - } - // get the base domain for the host URI. // e.g. for "www.bbc.co.uk", this would be "bbc.co.uk". // file:// URI's (i.e. with an empty host) are allowed, but any other @@ -946,18 +995,18 @@ nsCookieService::SetCookieStringInternal(nsIURI *aHostURI, if (NS_FAILED(rv)) { COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieHeader, "couldn't get base domain from URI"); - return NS_OK; + return; } // check default prefs - PRUint32 cookieStatus = CheckPrefs(aHostURI, aChannel, baseDomain, - requireHostMatch, aCookieHeader); + PRUint32 cookieStatus = CheckPrefs(aHostURI, aOriginatingURI, baseDomain, + requireHostMatch, aCookieHeader.get()); // fire a notification if cookie was rejected (but not if there was an error) switch (cookieStatus) { case STATUS_REJECTED: NotifyRejected(aHostURI); case STATUS_REJECTED_WITH_ERROR: - return NS_OK; + return; } // parse server local time. this is not just done here for efficiency @@ -967,8 +1016,9 @@ nsCookieService::SetCookieStringInternal(nsIURI *aHostURI, // user is prompted). PRTime tempServerTime; PRInt64 serverTime; - if (aServerTime && - PR_ParseTimeString(aServerTime, PR_TRUE, &tempServerTime) == PR_SUCCESS) { + PRStatus result = PR_ParseTimeString(aServerTime.get(), PR_TRUE, + &tempServerTime); + if (result == PR_SUCCESS) { serverTime = tempServerTime / PR_USEC_PER_SEC; } else { serverTime = PR_Now() / PR_USEC_PER_SEC; @@ -981,9 +1031,9 @@ nsCookieService::SetCookieStringInternal(nsIURI *aHostURI, mDBState->stmtInsert->NewBindingParamsArray(getter_AddRefs(paramsArray)); } - // switch to a nice string type now, and process each cookie in the header + // process each cookie in the header nsDependentCString cookieHeader(aCookieHeader); - while (SetCookieInternal(aHostURI, aChannel, baseDomain, requireHostMatch, + while (SetCookieInternal(aHostURI, baseDomain, requireHostMatch, cookieHeader, serverTime, aFromHttp, paramsArray)); // If we had a params array, go ahead and write it out to disk now. @@ -992,7 +1042,7 @@ nsCookieService::SetCookieStringInternal(nsIURI *aHostURI, PRUint32 length; paramsArray->GetLength(&length); if (length == 0) - return NS_OK; + return; rv = mDBState->stmtInsert->BindParameters(paramsArray); NS_ASSERT_SUCCESS(rv); @@ -1001,8 +1051,6 @@ nsCookieService::SetCookieStringInternal(nsIURI *aHostURI, getter_AddRefs(handle)); NS_ASSERT_SUCCESS(rv); } - - return NS_OK; } // notify observers that a cookie was rejected due to the users' prefs. @@ -1488,12 +1536,10 @@ public: void nsCookieService::GetCookieInternal(nsIURI *aHostURI, - nsIChannel *aChannel, + nsIURI *aOriginatingURI, PRBool aHttpBound, - char **aCookie) + nsCString &aCookieString) { - *aCookie = nsnull; - if (!aHostURI) { COOKIE_LOGFAILURE(GET_COOKIE, nsnull, nsnull, "host URI is null"); return; @@ -1520,7 +1566,7 @@ nsCookieService::GetCookieInternal(nsIURI *aHostURI, } // check default prefs - PRUint32 cookieStatus = CheckPrefs(aHostURI, aChannel, baseDomain, + PRUint32 cookieStatus = CheckPrefs(aHostURI, aOriginatingURI, baseDomain, requireHostMatch, nsnull); // for GetCookie(), we don't fire rejection notifications. switch (cookieStatus) { @@ -1643,7 +1689,6 @@ nsCookieService::GetCookieInternal(nsIURI *aHostURI, // then sort by creation time (see bug 236772). foundCookieList.Sort(CompareCookiesForSending()); - nsCAutoString cookieData; for (PRInt32 i = 0; i < count; ++i) { cookie = foundCookieList.ElementAt(i); @@ -1651,33 +1696,28 @@ nsCookieService::GetCookieInternal(nsIURI *aHostURI, if (!cookie->Name().IsEmpty() || !cookie->Value().IsEmpty()) { // if we've already added a cookie to the return list, append a "; " so // that subsequent cookies are delimited in the final list. - if (!cookieData.IsEmpty()) { - cookieData.AppendLiteral("; "); + if (!aCookieString.IsEmpty()) { + aCookieString.AppendLiteral("; "); } if (!cookie->Name().IsEmpty()) { // we have a name and value - write both - cookieData += cookie->Name() + NS_LITERAL_CSTRING("=") + cookie->Value(); + aCookieString += cookie->Name() + NS_LITERAL_CSTRING("=") + cookie->Value(); } else { // just write value - cookieData += cookie->Value(); + aCookieString += cookie->Value(); } } } - // it's wasteful to alloc a new string; but we have no other choice, until we - // fix the callers to use nsACStrings. - if (!cookieData.IsEmpty()) { - COOKIE_LOGSUCCESS(GET_COOKIE, aHostURI, cookieData, nsnull, nsnull); - *aCookie = ToNewCString(cookieData); - } + if (!aCookieString.IsEmpty()) + COOKIE_LOGSUCCESS(GET_COOKIE, aHostURI, aCookieString, nsnull, nsnull); } // processes a single cookie, and returns PR_TRUE if there are more cookies // to be processed PRBool nsCookieService::SetCookieInternal(nsIURI *aHostURI, - nsIChannel *aChannel, const nsCString &aBaseDomain, PRBool aRequireHostMatch, nsDependentCString &aCookieHeader, @@ -1746,10 +1786,10 @@ nsCookieService::SetCookieInternal(nsIURI *aHostURI, // to determine if we can set the cookie if (mPermissionService) { PRBool permission; - // we need to think about prompters/parent windows here - TestPermission - // needs one to prompt, so right now it has to fend for itself to get one + // Not passing an nsIChannel here means CanSetCookie will use the currently + // active window to display the prompt. This isn't exactly ideal... mPermissionService->CanSetCookie(aHostURI, - aChannel, + nsnull, static_cast(static_cast(cookie)), &cookieAttributes.isSession, &cookieAttributes.expiryTime, @@ -2222,9 +2262,26 @@ nsCookieService::IsForeign(const nsCString &aBaseDomain, return !IsSubdomainOf(firstHost, aBaseDomain); } +void +nsCookieService::GetOriginatingURI(nsIChannel *aChannel, + nsIURI **aURI) +{ + // Determine the originating URI. We only need to do this if we're + // rejecting third-party cookies. + if (mCookiesPermissions != BEHAVIOR_REJECTFOREIGN) + return; + + if (!mPermissionService) { + NS_WARNING("nsICookiePermission unavailable! Cookie may be rejected"); + return; + } + + mPermissionService->GetOriginatingURI(aChannel, aURI); +} + PRUint32 nsCookieService::CheckPrefs(nsIURI *aHostURI, - nsIChannel *aChannel, + nsIURI *aOriginatingURI, const nsCString &aBaseDomain, PRBool aRequireHostMatch, const char *aCookieHeader) @@ -2242,7 +2299,9 @@ nsCookieService::CheckPrefs(nsIURI *aHostURI, // default prefs. see bug 184059. if (mPermissionService) { nsCookieAccess access; - rv = mPermissionService->CanAccess(aHostURI, aChannel, &access); + // Not passing an nsIChannel here is probably OK; our implementation + // doesn't do anything with it anyway. + rv = mPermissionService->CanAccess(aHostURI, nsnull, &access); // if we found an entry, use it if (NS_SUCCEEDED(rv)) { @@ -2264,16 +2323,8 @@ nsCookieService::CheckPrefs(nsIURI *aHostURI, } else if (mCookiesPermissions == BEHAVIOR_REJECTFOREIGN) { // check if cookie is foreign - if (!mPermissionService) { - NS_WARNING("Foreign cookie blocking enabled, but nsICookiePermission unavailable! Rejecting cookie"); - COOKIE_LOGSTRING(PR_LOG_WARNING, ("CheckPrefs(): foreign blocking enabled, but nsICookiePermission unavailable! Rejecting cookie")); - return STATUS_REJECTED; - } - - nsCOMPtr firstURI; - rv = mPermissionService->GetOriginatingURI(aChannel, getter_AddRefs(firstURI)); - - if (NS_FAILED(rv) || IsForeign(aBaseDomain, aRequireHostMatch, firstURI)) { + if (!aOriginatingURI || + IsForeign(aBaseDomain, aRequireHostMatch, aOriginatingURI)) { COOKIE_LOGFAILURE(aCookieHeader ? SET_COOKIE : GET_COOKIE, aHostURI, aCookieHeader, "originating server test failed"); return STATUS_REJECTED; } @@ -2544,7 +2595,7 @@ purgeCookiesCallback(nsCookieEntry *aEntry, COOKIE_LOGEVICTED(cookie); // remove from list; do not increment our iterator - nsCookieService::gCookieService->RemoveCookieFromList(iter, array); + gCookieService->RemoveCookieFromList(iter, array); } else { // check if the cookie is over the age limit diff --git a/netwerk/cookie/src/nsCookieService.h b/netwerk/cookie/src/nsCookieService.h index 6b58f8a9afc5..761e516ed7f6 100644 --- a/netwerk/cookie/src/nsCookieService.h +++ b/netwerk/cookie/src/nsCookieService.h @@ -56,10 +56,6 @@ #include "mozIStorageStatement.h" #include "mozIStorageConnection.h" -struct nsCookieAttributes; -struct nsListIter; -struct nsEnumerationData; - class nsICookiePermission; class nsIEffectiveTLDService; class nsIIDNService; @@ -68,6 +64,18 @@ class nsIObserverService; class nsIURI; class nsIChannel; +struct nsCookieAttributes; +struct nsListIter; +struct nsEnumerationData; + +namespace mozilla { +namespace net { +#ifdef MOZ_IPC +class CookieServiceParent; +#endif +} +} + // hash entry class class nsCookieEntry : public PLDHashEntryHdr { @@ -159,7 +167,7 @@ class nsCookieService : public nsICookieService nsCookieService(); virtual ~nsCookieService(); - static nsCookieService* GetSingleton(); + static nsICookieService* GetXPCOMSingleton(); nsresult Init(); protected: @@ -172,9 +180,9 @@ class nsCookieService : public nsICookieService nsresult NormalizeHost(nsCString &aHost); nsresult GetBaseDomain(nsIURI *aHostURI, nsCString &aBaseDomain, PRBool &aRequireHostMatch); nsresult GetBaseDomainFromHost(const nsACString &aHost, nsCString &aBaseDomain); - void GetCookieInternal(nsIURI *aHostURI, nsIChannel *aChannel, PRBool aHttpBound, char **aCookie); - nsresult SetCookieStringInternal(nsIURI *aHostURI, nsIPrompt *aPrompt, const char *aCookieHeader, const char *aServerTime, nsIChannel *aChannel, PRBool aFromHttp); - PRBool SetCookieInternal(nsIURI *aHostURI, nsIChannel *aChannel, const nsCString& aBaseDomain, PRBool aRequireHostMatch, nsDependentCString &aCookieHeader, PRInt64 aServerTime, PRBool aFromHttp, mozIStorageBindingParamsArray *aParamsArray = NULL); + void GetCookieInternal(nsIURI *aHostURI, nsIURI *aOriginatingURI, PRBool aHttpBound, nsCString &aCookie); + void SetCookieStringInternal(nsIURI *aHostURI, nsIURI *aOriginatingURI, const nsCString &aCookieHeader, const nsCString &aServerTime, PRBool aFromHttp); + PRBool SetCookieInternal(nsIURI *aHostURI, const nsCString& aBaseDomain, PRBool aRequireHostMatch, nsDependentCString &aCookieHeader, PRInt64 aServerTime, PRBool aFromHttp, mozIStorageBindingParamsArray *aParamsArray = NULL); void AddInternal(const nsCString& aBaseDomain, nsCookie *aCookie, PRInt64 aCurrentTimeInUsec, nsIURI *aHostURI, const char *aCookieHeader, PRBool aFromHttp, mozIStorageBindingParamsArray *aParamsArray = NULL); void RemoveCookieFromList(const nsListIter &aIter, mozIStorageBindingParamsArray *aParamsArray = NULL); PRBool AddCookieToList(const nsCString& aBaseDomain, nsCookie *aCookie, mozIStorageBindingParamsArray *aParamsArray, PRBool aWriteToDB = PR_TRUE); @@ -182,7 +190,8 @@ class nsCookieService : public nsICookieService static PRBool GetTokenValue(nsASingleFragmentCString::const_char_iterator &aIter, nsASingleFragmentCString::const_char_iterator &aEndIter, nsDependentCSubstring &aTokenString, nsDependentCSubstring &aTokenValue, PRBool &aEqualsFound); static PRBool ParseAttributes(nsDependentCString &aCookieHeader, nsCookieAttributes &aCookie); PRBool IsForeign(const nsCString &aBaseDomain, PRBool aRequireHostMatch, nsIURI *aFirstURI); - PRUint32 CheckPrefs(nsIURI *aHostURI, nsIChannel *aChannel, const nsCString &aBaseDomain, PRBool aRequireHostMatch, const char *aCookieHeader); + void GetOriginatingURI(nsIChannel *aChannel, nsIURI **aURI); + PRUint32 CheckPrefs(nsIURI *aHostURI, nsIURI *aOriginatingURI, const nsCString &aBaseDomain, PRBool aRequireHostMatch, const char *aCookieHeader); PRBool CheckDomain(nsCookieAttributes &aCookie, nsIURI *aHostURI, const nsCString &aBaseDomain, PRBool aRequireHostMatch); static PRBool CheckPath(nsCookieAttributes &aCookie, nsIURI *aHostURI); static PRBool GetExpiry(nsCookieAttributes &aCookie, PRInt64 aServerTime, PRInt64 aCurrentTime); @@ -215,12 +224,13 @@ class nsCookieService : public nsICookieService PRUint16 mMaxCookiesPerHost; PRInt64 mCookiePurgeAge; - // private static member, used to cache a ptr to nsCookieService, - // so we can make nsCookieService a singleton xpcom object. - static nsCookieService *gCookieService; - // this callback needs access to member functions friend PLDHashOperator purgeCookiesCallback(nsCookieEntry *aEntry, void *aArg); + + static nsCookieService* GetSingleton(); +#ifdef MOZ_IPC + friend class mozilla::net::CookieServiceParent; +#endif }; #endif // nsCookieService_h__ diff --git a/netwerk/cookie/test/unit_ipc/head_ipc_setup.js b/netwerk/cookie/test/unit_ipc/head_ipc_setup.js new file mode 100644 index 000000000000..c39be6512997 --- /dev/null +++ b/netwerk/cookie/test/unit_ipc/head_ipc_setup.js @@ -0,0 +1,15 @@ + +/** + * Turn on e10s networking (god help us) + */ +Components.classes["@mozilla.org/process/environment;1"] + .getService(Components.interfaces.nsIEnvironment) + .set("NECKO_E10S_HTTP", "1"); + +// If using NSPR logging, create child log as "${NSPR_LOG_FILE}.child" +// - TODO: remove when bug 534764 is fixed +var env = Components.classes["@mozilla.org/process/environment;1"] + .getService(Components.interfaces.nsIEnvironment); +var log = env.get("NSPR_LOG_FILE"); +if (log) + env.set("NSPR_LOG_FILE", log + ".child"); diff --git a/netwerk/cookie/test/unit_ipc/test_ipc_parser_0001.js b/netwerk/cookie/test/unit_ipc/test_ipc_parser_0001.js new file mode 100644 index 000000000000..8bad531b676d --- /dev/null +++ b/netwerk/cookie/test/unit_ipc/test_ipc_parser_0001.js @@ -0,0 +1,3 @@ +function run_test() { + run_test_in_child("../unit/test_parser_0001.js"); +} diff --git a/netwerk/cookie/test/unit_ipc/test_ipc_parser_0019.js b/netwerk/cookie/test/unit_ipc/test_ipc_parser_0019.js new file mode 100644 index 000000000000..c36fe99991cd --- /dev/null +++ b/netwerk/cookie/test/unit_ipc/test_ipc_parser_0019.js @@ -0,0 +1,3 @@ +function run_test() { + run_test_in_child("../unit/test_parser_0019.js"); +} diff --git a/netwerk/ipc/NeckoChild.cpp b/netwerk/ipc/NeckoChild.cpp index 20dd315e2faa..926a4e4424e3 100644 --- a/netwerk/ipc/NeckoChild.cpp +++ b/netwerk/ipc/NeckoChild.cpp @@ -42,6 +42,7 @@ #include "mozilla/net/NeckoChild.h" #include "mozilla/dom/ContentProcessChild.h" #include "mozilla/net/HttpChannelChild.h" +#include "mozilla/net/CookieServiceChild.h" namespace mozilla { namespace net { @@ -103,5 +104,23 @@ NeckoChild::DeallocPHttpChannel(PHttpChannelChild* channel) return true; } +PCookieServiceChild* +NeckoChild::AllocPCookieService() +{ + // We don't allocate here: see nsCookieService::GetSingleton() + NS_NOTREACHED("AllocPCookieService should not be called"); + return nsnull; +} + +bool +NeckoChild::DeallocPCookieService(PCookieServiceChild* cs) +{ + NS_ASSERTION(IsNeckoChild(), "DeallocPCookieService called by non-child!"); + + CookieServiceChild *p = static_cast(cs); + p->Release(); + return true; +} + }} // mozilla::net diff --git a/netwerk/ipc/NeckoChild.h b/netwerk/ipc/NeckoChild.h index df34c6661fb7..30a68cfe458f 100644 --- a/netwerk/ipc/NeckoChild.h +++ b/netwerk/ipc/NeckoChild.h @@ -61,6 +61,8 @@ public: protected: virtual PHttpChannelChild* AllocPHttpChannel(); virtual bool DeallocPHttpChannel(PHttpChannelChild*); + virtual PCookieServiceChild* AllocPCookieService(); + virtual bool DeallocPCookieService(PCookieServiceChild*); }; /** diff --git a/netwerk/ipc/NeckoParent.cpp b/netwerk/ipc/NeckoParent.cpp index 8af6a1fa4166..1b8760ebbe04 100644 --- a/netwerk/ipc/NeckoParent.cpp +++ b/netwerk/ipc/NeckoParent.cpp @@ -41,6 +41,7 @@ #include "nsHttp.h" #include "mozilla/net/NeckoParent.h" #include "mozilla/net/HttpChannelParent.h" +#include "mozilla/net/CookieServiceParent.h" namespace mozilla { namespace net { @@ -70,6 +71,18 @@ NeckoParent::DeallocPHttpChannel(PHttpChannelParent* channel) return true; } +PCookieServiceParent* +NeckoParent::AllocPCookieService() +{ + return new CookieServiceParent(); +} + +bool +NeckoParent::DeallocPCookieService(PCookieServiceParent* cs) +{ + delete cs; + return true; +} }} // mozilla::net diff --git a/netwerk/ipc/NeckoParent.h b/netwerk/ipc/NeckoParent.h index 67b0ff9636ac..d3f99440f0cc 100644 --- a/netwerk/ipc/NeckoParent.h +++ b/netwerk/ipc/NeckoParent.h @@ -58,6 +58,8 @@ public: protected: virtual PHttpChannelParent* AllocPHttpChannel(); virtual bool DeallocPHttpChannel(PHttpChannelParent*); + virtual PCookieServiceParent* AllocPCookieService(); + virtual bool DeallocPCookieService(PCookieServiceParent*); }; } // namespace net diff --git a/netwerk/ipc/PNecko.ipdl b/netwerk/ipc/PNecko.ipdl index 5d4abb02f88a..e103dc8bedb0 100644 --- a/netwerk/ipc/PNecko.ipdl +++ b/netwerk/ipc/PNecko.ipdl @@ -40,21 +40,24 @@ include protocol "PContentProcess.ipdl"; include protocol "PHttpChannel.ipdl"; +include protocol "PCookieService.ipdl"; namespace mozilla { namespace net { //------------------------------------------------------------------- -protocol PNecko +sync protocol PNecko { manager PContentProcess; manages PHttpChannel; + manages PCookieService; parent: __delete__(); PHttpChannel(); + PCookieService(); };