Bug 1416384 - Part 3: Remove nsPIDOMWindow<nsISupports>, r=smaug
authorNika Layzell <nika@thelayzells.com>
Wed, 15 Nov 2017 11:34:04 -0500
changeset 436480 ba47537d18440f8d9df9351d3461d734beb9e867
parent 436479 862355bc5c589cc22420526d5bbf10e7f6f7ba78
child 436481 2d5ba51ff7e36562bb2534ed47e99af3b4e8c98d
push id117
push userfmarier@mozilla.com
push dateTue, 28 Nov 2017 20:17:16 +0000
reviewerssmaug
bugs1416384
milestone59.0a1
Bug 1416384 - Part 3: Remove nsPIDOMWindow<nsISupports>, r=smaug This was needed before as the base to nsGlobalWindow, but now that nsGlobalWindow doesn't exist, and we only have specific versions, we no longer need this type. MozReview-Commit-ID: 6IJmJtnSkMr
dom/base/nsGlobalWindow.cpp
dom/base/nsGlobalWindowInner.cpp
dom/base/nsGlobalWindowInner.h
dom/base/nsGlobalWindowOuter.cpp
dom/base/nsGlobalWindowOuter.h
dom/base/nsPIDOMWindow.h
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -901,31 +901,26 @@ IsInterval(const Optional<int32_t>& aTim
   }
 
   // If no interval was specified, treat this like a timeout, to avoid setting
   // an interval of 0 milliseconds.
   aResultTimeout = 0;
   return false;
 }
 
-template<typename T>
 mozilla::dom::TabGroup*
-nsPIDOMWindow<T>::TabGroup()
+nsPIDOMWindowInner::TabGroup()
 {
-  if (IsInnerWindow()) {
-    nsGlobalWindowInner* globalWindow =
-      static_cast<nsGlobalWindowInner*>(
-        reinterpret_cast<nsPIDOMWindow<nsISupports>*>(this));
-    return globalWindow->TabGroupInner();
-  } else {
-    nsGlobalWindowOuter* globalWindow =
-      static_cast<nsGlobalWindowOuter*>(
-        reinterpret_cast<nsPIDOMWindow<nsISupports>*>(this));
-    return globalWindow->TabGroupOuter();
-  }
+  return nsGlobalWindowInner::Cast(this)->TabGroupInner();
+}
+
+mozilla::dom::TabGroup*
+nsPIDOMWindowOuter::TabGroup()
+{
+  return nsGlobalWindowOuter::Cast(this)->TabGroupOuter();
 }
 
 template<typename T>
 mozilla::dom::DocGroup*
 nsPIDOMWindow<T>::GetDocGroup() const
 {
   nsIDocument* doc = GetExtantDoc();
   if (doc) {
@@ -952,9 +947,8 @@ EnsurePrefCaches()
 }
 
 // Include the implementations for the inner and outer windows respectively.
 #include "nsGlobalWindowOuter.cpp"
 #include "nsGlobalWindowInner.cpp"
 
 template class nsPIDOMWindow<mozIDOMWindowProxy>;
 template class nsPIDOMWindow<mozIDOMWindow>;
-template class nsPIDOMWindow<nsISupports>;
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -521,17 +521,17 @@ nsGlobalWindowInner::IsBackgroundInterna
   return !mOuterWindow || mOuterWindow->IsBackground();
 }
 
 //*****************************************************************************
 //***    nsGlobalWindowInner: Object Management
 //*****************************************************************************
 
 nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter *aOuterWindow)
-  : nsPIDOMWindow<nsISupports>(aOuterWindow->AsOuter()),
+  : nsPIDOMWindowInner(aOuterWindow->AsOuter()),
     mIdleFuzzFactor(0),
     mIdleCallbackIndex(-1),
     mCurrentlyIdle(false),
     mAddActiveEventFuzzTime(true),
     mFullScreen(false),
     mFullscreenMode(false),
     mIsClosed(false),
     mInClose(false),
--- a/dom/base/nsGlobalWindowInner.h
+++ b/dom/base/nsGlobalWindowInner.h
@@ -209,28 +209,18 @@ ImplCycleCollectionTraverse(nsCycleColle
 // needed to ensure that mOuterWindow doesn't end up dangling. The
 // nature of PRCList means that the window itself is always in the
 // list, and an outer window's list will also contain all inner window
 // objects that are still in memory (and in reality all inner window
 // object's lists also contain its outer and all other inner windows
 // belonging to the same outer window, but that's an unimportant
 // side effect of inheriting PRCList).
 
-// NB: Currently nsPIDOMWindowInner and nsPIDOMWindowOuter are identical classes
-// with identical member variables and identical vtables, that only differ in
-// type name. nsGlobalWindow doesn't want to doubly inherit (and have two
-// copies of everything), and it also doesn't want to privilege one over
-// the other by making it possible to convert types through the C++ type system
-// instead of our accessor methods (AsInner and AsOuter) that do dynamic
-// checking. So we inherit from nsPIDOMWindow<nsISupports>, which is also
-// identical to both nsPIDOMWindowInner and nsPIDOMWindowOuter, but not
-// convertible to either.
-
 class nsGlobalWindowInner : public mozilla::dom::EventTarget,
-                            public nsPIDOMWindow<nsISupports>,
+                            public nsPIDOMWindowInner,
                             private nsIDOMWindow,
                             // NOTE: This interface is private, as it's only
                             // implemented on chrome windows.
                             private nsIDOMChromeWindow,
                             public nsIScriptGlobalObject,
                             public nsIScriptObjectPrincipal,
                             public nsSupportsWeakReference,
                             public nsIInterfaceRequestor,
@@ -246,22 +236,20 @@ public:
   AssertIsOnMainThread()
 #ifdef DEBUG
   ;
 #else
   { }
 #endif
 
   static nsGlobalWindowInner* Cast(nsPIDOMWindowInner* aPIWin) {
-    return static_cast<nsGlobalWindowInner*>(
-      reinterpret_cast<nsPIDOMWindow<nsISupports>*>(aPIWin));
+    return static_cast<nsGlobalWindowInner*>(aPIWin);
   }
   static const nsGlobalWindowInner* Cast(const nsPIDOMWindowInner* aPIWin) {
-    return static_cast<const nsGlobalWindowInner*>(
-      reinterpret_cast<const nsPIDOMWindow<nsISupports>*>(aPIWin));
+    return static_cast<const nsGlobalWindowInner*>(aPIWin);
   }
   static nsGlobalWindowInner* Cast(mozIDOMWindow* aWin) {
     return Cast(nsPIDOMWindowInner::From(aWin));
   }
 
   static nsGlobalWindowInner*
   GetInnerWindowWithId(uint64_t aInnerWindowID)
   {
@@ -1690,16 +1678,18 @@ private:
   bool ComputeIsSecureContext(nsIDocument* aDocument,
                               SecureContextFlags aFlags =
                                 SecureContextFlags::eDefault);
 
   // nsPIDOMWindow<T> should be able to see these helper methods.
   friend class nsPIDOMWindow<mozIDOMWindowProxy>;
   friend class nsPIDOMWindow<mozIDOMWindow>;
   friend class nsPIDOMWindow<nsISupports>;
+  friend class nsPIDOMWindowInner;
+  friend class nsPIDOMWindowOuter;
 
   mozilla::dom::TabGroup* TabGroupInner();
   mozilla::dom::TabGroup* TabGroupOuter();
 
   bool IsBackgroundInternal() const;
 
   void SetIsBackgroundInternal(bool aIsBackground);
 
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -632,17 +632,17 @@ NewOuterWindowProxy(JSContext *cx, JS::H
   return obj;
 }
 
 //*****************************************************************************
 //***    nsGlobalWindowOuter: Object Management
 //*****************************************************************************
 
 nsGlobalWindowOuter::nsGlobalWindowOuter()
-  : nsPIDOMWindow<nsISupports>(nullptr),
+  : nsPIDOMWindowOuter(),
     mIdleFuzzFactor(0),
     mIdleCallbackIndex(-1),
     mCurrentlyIdle(false),
     mAddActiveEventFuzzTime(true),
     mFullScreen(false),
     mFullscreenMode(false),
     mIsClosed(false),
     mInClose(false),
--- a/dom/base/nsGlobalWindowOuter.h
+++ b/dom/base/nsGlobalWindowOuter.h
@@ -201,28 +201,18 @@ private:
 // needed to ensure that mOuterWindow doesn't end up dangling. The
 // nature of PRCList means that the window itself is always in the
 // list, and an outer window's list will also contain all inner window
 // objects that are still in memory (and in reality all inner window
 // object's lists also contain its outer and all other inner windows
 // belonging to the same outer window, but that's an unimportant
 // side effect of inheriting PRCList).
 
-// NB: Currently nsPIDOMWindowInner and nsPIDOMWindowOuter are identical classes
-// with identical member variables and identical vtables, that only differ in
-// type name. nsGlobalWindow doesn't want to doubly inherit (and have two
-// copies of everything), and it also doesn't want to privilege one over
-// the other by making it possible to convert types through the C++ type system
-// instead of our accessor methods (AsInner and AsOuter) that do dynamic
-// checking. So we inherit from nsPIDOMWindow<nsISupports>, which is also
-// identical to both nsPIDOMWindowInner and nsPIDOMWindowOuter, but not
-// convertible to either.
-
 class nsGlobalWindowOuter : public mozilla::dom::EventTarget,
-                            public nsPIDOMWindow<nsISupports>,
+                            public nsPIDOMWindowOuter,
                             private nsIDOMWindow,
                             // NOTE: This interface is private, as it's only
                             // implemented on chrome windows.
                             private nsIDOMChromeWindow,
                             public nsIScriptGlobalObject,
                             public nsIScriptObjectPrincipal,
                             public nsSupportsWeakReference,
                             public nsIInterfaceRequestor,
@@ -238,22 +228,20 @@ public:
   AssertIsOnMainThread()
 #ifdef DEBUG
   ;
 #else
   { }
 #endif
 
   static nsGlobalWindowOuter* Cast(nsPIDOMWindowOuter* aPIWin) {
-    return static_cast<nsGlobalWindowOuter*>(
-      reinterpret_cast<nsPIDOMWindow<nsISupports>*>(aPIWin));
+    return static_cast<nsGlobalWindowOuter*>(aPIWin);
   }
   static const nsGlobalWindowOuter* Cast(const nsPIDOMWindowOuter* aPIWin) {
-    return static_cast<const nsGlobalWindowOuter*>(
-      reinterpret_cast<const nsPIDOMWindow<nsISupports>*>(aPIWin));
+    return static_cast<const nsGlobalWindowOuter*>(aPIWin);
   }
   static nsGlobalWindowOuter* Cast(mozIDOMWindowProxy* aWin) {
     return Cast(nsPIDOMWindowOuter::From(aWin));
   }
 
   static nsGlobalWindowOuter*
   GetOuterWindowWithId(uint64_t aWindowID)
   {
@@ -1680,16 +1668,18 @@ private:
   bool ComputeIsSecureContext(nsIDocument* aDocument,
                               SecureContextFlags aFlags =
                                 SecureContextFlags::eDefault);
 
   // nsPIDOMWindow<T> should be able to see these helper methods.
   friend class nsPIDOMWindow<mozIDOMWindowProxy>;
   friend class nsPIDOMWindow<mozIDOMWindow>;
   friend class nsPIDOMWindow<nsISupports>;
+  friend class nsPIDOMWindowInner;
+  friend class nsPIDOMWindowOuter;
 
   mozilla::dom::TabGroup* TabGroupInner();
   mozilla::dom::TabGroup* TabGroupOuter();
 
   bool IsBackgroundInternal() const;
 
   void SetIsBackgroundInternal(bool aIsBackground);
 
--- a/dom/base/nsPIDOMWindow.h
+++ b/dom/base/nsPIDOMWindow.h
@@ -598,18 +598,16 @@ 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() const;
 
   virtual nsISerialEventTarget*
   EventTargetFor(mozilla::TaskCategory aCategory) const = 0;
 
 protected:
   // The nsPIDOMWindow constructor. The aOuterWindow argument should
   // be null if and only if the created window itself is an outer
@@ -764,16 +762,20 @@ protected:
 
 // NB: It's very very important that these two classes have identical vtables
 // and memory layout!
 class nsPIDOMWindowInner : public nsPIDOMWindow<mozIDOMWindow>
 {
   friend nsGlobalWindowInner;
   friend nsGlobalWindowOuter;
 
+  explicit nsPIDOMWindowInner(nsPIDOMWindowOuter* aOuterWindow)
+    : nsPIDOMWindow<mozIDOMWindow>(aOuterWindow)
+  {}
+
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_PIDOMWINDOWINNER_IID)
 
   static nsPIDOMWindowInner* From(mozIDOMWindow* aFrom) {
     return static_cast<nsPIDOMWindowInner*>(aFrom);
   }
 
   // Returns true if this object has an outer window and it is the current inner
@@ -936,27 +938,32 @@ public:
 
   // Increase/Decrease the number of open WebSockets.
   void UpdateWebSocketCount(int32_t aDelta);
 
   // Return true if there are any open WebSockets that could block
   // timeout-throttling.
   bool HasOpenWebSockets() const;
 
+  mozilla::dom::TabGroup* TabGroup();
 protected:
   void CreatePerformanceObjectIfNeeded();
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsPIDOMWindowInner, NS_PIDOMWINDOWINNER_IID)
 
 // NB: It's very very important that these two classes have identical vtables
 // and memory layout!
 class nsPIDOMWindowOuter : public nsPIDOMWindow<mozIDOMWindowProxy>
 {
 protected:
+  explicit nsPIDOMWindowOuter()
+    : nsPIDOMWindow<mozIDOMWindowProxy>(nullptr)
+  {}
+
   void RefreshMediaElementsVolume();
   void RefreshMediaElementsSuspend(SuspendTypes aSuspend);
   bool IsDisposableSuspend(SuspendTypes aSuspend) const;
   void MaybeNotifyMediaResumedFromBlock(SuspendTypes aSuspend);
 
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_PIDOMWINDOWOUTER_IID)
 
@@ -1027,16 +1034,18 @@ public:
   bool GetServiceWorkersTestingEnabled();
 
   float GetDevicePixelRatio(mozilla::dom::CallerType aCallerType);
 
   void SetLargeAllocStatus(mozilla::dom::LargeAllocStatus aStatus);
 
   bool IsTopLevelWindow();
   bool HadOriginalOpener() const;
+
+  mozilla::dom::TabGroup* TabGroup();
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsPIDOMWindowOuter, NS_PIDOMWINDOWOUTER_IID)
 
 #include "nsPIDOMWindowInlines.h"
 
 #ifdef MOZILLA_INTERNAL_API
 PopupControlState