xpcom/glue/nsComponentManagerUtils.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsComponentManagerUtils_h__
michael@0 7 #define nsComponentManagerUtils_h__
michael@0 8
michael@0 9 #include "nscore.h"
michael@0 10 #include "nsCOMPtr.h"
michael@0 11
michael@0 12 #include "nsIFactory.h"
michael@0 13
michael@0 14
michael@0 15 NS_COM_GLUE nsresult
michael@0 16 CallCreateInstance
michael@0 17 (const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID,
michael@0 18 void **aResult);
michael@0 19
michael@0 20 NS_COM_GLUE nsresult
michael@0 21 CallCreateInstance
michael@0 22 (const char *aContractID, nsISupports *aDelegate, const nsIID &aIID,
michael@0 23 void **aResult);
michael@0 24
michael@0 25 NS_COM_GLUE nsresult
michael@0 26 CallGetClassObject
michael@0 27 (const nsCID &aClass, const nsIID &aIID, void **aResult);
michael@0 28
michael@0 29 NS_COM_GLUE nsresult
michael@0 30 CallGetClassObject
michael@0 31 (const char *aContractID, const nsIID &aIID, void **aResult);
michael@0 32
michael@0 33
michael@0 34 class NS_COM_GLUE nsCreateInstanceByCID : public nsCOMPtr_helper
michael@0 35 {
michael@0 36 public:
michael@0 37 nsCreateInstanceByCID( const nsCID& aCID, nsISupports* aOuter, nsresult* aErrorPtr )
michael@0 38 : mCID(aCID),
michael@0 39 mOuter(aOuter),
michael@0 40 mErrorPtr(aErrorPtr)
michael@0 41 {
michael@0 42 // nothing else to do here
michael@0 43 }
michael@0 44
michael@0 45 virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
michael@0 46
michael@0 47 private:
michael@0 48 const nsCID& mCID;
michael@0 49 nsISupports* mOuter;
michael@0 50 nsresult* mErrorPtr;
michael@0 51 };
michael@0 52
michael@0 53 class NS_COM_GLUE nsCreateInstanceByContractID : public nsCOMPtr_helper
michael@0 54 {
michael@0 55 public:
michael@0 56 nsCreateInstanceByContractID( const char* aContractID, nsISupports* aOuter, nsresult* aErrorPtr )
michael@0 57 : mContractID(aContractID),
michael@0 58 mOuter(aOuter),
michael@0 59 mErrorPtr(aErrorPtr)
michael@0 60 {
michael@0 61 // nothing else to do here
michael@0 62 }
michael@0 63
michael@0 64 virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
michael@0 65
michael@0 66 private:
michael@0 67 const char* mContractID;
michael@0 68 nsISupports* mOuter;
michael@0 69 nsresult* mErrorPtr;
michael@0 70 };
michael@0 71
michael@0 72 class NS_COM_GLUE nsCreateInstanceFromFactory : public nsCOMPtr_helper
michael@0 73 {
michael@0 74 public:
michael@0 75 nsCreateInstanceFromFactory( nsIFactory* aFactory, nsISupports* aOuter, nsresult* aErrorPtr )
michael@0 76 : mFactory(aFactory),
michael@0 77 mOuter(aOuter),
michael@0 78 mErrorPtr(aErrorPtr)
michael@0 79 {
michael@0 80 // nothing else to do here
michael@0 81 }
michael@0 82
michael@0 83 virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
michael@0 84
michael@0 85 private:
michael@0 86 nsIFactory* mFactory;
michael@0 87 nsISupports* mOuter;
michael@0 88 nsresult* mErrorPtr;
michael@0 89 };
michael@0 90
michael@0 91
michael@0 92 inline
michael@0 93 const nsCreateInstanceByCID
michael@0 94 do_CreateInstance( const nsCID& aCID, nsresult* error = 0 )
michael@0 95 {
michael@0 96 return nsCreateInstanceByCID(aCID, 0, error);
michael@0 97 }
michael@0 98
michael@0 99 inline
michael@0 100 const nsCreateInstanceByCID
michael@0 101 do_CreateInstance( const nsCID& aCID, nsISupports* aOuter, nsresult* error = 0 )
michael@0 102 {
michael@0 103 return nsCreateInstanceByCID(aCID, aOuter, error);
michael@0 104 }
michael@0 105
michael@0 106 inline
michael@0 107 const nsCreateInstanceByContractID
michael@0 108 do_CreateInstance( const char* aContractID, nsresult* error = 0 )
michael@0 109 {
michael@0 110 return nsCreateInstanceByContractID(aContractID, 0, error);
michael@0 111 }
michael@0 112
michael@0 113 inline
michael@0 114 const nsCreateInstanceByContractID
michael@0 115 do_CreateInstance( const char* aContractID, nsISupports* aOuter, nsresult* error = 0 )
michael@0 116 {
michael@0 117 return nsCreateInstanceByContractID(aContractID, aOuter, error);
michael@0 118 }
michael@0 119
michael@0 120 inline
michael@0 121 const nsCreateInstanceFromFactory
michael@0 122 do_CreateInstance( nsIFactory* aFactory, nsresult* error = 0 )
michael@0 123 {
michael@0 124 return nsCreateInstanceFromFactory(aFactory, 0, error);
michael@0 125 }
michael@0 126
michael@0 127 inline
michael@0 128 const nsCreateInstanceFromFactory
michael@0 129 do_CreateInstance( nsIFactory* aFactory, nsISupports* aOuter, nsresult* error = 0 )
michael@0 130 {
michael@0 131 return nsCreateInstanceFromFactory(aFactory, aOuter, error);
michael@0 132 }
michael@0 133
michael@0 134
michael@0 135 class NS_COM_GLUE nsGetClassObjectByCID : public nsCOMPtr_helper
michael@0 136 {
michael@0 137 public:
michael@0 138 nsGetClassObjectByCID( const nsCID& aCID, nsresult* aErrorPtr )
michael@0 139 : mCID(aCID),
michael@0 140 mErrorPtr(aErrorPtr)
michael@0 141 {
michael@0 142 // nothing else to do here
michael@0 143 }
michael@0 144
michael@0 145 virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
michael@0 146
michael@0 147 private:
michael@0 148 const nsCID& mCID;
michael@0 149 nsresult* mErrorPtr;
michael@0 150 };
michael@0 151
michael@0 152 class NS_COM_GLUE nsGetClassObjectByContractID : public nsCOMPtr_helper
michael@0 153 {
michael@0 154 public:
michael@0 155 nsGetClassObjectByContractID( const char* aContractID, nsresult* aErrorPtr )
michael@0 156 : mContractID(aContractID),
michael@0 157 mErrorPtr(aErrorPtr)
michael@0 158 {
michael@0 159 // nothing else to do here
michael@0 160 }
michael@0 161
michael@0 162 virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
michael@0 163
michael@0 164 private:
michael@0 165 const char* mContractID;
michael@0 166 nsresult* mErrorPtr;
michael@0 167 };
michael@0 168
michael@0 169 /**
michael@0 170 * do_GetClassObject can be used to improve performance of callers
michael@0 171 * that call |CreateInstance| many times. They can cache the factory
michael@0 172 * and call do_CreateInstance or CallCreateInstance with the cached
michael@0 173 * factory rather than having the component manager retrieve it every
michael@0 174 * time.
michael@0 175 */
michael@0 176 inline const nsGetClassObjectByCID
michael@0 177 do_GetClassObject( const nsCID& aCID, nsresult* error = 0 )
michael@0 178 {
michael@0 179 return nsGetClassObjectByCID(aCID, error);
michael@0 180 }
michael@0 181
michael@0 182 inline const nsGetClassObjectByContractID
michael@0 183 do_GetClassObject( const char* aContractID, nsresult* error = 0 )
michael@0 184 {
michael@0 185 return nsGetClassObjectByContractID(aContractID, error);
michael@0 186 }
michael@0 187
michael@0 188 // type-safe shortcuts for calling |CreateInstance|
michael@0 189 template <class DestinationType>
michael@0 190 inline
michael@0 191 nsresult
michael@0 192 CallCreateInstance( const nsCID &aClass,
michael@0 193 nsISupports *aDelegate,
michael@0 194 DestinationType** aDestination )
michael@0 195 {
michael@0 196 NS_PRECONDITION(aDestination, "null parameter");
michael@0 197
michael@0 198 return CallCreateInstance(aClass, aDelegate,
michael@0 199 NS_GET_TEMPLATE_IID(DestinationType),
michael@0 200 reinterpret_cast<void**>(aDestination));
michael@0 201 }
michael@0 202
michael@0 203 template <class DestinationType>
michael@0 204 inline
michael@0 205 nsresult
michael@0 206 CallCreateInstance( const nsCID &aClass,
michael@0 207 DestinationType** aDestination )
michael@0 208 {
michael@0 209 NS_PRECONDITION(aDestination, "null parameter");
michael@0 210
michael@0 211 return CallCreateInstance(aClass, nullptr,
michael@0 212 NS_GET_TEMPLATE_IID(DestinationType),
michael@0 213 reinterpret_cast<void**>(aDestination));
michael@0 214 }
michael@0 215
michael@0 216 template <class DestinationType>
michael@0 217 inline
michael@0 218 nsresult
michael@0 219 CallCreateInstance( const char *aContractID,
michael@0 220 nsISupports *aDelegate,
michael@0 221 DestinationType** aDestination )
michael@0 222 {
michael@0 223 NS_PRECONDITION(aContractID, "null parameter");
michael@0 224 NS_PRECONDITION(aDestination, "null parameter");
michael@0 225
michael@0 226 return CallCreateInstance(aContractID,
michael@0 227 aDelegate,
michael@0 228 NS_GET_TEMPLATE_IID(DestinationType),
michael@0 229 reinterpret_cast<void**>(aDestination));
michael@0 230 }
michael@0 231
michael@0 232 template <class DestinationType>
michael@0 233 inline
michael@0 234 nsresult
michael@0 235 CallCreateInstance( const char *aContractID,
michael@0 236 DestinationType** aDestination )
michael@0 237 {
michael@0 238 NS_PRECONDITION(aContractID, "null parameter");
michael@0 239 NS_PRECONDITION(aDestination, "null parameter");
michael@0 240
michael@0 241 return CallCreateInstance(aContractID, nullptr,
michael@0 242 NS_GET_TEMPLATE_IID(DestinationType),
michael@0 243 reinterpret_cast<void**>(aDestination));
michael@0 244 }
michael@0 245
michael@0 246 template <class DestinationType>
michael@0 247 inline
michael@0 248 nsresult
michael@0 249 CallCreateInstance( nsIFactory *aFactory,
michael@0 250 nsISupports *aDelegate,
michael@0 251 DestinationType** aDestination )
michael@0 252 {
michael@0 253 NS_PRECONDITION(aFactory, "null parameter");
michael@0 254 NS_PRECONDITION(aDestination, "null parameter");
michael@0 255
michael@0 256 return aFactory->CreateInstance(aDelegate,
michael@0 257 NS_GET_TEMPLATE_IID(DestinationType),
michael@0 258 reinterpret_cast<void**>(aDestination));
michael@0 259 }
michael@0 260
michael@0 261 template <class DestinationType>
michael@0 262 inline
michael@0 263 nsresult
michael@0 264 CallCreateInstance( nsIFactory *aFactory,
michael@0 265 DestinationType** aDestination )
michael@0 266 {
michael@0 267 NS_PRECONDITION(aFactory, "null parameter");
michael@0 268 NS_PRECONDITION(aDestination, "null parameter");
michael@0 269
michael@0 270 return aFactory->CreateInstance(nullptr,
michael@0 271 NS_GET_TEMPLATE_IID(DestinationType),
michael@0 272 reinterpret_cast<void**>(aDestination));
michael@0 273 }
michael@0 274
michael@0 275 template <class DestinationType>
michael@0 276 inline
michael@0 277 nsresult
michael@0 278 CallGetClassObject( const nsCID &aClass,
michael@0 279 DestinationType** aDestination )
michael@0 280 {
michael@0 281 NS_PRECONDITION(aDestination, "null parameter");
michael@0 282
michael@0 283 return CallGetClassObject(aClass,
michael@0 284 NS_GET_TEMPLATE_IID(DestinationType), reinterpret_cast<void**>(aDestination));
michael@0 285 }
michael@0 286
michael@0 287 template <class DestinationType>
michael@0 288 inline
michael@0 289 nsresult
michael@0 290 CallGetClassObject( const char* aContractID,
michael@0 291 DestinationType** aDestination )
michael@0 292 {
michael@0 293 NS_PRECONDITION(aDestination, "null parameter");
michael@0 294
michael@0 295 return CallGetClassObject(aContractID,
michael@0 296 NS_GET_TEMPLATE_IID(DestinationType), reinterpret_cast<void**>(aDestination));
michael@0 297 }
michael@0 298
michael@0 299 #endif /* nsComponentManagerUtils_h__ */

mercurial