Commit c525c65f authored by Nika Layzell's avatar Nika Layzell
Browse files

Bug 1722880 - Part 1: Add IsInBFCache to WindowContext, and make it non-SHIP...

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
parent d7a06601
Loading
Loading
Loading
Loading
+9 −1
Original line number Original line Diff line number Diff line
@@ -209,7 +209,7 @@ int32_t BrowsingContext::IndexOf(BrowsingContext* aChild) {
  return index;
  return index;
}
}


WindowContext* BrowsingContext::GetTopWindowContext() {
WindowContext* BrowsingContext::GetTopWindowContext() const {
  if (mParentWindow) {
  if (mParentWindow) {
    return mParentWindow->TopWindowContext();
    return mParentWindow->TopWindowContext();
  }
  }
@@ -963,6 +963,14 @@ bool BrowsingContext::AncestorsAreCurrent() const {
  }
  }
}
}


bool BrowsingContext::IsInBFCache() const {
  if (mozilla::SessionHistoryInParent()) {
    return mIsInBFCache;
  }
  return mParentWindow &&
         mParentWindow->TopWindowContext()->GetWindowStateSaved();
}

Span<RefPtr<BrowsingContext>> BrowsingContext::Children() const {
Span<RefPtr<BrowsingContext>> BrowsingContext::Children() const {
  if (WindowContext* current = mCurrentWindowContext) {
  if (WindowContext* current = mCurrentWindowContext) {
    return current->Children();
    return current->Children();
+2 −2
Original line number Original line Diff line number Diff line
@@ -412,7 +412,7 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
  // NOTE: Unlike `GetEmbedderWindowGlobal`, `GetParentWindowContext` does not
  // NOTE: Unlike `GetEmbedderWindowGlobal`, `GetParentWindowContext` does not
  // cross toplevel content browser boundaries.
  // cross toplevel content browser boundaries.
  WindowContext* GetParentWindowContext() const { return mParentWindow; }
  WindowContext* GetParentWindowContext() const { return mParentWindow; }
  WindowContext* GetTopWindowContext();
  WindowContext* GetTopWindowContext() const;


  already_AddRefed<BrowsingContext> GetOpener() const {
  already_AddRefed<BrowsingContext> GetOpener() const {
    RefPtr<BrowsingContext> opener(Get(GetOpenerId()));
    RefPtr<BrowsingContext> opener(Get(GetOpenerId()));
@@ -857,7 +857,7 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {


  void FlushSessionStore();
  void FlushSessionStore();


  bool IsInBFCache() const { return mIsInBFCache; }
  bool IsInBFCache() const;


  bool AllowJavascript() const { return GetAllowJavascript(); }
  bool AllowJavascript() const { return GetAllowJavascript(); }
  bool CanExecuteScripts() const { return mCanExecuteScripts; }
  bool CanExecuteScripts() const { return mCanExecuteScripts; }
+14 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/ClearOnShutdown.h"
#include "nsGlobalWindowInner.h"
#include "nsGlobalWindowInner.h"
#include "nsIScriptError.h"
#include "nsIScriptError.h"
#include "nsIXULRuntime.h"
#include "nsRefPtrHashtable.h"
#include "nsRefPtrHashtable.h"
#include "nsContentUtils.h"
#include "nsContentUtils.h"


@@ -67,6 +68,13 @@ bool WindowContext::IsCurrent() const {
  return mBrowsingContext->mCurrentWindowContext == this;
  return mBrowsingContext->mCurrentWindowContext == this;
}
}


bool WindowContext::IsInBFCache() {
  if (mozilla::SessionHistoryInParent()) {
    return mBrowsingContext->IsInBFCache();
  }
  return TopWindowContext()->GetWindowStateSaved();
}

nsGlobalWindowInner* WindowContext::GetInnerWindow() const {
nsGlobalWindowInner* WindowContext::GetInnerWindow() const {
  return mWindowGlobalChild ? mWindowGlobalChild->GetWindowGlobal() : nullptr;
  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) {
void WindowContext::CreateFromIPC(IPCInitializer&& aInit) {
  MOZ_RELEASE_ASSERT(XRE_IsContentProcess(),
  MOZ_RELEASE_ASSERT(XRE_IsContentProcess(),
                     "Should be a WindowGlobalParent in the parent");
                     "Should be a WindowGlobalParent in the parent");
+11 −1
Original line number Original line Diff line number Diff line
@@ -89,7 +89,11 @@ class BrowsingContextGroup;
  FIELD(HadLazyLoadImage, bool)                                          \
  FIELD(HadLazyLoadImage, bool)                                          \
  /* Whether we can execute scripts in this WindowContext. Has no effect \
  /* Whether we can execute scripts in this WindowContext. Has no effect \
   * unless scripts are also allowed in the BrowsingContext. */          \
   * unless scripts are also allowed in the BrowsingContext. */          \
  FIELD(AllowJavascript, bool)
  FIELD(AllowJavascript, bool)                                           \
  /* If this field is `true`, it means that this WindowContext's         \
   * WindowState was saved to be stored in the legacy (non-SHIP) BFCache \
   * implementation. Always false for SHIP */                            \
  FIELD(WindowStateSaved, bool)


class WindowContext : public nsISupports, public nsWrapperCache {
class WindowContext : public nsISupports, public nsWrapperCache {
  MOZ_DECL_SYNCED_CONTEXT(WindowContext, MOZ_EACH_WC_FIELD)
  MOZ_DECL_SYNCED_CONTEXT(WindowContext, MOZ_EACH_WC_FIELD)
@@ -113,6 +117,9 @@ class WindowContext : public nsISupports, public nsWrapperCache {
  // BrowsingContext.
  // BrowsingContext.
  bool IsCurrent() const;
  bool IsCurrent() const;


  // Returns `true` if this WindowContext is currently in the BFCache.
  bool IsInBFCache();

  bool IsInProcess() const { return mIsInProcess; }
  bool IsInProcess() const { return mIsInProcess; }


  bool HasBeforeUnload() const { return GetHasBeforeUnload(); }
  bool HasBeforeUnload() const { return GetHasBeforeUnload(); }
@@ -287,6 +294,9 @@ class WindowContext : public nsISupports, public nsWrapperCache {


  void DidSet(FieldIndex<IDX_SHEntryHasUserInteraction>, bool aOldValue);
  void DidSet(FieldIndex<IDX_SHEntryHasUserInteraction>, bool aOldValue);


  bool CanSet(FieldIndex<IDX_WindowStateSaved>, bool aValue,
              ContentParent* aSource);

  // Overload `DidSet` to get notifications for a particular field being set.
  // Overload `DidSet` to get notifications for a particular field being set.
  //
  //
  // You can also overload the variant that gets the old value if you need it.
  // You can also overload the variant that gets the old value if you need it.
+1 −1
Original line number Original line Diff line number Diff line
@@ -6932,7 +6932,7 @@ bool Document::RemoveFromBFCacheSync() {
    removed = true;
    removed = true;
  }
  }
  if (XRE_IsContentProcess()) {
  if (mozilla::SessionHistoryInParent() && XRE_IsContentProcess()) {
    if (BrowsingContext* bc = GetBrowsingContext()) {
    if (BrowsingContext* bc = GetBrowsingContext()) {
      if (bc->IsInBFCache()) {
      if (bc->IsInBFCache()) {
        ContentChild* cc = ContentChild::GetSingleton();
        ContentChild* cc = ContentChild::GetSingleton();
Loading