Skip to content

Commit

Permalink
Bug 1814686 - Part 2: Make nsDocShellLoadState not-null, and simplify…
Browse files Browse the repository at this point in the history
… handling of nsDOMNavigationTiming, r=necko-reviewers,valentin,smaug

These types were already non-nullable, with the serializer implementation not
supporting nullptr values. This patch converts the uses to be explicitly
non-nullable, and adds the relevant `WrapNotNull` changes.

Differential Revision: https://phabricator.services.mozilla.com/D168890
  • Loading branch information
mystor committed Mar 20, 2023
1 parent ca81dd3 commit 73c6cca
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 59 deletions.
8 changes: 4 additions & 4 deletions docshell/base/BrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1946,7 +1946,7 @@ nsresult BrowsingContext::LoadURI(nsDocShellLoadState* aLoadState,
if (!wgc->CanNavigate(this)) {
return NS_ERROR_DOM_PROP_ACCESS_DENIED;
}
wgc->SendLoadURI(this, aLoadState, aSetNavigating);
wgc->SendLoadURI(this, mozilla::WrapNotNull(aLoadState), aSetNavigating);
}
} else if (XRE_IsParentProcess()) {
if (Canonical()->LoadInParent(aLoadState, aSetNavigating)) {
Expand All @@ -1969,7 +1969,7 @@ nsresult BrowsingContext::LoadURI(nsDocShellLoadState* aLoadState,
// load. Normally we'd expect a PDocumentChannel actor to have been
// created to claim the load identifier by that time. If not, then it
// won't be coming, so make sure we clean up and deregister.
cp->SendLoadURI(this, aLoadState, aSetNavigating)
cp->SendLoadURI(this, mozilla::WrapNotNull(aLoadState), aSetNavigating)
->Then(GetMainThreadSerialEventTarget(), __func__,
[loadIdentifier](
const PContentParent::LoadURIPromise::ResolveOrRejectValue&
Expand Down Expand Up @@ -2039,7 +2039,7 @@ nsresult BrowsingContext::InternalLoad(nsDocShellLoadState* aLoadState) {

MOZ_ALWAYS_SUCCEEDS(
SetCurrentLoadIdentifier(Some(aLoadState->GetLoadIdentifier())));
Unused << cp->SendInternalLoad(aLoadState);
Unused << cp->SendInternalLoad(mozilla::WrapNotNull(aLoadState));
} else {
MOZ_DIAGNOSTIC_ASSERT(sourceBC);
MOZ_DIAGNOSTIC_ASSERT(sourceBC->Group() == Group());
Expand All @@ -2056,7 +2056,7 @@ nsresult BrowsingContext::InternalLoad(nsDocShellLoadState* aLoadState) {

MOZ_ALWAYS_SUCCEEDS(
SetCurrentLoadIdentifier(Some(aLoadState->GetLoadIdentifier())));
wgc->SendInternalLoad(aLoadState);
wgc->SendInternalLoad(mozilla::WrapNotNull(aLoadState));
}

return NS_OK;
Expand Down
10 changes: 6 additions & 4 deletions docshell/base/CanonicalBrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ already_AddRefed<nsDocShellLoadState> CanonicalBrowsingContext::CreateLoadInfo(

void CanonicalBrowsingContext::NotifyOnHistoryReload(
bool aForceReload, bool& aCanReload,
Maybe<RefPtr<nsDocShellLoadState>>& aLoadState,
Maybe<NotNull<RefPtr<nsDocShellLoadState>>>& aLoadState,
Maybe<bool>& aReloadActiveEntry) {
MOZ_DIAGNOSTIC_ASSERT(!aLoadState);

Expand All @@ -1034,15 +1034,16 @@ void CanonicalBrowsingContext::NotifyOnHistoryReload(
}

if (mActiveEntry) {
aLoadState.emplace(CreateLoadInfo(mActiveEntry));
aLoadState.emplace(WrapMovingNotNull(RefPtr{CreateLoadInfo(mActiveEntry)}));
aReloadActiveEntry.emplace(true);
if (aForceReload) {
shistory->RemoveFrameEntries(mActiveEntry);
}
} else if (!mLoadingEntries.IsEmpty()) {
const LoadingSessionHistoryEntry& loadingEntry =
mLoadingEntries.LastElement();
aLoadState.emplace(CreateLoadInfo(loadingEntry.mEntry));
aLoadState.emplace(
WrapMovingNotNull(RefPtr{CreateLoadInfo(loadingEntry.mEntry)}));
aReloadActiveEntry.emplace(false);
if (aForceReload) {
SessionHistoryEntry::LoadingEntry* entry =
Expand Down Expand Up @@ -2486,7 +2487,8 @@ void CanonicalBrowsingContext::RequestRestoreTabContent(

if (data->CanRestoreInto(aWindow->GetDocumentURI())) {
if (!aWindow->IsInProcess()) {
aWindow->SendRestoreTabContent(data, onTabRestoreComplete,
aWindow->SendRestoreTabContent(WrapNotNull(data.get()),
onTabRestoreComplete,
onTabRestoreComplete);
return;
}
Expand Down
7 changes: 4 additions & 3 deletions docshell/base/CanonicalBrowsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ class CanonicalBrowsingContext final : public BrowsingContext {
// aReloadActiveEntry will be true if we have an active entry. If aCanReload
// is true and aLoadState and aReloadActiveEntry are not set then we should
// attempt to reload based on the current document in the docshell.
void NotifyOnHistoryReload(bool aForceReload, bool& aCanReload,
Maybe<RefPtr<nsDocShellLoadState>>& aLoadState,
Maybe<bool>& aReloadActiveEntry);
void NotifyOnHistoryReload(
bool aForceReload, bool& aCanReload,
Maybe<NotNull<RefPtr<nsDocShellLoadState>>>& aLoadState,
Maybe<bool>& aReloadActiveEntry);

// See BrowsingContext::SetActiveSessionHistoryEntry.
void SetActiveSessionHistoryEntry(const Maybe<nsPoint>& aPreviousScrollPos,
Expand Down
8 changes: 4 additions & 4 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4088,8 +4088,8 @@ nsDocShell::Reload(uint32_t aReloadFlags) {
mBrowsingContext, forceReload,
[docShell, doc, loadType, browsingContext, currentURI, referrerInfo,
loadGroup, stopDetector](
Tuple<bool, Maybe<RefPtr<nsDocShellLoadState>>, Maybe<bool>>&&
aResult) {
Tuple<bool, Maybe<NotNull<RefPtr<nsDocShellLoadState>>>,
Maybe<bool>>&& aResult) {
auto scopeExit = MakeScopeExit([loadGroup, stopDetector]() {
if (loadGroup) {
loadGroup->RemoveRequest(stopDetector, nullptr, NS_OK);
Expand All @@ -4099,7 +4099,7 @@ nsDocShell::Reload(uint32_t aReloadFlags) {
return;
}
bool canReload;
Maybe<RefPtr<nsDocShellLoadState>> loadState;
Maybe<NotNull<RefPtr<nsDocShellLoadState>>> loadState;
Maybe<bool> reloadingActiveEntry;

Tie(canReload, loadState, reloadingActiveEntry) = aResult;
Expand Down Expand Up @@ -4127,7 +4127,7 @@ nsDocShell::Reload(uint32_t aReloadFlags) {
} else {
// Parent process
bool canReload = false;
Maybe<RefPtr<nsDocShellLoadState>> loadState;
Maybe<NotNull<RefPtr<nsDocShellLoadState>>> loadState;
Maybe<bool> reloadingActiveEntry;
if (!mBrowsingContext->IsDiscarded()) {
mBrowsingContext->Canonical()->NotifyOnHistoryReload(
Expand Down
15 changes: 15 additions & 0 deletions dom/base/nsDOMNavigationTiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,12 @@ nsDOMNavigationTiming::nsDOMNavigationTiming(nsDocShell* aDocShell,
void mozilla::ipc::IPDLParamTraits<nsDOMNavigationTiming*>::Write(
IPC::MessageWriter* aWriter, IProtocol* aActor,
nsDOMNavigationTiming* aParam) {
bool isNull = !aParam;
WriteIPDLParam(aWriter, aActor, isNull);
if (isNull) {
return;
}

RefPtr<nsIURI> unloadedURI = aParam->mUnloadedURI.get();
RefPtr<nsIURI> loadedURI = aParam->mLoadedURI.get();
WriteIPDLParam(aWriter, aActor, unloadedURI ? Some(unloadedURI) : Nothing());
Expand Down Expand Up @@ -605,6 +611,15 @@ void mozilla::ipc::IPDLParamTraits<nsDOMNavigationTiming*>::Write(
bool mozilla::ipc::IPDLParamTraits<nsDOMNavigationTiming*>::Read(
IPC::MessageReader* aReader, IProtocol* aActor,
RefPtr<nsDOMNavigationTiming>* aResult) {
bool isNull;
if (!ReadIPDLParam(aReader, aActor, &isNull)) {
return false;
}
if (isNull) {
*aResult = nullptr;
return true;
}

auto timing = MakeRefPtr<nsDOMNavigationTiming>(nullptr);
uint32_t type;
Maybe<RefPtr<nsIURI>> unloadedURI;
Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/BrowserBridgeHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool BrowserBridgeHost::CanRecv() const {

void BrowserBridgeHost::LoadURL(nsDocShellLoadState* aLoadState) {
MOZ_ASSERT(aLoadState);
Unused << mBridge->SendLoadURL(aLoadState);
Unused << mBridge->SendLoadURL(WrapNotNull(aLoadState));
}

void BrowserBridgeHost::ResumeLoad(uint64_t aPendingSwitchId) {
Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/BrowserBridgeParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ IPCResult BrowserBridgeParent::RecvScrollbarPreferenceChanged(
}

IPCResult BrowserBridgeParent::RecvLoadURL(nsDocShellLoadState* aLoadState) {
Unused << mBrowserParent->SendLoadURL(aLoadState,
Unused << mBrowserParent->SendLoadURL(WrapNotNull(aLoadState),
mBrowserParent->GetShowInfo());
return IPC_OK();
}
Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/BrowserParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ void BrowserParent::LoadURL(nsDocShellLoadState* aLoadState) {
return;
}

Unused << SendLoadURL(aLoadState, GetShowInfo());
Unused << SendLoadURL(WrapNotNull(aLoadState), GetShowInfo());
}

void BrowserParent::ResumeLoad(uint64_t aPendingSwitchID) {
Expand Down
6 changes: 3 additions & 3 deletions dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3672,9 +3672,9 @@ mozilla::ipc::IPCResult ContentChild::RecvCrossProcessRedirect(
RefPtr<ChildProcessChannelListener> processListener =
ChildProcessChannelListener::GetSingleton();
// The listener will call completeRedirectSetup or asyncOpen on the channel.
processListener->OnChannelReady(
loadState, aArgs.loadIdentifier(), std::move(aEndpoints),
aArgs.timing().refOr(nullptr), std::move(resolve));
processListener->OnChannelReady(loadState, aArgs.loadIdentifier(),
std::move(aEndpoints), aArgs.timing(),
std::move(resolve));
scopeExit.release();

// scopeExit will call CrossProcessRedirectFinished(rv) here
Expand Down
7 changes: 4 additions & 3 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7832,14 +7832,15 @@ mozilla::ipc::IPCResult ContentParent::RecvNotifyOnHistoryReload(
const MaybeDiscarded<BrowsingContext>& aContext, const bool& aForceReload,
NotifyOnHistoryReloadResolver&& aResolver) {
bool canReload = false;
Maybe<RefPtr<nsDocShellLoadState>> loadState;
Maybe<NotNull<RefPtr<nsDocShellLoadState>>> loadState;
Maybe<bool> reloadActiveEntry;
if (!aContext.IsDiscarded()) {
aContext.get_canonical()->NotifyOnHistoryReload(
aForceReload, canReload, loadState, reloadActiveEntry);
}
aResolver(Tuple<const bool&, const Maybe<RefPtr<nsDocShellLoadState>>&,
const Maybe<bool>&>(canReload, loadState, reloadActiveEntry));
aResolver(
Tuple<const bool&, const Maybe<NotNull<RefPtr<nsDocShellLoadState>>>&,
const Maybe<bool>&>(canReload, loadState, reloadActiveEntry));
return IPC_OK();
}

Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/PBrowser.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ child:

async CompositorOptionsChanged(CompositorOptions newOptions);

async LoadURL(nullable nsDocShellLoadState loadState, ParentShowInfo info);
async LoadURL(nsDocShellLoadState loadState, ParentShowInfo info);

async CreateAboutBlankContentViewer(nullable nsIPrincipal principal,
nullable nsIPrincipal partitionedPrincipal);
Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/PBrowserBridge.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ parent:
async BeginDestroy();

// DocShell messaging.
async LoadURL(nullable nsDocShellLoadState aLoadState);
async LoadURL(nsDocShellLoadState aLoadState);
async ResumeLoad(uint64_t aPendingSwitchID);

// Out of process rendering.
Expand Down
6 changes: 3 additions & 3 deletions dom/ipc/PContent.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -995,10 +995,10 @@ child:
async InitSandboxTesting(Endpoint<PSandboxTestingChild> aEndpoint);
#endif

async LoadURI(MaybeDiscardedBrowsingContext aContext, nullable nsDocShellLoadState aLoadState, bool aSetNavigating)
async LoadURI(MaybeDiscardedBrowsingContext aContext, nsDocShellLoadState aLoadState, bool aSetNavigating)
returns (bool aSuccess);

async InternalLoad(nullable nsDocShellLoadState aLoadState);
async InternalLoad(nsDocShellLoadState aLoadState);

async DisplayLoadError(MaybeDiscardedBrowsingContext aContext, nsString aURI);

Expand Down Expand Up @@ -1804,7 +1804,7 @@ parent:

async NotifyOnHistoryReload(MaybeDiscardedBrowsingContext aContext,
bool aForceReload)
returns (bool canReload, nullable nsDocShellLoadState? loadState,
returns (bool canReload, nsDocShellLoadState? loadState,
bool? reloadActiveEntry);

async HistoryCommit(MaybeDiscardedBrowsingContext aContext,
Expand Down
4 changes: 2 additions & 2 deletions dom/ipc/PWindowGlobal.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ parent:
// BrowsingContext. aTargetBC must be in the same BrowsingContextGroup as this
// window global.
async LoadURI(MaybeDiscardedBrowsingContext aTargetBC,
nullable nsDocShellLoadState aLoadState, bool aSetNavigating);
nsDocShellLoadState aLoadState, bool aSetNavigating);

async InternalLoad(nullable nsDocShellLoadState aLoadState);
async InternalLoad(nsDocShellLoadState aLoadState);

/// Update the URI of the document in this WindowGlobal.
[LazySend] async UpdateDocumentURI(nullable nsIURI aUri);
Expand Down
24 changes: 8 additions & 16 deletions netwerk/ipc/DocumentChannelChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,33 +108,20 @@ DocumentChannelChild::AsyncOpen(nsIStreamListener* aListener) {
}
mLoadingContext = loadingContext;

DocumentChannelCreationArgs args;

args.loadState() = mLoadState;
args.cacheKey() = mCacheKey;
args.channelId() = mChannelId;
args.asyncOpenTime() = TimeStamp::Now();
args.parentInitiatedNavigationEpoch() =
loadingContext->GetParentInitiatedNavigationEpoch();

Maybe<IPCClientInfo> ipcClientInfo;
if (mInitialClientInfo.isSome()) {
ipcClientInfo.emplace(mInitialClientInfo.ref().ToIPC());
}
args.initialClientInfo() = ipcClientInfo;

if (mTiming) {
args.timing() = Some(mTiming);
}

DocumentChannelElementCreationArgs ipcElementCreationArgs;
switch (mLoadInfo->GetExternalContentPolicyType()) {
case ExtContentPolicy::TYPE_DOCUMENT:
case ExtContentPolicy::TYPE_SUBDOCUMENT: {
DocumentCreationArgs docArgs;
docArgs.uriModified() = mUriModified;
docArgs.isXFOError() = mIsXFOError;

args.elementCreationArgs() = docArgs;
ipcElementCreationArgs = docArgs;
break;
}

Expand All @@ -145,7 +132,7 @@ DocumentChannelChild::AsyncOpen(nsIStreamListener* aListener) {
objectArgs.contentPolicyType() = mLoadInfo->InternalContentPolicyType();
objectArgs.isUrgentStart() = UserActivation::IsHandlingUserInput();

args.elementCreationArgs() = objectArgs;
ipcElementCreationArgs = objectArgs;
break;
}

Expand All @@ -165,6 +152,11 @@ DocumentChannelChild::AsyncOpen(nsIStreamListener* aListener) {
break;
}

DocumentChannelCreationArgs args(
mozilla::WrapNotNull(mLoadState), TimeStamp::Now(), mChannelId, mCacheKey,
mTiming, ipcClientInfo, ipcElementCreationArgs,
loadingContext->GetParentInitiatedNavigationEpoch());

gNeckoChild->SendPDocumentChannelConstructor(this, loadingContext, args);

mIsPending = true;
Expand Down
15 changes: 7 additions & 8 deletions netwerk/ipc/DocumentChannelParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,18 @@ bool DocumentChannelParent::Init(dom::CanonicalBrowsingContext* aContext,

promise = mDocumentLoadListener->OpenDocument(
loadState, aArgs.cacheKey(), Some(aArgs.channelId()),
aArgs.asyncOpenTime(), aArgs.timing().refOr(nullptr),
std::move(clientInfo), Some(docArgs.uriModified()),
Some(docArgs.isXFOError()), contentParent, &rv);
aArgs.asyncOpenTime(), aArgs.timing(), std::move(clientInfo),
Some(docArgs.uriModified()), Some(docArgs.isXFOError()),
contentParent, &rv);
} else {
const ObjectCreationArgs& objectArgs = aArgs.elementCreationArgs();

promise = mDocumentLoadListener->OpenObject(
loadState, aArgs.cacheKey(), Some(aArgs.channelId()),
aArgs.asyncOpenTime(), aArgs.timing().refOr(nullptr),
std::move(clientInfo), objectArgs.embedderInnerWindowId(),
objectArgs.loadFlags(), objectArgs.contentPolicyType(),
objectArgs.isUrgentStart(), contentParent,
this /* ObjectUpgradeHandler */, &rv);
aArgs.asyncOpenTime(), aArgs.timing(), std::move(clientInfo),
objectArgs.embedderInnerWindowId(), objectArgs.loadFlags(),
objectArgs.contentPolicyType(), objectArgs.isUrgentStart(),
contentParent, this /* ObjectUpgradeHandler */, &rv);
}

if (NS_FAILED(rv)) {
Expand Down
2 changes: 1 addition & 1 deletion netwerk/ipc/DocumentLoadListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ DocumentLoadListener::RedirectToRealChannel(
aLoadFlags, cp, std::move(ehArgs));
if (mTiming) {
mTiming->Anonymize(args.uri());
args.timing() = Some(std::move(mTiming));
args.timing() = std::move(mTiming);
}

auto loadInfo = args.loadInfo();
Expand Down
6 changes: 3 additions & 3 deletions netwerk/ipc/NeckoChannelParams.ipdlh
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,11 @@ union DocumentChannelElementCreationArgs {
};

struct DocumentChannelCreationArgs {
nullable nsDocShellLoadState loadState;
nsDocShellLoadState loadState;
TimeStamp asyncOpenTime;
uint64_t channelId;
uint32_t cacheKey;
nullable nsDOMNavigationTiming? timing;
nullable nsDOMNavigationTiming timing;
IPCClientInfo? initialClientInfo;
DocumentChannelElementCreationArgs elementCreationArgs;
uint64_t parentInitiatedNavigationEpoch;
Expand All @@ -484,7 +484,7 @@ struct RedirectToRealChannelArgs {
uint32_t loadStateExternalLoadFlags;
uint32_t loadStateInternalLoadFlags;
uint32_t loadStateLoadType;
nullable nsDOMNavigationTiming? timing;
nullable nsDOMNavigationTiming timing;
nsString srcdocData;
nullable nsIURI baseUri;
LoadingSessionHistoryInfo? loadingSessionHistoryInfo;
Expand Down

0 comments on commit 73c6cca

Please sign in to comment.