Skip to content

Commit 42e5e22

Browse files
Merge remote-tracking branch 'upstream/master' into master
2 parents 5e3b16f + 2f9eacd commit 42e5e22

13 files changed

+168
-68
lines changed

docshell/base/CanonicalBrowsingContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ nsISHistory* CanonicalBrowsingContext::GetSessionHistory() {
281281
return mSessionHistory;
282282
}
283283

284+
SessionHistoryEntry* CanonicalBrowsingContext::GetActiveSessionHistoryEntry() {
285+
return mActiveEntry;
286+
}
287+
284288
UniquePtr<LoadingSessionHistoryInfo>
285289
CanonicalBrowsingContext::CreateLoadingSessionHistoryEntryForLoad(
286290
nsDocShellLoadState* aLoadState, nsIChannel* aChannel) {

docshell/base/CanonicalBrowsingContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class CanonicalBrowsingContext final : public BrowsingContext {
9696
Nullable<WindowProxyHolder> GetTopChromeWindow();
9797

9898
nsISHistory* GetSessionHistory();
99+
SessionHistoryEntry* GetActiveSessionHistoryEntry();
100+
99101
UniquePtr<LoadingSessionHistoryInfo> CreateLoadingSessionHistoryEntryForLoad(
100102
nsDocShellLoadState* aLoadState, nsIChannel* aChannel);
101103
void SessionHistoryCommit(uint64_t aSessionHistoryEntryId,

docshell/base/nsDocShell.cpp

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,16 +2961,20 @@ nsDocShell::GetCurrentSHEntry(nsISHEntry** aEntry, bool* aOSHE) {
29612961
}
29622962

29632963
NS_IMETHODIMP nsDocShell::SynchronizeLayoutHistoryState() {
2964-
if (mActiveEntry && mActiveEntry->GetLayoutHistoryState()) {
2964+
if (mActiveEntry && mActiveEntry->GetLayoutHistoryState() &&
2965+
mBrowsingContext) {
29652966
if (XRE_IsContentProcess()) {
29662967
dom::ContentChild* contentChild = dom::ContentChild::GetSingleton();
29672968
if (contentChild) {
29682969
contentChild->SendSynchronizeLayoutHistoryState(
2969-
mActiveEntry->Id(), mActiveEntry->GetLayoutHistoryState());
2970+
mBrowsingContext, mActiveEntry->GetLayoutHistoryState());
29702971
}
29712972
} else {
2972-
SessionHistoryEntry::UpdateLayoutHistoryState(
2973-
mActiveEntry->Id(), mActiveEntry->GetLayoutHistoryState());
2973+
SessionHistoryEntry* entry =
2974+
mBrowsingContext->Canonical()->GetActiveSessionHistoryEntry();
2975+
if (entry) {
2976+
entry->SetLayoutHistoryState(mActiveEntry->GetLayoutHistoryState());
2977+
}
29742978
}
29752979
}
29762980

@@ -4751,18 +4755,18 @@ void nsDocShell::SetTitleOnHistoryEntry() {
47514755
mOSHE->SetTitle(mTitle);
47524756
}
47534757

4754-
if (mActiveEntry) {
4758+
if (mActiveEntry && mBrowsingContext) {
47554759
mActiveEntry->SetTitle(mTitle);
47564760
if (XRE_IsParentProcess()) {
47574761
SessionHistoryEntry* entry =
4758-
SessionHistoryEntry::GetByInfoId(mActiveEntry->Id());
4762+
mBrowsingContext->Canonical()->GetActiveSessionHistoryEntry();
47594763
if (entry) {
47604764
entry->SetTitle(mTitle);
47614765
}
47624766
} else {
47634767
mozilla::Unused
47644768
<< ContentChild::GetSingleton()->SendSessionHistoryEntryTitle(
4765-
mActiveEntry->Id(), mTitle);
4769+
mBrowsingContext, mTitle);
47664770
}
47674771
}
47684772
}
@@ -8511,14 +8515,16 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
85118515
if (mLoadingEntry && !mLoadingEntry->mIsLoadFromSessionHistory) {
85128516
// If we're not doing a history load, scroll restoration
85138517
// should be inherited from the previous session history entry.
8514-
SetScrollRestorationIsManualOnHistoryEntry(
8515-
nullptr, &mLoadingEntry->mInfo, scrollRestorationIsManual);
8518+
// XXX This needs most probably tweaks once fragment navigation is fixed
8519+
// to work with session-history-in-parent.
8520+
SetScrollRestorationIsManualOnHistoryEntry(nullptr,
8521+
scrollRestorationIsManual);
85168522
}
85178523
if (mLSHE) {
85188524
if (!aLoadState->SHEntry()) {
85198525
// If we're not doing a history load, scroll restoration
85208526
// should be inherited from the previous session history entry.
8521-
SetScrollRestorationIsManualOnHistoryEntry(mLSHE, nullptr,
8527+
SetScrollRestorationIsManualOnHistoryEntry(mLSHE,
85228528
scrollRestorationIsManual);
85238529
}
85248530
mLSHE->AdoptBFCacheEntry(mOSHE);
@@ -8551,7 +8557,9 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
85518557
// Make sure we won't just repost without hitting the
85528558
// cache first
85538559
if (cacheKey != 0) {
8554-
mOSHE->SetCacheKey(cacheKey);
8560+
// XXX Ensure this method is still called when fragment navigation is
8561+
// fixed to work with session history in parent.
8562+
SetCacheKeyOnHistoryEntry(mOSHE, cacheKey);
85558563
}
85568564
}
85578565

@@ -10323,11 +10331,8 @@ bool nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
1032310331
// If we already have a loading history entry, store the new cache key
1032410332
// in it. Otherwise, since we're doing a reload and won't be updating
1032510333
// our history entry, store the cache key in our current history entry.
10326-
if (mLSHE) {
10327-
mLSHE->SetCacheKey(cacheKey);
10328-
} else if (mOSHE) {
10329-
mOSHE->SetCacheKey(cacheKey);
10330-
}
10334+
10335+
SetCacheKeyOnHistoryEntry(mLSHE ? mLSHE : mOSHE, cacheKey);
1033110336

1033210337
// Since we're force-reloading, clear all the sub frame history.
1033310338
ClearFrameHistory(mLSHE);
@@ -10794,31 +10799,50 @@ nsDocShell::GetCurrentScrollRestorationIsManual(bool* aIsManual) {
1079410799

1079510800
NS_IMETHODIMP
1079610801
nsDocShell::SetCurrentScrollRestorationIsManual(bool aIsManual) {
10797-
SetScrollRestorationIsManualOnHistoryEntry(mOSHE, mActiveEntry.get(),
10798-
aIsManual);
10802+
SetScrollRestorationIsManualOnHistoryEntry(mOSHE, aIsManual);
1079910803

1080010804
return NS_OK;
1080110805
}
1080210806

1080310807
void nsDocShell::SetScrollRestorationIsManualOnHistoryEntry(
10804-
nsISHEntry* aSHEntry, mozilla::dom::SessionHistoryInfo* aInfo,
10805-
bool aIsManual) {
10808+
nsISHEntry* aSHEntry, bool aIsManual) {
1080610809
if (aSHEntry) {
1080710810
aSHEntry->SetScrollRestorationIsManual(aIsManual);
1080810811
}
1080910812

10810-
if (aInfo) {
10811-
aInfo->SetScrollRestorationIsManual(aIsManual);
10813+
if (mActiveEntry && mBrowsingContext) {
10814+
mActiveEntry->SetScrollRestorationIsManual(aIsManual);
1081210815
if (XRE_IsParentProcess()) {
1081310816
SessionHistoryEntry* entry =
10814-
SessionHistoryEntry::GetByInfoId(aInfo->Id());
10817+
mBrowsingContext->Canonical()->GetActiveSessionHistoryEntry();
1081510818
if (entry) {
1081610819
entry->SetScrollRestorationIsManual(aIsManual);
1081710820
}
1081810821
} else {
1081910822
mozilla::Unused << ContentChild::GetSingleton()
1082010823
->SendSessionHistoryEntryScrollRestorationIsManual(
10821-
aInfo->Id(), aIsManual);
10824+
mBrowsingContext, aIsManual);
10825+
}
10826+
}
10827+
}
10828+
10829+
void nsDocShell::SetCacheKeyOnHistoryEntry(nsISHEntry* aSHEntry,
10830+
uint32_t aCacheKey) {
10831+
if (aSHEntry) {
10832+
aSHEntry->SetCacheKey(aCacheKey);
10833+
}
10834+
10835+
if (mActiveEntry && mBrowsingContext) {
10836+
if (XRE_IsParentProcess()) {
10837+
SessionHistoryEntry* entry =
10838+
mBrowsingContext->Canonical()->GetActiveSessionHistoryEntry();
10839+
if (entry) {
10840+
entry->SetCacheKey(aCacheKey);
10841+
}
10842+
} else {
10843+
mozilla::Unused
10844+
<< ContentChild::GetSingleton()->SendSessionHistoryEntryCacheKey(
10845+
mBrowsingContext, aCacheKey);
1082210846
}
1082310847
}
1082410848
}

docshell/base/nsDocShell.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,9 +1050,10 @@ class nsDocShell final : public nsDocLoader,
10501050

10511051
void SetTitleOnHistoryEntry();
10521052

1053-
void SetScrollRestorationIsManualOnHistoryEntry(
1054-
nsISHEntry* aSHEntry, mozilla::dom::SessionHistoryInfo* aInfo,
1055-
bool aIsManual);
1053+
void SetScrollRestorationIsManualOnHistoryEntry(nsISHEntry* aSHEntry,
1054+
bool aIsManual);
1055+
1056+
void SetCacheKeyOnHistoryEntry(nsISHEntry* aSHEntry, uint32_t aCacheKey);
10561057

10571058
private: // data members
10581059
nsID mHistoryID;

docshell/shistory/SessionHistoryEntry.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -952,13 +952,15 @@ SessionHistoryEntry::SyncTreesForSubframeNavigation(
952952
NS_WARNING("Need to implement this");
953953
}
954954

955-
void SessionHistoryEntry::UpdateLayoutHistoryState(
956-
uint64_t aSessionHistoryEntryID, nsILayoutHistoryState* aState) {
957-
SessionHistoryEntry* entry =
958-
SessionHistoryEntry::GetByInfoId(aSessionHistoryEntryID);
959-
if (entry) {
960-
entry->SetLayoutHistoryState(aState);
955+
void SessionHistoryEntry::MaybeSynchronizeSharedStateToInfo(
956+
nsISHEntry* aEntry) {
957+
nsCOMPtr<SessionHistoryEntry> entry = do_QueryInterface(aEntry);
958+
if (!entry) {
959+
return;
961960
}
961+
962+
entry->mInfo->mCacheKey = entry->mSharedInfo->mCacheKey;
963+
// XXX Add other member variables which live in mSharedInfo.
962964
}
963965

964966
} // namespace dom

docshell/shistory/SessionHistoryEntry.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class SessionHistoryInfo {
5353
mScrollRestorationIsManual = aIsManual;
5454
}
5555

56+
void SetCacheKey(uint32_t aCacheKey) { mCacheKey = aCacheKey; }
57+
5658
nsIURI* GetURI() const { return mURI; }
5759

5860
bool GetURIWasModified() const { return mURIWasModified; }
@@ -88,6 +90,9 @@ class SessionHistoryInfo {
8890
// SHEntrySharedParentState::mLayoutHistoryState
8991
nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState;
9092

93+
// mCacheKey is handled similar way to mLayoutHistoryState.
94+
uint32_t mCacheKey = 0;
95+
9196
uint64_t mId = 0;
9297
bool mLoadReplace = false;
9398
bool mURIWasModified = false;
@@ -146,8 +151,7 @@ class SessionHistoryEntry : public nsISHEntry {
146151
// Get an entry based on SessionHistoryInfo's Id. Parent process only.
147152
static SessionHistoryEntry* GetByInfoId(uint64_t aId);
148153

149-
static void UpdateLayoutHistoryState(uint64_t aSessionHistoryEntryID,
150-
nsILayoutHistoryState* aState);
154+
static void MaybeSynchronizeSharedStateToInfo(nsISHEntry* aEntry);
151155

152156
private:
153157
virtual ~SessionHistoryEntry();

docshell/shistory/nsSHistory.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,8 @@ void nsSHistory::InitiateLoad(nsISHEntry* aFrameEntry,
17261726
aFrameEntry->SetLoadType(aLoadType);
17271727

17281728
loadState->SetLoadType(aLoadType);
1729+
1730+
SessionHistoryEntry::MaybeSynchronizeSharedStateToInfo(aFrameEntry);
17291731
loadState->SetSHEntry(aFrameEntry);
17301732
loadState->SetLoadIsFromSessionHistory(mRequestedIndex, Length());
17311733

dom/base/nsDOMWindowUtils.cpp

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -218,21 +218,27 @@ nsDOMWindowUtils::nsDOMWindowUtils(nsGlobalWindowOuter* aWindow) {
218218

219219
nsDOMWindowUtils::~nsDOMWindowUtils() { OldWindowSize::GetAndRemove(mWindow); }
220220

221-
PresShell* nsDOMWindowUtils::GetPresShell() {
221+
nsIDocShell* nsDOMWindowUtils::GetDocShell() {
222222
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
223-
if (!window) return nullptr;
224-
225-
nsIDocShell* docShell = window->GetDocShell();
226-
if (!docShell) return nullptr;
223+
if (!window) {
224+
return nullptr;
225+
}
226+
return window->GetDocShell();
227+
}
227228

229+
PresShell* nsDOMWindowUtils::GetPresShell() {
230+
nsIDocShell* docShell = GetDocShell();
231+
if (!docShell) {
232+
return nullptr;
233+
}
228234
return docShell->GetPresShell();
229235
}
230236

231237
nsPresContext* nsDOMWindowUtils::GetPresContext() {
232-
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
233-
if (!window) return nullptr;
234-
nsIDocShell* docShell = window->GetDocShell();
235-
if (!docShell) return nullptr;
238+
nsIDocShell* docShell = GetDocShell();
239+
if (!docShell) {
240+
return nullptr;
241+
}
236242
return docShell->GetPresContext();
237243
}
238244

@@ -3179,25 +3185,39 @@ nsresult nsDOMWindowUtils::RemoteFrameFullscreenReverted() {
31793185
return NS_OK;
31803186
}
31813187

3182-
static void PrepareForFullscreenChange(PresShell* aPresShell,
3188+
static void PrepareForFullscreenChange(nsIDocShell* aDocShell,
31833189
const nsSize& aSize,
31843190
nsSize* aOldSize = nullptr) {
3185-
if (!aPresShell) {
3191+
if (!aDocShell) {
31863192
return;
31873193
}
3188-
if (nsRefreshDriver* rd = aPresShell->GetRefreshDriver()) {
3194+
PresShell* presShell = aDocShell->GetPresShell();
3195+
if (!presShell) {
3196+
return;
3197+
}
3198+
if (nsRefreshDriver* rd = presShell->GetRefreshDriver()) {
31893199
rd->SetIsResizeSuppressed();
31903200
// Since we are suppressing the resize reflow which would originally
31913201
// be triggered by view manager, we need to ensure that the refresh
31923202
// driver actually schedules a flush, otherwise it may get stuck.
31933203
rd->ScheduleViewManagerFlush();
31943204
}
31953205
if (!aSize.IsEmpty()) {
3196-
if (nsViewManager* viewManager = aPresShell->GetViewManager()) {
3206+
nsCOMPtr<nsIContentViewer> cv;
3207+
aDocShell->GetContentViewer(getter_AddRefs(cv));
3208+
if (cv) {
3209+
nsIntRect cvBounds;
3210+
cv->GetBounds(cvBounds);
3211+
nscoord auPerDev = presShell->GetPresContext()->AppUnitsPerDevPixel();
31973212
if (aOldSize) {
3198-
viewManager->GetWindowDimensions(&aOldSize->width, &aOldSize->height);
3213+
*aOldSize = LayoutDeviceIntSize::ToAppUnits(
3214+
LayoutDeviceIntSize::FromUnknownSize(cvBounds.Size()), auPerDev);
31993215
}
3200-
viewManager->SetWindowDimensions(aSize.width, aSize.height);
3216+
LayoutDeviceIntSize newSize =
3217+
LayoutDeviceIntSize::FromAppUnitsRounded(aSize, auPerDev);
3218+
3219+
cvBounds.SizeTo(newSize.width, newSize.height);
3220+
cv->SetBounds(cvBounds);
32013221
}
32023222
}
32033223
}
@@ -3217,7 +3237,7 @@ nsDOMWindowUtils::HandleFullscreenRequests(bool* aRetVal) {
32173237
presContext->DeviceContext()->GetRect(screenRect);
32183238
}
32193239
nsSize oldSize;
3220-
PrepareForFullscreenChange(GetPresShell(), screenRect.Size(), &oldSize);
3240+
PrepareForFullscreenChange(GetDocShell(), screenRect.Size(), &oldSize);
32213241
OldWindowSize::Set(mWindow, oldSize);
32223242

32233243
*aRetVal = Document::HandlePendingFullscreenRequests(doc);
@@ -3240,7 +3260,7 @@ nsresult nsDOMWindowUtils::ExitFullscreen() {
32403260
// set the window dimensions in advance. Since the resize message
32413261
// comes after the fullscreen change call, doing so could avoid an
32423262
// extra resize reflow after this point.
3243-
PrepareForFullscreenChange(GetPresShell(), oldSize);
3263+
PrepareForFullscreenChange(GetDocShell(), oldSize);
32443264
Document::ExitFullscreenInDocTree(doc);
32453265
return NS_OK;
32463266
}

dom/base/nsDOMWindowUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "mozilla/BasicEvents.h"
1515

1616
class nsGlobalWindowOuter;
17+
class nsIDocShell;
1718
class nsIWidget;
1819
class nsPresContext;
1920
class nsView;
@@ -77,6 +78,7 @@ class nsDOMWindowUtils final : public nsIDOMWindowUtils,
7778
nsIWidget* GetWidget(nsPoint* aOffset = nullptr);
7879
nsIWidget* GetWidgetForElement(mozilla::dom::Element* aElement);
7980

81+
nsIDocShell* GetDocShell();
8082
mozilla::PresShell* GetPresShell();
8183
nsPresContext* GetPresContext();
8284
mozilla::dom::Document* GetDocument();

0 commit comments

Comments
 (0)