mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-28 13:40:17 -10:00
Bug 2042379 - Part 1: Make sure to truncate navigation.entries when sesion history changes length. r=jjaschke
Differential Revision: https://phabricator.services.mozilla.com/D302493
This commit is contained in:
1 parent
cb8a714584
commit
1147371945
8 files changed
+85
-8
No files matched your search
@@ -2845,9 +2845,29 @@ void CanonicalBrowsingContext::HistoryCommitIndexAndLength(
|
||||
|
||||
shistory->EvictOutOfRangeDocumentViewers(index);
|
||||
|
||||
nsTArray<NavigationEntriesTruncation> truncations;
|
||||
if (Navigation::IsAPIEnabled()) {
|
||||
PreOrderWalk([&truncations](BrowsingContext* aContext) {
|
||||
RefPtr<SessionHistoryEntry> activeEntry =
|
||||
aContext->Canonical()->GetActiveSessionHistoryEntry();
|
||||
if (!activeEntry) {
|
||||
return;
|
||||
}
|
||||
uint32_t count = 0;
|
||||
nsSHistory::WalkContiguousEntriesInOrder(activeEntry,
|
||||
[&count](SessionHistoryEntry*) {
|
||||
++count;
|
||||
return true;
|
||||
});
|
||||
if (count) {
|
||||
truncations.AppendElement(NavigationEntriesTruncation{aContext, count});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Group()->EachParent([&](ContentParent* aParent) {
|
||||
(void)aParent->SendHistoryCommitIndexAndLength(this, index, length,
|
||||
aChangeID);
|
||||
aChangeID, truncations);
|
||||
});
|
||||
|
||||
shistory->NotifyOnHistoryCommit();
|
||||
|
||||
@@ -4430,13 +4430,32 @@ mozilla::ipc::IPCResult ContentChild::RecvDisplayLoadError(
|
||||
|
||||
mozilla::ipc::IPCResult ContentChild::RecvHistoryCommitIndexAndLength(
|
||||
const MaybeDiscarded<BrowsingContext>& aContext, const uint32_t& aIndex,
|
||||
const uint32_t& aLength, const nsID& aChangeID) {
|
||||
const uint32_t& aLength, const nsID& aChangeID,
|
||||
nsTArray<NavigationEntriesTruncation>&& aTruncations) {
|
||||
if (!aContext.IsNullOrDiscarded()) {
|
||||
ChildSHistory* shistory = aContext.get()->GetChildSessionHistory();
|
||||
if (shistory) {
|
||||
shistory->SetIndexAndLength(aIndex, aLength, aChangeID);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& truncation : aTruncations) {
|
||||
if (truncation.context().IsNullOrDiscarded()) {
|
||||
continue;
|
||||
}
|
||||
RefPtr<nsDocShell> docShell =
|
||||
nsDocShell::Cast(truncation.context().get()->GetDocShell());
|
||||
if (!docShell) {
|
||||
continue;
|
||||
}
|
||||
RefPtr<nsPIDOMWindowInner> window = docShell->GetActiveWindow();
|
||||
if (!window) {
|
||||
continue;
|
||||
}
|
||||
if (RefPtr<Navigation> navigation = window->Navigation()) {
|
||||
navigation->TruncateForwardEntries(truncation.newLength());
|
||||
}
|
||||
}
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
|
||||
@@ -778,9 +778,11 @@ class ContentChild final : public PContentChild,
|
||||
ErrorResult& aRv) override;
|
||||
mozilla::ipc::IProtocol* AsNativeActor() override { return this; }
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
||||
mozilla::ipc::IPCResult RecvHistoryCommitIndexAndLength(
|
||||
const MaybeDiscarded<BrowsingContext>& aContext, const uint32_t& aIndex,
|
||||
const uint32_t& aLength, const nsID& aChangeID);
|
||||
const uint32_t& aLength, const nsID& aChangeID,
|
||||
nsTArray<NavigationEntriesTruncation>&& aTruncations);
|
||||
|
||||
mozilla::ipc::IPCResult RecvConsumeHistoryActivation(
|
||||
const MaybeDiscarded<BrowsingContext>& aTop);
|
||||
|
||||
@@ -74,6 +74,12 @@ struct MessagePortIdentifier
|
||||
bool neutered;
|
||||
};
|
||||
|
||||
struct NavigationEntriesTruncation
|
||||
{
|
||||
MaybeDiscardedBrowsingContext context;
|
||||
uint32_t newLength;
|
||||
};
|
||||
|
||||
struct ScreenDetails {
|
||||
LayoutDeviceIntRect rect;
|
||||
DesktopIntRect rectDisplayPix;
|
||||
|
||||
@@ -1066,7 +1066,8 @@ child:
|
||||
|
||||
async HistoryCommitIndexAndLength(MaybeDiscardedBrowsingContext aContext,
|
||||
uint32_t aIndex, uint32_t aLength,
|
||||
nsID aChangeID);
|
||||
nsID aChangeID,
|
||||
NavigationEntriesTruncation[] aTruncations);
|
||||
|
||||
async GetLayoutHistoryState(MaybeDiscardedBrowsingContext aContext)
|
||||
returns (nullable nsILayoutHistoryState aState, Wireframe? aWireframe);
|
||||
|
||||
@@ -462,6 +462,37 @@ void Navigation::UpdateEntriesForSameDocumentNavigation(
|
||||
}
|
||||
}
|
||||
|
||||
void Navigation::TruncateForwardEntries(uint32_t aNewLength) {
|
||||
if (HasEntriesAndEventsDisabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (aNewLength >= mEntries.Length()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mCurrentEntryIndex && *mCurrentEntryIndex >= aNewLength) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsTArray<RefPtr<NavigationHistoryEntry>> disposedEntries;
|
||||
disposedEntries.AppendElements(Span(mEntries).From(aNewLength));
|
||||
mEntries.TruncateLength(aNewLength);
|
||||
|
||||
for (auto& entry : disposedEntries) {
|
||||
entry->ResetIndexForDisposal();
|
||||
}
|
||||
|
||||
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
||||
"Navigation::TruncateForwardEntries",
|
||||
[oldEntries =
|
||||
std::move(disposedEntries)]() MOZ_CAN_RUN_SCRIPT_BOUNDARY_LAMBDA {
|
||||
for (const RefPtr<NavigationHistoryEntry>& disposedNHE : oldEntries) {
|
||||
MOZ_KnownLive(disposedNHE)->FireDisposeEvent();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
static bool Equals(nsIURI* aURI, nsIURI* aOtherURI) {
|
||||
bool equals = false;
|
||||
return aURI && aOtherURI && NS_SUCCEEDED(aURI->Equals(aOtherURI, &equals)) &&
|
||||
|
||||
@@ -145,6 +145,8 @@ class Navigation final : public DOMEventTargetHelper {
|
||||
SessionHistoryInfo* aDestinationSHE, NavigationType aNavigationType,
|
||||
bool aFiredNavigateEvent = true);
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT void TruncateForwardEntries(uint32_t aNewLength);
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
void RunNavigateEventHandlerSteps(
|
||||
NavigateEvent* aNavigateEvent,
|
||||
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
[dispose-for-navigation-in-child.html]
|
||||
expected: TIMEOUT
|
||||
[Dispose events should fire when entries are removed by a navigation in a different frame]
|
||||
expected: TIMEOUT
|
||||
Reference in new issue
Block a user