From 181d5d396ebf1af52776ce5a6da269c1c79631e2 Mon Sep 17 00:00:00 2001 From: Eden Chuang Date: Thu, 12 Jan 2023 17:24:29 +0000 Subject: [PATCH] Bug 1351231 - Integrate FetchChild into Fetch.cpp r=dom-worker-reviewers,jesup Depends on D142437 Differential Revision: https://phabricator.services.mozilla.com/D142704 --- devtools/client/netmonitor/test/browser.ini | 4 +- dom/fetch/Fetch.cpp | 56 ++++ dom/fetch/FetchChild.cpp | 303 +++++++++++++++++- dom/fetch/FetchChild.h | 40 ++- dom/workers/WorkerCSPEventListener.cpp | 25 +- dom/workers/WorkerLoadInfo.h | 5 + dom/workers/WorkerPrivate.cpp | 11 + dom/workers/WorkerPrivate.h | 6 + .../remoteworkers/RemoteWorkerChild.cpp | 1 + ...arker_network_serviceworker_cache_first.js | 7 - ...work_serviceworker_synthetized_response.js | 77 +---- 11 files changed, 438 insertions(+), 97 deletions(-) diff --git a/devtools/client/netmonitor/test/browser.ini b/devtools/client/netmonitor/test/browser.ini index 2ad4cf29b3bb..8896dc8d6f7c 100644 --- a/devtools/client/netmonitor/test/browser.ini +++ b/devtools/client/netmonitor/test/browser.ini @@ -300,7 +300,9 @@ skip-if = [browser_net_waterfall-click.js] [browser_net_websocket_stacks.js] [browser_net_worker_stacks.js] -skip-if = win10_2004 # Bug 1723573 +skip-if = + win10_2004 # Bug 1723573 + nightly_build # Bug 1351231 [browser_net_ws-basic.js] [browser_net_ws-clear.js] [browser_net_ws-connection-closed.js] diff --git a/dom/fetch/Fetch.cpp b/dom/fetch/Fetch.cpp index 98ff71f04778..96c49883ce7a 100644 --- a/dom/fetch/Fetch.cpp +++ b/dom/fetch/Fetch.cpp @@ -9,8 +9,12 @@ #include "js/RootingAPI.h" #include "js/Value.h" #include "mozilla/CycleCollectedJSContext.h" +#include "mozilla/StaticPrefs_dom.h" #include "mozilla/dom/Document.h" +#include "mozilla/ipc/BackgroundChild.h" +#include "mozilla/ipc/PBackgroundChild.h" #include "mozilla/ipc/PBackgroundSharedTypes.h" +#include "mozilla/ipc/IPCStreamUtils.h" #include "nsIGlobalObject.h" #include "nsDOMString.h" @@ -41,6 +45,7 @@ #include "mozilla/net/CookieJarSettings.h" #include "BodyExtractor.h" +#include "FetchChild.h" #include "FetchObserver.h" #include "InternalRequest.h" #include "InternalResponse.h" @@ -599,6 +604,57 @@ already_AddRefed FetchRequest(nsIGlobalObject* aGlobal, r->SetSkipServiceWorker(); } + // PFetch gives no benefit for the fetch in the parent process. + // Dispatch fetch to the parent process main thread directly for that case. + // For child process, dispatch fetch op to the parent. + if (StaticPrefs::dom_workers_pFetch_enabled() && !XRE_IsParentProcess()) { + RefPtr actor = + FetchChild::Create(worker, p, signalImpl, observer); + if (!actor) { + NS_WARNING("Could not keep the worker alive."); + aRv.Throw(NS_ERROR_DOM_ABORT_ERR); + return nullptr; + } + + Maybe clientInfo(worker->GlobalScope()->GetClientInfo()); + if (clientInfo.isNothing()) { + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); + return nullptr; + } + + auto* backgroundChild = + mozilla::ipc::BackgroundChild::GetOrCreateForCurrentThread(); + Unused << NS_WARN_IF(!backgroundChild->SendPFetchConstructor(actor)); + + FetchOpArgs ipcArgs; + + ipcArgs.request() = IPCInternalRequest(); + r->ToIPCInternalRequest(&(ipcArgs.request()), backgroundChild); + + ipcArgs.principalInfo() = worker->GetPrincipalInfo(); + ipcArgs.clientInfo() = clientInfo.ref().ToIPC(); + if (worker->GetBaseURI()) { + worker->GetBaseURI()->GetAsciiSpec(ipcArgs.workerScript()); + } + if (worker->GlobalScope()->GetController().isSome()) { + ipcArgs.controller() = + Some(worker->GlobalScope()->GetController().ref().ToIPC()); + } + if (worker->CookieJarSettings()) { + ipcArgs.cookieJarSettings() = Some(worker->CookieJarSettingsArgs()); + } + if (worker->CSPEventListener()) { + ipcArgs.hasCSPEventListener() = true; + actor->SetCSPEventListener(worker->CSPEventListener()); + } else { + ipcArgs.hasCSPEventListener() = false; + } + + actor->DoFetchOp(ipcArgs); + + return p.forget(); + } + RefPtr resolver = WorkerFetchResolver::Create(worker, p, signalImpl, observer); if (!resolver) { diff --git a/dom/fetch/FetchChild.cpp b/dom/fetch/FetchChild.cpp index 124a05118618..469d0e84a78a 100644 --- a/dom/fetch/FetchChild.cpp +++ b/dom/fetch/FetchChild.cpp @@ -3,41 +3,332 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "FetchChild.h" +#include "FetchLog.h" +#include "FetchObserver.h" +#include "InternalResponse.h" +#include "Request.h" +#include "Response.h" +#include "mozilla/ConsoleReportCollector.h" +#include "mozilla/SchedulerGroup.h" +#include "mozilla/dom/PerformanceTiming.h" +#include "mozilla/dom/PerformanceStorage.h" +#include "mozilla/dom/Promise.h" +#include "mozilla/dom/RemoteWorkerChild.h" +#include "mozilla/dom/SecurityPolicyViolationEventBinding.h" +#include "mozilla/dom/WorkerPrivate.h" +#include "mozilla/dom/WorkerRef.h" +#include "mozilla/dom/WorkerScope.h" +#include "nsIAsyncInputStream.h" +#include "nsIGlobalObject.h" +#include "nsIObserverService.h" +#include "nsIRunnable.h" +#include "nsIURI.h" +#include "nsNetUtil.h" +#include "nsThreadUtils.h" namespace mozilla::dom { +NS_IMPL_ISUPPORTS0(FetchChild) + mozilla::ipc::IPCResult FetchChild::Recv__delete__(const nsresult&& aResult) { + FETCH_LOG(("FetchChild::Recv__delete__ [%p]", this)); + if (mIsShutdown) { + return IPC_OK(); + } + // Shutdown has not been called, so mWorkerRef->Private() should be still + // alive. + MOZ_ASSERT(mWorkerRef->Private()); + mWorkerRef->Private()->AssertIsOnWorkerThread(); + + if (mPromise->State() == Promise::PromiseState::Pending) { + if (NS_FAILED(aResult)) { + mPromise->MaybeReject(aResult); + if (mFetchObserver) { + mFetchObserver->SetState(FetchState::Errored); + } + } else { + mPromise->MaybeResolve(aResult); + if (mFetchObserver) { + mFetchObserver->SetState(FetchState::Complete); + } + } + } return IPC_OK(); } mozilla::ipc::IPCResult FetchChild::RecvOnResponseAvailableInternal( ParentToChildInternalResponse&& aResponse) { - // TODO: Should perform WorkerFetchResolver::OnResponseAvailableInternal here. + FETCH_LOG(("FetchChild::RecvOnResponseAvailableInternal [%p]", this)); + if (mIsShutdown) { + return IPC_OK(); + } + // Shutdown has not been called, so mWorkerRef->Private() should be still + // alive. + MOZ_ASSERT(mWorkerRef->Private()); + mWorkerRef->Private()->AssertIsOnWorkerThread(); + SafeRefPtr internalResponse = + InternalResponse::FromIPC(aResponse); + IgnoredErrorResult result; + internalResponse->Headers()->SetGuard(HeadersGuardEnum::Immutable, result); + MOZ_ASSERT(internalResponse); + + if (internalResponse->Type() != ResponseType::Error) { + if (internalResponse->Type() == ResponseType::Opaque) { + internalResponse->GeneratePaddingInfo(); + } + + if (mFetchObserver) { + mFetchObserver->SetState(FetchState::Complete); + } + nsCOMPtr global; + global = mWorkerRef->Private()->GlobalScope(); + RefPtr response = + new Response(global, internalResponse.clonePtr(), mSignalImpl); + mPromise->MaybeResolve(response); + + return IPC_OK(); + } + + FETCH_LOG( + ("FetchChild::RecvOnResponseAvailableInternal [%p] response type is " + "Error(0x%x)", + this, static_cast(internalResponse->GetErrorCode()))); + if (mFetchObserver) { + mFetchObserver->SetState(FetchState::Errored); + } + mPromise->MaybeRejectWithTypeError(); return IPC_OK(); } mozilla::ipc::IPCResult FetchChild::RecvOnResponseEnd(ResponseEndArgs&& aArgs) { - // TODO: Should perform WorkerFetchResolver::OnResponseEnd here. + FETCH_LOG(("FetchChild::RecvOnResponseEnd [%p]", this)); + if (mIsShutdown) { + return IPC_OK(); + } + // Shutdown has not been called, so mWorkerRef->Private() should be still + // alive. + MOZ_ASSERT(mWorkerRef->Private()); + mWorkerRef->Private()->AssertIsOnWorkerThread(); + + if (aArgs.timing().isSome()) { + const auto& timing = aArgs.timing().ref(); + RefPtr performanceStorage = + mWorkerRef->Private()->GetPerformanceStorage(); + if (performanceStorage) { + performanceStorage->AddEntry( + timing.entryName(), timing.initiatorType(), + MakeUnique(timing.timingData())); + } + } + + if (aArgs.endReason() == FetchDriverObserver::eAborted) { + FETCH_LOG( + ("FetchChild::RecvOnResponseEnd [%p] endReason is eAborted", this)); + if (mFetchObserver) { + mFetchObserver->SetState(FetchState::Errored); + } + mPromise->MaybeReject(NS_ERROR_DOM_ABORT_ERR); + } + + Unfollow(); return IPC_OK(); } mozilla::ipc::IPCResult FetchChild::RecvOnDataAvailable() { - // TODO: Should perform WorkerFetchResolver::OnDataAvailable here. + FETCH_LOG(("FetchChild::RecvOnDataAvailable [%p]", this)); + if (mIsShutdown) { + return IPC_OK(); + } + // Shutdown has not been called, so mWorkerRef->Private() should be still + // alive. + MOZ_ASSERT(mWorkerRef->Private()); + mWorkerRef->Private()->AssertIsOnWorkerThread(); + + if (mFetchObserver && mFetchObserver->State() == FetchState::Requesting) { + mFetchObserver->SetState(FetchState::Responding); + } return IPC_OK(); } mozilla::ipc::IPCResult FetchChild::RecvOnFlushConsoleReport( nsTArray&& aReports) { - // TODO: Should perform WorkerFetchResolver::FlushConsoleReport here. + FETCH_LOG(("FetchChild::RecvOnFlushConsoleReport [%p]", this)); + if (mIsShutdown) { + return IPC_OK(); + } + // Shutdown has not been called, so mWorkerRef->Private() should be still + // alive. + MOZ_ASSERT(mWorkerRef->Private()); + mWorkerRef->Private()->AssertIsOnWorkerThread(); + MOZ_ASSERT(mReporter); + + RefPtr workerRef = mWorkerRef; + nsCOMPtr reporter = mReporter; + + nsCOMPtr r = NS_NewRunnableFunction( + __func__, [reports = std::move(aReports), reporter = std::move(reporter), + workerRef = std::move(workerRef)]() mutable { + for (const auto& report : reports) { + reporter->AddConsoleReport( + report.errorFlags(), report.category(), + static_cast( + report.propertiesFile()), + report.sourceFileURI(), report.lineNumber(), + report.columnNumber(), report.messageName(), + report.stringParams()); + } + + if (workerRef->Private()->IsServiceWorker()) { + reporter->FlushReportsToConsoleForServiceWorkerScope( + workerRef->Private()->ServiceWorkerScope()); + } + + if (workerRef->Private()->IsSharedWorker()) { + workerRef->Private() + ->GetRemoteWorkerController() + ->FlushReportsOnMainThread(reporter); + } + + reporter->FlushConsoleReports(workerRef->Private()->GetLoadGroup()); + }); + MOZ_ALWAYS_SUCCEEDS( + SchedulerGroup::Dispatch(TaskCategory::Other, r.forget())); + return IPC_OK(); } +RefPtr FetchChild::Create(WorkerPrivate* aWorkerPrivate, + RefPtr aPromise, + RefPtr aSignalImpl, + RefPtr aObserver) { + MOZ_DIAGNOSTIC_ASSERT(aWorkerPrivate); + aWorkerPrivate->AssertIsOnWorkerThread(); + + RefPtr actor = MakeRefPtr( + std::move(aPromise), std::move(aSignalImpl), std::move(aObserver)); + + RefPtr workerRef = + StrongWorkerRef::Create(aWorkerPrivate, "FetchChild", [actor]() { + FETCH_LOG(("StrongWorkerRef callback")); + actor->Shutdown(); + }); + if (NS_WARN_IF(!workerRef)) { + return nullptr; + } + + actor->mWorkerRef = new ThreadSafeWorkerRef(workerRef); + if (NS_WARN_IF(!actor->mWorkerRef)) { + return nullptr; + } + return actor; +} + mozilla::ipc::IPCResult FetchChild::RecvOnCSPViolationEvent( const nsAString& aJSON) { - // TODO: Should dispatch csp violation event to worker scope. + FETCH_LOG(("FetchChild::RecvOnCSPViolationEvent [%p] aJSON: %s\n", this, + NS_ConvertUTF16toUTF8(aJSON).BeginReading())); + + nsString JSON(aJSON); + + nsCOMPtr r = NS_NewRunnableFunction(__func__, [JSON]() mutable { + SecurityPolicyViolationEventInit violationEventInit; + if (NS_WARN_IF(!violationEventInit.Init(JSON))) { + return; + } + + nsCOMPtr uri; + nsresult rv = + NS_NewURI(getter_AddRefs(uri), violationEventInit.mBlockedURI); + if (NS_WARN_IF(NS_FAILED(rv))) { + return; + } + + nsCOMPtr observerService = + mozilla::services::GetObserverService(); + if (!observerService) { + return; + } + + rv = observerService->NotifyObservers( + uri, CSP_VIOLATION_TOPIC, violationEventInit.mViolatedDirective.get()); + if (NS_WARN_IF(NS_FAILED(rv))) { + return; + } + }); + MOZ_ALWAYS_SUCCEEDS( + SchedulerGroup::Dispatch(TaskCategory::Other, r.forget())); + + if (mCSPEventListener) { + Unused << NS_WARN_IF( + NS_FAILED(mCSPEventListener->OnCSPViolationEvent(aJSON))); + } return IPC_OK(); } -void FetchChild::ActorDestroy(ActorDestroyReason aReason) {} +void FetchChild::SetCSPEventListener(nsICSPEventListener* aListener) { + MOZ_ASSERT(aListener && !mCSPEventListener); + mCSPEventListener = aListener; +} + +FetchChild::FetchChild(RefPtr&& aPromise, + RefPtr&& aSignalImpl, + RefPtr&& aObserver) + : mPromise(std::move(aPromise)), + mSignalImpl(std::move(aSignalImpl)), + mFetchObserver(std::move(aObserver)), + mReporter(new ConsoleReportCollector()) { + FETCH_LOG(("FetchChild::FetchChild [%p]", this)); +} + +void FetchChild::RunAbortAlgorithm() { + FETCH_LOG(("FetchChild::RunAbortAlgorithm [%p]", this)); + if (mIsShutdown) { + return; + } + if (mWorkerRef) { + Unused << SendAbortFetchOp(); + } +} + +void FetchChild::DoFetchOp(const FetchOpArgs& aArgs) { + FETCH_LOG(("FetchChild::DoFetchOp [%p]", this)); + if (mSignalImpl) { + if (mSignalImpl->Aborted()) { + Unused << SendAbortFetchOp(); + return; + } + Follow(mSignalImpl); + } + Unused << SendFetchOp(aArgs); +} + +void FetchChild::Shutdown() { + FETCH_LOG(("FetchChild::Shutdown [%p]", this)); + if (mIsShutdown) { + return; + } + mIsShutdown.Flip(); + + // If mWorkerRef is nullptr here, that means Recv__delete__() must be called + if (!mWorkerRef) { + return; + } + mPromise = nullptr; + mFetchObserver = nullptr; + Unfollow(); + mSignalImpl = nullptr; + mCSPEventListener = nullptr; + Unused << SendAbortFetchOp(); + mWorkerRef = nullptr; +} + +void FetchChild::ActorDestroy(ActorDestroyReason aReason) { + FETCH_LOG(("FetchChild::ActorDestroy [%p]", this)); + mPromise = nullptr; + mFetchObserver = nullptr; + mSignalImpl = nullptr; + mCSPEventListener = nullptr; + mWorkerRef = nullptr; +} } // namespace mozilla::dom diff --git a/dom/fetch/FetchChild.h b/dom/fetch/FetchChild.h index 88104f8cc8b0..4720a186095b 100644 --- a/dom/fetch/FetchChild.h +++ b/dom/fetch/FetchChild.h @@ -5,15 +5,26 @@ #ifndef mozilla_dom_fetchChild_h__ #define mozilla_dom_fetchChild_h__ +#include "mozilla/dom/AbortSignal.h" +#include "mozilla/dom/AbortFollower.h" +#include "mozilla/dom/FlippedOnce.h" #include "mozilla/dom/PFetchChild.h" +#include "nsIConsoleReportCollector.h" +#include "nsIContentSecurityPolicy.h" +#include "nsISupports.h" namespace mozilla::dom { -class FetchChild final : public PFetchChild { +class FetchObserver; +class ThreadSafeWorkerRef; +class Promise; +class WorkerPrivate; + +class FetchChild final : public PFetchChild, public AbortFollower { friend class PFetchChild; public: - NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FetchChild, override); + NS_DECL_THREADSAFE_ISUPPORTS mozilla::ipc::IPCResult Recv__delete__(const nsresult&& aResult); @@ -29,10 +40,35 @@ class FetchChild final : public PFetchChild { mozilla::ipc::IPCResult RecvOnCSPViolationEvent(const nsAString& aJSon); + void SetCSPEventListener(nsICSPEventListener* aListener); + + static RefPtr Create(WorkerPrivate* aWorkerPrivate, + RefPtr aPromise, + RefPtr aSignalImpl, + RefPtr aObserver); + + FetchChild(RefPtr&& aPromise, RefPtr&& aSignalImpl, + RefPtr&& aObserver); + + // AbortFollower + void RunAbortAlgorithm() override; + + void DoFetchOp(const FetchOpArgs& aArgs); + private: ~FetchChild() = default; + // WorkerPrivate shutdown callback. + void Shutdown(); void ActorDestroy(ActorDestroyReason aReason) override; + + RefPtr mWorkerRef; + RefPtr mPromise; + RefPtr mSignalImpl; + RefPtr mFetchObserver; + nsCOMPtr mCSPEventListener; + nsCOMPtr mReporter; + FlippedOnce mIsShutdown; }; } // namespace mozilla::dom diff --git a/dom/workers/WorkerCSPEventListener.cpp b/dom/workers/WorkerCSPEventListener.cpp index 4fbb7e74ca66..bcfe219cc789 100644 --- a/dom/workers/WorkerCSPEventListener.cpp +++ b/dom/workers/WorkerCSPEventListener.cpp @@ -71,8 +71,6 @@ WorkerCSPEventListener::WorkerCSPEventListener() NS_IMETHODIMP WorkerCSPEventListener::OnCSPViolationEvent(const nsAString& aJSON) { - MOZ_ASSERT(NS_IsMainThread()); - MutexAutoLock lock(mMutex); if (!mWorkerRef) { return NS_OK; @@ -81,9 +79,26 @@ WorkerCSPEventListener::OnCSPViolationEvent(const nsAString& aJSON) { WorkerPrivate* workerPrivate = mWorkerRef->GetUnsafePrivate(); MOZ_ASSERT(workerPrivate); - RefPtr runnable = - new WorkerCSPEventRunnable(workerPrivate, aJSON); - runnable->Dispatch(); + if (NS_IsMainThread()) { + RefPtr runnable = + new WorkerCSPEventRunnable(workerPrivate, aJSON); + runnable->Dispatch(); + + return NS_OK; + } + + SecurityPolicyViolationEventInit violationEventInit; + if (NS_WARN_IF(!violationEventInit.Init(aJSON))) { + return NS_ERROR_UNEXPECTED; + } + + RefPtr event = + mozilla::dom::SecurityPolicyViolationEvent::Constructor( + workerPrivate->GlobalScope(), u"securitypolicyviolation"_ns, + violationEventInit); + event->SetTrusted(true); + + workerPrivate->GlobalScope()->DispatchEvent(*event); return NS_OK; } diff --git a/dom/workers/WorkerLoadInfo.h b/dom/workers/WorkerLoadInfo.h index 7fb0b6bec041..c75ab4588651 100644 --- a/dom/workers/WorkerLoadInfo.h +++ b/dom/workers/WorkerLoadInfo.h @@ -12,6 +12,7 @@ #include "mozilla/OriginTrials.h" #include "mozilla/UniquePtr.h" #include "mozilla/dom/ChannelInfo.h" +#include "mozilla/net/NeckoChannelParams.h" #include "mozilla/dom/ServiceWorkerRegistrationDescriptor.h" #include "mozilla/dom/WorkerCommon.h" @@ -62,6 +63,10 @@ struct WorkerLoadInfoData { // Taken from the parent context. nsCOMPtr mCookieJarSettings; + // The CookieJarSettingsArgs of mCookieJarSettings. + // This is specific for accessing on worker thread. + net::CookieJarSettingsArgs mCookieJarSettingsArgs; + nsCOMPtr mScriptContext; nsCOMPtr mWindow; nsCOMPtr mCSP; diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index a03caa714962..394a19945525 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -2753,6 +2753,9 @@ nsresult WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow, loadInfo.mHasStorageAccessPermissionGranted = aParent->HasStorageAccessPermissionGranted(); loadInfo.mCookieJarSettings = aParent->CookieJarSettings(); + if (loadInfo.mCookieJarSettings) { + loadInfo.mCookieJarSettingsArgs = aParent->CookieJarSettingsArgs(); + } loadInfo.mOriginAttributes = aParent->GetOriginAttributes(); loadInfo.mServiceWorkersTestingInWindow = aParent->ServiceWorkersTestingInWindow(); @@ -2910,6 +2913,11 @@ nsresult WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow, loadInfo.mIsThirdPartyContextToTopWindow = AntiTrackingUtils::IsThirdPartyWindow(globalWindow, nullptr); loadInfo.mCookieJarSettings = document->CookieJarSettings(); + if (loadInfo.mCookieJarSettings) { + auto* cookieJarSettings = + net::CookieJarSettings::Cast(loadInfo.mCookieJarSettings); + cookieJarSettings->Serialize(loadInfo.mCookieJarSettingsArgs); + } StoragePrincipalHelper::GetRegularPrincipalOriginAttributes( document, loadInfo.mOriginAttributes); loadInfo.mParentController = globalWindow->GetController(); @@ -2964,6 +2972,9 @@ nsresult WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow, loadInfo.mLoadingPrincipal, "Unusual situation - we have no document or CookieJarSettings"); MOZ_ASSERT(loadInfo.mCookieJarSettings); + auto* cookieJarSettings = + net::CookieJarSettings::Cast(loadInfo.mCookieJarSettings); + cookieJarSettings->Serialize(loadInfo.mCookieJarSettingsArgs); loadInfo.mOriginAttributes = OriginAttributes(); loadInfo.mIsThirdPartyContextToTopWindow = false; diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index 2107d505d921..dd52bfa137a6 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -38,6 +38,7 @@ #include "mozilla/dom/workerinternals/JSSettings.h" #include "mozilla/dom/workerinternals/Queue.h" #include "mozilla/dom/JSExecutionManager.h" +#include "mozilla/net/NeckoChannelParams.h" #include "mozilla/StaticPrefs_extensions.h" #include "nsContentUtils.h" #include "nsIChannel.h" @@ -872,6 +873,11 @@ class WorkerPrivate final return mLoadInfo.mCookieJarSettings; } + const net::CookieJarSettingsArgs& CookieJarSettingsArgs() const { + MOZ_ASSERT(mLoadInfo.mCookieJarSettings); + return mLoadInfo.mCookieJarSettingsArgs; + } + const OriginAttributes& GetOriginAttributes() const { return mLoadInfo.mOriginAttributes; } diff --git a/dom/workers/remoteworkers/RemoteWorkerChild.cpp b/dom/workers/remoteworkers/RemoteWorkerChild.cpp index 71e77f6030f6..64cf434fb44f 100644 --- a/dom/workers/remoteworkers/RemoteWorkerChild.cpp +++ b/dom/workers/remoteworkers/RemoteWorkerChild.cpp @@ -374,6 +374,7 @@ nsresult RemoteWorkerChild::ExecWorkerOnMainThread(RemoteWorkerData&& aData) { info.mShouldResistFingerprinting = aData.shouldResistFingerprinting(); net::CookieJarSettings::Deserialize(aData.cookieJarSettings(), getter_AddRefs(info.mCookieJarSettings)); + info.mCookieJarSettingsArgs = aData.cookieJarSettings(); // Default CSP permissions for now. These will be overrided if necessary // based on the script CSP headers during load in ScriptLoader. diff --git a/tools/profiler/tests/browser/browser_test_marker_network_serviceworker_cache_first.js b/tools/profiler/tests/browser/browser_test_marker_network_serviceworker_cache_first.js index 4b715efa1cdc..0dce2576444e 100644 --- a/tools/profiler/tests/browser/browser_test_marker_network_serviceworker_cache_first.js +++ b/tools/profiler/tests/browser/browser_test_marker_network_serviceworker_cache_first.js @@ -157,9 +157,6 @@ add_task(async function test_network_markers_service_worker_register() { // Let's look at all pairs and make sure we requested all expected files. const parentStopMarkers = parentPairs.map(([_, stopMarker]) => stopMarker); - const serviceWorkerStopMarkers = serviceWorkerPairs.map( - ([_, stopMarker]) => stopMarker - ); // These are the files cached by the service worker. We should see markers // for both the parent thread and the service worker thread. @@ -175,9 +172,6 @@ add_task(async function test_network_markers_service_worker_register() { const parentMarker = parentStopMarkers.find( marker => marker.data.URI === expectedFile ); - const serviceWorkerMarker = serviceWorkerStopMarkers.find( - marker => marker.data.URI === expectedFile - ); const expectedProperties = { name: Expect.stringMatches( @@ -205,7 +199,6 @@ add_task(async function test_network_markers_service_worker_register() { }; Assert.objectContains(parentMarker, expectedProperties); - Assert.objectContains(serviceWorkerMarker, expectedProperties); } }); }); diff --git a/tools/profiler/tests/browser/browser_test_marker_network_serviceworker_synthetized_response.js b/tools/profiler/tests/browser/browser_test_marker_network_serviceworker_synthetized_response.js index 41690e11a6f2..ed1ee9e9e4f8 100644 --- a/tools/profiler/tests/browser/browser_test_marker_network_serviceworker_synthetized_response.js +++ b/tools/profiler/tests/browser/browser_test_marker_network_serviceworker_synthetized_response.js @@ -178,10 +178,6 @@ add_task(async function test_network_markers_service_worker_use() { const contentStopMarkers = contentPairs.map( ([_, stopMarker]) => stopMarker ); - const serviceWorkerStopMarkers = serviceWorkerPairs.map( - ([_, stopMarker]) => stopMarker - ); - // In this test we have very different results in the various threads, so // we'll assert every case separately. // A simple function to help constructing better assertions: @@ -394,11 +390,7 @@ add_task(async function test_network_markers_service_worker_use() { // The "1" requests are the initial requests that are intercepted, coming // from the web page, while the "2" requests are the requests coming from // the service worker. - let htmlFetch1, - htmlFetch2, - generatedSvgFetch1, - firefoxSvgFetch1, - firefoxSvgFetch2; + let htmlFetch1, generatedSvgFetch1, firefoxSvgFetch1; // First, let's handle the case where the threads are different: if (serviceWorkerParentThread !== contentThread) { @@ -418,18 +410,6 @@ add_task(async function test_network_markers_service_worker_use() { ); [htmlFetch1, generatedSvgFetch1, firefoxSvgFetch1] = contentStopMarkers; - - // In the service worker parent thread, we have 2 network markers: - // - the HTML file - // - the firefox SVG file. - // Remember that the generated SVG file is returned directly by the SW. - Assert.equal( - serviceWorkerStopMarkers.length, - 2, - "There should be 2 stop markers in the service worker thread." - ); - - [htmlFetch2, firefoxSvgFetch2] = serviceWorkerStopMarkers; } else { // Else case: the service worker parent thread IS the content thread // (note: this is always the case with fission). In that case all network @@ -448,11 +428,9 @@ add_task(async function test_network_markers_service_worker_use() { // everything happens first in the main process, possibly before a // content process even exists, and the content process is merely // notified at the end. - htmlFetch2, htmlFetch1, generatedSvgFetch1, firefoxSvgFetch1, - firefoxSvgFetch2, ] = contentStopMarkers; } @@ -501,58 +479,5 @@ add_task(async function test_network_markers_service_worker_use() { innerWindowID: Expect.number(), }), }); - - // Now let's test the markers coming from the service worker. - Assert.objectContains(htmlFetch2, { - name: Expect.stringMatches(/Load \d+:.*serviceworker_simple.html/), - data: Expect.objectContainsOnly({ - type: "Network", - status: "STATUS_STOP", - URI: fullUrl("serviceworker_simple.html"), - requestMethod: "GET", - contentType: "text/html", - startTime: Expect.number(), - endTime: Expect.number(), - domainLookupStart: Expect.number(), - domainLookupEnd: Expect.number(), - connectStart: Expect.number(), - tcpConnectEnd: Expect.number(), - connectEnd: Expect.number(), - requestStart: Expect.number(), - responseStart: Expect.number(), - responseEnd: Expect.number(), - id: Expect.number(), - count: Expect.number(), - pri: Expect.number(), - // Note: no innerWindowID here, is that a bug? - // Note: no cache either, this is bug 1544821. - }), - }); - - Assert.objectContains(firefoxSvgFetch2, { - name: Expect.stringMatches(/Load \d+:.*firefox-logo-nightly.svg/), - data: Expect.objectContainsOnly({ - type: "Network", - status: "STATUS_STOP", - URI: fullUrl("firefox-logo-nightly.svg"), - requestMethod: "GET", - contentType: "image/svg+xml", - startTime: Expect.number(), - endTime: Expect.number(), - domainLookupStart: Expect.number(), - domainLookupEnd: Expect.number(), - connectStart: Expect.number(), - tcpConnectEnd: Expect.number(), - connectEnd: Expect.number(), - requestStart: Expect.number(), - responseStart: Expect.number(), - responseEnd: Expect.number(), - id: Expect.number(), - count: Expect.number(), - pri: Expect.number(), - // Note: no innerWindowID here, is that a bug? - // Note: no cache either, this is bug 1544821. - }), - }); }); });