2010-03-25 16:02:28 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-03-25 16:02:28 -07:00
|
|
|
|
|
|
|
#include "mozilla/net/CookieServiceParent.h"
|
2012-12-29 01:02:16 -08:00
|
|
|
#include "mozilla/dom/PBrowserParent.h"
|
|
|
|
#include "mozilla/net/NeckoParent.h"
|
2012-08-23 12:33:46 -07:00
|
|
|
|
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
2010-03-25 16:02:28 -07:00
|
|
|
#include "nsCookieService.h"
|
|
|
|
#include "nsNetUtil.h"
|
2012-12-29 01:02:16 -08:00
|
|
|
#include "nsPrintfCString.h"
|
2010-03-25 16:02:28 -07:00
|
|
|
|
2012-08-23 12:33:46 -07:00
|
|
|
using namespace mozilla::ipc;
|
2012-12-29 01:02:16 -08:00
|
|
|
using mozilla::dom::PBrowserParent;
|
|
|
|
using mozilla::net::NeckoParent;
|
2012-12-16 10:09:39 -08:00
|
|
|
|
2012-12-29 01:02:16 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
MOZ_WARN_UNUSED_RESULT
|
|
|
|
static bool
|
|
|
|
GetAppInfoFromParams(const IPC::SerializedLoadContext &aLoadContext,
|
|
|
|
PBrowserParent* aBrowser,
|
|
|
|
uint32_t& aAppId,
|
|
|
|
bool& aIsInBrowserElement,
|
|
|
|
bool& aIsPrivate)
|
2012-02-08 10:37:07 -08:00
|
|
|
{
|
|
|
|
aAppId = NECKO_NO_APP_ID;
|
|
|
|
aIsInBrowserElement = false;
|
2012-12-28 16:18:38 -08:00
|
|
|
aIsPrivate = false;
|
2012-02-08 10:37:07 -08:00
|
|
|
|
2012-12-29 01:02:16 -08:00
|
|
|
const char* error = NeckoParent::GetValidatedAppInfo(aLoadContext, aBrowser,
|
|
|
|
&aAppId,
|
|
|
|
&aIsInBrowserElement);
|
|
|
|
if (error) {
|
|
|
|
NS_WARNING(nsPrintfCString("CookieServiceParent: GetAppInfoFromParams: "
|
|
|
|
"FATAL error: %s: KILLING CHILD PROCESS\n",
|
|
|
|
error).get());
|
|
|
|
return false;
|
2012-02-08 10:37:07 -08:00
|
|
|
}
|
|
|
|
|
2012-12-29 01:02:16 -08:00
|
|
|
if (aLoadContext.IsPrivateBitValid()) {
|
2012-12-28 16:18:38 -08:00
|
|
|
aIsPrivate = aLoadContext.mUsePrivateBrowsing;
|
2012-12-29 01:02:16 -08:00
|
|
|
}
|
|
|
|
return true;
|
2012-02-08 10:37:07 -08:00
|
|
|
}
|
|
|
|
|
2010-03-25 16:02:28 -07:00
|
|
|
CookieServiceParent::CookieServiceParent()
|
|
|
|
{
|
|
|
|
// Instantiate the cookieservice via the service manager, so it sticks around
|
|
|
|
// until shutdown.
|
|
|
|
nsCOMPtr<nsICookieService> cs = do_GetService(NS_COOKIESERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
// Get the nsCookieService instance directly, so we can call internal methods.
|
|
|
|
mCookieService =
|
|
|
|
already_AddRefed<nsCookieService>(nsCookieService::GetSingleton());
|
|
|
|
NS_ASSERTION(mCookieService, "couldn't get nsICookieService");
|
|
|
|
}
|
|
|
|
|
|
|
|
CookieServiceParent::~CookieServiceParent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-08-23 12:33:46 -07:00
|
|
|
CookieServiceParent::RecvGetCookieString(const URIParams& aHost,
|
2010-10-19 09:37:03 -07:00
|
|
|
const bool& aIsForeign,
|
2010-03-25 16:02:28 -07:00
|
|
|
const bool& aFromHttp,
|
2012-09-18 09:04:04 -07:00
|
|
|
const IPC::SerializedLoadContext&
|
|
|
|
aLoadContext,
|
2012-12-29 01:02:16 -08:00
|
|
|
PBrowserParent* aBrowser,
|
2010-03-25 16:02:28 -07:00
|
|
|
nsCString* aResult)
|
|
|
|
{
|
|
|
|
if (!mCookieService)
|
|
|
|
return true;
|
|
|
|
|
2010-10-19 09:37:03 -07:00
|
|
|
// Deserialize URI. Having a host URI is mandatory and should always be
|
2010-03-25 16:02:28 -07:00
|
|
|
// provided by the child; thus we consider failure fatal.
|
2012-08-23 12:33:46 -07:00
|
|
|
nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost);
|
2010-03-25 16:02:28 -07:00
|
|
|
if (!hostURI)
|
|
|
|
return false;
|
|
|
|
|
2012-09-18 09:04:04 -07:00
|
|
|
uint32_t appId;
|
2012-02-08 10:37:07 -08:00
|
|
|
bool isInBrowserElement, isPrivate;
|
2012-12-29 01:02:16 -08:00
|
|
|
bool valid = GetAppInfoFromParams(aLoadContext, aBrowser, appId,
|
|
|
|
isInBrowserElement, isPrivate);
|
|
|
|
if (!valid) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-18 09:04:04 -07:00
|
|
|
|
|
|
|
mCookieService->GetCookieStringInternal(hostURI, aIsForeign, aFromHttp, appId,
|
2012-12-16 10:09:39 -08:00
|
|
|
isInBrowserElement, isPrivate, *aResult);
|
2010-03-25 16:02:28 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-08-23 12:33:46 -07:00
|
|
|
CookieServiceParent::RecvSetCookieString(const URIParams& aHost,
|
2010-10-19 09:37:03 -07:00
|
|
|
const bool& aIsForeign,
|
2010-03-25 16:02:28 -07:00
|
|
|
const nsCString& aCookieString,
|
|
|
|
const nsCString& aServerTime,
|
2012-09-18 09:04:04 -07:00
|
|
|
const bool& aFromHttp,
|
|
|
|
const IPC::SerializedLoadContext&
|
2012-12-29 01:02:16 -08:00
|
|
|
aLoadContext,
|
|
|
|
PBrowserParent* aBrowser)
|
2010-03-25 16:02:28 -07:00
|
|
|
{
|
|
|
|
if (!mCookieService)
|
|
|
|
return true;
|
|
|
|
|
2010-10-19 09:37:03 -07:00
|
|
|
// Deserialize URI. Having a host URI is mandatory and should always be
|
2010-03-25 16:02:28 -07:00
|
|
|
// provided by the child; thus we consider failure fatal.
|
2012-08-23 12:33:46 -07:00
|
|
|
nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost);
|
2010-03-25 16:02:28 -07:00
|
|
|
if (!hostURI)
|
|
|
|
return false;
|
|
|
|
|
2012-09-18 09:04:04 -07:00
|
|
|
uint32_t appId;
|
2012-02-08 10:37:07 -08:00
|
|
|
bool isInBrowserElement, isPrivate;
|
2012-12-29 01:02:16 -08:00
|
|
|
bool valid = GetAppInfoFromParams(aLoadContext, aBrowser, appId,
|
|
|
|
isInBrowserElement, isPrivate);
|
|
|
|
if (!valid) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-18 09:04:04 -07:00
|
|
|
|
2011-09-15 00:40:17 -07:00
|
|
|
nsDependentCString cookieString(aCookieString, 0);
|
2012-02-01 02:20:01 -08:00
|
|
|
//TODO: bug 812475, pass a real channel object
|
2012-09-18 09:04:04 -07:00
|
|
|
mCookieService->SetCookieStringInternal(hostURI, aIsForeign, cookieString,
|
|
|
|
aServerTime, aFromHttp, appId,
|
2012-02-01 02:20:01 -08:00
|
|
|
isInBrowserElement, isPrivate, nullptr);
|
2010-03-25 16:02:28 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|