diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index 39192c1ae834c4..ab1eb3b29a994e 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -1933,7 +1933,8 @@ nsresult BrowsingContext::LoadURI(nsDocShellLoadState* aLoadState, aLoadState->AssertProcessCouldTriggerLoadIfSystem(); if (mDocShell) { - return mDocShell->LoadURI(aLoadState, aSetNavigating); + nsCOMPtr docShell = mDocShell; + return docShell->LoadURI(aLoadState, aSetNavigating); } // Note: We do this check both here and in `nsDocShell::InternalLoad`, since @@ -2030,7 +2031,8 @@ nsresult BrowsingContext::InternalLoad(nsDocShellLoadState* aLoadState) { aLoadState->AssertProcessCouldTriggerLoadIfSystem(); if (mDocShell) { - return nsDocShell::Cast(mDocShell)->InternalLoad(aLoadState); + RefPtr docShell = nsDocShell::Cast(mDocShell); + return docShell->InternalLoad(aLoadState); } // Note: We do this check both here and in `nsDocShell::InternalLoad`, since @@ -2092,9 +2094,10 @@ void BrowsingContext::DisplayLoadError(const nsAString& aURI) { if (mDocShell) { bool didDisplayLoadError = false; - mDocShell->DisplayLoadError(NS_ERROR_MALFORMED_URI, nullptr, - PromiseFlatString(aURI).get(), nullptr, - &didDisplayLoadError); + nsCOMPtr docShell = mDocShell; + docShell->DisplayLoadError(NS_ERROR_MALFORMED_URI, nullptr, + PromiseFlatString(aURI).get(), nullptr, + &didDisplayLoadError); } else { if (ContentParent* cp = Canonical()->GetContentParent()) { Unused << cp->SendDisplayLoadError(this, PromiseFlatString(aURI)); @@ -3681,7 +3684,8 @@ void BrowsingContext::HistoryGo( [](mozilla::ipc:: ResponseRejectReason) { /* FIXME Is ignoring this fine? */ }); } else { - aResolver(Canonical()->HistoryGo( + RefPtr self = Canonical(); + aResolver(self->HistoryGo( aOffset, aHistoryEpoch, aRequireUserInteraction, aUserActivation, Canonical()->GetContentParent() ? Some(Canonical()->GetContentParent()->ChildID()) diff --git a/docshell/base/CanonicalBrowsingContext.cpp b/docshell/base/CanonicalBrowsingContext.cpp index fbf4aee1749cf2..2f383a90e6600e 100644 --- a/docshell/base/CanonicalBrowsingContext.cpp +++ b/docshell/base/CanonicalBrowsingContext.cpp @@ -1502,7 +1502,7 @@ void CanonicalBrowsingContext::GoBack( mCurrentLoad->Cancel(NS_BINDING_CANCELLED_OLD_LOAD, ""_ns); } - if (nsDocShell* docShell = nsDocShell::Cast(GetDocShell())) { + if (RefPtr docShell = nsDocShell::Cast(GetDocShell())) { if (aCancelContentJSEpoch.WasPassed()) { docShell->SetCancelContentJSEpoch(aCancelContentJSEpoch.Value()); } @@ -1528,7 +1528,7 @@ void CanonicalBrowsingContext::GoForward( mCurrentLoad->Cancel(NS_BINDING_CANCELLED_OLD_LOAD, ""_ns); } - if (auto* docShell = nsDocShell::Cast(GetDocShell())) { + if (RefPtr docShell = nsDocShell::Cast(GetDocShell())) { if (aCancelContentJSEpoch.WasPassed()) { docShell->SetCancelContentJSEpoch(aCancelContentJSEpoch.Value()); } @@ -1554,7 +1554,7 @@ void CanonicalBrowsingContext::GoToIndex( mCurrentLoad->Cancel(NS_BINDING_CANCELLED_OLD_LOAD, ""_ns); } - if (auto* docShell = nsDocShell::Cast(GetDocShell())) { + if (RefPtr docShell = nsDocShell::Cast(GetDocShell())) { if (aCancelContentJSEpoch.WasPassed()) { docShell->SetCancelContentJSEpoch(aCancelContentJSEpoch.Value()); } @@ -1578,7 +1578,7 @@ void CanonicalBrowsingContext::Reload(uint32_t aReloadFlags) { mCurrentLoad->Cancel(NS_BINDING_CANCELLED_OLD_LOAD, ""_ns); } - if (auto* docShell = nsDocShell::Cast(GetDocShell())) { + if (RefPtr docShell = nsDocShell::Cast(GetDocShell())) { docShell->Reload(aReloadFlags); } else if (ContentParent* cp = GetContentParent()) { Unused << cp->SendReload(this, aReloadFlags); diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 543fa3af44aa81..c9b766430614e7 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -784,7 +784,8 @@ nsresult nsDocShell::LoadURI(nsDocShellLoadState* aLoadState, ("nsDocShell[%p]: loading from session history", this)); if (!mozilla::SessionHistoryInParent()) { - return LoadHistoryEntry(aLoadState->SHEntry(), aLoadState->LoadType(), + nsCOMPtr entry = aLoadState->SHEntry(); + return LoadHistoryEntry(entry, aLoadState->LoadType(), aLoadState->HasValidUserGestureActivation()); } @@ -4130,8 +4131,11 @@ nsDocShell::Reload(uint32_t aReloadFlags) { } else { MOZ_LOG(gSHLog, LogLevel::Debug, ("nsDocShell %p ReloadDocument", this)); - ReloadDocument(this, GetDocument(), loadType, mBrowsingContext, - mCurrentURI, mReferrerInfo); + RefPtr doc = GetDocument(); + RefPtr bc = mBrowsingContext; + nsCOMPtr currentURI = mCurrentURI; + nsCOMPtr referrerInfo = mReferrerInfo; + ReloadDocument(this, doc, loadType, bc, currentURI, referrerInfo); } } } @@ -4149,19 +4153,24 @@ nsDocShell::Reload(uint32_t aReloadFlags) { /* If you change this part of code, make sure bug 45297 does not re-occur */ if (mOSHE) { + nsCOMPtr oshe = mOSHE; return LoadHistoryEntry( - mOSHE, loadType, + oshe, loadType, aReloadFlags & nsIWebNavigation::LOAD_FLAGS_USER_ACTIVATION); } if (mLSHE) { // In case a reload happened before the current load is done + nsCOMPtr lshe = mLSHE; return LoadHistoryEntry( - mLSHE, loadType, + lshe, loadType, aReloadFlags & nsIWebNavigation::LOAD_FLAGS_USER_ACTIVATION); } - return ReloadDocument(this, GetDocument(), loadType, mBrowsingContext, - mCurrentURI, mReferrerInfo); + RefPtr doc = GetDocument(); + RefPtr bc = mBrowsingContext; + nsCOMPtr currentURI = mCurrentURI; + nsCOMPtr referrerInfo = mReferrerInfo; + return ReloadDocument(this, doc, loadType, bc, currentURI, referrerInfo); } /* static */ @@ -9670,7 +9679,8 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState, if (NS_FAILED(rv)) { nsCOMPtr chan(do_QueryInterface(req)); UnblockEmbedderLoadEventForFailure(); - if (DisplayLoadError(rv, aLoadState->URI(), nullptr, chan) && + nsCOMPtr uri = aLoadState->URI(); + if (DisplayLoadError(rv, uri, nullptr, chan) && // FIXME: At this point code was using internal load flags, but checking // non-internal load flags? aLoadState->HasLoadFlags(LOAD_FLAGS_ERROR_LOAD_CHANGES_RV)) { diff --git a/docshell/base/nsDocShellTreeOwner.cpp b/docshell/base/nsDocShellTreeOwner.cpp index c9109f5f37048a..fd0ef1828fad93 100644 --- a/docshell/base/nsDocShellTreeOwner.cpp +++ b/docshell/base/nsDocShellTreeOwner.cpp @@ -930,7 +930,8 @@ nsDocShellTreeOwner::HandleEvent(Event* aEvent) { asWidgetDropEvent->mCurrentTarget); } } else if (eventType.EqualsLiteral("drop")) { - nsIWebNavigation* webnav = static_cast(mWebBrowser); + nsCOMPtr webnav = + static_cast(mWebBrowser); // The page might have cancelled the dragover event itself, so check to // make sure that the link can be dropped first. diff --git a/docshell/shistory/ChildSHistory.cpp b/docshell/shistory/ChildSHistory.cpp index 85708d6278c552..87b6a7b3fc4b03 100644 --- a/docshell/shistory/ChildSHistory.cpp +++ b/docshell/shistory/ChildSHistory.cpp @@ -108,7 +108,7 @@ void ChildSHistory::SetIndexAndLength(uint32_t aIndex, uint32_t aLength, void ChildSHistory::Reload(uint32_t aReloadFlags, ErrorResult& aRv) { if (mozilla::SessionHistoryInParent()) { if (XRE_IsParentProcess()) { - nsISHistory* shistory = + nsCOMPtr shistory = mBrowsingContext->Canonical()->GetSessionHistory(); if (shistory) { aRv = shistory->Reload(aReloadFlags); @@ -120,7 +120,8 @@ void ChildSHistory::Reload(uint32_t aReloadFlags, ErrorResult& aRv) { return; } - aRv = mHistory->Reload(aReloadFlags); + nsCOMPtr shistory = mHistory; + aRv = shistory->Reload(aReloadFlags); } bool ChildSHistory::CanGo(int32_t aOffset) { @@ -207,7 +208,8 @@ void ChildSHistory::GotoIndex(int32_t aIndex, int32_t aOffset, } nsCOMPtr shistory = mHistory; - mBrowsingContext->HistoryGo( + RefPtr bc = mBrowsingContext; + bc->HistoryGo( aOffset, mHistoryEpoch, aRequireUserInteraction, aUserActivation, [shistory](Maybe&& aRequestedIndex) { // FIXME Should probably only do this for non-fission. @@ -216,7 +218,8 @@ void ChildSHistory::GotoIndex(int32_t aIndex, int32_t aOffset, } }); } else { - aRv = mHistory->GotoIndex(aIndex, aUserActivation); + nsCOMPtr shistory = mHistory; + aRv = shistory->GotoIndex(aIndex, aUserActivation); } } diff --git a/docshell/shistory/nsSHistory.cpp b/docshell/shistory/nsSHistory.cpp index 740b636e1166b2..f781820586d368 100644 --- a/docshell/shistory/nsSHistory.cpp +++ b/docshell/shistory/nsSHistory.cpp @@ -1398,7 +1398,9 @@ void nsSHistory::LoadURIOrBFCache(LoadEntryResult& aLoadEntry) { } } - aLoadEntry.mBrowsingContext->LoadURI(aLoadEntry.mLoadState, false); + RefPtr bc = aLoadEntry.mBrowsingContext; + RefPtr loadState = aLoadEntry.mLoadState; + bc->LoadURI(loadState, false); } /* static */ diff --git a/dom/base/Location.cpp b/dom/base/Location.cpp index 6b488991204bd0..06b104a0cba0cd 100644 --- a/dom/base/Location.cpp +++ b/dom/base/Location.cpp @@ -544,7 +544,7 @@ void Location::Reload(bool aForceget, nsIPrincipal& aSubjectPrincipal, return; } - nsCOMPtr docShell(GetDocShell()); + RefPtr docShell(GetDocShell().downcast()); if (!docShell) { return aRv.Throw(NS_ERROR_FAILURE); } @@ -591,7 +591,7 @@ void Location::Reload(bool aForceget, nsIPrincipal& aSubjectPrincipal, nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY; } - rv = nsDocShell::Cast(docShell)->Reload(reloadFlags); + rv = docShell->Reload(reloadFlags); if (NS_FAILED(rv) && rv != NS_BINDING_ABORTED) { // NS_BINDING_ABORTED is returned when we attempt to reload a POST result // and the user says no at the "do you want to reload?" prompt. Don't diff --git a/dom/base/nsFrameLoader.cpp b/dom/base/nsFrameLoader.cpp index f5b65d7d1c369d..13607d7c5f5e51 100644 --- a/dom/base/nsFrameLoader.cpp +++ b/dom/base/nsFrameLoader.cpp @@ -766,7 +766,8 @@ nsresult nsFrameLoader::ReallyStartLoadingInternal() { bool tmpState = mNeedsAsyncDestroy; mNeedsAsyncDestroy = true; - rv = GetDocShell()->LoadURI(loadState, false); + RefPtr docShell = GetDocShell(); + rv = docShell->LoadURI(loadState, false); mNeedsAsyncDestroy = tmpState; mURIToLoad = nullptr; NS_ENSURE_SUCCESS(rv, rv); diff --git a/dom/html/HTMLFormElement.cpp b/dom/html/HTMLFormElement.cpp index 544abcd8b77408..e30f1e58161ef6 100644 --- a/dom/html/HTMLFormElement.cpp +++ b/dom/html/HTMLFormElement.cpp @@ -566,7 +566,8 @@ nsresult HTMLFormElement::PostHandleEvent(EventChainPostVisitor& aVisitor) { OwnerDoc()->WarnOnceAbout( DeprecatedOperations::eFormSubmissionUntrustedEvent); } - DoSubmit(aVisitor.mDOMEvent); + RefPtr event = aVisitor.mDOMEvent; + DoSubmit(event); break; } default: @@ -762,7 +763,8 @@ nsresult HTMLFormElement::SubmitSubmission( // If there is no link handler, then we won't actually be able to submit. Document* doc = GetComposedDoc(); - nsCOMPtr container = doc ? doc->GetDocShell() : nullptr; + RefPtr container = + doc ? nsDocShell::Cast(doc->GetDocShell()) : nullptr; if (!container || IsEditable()) { return NS_OK; } @@ -807,7 +809,6 @@ nsresult HTMLFormElement::SubmitSubmission( // // Submit // - nsCOMPtr docShell; uint64_t currentLoadId = 0; { @@ -834,8 +835,8 @@ nsresult HTMLFormElement::SubmitSubmission( loadState->SetCsp(GetCsp()); loadState->SetAllowFocusMove(UserActivation::IsHandlingUserInput()); - rv = nsDocShell::Cast(container)->OnLinkClickSync(this, loadState, false, - NodePrincipal()); + nsCOMPtr nodePrincipal = NodePrincipal(); + rv = container->OnLinkClickSync(this, loadState, false, nodePrincipal); NS_ENSURE_SUBMIT_SUCCESS(rv); mTargetContext = loadState->TargetBrowsingContext().GetMaybeDiscarded(); diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index 222b47a409c6d9..9940ffd045e9dc 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -4317,7 +4317,7 @@ mozilla::ipc::IPCResult ContentChild::RecvLoadURI( if (aContext.IsNullOrDiscarded()) { return IPC_OK(); } - BrowsingContext* context = aContext.get(); + RefPtr context = aContext.get(); if (!context->IsInProcess()) { // The DocShell has been torn down or the BrowsingContext has changed // process in the middle of the load request. There's not much we can do at @@ -4363,7 +4363,7 @@ mozilla::ipc::IPCResult ContentChild::RecvInternalLoad( if (aLoadState->TargetBrowsingContext().IsDiscarded()) { return IPC_OK(); } - BrowsingContext* context = aLoadState->TargetBrowsingContext().get(); + RefPtr context = aLoadState->TargetBrowsingContext().get(); context->InternalLoad(aLoadState); @@ -4393,7 +4393,7 @@ mozilla::ipc::IPCResult ContentChild::RecvDisplayLoadError( if (aContext.IsNullOrDiscarded()) { return IPC_OK(); } - BrowsingContext* context = aContext.get(); + RefPtr context = aContext.get(); context->DisplayLoadError(aURI); @@ -4506,7 +4506,7 @@ mozilla::ipc::IPCResult ContentChild::RecvGoBack( } BrowsingContext* bc = aContext.get(); - if (auto* docShell = nsDocShell::Cast(bc->GetDocShell())) { + if (RefPtr docShell = nsDocShell::Cast(bc->GetDocShell())) { if (aCancelContentJSEpoch) { docShell->SetCancelContentJSEpoch(*aCancelContentJSEpoch); } @@ -4529,7 +4529,7 @@ mozilla::ipc::IPCResult ContentChild::RecvGoForward( } BrowsingContext* bc = aContext.get(); - if (auto* docShell = nsDocShell::Cast(bc->GetDocShell())) { + if (RefPtr docShell = nsDocShell::Cast(bc->GetDocShell())) { if (aCancelContentJSEpoch) { docShell->SetCancelContentJSEpoch(*aCancelContentJSEpoch); } @@ -4551,7 +4551,7 @@ mozilla::ipc::IPCResult ContentChild::RecvGoToIndex( } BrowsingContext* bc = aContext.get(); - if (auto* docShell = nsDocShell::Cast(bc->GetDocShell())) { + if (RefPtr docShell = nsDocShell::Cast(bc->GetDocShell())) { if (aCancelContentJSEpoch) { docShell->SetCancelContentJSEpoch(*aCancelContentJSEpoch); } @@ -4573,7 +4573,7 @@ mozilla::ipc::IPCResult ContentChild::RecvReload( } BrowsingContext* bc = aContext.get(); - if (auto* docShell = nsDocShell::Cast(bc->GetDocShell())) { + if (RefPtr docShell = nsDocShell::Cast(bc->GetDocShell())) { docShell->Reload(aReloadFlags); } diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 84cf9d626a086e..8db930918e8975 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -7829,9 +7829,10 @@ mozilla::ipc::IPCResult ContentParent::RecvHistoryGo( uint64_t aHistoryEpoch, bool aRequireUserInteraction, bool aUserActivation, HistoryGoResolver&& aResolveRequestedIndex) { if (!aContext.IsDiscarded()) { - aResolveRequestedIndex(aContext.get_canonical()->HistoryGo( - aOffset, aHistoryEpoch, aRequireUserInteraction, aUserActivation, - Some(ChildID()))); + RefPtr canonical = aContext.get_canonical(); + aResolveRequestedIndex( + canonical->HistoryGo(aOffset, aHistoryEpoch, aRequireUserInteraction, + aUserActivation, Some(ChildID()))); } return IPC_OK(); } @@ -8054,7 +8055,8 @@ mozilla::ipc::IPCResult ContentParent::RecvHistoryReload( const MaybeDiscarded& aContext, const uint32_t aReloadFlags) { if (!aContext.IsDiscarded()) { - nsISHistory* shistory = aContext.get_canonical()->GetSessionHistory(); + nsCOMPtr shistory = + aContext.get_canonical()->GetSessionHistory(); if (shistory) { shistory->Reload(aReloadFlags); } diff --git a/dom/ipc/WindowGlobalParent.cpp b/dom/ipc/WindowGlobalParent.cpp index 7e92f9ad5641a9..78cf28ef22610d 100644 --- a/dom/ipc/WindowGlobalParent.cpp +++ b/dom/ipc/WindowGlobalParent.cpp @@ -321,7 +321,7 @@ mozilla::ipc::IPCResult WindowGlobalParent::RecvLoadURI( return IPC_FAIL(this, "Illegal cross-process javascript: load attempt"); } - CanonicalBrowsingContext* targetBC = aTargetBC.get_canonical(); + RefPtr targetBC = aTargetBC.get_canonical(); // FIXME: For cross-process loads, we should double check CanAccess() for the // source browsing context in the parent process. @@ -354,7 +354,7 @@ mozilla::ipc::IPCResult WindowGlobalParent::RecvInternalLoad( return IPC_FAIL(this, "Illegal cross-process javascript: load attempt"); } - CanonicalBrowsingContext* targetBC = + RefPtr targetBC = aLoadState->TargetBrowsingContext().get_canonical(); // FIXME: For cross-process loads, we should double check CanAccess() for the @@ -1356,7 +1356,8 @@ mozilla::ipc::IPCResult WindowGlobalParent::RecvReloadWithHttpsOnlyException() { loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal()); loadState->SetLoadType(LOAD_NORMAL_REPLACE); - BrowsingContext()->Top()->LoadURI(loadState, /* setNavigating */ true); + RefPtr topBC = BrowsingContext()->Top(); + topBC->LoadURI(loadState, /* setNavigating */ true); return IPC_OK(); } diff --git a/dom/l10n/DocumentL10n.cpp b/dom/l10n/DocumentL10n.cpp index b25a6d0fce4b6e..828a0583e3bbdf 100644 --- a/dom/l10n/DocumentL10n.cpp +++ b/dom/l10n/DocumentL10n.cpp @@ -318,12 +318,13 @@ void DocumentL10n::InitialTranslationCompleted(bool aL10nCached) { MaybeRecordTelemetry(); - mDocument->InitialTranslationCompleted(aL10nCached); + RefPtr doc = mDocument; + doc->InitialTranslationCompleted(aL10nCached); // In XUL scenario contentSink is nullptr. if (mContentSink) { - mContentSink->InitialTranslationCompleted(); - mContentSink = nullptr; + nsCOMPtr sink = mContentSink.forget(); + sink->InitialTranslationCompleted(); } // From now on, the state of Localization is unconditionally diff --git a/dom/prototype/PrototypeDocumentContentSink.cpp b/dom/prototype/PrototypeDocumentContentSink.cpp index fe07fbb882cd8e..b479f38e22e141 100644 --- a/dom/prototype/PrototypeDocumentContentSink.cpp +++ b/dom/prototype/PrototypeDocumentContentSink.cpp @@ -675,14 +675,15 @@ nsresult PrototypeDocumentContentSink::DoneWalking() { } mDocument->SetDelayFrameLoaderInitialization(false); - mDocument->MaybeInitializeFinalizeFrameLoaders(); + RefPtr doc = mDocument; + doc->MaybeInitializeFinalizeFrameLoaders(); // If the document we are loading has a reference or it is a // frameset document, disable the scroll bars on the views. - mDocument->SetScrollToRef(mDocument->GetDocumentURI()); + doc->SetScrollToRef(mDocument->GetDocumentURI()); - mDocument->EndLoad(); + doc->EndLoad(); return NS_OK; } diff --git a/netwerk/ipc/DocumentLoadListener.cpp b/netwerk/ipc/DocumentLoadListener.cpp index ec5bb1e35b0bff..d721aa16fa020d 100644 --- a/netwerk/ipc/DocumentLoadListener.cpp +++ b/netwerk/ipc/DocumentLoadListener.cpp @@ -2340,7 +2340,7 @@ bool DocumentLoadListener::DocShellWillDisplayContent(nsresult aStatus) { } bool DocumentLoadListener::MaybeHandleLoadErrorWithURIFixup(nsresult aStatus) { - auto* bc = GetDocumentBrowsingContext(); + RefPtr bc = GetDocumentBrowsingContext(); if (!bc) { return false; } diff --git a/parser/html/nsHtml5TreeOpExecutor.cpp b/parser/html/nsHtml5TreeOpExecutor.cpp index 86302592900dba..177fbd0a496bac 100644 --- a/parser/html/nsHtml5TreeOpExecutor.cpp +++ b/parser/html/nsHtml5TreeOpExecutor.cpp @@ -996,7 +996,7 @@ void nsHtml5TreeOpExecutor::NeedsCharsetSwitchTo( return; } - nsDocShell* docShell = static_cast(mDocShell.get()); + RefPtr docShell = static_cast(mDocShell.get()); if (NS_SUCCEEDED(docShell->CharsetChangeStopDocumentLoad())) { docShell->CharsetChangeReloadDocument(aEncoding, aSource); diff --git a/parser/prototype/PrototypeDocumentParser.cpp b/parser/prototype/PrototypeDocumentParser.cpp index edeb3ed7f13110..c07a35b892d0f7 100644 --- a/parser/prototype/PrototypeDocumentParser.cpp +++ b/parser/prototype/PrototypeDocumentParser.cpp @@ -8,6 +8,7 @@ #include "nsXULPrototypeCache.h" #include "nsXULContentSink.h" +#include "nsXULPrototypeDocument.h" #include "mozilla/Encoding.h" #include "nsCharsetSource.h" #include "nsParser.h" @@ -161,7 +162,9 @@ nsresult PrototypeDocumentParser::OnPrototypeLoadDone() { MOZ_ASSERT(!mIsComplete, "Should not be called more than once."); mIsComplete = true; - return mOriginalSink->OnPrototypeLoadDone(mCurrentPrototype); + RefPtr sink = mOriginalSink; + RefPtr prototype = mCurrentPrototype; + return sink->OnPrototypeLoadDone(prototype); } nsresult PrototypeDocumentParser::PrepareToLoadPrototype( diff --git a/toolkit/components/browser/nsWebBrowser.cpp b/toolkit/components/browser/nsWebBrowser.cpp index 6708d2bda95160..53ed9eb1a4537e 100644 --- a/toolkit/components/browser/nsWebBrowser.cpp +++ b/toolkit/components/browser/nsWebBrowser.cpp @@ -459,14 +459,16 @@ NS_IMETHODIMP nsWebBrowser::GoBack(bool aRequireUserInteraction, bool aUserActivation) { NS_ENSURE_STATE(mDocShell); - return mDocShell->GoBack(aRequireUserInteraction, aUserActivation); + RefPtr docShell = mDocShell; + return docShell->GoBack(aRequireUserInteraction, aUserActivation); } NS_IMETHODIMP nsWebBrowser::GoForward(bool aRequireUserInteraction, bool aUserActivation) { NS_ENSURE_STATE(mDocShell); - return mDocShell->GoForward(aRequireUserInteraction, aUserActivation); + RefPtr docShell = mDocShell; + return docShell->GoForward(aRequireUserInteraction, aUserActivation); } nsresult nsWebBrowser::LoadURI(nsIURI* aURI, @@ -477,7 +479,8 @@ nsresult nsWebBrowser::LoadURI(nsIURI* aURI, #endif NS_ENSURE_STATE(mDocShell); - return mDocShell->LoadURI(aURI, aLoadURIOptions); + RefPtr docShell = mDocShell; + return docShell->LoadURI(aURI, aLoadURIOptions); } NS_IMETHODIMP @@ -501,7 +504,8 @@ nsresult nsWebBrowser::FixupAndLoadURIString( #endif NS_ENSURE_STATE(mDocShell); - return mDocShell->FixupAndLoadURIString(aURI, aLoadURIOptions); + RefPtr docShell = mDocShell; + return docShell->FixupAndLoadURIString(aURI, aLoadURIOptions); } NS_IMETHODIMP @@ -528,14 +532,16 @@ NS_IMETHODIMP nsWebBrowser::Reload(uint32_t aReloadFlags) { NS_ENSURE_STATE(mDocShell); - return mDocShell->Reload(aReloadFlags); + RefPtr docShell = mDocShell; + return docShell->Reload(aReloadFlags); } NS_IMETHODIMP nsWebBrowser::GotoIndex(int32_t aIndex, bool aUserActivation) { NS_ENSURE_STATE(mDocShell); - return mDocShell->GotoIndex(aIndex, aUserActivation); + RefPtr docShell = mDocShell; + return docShell->GotoIndex(aIndex, aUserActivation); } NS_IMETHODIMP diff --git a/toolkit/components/sessionstore/SessionStoreUtils.cpp b/toolkit/components/sessionstore/SessionStoreUtils.cpp index 43fd9ed2af57b7..19f28995b546cc 100644 --- a/toolkit/components/sessionstore/SessionStoreUtils.cpp +++ b/toolkit/components/sessionstore/SessionStoreUtils.cpp @@ -1666,8 +1666,9 @@ already_AddRefed SessionStoreUtils::InitializeRestore( return nullptr; } - MOZ_DIAGNOSTIC_ASSERT(aContext.GetSessionHistory()); - aContext.GetSessionHistory()->ReloadCurrentEntry(); + nsCOMPtr shistory = aContext.GetSessionHistory(); + MOZ_DIAGNOSTIC_ASSERT(shistory); + shistory->ReloadCurrentEntry(); return aContext.GetRestorePromise(); } diff --git a/xpfe/appshell/nsAppShellService.cpp b/xpfe/appshell/nsAppShellService.cpp index ae9bef147db678..d174144e52e657 100644 --- a/xpfe/appshell/nsAppShellService.cpp +++ b/xpfe/appshell/nsAppShellService.cpp @@ -685,7 +685,7 @@ nsresult nsAppShellService::JustCreateTopWindow( isPrivateBrowsingWindow = parentContext->UsePrivateBrowsing(); } - if (nsDocShell* docShell = window->GetDocShell()) { + if (RefPtr docShell = window->GetDocShell()) { MOZ_ASSERT(docShell->GetBrowsingContext()->IsChrome()); docShell->SetPrivateBrowsing(isPrivateBrowsingWindow);