1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is mozilla.org code.
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either of the GNU General Public License Version 2 or later (the "GPL"),
|
---|
26 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | #ifndef nsXPCOM_h__
|
---|
39 | #include "nsXPCOM.h"
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #ifndef nsCOMPtr_h__
|
---|
43 | #include "nsCOMPtr.h"
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | #include "nsComponentManagerUtils.h"
|
---|
47 | #include "nsIServiceManagerUtils.h"
|
---|
48 |
|
---|
49 | nsresult
|
---|
50 | nsCreateInstanceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
|
---|
51 | {
|
---|
52 | nsCOMPtr<nsIComponentManager> compMgr;
|
---|
53 | nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
|
---|
54 | if (compMgr)
|
---|
55 | status = compMgr->CreateInstance(mCID, mOuter, aIID, aInstancePtr);
|
---|
56 | else if (NS_SUCCEEDED(status))
|
---|
57 | status = NS_ERROR_UNEXPECTED;
|
---|
58 |
|
---|
59 | if ( NS_FAILED(status) )
|
---|
60 | *aInstancePtr = 0;
|
---|
61 |
|
---|
62 | if ( mErrorPtr )
|
---|
63 | *mErrorPtr = status;
|
---|
64 | return status;
|
---|
65 | }
|
---|
66 |
|
---|
67 | nsresult
|
---|
68 | nsCreateInstanceByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const
|
---|
69 | {
|
---|
70 | nsresult status;
|
---|
71 | if ( mContractID ) {
|
---|
72 | nsCOMPtr<nsIComponentManager> compMgr;
|
---|
73 | status = NS_GetComponentManager(getter_AddRefs(compMgr));
|
---|
74 | if (compMgr)
|
---|
75 | status = compMgr->CreateInstanceByContractID(mContractID, mOuter,
|
---|
76 | aIID, aInstancePtr);
|
---|
77 | else if (NS_SUCCEEDED(status))
|
---|
78 | status = NS_ERROR_UNEXPECTED;
|
---|
79 | }
|
---|
80 | else
|
---|
81 | status = NS_ERROR_NULL_POINTER;
|
---|
82 |
|
---|
83 | if (NS_FAILED(status))
|
---|
84 | *aInstancePtr = 0;
|
---|
85 | if ( mErrorPtr )
|
---|
86 | *mErrorPtr = status;
|
---|
87 | return status;
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | nsresult
|
---|
92 | nsGetServiceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
|
---|
93 | {
|
---|
94 | nsresult status = NS_ERROR_FAILURE;
|
---|
95 | if ( mServiceManager ) {
|
---|
96 | status = mServiceManager->GetService(mCID, aIID, (void**)aInstancePtr);
|
---|
97 | } else {
|
---|
98 | nsCOMPtr<nsIServiceManager> mgr;
|
---|
99 | NS_GetServiceManager(getter_AddRefs(mgr));
|
---|
100 | if (mgr)
|
---|
101 | status = mgr->GetService(mCID, aIID, (void**)aInstancePtr);
|
---|
102 | }
|
---|
103 | if ( NS_FAILED(status) )
|
---|
104 | *aInstancePtr = 0;
|
---|
105 |
|
---|
106 | if ( mErrorPtr )
|
---|
107 | *mErrorPtr = status;
|
---|
108 | return status;
|
---|
109 | }
|
---|
110 |
|
---|
111 | nsresult
|
---|
112 | nsGetServiceByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const
|
---|
113 | {
|
---|
114 | nsresult status = NS_ERROR_FAILURE;
|
---|
115 | if ( mServiceManager ) {
|
---|
116 | status = mServiceManager->GetServiceByContractID(mContractID, aIID, (void**)aInstancePtr);
|
---|
117 | } else {
|
---|
118 | nsCOMPtr<nsIServiceManager> mgr;
|
---|
119 | NS_GetServiceManager(getter_AddRefs(mgr));
|
---|
120 | if (mgr)
|
---|
121 | status = mgr->GetServiceByContractID(mContractID, aIID, (void**)aInstancePtr);
|
---|
122 | }
|
---|
123 |
|
---|
124 | if ( NS_FAILED(status) )
|
---|
125 | *aInstancePtr = 0;
|
---|
126 |
|
---|
127 | if ( mErrorPtr )
|
---|
128 | *mErrorPtr = status;
|
---|
129 | return status;
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|