diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 906463221721..7c331730d0a5 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -316,7 +316,6 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext) mForcedCharset(nullptr), mParentCharset(nullptr), mTreeOwner(nullptr), - mChromeEventHandler(nullptr), mDefaultScrollbarPref(Scrollbar_Auto, Scrollbar_Auto), mCharsetReloadState(eCharsetReloadInit), mOrientationLock(hal::eScreenOrientation_None), @@ -541,7 +540,7 @@ void nsDocShell::DestroyChildren() { NS_IMPL_CYCLE_COLLECTION_INHERITED(nsDocShell, nsDocLoader, mSessionStorageManager, mScriptGlobal, mInitialClientSource, mSessionHistory, - mBrowsingContext) + mBrowsingContext, mChromeEventHandler) NS_IMPL_ADDREF_INHERITED(nsDocShell, nsDocLoader) NS_IMPL_RELEASE_INHERITED(nsDocShell, nsDocLoader) @@ -1141,7 +1140,6 @@ nsDocShell::GetOuterWindowID(uint64_t* aWindowID) { NS_IMETHODIMP nsDocShell::SetChromeEventHandler(EventTarget* aChromeEventHandler) { - // Weak reference. Don't addref. mChromeEventHandler = aChromeEventHandler; if (mScriptGlobal) { @@ -1154,7 +1152,7 @@ nsDocShell::SetChromeEventHandler(EventTarget* aChromeEventHandler) { NS_IMETHODIMP nsDocShell::GetChromeEventHandler(EventTarget** aChromeEventHandler) { NS_ENSURE_ARG_POINTER(aChromeEventHandler); - nsCOMPtr handler = mChromeEventHandler; + RefPtr handler = mChromeEventHandler; handler.forget(aChromeEventHandler); return NS_OK; } @@ -4199,7 +4197,7 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI, errorPage.AssignLiteral("tabcrashed"); error = "tabcrashed"; - nsCOMPtr handler = mChromeEventHandler; + RefPtr handler = mChromeEventHandler; if (handler) { nsCOMPtr element = do_QueryInterface(handler); element->GetAttribute(NS_LITERAL_STRING("crashedPageTitle"), messageStr); @@ -4993,6 +4991,8 @@ nsDocShell::Destroy() { mTabChild = nullptr; + mChromeEventHandler = nullptr; + mOnePermittedSandboxedNavigator = nullptr; // required to break ref cycle diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 9c29c42546d8..802a85cb5298 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -1036,8 +1036,9 @@ class nsDocShell final : public nsDocLoader, // Note these are intentionally not addrefd. Doing so will create a cycle. // For that reasons don't use nsCOMPtr. - nsIDocShellTreeOwner* mTreeOwner; // Weak Reference - mozilla::dom::EventTarget* mChromeEventHandler; // Weak Reference + nsIDocShellTreeOwner* mTreeOwner; // Weak Reference + + RefPtr mChromeEventHandler; nsIntPoint mDefaultScrollbarPref; // persistent across doc loads