2014-06-30 19:39:45 +04: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 15:12:37 +04: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 23:16:52 +03:00
|
|
|
|
|
|
|
#include "nsInterfaceRequestorAgg.h"
|
2013-09-19 22:29:31 +04:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2004-11-15 23:16:52 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2012-06-06 03:51:58 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-11-14 20:00:44 +04:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsProxyRelease.h"
|
2004-11-15 23:16:52 +03:00
|
|
|
|
2012-06-06 03:51:58 +04:00
|
|
|
class nsInterfaceRequestorAgg MOZ_FINAL : public nsIInterfaceRequestor
|
2004-11-15 23:16:52 +03:00
|
|
|
{
|
|
|
|
public:
|
2013-07-19 06:31:26 +04:00
|
|
|
// XXX This needs to support threadsafe refcounting until we fix bug 243591.
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2004-11-15 23:16:52 +03:00
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
nsInterfaceRequestorAgg(nsIInterfaceRequestor* aFirst,
|
|
|
|
nsIInterfaceRequestor* aSecond,
|
|
|
|
nsIEventTarget* aConsumerTarget = nullptr)
|
2004-11-15 23:16:52 +03:00
|
|
|
: mFirst(aFirst)
|
2012-11-14 20:00:44 +04:00
|
|
|
, mSecond(aSecond)
|
|
|
|
, mConsumerTarget(aConsumerTarget)
|
|
|
|
{
|
|
|
|
if (!mConsumerTarget) {
|
|
|
|
mConsumerTarget = NS_GetCurrentThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
~nsInterfaceRequestorAgg();
|
2004-11-15 23:16:52 +03:00
|
|
|
|
2012-11-14 20:00:44 +04:00
|
|
|
private:
|
2004-11-15 23:16:52 +03:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mFirst, mSecond;
|
2012-11-14 20:00:44 +04:00
|
|
|
nsCOMPtr<nsIEventTarget> mConsumerTarget;
|
2004-11-15 23:16:52 +03:00
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsInterfaceRequestorAgg, nsIInterfaceRequestor)
|
2004-11-15 23:16:52 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-13 21:41:38 +04:00
|
|
|
nsInterfaceRequestorAgg::GetInterface(const nsIID& aIID, void** aResult)
|
2004-11-15 23:16:52 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_NO_INTERFACE;
|
2014-05-13 21:41:38 +04:00
|
|
|
if (mFirst) {
|
2004-11-15 23:16:52 +03:00
|
|
|
rv = mFirst->GetInterface(aIID, aResult);
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
|
|
|
if (mSecond && NS_FAILED(rv)) {
|
2004-11-15 23:16:52 +03:00
|
|
|
rv = mSecond->GetInterface(aIID, aResult);
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
2004-11-15 23:16:52 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-11-14 20:00:44 +04: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 23:16:52 +03:00
|
|
|
nsresult
|
2014-05-13 21:41:38 +04:00
|
|
|
NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor* aFirst,
|
|
|
|
nsIInterfaceRequestor* aSecond,
|
|
|
|
nsIInterfaceRequestor** aResult)
|
2004-11-15 23:16:52 +03:00
|
|
|
{
|
|
|
|
*aResult = new nsInterfaceRequestorAgg(aFirst, aSecond);
|
2014-05-13 21:41:38 +04:00
|
|
|
if (!*aResult) {
|
2004-11-15 23:16:52 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
2004-11-15 23:16:52 +03:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-11-14 20:00:44 +04:00
|
|
|
|
|
|
|
nsresult
|
2014-05-13 21:41:38 +04:00
|
|
|
NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor* aFirst,
|
|
|
|
nsIInterfaceRequestor* aSecond,
|
2012-11-14 20:00:44 +04:00
|
|
|
nsIEventTarget* aTarget,
|
2014-05-13 21:41:38 +04:00
|
|
|
nsIInterfaceRequestor** aResult)
|
2012-11-14 20:00:44 +04:00
|
|
|
{
|
|
|
|
*aResult = new nsInterfaceRequestorAgg(aFirst, aSecond, aTarget);
|
2014-05-13 21:41:38 +04:00
|
|
|
if (!*aResult) {
|
2012-11-14 20:00:44 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
2012-11-14 20:00:44 +04:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|