2010-03-25 23:02:28 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 23:02:28 +00:00
|
|
|
|
|
|
|
#include "mozilla/net/CookieServiceParent.h"
|
2012-08-23 19:33:46 +00:00
|
|
|
|
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
2010-03-25 23:02:28 +00:00
|
|
|
#include "nsCookieService.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
2012-08-23 19:33:46 +00:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
2010-03-25 23:02:28 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
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 19:33:46 +00:00
|
|
|
CookieServiceParent::RecvGetCookieString(const URIParams& aHost,
|
2010-10-19 16:37:03 +00:00
|
|
|
const bool& aIsForeign,
|
2010-03-25 23:02:28 +00:00
|
|
|
const bool& aFromHttp,
|
2012-09-18 16:04:04 +00:00
|
|
|
const IPC::SerializedLoadContext&
|
|
|
|
aLoadContext,
|
2010-03-25 23:02:28 +00:00
|
|
|
nsCString* aResult)
|
|
|
|
{
|
|
|
|
if (!mCookieService)
|
|
|
|
return true;
|
|
|
|
|
2010-10-19 16:37:03 +00:00
|
|
|
// Deserialize URI. Having a host URI is mandatory and should always be
|
2010-03-25 23:02:28 +00:00
|
|
|
// provided by the child; thus we consider failure fatal.
|
2012-08-23 19:33:46 +00:00
|
|
|
nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost);
|
2010-03-25 23:02:28 +00:00
|
|
|
if (!hostURI)
|
|
|
|
return false;
|
|
|
|
|
2012-09-18 16:04:04 +00:00
|
|
|
uint32_t appId;
|
|
|
|
bool isInBrowserElement;
|
|
|
|
GetAppInfoFromLoadContext(aLoadContext, appId, isInBrowserElement);
|
|
|
|
|
|
|
|
mCookieService->GetCookieStringInternal(hostURI, aIsForeign, aFromHttp, appId,
|
|
|
|
isInBrowserElement, *aResult);
|
2010-03-25 23:02:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-08-23 19:33:46 +00:00
|
|
|
CookieServiceParent::RecvSetCookieString(const URIParams& aHost,
|
2010-10-19 16:37:03 +00:00
|
|
|
const bool& aIsForeign,
|
2010-03-25 23:02:28 +00:00
|
|
|
const nsCString& aCookieString,
|
|
|
|
const nsCString& aServerTime,
|
2012-09-18 16:04:04 +00:00
|
|
|
const bool& aFromHttp,
|
|
|
|
const IPC::SerializedLoadContext&
|
|
|
|
aLoadContext)
|
2010-03-25 23:02:28 +00:00
|
|
|
{
|
|
|
|
if (!mCookieService)
|
|
|
|
return true;
|
|
|
|
|
2010-10-19 16:37:03 +00:00
|
|
|
// Deserialize URI. Having a host URI is mandatory and should always be
|
2010-03-25 23:02:28 +00:00
|
|
|
// provided by the child; thus we consider failure fatal.
|
2012-08-23 19:33:46 +00:00
|
|
|
nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost);
|
2010-03-25 23:02:28 +00:00
|
|
|
if (!hostURI)
|
|
|
|
return false;
|
|
|
|
|
2012-09-18 16:04:04 +00:00
|
|
|
uint32_t appId;
|
|
|
|
bool isInBrowserElement;
|
|
|
|
GetAppInfoFromLoadContext(aLoadContext, appId, isInBrowserElement);
|
|
|
|
|
2011-09-15 07:40:17 +00:00
|
|
|
nsDependentCString cookieString(aCookieString, 0);
|
2012-09-18 16:04:04 +00:00
|
|
|
mCookieService->SetCookieStringInternal(hostURI, aIsForeign, cookieString,
|
|
|
|
aServerTime, aFromHttp, appId,
|
|
|
|
isInBrowserElement);
|
2010-03-25 23:02:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-18 16:04:04 +00:00
|
|
|
void
|
|
|
|
CookieServiceParent::GetAppInfoFromLoadContext(
|
|
|
|
const IPC::SerializedLoadContext &aLoadContext,
|
|
|
|
uint32_t& aAppId,
|
|
|
|
bool& aIsInBrowserElement)
|
|
|
|
{
|
|
|
|
// TODO: bug 782542: what to do when we get null loadContext? For now assume
|
|
|
|
// NECKO_NO_APP_ID.
|
|
|
|
aAppId = NECKO_NO_APP_ID;
|
|
|
|
aIsInBrowserElement = false;
|
|
|
|
|
|
|
|
if (aLoadContext.IsNotNull()) {
|
|
|
|
aAppId = aLoadContext.mAppId;
|
|
|
|
aIsInBrowserElement = aLoadContext.mIsInBrowserElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-25 23:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|