Bug 1308459 - Rename RefreshDriver::PresContext() to hint about its behavior, r=tnikkel
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 12 Oct 2016 14:27:38 +0300
changeset 360499 1eed82166f20edd6da96df2eb12338d696db93da
parent 360498 6658f810356298603974bfc46c375f099239c0b5
child 360500 8c72a107222aadc4a852aa9e6a3e0097e45faf11
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-beta@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstnikkel
bugs1308459
milestone52.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 1308459 - Rename RefreshDriver::PresContext() to hint about its behavior, r=tnikkel
layout/base/nsPresContext.cpp
layout/base/nsPresContext.h
layout/base/nsPresShell.cpp
layout/base/nsRefreshDriver.cpp
layout/base/nsRefreshDriver.h
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -982,17 +982,17 @@ nsPresContext::DetachShell()
   if (mAnimationManager) {
     mAnimationManager->Disconnect();
     mAnimationManager = nullptr;
   }
   if (mRestyleManager) {
     mRestyleManager->Disconnect();
     mRestyleManager = nullptr;
   }
-  if (mRefreshDriver && mRefreshDriver->PresContext() == this) {
+  if (mRefreshDriver && mRefreshDriver->GetPresContext() == this) {
     mRefreshDriver->Disconnect();
     // Can't null out the refresh driver here.
   }
 
   if (IsRoot()) {
     nsRootPresContext* thisRoot = static_cast<nsRootPresContext*>(this);
 
     // Have to cancel our plugin geometry timer, because the
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -129,27 +129,29 @@ public:
 #define NS_AUTHOR_SPECIFIED_PADDING         (1 << 2)
 #define NS_AUTHOR_SPECIFIED_TEXT_SHADOW     (1 << 3)
 
 class nsRootPresContext;
 
 // An interface for presentation contexts. Presentation contexts are
 // objects that provide an outer context for a presentation shell.
 
-class nsPresContext : public nsIObserver {
+class nsPresContext : public nsIObserver,
+                      public mozilla::SupportsWeakPtr<nsPresContext> {
 public:
   typedef mozilla::FramePropertyTable FramePropertyTable;
   typedef mozilla::LangGroupFontPrefs LangGroupFontPrefs;
   typedef mozilla::ScrollbarStyles ScrollbarStyles;
   typedef mozilla::StaticPresData StaticPresData;
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_NSIOBSERVER
   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
   NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext)
+  MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsPresContext)
 
   enum nsPresContextType {
     eContext_Galley,       // unpaginated screen presentation
     eContext_PrintPreview, // paginated screen presentation
     eContext_Print,        // paginated printer presentation
     eContext_PageLayout    // paginated & editable.
   };
 
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -1290,17 +1290,17 @@ PresShell::Destroy()
   // Revoke any pending events.  We need to do this and cancel pending reflows
   // before we destroy the frame manager, since apparently frame destruction
   // sometimes spins the event queue when plug-ins are involved(!).
   rd->RemoveLayoutFlushObserver(this);
   if (mHiddenInvalidationObserverRefreshDriver) {
     mHiddenInvalidationObserverRefreshDriver->RemovePresShellToInvalidateIfHidden(this);
   }
 
-  if (rd->PresContext() == GetPresContext()) {
+  if (rd->GetPresContext() == GetPresContext()) {
     rd->RevokeViewManagerFlush();
   }
 
   mResizeEvent.Revoke();
   if (mAsyncResizeTimerIsActive) {
     mAsyncResizeEventTimer->Cancel();
     mAsyncResizeTimerIsActive = false;
   }
@@ -8992,17 +8992,17 @@ PresShell::Freeze()
   mPaintingSuppressed = true;
 
   if (mDocument) {
     mDocument->EnumerateSubDocuments(FreezeSubDocument, nullptr);
   }
 
   nsPresContext* presContext = GetPresContext();
   if (presContext &&
-      presContext->RefreshDriver()->PresContext() == presContext) {
+      presContext->RefreshDriver()->GetPresContext() == presContext) {
     presContext->RefreshDriver()->Freeze();
   }
 
   mFrozen = true;
   if (mDocument) {
     UpdateImageLockingState();
   }
 }
@@ -9050,17 +9050,17 @@ ThawSubDocument(nsIDocument *aDocument, 
   return true;
 }
 
 void
 PresShell::Thaw()
 {
   nsPresContext* presContext = GetPresContext();
   if (presContext &&
-      presContext->RefreshDriver()->PresContext() == presContext) {
+      presContext->RefreshDriver()->GetPresContext() == presContext) {
     presContext->RefreshDriver()->Thaw();
   }
 
   mDocument->EnumerateActivityObservers(ThawElement, this);
 
   if (mDocument)
     mDocument->EnumerateSubDocuments(ThawSubDocument, nullptr);
 
@@ -10906,17 +10906,17 @@ nsresult
 PresShell::SetIsActive(bool aIsActive)
 {
   NS_PRECONDITION(mDocument, "should only be called with a document");
 
   mIsActive = aIsActive;
 
   nsPresContext* presContext = GetPresContext();
   if (presContext &&
-      presContext->RefreshDriver()->PresContext() == presContext) {
+      presContext->RefreshDriver()->GetPresContext() == presContext) {
     presContext->RefreshDriver()->SetThrottled(!mIsActive);
   }
 
   // Propagate state-change to my resource documents' PresShells
   mDocument->EnumerateExternalResources(SetExternalResourceIsActive,
                                         &aIsActive);
   mDocument->EnumerateActivityObservers(SetPluginIsActive,
                                         &aIsActive);
@@ -11137,27 +11137,27 @@ nsIPresShell::FontSizeInflationEnabled()
   }
 
   return mFontSizeInflationEnabled;
 }
 
 void
 PresShell::PausePainting()
 {
-  if (GetPresContext()->RefreshDriver()->PresContext() != GetPresContext())
+  if (GetPresContext()->RefreshDriver()->GetPresContext() != GetPresContext())
     return;
 
   mPaintingIsFrozen = true;
   GetPresContext()->RefreshDriver()->Freeze();
 }
 
 void
 PresShell::ResumePainting()
 {
-  if (GetPresContext()->RefreshDriver()->PresContext() != GetPresContext())
+  if (GetPresContext()->RefreshDriver()->GetPresContext() != GetPresContext())
     return;
 
   mPaintingIsFrozen = false;
   GetPresContext()->RefreshDriver()->Thaw();
 }
 
 void
 nsIPresShell::SyncWindowProperties(nsView* aView)
--- a/layout/base/nsRefreshDriver.cpp
+++ b/layout/base/nsRefreshDriver.cpp
@@ -168,17 +168,18 @@ public:
   virtual void RemoveRefreshDriver(nsRefreshDriver* aDriver)
   {
     LOG("[%p] RemoveRefreshDriver %p", this, aDriver);
 
     if (IsRootRefreshDriver(aDriver)) {
       NS_ASSERTION(mRootRefreshDrivers.Contains(aDriver), "RemoveRefreshDriver for a refresh driver that's not in the root refresh list!");
       mRootRefreshDrivers.RemoveElement(aDriver);
     } else {
-      nsPresContext* rootContext = aDriver->PresContext()->GetRootPresContext();
+      nsPresContext* pc = aDriver->GetPresContext();
+      nsPresContext* rootContext = pc ? pc->GetRootPresContext() : nullptr;
       // During PresContext shutdown, we can't accurately detect
       // if a root refresh driver exists or not. Therefore, we have to
       // search and find out which list this driver exists in.
       if (!rootContext) {
         if (mRootRefreshDrivers.Contains(aDriver)) {
           mRootRefreshDrivers.RemoveElement(aDriver);
         } else {
           NS_ASSERTION(mContentRefreshDrivers.Contains(aDriver),
@@ -222,17 +223,18 @@ public:
 
 protected:
   virtual void StartTimer() = 0;
   virtual void StopTimer() = 0;
   virtual void ScheduleNextTick(TimeStamp aNowTime) = 0;
 
   bool IsRootRefreshDriver(nsRefreshDriver* aDriver)
   {
-    nsPresContext* rootContext = aDriver->PresContext()->GetRootPresContext();
+    nsPresContext* pc = aDriver->GetPresContext();
+    nsPresContext* rootContext = pc ? pc->GetRootPresContext() : nullptr;
     if (!rootContext) {
       return false;
     }
 
     return aDriver == rootContext->RefreshDriver();
   }
 
   /*
@@ -2095,17 +2097,18 @@ nsRefreshDriver::IsWaitingForPaint(mozil
     }
 
     mSkippedPaints = true;
     return true;
   }
 
   // Try find the 'root' refresh driver for the current window and check
   // if that is waiting for a paint.
-  nsPresContext *rootContext = PresContext()->GetRootPresContext();
+  nsPresContext* pc = GetPresContext();
+  nsPresContext* rootContext = pc ? pc->GetRootPresContext() : nullptr;
   if (rootContext) {
     nsRefreshDriver *rootRefresh = rootContext->RefreshDriver();
     if (rootRefresh && rootRefresh != this) {
       if (rootRefresh->IsWaitingForPaint(aTime)) {
         if (mRootRefresh != rootRefresh) {
           if (mRootRefresh) {
             mRootRefresh->RemoveRefreshObserver(this, Flush_Style);
           }
--- a/layout/base/nsRefreshDriver.h
+++ b/layout/base/nsRefreshDriver.h
@@ -9,17 +9,17 @@
  * refresh rate.  (Perhaps temporary, until replaced by compositor.)
  */
 
 #ifndef nsRefreshDriver_h_
 #define nsRefreshDriver_h_
 
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Vector.h"
-
+#include "mozilla/WeakPtr.h"
 #include "mozFlushType.h"
 #include "nsTObserverArray.h"
 #include "nsTArray.h"
 #include "nsTHashtable.h"
 #include "nsTObserverArray.h"
 #include "nsClassHashtable.h"
 #include "nsHashKeys.h"
 #include "mozilla/Attributes.h"
@@ -268,17 +268,17 @@ public:
    * Throttle or unthrottle the refresh driver.  This is done if the
    * corresponding presshell is hidden or shown.
    */
   void SetThrottled(bool aThrottled);
 
   /**
    * Return the prescontext we were initialized with
    */
-  nsPresContext* PresContext() const { return mPresContext; }
+  nsPresContext* GetPresContext() const { return mPresContext; }
 
   /**
    * PBackgroundChild actor is created asynchronously in content process.
    * We can't create vsync-based timers during PBackground startup. This
    * function will be called when PBackgroundChild actor is created. Then we can
    * do the pending vsync-based timer creation.
    */
   static void PVsyncActorCreated(mozilla::layout::VsyncChild* aVsyncChild);
@@ -376,18 +376,18 @@ private:
   void FinishedWaitingForTransaction();
 
   mozilla::RefreshDriverTimer* ChooseTimer() const;
   mozilla::RefreshDriverTimer* mActiveTimer;
 
   ProfilerBacktrace* mReflowCause;
   ProfilerBacktrace* mStyleCause;
 
-  nsPresContext *mPresContext; // weak; pres context passed in constructor
-                               // and unset in Disconnect
+  // nsPresContext passed in constructor and unset in Disconnect.
+  mozilla::WeakPtr<nsPresContext> mPresContext;
 
   RefPtr<nsRefreshDriver> mRootRefresh;
 
   // The most recently allocated transaction id.
   uint64_t mPendingTransaction;
   // The most recently completed transaction id.
   uint64_t mCompletedTransaction;