Bug 1542785 - Expose a `top` method on BrowsingContext to Chrome JS, r=farre
authorNika Layzell <nika@thelayzells.com>
Tue, 09 Apr 2019 06:19:24 +0000
changeset 469515 04fa858d12cf64a881d3f73eb19bb1110b45b358
parent 469514 12d67626c02abf74d423403b35e25f98b94d5401
child 469516 3609e70954e882291238a97c5185a730a845d777
push id112801
push userccoroiu@mozilla.com
push dateMon, 15 Apr 2019 21:40:09 +0000
treeherdermozilla-inbound@afb20612c0e5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfarre
bugs1542785
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 1542785 - Expose a `top` method on BrowsingContext to Chrome JS, r=farre Differential Revision: https://phabricator.services.mozilla.com/D26554
docshell/base/BrowsingContext.cpp
docshell/base/BrowsingContext.h
dom/chrome-webidl/BrowsingContext.webidl
--- a/docshell/base/BrowsingContext.cpp
+++ b/docshell/base/BrowsingContext.cpp
@@ -60,17 +60,17 @@ static StaticAutoPtr<BrowsingContextMap<
 
 static void Register(BrowsingContext* aBrowsingContext) {
   MOZ_ALWAYS_TRUE(
       sBrowsingContexts->putNew(aBrowsingContext->Id(), aBrowsingContext));
 
   aBrowsingContext->Group()->Register(aBrowsingContext);
 }
 
-BrowsingContext* BrowsingContext::TopLevelBrowsingContext() {
+BrowsingContext* BrowsingContext::Top() {
   BrowsingContext* bc = this;
   while (bc->mParent) {
     bc = bc->mParent;
   }
   return bc;
 }
 
 /* static */
@@ -408,17 +408,17 @@ BrowsingContext* BrowsingContext::FindWi
     return this;
   }
 
   if (aName.LowerCaseEqualsLiteral("_parent")) {
     return mParent && CanAccess(mParent.get()) ? mParent.get() : this;
   }
 
   if (aName.LowerCaseEqualsLiteral("_top")) {
-    BrowsingContext* top = TopLevelBrowsingContext();
+    BrowsingContext* top = Top();
 
     return CanAccess(top) ? top : nullptr;
   }
 
   return nullptr;
 }
 
 BrowsingContext* BrowsingContext::FindWithNameInSubtree(
@@ -485,34 +485,34 @@ JSObject* BrowsingContext::WrapObject(JS
                                       JS::Handle<JSObject*> aGivenProto) {
   return BrowsingContext_Binding::Wrap(aCx, this, aGivenProto);
 }
 
 void BrowsingContext::NotifyUserGestureActivation() {
   // We would set the user gesture activation flag on the top level browsing
   // context, which would automatically be sync to other top level browsing
   // contexts which are in the different process.
-  RefPtr<BrowsingContext> topLevelBC = TopLevelBrowsingContext();
+  RefPtr<BrowsingContext> topLevelBC = Top();
   USER_ACTIVATION_LOG("Get top level browsing context 0x%08" PRIx64,
                       topLevelBC->Id());
   topLevelBC->SetIsActivatedByUserGesture(true);
 }
 
 void BrowsingContext::NotifyResetUserGestureActivation() {
   // We would reset the user gesture activation flag on the top level browsing
   // context, which would automatically be sync to other top level browsing
   // contexts which are in the different process.
-  RefPtr<BrowsingContext> topLevelBC = TopLevelBrowsingContext();
+  RefPtr<BrowsingContext> topLevelBC = Top();
   USER_ACTIVATION_LOG("Get top level browsing context 0x%08" PRIx64,
                       topLevelBC->Id());
   topLevelBC->SetIsActivatedByUserGesture(false);
 }
 
 bool BrowsingContext::GetUserGestureActivation() {
-  RefPtr<BrowsingContext> topLevelBC = TopLevelBrowsingContext();
+  RefPtr<BrowsingContext> topLevelBC = Top();
   return topLevelBC->GetIsActivatedByUserGesture();
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(BrowsingContext)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(BrowsingContext)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocShell, mChildren, mParent, mGroup)
   if (XRE_IsParentProcess()) {
@@ -597,17 +597,17 @@ void BrowsingContext::Blur(ErrorResult& 
   } else if (ContentParent* cp = Canonical()->GetContentParent()) {
     Unused << cp->SendWindowBlur(this);
   }
 }
 
 Nullable<WindowProxyHolder> BrowsingContext::GetTop(ErrorResult& aError) {
   // We never return null or throw an error, but the implementation in
   // nsGlobalWindow does and we need to use the same signature.
-  return WindowProxyHolder(TopLevelBrowsingContext());
+  return WindowProxyHolder(Top());
 }
 
 void BrowsingContext::GetOpener(JSContext* aCx,
                                 JS::MutableHandle<JS::Value> aOpener,
                                 ErrorResult& aError) const {
   RefPtr<BrowsingContext> opener = GetOpener();
   if (!opener) {
     aOpener.setNull();
--- a/docshell/base/BrowsingContext.h
+++ b/docshell/base/BrowsingContext.h
@@ -151,16 +151,18 @@ class BrowsingContext : public nsWrapper
   bool NameEquals(const nsAString& aName) { return mName.Equals(aName); }
 
   bool IsContent() const { return mType == Type::Content; }
 
   uint64_t Id() const { return mBrowsingContextId; }
 
   BrowsingContext* GetParent() const { return mParent; }
 
+  BrowsingContext* Top();
+
   already_AddRefed<BrowsingContext> GetOpener() const { return Get(mOpenerId); }
   void SetOpener(BrowsingContext* aOpener) {
     SetOpenerId(aOpener ? aOpener->Id() : 0);
   }
 
   void GetChildren(nsTArray<RefPtr<BrowsingContext>>& aChildren);
 
   BrowsingContextGroup* Group() { return mGroup; }
@@ -379,18 +381,16 @@ class BrowsingContext : public nsWrapper
       mWindowProxy = obj;
     }
   }
   // Clear the window proxy object that corresponds to this browsing context.
   // This should be called if the window proxy object is finalized, or it can't
   // reach its browsing context anymore.
   void ClearWindowProxy() { mWindowProxy = nullptr; }
 
-  BrowsingContext* TopLevelBrowsingContext();
-
   friend class Location;
   friend class RemoteLocationProxy;
   /**
    * LocationProxy is the class for the native object stored as a private in a
    * RemoteLocationProxy proxy representing a Location object in a different
    * process. It forwards all operations to its BrowsingContext and aggregates
    * its refcount to that BrowsingContext.
    */
--- a/dom/chrome-webidl/BrowsingContext.webidl
+++ b/dom/chrome-webidl/BrowsingContext.webidl
@@ -11,16 +11,18 @@ interface BrowsingContext {
 
   BrowsingContext? findChildWithName(DOMString name);
   BrowsingContext? findWithName(DOMString name);
 
   readonly attribute DOMString name;
 
   readonly attribute BrowsingContext? parent;
 
+  readonly attribute BrowsingContext top;
+
   sequence<BrowsingContext> getChildren();
 
   readonly attribute nsIDocShell? docShell;
 
   readonly attribute unsigned long long id;
 
   readonly attribute BrowsingContext? opener;