Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsCOMPtr.h"
8 nsresult
9 nsQueryInterface::operator()( const nsIID& aIID, void** answer ) const
10 {
11 nsresult status;
12 if ( mRawPtr )
13 {
14 status = mRawPtr->QueryInterface(aIID, answer);
15 #ifdef NSCAP_FEATURE_TEST_NONNULL_QUERY_SUCCEEDS
16 NS_ASSERTION(NS_SUCCEEDED(status), "interface not found---were you expecting that?");
17 #endif
18 }
19 else
20 status = NS_ERROR_NULL_POINTER;
22 return status;
23 }
25 nsresult
26 nsQueryInterfaceWithError::operator()( const nsIID& aIID, void** answer ) const
27 {
28 nsresult status;
29 if ( mRawPtr )
30 {
31 status = mRawPtr->QueryInterface(aIID, answer);
32 #ifdef NSCAP_FEATURE_TEST_NONNULL_QUERY_SUCCEEDS
33 NS_ASSERTION(NS_SUCCEEDED(status), "interface not found---were you expecting that?");
34 #endif
35 }
36 else
37 status = NS_ERROR_NULL_POINTER;
39 if ( mErrorPtr )
40 *mErrorPtr = status;
41 return status;
42 }
44 void
45 nsCOMPtr_base::assign_with_AddRef( nsISupports* rawPtr )
46 {
47 if ( rawPtr )
48 NSCAP_ADDREF(this, rawPtr);
49 assign_assuming_AddRef(rawPtr);
50 }
52 void
53 nsCOMPtr_base::assign_from_qi( const nsQueryInterface qi, const nsIID& iid )
54 {
55 void* newRawPtr;
56 if ( NS_FAILED( qi(iid, &newRawPtr) ) )
57 newRawPtr = 0;
58 assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
59 }
61 void
62 nsCOMPtr_base::assign_from_qi_with_error( const nsQueryInterfaceWithError& qi, const nsIID& iid )
63 {
64 void* newRawPtr;
65 if ( NS_FAILED( qi(iid, &newRawPtr) ) )
66 newRawPtr = 0;
67 assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
68 }
70 void
71 nsCOMPtr_base::assign_from_gs_cid( const nsGetServiceByCID gs, const nsIID& iid )
72 {
73 void* newRawPtr;
74 if ( NS_FAILED( gs(iid, &newRawPtr) ) )
75 newRawPtr = 0;
76 assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
77 }
79 void
80 nsCOMPtr_base::assign_from_gs_cid_with_error( const nsGetServiceByCIDWithError& gs, const nsIID& iid )
81 {
82 void* newRawPtr;
83 if ( NS_FAILED( gs(iid, &newRawPtr) ) )
84 newRawPtr = 0;
85 assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
86 }
88 void
89 nsCOMPtr_base::assign_from_gs_contractid( const nsGetServiceByContractID gs, const nsIID& iid )
90 {
91 void* newRawPtr;
92 if ( NS_FAILED( gs(iid, &newRawPtr) ) )
93 newRawPtr = 0;
94 assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
95 }
97 void
98 nsCOMPtr_base::assign_from_gs_contractid_with_error( const nsGetServiceByContractIDWithError& gs, const nsIID& iid )
99 {
100 void* newRawPtr;
101 if ( NS_FAILED( gs(iid, &newRawPtr) ) )
102 newRawPtr = 0;
103 assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
104 }
106 void
107 nsCOMPtr_base::assign_from_helper( const nsCOMPtr_helper& helper, const nsIID& iid )
108 {
109 void* newRawPtr;
110 if ( NS_FAILED( helper(iid, &newRawPtr) ) )
111 newRawPtr = 0;
112 assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
113 }
115 void**
116 nsCOMPtr_base::begin_assignment()
117 {
118 assign_assuming_AddRef(0);
119 return reinterpret_cast<void**>(&mRawPtr);
120 }