Bug 1645901 - handle cookie setting in child process for Set-Cookie response, r=baku,mayhemer,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D82130
This commit is contained in:
Junior Hsu 2020-07-07 15:19:09 +00:00
Родитель 99149df7fc
Коммит da7ef4914b
5 изменённых файлов: 36 добавлений и 2 удалений

Просмотреть файл

@ -547,6 +547,10 @@ void HttpChannelChild::OnStartRequest(
false);
}
if (!aArgs.cookie().IsEmpty()) {
SetCookie(aArgs.cookie());
}
if (aArgs.shouldWaitForOnStartRequestSent() &&
!mRecvOnStartRequestSentCalled) {
LOG((" > pending DoOnStartRequest until RecvOnStartRequestSent\n"));

Просмотреть файл

@ -49,6 +49,7 @@ struct HttpChannelOnStartRequestArgs
nsCString appCacheClientId;
nsIReferrerInfo overrideReferrerInfo;
bool shouldWaitForOnStartRequestSent;
nsCString cookie;
};
} // namespace ipc

Просмотреть файл

@ -1523,6 +1523,9 @@ HttpChannelParent::OnStartRequest(nsIRequest* aRequest) {
if (mOverrideReferrerInfo) {
args.overrideReferrerInfo() = ToRefPtr(std::move(mOverrideReferrerInfo));
}
if (!mCookie.IsEmpty()) {
args.cookie() = std::move(mCookie);
}
nsHttpRequestHead* requestHead = chan->GetRequestHead();
// !!! We need to lock headers and please don't forget to unlock them !!!
@ -2686,5 +2689,12 @@ auto HttpChannelParent::AttachStreamFilter(
std::move(aParentEndpoint), std::move(aChildEndpoint));
}
void HttpChannelParent::SetCookie(nsCString&& aCookie) {
LOG(("HttpChannelParent::SetCookie [this=%p]", this));
MOZ_ASSERT(!mAfterOnStartRequestBegun);
MOZ_ASSERT(mCookie.IsEmpty());
mCookie = std::move(aCookie);
}
} // namespace net
} // namespace mozilla

Просмотреть файл

@ -134,6 +134,15 @@ class HttpChannelParent final : public nsIInterfaceRequestor,
// BeginConnect.
void OverrideReferrerInfoDuringBeginConnect(nsIReferrerInfo* aReferrerInfo);
// Set the cookie string, which will be informed to the child actor during
// PHttpBackgroundChannel::OnStartRequest. Note that CookieService also sends
// the information to all actors via PContent, a main thread IPC, which could
// be slower than background IPC PHttpBackgroundChannel::OnStartRequest.
// Therefore, another cookie notification via PBackground is needed to
// guarantee the listener in child has the necessary cookies before
// OnStartRequest.
void SetCookie(nsCString&& aCookie);
using ChildEndpointPromise =
MozPromise<ipc::Endpoint<extensions::PStreamFilterChild>, bool, true>;
[[nodiscard]] RefPtr<ChildEndpointPromise> AttachStreamFilter(
@ -326,6 +335,10 @@ class HttpChannelParent final : public nsIInterfaceRequestor,
// original one. This info will be sent in OnStartRequest.
nsCOMPtr<nsIReferrerInfo> mOverrideReferrerInfo;
// The cookie string in Set-Cookie header. This info will be sent in
// OnStartRequest.
nsCString mCookie;
// OnStatus is always called before OnProgress.
// Set true in OnStatus if next OnProgress can be ignored
// since the information can be recontructed from ODA.

Просмотреть файл

@ -2602,9 +2602,15 @@ nsresult nsHttpChannel::ContinueProcessResponse1() {
// for Strict-Transport-Security.
if (!(mTransaction && mTransaction->ProxyConnectFailed()) &&
(httpStatus != 407)) {
nsAutoCString cookie;
if (NS_SUCCEEDED(mResponseHead->GetHeader(nsHttp::Set_Cookie, cookie))) {
if (nsAutoCString cookie;
NS_SUCCEEDED(mResponseHead->GetHeader(nsHttp::Set_Cookie, cookie))) {
SetCookie(cookie);
nsCOMPtr<nsIParentChannel> parentChannel;
NS_QueryNotificationCallbacks(this, parentChannel);
if (RefPtr<HttpChannelParent> httpParent =
do_QueryObject(parentChannel)) {
httpParent->SetCookie(std::move(cookie));
}
}
// Given a successful connection, process any STS or PKP data that's