Bug 1745638, allow stopping session history load to an iframe, r=peterv
Differential Revision: https://phabricator.services.mozilla.com/D136041
This commit is contained in:
@@ -891,6 +891,83 @@ bool nsDocShell::IsLoadingFromSessionHistory() {
|
||||
return mActiveEntryIsLoadingFromSessionHistory;
|
||||
}
|
||||
|
||||
// StopDetector is modeled similarly to OnloadBlocker; it is a rather
|
||||
// dummy nsIRequest implementation which can be added to an nsILoadGroup to
|
||||
// detect Cancel calls.
|
||||
class StopDetector final : public nsIRequest {
|
||||
public:
|
||||
StopDetector() = default;
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIREQUEST
|
||||
|
||||
bool Canceled() { return mCanceled; }
|
||||
|
||||
private:
|
||||
~StopDetector() = default;
|
||||
|
||||
bool mCanceled = false;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(StopDetector, nsIRequest)
|
||||
|
||||
NS_IMETHODIMP
|
||||
StopDetector::GetName(nsACString& aResult) {
|
||||
aResult.AssignLiteral("about:stop-detector");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
StopDetector::IsPending(bool* aRetVal) {
|
||||
*aRetVal = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
StopDetector::GetStatus(nsresult* aStatus) {
|
||||
*aStatus = NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
StopDetector::Cancel(nsresult aStatus) {
|
||||
mCanceled = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
StopDetector::Suspend(void) { return NS_OK; }
|
||||
NS_IMETHODIMP
|
||||
StopDetector::Resume(void) { return NS_OK; }
|
||||
|
||||
NS_IMETHODIMP
|
||||
StopDetector::GetLoadGroup(nsILoadGroup** aLoadGroup) {
|
||||
*aLoadGroup = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
StopDetector::SetLoadGroup(nsILoadGroup* aLoadGroup) { return NS_OK; }
|
||||
|
||||
NS_IMETHODIMP
|
||||
StopDetector::GetLoadFlags(nsLoadFlags* aLoadFlags) {
|
||||
*aLoadFlags = nsIRequest::LOAD_NORMAL;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
StopDetector::GetTRRMode(nsIRequest::TRRMode* aTRRMode) {
|
||||
return GetTRRModeImpl(aTRRMode);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
StopDetector::SetTRRMode(nsIRequest::TRRMode aTRRMode) {
|
||||
return SetTRRModeImpl(aTRRMode);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
StopDetector::SetLoadFlags(nsLoadFlags aLoadFlags) { return NS_OK; }
|
||||
|
||||
bool nsDocShell::MaybeHandleSubframeHistory(
|
||||
nsDocShellLoadState* aLoadState, bool aContinueHandlingSubframeHistory) {
|
||||
// First, verify if this is a subframe.
|
||||
@@ -933,7 +1010,9 @@ bool nsDocShell::MaybeHandleSubframeHistory(
|
||||
!GetCreatedDynamically()) {
|
||||
if (XRE_IsContentProcess()) {
|
||||
dom::ContentChild* contentChild = dom::ContentChild::GetSingleton();
|
||||
if (contentChild) {
|
||||
nsCOMPtr<nsILoadGroup> loadGroup;
|
||||
GetLoadGroup(getter_AddRefs(loadGroup));
|
||||
if (contentChild && loadGroup && !mDocumentRequest) {
|
||||
RefPtr<Document> parentDoc = parentDS->GetDocument();
|
||||
parentDoc->BlockOnload();
|
||||
RefPtr<BrowsingContext> browsingContext = mBrowsingContext;
|
||||
@@ -941,11 +1020,33 @@ bool nsDocShell::MaybeHandleSubframeHistory(
|
||||
mBrowsingContext->GetCurrentLoadIdentifier();
|
||||
RefPtr<nsDocShellLoadState> loadState = aLoadState;
|
||||
bool isNavigating = mIsNavigating;
|
||||
RefPtr<StopDetector> stopDetector = new StopDetector();
|
||||
loadGroup->AddRequest(stopDetector, nullptr);
|
||||
// Need to set mDocumentRequest so that GetIsAttemptingToNavigate()
|
||||
// returns true.
|
||||
mDocumentRequest = stopDetector;
|
||||
|
||||
auto resolve =
|
||||
[currentLoadIdentifier, browsingContext, parentDoc, loadState,
|
||||
isNavigating](
|
||||
isNavigating, loadGroup, stopDetector](
|
||||
mozilla::Maybe<LoadingSessionHistoryInfo>&& aResult) {
|
||||
auto unblockParent =
|
||||
MakeScopeExit([loadGroup, stopDetector, parentDoc]() {
|
||||
loadGroup->RemoveRequest(stopDetector, nullptr, NS_OK);
|
||||
parentDoc->UnblockOnload(false);
|
||||
});
|
||||
|
||||
RefPtr<nsDocShell> docShell =
|
||||
static_cast<nsDocShell*>(browsingContext->GetDocShell());
|
||||
if (!docShell) {
|
||||
return;
|
||||
}
|
||||
if (docShell->mDocumentRequest == stopDetector) {
|
||||
docShell->mDocumentRequest = nullptr;
|
||||
}
|
||||
if (stopDetector->Canceled()) {
|
||||
return;
|
||||
}
|
||||
if (currentLoadIdentifier ==
|
||||
browsingContext->GetCurrentLoadIdentifier() &&
|
||||
aResult.isSome()) {
|
||||
@@ -954,16 +1055,15 @@ bool nsDocShell::MaybeHandleSubframeHistory(
|
||||
// history, index doesn't need to be updated.
|
||||
loadState->SetLoadIsFromSessionHistory(0, false);
|
||||
}
|
||||
RefPtr<nsDocShell> docShell =
|
||||
static_cast<nsDocShell*>(browsingContext->GetDocShell());
|
||||
if (docShell) {
|
||||
// We got the results back from the parent process, call
|
||||
// LoadURI again with the possibly updated data.
|
||||
docShell->LoadURI(loadState, isNavigating, true);
|
||||
}
|
||||
parentDoc->UnblockOnload(false);
|
||||
|
||||
// We got the results back from the parent process, call
|
||||
// LoadURI again with the possibly updated data.
|
||||
docShell->LoadURI(loadState, isNavigating, true);
|
||||
};
|
||||
auto reject = [parentDoc](mozilla::ipc::ResponseRejectReason) {
|
||||
auto reject = [loadGroup, stopDetector,
|
||||
parentDoc](mozilla::ipc::ResponseRejectReason) {
|
||||
// In practise reject shouldn't be called ever.
|
||||
loadGroup->RemoveRequest(stopDetector, nullptr, NS_OK);
|
||||
parentDoc->UnblockOnload(false);
|
||||
};
|
||||
contentChild->SendGetLoadingSessionHistoryInfoFromParent(
|
||||
|
||||
Reference in New Issue
Block a user