Bug 1097094 - Keep a WeakPtr to nsDocShell in SectionCarets. r=roc

When SelectionCarets::Terminate() is called, it's not guaranteed that we
can get nsDocShell from PresContext. It causes that SelectionCarets
cannot remove itself as an observer.

To fix this, we keep a member WeakPtr<nsDocShell> so that we can always
have nsDocShell in SelectionCarets::Terminate().
This commit is contained in:
Ting-Yu Lin 2014-11-13 08:32:00 -05:00
parent ca0f216c74
commit 4e6fe284fc
2 changed files with 7 additions and 4 deletions

View File

@ -13,6 +13,7 @@
#include "nsCaret.h"
#include "nsContentUtils.h"
#include "nsDebug.h"
#include "nsDocShell.h"
#include "nsDOMTokenList.h"
#include "nsFocusManager.h"
#include "nsFrame.h"
@ -124,6 +125,8 @@ SelectionCarets::Init()
docShell->AddWeakReflowObserver(this);
docShell->AddWeakScrollObserver(this);
mDocShell = static_cast<nsDocShell*>(docShell);
}
SelectionCarets::~SelectionCarets()
@ -147,10 +150,7 @@ SelectionCarets::~SelectionCarets()
void
SelectionCarets::Terminate()
{
nsPresContext* presContext = mPresShell->GetPresContext();
MOZ_ASSERT(presContext, "PresContext should be given in PresShell::Init()");
nsIDocShell* docShell = presContext->GetDocShell();
nsRefPtr<nsDocShell> docShell(mDocShell.get());
if (docShell) {
docShell->RemoveWeakReflowObserver(this);
docShell->RemoveWeakScrollObserver(this);

View File

@ -14,8 +14,10 @@
#include "nsWeakReference.h"
#include "Units.h"
#include "mozilla/EventForwards.h"
#include "mozilla/WeakPtr.h"
class nsCanvasFrame;
class nsDocShell;
class nsFrameSelection;
class nsIContent;
class nsIDocument;
@ -209,6 +211,7 @@ private:
static void FireScrollEnd(nsITimer* aTimer, void* aSelectionCarets);
nsIPresShell* mPresShell;
WeakPtr<nsDocShell> mDocShell;
// This timer is used for detecting long tap fire. If content process
// has APZC, we'll use APZC for long tap detecting. Otherwise, we use this