2010-03-26 02:02:28 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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-26 02:02:28 +03:00
|
|
|
|
|
|
|
#include "mozilla/net/CookieServiceParent.h"
|
2013-08-21 10:49:41 +04:00
|
|
|
#include "mozilla/dom/PContentParent.h"
|
2012-12-29 13:02:16 +04:00
|
|
|
#include "mozilla/net/NeckoParent.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
|
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
2010-03-26 02:02:28 +03:00
|
|
|
#include "nsCookieService.h"
|
2015-07-17 15:52:00 +03:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIPrivateBrowsingChannel.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsNetCID.h"
|
2012-12-29 13:02:16 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2013-10-19 00:57:55 +04:00
|
|
|
#include "SerializedLoadContext.h"
|
2010-03-26 02:02:28 +03:00
|
|
|
|
2012-08-23 23:33:46 +04:00
|
|
|
using namespace mozilla::ipc;
|
2013-08-21 10:49:41 +04:00
|
|
|
using mozilla::dom::PContentParent;
|
2012-12-29 13:02:16 +04:00
|
|
|
using mozilla::net::NeckoParent;
|
2012-12-16 22:09:39 +04:00
|
|
|
|
2015-07-17 15:52:00 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool
|
|
|
|
CreateDummyChannel(nsIURI* aHostURI, bool aIsPrivate, nsIChannel **aChannel)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
|
|
|
nsresult rv = ssm->GetNoAppCodebasePrincipal(aHostURI, getter_AddRefs(principal));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> dummyChannel;
|
|
|
|
NS_NewChannel(getter_AddRefs(dummyChannel), aHostURI, principal,
|
|
|
|
nsILoadInfo::SEC_NORMAL, nsIContentPolicy::TYPE_INVALID);
|
|
|
|
nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(dummyChannel);
|
|
|
|
if (!pbChannel) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pbChannel->SetPrivate(aIsPrivate);
|
|
|
|
dummyChannel.forget(aChannel);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-29 13:02:16 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
MOZ_WARN_UNUSED_RESULT
|
2013-08-21 10:49:41 +04:00
|
|
|
bool
|
|
|
|
CookieServiceParent::GetAppInfoFromParams(const IPC::SerializedLoadContext &aLoadContext,
|
|
|
|
uint32_t& aAppId,
|
|
|
|
bool& aIsInBrowserElement,
|
|
|
|
bool& aIsPrivate)
|
2012-02-08 22:37:07 +04:00
|
|
|
{
|
|
|
|
aAppId = NECKO_NO_APP_ID;
|
|
|
|
aIsInBrowserElement = false;
|
2012-12-29 04:18:38 +04:00
|
|
|
aIsPrivate = false;
|
2012-02-08 22:37:07 +04:00
|
|
|
|
2013-08-21 10:49:41 +04:00
|
|
|
const char* error = NeckoParent::GetValidatedAppInfo(aLoadContext,
|
|
|
|
Manager()->Manager(),
|
2012-12-29 13:02:16 +04:00
|
|
|
&aAppId,
|
|
|
|
&aIsInBrowserElement);
|
|
|
|
if (error) {
|
|
|
|
NS_WARNING(nsPrintfCString("CookieServiceParent: GetAppInfoFromParams: "
|
|
|
|
"FATAL error: %s: KILLING CHILD PROCESS\n",
|
|
|
|
error).get());
|
|
|
|
return false;
|
2012-02-08 22:37:07 +04:00
|
|
|
}
|
|
|
|
|
2012-12-29 13:02:16 +04:00
|
|
|
if (aLoadContext.IsPrivateBitValid()) {
|
2012-12-29 04:18:38 +04:00
|
|
|
aIsPrivate = aLoadContext.mUsePrivateBrowsing;
|
2012-12-29 13:02:16 +04:00
|
|
|
}
|
|
|
|
return true;
|
2012-02-08 22:37:07 +04:00
|
|
|
}
|
|
|
|
|
2010-03-26 02:02:28 +03: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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-02 22:44:13 +04:00
|
|
|
void
|
|
|
|
CookieServiceParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
// Implement me! Bug 1005181
|
|
|
|
}
|
|
|
|
|
2010-03-26 02:02:28 +03:00
|
|
|
bool
|
2012-08-23 23:33:46 +04:00
|
|
|
CookieServiceParent::RecvGetCookieString(const URIParams& aHost,
|
2010-10-19 20:37:03 +04:00
|
|
|
const bool& aIsForeign,
|
2010-03-26 02:02:28 +03:00
|
|
|
const bool& aFromHttp,
|
2012-09-18 20:04:04 +04:00
|
|
|
const IPC::SerializedLoadContext&
|
|
|
|
aLoadContext,
|
2010-03-26 02:02:28 +03:00
|
|
|
nsCString* aResult)
|
|
|
|
{
|
|
|
|
if (!mCookieService)
|
|
|
|
return true;
|
|
|
|
|
2010-10-19 20:37:03 +04:00
|
|
|
// Deserialize URI. Having a host URI is mandatory and should always be
|
2010-03-26 02:02:28 +03:00
|
|
|
// provided by the child; thus we consider failure fatal.
|
2012-08-23 23:33:46 +04:00
|
|
|
nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost);
|
2010-03-26 02:02:28 +03:00
|
|
|
if (!hostURI)
|
|
|
|
return false;
|
|
|
|
|
2012-09-18 20:04:04 +04:00
|
|
|
uint32_t appId;
|
2012-02-08 22:37:07 +04:00
|
|
|
bool isInBrowserElement, isPrivate;
|
2013-08-21 10:49:41 +04:00
|
|
|
bool valid = GetAppInfoFromParams(aLoadContext, appId,
|
2012-12-29 13:02:16 +04:00
|
|
|
isInBrowserElement, isPrivate);
|
|
|
|
if (!valid) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-18 20:04:04 +04:00
|
|
|
|
|
|
|
mCookieService->GetCookieStringInternal(hostURI, aIsForeign, aFromHttp, appId,
|
2012-12-16 22:09:39 +04:00
|
|
|
isInBrowserElement, isPrivate, *aResult);
|
2010-03-26 02:02:28 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-08-23 23:33:46 +04:00
|
|
|
CookieServiceParent::RecvSetCookieString(const URIParams& aHost,
|
2010-10-19 20:37:03 +04:00
|
|
|
const bool& aIsForeign,
|
2010-03-26 02:02:28 +03:00
|
|
|
const nsCString& aCookieString,
|
|
|
|
const nsCString& aServerTime,
|
2012-09-18 20:04:04 +04:00
|
|
|
const bool& aFromHttp,
|
|
|
|
const IPC::SerializedLoadContext&
|
2013-08-21 10:49:41 +04:00
|
|
|
aLoadContext)
|
2010-03-26 02:02:28 +03:00
|
|
|
{
|
|
|
|
if (!mCookieService)
|
|
|
|
return true;
|
|
|
|
|
2010-10-19 20:37:03 +04:00
|
|
|
// Deserialize URI. Having a host URI is mandatory and should always be
|
2010-03-26 02:02:28 +03:00
|
|
|
// provided by the child; thus we consider failure fatal.
|
2012-08-23 23:33:46 +04:00
|
|
|
nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost);
|
2010-03-26 02:02:28 +03:00
|
|
|
if (!hostURI)
|
|
|
|
return false;
|
|
|
|
|
2012-09-18 20:04:04 +04:00
|
|
|
uint32_t appId;
|
2012-02-08 22:37:07 +04:00
|
|
|
bool isInBrowserElement, isPrivate;
|
2013-08-21 10:49:41 +04:00
|
|
|
bool valid = GetAppInfoFromParams(aLoadContext, appId,
|
2012-12-29 13:02:16 +04:00
|
|
|
isInBrowserElement, isPrivate);
|
|
|
|
if (!valid) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-18 20:04:04 +04:00
|
|
|
|
2015-07-17 15:52:00 +03:00
|
|
|
// This is a gross hack. We've already computed everything we need to know
|
|
|
|
// for whether to set this cookie or not, but we need to communicate all of
|
|
|
|
// this information through to nsICookiePermission, which indirectly
|
|
|
|
// computes the information from the channel. We only care about the
|
|
|
|
// aIsPrivate argument as nsCookieService::SetCookieStringInternal deals
|
|
|
|
// with aIsForeign before we have to worry about nsCookiePermission trying
|
|
|
|
// to use the channel to inspect it.
|
|
|
|
nsCOMPtr<nsIChannel> dummyChannel;
|
|
|
|
if (!CreateDummyChannel(hostURI, isPrivate, getter_AddRefs(dummyChannel))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-15 11:40:17 +04:00
|
|
|
nsDependentCString cookieString(aCookieString, 0);
|
2012-09-18 20:04:04 +04:00
|
|
|
mCookieService->SetCookieStringInternal(hostURI, aIsForeign, cookieString,
|
|
|
|
aServerTime, aFromHttp, appId,
|
2015-07-17 15:52:00 +03:00
|
|
|
isInBrowserElement, isPrivate, dummyChannel);
|
2010-03-26 02:02:28 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-03 14:14:37 +04:00
|
|
|
mozilla::ipc::IProtocol*
|
|
|
|
CookieServiceParent::CloneProtocol(Channel* aChannel,
|
|
|
|
mozilla::ipc::ProtocolCloneContext* aCtx)
|
|
|
|
{
|
|
|
|
NeckoParent* manager = aCtx->GetNeckoParent();
|
|
|
|
nsAutoPtr<PCookieServiceParent> actor(manager->AllocPCookieServiceParent());
|
|
|
|
if (!actor || !manager->RecvPCookieServiceConstructor(actor)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return actor.forget();
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
2010-03-26 02:02:28 +03:00
|
|
|
|