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
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsInterfaceRequestorAgg 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)
|
2012-11-14 20:00:44 +04:00
|
|
|
: mFirst(aFirst), mSecond(aSecond), mConsumerTarget(aConsumerTarget) {
|
|
|
|
if (!mConsumerTarget) {
|
2023-01-17 02:14:11 +03:00
|
|
|
mConsumerTarget = mozilla::GetCurrentSerialEventTarget();
|
2012-11-14 20:00:44 +04:00
|
|
|
}
|
|
|
|
}
|
2014-07-01 02:11:53 +04:00
|
|
|
|
2014-07-01 02:50:19 +04:00
|
|
|
private:
|
2014-07-01 02:11:53 +04:00
|
|
|
~nsInterfaceRequestorAgg();
|
|
|
|
|
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() {
|
2017-06-14 04:27:17 +03:00
|
|
|
NS_ProxyRelease("nsInterfaceRequestorAgg::mFirst", mConsumerTarget,
|
|
|
|
mFirst.forget());
|
|
|
|
NS_ProxyRelease("nsInterfaceRequestorAgg::mSecond", mConsumerTarget,
|
|
|
|
mSecond.forget());
|
2012-11-14 20:00:44 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
nsresult NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor* aFirst,
|
|
|
|
nsIInterfaceRequestor* aSecond,
|
|
|
|
nsIInterfaceRequestor** aResult) {
|
2004-11-15 23:16:52 +03:00
|
|
|
*aResult = new nsInterfaceRequestorAgg(aFirst, aSecond);
|
2019-06-04 07:43:11 +03:00
|
|
|
|
2004-11-15 23:16:52 +03:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-11-14 20:00:44 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
nsresult 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);
|
2019-06-04 07:43:11 +03:00
|
|
|
|
2012-11-14 20:00:44 +04:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|