Bug 1525245 - Stabilize cookiePolicy/cookiePermission for live documents - part 12 - nsICookieSettings for the channel creation, r=ckerschb,asuth,Ehsan

Differential Revision: https://phabricator.services.mozilla.com/D21538
This commit is contained in:
Andrea Marchesini
2019-03-07 10:21:15 +00:00
parent d27acc34fe
commit 83054c5a7a
47 changed files with 327 additions and 109 deletions

View File

@@ -82,7 +82,8 @@ class EventSourceImpl final : public nsIObserver,
NS_DECL_NSIEVENTTARGET_FULL NS_DECL_NSIEVENTTARGET_FULL
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
explicit EventSourceImpl(EventSource* aEventSource); EventSourceImpl(EventSource* aEventSource,
nsICookieSettings* aCookieSettings);
enum { CONNECTING = 0U, OPEN = 1U, CLOSED = 2U }; enum { CONNECTING = 0U, OPEN = 1U, CLOSED = 2U };
@@ -291,6 +292,8 @@ class EventSourceImpl final : public nsIObserver,
uint64_t mInnerWindowID; uint64_t mInnerWindowID;
private: private:
nsCOMPtr<nsICookieSettings> mCookieSettings;
// Pointer to the target thread for checking whether we are // Pointer to the target thread for checking whether we are
// on the target thread. This is intentionally a non-owning // on the target thread. This is intentionally a non-owning
// pointer in order not to affect the thread destruction // pointer in order not to affect the thread destruction
@@ -316,7 +319,8 @@ NS_IMPL_ISUPPORTS(EventSourceImpl, nsIObserver, nsIStreamListener,
nsIInterfaceRequestor, nsISupportsWeakReference, nsIInterfaceRequestor, nsISupportsWeakReference,
nsIEventTarget, nsIThreadRetargetableStreamListener) nsIEventTarget, nsIThreadRetargetableStreamListener)
EventSourceImpl::EventSourceImpl(EventSource* aEventSource) EventSourceImpl::EventSourceImpl(EventSource* aEventSource,
nsICookieSettings* aCookieSettings)
: mEventSource(aEventSource), : mEventSource(aEventSource),
mReconnectionTime(0), mReconnectionTime(0),
mStatus(PARSE_STATE_OFF), mStatus(PARSE_STATE_OFF),
@@ -328,6 +332,7 @@ EventSourceImpl::EventSourceImpl(EventSource* aEventSource)
mScriptLine(0), mScriptLine(0),
mScriptColumn(0), mScriptColumn(0),
mInnerWindowID(0), mInnerWindowID(0),
mCookieSettings(aCookieSettings),
mTargetThread(NS_GetCurrentThread()) { mTargetThread(NS_GetCurrentThread()) {
MOZ_ASSERT(mEventSource); MOZ_ASSERT(mEventSource);
if (!mIsMainThread) { if (!mIsMainThread) {
@@ -971,6 +976,8 @@ nsresult EventSourceImpl::InitChannelAndRequestEventSource() {
nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIChannel> channel;
// If we have the document, use it // If we have the document, use it
if (doc) { if (doc) {
MOZ_ASSERT(mCookieSettings == doc->CookieSettings());
nsCOMPtr<nsILoadGroup> loadGroup = doc->GetDocumentLoadGroup(); nsCOMPtr<nsILoadGroup> loadGroup = doc->GetDocumentLoadGroup();
rv = NS_NewChannel(getter_AddRefs(channel), mSrc, doc, securityFlags, rv = NS_NewChannel(getter_AddRefs(channel), mSrc, doc, securityFlags,
nsIContentPolicy::TYPE_INTERNAL_EVENTSOURCE, nsIContentPolicy::TYPE_INTERNAL_EVENTSOURCE,
@@ -982,6 +989,7 @@ nsresult EventSourceImpl::InitChannelAndRequestEventSource() {
// otherwise use the principal // otherwise use the principal
rv = NS_NewChannel(getter_AddRefs(channel), mSrc, mPrincipal, securityFlags, rv = NS_NewChannel(getter_AddRefs(channel), mSrc, mPrincipal, securityFlags,
nsIContentPolicy::TYPE_INTERNAL_EVENTSOURCE, nsIContentPolicy::TYPE_INTERNAL_EVENTSOURCE,
mCookieSettings,
nullptr, // aPerformanceStorage nullptr, // aPerformanceStorage
nullptr, // loadGroup nullptr, // loadGroup
nullptr, // aCallbacks nullptr, // aCallbacks
@@ -1777,12 +1785,14 @@ EventSourceImpl::CheckListenerChain() {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
EventSource::EventSource(nsPIDOMWindowInner* aOwnerWindow, EventSource::EventSource(nsPIDOMWindowInner* aOwnerWindow,
nsICookieSettings* aCookieSettings,
bool aWithCredentials) bool aWithCredentials)
: DOMEventTargetHelper(aOwnerWindow), : DOMEventTargetHelper(aOwnerWindow),
mWithCredentials(aWithCredentials), mWithCredentials(aWithCredentials),
mIsMainThread(true), mIsMainThread(true),
mKeepingAlive(false) { mKeepingAlive(false) {
mImpl = new EventSourceImpl(this); MOZ_ASSERT(aCookieSettings);
mImpl = new EventSourceImpl(this, aCookieSettings);
} }
EventSource::~EventSource() {} EventSource::~EventSource() {}
@@ -1806,8 +1816,24 @@ already_AddRefed<EventSource> EventSource::Constructor(
MOZ_ASSERT(!NS_IsMainThread() || ownerWindow); MOZ_ASSERT(!NS_IsMainThread() || ownerWindow);
RefPtr<EventSource> eventSource = nsCOMPtr<nsICookieSettings> cookieSettings;
new EventSource(ownerWindow, aEventSourceInitDict.mWithCredentials); if (ownerWindow) {
Document* doc = ownerWindow->GetExtantDoc();
if (NS_WARN_IF(!doc)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
cookieSettings = doc->CookieSettings();
} else {
// Worker side.
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate);
cookieSettings = workerPrivate->CookieSettings();
}
RefPtr<EventSource> eventSource = new EventSource(
ownerWindow, cookieSettings, aEventSourceInitDict.mWithCredentials);
RefPtr<EventSourceImpl> eventSourceImp = eventSource->mImpl; RefPtr<EventSourceImpl> eventSourceImp = eventSource->mImpl;
if (NS_IsMainThread()) { if (NS_IsMainThread()) {

View File

@@ -25,6 +25,7 @@
#include "nsDeque.h" #include "nsDeque.h"
class nsPIDOMWindowInner; class nsPIDOMWindowInner;
class nsICookieSettings;
namespace mozilla { namespace mozilla {
@@ -80,7 +81,8 @@ class EventSource final : public DOMEventTargetHelper {
void Close(); void Close();
private: private:
EventSource(nsPIDOMWindowInner* aOwnerWindow, bool aWithCredentials); EventSource(nsPIDOMWindowInner* aOwnerWindow,
nsICookieSettings* aCookieSettings, bool aWithCredentials);
virtual ~EventSource(); virtual ~EventSource();
// prevent bad usage // prevent bad usage
EventSource(const EventSource& x) = delete; EventSource(const EventSource& x) = delete;

View File

@@ -279,13 +279,14 @@ nsSyncLoader::GetInterface(const nsIID &aIID, void **aResult) {
nsresult nsSyncLoadService::LoadDocument( nsresult nsSyncLoadService::LoadDocument(
nsIURI *aURI, nsContentPolicyType aContentPolicyType, nsIURI *aURI, nsContentPolicyType aContentPolicyType,
nsIPrincipal *aLoaderPrincipal, nsSecurityFlags aSecurityFlags, nsIPrincipal *aLoaderPrincipal, nsSecurityFlags aSecurityFlags,
nsILoadGroup *aLoadGroup, bool aForceToXML, ReferrerPolicy aReferrerPolicy, nsILoadGroup *aLoadGroup, nsICookieSettings *aCookieSettings,
Document **aResult) { bool aForceToXML, ReferrerPolicy aReferrerPolicy, Document **aResult) {
nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIChannel> channel;
nsresult rv = NS_NewChannel(getter_AddRefs(channel), aURI, aLoaderPrincipal, nsresult rv =
aSecurityFlags, aContentPolicyType, NS_NewChannel(getter_AddRefs(channel), aURI, aLoaderPrincipal,
nullptr, // PerformanceStorage aSecurityFlags, aContentPolicyType, aCookieSettings,
aLoadGroup); nullptr, // PerformanceStorage
aLoadGroup);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (!aForceToXML) { if (!aForceToXML) {

View File

@@ -15,6 +15,7 @@
#include "nscore.h" #include "nscore.h"
#include "mozilla/net/ReferrerPolicy.h" #include "mozilla/net/ReferrerPolicy.h"
class nsICookieSettings;
class nsIInputStream; class nsIInputStream;
class nsILoadGroup; class nsILoadGroup;
class nsIStreamListener; class nsIStreamListener;
@@ -44,13 +45,12 @@ class nsSyncLoadService {
* @param referrerPolicy Referrer policy. * @param referrerPolicy Referrer policy.
* @param aResult [out] The document loaded from the URI. * @param aResult [out] The document loaded from the URI.
*/ */
static nsresult LoadDocument(nsIURI* aURI, static nsresult LoadDocument(
nsContentPolicyType aContentPolicyType, nsIURI* aURI, nsContentPolicyType aContentPolicyType,
nsIPrincipal* aLoaderPrincipal, nsIPrincipal* aLoaderPrincipal, nsSecurityFlags aSecurityFlags,
nsSecurityFlags aSecurityFlags, nsILoadGroup* aLoadGroup, nsICookieSettings* aCookieSettings,
nsILoadGroup* aLoadGroup, bool aForceToXML, bool aForceToXML, mozilla::net::ReferrerPolicy aReferrerPolicy,
mozilla::net::ReferrerPolicy aReferrerPolicy, mozilla::dom::Document** aResult);
mozilla::dom::Document** aResult);
/** /**
* Read input stream aIn in chunks and deliver synchronously to aListener. * Read input stream aIn in chunks and deliver synchronously to aListener.

View File

@@ -38,6 +38,7 @@
#include "mozilla/dom/Response.h" #include "mozilla/dom/Response.h"
#include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/URLSearchParams.h" #include "mozilla/dom/URLSearchParams.h"
#include "mozilla/net/CookieSettings.h"
#include "mozilla/Telemetry.h" #include "mozilla/Telemetry.h"
#include "BodyExtractor.h" #include "BodyExtractor.h"
@@ -389,6 +390,7 @@ class MainThreadFetchRunnable : public Runnable {
// so pass false as the last argument to FetchDriver(). // so pass false as the last argument to FetchDriver().
fetch = new FetchDriver(mRequest, principal, loadGroup, fetch = new FetchDriver(mRequest, principal, loadGroup,
workerPrivate->MainThreadEventTarget(), workerPrivate->MainThreadEventTarget(),
workerPrivate->CookieSettings(),
workerPrivate->GetPerformanceStorage(), false); workerPrivate->GetPerformanceStorage(), false);
nsAutoCString spec; nsAutoCString spec;
if (proxy->GetWorkerPrivate()->GetBaseURI()) { if (proxy->GetWorkerPrivate()->GetBaseURI()) {
@@ -462,6 +464,7 @@ already_AddRefed<Promise> FetchRequest(nsIGlobalObject* aGlobal,
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal); nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal);
nsCOMPtr<Document> doc; nsCOMPtr<Document> doc;
nsCOMPtr<nsILoadGroup> loadGroup; nsCOMPtr<nsILoadGroup> loadGroup;
nsCOMPtr<nsICookieSettings> cookieSettings;
nsIPrincipal* principal; nsIPrincipal* principal;
bool isTrackingFetch = false; bool isTrackingFetch = false;
if (window) { if (window) {
@@ -472,6 +475,7 @@ already_AddRefed<Promise> FetchRequest(nsIGlobalObject* aGlobal,
} }
principal = doc->NodePrincipal(); principal = doc->NodePrincipal();
loadGroup = doc->GetDocumentLoadGroup(); loadGroup = doc->GetDocumentLoadGroup();
cookieSettings = doc->CookieSettings();
nsAutoCString fileNameString; nsAutoCString fileNameString;
if (nsJSUtils::GetCallingLocation(cx, fileNameString)) { if (nsJSUtils::GetCallingLocation(cx, fileNameString)) {
@@ -488,6 +492,8 @@ already_AddRefed<Promise> FetchRequest(nsIGlobalObject* aGlobal,
aRv.Throw(rv); aRv.Throw(rv);
return nullptr; return nullptr;
} }
cookieSettings = mozilla::net::CookieSettings::Create();
} }
Telemetry::Accumulate(Telemetry::FETCH_IS_MAINTHREAD, 1); Telemetry::Accumulate(Telemetry::FETCH_IS_MAINTHREAD, 1);
@@ -496,7 +502,7 @@ already_AddRefed<Promise> FetchRequest(nsIGlobalObject* aGlobal,
p, observer, signalImpl, request->MozErrors()); p, observer, signalImpl, request->MozErrors());
RefPtr<FetchDriver> fetch = new FetchDriver( RefPtr<FetchDriver> fetch = new FetchDriver(
r, principal, loadGroup, aGlobal->EventTargetFor(TaskCategory::Other), r, principal, loadGroup, aGlobal->EventTargetFor(TaskCategory::Other),
nullptr, // PerformanceStorage cookieSettings, nullptr, // PerformanceStorage
isTrackingFetch); isTrackingFetch);
fetch->SetDocument(doc); fetch->SetDocument(doc);
resolver->SetLoadGroup(loadGroup); resolver->SetLoadGroup(loadGroup);

View File

@@ -323,12 +323,14 @@ NS_IMPL_ISUPPORTS(FetchDriver, nsIStreamListener, nsIChannelEventSink,
FetchDriver::FetchDriver(InternalRequest* aRequest, nsIPrincipal* aPrincipal, FetchDriver::FetchDriver(InternalRequest* aRequest, nsIPrincipal* aPrincipal,
nsILoadGroup* aLoadGroup, nsILoadGroup* aLoadGroup,
nsIEventTarget* aMainThreadEventTarget, nsIEventTarget* aMainThreadEventTarget,
nsICookieSettings* aCookieSettings,
PerformanceStorage* aPerformanceStorage, PerformanceStorage* aPerformanceStorage,
bool aIsTrackingFetch) bool aIsTrackingFetch)
: mPrincipal(aPrincipal), : mPrincipal(aPrincipal),
mLoadGroup(aLoadGroup), mLoadGroup(aLoadGroup),
mRequest(aRequest), mRequest(aRequest),
mMainThreadEventTarget(aMainThreadEventTarget), mMainThreadEventTarget(aMainThreadEventTarget),
mCookieSettings(aCookieSettings),
mPerformanceStorage(aPerformanceStorage), mPerformanceStorage(aPerformanceStorage),
mNeedToObserveOnDataAvailable(false), mNeedToObserveOnDataAvailable(false),
mIsTrackingFetch(aIsTrackingFetch), mIsTrackingFetch(aIsTrackingFetch),
@@ -509,22 +511,24 @@ nsresult FetchDriver::HttpFetch(
nsIRequest::LOAD_BACKGROUND | bypassFlag | nsIChannel::LOAD_CLASSIFY_URI; nsIRequest::LOAD_BACKGROUND | bypassFlag | nsIChannel::LOAD_CLASSIFY_URI;
if (mDocument) { if (mDocument) {
MOZ_ASSERT(mDocument->NodePrincipal() == mPrincipal); MOZ_ASSERT(mDocument->NodePrincipal() == mPrincipal);
MOZ_ASSERT(mDocument->CookieSettings() == mCookieSettings);
rv = NS_NewChannel(getter_AddRefs(chan), uri, mDocument, secFlags, rv = NS_NewChannel(getter_AddRefs(chan), uri, mDocument, secFlags,
mRequest->ContentPolicyType(), mRequest->ContentPolicyType(),
nullptr, /* aPerformanceStorage */ nullptr, /* aPerformanceStorage */
mLoadGroup, nullptr, /* aCallbacks */ mLoadGroup, nullptr, /* aCallbacks */
loadFlags, ios); loadFlags, ios);
} else if (mClientInfo.isSome()) { } else if (mClientInfo.isSome()) {
rv = NS_NewChannel(getter_AddRefs(chan), uri, mPrincipal, mClientInfo.ref(),
mController, secFlags, mRequest->ContentPolicyType(),
mCookieSettings, mPerformanceStorage, mLoadGroup,
nullptr, /* aCallbacks */
loadFlags, ios);
} else {
rv = rv =
NS_NewChannel(getter_AddRefs(chan), uri, mPrincipal, mClientInfo.ref(), NS_NewChannel(getter_AddRefs(chan), uri, mPrincipal, secFlags,
mController, secFlags, mRequest->ContentPolicyType(), mRequest->ContentPolicyType(), mCookieSettings,
mPerformanceStorage, mLoadGroup, nullptr, /* aCallbacks */ mPerformanceStorage, mLoadGroup, nullptr, /* aCallbacks */
loadFlags, ios); loadFlags, ios);
} else {
rv = NS_NewChannel(getter_AddRefs(chan), uri, mPrincipal, secFlags,
mRequest->ContentPolicyType(), mPerformanceStorage,
mLoadGroup, nullptr, /* aCallbacks */
loadFlags, ios);
} }
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);

View File

@@ -21,6 +21,7 @@
#include "mozilla/net/ReferrerPolicy.h" #include "mozilla/net/ReferrerPolicy.h"
class nsIConsoleReportCollector; class nsIConsoleReportCollector;
class nsICookieSettings;
class nsICSPEventListener; class nsICSPEventListener;
class nsIEventTarget; class nsIEventTarget;
class nsIOutputStream; class nsIOutputStream;
@@ -101,6 +102,7 @@ class FetchDriver final : public nsIStreamListener,
FetchDriver(InternalRequest* aRequest, nsIPrincipal* aPrincipal, FetchDriver(InternalRequest* aRequest, nsIPrincipal* aPrincipal,
nsILoadGroup* aLoadGroup, nsIEventTarget* aMainThreadEventTarget, nsILoadGroup* aLoadGroup, nsIEventTarget* aMainThreadEventTarget,
nsICookieSettings* aCookieSettings,
PerformanceStorage* aPerformanceStorage, bool aIsTrackingFetch); PerformanceStorage* aPerformanceStorage, bool aIsTrackingFetch);
nsresult Fetch(AbortSignalImpl* aSignalImpl, FetchDriverObserver* aObserver); nsresult Fetch(AbortSignalImpl* aSignalImpl, FetchDriverObserver* aObserver);
@@ -136,6 +138,8 @@ class FetchDriver final : public nsIStreamListener,
nsAutoPtr<SRICheckDataVerifier> mSRIDataVerifier; nsAutoPtr<SRICheckDataVerifier> mSRIDataVerifier;
nsCOMPtr<nsIEventTarget> mMainThreadEventTarget; nsCOMPtr<nsIEventTarget> mMainThreadEventTarget;
nsCOMPtr<nsICookieSettings> mCookieSettings;
// This is set only when Fetch is used in workers. // This is set only when Fetch is used in workers.
RefPtr<PerformanceStorage> mPerformanceStorage; RefPtr<PerformanceStorage> mPerformanceStorage;

View File

@@ -1016,6 +1016,7 @@ nsresult nsCSPContext::SendReports(
mLoadingPrincipal, mLoadingPrincipal,
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_CSP_REPORT, nsIContentPolicy::TYPE_CSP_REPORT,
nullptr, // nsICookieSettings
nullptr, // PerformanceStorage nullptr, // PerformanceStorage
nullptr, // aLoadGroup nullptr, // aLoadGroup
nullptr, // aCallbacks nullptr, // aCallbacks

View File

@@ -40,6 +40,7 @@
#include "mozilla/dom/WorkerRunnable.h" #include "mozilla/dom/WorkerRunnable.h"
#include "mozilla/dom/WorkerScope.h" #include "mozilla/dom/WorkerScope.h"
#include "mozilla/dom/ipc/StructuredCloneData.h" #include "mozilla/dom/ipc/StructuredCloneData.h"
#include "mozilla/net/CookieSettings.h"
#include "mozilla/net/NeckoChannelParams.h" #include "mozilla/net/NeckoChannelParams.h"
#include "mozilla/StaticPrefs.h" #include "mozilla/StaticPrefs.h"
#include "mozilla/Unused.h" #include "mozilla/Unused.h"
@@ -1731,6 +1732,10 @@ nsresult ServiceWorkerPrivate::SpawnWorkerIfNeeded(WakeUpReason aWhy,
nsContentUtils::StorageAllowedForServiceWorker(info.mPrincipal); nsContentUtils::StorageAllowedForServiceWorker(info.mPrincipal);
info.mStorageAllowed = info.mStorageAllowed =
access > nsContentUtils::StorageAccess::ePrivateBrowsing; access > nsContentUtils::StorageAccess::ePrivateBrowsing;
info.mCookieSettings = mozilla::net::CookieSettings::Create();
MOZ_ASSERT(info.mCookieSettings);
info.mOriginAttributes = mInfo->GetOriginAttributes(); info.mOriginAttributes = mInfo->GetOriginAttributes();
// Verify that we don't have any CSP on pristine principal. // Verify that we don't have any CSP on pristine principal.

View File

@@ -16,6 +16,7 @@
#include "mozilla/dom/WorkerCommon.h" #include "mozilla/dom/WorkerCommon.h"
#include "mozilla/ipc/BackgroundUtils.h" #include "mozilla/ipc/BackgroundUtils.h"
#include "mozilla/ipc/PBackgroundSharedTypes.h" #include "mozilla/ipc/PBackgroundSharedTypes.h"
#include "mozilla/net/CookieSettings.h"
#include "nsICacheInfoChannel.h" #include "nsICacheInfoChannel.h"
#include "nsIHttpChannelInternal.h" #include "nsIHttpChannelInternal.h"
#include "nsIStreamLoader.h" #include "nsIStreamLoader.h"
@@ -657,12 +658,17 @@ nsresult CompareNetwork::Initialize(nsIPrincipal* aPrincipal,
mIsMainScript ? nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER mIsMainScript ? nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER
: nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS; : nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS;
// Create a new cookieSettings.
nsCOMPtr<nsICookieSettings> cookieSettings =
mozilla::net::CookieSettings::Create();
// Note that because there is no "serviceworker" RequestContext type, we can // Note that because there is no "serviceworker" RequestContext type, we can
// use the TYPE_INTERNAL_SCRIPT content policy types when loading a service // use the TYPE_INTERNAL_SCRIPT content policy types when loading a service
// worker. // worker.
rv = NS_NewChannel(getter_AddRefs(mChannel), uri, aPrincipal, secFlags, rv = NS_NewChannel(getter_AddRefs(mChannel), uri, aPrincipal, secFlags,
contentPolicyType, nullptr, /* aPerformanceStorage */ contentPolicyType, cookieSettings,
loadGroup, nullptr /* aCallbacks */, mLoadFlags); nullptr /* aPerformanceStorage */, loadGroup,
nullptr /* aCallbacks */, mLoadFlags);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }

View File

@@ -62,6 +62,7 @@
#include "nsIMIMEInfo.h" #include "nsIMIMEInfo.h"
#include "mozilla/dom/HTMLInputElement.h" #include "mozilla/dom/HTMLInputElement.h"
#include "mozilla/dom/HTMLSharedElement.h" #include "mozilla/dom/HTMLSharedElement.h"
#include "mozilla/net/CookieSettings.h"
#include "mozilla/Printf.h" #include "mozilla/Printf.h"
using namespace mozilla; using namespace mozilla;
@@ -1234,11 +1235,16 @@ nsresult nsWebBrowserPersist::SaveURIInternal(
loadFlags |= nsIRequest::LOAD_FROM_CACHE; loadFlags |= nsIRequest::LOAD_FROM_CACHE;
} }
// Create a new cookieSettings for this download in order to send cookies
// based on the current state of the prefs/permissions.
nsCOMPtr<nsICookieSettings> cookieSettings =
mozilla::net::CookieSettings::Create();
// Open a channel to the URI // Open a channel to the URI
nsCOMPtr<nsIChannel> inputChannel; nsCOMPtr<nsIChannel> inputChannel;
rv = NS_NewChannel(getter_AddRefs(inputChannel), aURI, aTriggeringPrincipal, rv = NS_NewChannel(getter_AddRefs(inputChannel), aURI, aTriggeringPrincipal,
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_SAVEAS_DOWNLOAD, nsIContentPolicy::TYPE_SAVEAS_DOWNLOAD, cookieSettings,
nullptr, // aPerformanceStorage nullptr, // aPerformanceStorage
nullptr, // aLoadGroup nullptr, // aLoadGroup
static_cast<nsIInterfaceRequestor *>(this), loadFlags); static_cast<nsIInterfaceRequestor *>(this), loadFlags);

View File

@@ -125,17 +125,15 @@ nsresult ConstructURI(const nsAString& aScriptURL, nsIURI* baseURI,
return NS_OK; return NS_OK;
} }
nsresult ChannelFromScriptURL(nsIPrincipal* principal, Document* parentDoc, nsresult ChannelFromScriptURL(
WorkerPrivate* aWorkerPrivate, nsIPrincipal* principal, Document* parentDoc, WorkerPrivate* aWorkerPrivate,
nsILoadGroup* loadGroup, nsIIOService* ios, nsILoadGroup* loadGroup, nsIIOService* ios,
nsIScriptSecurityManager* secMan, nsIScriptSecurityManager* secMan, nsIURI* aScriptURL,
nsIURI* aScriptURL, const Maybe<ClientInfo>& aClientInfo,
const Maybe<ClientInfo>& aClientInfo, const Maybe<ServiceWorkerDescriptor>& aController, bool aIsMainScript,
const Maybe<ServiceWorkerDescriptor>& aController, WorkerScriptType aWorkerScriptType,
bool aIsMainScript, nsContentPolicyType aMainScriptContentPolicyType, nsLoadFlags aLoadFlags,
WorkerScriptType aWorkerScriptType, nsICookieSettings* aCookieSettings, nsIChannel** aChannel) {
nsContentPolicyType aMainScriptContentPolicyType,
nsLoadFlags aLoadFlags, nsIChannel** aChannel) {
AssertIsOnMainThread(); AssertIsOnMainThread();
nsresult rv; nsresult rv;
@@ -206,11 +204,7 @@ nsresult ChannelFromScriptURL(nsIPrincipal* principal, Document* parentDoc,
nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER); nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER);
nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIChannel> channel;
// If we have the document, use it. Unfortunately, for dedicated workers if (parentDoc) {
// 'parentDoc' ends up being the parent document, which is not the document
// that we want to use. So make sure to avoid using 'parentDoc' in that
// situation.
if (parentDoc && parentDoc->NodePrincipal() == principal) {
rv = NS_NewChannel(getter_AddRefs(channel), uri, parentDoc, secFlags, rv = NS_NewChannel(getter_AddRefs(channel), uri, parentDoc, secFlags,
contentPolicyType, contentPolicyType,
nullptr, // aPerformanceStorage nullptr, // aPerformanceStorage
@@ -234,13 +228,13 @@ nsresult ChannelFromScriptURL(nsIPrincipal* principal, Document* parentDoc,
if (aClientInfo.isSome()) { if (aClientInfo.isSome()) {
rv = NS_NewChannel(getter_AddRefs(channel), uri, principal, rv = NS_NewChannel(getter_AddRefs(channel), uri, principal,
aClientInfo.ref(), aController, secFlags, aClientInfo.ref(), aController, secFlags,
contentPolicyType, performanceStorage, loadGroup, contentPolicyType, aCookieSettings, performanceStorage,
nullptr, // aCallbacks loadGroup, nullptr, // aCallbacks
aLoadFlags, ios); aLoadFlags, ios);
} else { } else {
rv = NS_NewChannel(getter_AddRefs(channel), uri, principal, secFlags, rv = NS_NewChannel(getter_AddRefs(channel), uri, principal, secFlags,
contentPolicyType, performanceStorage, loadGroup, contentPolicyType, aCookieSettings, performanceStorage,
nullptr, // aCallbacks loadGroup, nullptr, // aCallbacks
aLoadFlags, ios); aLoadFlags, ios);
} }
@@ -960,11 +954,11 @@ class ScriptLoaderRunnable final : public nsIRunnable, public nsINamed {
return rv; return rv;
} }
rv = ChannelFromScriptURL(principal, parentDoc, mWorkerPrivate, loadGroup, rv = ChannelFromScriptURL(
ios, secMan, url, mClientInfo, mController, principal, parentDoc, mWorkerPrivate, loadGroup, ios, secMan, url,
IsMainWorkerScript(), mWorkerScriptType, mClientInfo, mController, IsMainWorkerScript(), mWorkerScriptType,
mWorkerPrivate->ContentPolicyType(), loadFlags, mWorkerPrivate->ContentPolicyType(), loadFlags,
getter_AddRefs(channel)); mWorkerPrivate->CookieSettings(), getter_AddRefs(channel));
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@@ -1829,6 +1823,7 @@ class ChannelGetterRunnable final : public WorkerMainThreadRunnable {
nsCOMPtr<Document> parentDoc = mWorkerPrivate->GetDocument(); nsCOMPtr<Document> parentDoc = mWorkerPrivate->GetDocument();
mLoadInfo.mLoadGroup = mWorkerPrivate->GetLoadGroup(); mLoadInfo.mLoadGroup = mWorkerPrivate->GetLoadGroup();
mLoadInfo.mCookieSettings = mWorkerPrivate->CookieSettings();
// Nested workers use default uri encoding. // Nested workers use default uri encoding.
nsCOMPtr<nsIURI> url; nsCOMPtr<nsIURI> url;
@@ -1844,7 +1839,8 @@ class ChannelGetterRunnable final : public WorkerMainThreadRunnable {
mLoadInfo.mLoadingPrincipal, parentDoc, mLoadInfo.mLoadGroup, url, mLoadInfo.mLoadingPrincipal, parentDoc, mLoadInfo.mLoadGroup, url,
clientInfo, clientInfo,
// Nested workers are always dedicated. // Nested workers are always dedicated.
nsIContentPolicy::TYPE_INTERNAL_WORKER, getter_AddRefs(channel)); nsIContentPolicy::TYPE_INTERNAL_WORKER, mLoadInfo.mCookieSettings,
getter_AddRefs(channel));
NS_ENSURE_SUCCESS(mResult, true); NS_ENSURE_SUCCESS(mResult, true);
mResult = mLoadInfo.SetPrincipalFromChannel(channel); mResult = mLoadInfo.SetPrincipalFromChannel(channel);
@@ -2159,7 +2155,8 @@ namespace workerinternals {
nsresult ChannelFromScriptURLMainThread( nsresult ChannelFromScriptURLMainThread(
nsIPrincipal* aPrincipal, Document* aParentDoc, nsILoadGroup* aLoadGroup, nsIPrincipal* aPrincipal, Document* aParentDoc, nsILoadGroup* aLoadGroup,
nsIURI* aScriptURL, const Maybe<ClientInfo>& aClientInfo, nsIURI* aScriptURL, const Maybe<ClientInfo>& aClientInfo,
nsContentPolicyType aMainScriptContentPolicyType, nsIChannel** aChannel) { nsContentPolicyType aMainScriptContentPolicyType,
nsICookieSettings* aCookieSettings, nsIChannel** aChannel) {
AssertIsOnMainThread(); AssertIsOnMainThread();
nsCOMPtr<nsIIOService> ios(do_GetIOService()); nsCOMPtr<nsIIOService> ios(do_GetIOService());
@@ -2170,7 +2167,8 @@ nsresult ChannelFromScriptURLMainThread(
return ChannelFromScriptURL( return ChannelFromScriptURL(
aPrincipal, aParentDoc, nullptr, aLoadGroup, ios, secMan, aScriptURL, aPrincipal, aParentDoc, nullptr, aLoadGroup, ios, secMan, aScriptURL,
aClientInfo, Maybe<ServiceWorkerDescriptor>(), true, WorkerScript, aClientInfo, Maybe<ServiceWorkerDescriptor>(), true, WorkerScript,
aMainScriptContentPolicyType, nsIRequest::LOAD_NORMAL, aChannel); aMainScriptContentPolicyType, nsIRequest::LOAD_NORMAL, aCookieSettings,
aChannel);
} }
nsresult ChannelFromScriptURLWorkerThread(JSContext* aCx, nsresult ChannelFromScriptURLWorkerThread(JSContext* aCx,

View File

@@ -16,6 +16,7 @@ class nsIURI;
class nsILoadGroup; class nsILoadGroup;
class nsIChannel; class nsIChannel;
class nsICookieSettings;
namespace mozilla { namespace mozilla {
@@ -33,7 +34,8 @@ namespace workerinternals {
nsresult ChannelFromScriptURLMainThread( nsresult ChannelFromScriptURLMainThread(
nsIPrincipal* aPrincipal, Document* aParentDoc, nsILoadGroup* aLoadGroup, nsIPrincipal* aPrincipal, Document* aParentDoc, nsILoadGroup* aLoadGroup,
nsIURI* aScriptURL, const Maybe<ClientInfo>& aClientInfo, nsIURI* aScriptURL, const Maybe<ClientInfo>& aClientInfo,
nsContentPolicyType aContentPolicyType, nsIChannel** aChannel); nsContentPolicyType aContentPolicyType, nsICookieSettings* aCookieSettings,
nsIChannel** aChannel);
nsresult ChannelFromScriptURLWorkerThread(JSContext* aCx, nsresult ChannelFromScriptURLWorkerThread(JSContext* aCx,
WorkerPrivate* aParent, WorkerPrivate* aParent,

View File

@@ -19,6 +19,7 @@
class nsIChannel; class nsIChannel;
class nsIContentSecurityPolicy; class nsIContentSecurityPolicy;
class nsICookieSettings;
class nsILoadGroup; class nsILoadGroup;
class nsIPrincipal; class nsIPrincipal;
class nsIRunnable; class nsIRunnable;
@@ -50,6 +51,9 @@ struct WorkerLoadInfoData {
nsCOMPtr<nsIPrincipal> mLoadingPrincipal; nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
nsCOMPtr<nsIPrincipal> mPrincipal; nsCOMPtr<nsIPrincipal> mPrincipal;
// Taken from the parent context.
nsCOMPtr<nsICookieSettings> mCookieSettings;
nsCOMPtr<nsIScriptContext> mScriptContext; nsCOMPtr<nsIScriptContext> mScriptContext;
nsCOMPtr<nsPIDOMWindowInner> mWindow; nsCOMPtr<nsPIDOMWindowInner> mWindow;
nsCOMPtr<nsIContentSecurityPolicy> mCSP; nsCOMPtr<nsIContentSecurityPolicy> mCSP;

View File

@@ -59,6 +59,7 @@
#include "ScriptLoader.h" #include "ScriptLoader.h"
#include "mozilla/dom/ServiceWorkerEvents.h" #include "mozilla/dom/ServiceWorkerEvents.h"
#include "mozilla/dom/ServiceWorkerManager.h" #include "mozilla/dom/ServiceWorkerManager.h"
#include "mozilla/net/CookieSettings.h"
#include "WorkerCSPEventListener.h" #include "WorkerCSPEventListener.h"
#include "WorkerDebugger.h" #include "WorkerDebugger.h"
#include "WorkerDebuggerManager.h" #include "WorkerDebuggerManager.h"
@@ -2481,6 +2482,7 @@ nsresult WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow,
nsContentUtils::StorageAccess access = nsContentUtils::StorageAccess access =
nsContentUtils::StorageAllowedForWindow(globalWindow); nsContentUtils::StorageAllowedForWindow(globalWindow);
loadInfo.mStorageAllowed = access > nsContentUtils::StorageAccess::eDeny; loadInfo.mStorageAllowed = access > nsContentUtils::StorageAccess::eDeny;
loadInfo.mCookieSettings = document->CookieSettings();
loadInfo.mOriginAttributes = loadInfo.mOriginAttributes =
nsContentUtils::GetOriginAttributes(document); nsContentUtils::GetOriginAttributes(document);
loadInfo.mParentController = globalWindow->GetController(); loadInfo.mParentController = globalWindow->GetController();
@@ -2526,6 +2528,9 @@ nsresult WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow,
loadInfo.mFromWindow = false; loadInfo.mFromWindow = false;
loadInfo.mWindowID = UINT64_MAX; loadInfo.mWindowID = UINT64_MAX;
loadInfo.mStorageAllowed = true; loadInfo.mStorageAllowed = true;
loadInfo.mCookieSettings = mozilla::net::CookieSettings::Create();
MOZ_ASSERT(loadInfo.mCookieSettings);
loadInfo.mOriginAttributes = OriginAttributes(); loadInfo.mOriginAttributes = OriginAttributes();
} }
@@ -2545,10 +2550,10 @@ nsresult WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow,
getter_AddRefs(url), aScriptURL, document, loadInfo.mBaseURI); getter_AddRefs(url), aScriptURL, document, loadInfo.mBaseURI);
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_SYNTAX_ERR); NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_SYNTAX_ERR);
rv = ChannelFromScriptURLMainThread(loadInfo.mLoadingPrincipal, document, rv = ChannelFromScriptURLMainThread(
loadInfo.mLoadGroup, url, clientInfo, loadInfo.mLoadingPrincipal, document, loadInfo.mLoadGroup, url,
ContentPolicyType(aWorkerType), clientInfo, ContentPolicyType(aWorkerType), loadInfo.mCookieSettings,
getter_AddRefs(loadInfo.mChannel)); getter_AddRefs(loadInfo.mChannel));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = NS_GetFinalChannelURI(loadInfo.mChannel, rv = NS_GetFinalChannelURI(loadInfo.mChannel,

View File

@@ -739,6 +739,12 @@ class WorkerPrivate : public RelativeTimeline {
mLoadInfo.mFirstPartyStorageAccessGranted; mLoadInfo.mFirstPartyStorageAccessGranted;
} }
nsICookieSettings* CookieSettings() const {
// Any thread.
MOZ_ASSERT(mLoadInfo.mCookieSettings);
return mLoadInfo.mCookieSettings;
}
const OriginAttributes& GetOriginAttributes() const { const OriginAttributes& GetOriginAttributes() const {
return mLoadInfo.mOriginAttributes; return mLoadInfo.mOriginAttributes;
} }

View File

@@ -18,6 +18,7 @@
#include "mozilla/dom/WorkerRunnable.h" #include "mozilla/dom/WorkerRunnable.h"
#include "mozilla/ipc/BackgroundUtils.h" #include "mozilla/ipc/BackgroundUtils.h"
#include "mozilla/ipc/URIUtils.h" #include "mozilla/ipc/URIUtils.h"
#include "mozilla/net/CookieSettings.h"
#include "nsIConsoleReportCollector.h" #include "nsIConsoleReportCollector.h"
#include "nsIPrincipal.h" #include "nsIPrincipal.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
@@ -270,6 +271,7 @@ nsresult RemoteWorkerChild::ExecWorkerOnMainThread(
info.mStorageAllowed = aData.isStorageAccessAllowed(); info.mStorageAllowed = aData.isStorageAccessAllowed();
info.mOriginAttributes = info.mOriginAttributes =
BasePrincipal::Cast(principal)->OriginAttributesRef(); BasePrincipal::Cast(principal)->OriginAttributesRef();
info.mCookieSettings = net::CookieSettings::Create();
// Default CSP permissions for now. These will be overrided if necessary // Default CSP permissions for now. These will be overrided if necessary
// based on the script CSP headers during load in ScriptLoader. // based on the script CSP headers during load in ScriptLoader.
@@ -302,7 +304,7 @@ nsresult RemoteWorkerChild::ExecWorkerOnMainThread(
info.mResolvedScriptURI, clientInfo, info.mResolvedScriptURI, clientInfo,
aData.isSharedWorker() ? nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER aData.isSharedWorker() ? nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER
: nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER, : nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER,
getter_AddRefs(info.mChannel)); info.mCookieSettings, getter_AddRefs(info.mChannel));
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }

View File

@@ -1047,6 +1047,7 @@ nsresult nsXBLService::FetchBindingDocument(
nsContentUtils::GetSystemPrincipal(), nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS, nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS,
nsIContentPolicy::TYPE_XBL, nsIContentPolicy::TYPE_XBL,
nullptr, // nsICookieSettings
nullptr, // PerformanceStorage nullptr, // PerformanceStorage
loadGroup); loadGroup);
} }

View File

@@ -7,6 +7,8 @@
#include "XMLHttpRequest.h" #include "XMLHttpRequest.h"
#include "XMLHttpRequestMainThread.h" #include "XMLHttpRequestMainThread.h"
#include "XMLHttpRequestWorker.h" #include "XMLHttpRequestWorker.h"
#include "mozilla/net/CookieSettings.h"
#include "nsGlobalWindowInner.h"
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
@@ -25,8 +27,23 @@ already_AddRefed<XMLHttpRequest> XMLHttpRequest::Constructor(
return nullptr; return nullptr;
} }
nsCOMPtr<nsICookieSettings> cookieSettings;
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global);
if (window) {
Document* document = window->GetExtantDoc();
if (NS_WARN_IF(!document)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
cookieSettings = document->CookieSettings();
} else {
// We are here because this is a sandbox.
cookieSettings = net::CookieSettings::Create();
}
RefPtr<XMLHttpRequestMainThread> req = new XMLHttpRequestMainThread(); RefPtr<XMLHttpRequestMainThread> req = new XMLHttpRequestMainThread();
req->Construct(principal->GetPrincipal(), global); req->Construct(principal->GetPrincipal(), global, cookieSettings);
req->InitParameters(aParams.mMozAnon, aParams.mMozSystem); req->InitParameters(aParams.mMozAnon, aParams.mMozSystem);
return req.forget(); return req.forget();
} }

View File

@@ -2334,6 +2334,7 @@ nsresult XMLHttpRequestMainThread::CreateChannel() {
rv = NS_NewChannel(getter_AddRefs(mChannel), mRequestURL, mPrincipal, rv = NS_NewChannel(getter_AddRefs(mChannel), mRequestURL, mPrincipal,
mClientInfo.ref(), mController, secFlags, mClientInfo.ref(), mController, secFlags,
nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST, nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST,
mCookieSettings,
mPerformanceStorage, // aPerformanceStorage mPerformanceStorage, // aPerformanceStorage
loadGroup, loadGroup,
nullptr, // aCallbacks nullptr, // aCallbacks
@@ -2342,6 +2343,7 @@ nsresult XMLHttpRequestMainThread::CreateChannel() {
// Otherwise use the principal. // Otherwise use the principal.
rv = NS_NewChannel(getter_AddRefs(mChannel), mRequestURL, mPrincipal, rv = NS_NewChannel(getter_AddRefs(mChannel), mRequestURL, mPrincipal,
secFlags, nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST, secFlags, nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST,
mCookieSettings,
mPerformanceStorage, // aPerformanceStorage mPerformanceStorage, // aPerformanceStorage
loadGroup, loadGroup,
nullptr, // aCallbacks nullptr, // aCallbacks

View File

@@ -199,7 +199,8 @@ class XMLHttpRequestMainThread final : public XMLHttpRequest,
XMLHttpRequestMainThread(); XMLHttpRequestMainThread();
void Construct(nsIPrincipal* aPrincipal, nsIGlobalObject* aGlobalObject, void Construct(nsIPrincipal* aPrincipal, nsIGlobalObject* aGlobalObject,
nsIURI* aBaseURI = nullptr, nsILoadGroup* aLoadGroup = nullptr, nsICookieSettings* aCookieSettings, nsIURI* aBaseURI = nullptr,
nsILoadGroup* aLoadGroup = nullptr,
PerformanceStorage* aPerformanceStorage = nullptr, PerformanceStorage* aPerformanceStorage = nullptr,
nsICSPEventListener* aCSPEventListener = nullptr) { nsICSPEventListener* aCSPEventListener = nullptr) {
MOZ_ASSERT(aPrincipal); MOZ_ASSERT(aPrincipal);
@@ -207,6 +208,7 @@ class XMLHttpRequestMainThread final : public XMLHttpRequest,
BindToOwner(aGlobalObject); BindToOwner(aGlobalObject);
mBaseURI = aBaseURI; mBaseURI = aBaseURI;
mLoadGroup = aLoadGroup; mLoadGroup = aLoadGroup;
mCookieSettings = aCookieSettings;
mPerformanceStorage = aPerformanceStorage; mPerformanceStorage = aPerformanceStorage;
mCSPEventListener = aCSPEventListener; mCSPEventListener = aCSPEventListener;
} }
@@ -494,6 +496,8 @@ class XMLHttpRequestMainThread final : public XMLHttpRequest,
nsCOMPtr<nsIStreamListener> mXMLParserStreamListener; nsCOMPtr<nsIStreamListener> mXMLParserStreamListener;
nsCOMPtr<nsICookieSettings> mCookieSettings;
RefPtr<PerformanceStorage> mPerformanceStorage; RefPtr<PerformanceStorage> mPerformanceStorage;
nsCOMPtr<nsICSPEventListener> mCSPEventListener; nsCOMPtr<nsICSPEventListener> mCSPEventListener;

View File

@@ -779,6 +779,7 @@ bool Proxy::Init() {
mXHR = new XMLHttpRequestMainThread(); mXHR = new XMLHttpRequestMainThread();
mXHR->Construct(mWorkerPrivate->GetPrincipal(), mXHR->Construct(mWorkerPrivate->GetPrincipal(),
ownerWindow ? ownerWindow->AsGlobal() : nullptr, ownerWindow ? ownerWindow->AsGlobal() : nullptr,
mWorkerPrivate->CookieSettings(),
mWorkerPrivate->GetBaseURI(), mWorkerPrivate->GetLoadGroup(), mWorkerPrivate->GetBaseURI(), mWorkerPrivate->GetLoadGroup(),
mWorkerPrivate->GetPerformanceStorage(), mWorkerPrivate->GetPerformanceStorage(),
mWorkerPrivate->CSPEventListener()); mWorkerPrivate->CSPEventListener());

View File

@@ -68,8 +68,9 @@ nsresult nsXMLPrettyPrinter::PrettyPrint(Document* aDocument,
nsCOMPtr<Document> xslDocument; nsCOMPtr<Document> xslDocument;
rv = nsSyncLoadService::LoadDocument( rv = nsSyncLoadService::LoadDocument(
xslUri, nsIContentPolicy::TYPE_XSLT, nsContentUtils::GetSystemPrincipal(), xslUri, nsIContentPolicy::TYPE_XSLT, nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nullptr, true, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nullptr,
mozilla::net::RP_Unset, getter_AddRefs(xslDocument)); aDocument->CookieSettings(), true, mozilla::net::RP_Unset,
getter_AddRefs(xslDocument));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// Transform the document // Transform the document

View File

@@ -38,7 +38,8 @@ nsresult txParseDocumentFromURI(const nsAString& aHref,
rv = nsSyncLoadService::LoadDocument( rv = nsSyncLoadService::LoadDocument(
documentURI, nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST, documentURI, nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST,
loaderDocument->NodePrincipal(), loaderDocument->NodePrincipal(),
nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS, loadGroup, true, nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS, loadGroup,
loaderDocument->CookieSettings(), true,
loaderDocument->GetReferrerPolicy(), &theDocument); loaderDocument->GetReferrerPolicy(), &theDocument);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {

View File

@@ -563,7 +563,8 @@ nsresult txSyncCompileObserver::loadURI(const nsAString& aUri,
rv = nsSyncLoadService::LoadDocument( rv = nsSyncLoadService::LoadDocument(
uri, nsIContentPolicy::TYPE_XSLT, referrerPrincipal, uri, nsIContentPolicy::TYPE_XSLT, referrerPrincipal,
nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS, nullptr, false, nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS, nullptr,
source ? source->OwnerDoc()->CookieSettings() : nullptr, false,
aReferrerPolicy, getter_AddRefs(document)); aReferrerPolicy, getter_AddRefs(document));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);

View File

@@ -249,6 +249,7 @@ nsresult nsAutoConfig::downloadAutoConfig() {
getter_AddRefs(channel), url, nsContentUtils::GetSystemPrincipal(), getter_AddRefs(channel), url, nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER, nsIContentPolicy::TYPE_OTHER,
nullptr, // nsICookieSettings
nullptr, // PerformanceStorage nullptr, // PerformanceStorage
nullptr, // loadGroup nullptr, // loadGroup
nullptr, // aCallbacks nullptr, // aCallbacks

View File

@@ -835,10 +835,11 @@ static nsresult NewImageChannel(
// outside a document, in which case the triggeringPrincipal and // outside a document, in which case the triggeringPrincipal and
// triggeringPrincipal should always be the systemPrincipal. // triggeringPrincipal should always be the systemPrincipal.
// However, there are exceptions: one is Notifications which create a // However, there are exceptions: one is Notifications which create a
// channel in the parent prcoess in which case we can't get a // channel in the parent process in which case we can't get a
// requestingNode. // requestingNode.
rv = NS_NewChannel(aResult, aURI, nsContentUtils::GetSystemPrincipal(), rv = NS_NewChannel(aResult, aURI, nsContentUtils::GetSystemPrincipal(),
securityFlags, aPolicyType, securityFlags, aPolicyType,
nullptr, // nsICookieSettings
nullptr, // PerformanceStorage nullptr, // PerformanceStorage
nullptr, // loadGroup nullptr, // loadGroup
callbacks, aLoadFlags); callbacks, aLoadFlags);

View File

@@ -238,6 +238,7 @@ class MOZ_STACK_CLASS ComponentLoaderInfo {
nsContentUtils::GetSystemPrincipal(), nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_SCRIPT, nsIContentPolicy::TYPE_SCRIPT,
nullptr, // nsICookieSettings
nullptr, // aPerformanceStorage nullptr, // aPerformanceStorage
nullptr, // aLoadGroup nullptr, // aLoadGroup
nullptr, // aCallbacks nullptr, // aCallbacks

View File

@@ -417,6 +417,7 @@ nsresult mozJSSubScriptLoader::ReadScriptAsync(nsIURI* uri,
nsContentUtils::GetSystemPrincipal(), nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER, nsIContentPolicy::TYPE_OTHER,
nullptr, // nsICookieSettings
nullptr, // aPerformanceStorage nullptr, // aPerformanceStorage
nullptr, // aLoadGroup nullptr, // aLoadGroup
nullptr, // aCallbacks nullptr, // aCallbacks
@@ -456,6 +457,7 @@ bool mozJSSubScriptLoader::ReadScript(nsIURI* uri, JSContext* cx,
nsContentUtils::GetSystemPrincipal(), nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER, nsIContentPolicy::TYPE_OTHER,
nullptr, // nsICookieSettings
nullptr, // PerformanceStorage nullptr, // PerformanceStorage
nullptr, // aLoadGroup nullptr, // aLoadGroup
nullptr, // aCallbacks nullptr, // aCallbacks

View File

@@ -1393,6 +1393,7 @@ nsresult Loader::LoadSheet(SheetLoadData* aLoadData,
} }
nsCOMPtr<nsILoadGroup> loadGroup; nsCOMPtr<nsILoadGroup> loadGroup;
nsCOMPtr<nsICookieSettings> cookieSettings;
if (mDocument) { if (mDocument) {
loadGroup = mDocument->GetDocumentLoadGroup(); loadGroup = mDocument->GetDocumentLoadGroup();
// load for a document with no loadgrup indicates that something is // load for a document with no loadgrup indicates that something is
@@ -1402,6 +1403,8 @@ nsresult Loader::LoadSheet(SheetLoadData* aLoadData,
SheetComplete(aLoadData, NS_ERROR_UNEXPECTED); SheetComplete(aLoadData, NS_ERROR_UNEXPECTED);
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }
cookieSettings = mDocument->CookieSettings();
} }
#ifdef DEBUG #ifdef DEBUG
mSyncCallback = true; mSyncCallback = true;
@@ -1443,7 +1446,7 @@ nsresult Loader::LoadSheet(SheetLoadData* aLoadData,
// triggeringPrincipal should always be the systemPrincipal. // triggeringPrincipal should always be the systemPrincipal.
rv = NS_NewChannel(getter_AddRefs(channel), aLoadData->mURI, rv = NS_NewChannel(getter_AddRefs(channel), aLoadData->mURI,
nsContentUtils::GetSystemPrincipal(), securityFlags, nsContentUtils::GetSystemPrincipal(), securityFlags,
contentPolicyType, contentPolicyType, cookieSettings,
nullptr, // aPerformanceStorage nullptr, // aPerformanceStorage
loadGroup, loadGroup,
nullptr, // aCallbacks nullptr, // aCallbacks

View File

@@ -786,14 +786,31 @@ LoadInfo::GetCookiePolicy(uint32_t* aResult) {
return NS_OK; return NS_OK;
} }
namespace {
already_AddRefed<nsICookieSettings> CreateCookieSettings(
nsContentPolicyType aContentPolicyType) {
if (StaticPrefs::network_cookieSettings_unblocked_for_testing()) {
return CookieSettings::Create();
}
// These contentPolictTypes require a real CookieSettings because favicon and
// save-as requests must send cookies. Anything else should not send/receive
// cookies.
if (aContentPolicyType == nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON ||
aContentPolicyType == nsIContentPolicy::TYPE_SAVEAS_DOWNLOAD) {
return CookieSettings::Create();
}
return CookieSettings::CreateBlockingAll();
}
} // namespace
NS_IMETHODIMP NS_IMETHODIMP
LoadInfo::GetCookieSettings(nsICookieSettings** aCookieSettings) { LoadInfo::GetCookieSettings(nsICookieSettings** aCookieSettings) {
if (!mCookieSettings) { if (!mCookieSettings) {
if (StaticPrefs::network_cookieSettings_unblocked_for_testing()) { mCookieSettings = CreateCookieSettings(mInternalContentPolicyType);
mCookieSettings = CookieSettings::Create();
} else {
mCookieSettings = CookieSettings::CreateBlockingAll();
}
} }
nsCOMPtr<nsICookieSettings> cookieSettings = mCookieSettings; nsCOMPtr<nsICookieSettings> cookieSettings = mCookieSettings;
@@ -801,6 +818,14 @@ LoadInfo::GetCookieSettings(nsICookieSettings** aCookieSettings) {
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
LoadInfo::SetCookieSettings(nsICookieSettings* aCookieSettings) {
MOZ_ASSERT(aCookieSettings);
// We allow the overwrite of CookieSettings.
mCookieSettings = aCookieSettings;
return NS_OK;
}
void LoadInfo::SetIncludeCookiesSecFlag() { void LoadInfo::SetIncludeCookiesSecFlag() {
MOZ_ASSERT((mSecurityFlags & sCookiePolicyMask) == MOZ_ASSERT((mSecurityFlags & sCookiePolicyMask) ==
nsILoadInfo::SEC_COOKIES_DEFAULT); nsILoadInfo::SEC_COOKIES_DEFAULT);

View File

@@ -191,6 +191,7 @@ static inline already_AddRefed<nsIChannel> SetupIPCheckChannel(bool ipv4) {
getter_AddRefs(channel), uri, nsContentUtils::GetSystemPrincipal(), getter_AddRefs(channel), uri, nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER, nsIContentPolicy::TYPE_OTHER,
nullptr, // nsICookieSettings
nullptr, // aPerformanceStorage nullptr, // aPerformanceStorage
nullptr, // aLoadGroup nullptr, // aLoadGroup
nullptr, nullptr,

View File

@@ -1246,7 +1246,8 @@ nsresult Predictor::Prefetch(nsIURI *uri, nsIURI *referrer,
nsresult rv = NS_NewChannel( nsresult rv = NS_NewChannel(
getter_AddRefs(channel), uri, nsContentUtils::GetSystemPrincipal(), getter_AddRefs(channel), uri, nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER, nullptr, /* aPerformanceStorage */ nsIContentPolicy::TYPE_OTHER, nullptr, /* nsICookieSettings */
nullptr, /* aPerformanceStorage */
nullptr, /* aLoadGroup */ nullptr, /* aLoadGroup */
nullptr, /* aCallbacks */ nullptr, /* aCallbacks */
nsIRequest::LOAD_BACKGROUND); nsIRequest::LOAD_BACKGROUND);

View File

@@ -431,7 +431,7 @@ interface nsILoadInfo : nsISupports
* The cookie settings inherited from the top-level document's loadInfo. * The cookie settings inherited from the top-level document's loadInfo.
* It cannot be null. * It cannot be null.
*/ */
readonly attribute nsICookieSettings cookieSettings; attribute nsICookieSettings cookieSettings;
/** /**
* If forceInheritPrincipal is true, the data coming from the channel should * If forceInheritPrincipal is true, the data coming from the channel should

View File

@@ -220,6 +220,7 @@ nsresult nsIncrementalDownload::ProcessTimeout() {
nsContentUtils::GetSystemPrincipal(), nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER, nsIContentPolicy::TYPE_OTHER,
nullptr, // nsICookieSettings
nullptr, // PerformanceStorage nullptr, // PerformanceStorage
nullptr, // loadGroup nullptr, // loadGroup
this, // aCallbacks this, // aCallbacks

View File

@@ -298,19 +298,20 @@ nsresult NS_NewChannel(nsIChannel **outChannel, nsIURI *aUri,
nsIPrincipal *aLoadingPrincipal, nsIPrincipal *aLoadingPrincipal,
nsSecurityFlags aSecurityFlags, nsSecurityFlags aSecurityFlags,
nsContentPolicyType aContentPolicyType, nsContentPolicyType aContentPolicyType,
PerformanceStorage *aPerformanceStorage /* nullptr */, nsICookieSettings *aCookieSettings /* = nullptr */,
PerformanceStorage *aPerformanceStorage /* = nullptr */,
nsILoadGroup *aLoadGroup /* = nullptr */, nsILoadGroup *aLoadGroup /* = nullptr */,
nsIInterfaceRequestor *aCallbacks /* = nullptr */, nsIInterfaceRequestor *aCallbacks /* = nullptr */,
nsLoadFlags aLoadFlags /* = nsIRequest::LOAD_NORMAL */, nsLoadFlags aLoadFlags /* = nsIRequest::LOAD_NORMAL */,
nsIIOService *aIoService /* = nullptr */) { nsIIOService *aIoService /* = nullptr */) {
return NS_NewChannelInternal(outChannel, aUri, return NS_NewChannelInternal(
nullptr, // aLoadingNode, outChannel, aUri,
aLoadingPrincipal, nullptr, // aLoadingNode,
nullptr, // aTriggeringPrincipal aLoadingPrincipal,
Maybe<ClientInfo>(), nullptr, // aTriggeringPrincipal
Maybe<ServiceWorkerDescriptor>(), aSecurityFlags, Maybe<ClientInfo>(), Maybe<ServiceWorkerDescriptor>(), aSecurityFlags,
aContentPolicyType, aPerformanceStorage, aContentPolicyType, aCookieSettings, aPerformanceStorage, aLoadGroup,
aLoadGroup, aCallbacks, aLoadFlags, aIoService); aCallbacks, aLoadFlags, aIoService);
} }
nsresult NS_NewChannel(nsIChannel **outChannel, nsIURI *aUri, nsresult NS_NewChannel(nsIChannel **outChannel, nsIURI *aUri,
@@ -319,7 +320,8 @@ nsresult NS_NewChannel(nsIChannel **outChannel, nsIURI *aUri,
const Maybe<ServiceWorkerDescriptor> &aController, const Maybe<ServiceWorkerDescriptor> &aController,
nsSecurityFlags aSecurityFlags, nsSecurityFlags aSecurityFlags,
nsContentPolicyType aContentPolicyType, nsContentPolicyType aContentPolicyType,
PerformanceStorage *aPerformanceStorage /* nullptr */, nsICookieSettings *aCookieSettings /* = nullptr */,
PerformanceStorage *aPerformanceStorage /* = nullptr */,
nsILoadGroup *aLoadGroup /* = nullptr */, nsILoadGroup *aLoadGroup /* = nullptr */,
nsIInterfaceRequestor *aCallbacks /* = nullptr */, nsIInterfaceRequestor *aCallbacks /* = nullptr */,
nsLoadFlags aLoadFlags /* = nsIRequest::LOAD_NORMAL */, nsLoadFlags aLoadFlags /* = nsIRequest::LOAD_NORMAL */,
@@ -335,8 +337,9 @@ nsresult NS_NewChannel(nsIChannel **outChannel, nsIURI *aUri,
aLoadingPrincipal, aLoadingPrincipal,
nullptr, // aTriggeringPrincipal nullptr, // aTriggeringPrincipal
loadingClientInfo, aController, aSecurityFlags, loadingClientInfo, aController, aSecurityFlags,
aContentPolicyType, aPerformanceStorage, aContentPolicyType, aCookieSettings,
aLoadGroup, aCallbacks, aLoadFlags, aIoService); aPerformanceStorage, aLoadGroup, aCallbacks,
aLoadFlags, aIoService);
} }
nsresult NS_NewChannelInternal( nsresult NS_NewChannelInternal(
@@ -345,7 +348,8 @@ nsresult NS_NewChannelInternal(
const Maybe<ClientInfo> &aLoadingClientInfo, const Maybe<ClientInfo> &aLoadingClientInfo,
const Maybe<ServiceWorkerDescriptor> &aController, const Maybe<ServiceWorkerDescriptor> &aController,
nsSecurityFlags aSecurityFlags, nsContentPolicyType aContentPolicyType, nsSecurityFlags aSecurityFlags, nsContentPolicyType aContentPolicyType,
PerformanceStorage *aPerformanceStorage /* nullptr */, nsICookieSettings *aCookieSettings /* = nullptr */,
PerformanceStorage *aPerformanceStorage /* = nullptr */,
nsILoadGroup *aLoadGroup /* = nullptr */, nsILoadGroup *aLoadGroup /* = nullptr */,
nsIInterfaceRequestor *aCallbacks /* = nullptr */, nsIInterfaceRequestor *aCallbacks /* = nullptr */,
nsLoadFlags aLoadFlags /* = nsIRequest::LOAD_NORMAL */, nsLoadFlags aLoadFlags /* = nsIRequest::LOAD_NORMAL */,
@@ -389,9 +393,16 @@ nsresult NS_NewChannelInternal(
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
if (aPerformanceStorage) { if (aPerformanceStorage || aCookieSettings) {
nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo(); nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
loadInfo->SetPerformanceStorage(aPerformanceStorage);
if (aPerformanceStorage) {
loadInfo->SetPerformanceStorage(aPerformanceStorage);
}
if (aCookieSettings) {
loadInfo->SetCookieSettings(aCookieSettings);
}
} }
channel.forget(outChannel); channel.forget(outChannel);
@@ -415,7 +426,8 @@ NS_NewChannelWithTriggeringPrincipal(
outChannel, aUri, aLoadingNode, aLoadingNode->NodePrincipal(), outChannel, aUri, aLoadingNode, aLoadingNode->NodePrincipal(),
aTriggeringPrincipal, Maybe<ClientInfo>(), aTriggeringPrincipal, Maybe<ClientInfo>(),
Maybe<ServiceWorkerDescriptor>(), aSecurityFlags, aContentPolicyType, Maybe<ServiceWorkerDescriptor>(), aSecurityFlags, aContentPolicyType,
aPerformanceStorage, aLoadGroup, aCallbacks, aLoadFlags, aIoService); aLoadingNode->OwnerDoc()->CookieSettings(), aPerformanceStorage,
aLoadGroup, aCallbacks, aLoadFlags, aIoService);
} }
// See NS_NewChannelInternal for usage and argument description // See NS_NewChannelInternal for usage and argument description
@@ -423,6 +435,7 @@ nsresult NS_NewChannelWithTriggeringPrincipal(
nsIChannel **outChannel, nsIURI *aUri, nsIPrincipal *aLoadingPrincipal, nsIChannel **outChannel, nsIURI *aUri, nsIPrincipal *aLoadingPrincipal,
nsIPrincipal *aTriggeringPrincipal, nsSecurityFlags aSecurityFlags, nsIPrincipal *aTriggeringPrincipal, nsSecurityFlags aSecurityFlags,
nsContentPolicyType aContentPolicyType, nsContentPolicyType aContentPolicyType,
nsICookieSettings *aCookieSettings /* = nullptr */,
PerformanceStorage *aPerformanceStorage /* = nullptr */, PerformanceStorage *aPerformanceStorage /* = nullptr */,
nsILoadGroup *aLoadGroup /* = nullptr */, nsILoadGroup *aLoadGroup /* = nullptr */,
nsIInterfaceRequestor *aCallbacks /* = nullptr */, nsIInterfaceRequestor *aCallbacks /* = nullptr */,
@@ -435,7 +448,8 @@ nsresult NS_NewChannelWithTriggeringPrincipal(
nullptr, // aLoadingNode nullptr, // aLoadingNode
aLoadingPrincipal, aTriggeringPrincipal, Maybe<ClientInfo>(), aLoadingPrincipal, aTriggeringPrincipal, Maybe<ClientInfo>(),
Maybe<ServiceWorkerDescriptor>(), aSecurityFlags, aContentPolicyType, Maybe<ServiceWorkerDescriptor>(), aSecurityFlags, aContentPolicyType,
aPerformanceStorage, aLoadGroup, aCallbacks, aLoadFlags, aIoService); aCookieSettings, aPerformanceStorage, aLoadGroup, aCallbacks, aLoadFlags,
aIoService);
} }
// See NS_NewChannelInternal for usage and argument description // See NS_NewChannelInternal for usage and argument description
@@ -444,6 +458,7 @@ nsresult NS_NewChannelWithTriggeringPrincipal(
nsIPrincipal *aTriggeringPrincipal, const ClientInfo &aLoadingClientInfo, nsIPrincipal *aTriggeringPrincipal, const ClientInfo &aLoadingClientInfo,
const Maybe<ServiceWorkerDescriptor> &aController, const Maybe<ServiceWorkerDescriptor> &aController,
nsSecurityFlags aSecurityFlags, nsContentPolicyType aContentPolicyType, nsSecurityFlags aSecurityFlags, nsContentPolicyType aContentPolicyType,
nsICookieSettings *aCookieSettings /* = nullptr */,
PerformanceStorage *aPerformanceStorage /* = nullptr */, PerformanceStorage *aPerformanceStorage /* = nullptr */,
nsILoadGroup *aLoadGroup /* = nullptr */, nsILoadGroup *aLoadGroup /* = nullptr */,
nsIInterfaceRequestor *aCallbacks /* = nullptr */, nsIInterfaceRequestor *aCallbacks /* = nullptr */,
@@ -455,12 +470,12 @@ nsresult NS_NewChannelWithTriggeringPrincipal(
Maybe<ClientInfo> loadingClientInfo; Maybe<ClientInfo> loadingClientInfo;
loadingClientInfo.emplace(aLoadingClientInfo); loadingClientInfo.emplace(aLoadingClientInfo);
return NS_NewChannelInternal(outChannel, aUri, return NS_NewChannelInternal(
nullptr, // aLoadingNode outChannel, aUri,
aLoadingPrincipal, aTriggeringPrincipal, nullptr, // aLoadingNode
loadingClientInfo, aController, aSecurityFlags, aLoadingPrincipal, aTriggeringPrincipal, loadingClientInfo, aController,
aContentPolicyType, aPerformanceStorage, aSecurityFlags, aContentPolicyType, aCookieSettings, aPerformanceStorage,
aLoadGroup, aCallbacks, aLoadFlags, aIoService); aLoadGroup, aCallbacks, aLoadFlags, aIoService);
} }
nsresult NS_NewChannel(nsIChannel **outChannel, nsIURI *aUri, nsresult NS_NewChannel(nsIChannel **outChannel, nsIURI *aUri,
@@ -476,8 +491,8 @@ nsresult NS_NewChannel(nsIChannel **outChannel, nsIURI *aUri,
outChannel, aUri, aLoadingNode, aLoadingNode->NodePrincipal(), outChannel, aUri, aLoadingNode, aLoadingNode->NodePrincipal(),
nullptr, // aTriggeringPrincipal nullptr, // aTriggeringPrincipal
Maybe<ClientInfo>(), Maybe<ServiceWorkerDescriptor>(), aSecurityFlags, Maybe<ClientInfo>(), Maybe<ServiceWorkerDescriptor>(), aSecurityFlags,
aContentPolicyType, aPerformanceStorage, aLoadGroup, aCallbacks, aContentPolicyType, aLoadingNode->OwnerDoc()->CookieSettings(),
aLoadFlags, aIoService); aPerformanceStorage, aLoadGroup, aCallbacks, aLoadFlags, aIoService);
} }
nsresult NS_GetIsDocumentChannel(nsIChannel *aChannel, bool *aIsDocument) { nsresult NS_GetIsDocumentChannel(nsIChannel *aChannel, bool *aIsDocument) {
@@ -909,6 +924,7 @@ nsresult NS_NewStreamLoaderInternal(
nullptr, // aTriggeringPrincipal nullptr, // aTriggeringPrincipal
Maybe<ClientInfo>(), Maybe<ServiceWorkerDescriptor>(), aSecurityFlags, Maybe<ClientInfo>(), Maybe<ServiceWorkerDescriptor>(), aSecurityFlags,
aContentPolicyType, aContentPolicyType,
nullptr, // nsICookieSettings
nullptr, // PerformanceStorage nullptr, // PerformanceStorage
aLoadGroup, aCallbacks, aLoadFlags); aLoadGroup, aCallbacks, aLoadFlags);

View File

@@ -32,6 +32,7 @@ class nsIAuthPrompt;
class nsIAuthPrompt2; class nsIAuthPrompt2;
class nsIChannel; class nsIChannel;
class nsIChannelPolicy; class nsIChannelPolicy;
class nsICookieSettings;
class nsIDownloadObserver; class nsIDownloadObserver;
class nsIEventTarget; class nsIEventTarget;
class nsIFileProtocolHandler; class nsIFileProtocolHandler;
@@ -166,6 +167,7 @@ nsresult NS_NewChannelInternal(
const mozilla::Maybe<mozilla::dom::ClientInfo> &aLoadingClientInfo, const mozilla::Maybe<mozilla::dom::ClientInfo> &aLoadingClientInfo,
const mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor> &aController, const mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor> &aController,
nsSecurityFlags aSecurityFlags, nsContentPolicyType aContentPolicyType, nsSecurityFlags aSecurityFlags, nsContentPolicyType aContentPolicyType,
nsICookieSettings *aCookieSettings = nullptr,
mozilla::dom::PerformanceStorage *aPerformanceStorage = nullptr, mozilla::dom::PerformanceStorage *aPerformanceStorage = nullptr,
nsILoadGroup *aLoadGroup = nullptr, nsILoadGroup *aLoadGroup = nullptr,
nsIInterfaceRequestor *aCallbacks = nullptr, nsIInterfaceRequestor *aCallbacks = nullptr,
@@ -198,6 +200,7 @@ nsresult NS_NewChannelWithTriggeringPrincipal(
nsIChannel **outChannel, nsIURI *aUri, nsIPrincipal *aLoadingPrincipal, nsIChannel **outChannel, nsIURI *aUri, nsIPrincipal *aLoadingPrincipal,
nsIPrincipal *aTriggeringPrincipal, nsSecurityFlags aSecurityFlags, nsIPrincipal *aTriggeringPrincipal, nsSecurityFlags aSecurityFlags,
nsContentPolicyType aContentPolicyType, nsContentPolicyType aContentPolicyType,
nsICookieSettings *aCookieSettings = nullptr,
mozilla::dom::PerformanceStorage *aPerformanceStorage = nullptr, mozilla::dom::PerformanceStorage *aPerformanceStorage = nullptr,
nsILoadGroup *aLoadGroup = nullptr, nsILoadGroup *aLoadGroup = nullptr,
nsIInterfaceRequestor *aCallbacks = nullptr, nsIInterfaceRequestor *aCallbacks = nullptr,
@@ -211,6 +214,7 @@ nsresult NS_NewChannelWithTriggeringPrincipal(
const mozilla::dom::ClientInfo &aLoadingClientInfo, const mozilla::dom::ClientInfo &aLoadingClientInfo,
const mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor> &aController, const mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor> &aController,
nsSecurityFlags aSecurityFlags, nsContentPolicyType aContentPolicyType, nsSecurityFlags aSecurityFlags, nsContentPolicyType aContentPolicyType,
nsICookieSettings *aCookieSettings = nullptr,
mozilla::dom::PerformanceStorage *aPerformanceStorage = nullptr, mozilla::dom::PerformanceStorage *aPerformanceStorage = nullptr,
nsILoadGroup *aLoadGroup = nullptr, nsILoadGroup *aLoadGroup = nullptr,
nsIInterfaceRequestor *aCallbacks = nullptr, nsIInterfaceRequestor *aCallbacks = nullptr,
@@ -231,6 +235,7 @@ nsresult NS_NewChannel(
nsresult NS_NewChannel( nsresult NS_NewChannel(
nsIChannel **outChannel, nsIURI *aUri, nsIPrincipal *aLoadingPrincipal, nsIChannel **outChannel, nsIURI *aUri, nsIPrincipal *aLoadingPrincipal,
nsSecurityFlags aSecurityFlags, nsContentPolicyType aContentPolicyType, nsSecurityFlags aSecurityFlags, nsContentPolicyType aContentPolicyType,
nsICookieSettings *aCookieSettings = nullptr,
mozilla::dom::PerformanceStorage *aPerformanceStorage = nullptr, mozilla::dom::PerformanceStorage *aPerformanceStorage = nullptr,
nsILoadGroup *aLoadGroup = nullptr, nsILoadGroup *aLoadGroup = nullptr,
nsIInterfaceRequestor *aCallbacks = nullptr, nsIInterfaceRequestor *aCallbacks = nullptr,
@@ -243,6 +248,7 @@ nsresult NS_NewChannel(
const mozilla::dom::ClientInfo &aLoadingClientInfo, const mozilla::dom::ClientInfo &aLoadingClientInfo,
const mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor> &aController, const mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor> &aController,
nsSecurityFlags aSecurityFlags, nsContentPolicyType aContentPolicyType, nsSecurityFlags aSecurityFlags, nsContentPolicyType aContentPolicyType,
nsICookieSettings *aCookieSettings = nullptr,
mozilla::dom::PerformanceStorage *aPerformanceStorage = nullptr, mozilla::dom::PerformanceStorage *aPerformanceStorage = nullptr,
nsILoadGroup *aLoadGroup = nullptr, nsILoadGroup *aLoadGroup = nullptr,
nsIInterfaceRequestor *aCallbacks = nullptr, nsIInterfaceRequestor *aCallbacks = nullptr,

View File

@@ -637,7 +637,8 @@ void nsPACMan::ContinueLoadingAfterPACUriKnown() {
nsContentUtils::GetSystemPrincipal(), nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER, nsIContentPolicy::TYPE_OTHER,
nullptr, // PerformanceStorage, nullptr, // nsICookieSettings
nullptr, // PerformanceStorage
nullptr, // aLoadGroup nullptr, // aLoadGroup
nullptr, // aCallbacks nullptr, // aCallbacks
nsIRequest::LOAD_NORMAL, ios); nsIRequest::LOAD_NORMAL, ios);

View File

@@ -40,10 +40,29 @@ class PermissionComparator {
} }
}; };
class ReleaseCookiePermissions final : public Runnable {
public:
explicit ReleaseCookiePermissions(nsTArray<RefPtr<nsIPermission>>& aArray)
: Runnable("ReleaseCookiePermissions") {
mArray.SwapElements(aArray);
}
NS_IMETHOD Run() override {
MOZ_ASSERT(NS_IsMainThread());
mArray.Clear();
return NS_OK;
}
private:
nsTArray<RefPtr<nsIPermission>> mArray;
};
} // namespace } // namespace
// static // static
already_AddRefed<nsICookieSettings> CookieSettings::CreateBlockingAll() { already_AddRefed<nsICookieSettings> CookieSettings::CreateBlockingAll() {
MOZ_ASSERT(NS_IsMainThread());
RefPtr<CookieSettings> cookieSettings = RefPtr<CookieSettings> cookieSettings =
new CookieSettings(nsICookieService::BEHAVIOR_REJECT, eFixed); new CookieSettings(nsICookieService::BEHAVIOR_REJECT, eFixed);
return cookieSettings.forget(); return cookieSettings.forget();
@@ -51,15 +70,30 @@ already_AddRefed<nsICookieSettings> CookieSettings::CreateBlockingAll() {
// static // static
already_AddRefed<nsICookieSettings> CookieSettings::Create() { already_AddRefed<nsICookieSettings> CookieSettings::Create() {
MOZ_ASSERT(NS_IsMainThread());
RefPtr<CookieSettings> cookieSettings = new CookieSettings( RefPtr<CookieSettings> cookieSettings = new CookieSettings(
StaticPrefs::network_cookie_cookieBehavior(), eProgressive); StaticPrefs::network_cookie_cookieBehavior(), eProgressive);
return cookieSettings.forget(); return cookieSettings.forget();
} }
CookieSettings::CookieSettings(uint32_t aCookieBehavior, State aState) CookieSettings::CookieSettings(uint32_t aCookieBehavior, State aState)
: mCookieBehavior(aCookieBehavior), mState(aState) {} : mCookieBehavior(aCookieBehavior), mState(aState) {
MOZ_ASSERT(NS_IsMainThread());
}
CookieSettings::~CookieSettings() = default; CookieSettings::~CookieSettings() {
if (!NS_IsMainThread() && !mCookiePermissions.IsEmpty()) {
nsCOMPtr<nsIEventTarget> systemGroupEventTarget =
mozilla::SystemGroup::EventTargetFor(mozilla::TaskCategory::Other);
MOZ_ASSERT(systemGroupEventTarget);
RefPtr<Runnable> r = new ReleaseCookiePermissions(mCookiePermissions);
MOZ_ASSERT(mCookiePermissions.IsEmpty());
systemGroupEventTarget->Dispatch(r.forget());
}
}
NS_IMETHODIMP NS_IMETHODIMP
CookieSettings::GetCookieBehavior(uint32_t* aCookieBehavior) { CookieSettings::GetCookieBehavior(uint32_t* aCookieBehavior) {
@@ -70,6 +104,7 @@ CookieSettings::GetCookieBehavior(uint32_t* aCookieBehavior) {
NS_IMETHODIMP NS_IMETHODIMP
CookieSettings::CookiePermission(nsIPrincipal* aPrincipal, CookieSettings::CookiePermission(nsIPrincipal* aPrincipal,
uint32_t* aCookiePermission) { uint32_t* aCookiePermission) {
MOZ_ASSERT(NS_IsMainThread());
NS_ENSURE_ARG_POINTER(aPrincipal); NS_ENSURE_ARG_POINTER(aPrincipal);
NS_ENSURE_ARG_POINTER(aCookiePermission); NS_ENSURE_ARG_POINTER(aCookiePermission);
@@ -118,6 +153,8 @@ CookieSettings::CookiePermission(nsIPrincipal* aPrincipal,
} }
void CookieSettings::Serialize(CookieSettingsArgs& aData) { void CookieSettings::Serialize(CookieSettingsArgs& aData) {
MOZ_ASSERT(NS_IsMainThread());
aData.isFixed() = mState == eFixed; aData.isFixed() = mState == eFixed;
aData.cookieBehavior() = mCookieBehavior; aData.cookieBehavior() = mCookieBehavior;
@@ -147,6 +184,8 @@ void CookieSettings::Serialize(CookieSettingsArgs& aData) {
/* static */ void CookieSettings::Deserialize( /* static */ void CookieSettings::Deserialize(
const CookieSettingsArgs& aData, nsICookieSettings** aCookieSettings) { const CookieSettingsArgs& aData, nsICookieSettings** aCookieSettings) {
MOZ_ASSERT(NS_IsMainThread());
CookiePermissionList list; CookiePermissionList list;
for (const CookiePermissionData& data : aData.cookiePermissions()) { for (const CookiePermissionData& data : aData.cookiePermissions()) {
nsCOMPtr<nsIPrincipal> principal = nsCOMPtr<nsIPrincipal> principal =
@@ -173,6 +212,7 @@ void CookieSettings::Serialize(CookieSettingsArgs& aData) {
} }
void CookieSettings::Merge(const CookieSettingsArgs& aData) { void CookieSettings::Merge(const CookieSettingsArgs& aData) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mCookieBehavior == aData.cookieBehavior()); MOZ_ASSERT(mCookieBehavior == aData.cookieBehavior());
if (mState == eFixed) { if (mState == eFixed) {

View File

@@ -24,7 +24,7 @@ class CookieSettings final : public nsICookieSettings {
public: public:
typedef nsTArray<RefPtr<nsIPermission>> CookiePermissionList; typedef nsTArray<RefPtr<nsIPermission>> CookiePermissionList;
NS_DECL_ISUPPORTS NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSICOOKIESETTINGS NS_DECL_NSICOOKIESETTINGS
static already_AddRefed<nsICookieSettings> CreateBlockingAll(); static already_AddRefed<nsICookieSettings> CreateBlockingAll();

View File

@@ -236,6 +236,7 @@ nsresult TRR::SendHTTPRequest() {
getter_AddRefs(mChannel), dnsURI, nsContentUtils::GetSystemPrincipal(), getter_AddRefs(mChannel), dnsURI, nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER, nsIContentPolicy::TYPE_OTHER,
nullptr, // nsICookieSettings
nullptr, // PerformanceStorage nullptr, // PerformanceStorage
nullptr, // aLoadGroup nullptr, // aLoadGroup
this, this,

View File

@@ -1993,6 +1993,7 @@ nsUrlClassifierDBService::SendThreatHitReport(nsIChannel* aChannel,
nsContentUtils::GetSystemPrincipal(), nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER, nsIContentPolicy::TYPE_OTHER,
nullptr, // nsICookieSettings
nullptr, // aPerformanceStorage nullptr, // aPerformanceStorage
nullptr, // aLoadGroup nullptr, // aLoadGroup
nullptr, loadFlags); nullptr, loadFlags);

View File

@@ -133,6 +133,7 @@ nsresult nsUrlClassifierStreamUpdater::FetchUpdate(
nsContentUtils::GetSystemPrincipal(), nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER, nsIContentPolicy::TYPE_OTHER,
nullptr, // nsICookieSettings
nullptr, // aPerformanceStorage nullptr, // aPerformanceStorage
nullptr, // aLoadGroup nullptr, // aLoadGroup
this, // aInterfaceRequestor this, // aInterfaceRequestor

View File

@@ -166,6 +166,7 @@ nsresult nsManifestCheck::Begin() {
rv = NS_NewChannel(getter_AddRefs(mChannel), mURI, mLoadingPrincipal, rv = NS_NewChannel(getter_AddRefs(mChannel), mURI, mLoadingPrincipal,
nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED, nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED,
nsIContentPolicy::TYPE_OTHER, nsIContentPolicy::TYPE_OTHER,
nullptr, // nsICookieSettings
nullptr, // PerformanceStorage nullptr, // PerformanceStorage
nullptr, // loadGroup nullptr, // loadGroup
nullptr, // aCallbacks nullptr, // aCallbacks
@@ -335,6 +336,7 @@ nsresult nsOfflineCacheUpdateItem::OpenChannel(nsOfflineCacheUpdate *aUpdate) {
rv = NS_NewChannel(getter_AddRefs(mChannel), mURI, mLoadingPrincipal, rv = NS_NewChannel(getter_AddRefs(mChannel), mURI, mLoadingPrincipal,
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER, nsIContentPolicy::TYPE_OTHER,
nullptr, // nsICookieSettings
nullptr, // PerformanceStorage nullptr, // PerformanceStorage
nullptr, // aLoadGroup nullptr, // aLoadGroup
this, // aCallbacks this, // aCallbacks

View File

@@ -127,7 +127,7 @@ nsresult nsPrefetchNode::OpenChannel() {
getter_AddRefs(mChannel), mURI, source, source->NodePrincipal(), getter_AddRefs(mChannel), mURI, source, source->NodePrincipal(),
nullptr, // aTriggeringPrincipal nullptr, // aTriggeringPrincipal
Maybe<ClientInfo>(), Maybe<ServiceWorkerDescriptor>(), securityFlags, Maybe<ClientInfo>(), Maybe<ServiceWorkerDescriptor>(), securityFlags,
mPolicyType, mPolicyType, source->OwnerDoc()->CookieSettings(),
nullptr, // aPerformanceStorage nullptr, // aPerformanceStorage
loadGroup, // aLoadGroup loadGroup, // aLoadGroup
this, // aCallbacks this, // aCallbacks

View File

@@ -22,6 +22,7 @@
#include "nsIDNSRecord.h" #include "nsIDNSRecord.h"
#include "mozilla/net/DNS.h" // for NetAddr #include "mozilla/net/DNS.h" // for NetAddr
#include "mozilla/net/CookieSettings.h"
#include "nsNetUtil.h" // for NS_NewURI, NS_NewChannel, NS_NewStreamLoader #include "nsNetUtil.h" // for NS_NewURI, NS_NewChannel, NS_NewStreamLoader
@@ -443,6 +444,12 @@ nsresult WebExecutorSupport::CreateStreamLoader(
channel->SetLoadFlags(nsIRequest::LOAD_ANONYMOUS); channel->SetLoadFlags(nsIRequest::LOAD_ANONYMOUS);
} }
nsCOMPtr<nsICookieSettings> cookieSettings = CookieSettings::Create();
MOZ_ASSERT(cookieSettings);
nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
loadInfo->SetCookieSettings(cookieSettings);
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel, &rv)); nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel, &rv));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);

View File

@@ -71,6 +71,7 @@ nsresult nsDataObj::CStream::Init(nsIURI* pSourceURI,
rv = NS_NewChannel(getter_AddRefs(mChannel), pSourceURI, aRequestingPrincipal, rv = NS_NewChannel(getter_AddRefs(mChannel), pSourceURI, aRequestingPrincipal,
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS,
aContentPolicyType, aContentPolicyType,
nullptr, // nsICookieSettings
nullptr, // PerformanceStorage nullptr, // PerformanceStorage
nullptr, // loadGroup nullptr, // loadGroup
nullptr, // aCallbacks nullptr, // aCallbacks