2014-06-30 15:39:45 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2004-11-15 20:16:52 +00:00
|
|
|
|
|
|
|
#include "nsInterfaceRequestorAgg.h"
|
2013-09-19 18:29:31 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2004-11-15 20:16:52 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2012-06-05 23:51:58 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-11-14 16:00:44 +00:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsProxyRelease.h"
|
2004-11-15 20:16:52 +00:00
|
|
|
|
2012-06-05 23:51:58 +00:00
|
|
|
class nsInterfaceRequestorAgg MOZ_FINAL : public nsIInterfaceRequestor
|
2004-11-15 20:16:52 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-07-19 02:31:26 +00:00
|
|
|
// XXX This needs to support threadsafe refcounting until we fix bug 243591.
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2004-11-15 20:16:52 +00:00
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
|
2014-05-13 17:41:38 +00:00
|
|
|
nsInterfaceRequestorAgg(nsIInterfaceRequestor* aFirst,
|
|
|
|
nsIInterfaceRequestor* aSecond,
|
|
|
|
nsIEventTarget* aConsumerTarget = nullptr)
|
2004-11-15 20:16:52 +00:00
|
|
|
: mFirst(aFirst)
|
2012-11-14 16:00:44 +00:00
|
|
|
, mSecond(aSecond)
|
|
|
|
, mConsumerTarget(aConsumerTarget)
|
|
|
|
{
|
|
|
|
if (!mConsumerTarget) {
|
|
|
|
mConsumerTarget = NS_GetCurrentThread();
|
|
|
|
}
|
|
|
|
}
|
2014-06-30 22:11:53 +00:00
|
|
|
|
2014-06-30 22:50:19 +00:00
|
|
|
private:
|
2014-06-30 22:11:53 +00:00
|
|
|
~nsInterfaceRequestorAgg();
|
|
|
|
|
2004-11-15 20:16:52 +00:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mFirst, mSecond;
|
2012-11-14 16:00:44 +00:00
|
|
|
nsCOMPtr<nsIEventTarget> mConsumerTarget;
|
2004-11-15 20:16:52 +00:00
|
|
|
};
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsInterfaceRequestorAgg, nsIInterfaceRequestor)
|
2004-11-15 20:16:52 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-13 17:41:38 +00:00
|
|
|
nsInterfaceRequestorAgg::GetInterface(const nsIID& aIID, void** aResult)
|
2004-11-15 20:16:52 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_NO_INTERFACE;
|
2014-05-13 17:41:38 +00:00
|
|
|
if (mFirst) {
|
2004-11-15 20:16:52 +00:00
|
|
|
rv = mFirst->GetInterface(aIID, aResult);
|
2014-05-13 17:41:38 +00:00
|
|
|
}
|
|
|
|
if (mSecond && NS_FAILED(rv)) {
|
2004-11-15 20:16:52 +00:00
|
|
|
rv = mSecond->GetInterface(aIID, aResult);
|
2014-05-13 17:41:38 +00:00
|
|
|
}
|
2004-11-15 20:16:52 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-11-14 16:00:44 +00:00
|
|
|
nsInterfaceRequestorAgg::~nsInterfaceRequestorAgg()
|
|
|
|
{
|
|
|
|
nsIInterfaceRequestor* iir = nullptr;
|
|
|
|
mFirst.swap(iir);
|
|
|
|
if (iir) {
|
|
|
|
NS_ProxyRelease(mConsumerTarget, iir);
|
|
|
|
}
|
|
|
|
iir = nullptr;
|
|
|
|
mSecond.swap(iir);
|
|
|
|
if (iir) {
|
|
|
|
NS_ProxyRelease(mConsumerTarget, iir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-15 20:16:52 +00:00
|
|
|
nsresult
|
2014-05-13 17:41:38 +00:00
|
|
|
NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor* aFirst,
|
|
|
|
nsIInterfaceRequestor* aSecond,
|
|
|
|
nsIInterfaceRequestor** aResult)
|
2004-11-15 20:16:52 +00:00
|
|
|
{
|
|
|
|
*aResult = new nsInterfaceRequestorAgg(aFirst, aSecond);
|
2014-05-13 17:41:38 +00:00
|
|
|
if (!*aResult) {
|
2004-11-15 20:16:52 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2014-05-13 17:41:38 +00:00
|
|
|
}
|
2004-11-15 20:16:52 +00:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-11-14 16:00:44 +00:00
|
|
|
|
|
|
|
nsresult
|
2014-05-13 17:41:38 +00:00
|
|
|
NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor* aFirst,
|
|
|
|
nsIInterfaceRequestor* aSecond,
|
2012-11-14 16:00:44 +00:00
|
|
|
nsIEventTarget* aTarget,
|
2014-05-13 17:41:38 +00:00
|
|
|
nsIInterfaceRequestor** aResult)
|
2012-11-14 16:00:44 +00:00
|
|
|
{
|
|
|
|
*aResult = new nsInterfaceRequestorAgg(aFirst, aSecond, aTarget);
|
2014-05-13 17:41:38 +00:00
|
|
|
if (!*aResult) {
|
2012-11-14 16:00:44 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2014-05-13 17:41:38 +00:00
|
|
|
}
|
2012-11-14 16:00:44 +00:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|