2015-05-25 21:21:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/ChannelInfo.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2015-09-01 00:26:30 +03:00
|
|
|
#include "nsContentUtils.h"
|
2015-05-25 21:21:05 +03:00
|
|
|
#include "nsIChannel.h"
|
2015-08-18 01:08:58 +03:00
|
|
|
#include "nsIDocument.h"
|
2015-05-25 21:21:05 +03:00
|
|
|
#include "nsIHttpChannel.h"
|
|
|
|
#include "nsSerializationHelper.h"
|
|
|
|
#include "mozilla/net/HttpBaseChannel.h"
|
|
|
|
#include "mozilla/ipc/ChannelInfo.h"
|
2015-06-03 01:01:26 +03:00
|
|
|
#include "nsNetUtil.h"
|
2015-05-25 21:21:05 +03:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2015-08-18 01:08:58 +03:00
|
|
|
void
|
|
|
|
ChannelInfo::InitFromDocument(nsIDocument* aDoc)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!mInited, "Cannot initialize the object twice");
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> securityInfo = aDoc->GetSecurityInfo();
|
|
|
|
if (securityInfo) {
|
|
|
|
SetSecurityInfo(securityInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
mInited = true;
|
|
|
|
}
|
|
|
|
|
2015-05-25 21:21:05 +03:00
|
|
|
void
|
|
|
|
ChannelInfo::InitFromChannel(nsIChannel* aChannel)
|
|
|
|
{
|
2015-06-03 01:01:26 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-05-25 21:21:05 +03:00
|
|
|
MOZ_ASSERT(!mInited, "Cannot initialize the object twice");
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> securityInfo;
|
|
|
|
aChannel->GetSecurityInfo(getter_AddRefs(securityInfo));
|
|
|
|
if (securityInfo) {
|
|
|
|
SetSecurityInfo(securityInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
mInited = true;
|
2015-09-01 00:26:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ChannelInfo::InitFromChromeGlobal(nsIGlobalObject* aGlobal)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mInited, "Cannot initialize the object twice");
|
|
|
|
MOZ_ASSERT(aGlobal);
|
|
|
|
|
|
|
|
MOZ_RELEASE_ASSERT(
|
|
|
|
nsContentUtils::IsSystemPrincipal(aGlobal->PrincipalOrNull()));
|
|
|
|
|
|
|
|
mSecurityInfo.Truncate();
|
|
|
|
mInited = true;
|
2015-05-25 21:21:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-09-10 23:50:58 +03:00
|
|
|
ChannelInfo::InitFromIPCChannelInfo(const mozilla::ipc::IPCChannelInfo& aChannelInfo)
|
2015-05-25 21:21:05 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mInited, "Cannot initialize the object twice");
|
|
|
|
|
|
|
|
mSecurityInfo = aChannelInfo.securityInfo();
|
|
|
|
|
|
|
|
mInited = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ChannelInfo::SetSecurityInfo(nsISupports* aSecurityInfo)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mSecurityInfo.IsEmpty(), "security info should only be set once");
|
|
|
|
nsCOMPtr<nsISerializable> serializable = do_QueryInterface(aSecurityInfo);
|
|
|
|
if (!serializable) {
|
|
|
|
NS_WARNING("A non-serializable object was passed to InternalResponse::SetSecurityInfo");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_SerializeToString(serializable, mSecurityInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ChannelInfo::ResurrectInfoOnChannel(nsIChannel* aChannel)
|
|
|
|
{
|
2015-06-03 01:01:26 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-05-25 21:21:05 +03:00
|
|
|
MOZ_ASSERT(mInited);
|
|
|
|
|
|
|
|
if (!mSecurityInfo.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsISupports> infoObj;
|
|
|
|
nsresult rv = NS_DeserializeObject(mSecurityInfo, getter_AddRefs(infoObj));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2016-01-25 22:03:13 +03:00
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel =
|
|
|
|
do_QueryInterface(aChannel);
|
|
|
|
MOZ_ASSERT(httpChannel);
|
|
|
|
net::HttpBaseChannel* httpBaseChannel =
|
|
|
|
static_cast<net::HttpBaseChannel*>(httpChannel.get());
|
|
|
|
rv = httpBaseChannel->OverrideSecurityInfo(infoObj);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
2015-05-25 21:21:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
mozilla::ipc::IPCChannelInfo
|
2015-05-25 21:21:05 +03:00
|
|
|
ChannelInfo::AsIPCChannelInfo() const
|
|
|
|
{
|
|
|
|
// This may be called when mInited is false, for example if we try to store
|
|
|
|
// a synthesized Response object into the Cache. Uninitialized and empty
|
|
|
|
// ChannelInfo objects are indistinguishable at the IPC level, so this is
|
|
|
|
// fine.
|
|
|
|
|
|
|
|
IPCChannelInfo ipcInfo;
|
|
|
|
|
|
|
|
ipcInfo.securityInfo() = mSecurityInfo;
|
|
|
|
|
|
|
|
return ipcInfo;
|
|
|
|
}
|