Bug 1444580: Devirtualize the visibility state stuff. r=smaug draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 10 Mar 2018 05:52:58 +0100
changeset 765762 dab669fbf32c490bc910f3ccaf235903eadb1eca
parent 765761 f5f1cb775c01edc1ccbd8f677ef09642f3dace24
child 765763 4a0e57ce351909454ba7e8bc648a9668faf392ef
push id102160
push userbmo:emilio@crisal.io
push dateSat, 10 Mar 2018 06:32:21 +0000
reviewerssmaug
bugs1444580
milestone60.0a1
Bug 1444580: Devirtualize the visibility state stuff. r=smaug Also rename GetVisibilityState to ComputeVisibilityState, since that's what it does, the getter is VisibilityState. MozReview-Commit-ID: 9qfKvUmO0dW
dom/base/nsDocument.cpp
dom/base/nsDocument.h
dom/base/nsIDocument.h
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -4966,17 +4966,17 @@ nsDocument::SetScriptGlobalObject(nsIScr
   }
 
   // Set our visibility state, but do not fire the event.  This is correct
   // because either we're coming out of bfcache (in which case IsVisible() will
   // still test false at this point and no state change will happen) or we're
   // doing the initial document load and don't want to fire the event for this
   // change.
   dom::VisibilityState oldState = mVisibilityState;
-  mVisibilityState = GetVisibilityState();
+  mVisibilityState = ComputeVisibilityState();
   // When the visibility is changed, notify it to observers.
   // Some observers need the notification, for example HTMLMediaElement uses
   // it to update internal media resource allocation.
   // When video is loaded via VideoDocument, HTMLMediaElement and MediaDecoder
   // creation are already done before nsDocument::SetScriptGlobalObject() call.
   // MediaDecoder decides whether starting decoding is decided based on
   // document's visibility. When the MediaDecoder is created,
   // nsDocument::SetScriptGlobalObject() is not yet called and document is
@@ -11811,63 +11811,63 @@ nsDocument::UnlockPointer(nsIDocument* a
 
 void
 nsIDocument::UnlockPointer(nsIDocument* aDoc)
 {
   nsDocument::UnlockPointer(aDoc);
 }
 
 void
-nsDocument::UpdateVisibilityState()
+nsIDocument::UpdateVisibilityState()
 {
   dom::VisibilityState oldState = mVisibilityState;
-  mVisibilityState = GetVisibilityState();
+  mVisibilityState = ComputeVisibilityState();
   if (oldState != mVisibilityState) {
     nsContentUtils::DispatchTrustedEvent(this, static_cast<nsIDocument*>(this),
                                          NS_LITERAL_STRING("visibilitychange"),
                                          /* bubbles = */ true,
                                          /* cancelable = */ false);
     EnumerateActivityObservers(NotifyActivityChanged, nullptr);
   }
 
   if (mVisibilityState == dom::VisibilityState::Visible) {
     MaybeActiveMediaComponents();
   }
 }
 
 VisibilityState
-nsDocument::GetVisibilityState() const
+nsIDocument::ComputeVisibilityState() const
 {
   // We have to check a few pieces of information here:
   // 1)  Are we in bfcache (!IsVisible())?  If so, nothing else matters.
   // 2)  Do we have an outer window?  If not, we're hidden.  Note that we don't
   //     want to use GetWindow here because it does weird groveling for windows
   //     in some cases.
   // 3)  Is our outer window background?  If so, we're hidden.
   // Otherwise, we're visible.
   if (!IsVisible() || !mWindow || !mWindow->GetOuterWindow() ||
       mWindow->GetOuterWindow()->IsBackground()) {
     return dom::VisibilityState::Hidden;
   }
 
   return dom::VisibilityState::Visible;
 }
 
-/* virtual */ void
-nsDocument::PostVisibilityUpdateEvent()
+void
+nsIDocument::PostVisibilityUpdateEvent()
 {
   nsCOMPtr<nsIRunnable> event =
-    NewRunnableMethod("nsDocument::UpdateVisibilityState",
+    NewRunnableMethod("nsIDocument::UpdateVisibilityState",
                       this,
-                      &nsDocument::UpdateVisibilityState);
+                      &nsIDocument::UpdateVisibilityState);
   Dispatch(TaskCategory::Other, event.forget());
 }
 
 void
-nsDocument::MaybeActiveMediaComponents()
+nsIDocument::MaybeActiveMediaComponents()
 {
   if (!mWindow) {
     return;
   }
 
   GetWindow()->MaybeActiveMediaComponents();
 }
 
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -742,26 +742,16 @@ public:
 
   void SetCurrentOrientation(mozilla::dom::OrientationType aType,
                              uint16_t aAngle) override;
   uint16_t CurrentOrientationAngle() const override;
   mozilla::dom::OrientationType CurrentOrientationType() const override;
   void SetOrientationPendingPromise(mozilla::dom::Promise* aPromise) override;
   mozilla::dom::Promise* GetOrientationPendingPromise() const override;
 
-  // This method may fire a DOM event; if it does so it will happen
-  // synchronously.
-  void UpdateVisibilityState();
-  // Posts an event to call UpdateVisibilityState
-  virtual void PostVisibilityUpdateEvent() override;
-
-  // Since we wouldn't automatically play media from non-visited page, we need
-  // to notify window when the page was first visited.
-  void MaybeActiveMediaComponents();
-
   virtual void DocAddSizeOfExcludingThis(nsWindowSizes& aWindowSizes) const override;
   // DocAddSizeOfIncludingThis is inherited from nsIDocument.
 
   virtual nsIDOMNode* AsDOMNode() override { return this; }
 
   // WebIDL bits
   virtual mozilla::dom::DOMImplementation*
     GetImplementation(mozilla::ErrorResult& rv) override;
@@ -896,18 +886,16 @@ public:
 
   // The application cache that this document is associated with, if
   // any.  This can change during the lifetime of the document.
   nsCOMPtr<nsIApplicationCache> mApplicationCache;
 
   nsCOMPtr<nsIContent> mFirstBaseNodeWithHref;
 private:
   friend class nsUnblockOnloadEvent;
-  // Recomputes the visibility state but doesn't set the new value.
-  mozilla::dom::VisibilityState GetVisibilityState() const;
 
   void PostUnblockOnloadEvent();
   void DoUnblockOnload();
 
   nsresult InitCSP(nsIChannel* aChannel);
 
   void ClearAllBoxObjects();
 
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -2817,17 +2817,18 @@ public:
   };
 #undef DOCUMENT_WARNING
   bool HasWarnedAbout(DocumentWarnings aWarning) const;
   void WarnOnceAbout(DocumentWarnings aWarning,
                      bool asError = false,
                      const char16_t **aParams = nullptr,
                      uint32_t aParamsLength = 0) const;
 
-  virtual void PostVisibilityUpdateEvent() = 0;
+  // Posts an event to call UpdateVisibilityState
+  void PostVisibilityUpdateEvent();
 
   bool IsSyntheticDocument() const { return mIsSyntheticDocument; }
 
   // Note: nsIDocument is a sub-class of nsINode, which has a
   // SizeOfExcludingThis function.  However, because nsIDocument objects can
   // only appear at the top of the DOM tree, we have a specialized measurement
   // function which returns multiple sizes.
   virtual void DocAddSizeOfExcludingThis(nsWindowSizes& aWindowSizes) const;
@@ -3327,16 +3328,27 @@ protected:
   mozilla::dom::FlashClassification PrincipalFlashClassification();
 
   // Attempts to determine the Flash classification of this page based on the
   // the classification lists and the classification of parent documents.
   mozilla::dom::FlashClassification ComputeFlashClassification();
 
   void RecordNavigationTiming(ReadyState aReadyState);
 
+  // This method may fire a DOM event; if it does so it will happen
+  // synchronously.
+  void UpdateVisibilityState();
+
+  // Recomputes the visibility state but doesn't set the new value.
+  mozilla::dom::VisibilityState ComputeVisibilityState() const;
+
+  // Since we wouldn't automatically play media from non-visited page, we need
+  // to notify window when the page was first visited.
+  void MaybeActiveMediaComponents();
+
   bool GetUseCounter(mozilla::UseCounter aUseCounter)
   {
     return mUseCounters[aUseCounter];
   }
 
   void SetChildDocumentUseCounter(mozilla::UseCounter aUseCounter)
   {
     if (!mChildDocumentUseCounters[aUseCounter]) {