1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsInterfaceRequestorAgg.h"
8 #include "nsIInterfaceRequestor.h"
10 #include "mozilla/Attributes.h"
11 #include "nsThreadUtils.h"
12 #include "nsProxyRelease.h"
14 class nsInterfaceRequestorAgg final
: public nsIInterfaceRequestor
{
16 // XXX This needs to support threadsafe refcounting until we fix bug 243591.
17 NS_DECL_THREADSAFE_ISUPPORTS
18 NS_DECL_NSIINTERFACEREQUESTOR
20 nsInterfaceRequestorAgg(nsIInterfaceRequestor
* aFirst
,
21 nsIInterfaceRequestor
* aSecond
,
22 nsIEventTarget
* aConsumerTarget
= nullptr)
23 : mFirst(aFirst
), mSecond(aSecond
), mConsumerTarget(aConsumerTarget
) {
24 if (!mConsumerTarget
) {
25 mConsumerTarget
= mozilla::GetCurrentSerialEventTarget();
30 ~nsInterfaceRequestorAgg();
32 nsCOMPtr
<nsIInterfaceRequestor
> mFirst
, mSecond
;
33 nsCOMPtr
<nsIEventTarget
> mConsumerTarget
;
36 NS_IMPL_ISUPPORTS(nsInterfaceRequestorAgg
, nsIInterfaceRequestor
)
39 nsInterfaceRequestorAgg::GetInterface(const nsIID
& aIID
, void** aResult
) {
40 nsresult rv
= NS_ERROR_NO_INTERFACE
;
42 rv
= mFirst
->GetInterface(aIID
, aResult
);
44 if (mSecond
&& NS_FAILED(rv
)) {
45 rv
= mSecond
->GetInterface(aIID
, aResult
);
50 nsInterfaceRequestorAgg::~nsInterfaceRequestorAgg() {
51 NS_ProxyRelease("nsInterfaceRequestorAgg::mFirst", mConsumerTarget
,
53 NS_ProxyRelease("nsInterfaceRequestorAgg::mSecond", mConsumerTarget
,
57 nsresult
NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor
* aFirst
,
58 nsIInterfaceRequestor
* aSecond
,
59 nsIInterfaceRequestor
** aResult
) {
60 *aResult
= new nsInterfaceRequestorAgg(aFirst
, aSecond
);
66 nsresult
NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor
* aFirst
,
67 nsIInterfaceRequestor
* aSecond
,
68 nsIEventTarget
* aTarget
,
69 nsIInterfaceRequestor
** aResult
) {
70 *aResult
= new nsInterfaceRequestorAgg(aFirst
, aSecond
, aTarget
);