Skip to content

Commit

Permalink
Bug 1666596 - Ensure location.reload(true) removes entries for iframe…
Browse files Browse the repository at this point in the history
…s, r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D91050
  • Loading branch information
Olli Pettay authored and Olli Pettay committed Sep 23, 2020
1 parent cd329e8 commit beabb98
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
13 changes: 12 additions & 1 deletion docshell/base/CanonicalBrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ static already_AddRefed<nsDocShellLoadState> CreateLoadInfo(
}

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

Expand All @@ -529,12 +530,22 @@ void CanonicalBrowsingContext::NotifyOnHistoryReload(
if (mActiveEntry) {
aLoadState.emplace(CreateLoadInfo(mActiveEntry, Nothing()));
aReloadActiveEntry.emplace(true);
if (aForceReload) {
shistory->RemoveFrameEntries(mActiveEntry);
}
} else if (!mLoadingEntries.IsEmpty()) {
const LoadingSessionHistoryEntry& loadingEntry =
mLoadingEntries.LastElement();
aLoadState.emplace(
CreateLoadInfo(loadingEntry.mEntry, Some(loadingEntry.mLoadId)));
aReloadActiveEntry.emplace(false);
if (aForceReload) {
SessionHistoryEntry* entry =
SessionHistoryEntry::GetByLoadId(loadingEntry.mLoadId);
if (entry) {
shistory->RemoveFrameEntries(entry);
}
}
}

if (aLoadState) {
Expand Down
2 changes: 1 addition & 1 deletion docshell/base/CanonicalBrowsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ 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& aCanReload,
void NotifyOnHistoryReload(bool aForceReload, bool& aCanReload,
Maybe<RefPtr<nsDocShellLoadState>>& aLoadState,
Maybe<bool>& aReloadActiveEntry);

Expand Down
5 changes: 3 additions & 2 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4037,14 +4037,15 @@ nsDocShell::Reload(uint32_t aReloadFlags) {
RefPtr<ChildSHistory> rootSH = GetRootSessionHistory();
if (StaticPrefs::fission_sessionHistoryInParent()) {
MOZ_LOG(gSHLog, LogLevel::Debug, ("document %p Reload", this));
bool forceReload = IsForceReloadType(loadType);
if (!XRE_IsParentProcess()) {
RefPtr<nsDocShell> docShell(this);
RefPtr<Document> doc(GetDocument());
RefPtr<BrowsingContext> browsingContext(mBrowsingContext);
nsCOMPtr<nsIURI> currentURI(mCurrentURI);
nsCOMPtr<nsIReferrerInfo> referrerInfo(mReferrerInfo);
ContentChild::GetSingleton()->SendNotifyOnHistoryReload(
mBrowsingContext,
mBrowsingContext, forceReload,
[docShell, doc, loadType, browsingContext, currentURI, referrerInfo](
Tuple<bool, Maybe<RefPtr<nsDocShellLoadState>>, Maybe<bool>>&&
aResult) {
Expand Down Expand Up @@ -4079,7 +4080,7 @@ nsDocShell::Reload(uint32_t aReloadFlags) {
Maybe<bool> reloadingActiveEntry;
if (!mBrowsingContext->IsDiscarded()) {
mBrowsingContext->Canonical()->NotifyOnHistoryReload(
canReload, loadState, reloadingActiveEntry);
forceReload, canReload, loadState, reloadingActiveEntry);
}
if (canReload) {
if (loadState.isSome()) {
Expand Down
6 changes: 3 additions & 3 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6890,14 +6890,14 @@ mozilla::ipc::IPCResult ContentParent::RecvReportServiceWorkerShutdownProgress(
}

mozilla::ipc::IPCResult ContentParent::RecvNotifyOnHistoryReload(
const MaybeDiscarded<BrowsingContext>& aContext,
const MaybeDiscarded<BrowsingContext>& aContext, const bool& aForceReload,
NotifyOnHistoryReloadResolver&& aResolver) {
bool canReload = false;
Maybe<RefPtr<nsDocShellLoadState>> loadState;
Maybe<bool> reloadActiveEntry;
if (!aContext.IsDiscarded()) {
aContext.get_canonical()->NotifyOnHistoryReload(canReload, loadState,
reloadActiveEntry);
aContext.get_canonical()->NotifyOnHistoryReload(
aForceReload, canReload, loadState, reloadActiveEntry);
}
aResolver(Tuple<const bool&, const Maybe<RefPtr<nsDocShellLoadState>>&,
const Maybe<bool>&>(canReload, loadState, reloadActiveEntry));
Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/ContentParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ class ContentParent final
const MaybeDiscarded<BrowsingContext>& aContext);

mozilla::ipc::IPCResult RecvNotifyOnHistoryReload(
const MaybeDiscarded<BrowsingContext>& aContext,
const MaybeDiscarded<BrowsingContext>& aContext, const bool& aForceReload,
NotifyOnHistoryReloadResolver&& aResolver);

mozilla::ipc::IPCResult RecvHistoryCommit(
Expand Down
3 changes: 2 additions & 1 deletion dom/ipc/PContent.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,8 @@ parent:

async HistoryReload(MaybeDiscardedBrowsingContext aContext, uint32_t aReloadFlags);

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

Expand Down

0 comments on commit beabb98

Please sign in to comment.