Bug 1310778 - Move TabGroup and GetDocGroup accessors onto nsPIDOMWindow{Inner,Outer}, r=smaug
authorMichael Layzell <michael@thelayzells.com>
Fri, 28 Oct 2016 14:10:32 -0400
changeset 320073 3ecd7c2308e72d85b9797458c1d2594ade5458c3
parent 320041 f4459d4ba9bad96caee8ec37b3ffde872fbab42f
child 320074 d77c9965e9b287150fcc5fc23d386a9ade278bd2
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1310778
milestone52.0a1
Bug 1310778 - Move TabGroup and GetDocGroup accessors onto nsPIDOMWindow{Inner,Outer}, r=smaug MozReview-Commit-ID: Hl0QVktr0Lw
docshell/base/nsDocShell.cpp
dom/base/nsDocument.cpp
dom/base/nsGlobalWindow.cpp
dom/base/nsGlobalWindow.h
dom/base/nsPIDOMWindow.h
embedding/components/windowwatcher/nsWindowWatcher.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -3770,18 +3770,17 @@ nsDocShell::DoFindItemWithName(const nsA
         aResult);
     }
   }
 
   // If we have a null parent or the parent is not of the same type, we need to
   // give up on finding it in our tree, and start looking in our TabGroup.
   nsCOMPtr<nsPIDOMWindowOuter> window = GetWindow();
   if (window) {
-    RefPtr<mozilla::dom::TabGroup> tabGroup =
-      nsGlobalWindow::Cast(window)->TabGroup();
+    RefPtr<mozilla::dom::TabGroup> tabGroup = window->TabGroup();
     // We don't want to make the request to our TabGroup if they are the ones
     // which made a request to us.
     if (tabGroup != aRequestor) {
       tabGroup->FindItemWithName(aName, this, aOriginalRequestor, aResult);
     }
   }
 
   return NS_OK;
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -4284,17 +4284,17 @@ nsDocument::SetScopeObject(nsIGlobalObje
   mScopeObject = do_GetWeakReference(aGlobal);
   if (aGlobal) {
     mHasHadScriptHandlingObject = true;
 
     nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal);
     if (window) {
       // We want to get the tabgroup unconditionally, such that we can make
       // certain that it is cached in the inner window early enough.
-      mozilla::dom::TabGroup* tabgroup = nsGlobalWindow::Cast(window)->TabGroup();
+      mozilla::dom::TabGroup* tabgroup = window->TabGroup();
       // We should already have the principal, and now that we have been added to a
       // window, we should be able to join a DocGroup!
       nsAutoCString docGroupKey;
       mozilla::dom::DocGroup::GetKey(NodePrincipal(), docGroupKey);
       if (mDocGroup) {
         MOZ_RELEASE_ASSERT(mDocGroup->MatchesKey(docGroupKey));
       } else {
         mDocGroup = tabgroup->AddDocument(docGroupKey, this);
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -14636,18 +14636,18 @@ nsGlobalWindow::TabGroupOuter()
   // Outer windows lazily join TabGroups when requested. This is usually done
   // because a document is getting its NodePrincipal, and asking for the
   // TabGroup to determine its DocGroup.
   if (!mTabGroup) {
     // Get mOpener ourselves, instead of relying on GetOpenerWindowOuter,
     // because that way we dodge the LegacyIsCallerChromeOrNativeCode() call
     // which we want to return false.
     nsCOMPtr<nsPIDOMWindowOuter> piOpener = do_QueryReferent(mOpener);
-    nsGlobalWindow* opener = Cast(GetSanitizedOpener(piOpener));
-    nsGlobalWindow* parent = Cast(GetScriptableParentOrNull());
+    nsPIDOMWindowOuter* opener = GetSanitizedOpener(piOpener);
+    nsPIDOMWindowOuter* parent = GetScriptableParentOrNull();
     MOZ_ASSERT(!parent || !opener, "Only one of parent and opener may be provided");
 
     mozilla::dom::TabGroup* toJoin = nullptr;
     if (GetDocShell()->ItemType() == nsIDocShellTreeItem::typeChrome) {
       toJoin = TabGroup::GetChromeTabGroup();
     } else if (opener) {
       toJoin = opener->TabGroup();
     } else if (parent) {
@@ -14662,20 +14662,20 @@ nsGlobalWindow::TabGroupOuter()
   if (!mIsValidatingTabGroup) {
     mIsValidatingTabGroup = true;
     // We only need to do this check if we aren't in the chrome tab group
     if (GetDocShell()->ItemType() == nsIDocShellTreeItem::typeChrome) {
       MOZ_ASSERT(mTabGroup == TabGroup::GetChromeTabGroup());
     } else {
       // Sanity check that our tabgroup matches our opener or parent.
       RefPtr<nsPIDOMWindowOuter> parent = GetScriptableParentOrNull();
-      MOZ_ASSERT_IF(parent, Cast(parent)->TabGroup() == mTabGroup);
+      MOZ_ASSERT_IF(parent, parent->TabGroup() == mTabGroup);
       nsCOMPtr<nsPIDOMWindowOuter> piOpener = do_QueryReferent(mOpener);
-      nsGlobalWindow* opener = Cast(GetSanitizedOpener(piOpener));
-      MOZ_ASSERT_IF(opener && opener != this, opener->TabGroup() == mTabGroup);
+      nsPIDOMWindowOuter* opener = GetSanitizedOpener(piOpener);
+      MOZ_ASSERT_IF(opener && Cast(opener) != this, opener->TabGroup() == mTabGroup);
     }
     mIsValidatingTabGroup = false;
   }
 #endif
 
   return mTabGroup;
 }
 
@@ -14704,27 +14704,33 @@ nsGlobalWindow::TabGroupInner()
 #ifdef DEBUG
   nsGlobalWindow* outer = GetOuterWindowInternal();
   MOZ_ASSERT_IF(outer, outer->TabGroup() == mTabGroup);
 #endif
 
   return mTabGroup;
 }
 
+template<typename T>
 mozilla::dom::TabGroup*
-nsGlobalWindow::TabGroup()
-{
+nsPIDOMWindow<T>::TabGroup()
+{
+  nsGlobalWindow* globalWindow =
+    static_cast<nsGlobalWindow*>(
+        reinterpret_cast<nsPIDOMWindow<nsISupports>*>(this));
+
   if (IsInnerWindow()) {
-    return TabGroupInner();
-  }
-  return TabGroupOuter();
-}
-
+    return globalWindow->TabGroupInner();
+  }
+  return globalWindow->TabGroupOuter();
+}
+
+template<typename T>
 mozilla::dom::DocGroup*
-nsGlobalWindow::GetDocGroup()
+nsPIDOMWindow<T>::GetDocGroup()
 {
   nsIDocument* doc = GetExtantDoc();
   if (doc) {
     return doc->GetDocGroup();
   }
   return nullptr;
 }
 
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -1740,23 +1740,24 @@ private:
   void FireOnNewGlobalObject();
 
   void DisconnectEventTargetObjects();
 
   // Called only on outer windows to compute the value that will be returned by
   // IsSecureContext() for the inner window that corresponds to aDocument.
   bool ComputeIsSecureContext(nsIDocument* aDocument);
 
+  // nsPIDOMWindow<T> should be able to see these helper methods.
+  friend class nsPIDOMWindow<mozIDOMWindowProxy>;
+  friend class nsPIDOMWindow<mozIDOMWindow>;
+  friend class nsPIDOMWindow<nsISupports>;
+
   mozilla::dom::TabGroup* TabGroupInner();
   mozilla::dom::TabGroup* TabGroupOuter();
 
-public:
-  mozilla::dom::TabGroup* TabGroup();
-  mozilla::dom::DocGroup* GetDocGroup();
-
 protected:
   // These members are only used on outer window objects. Make sure
   // you never set any of these on an inner object!
   bool                          mFullScreen : 1;
   bool                          mFullscreenMode : 1;
   bool                          mIsClosed : 1;
   bool                          mInClose : 1;
   // mHavePendingClose means we've got a termination function set to
@@ -1950,17 +1951,16 @@ protected:
   nsAutoPtr<mozilla::dom::WindowOrientationObserver> mOrientationChangeObserver;
 #endif
 
 #ifdef MOZ_WEBSPEECH
   // mSpeechSynthesis is only used on inner windows.
   RefPtr<mozilla::dom::SpeechSynthesis> mSpeechSynthesis;
 #endif
 
-  RefPtr<mozilla::dom::TabGroup> mTabGroup; // Outer window only
 #ifdef DEBUG
   // This member is used in the debug only assertions in TabGroup()
   // to catch cyclic parent/opener trees and not overflow the stack.
   bool mIsValidatingTabGroup;
 #endif
 
   // This is the CC generation the last time we called CanSkip.
   uint32_t mCanSkipCCGeneration;
--- a/dom/base/nsPIDOMWindow.h
+++ b/dom/base/nsPIDOMWindow.h
@@ -38,16 +38,18 @@ class nsPIWindowRoot;
 class nsXBLPrototypeHandler;
 struct nsTimeout;
 
 typedef uint32_t SuspendTypes;
 
 namespace mozilla {
 namespace dom {
 class AudioContext;
+class DocGroup;
+class TabGroup;
 class Element;
 class Performance;
 class ServiceWorkerRegistration;
 class CustomElementRegistry;
 } // namespace dom
 } // namespace mozilla
 
 // Popup control state enum. The values in this enum must go from most
@@ -570,16 +572,20 @@ public:
   virtual nsresult SetFullScreen(bool aFullScreen) = 0;
 
   virtual nsresult Focus() = 0;
   virtual nsresult Close() = 0;
 
   virtual nsresult MoveBy(int32_t aXDif, int32_t aYDif) = 0;
   virtual nsresult UpdateCommands(const nsAString& anAction, nsISelection* aSel, int16_t aReason) = 0;
 
+  mozilla::dom::TabGroup* TabGroup();
+
+  mozilla::dom::DocGroup* GetDocGroup();
+
 protected:
   // The nsPIDOMWindow constructor. The aOuterWindow argument should
   // be null if and only if the created window itself is an outer
   // window. In all other cases aOuterWindow should be the outer
   // window for the inner window that is being created.
   explicit nsPIDOMWindow<T>(nsPIDOMWindowOuter *aOuterWindow);
 
   ~nsPIDOMWindow<T>();
@@ -681,16 +687,19 @@ protected:
 
   // the element within the document that is currently focused when this
   // window is active
   nsCOMPtr<nsIContent> mFocusedNode;
 
   // The AudioContexts created for the current document, if any.
   nsTArray<mozilla::dom::AudioContext*> mAudioContexts; // Weak
 
+  // This is present both on outer and inner windows.
+  RefPtr<mozilla::dom::TabGroup> mTabGroup;
+
   // A unique (as long as our 64-bit counter doesn't roll over) id for
   // this window.
   uint64_t mWindowID;
 
   // This is only used by the inner window. Set to true once we've sent
   // the (chrome|content)-document-global-created notification.
   bool mHasNotifiedGlobalCreated;
 
--- a/embedding/components/windowwatcher/nsWindowWatcher.cpp
+++ b/embedding/components/windowwatcher/nsWindowWatcher.cpp
@@ -2141,18 +2141,17 @@ nsWindowWatcher::ReadyOpenedDocShellItem
   NS_ENSURE_ARG(aOpenedWindow);
 
   *aOpenedWindow = 0;
   nsCOMPtr<nsPIDOMWindowOuter> piOpenedWindow = aOpenedItem->GetWindow();
   if (piOpenedWindow) {
     if (!aForceNoOpener) {
       piOpenedWindow->SetOpenerWindow(aParent, aWindowIsNew); // damnit
     } else if (aParent && aParent != piOpenedWindow) {
-      MOZ_ASSERT(nsGlobalWindow::Cast(piOpenedWindow)->TabGroup() !=
-                 nsGlobalWindow::Cast(aParent)->TabGroup(),
+      MOZ_ASSERT(piOpenedWindow->TabGroup() != aParent->TabGroup(),
                  "If we're forcing no opener, they should be in different tab groups");
     }
 
     if (aWindowIsNew) {
 #ifdef DEBUG
       // Assert that we're not loading things right now.  If we are, when
       // that load completes it will clobber whatever principals we set up
       // on this new window!