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 MOZ_FINAL
: public nsIInterfaceRequestor
17 // XXX This needs to support threadsafe refcounting until we fix bug 243591.
18 NS_DECL_THREADSAFE_ISUPPORTS
19 NS_DECL_NSIINTERFACEREQUESTOR
21 nsInterfaceRequestorAgg(nsIInterfaceRequestor
* aFirst
,
22 nsIInterfaceRequestor
* aSecond
,
23 nsIEventTarget
* aConsumerTarget
= nullptr)
26 , mConsumerTarget(aConsumerTarget
)
28 if (!mConsumerTarget
) {
29 mConsumerTarget
= NS_GetCurrentThread();
34 ~nsInterfaceRequestorAgg();
36 nsCOMPtr
<nsIInterfaceRequestor
> mFirst
, mSecond
;
37 nsCOMPtr
<nsIEventTarget
> mConsumerTarget
;
40 NS_IMPL_ISUPPORTS(nsInterfaceRequestorAgg
, nsIInterfaceRequestor
)
43 nsInterfaceRequestorAgg::GetInterface(const nsIID
& aIID
, void** aResult
)
45 nsresult rv
= NS_ERROR_NO_INTERFACE
;
47 rv
= mFirst
->GetInterface(aIID
, aResult
);
49 if (mSecond
&& NS_FAILED(rv
)) {
50 rv
= mSecond
->GetInterface(aIID
, aResult
);
55 nsInterfaceRequestorAgg::~nsInterfaceRequestorAgg()
57 nsIInterfaceRequestor
* iir
= nullptr;
60 NS_ProxyRelease(mConsumerTarget
, iir
);
65 NS_ProxyRelease(mConsumerTarget
, iir
);
70 NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor
* aFirst
,
71 nsIInterfaceRequestor
* aSecond
,
72 nsIInterfaceRequestor
** aResult
)
74 *aResult
= new nsInterfaceRequestorAgg(aFirst
, aSecond
);
76 return NS_ERROR_OUT_OF_MEMORY
;
83 NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor
* aFirst
,
84 nsIInterfaceRequestor
* aSecond
,
85 nsIEventTarget
* aTarget
,
86 nsIInterfaceRequestor
** aResult
)
88 *aResult
= new nsInterfaceRequestorAgg(aFirst
, aSecond
, aTarget
);
90 return NS_ERROR_OUT_OF_MEMORY
;