summaryrefslogtreecommitdiffstats
path: root/xpcom/reflect/xptcall/xptcall.cpp
blob: 0b28791b542e7dfbb4ee2aaa794d79f0c2c9993f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */

/* entry point wrappers. */

#include "xptcprivate.h"

using namespace mozilla;

NS_IMETHODIMP
nsXPTCStubBase::QueryInterface(REFNSIID aIID, void** aInstancePtr) {
  if (aIID.Equals(mEntry->IID())) {
    NS_ADDREF_THIS();
    *aInstancePtr = static_cast<nsISupports*>(this);
    return NS_OK;
  }

  return mOuter->QueryInterface(aIID, aInstancePtr);
}

NS_IMETHODIMP_(MozExternalRefCountType)
nsXPTCStubBase::AddRef() { return mOuter->AddRef(); }

NS_IMETHODIMP_(MozExternalRefCountType)
nsXPTCStubBase::Release() { return mOuter->Release(); }

EXPORT_XPCOM_API(nsresult)
NS_GetXPTCallStub(REFNSIID aIID, nsIXPTCProxy* aOuter,
                  nsISomeInterface** aResult) {
  if (NS_WARN_IF(!aOuter) || NS_WARN_IF(!aResult)) return NS_ERROR_INVALID_ARG;

  const nsXPTInterfaceInfo* iie = nsXPTInterfaceInfo::ByIID(aIID);
  if (!iie || iie->IsBuiltinClass()) {
    return NS_ERROR_FAILURE;
  }

  *aResult = new nsXPTCStubBase(aOuter, iie);
  return NS_OK;
}

EXPORT_XPCOM_API(void)
NS_DestroyXPTCallStub(nsISomeInterface* aStub) {
  nsXPTCStubBase* stub = static_cast<nsXPTCStubBase*>(aStub);
  delete (stub);
}

EXPORT_XPCOM_API(size_t)
NS_SizeOfIncludingThisXPTCallStub(const nsISomeInterface* aStub,
                                  mozilla::MallocSizeOf aMallocSizeOf) {
  // We could cast aStub to nsXPTCStubBase, but that class doesn't seem to own
  // anything, so just measure the size of the object itself.
  return aMallocSizeOf(aStub);
}