Bug 1411817: Add do_AddRef overloads for nsCOMPtr<T> and nsRevocableEventPtr<T>. r?froydnj
MozReview-Commit-ID: gEU7whtNHc
--- a/caps/nsScriptSecurityManager.cpp
+++ b/caps/nsScriptSecurityManager.cpp
@@ -1436,17 +1436,17 @@ nsScriptSecurityManager::InitStatics()
// Currently this nsGenericFactory constructor is used only from FastLoad
// (XPCOM object deserialization) code, when "creating" the system principal
// singleton.
already_AddRefed<SystemPrincipal>
nsScriptSecurityManager::SystemPrincipalSingletonConstructor()
{
if (gScriptSecMan)
- return do_AddRef(gScriptSecMan->mSystemPrincipal.get()).downcast<SystemPrincipal>();
+ return do_AddRef(gScriptSecMan->mSystemPrincipal).downcast<SystemPrincipal>();
return nullptr;
}
struct IsWhitespace {
static bool Test(char aChar) { return NS_IsAsciiWhitespace(aChar); };
};
struct IsWhitespaceOrComma {
static bool Test(char aChar) { return aChar == ',' || NS_IsAsciiWhitespace(aChar); };
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -2491,17 +2491,17 @@ nsDocument::MaybeDowngradePrincipal(nsIP
// automatically downgrade it to the last principal it subsumes (which is the
// extension principal, in the case of extension content scripts).
auto* basePrin = BasePrincipal::Cast(aPrincipal);
if (basePrin->Is<ExpandedPrincipal>()) {
auto* expanded = basePrin->As<ExpandedPrincipal>();
MOZ_ASSERT(expanded->WhiteList().Length() > 0);
- return do_AddRef(expanded->WhiteList().LastElement().get());
+ return do_AddRef(expanded->WhiteList().LastElement());
}
if (!sChromeInContentPrefCached) {
sChromeInContentPrefCached = true;
Preferences::AddBoolVarCache(&sChromeInContentAllowed,
kChromeInContentPref, false);
}
if (!sChromeInContentAllowed &&
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -139,17 +139,17 @@ nsFontCache::GetMetricsFor(const nsFont&
// It's not in the cache. Get font metrics and then cache them.
nsFontMetrics::Params params = aParams;
params.language = language;
RefPtr<nsFontMetrics> fm = new nsFontMetrics(aFont, params, mContext);
// the mFontMetrics list has the "head" at the end, because append
// is cheaper than insert
- mFontMetrics.AppendElement(do_AddRef(fm.get()).take());
+ mFontMetrics.AppendElement(do_AddRef(fm).take());
return fm.forget();
}
void
nsFontCache::UpdateUserFonts(gfxUserFontSet* aUserFontSet)
{
for (nsFontMetrics* fm : mFontMetrics) {
gfxFontGroup* fg = fm->GetThebesFontGroup();
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -12292,17 +12292,17 @@ nsCSSFrameConstructor::CreateListBoxCont
if (nullptr != aParentFrame) {
nsFrameItems frameItems;
TreeMatchContextHolder matchContext(mDocument);
nsFrameConstructorState state(mPresShell,
matchContext,
GetAbsoluteContainingBlock(aParentFrame, FIXED_POS),
GetAbsoluteContainingBlock(aParentFrame, ABS_POS),
GetFloatContainingBlock(aParentFrame),
- do_AddRef(mTempFrameTreeState.get()));
+ do_AddRef(mTempFrameTreeState));
// If we ever initialize the ancestor filter on |state|, make sure
// to push the right parent!
RefPtr<nsStyleContext> styleContext;
styleContext = ResolveStyleContext(aParentFrame, aChild, &state);
// Pre-check for display "none" - only if we find that, do we create
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -3486,17 +3486,17 @@ nsRootPresContext::CancelAllDidPaintTime
}
void
nsRootPresContext::AddWillPaintObserver(nsIRunnable* aRunnable)
{
if (!mWillPaintFallbackEvent.IsPending()) {
mWillPaintFallbackEvent = new RunWillPaintObservers(this);
Document()->Dispatch(TaskCategory::Other,
- do_AddRef(mWillPaintFallbackEvent.get()));
+ do_AddRef(mWillPaintFallbackEvent));
}
mWillPaintObservers.AppendElement(aRunnable);
}
/**
* Run all runnables that need to get called before the next paint.
*/
void
--- a/netwerk/protocol/res/ExtensionProtocolHandler.cpp
+++ b/netwerk/protocol/res/ExtensionProtocolHandler.cpp
@@ -333,17 +333,17 @@ NS_IMPL_RELEASE_INHERITED(ExtensionProto
already_AddRefed<ExtensionProtocolHandler>
ExtensionProtocolHandler::GetSingleton()
{
if (!sSingleton) {
sSingleton = new ExtensionProtocolHandler();
ClearOnShutdown(&sSingleton);
}
- return do_AddRef(sSingleton.get());
+ return do_AddRef(sSingleton);
}
ExtensionProtocolHandler::ExtensionProtocolHandler()
: SubstitutingProtocolHandler(EXTENSION_SCHEME)
#if !defined(XP_WIN)
#if defined(XP_MACOSX)
, mAlreadyCheckedDevRepo(false)
#endif /* XP_MACOSX */
--- a/toolkit/components/extensions/webrequest/StreamFilterParent.cpp
+++ b/toolkit/components/extensions/webrequest/StreamFilterParent.cpp
@@ -40,17 +40,17 @@ class ChannelEventWrapper : public Chann
{
public:
ChannelEventWrapper(nsIEventTarget* aTarget)
: mTarget(aTarget)
{}
already_AddRefed<nsIEventTarget> GetEventTarget() override
{
- return do_AddRef(mTarget.get());
+ return do_AddRef(mTarget);
}
protected:
~ChannelEventWrapper() override = default;
private:
nsCOMPtr<nsIEventTarget> mTarget;
};
--- a/xpcom/base/nsCOMPtr.h
+++ b/xpcom/base/nsCOMPtr.h
@@ -1544,9 +1544,17 @@ RefPtr<T>::operator=(const nsCOMPtr_help
void* newRawPtr;
if (NS_FAILED(aHelper(NS_GET_TEMPLATE_IID(T), &newRawPtr))) {
newRawPtr = nullptr;
}
assign_assuming_AddRef(static_cast<T*>(newRawPtr));
return *this;
}
+template <class T>
+inline already_AddRefed<T>
+do_AddRef(const nsCOMPtr<T>& aObj)
+{
+ nsCOMPtr<T> ref(aObj);
+ return ref.forget();
+}
+
#endif // !defined(nsCOMPtr_h___)
--- a/xpcom/threads/Scheduler.cpp
+++ b/xpcom/threads/Scheduler.cpp
@@ -322,24 +322,24 @@ SchedulerEventQueue::SetScheduler(Schedu
MutexAutoLock lock(mLock);
mScheduler = aScheduler;
}
already_AddRefed<nsIThreadObserver>
SchedulerEventQueue::GetObserver()
{
MutexAutoLock lock(mLock);
- return do_AddRef(mObserver.get());
+ return do_AddRef(mObserver);
}
already_AddRefed<nsIThreadObserver>
SchedulerEventQueue::GetObserverOnThread()
{
MOZ_ASSERT(NS_IsMainThread());
- return do_AddRef(mObserver.get());
+ return do_AddRef(mObserver);
}
void
SchedulerEventQueue::SetObserver(nsIThreadObserver* aObserver)
{
MutexAutoLock lock(mLock);
mObserver = aObserver;
}
--- a/xpcom/threads/ThreadEventQueue.cpp
+++ b/xpcom/threads/ThreadEventQueue.cpp
@@ -244,24 +244,24 @@ ThreadEventQueue<InnerQueueT>::PopEventQ
mNestedQueues.RemoveElementAt(mNestedQueues.Length() - 1);
}
template<class InnerQueueT>
already_AddRefed<nsIThreadObserver>
ThreadEventQueue<InnerQueueT>::GetObserver()
{
MutexAutoLock lock(mLock);
- return do_AddRef(mObserver.get());
+ return do_AddRef(mObserver);
}
template<class InnerQueueT>
already_AddRefed<nsIThreadObserver>
ThreadEventQueue<InnerQueueT>::GetObserverOnThread()
{
- return do_AddRef(mObserver.get());
+ return do_AddRef(mObserver);
}
template<class InnerQueueT>
void
ThreadEventQueue<InnerQueueT>::SetObserver(nsIThreadObserver* aObserver)
{
MutexAutoLock lock(mLock);
mObserver = aObserver;
--- a/xpcom/threads/nsThreadUtils.h
+++ b/xpcom/threads/nsThreadUtils.h
@@ -1627,16 +1627,23 @@ public:
private:
// Not implemented
nsRevocableEventPtr(const nsRevocableEventPtr&);
nsRevocableEventPtr& operator=(const nsRevocableEventPtr&);
RefPtr<T> mEvent;
};
+template <class T>
+inline already_AddRefed<T>
+do_AddRef(nsRevocableEventPtr<T>& aObj)
+{
+ return do_AddRef(aObj.get());
+}
+
/**
* A simple helper to suffix thread pool name
* with incremental numbers.
*/
class nsThreadPoolNaming
{
public:
nsThreadPoolNaming() : mCounter(0) {}