Bug 1722880 - Part 1: Add IsInBFCache to WindowContext, and make it non-SHIP compatible, r=smaug,necko-reviewers,dragana

This field will be useful to JS code such as JSWindowActors which need to be
able to detect when their WindowContext is no longer active.

Differential Revision: https://phabricator.services.mozilla.com/D124098
This commit is contained in:
Nika Layzell
2021-09-03 15:26:13 +00:00
parent 5ec6e27b91
commit 0eeb1388f2
10 changed files with 58 additions and 7 deletions

View File

@@ -18,6 +18,7 @@
#include "mozilla/ClearOnShutdown.h"
#include "nsGlobalWindowInner.h"
#include "nsIScriptError.h"
#include "nsIXULRuntime.h"
#include "nsRefPtrHashtable.h"
#include "nsContentUtils.h"
@@ -67,6 +68,13 @@ bool WindowContext::IsCurrent() const {
return mBrowsingContext->mCurrentWindowContext == this;
}
bool WindowContext::IsInBFCache() {
if (mozilla::SessionHistoryInParent()) {
return mBrowsingContext->IsInBFCache();
}
return TopWindowContext()->GetWindowStateSaved();
}
nsGlobalWindowInner* WindowContext::GetInnerWindow() const {
return mWindowGlobalChild ? mWindowGlobalChild->GetWindowGlobal() : nullptr;
}
@@ -354,6 +362,12 @@ void WindowContext::DidSet(FieldIndex<IDX_HasReportedShadowDOMUsage>,
}
}
bool WindowContext::CanSet(FieldIndex<IDX_WindowStateSaved>, bool aValue,
ContentParent* aSource) {
return !mozilla::SessionHistoryInParent() && IsTop() &&
CheckOnlyOwningProcessCanSet(aSource);
}
void WindowContext::CreateFromIPC(IPCInitializer&& aInit) {
MOZ_RELEASE_ASSERT(XRE_IsContentProcess(),
"Should be a WindowGlobalParent in the parent");