Bug 1542790 - Part 2: Use BC::GetParent and BC::GetTop for local windows, r=peterv
authorNika Layzell <nika@thelayzells.com>
Wed, 17 Apr 2019 00:53:09 +0000
changeset 469845 607e1bc95c9bd82cbf4dc5426cfa66147f1d9458
parent 469844 5fde2cc9277a3d4bb73d859ba571c84fdc2ead9b
child 469846 4a3f5fbd5011ed794673c000a0e369393b435e43
push id112826
push userbtara@mozilla.com
push dateWed, 17 Apr 2019 21:50:20 +0000
treeherdermozilla-inbound@5d0134101bec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1542790
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1542790 - Part 2: Use BC::GetParent and BC::GetTop for local windows, r=peterv This is required to support getting the `parent` and `top` properties from within remote subframes. Differential Revision: https://phabricator.services.mozilla.com/D26559
docshell/base/BrowsingContext.cpp
dom/base/nsGlobalWindowOuter.cpp
--- a/docshell/base/BrowsingContext.cpp
+++ b/docshell/base/BrowsingContext.cpp
@@ -625,16 +625,20 @@ void BrowsingContext::Blur(ErrorResult& 
   if (ContentChild* cc = ContentChild::GetSingleton()) {
     cc->SendWindowBlur(this);
   } else if (ContentParent* cp = Canonical()->GetContentParent()) {
     Unused << cp->SendWindowBlur(this);
   }
 }
 
 Nullable<WindowProxyHolder> BrowsingContext::GetTop(ErrorResult& aError) {
+  if (mClosed) {
+    return nullptr;
+  }
+
   // We never return null or throw an error, but the implementation in
   // nsGlobalWindow does and we need to use the same signature.
   return WindowProxyHolder(Top());
 }
 
 void BrowsingContext::GetOpener(JSContext* aCx,
                                 JS::MutableHandle<JS::Value> aOpener,
                                 ErrorResult& aError) const {
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -2939,23 +2939,18 @@ bool nsPIDOMWindowOuter::GetServiceWorke
   nsCOMPtr<nsPIDOMWindowOuter> topWindow = GetScriptableTop();
   if (!topWindow) {
     return false;
   }
   return topWindow->mServiceWorkersTestingEnabled;
 }
 
 Nullable<WindowProxyHolder> nsGlobalWindowOuter::GetParentOuter() {
-  nsPIDOMWindowOuter* parent = GetScriptableParent();
-  BrowsingContext* parentBC;
-  if (!parent || !(parentBC = parent->GetBrowsingContext())) {
-    return nullptr;
-  }
-
-  return WindowProxyHolder(parentBC);
+  BrowsingContext* bc = GetBrowsingContext();
+  return bc ? bc->GetParent(IgnoreErrors()) : nullptr;
 }
 
 /**
  * GetScriptableParent is called when script reads window.parent.
  *
  * In contrast to GetRealParent, GetScriptableParent respects <iframe
  * mozbrowser> boundaries, so if |this| is contained by an <iframe
  * mozbrowser>, we will return |this| as its own parent.
@@ -3949,22 +3944,18 @@ double nsGlobalWindowOuter::GetScrollYOu
 
 uint32_t nsGlobalWindowOuter::Length() {
   nsDOMWindowList* windows = GetFrames();
 
   return windows ? windows->GetLength() : 0;
 }
 
 Nullable<WindowProxyHolder> nsGlobalWindowOuter::GetTopOuter() {
-  nsCOMPtr<nsPIDOMWindowOuter> top = GetScriptableTop();
-  BrowsingContext* topBC;
-  if (!top || !(topBC = top->GetBrowsingContext())) {
-    return nullptr;
-  }
-  return WindowProxyHolder(topBC);
+  BrowsingContext* bc = GetBrowsingContext();
+  return bc ? bc->GetTop(IgnoreErrors()) : nullptr;
 }
 
 already_AddRefed<BrowsingContext> nsGlobalWindowOuter::GetChildWindow(
     const nsAString& aName) {
   NS_ENSURE_TRUE(mBrowsingContext, nullptr);
 
   return do_AddRef(mBrowsingContext->FindChildWithName(aName));
 }