Line data Source code
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/. */
6 :
7 : #include "nsCOMPtr.h"
8 :
9 : nsresult
10 482875 : nsQueryInterface::operator()(const nsIID& aIID, void** aAnswer) const
11 : {
12 : nsresult status;
13 482875 : if (mRawPtr) {
14 479199 : status = mRawPtr->QueryInterface(aIID, aAnswer);
15 : } else {
16 3676 : status = NS_ERROR_NULL_POINTER;
17 : }
18 :
19 482874 : return status;
20 : }
21 :
22 : nsresult
23 6384 : nsQueryInterfaceWithError::operator()(const nsIID& aIID, void** aAnswer) const
24 : {
25 : nsresult status;
26 6384 : if (mRawPtr) {
27 6380 : status = mRawPtr->QueryInterface(aIID, aAnswer);
28 : } else {
29 4 : status = NS_ERROR_NULL_POINTER;
30 : }
31 :
32 6384 : if (mErrorPtr) {
33 6384 : *mErrorPtr = status;
34 : }
35 6384 : return status;
36 : }
37 :
38 : void
39 6322 : nsCOMPtr_base::assign_with_AddRef(nsISupports* aRawPtr)
40 : {
41 6322 : if (aRawPtr) {
42 783 : NSCAP_ADDREF(this, aRawPtr);
43 : }
44 6322 : assign_assuming_AddRef(aRawPtr);
45 6322 : }
46 :
47 : void
48 10420 : nsCOMPtr_base::assign_from_qi(const nsQueryInterface aQI, const nsIID& aIID)
49 : {
50 : void* newRawPtr;
51 10420 : if (NS_FAILED(aQI(aIID, &newRawPtr))) {
52 3 : newRawPtr = nullptr;
53 : }
54 10420 : assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
55 10420 : }
56 :
57 : void
58 0 : nsCOMPtr_base::assign_from_qi_with_error(const nsQueryInterfaceWithError& aQI,
59 : const nsIID& aIID)
60 : {
61 : void* newRawPtr;
62 0 : if (NS_FAILED(aQI(aIID, &newRawPtr))) {
63 0 : newRawPtr = nullptr;
64 : }
65 0 : assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
66 0 : }
67 :
68 : void
69 0 : nsCOMPtr_base::assign_from_gs_cid(const nsGetServiceByCID aGS,
70 : const nsIID& aIID)
71 : {
72 : void* newRawPtr;
73 0 : if (NS_FAILED(aGS(aIID, &newRawPtr))) {
74 0 : newRawPtr = nullptr;
75 : }
76 0 : assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
77 0 : }
78 :
79 : void
80 0 : nsCOMPtr_base::assign_from_gs_cid_with_error(
81 : const nsGetServiceByCIDWithError& aGS, const nsIID& aIID)
82 : {
83 : void* newRawPtr;
84 0 : if (NS_FAILED(aGS(aIID, &newRawPtr))) {
85 0 : newRawPtr = nullptr;
86 : }
87 0 : assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
88 0 : }
89 :
90 : void
91 44 : nsCOMPtr_base::assign_from_gs_contractid(const nsGetServiceByContractID aGS,
92 : const nsIID& aIID)
93 : {
94 : void* newRawPtr;
95 44 : if (NS_FAILED(aGS(aIID, &newRawPtr))) {
96 0 : newRawPtr = nullptr;
97 : }
98 44 : assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
99 44 : }
100 :
101 : void
102 35 : nsCOMPtr_base::assign_from_gs_contractid_with_error(
103 : const nsGetServiceByContractIDWithError& aGS, const nsIID& aIID)
104 : {
105 : void* newRawPtr;
106 35 : if (NS_FAILED(aGS(aIID, &newRawPtr))) {
107 0 : newRawPtr = nullptr;
108 : }
109 35 : assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
110 35 : }
111 :
112 : void
113 212 : nsCOMPtr_base::assign_from_helper(const nsCOMPtr_helper& aHelper,
114 : const nsIID& aIID)
115 : {
116 : void* newRawPtr;
117 212 : if (NS_FAILED(aHelper(aIID, &newRawPtr))) {
118 0 : newRawPtr = nullptr;
119 : }
120 212 : assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
121 212 : }
122 :
123 : void**
124 4344 : nsCOMPtr_base::begin_assignment()
125 : {
126 4344 : assign_assuming_AddRef(nullptr);
127 4344 : return reinterpret_cast<void**>(&mRawPtr);
128 : }
|