Bug 1819570 - P2 Save worker's associated BrowsingContextID in channel's LoadInfo for the netmonitor. r=necko-reviewers,valentin

After PFetch is enabled, fetch() call in workers will not create a channel in the content process anymore.
Although netmonitor also watches the channels in the parent process, the created channel still loses the BrowsingContext information for netmonitor to connect the network event and the channel.

In P1, https://phabricator.services.mozilla.com/D174249, we propagate the BrowsingContext ID through PFetch.
In this patch, we need to save it in channel's LoadInfo for netmonitor.

In order not to confuse with nsILoadInfo's BrowsingContextID, we create a new attribute WorkerAssociatedBrowsingContextID in nsILoadInfo.

Depends on D174249

Differential Revision: https://phabricator.services.mozilla.com/D174441
This commit is contained in:
Eden Chuang 2023-05-05 15:24:09 +00:00
Родитель f6ba398065
Коммит da9145b668
5 изменённых файлов: 55 добавлений и 0 удалений

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

@ -648,6 +648,12 @@ nsresult FetchDriver::HttpFetch(
NS_ENSURE_SUCCESS(rv, rv);
}
if (mAssociatedBrowsingContextID) {
nsCOMPtr<nsILoadInfo> loadInfo = chan->LoadInfo();
rv = loadInfo->SetWorkerAssociatedBrowsingContextID(
mAssociatedBrowsingContextID);
}
// If the fetch is created by FetchEvent.request or NavigationPreload request,
// corresponding InterceptedHttpChannel information need to propagte to the
// channel of the fetch.

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

@ -586,6 +586,8 @@ LoadInfo::LoadInfo(const LoadInfo& rhs)
mForceInheritPrincipalDropped(rhs.mForceInheritPrincipalDropped),
mInnerWindowID(rhs.mInnerWindowID),
mBrowsingContextID(rhs.mBrowsingContextID),
mWorkerAssociatedBrowsingContextID(
rhs.mWorkerAssociatedBrowsingContextID),
mFrameBrowsingContextID(rhs.mFrameBrowsingContextID),
mInitialSecurityCheckDone(rhs.mInitialSecurityCheckDone),
mIsThirdPartyContext(rhs.mIsThirdPartyContext),
@ -1294,6 +1296,18 @@ LoadInfo::GetBrowsingContextID(uint64_t* aResult) {
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::GetWorkerAssociatedBrowsingContextID(uint64_t* aResult) {
*aResult = mWorkerAssociatedBrowsingContextID;
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::SetWorkerAssociatedBrowsingContextID(uint64_t aID) {
mWorkerAssociatedBrowsingContextID = aID;
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::GetFrameBrowsingContextID(uint64_t* aResult) {
*aResult = mFrameBrowsingContextID;
@ -1314,6 +1328,12 @@ LoadInfo::GetBrowsingContext(dom::BrowsingContext** aResult) {
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::GetWorkerAssociatedBrowsingContext(dom::BrowsingContext** aResult) {
*aResult = BrowsingContext::Get(mWorkerAssociatedBrowsingContextID).take();
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::GetFrameBrowsingContext(dom::BrowsingContext** aResult) {
*aResult = BrowsingContext::Get(mFrameBrowsingContextID).take();

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

@ -317,6 +317,7 @@ class LoadInfo final : public nsILoadInfo {
bool mForceInheritPrincipalDropped = false;
uint64_t mInnerWindowID = 0;
uint64_t mBrowsingContextID = 0;
uint64_t mWorkerAssociatedBrowsingContextID = 0;
uint64_t mFrameBrowsingContextID = 0;
bool mInitialSecurityCheckDone = false;
// NB: TYPE_DOCUMENT implies !third-party.

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

@ -336,6 +336,16 @@ TRRLoadInfo::GetBrowsingContextID(uint64_t* aResult) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
TRRLoadInfo::GetWorkerAssociatedBrowsingContextID(uint64_t* aResult) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
TRRLoadInfo::SetWorkerAssociatedBrowsingContextID(uint64_t aResult) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
TRRLoadInfo::GetFrameBrowsingContextID(uint64_t* aResult) {
return NS_ERROR_NOT_IMPLEMENTED;
@ -351,6 +361,12 @@ TRRLoadInfo::GetBrowsingContext(dom::BrowsingContext** aResult) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
TRRLoadInfo::GetWorkerAssociatedBrowsingContext(
dom::BrowsingContext** aResult) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
TRRLoadInfo::GetFrameBrowsingContext(dom::BrowsingContext** aResult) {
return NS_ERROR_NOT_IMPLEMENTED;

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

@ -800,6 +800,18 @@ interface nsILoadInfo : nsISupports
[infallible] readonly attribute unsigned long long browsingContextID;
[infallible] readonly attribute BrowsingContext browsingContext;
/**
* The BrowsingContext which the worker is associated.
*
* Note that this could be 0 if the load is not triggered in a WorkerScope.
* This value is only set and used in the parent process for some sitautions
* the channel is created in the parent process for Workers. Such as fetch().
* In content process, it is always 0.
* This value would not be propagated through IPC.
*/
[infallible] attribute unsigned long long workerAssociatedBrowsingContextID;
[infallible] readonly attribute BrowsingContext workerAssociatedBrowsingContext;
/**
* Only when the element being loaded is <frame src="foo.html">
* (or, more generally, if the element QIs to nsFrameLoaderOwner),