sbRemoteAPI.h
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25  */
26 
27 #ifndef __SB_REMOTE_API_H__
28 #define __SB_REMOTE_API_H__
29 
30 #include <sbISecurityAggregator.h>
31 #include <sbISecurityMixin.h>
32 #include <nsAutoPtr.h>
33 #include <nsMemory.h>
34 #include <nsPIDOMWindow.h>
35 #include <nsIDOMDocument.h>
36 #include "sbSecurityMixin.h"
37 
38 #ifndef LOG
39 #define LOG(args) /* nothing */
40 #endif
41 
42 #define SB_DECL_SECURITYCHECKEDCOMP_INIT virtual nsresult Init();
43 
44 #define SB_IMPL_SECURITYCHECKEDCOMP_INIT_TAIL() \
45  return NS_OK; \
46 }
47 
48 #define SB_IMPL_SECURITYCHECKEDCOMP_INIT_MIXIN_MID( _class, _mixin, _mixinArgs ) \
49 nsresult \
50 _class::Init() \
51 { \
52  LOG(( "%s::Init()", #_class )); \
53  nsresult rv; \
54  nsRefPtr<_mixin> mixin = new _mixin _mixinArgs; \
55  NS_ENSURE_TRUE( mixin, NS_ERROR_OUT_OF_MEMORY ); \
56  /* Get the list of IIDs to pass to the security mixin */ \
57  nsIID **iids; \
58  PRUint32 iidCount; \
59  GetInterfaces( &iidCount, &iids ); \
60  /* initialize our mixin with approved interfaces, methods, properties */ \
61  rv = mixin->Init( (sbISecurityAggregator*)this, \
62  ( const nsIID** )iids, iidCount, \
63  sPublicMethods, NS_ARRAY_LENGTH(sPublicMethods), \
64  sPublicRProperties, NS_ARRAY_LENGTH(sPublicRProperties), \
65  sPublicWProperties, NS_ARRAY_LENGTH(sPublicWProperties), \
66  mRemotePlayer->IsPrivileged() ); \
67  NS_ENSURE_SUCCESS( rv, rv ); \
68  NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(iidCount, iids); \
69  mSecurityMixin = do_QueryInterface( \
70  NS_ISUPPORTS_CAST( sbISecurityMixin*, mixin ), &rv ); \
71  NS_ENSURE_SUCCESS( rv, rv ); \
72  /* pull the dom window from the js stack and context */ \
73  nsCOMPtr<nsPIDOMWindow> privWindow = mRemotePlayer->GetWindow(); \
74  if(privWindow) { \
75  nsCOMPtr<nsIDOMDocument> domDoc; \
76  privWindow->GetDocument( getter_AddRefs(domDoc) ); \
77  NS_ENSURE_STATE(domDoc); \
78  rv = mixin->SetNotificationDocument( domDoc ); \
79  NS_ENSURE_SUCCESS( rv, rv ); \
80  }
81 
82 #define SB_IMPL_SECURITYCHECKEDCOMP_INIT(_class) \
83  SB_IMPL_SECURITYCHECKEDCOMP_INIT_MIXIN_MID( _class, sbSecurityMixin, () ) \
84  SB_IMPL_SECURITYCHECKEDCOMP_INIT_TAIL()
85 
86 #define SB_IMPL_SECURITYCHECKEDCOMP_INIT_MIXIN_LIBRES( _class, \
87  _mixin, _mixinArgs, \
88  _libres, _libresArgs ) \
89  SB_IMPL_SECURITYCHECKEDCOMP_INIT_MIXIN_MID( _class, _mixin, _mixinArgs ) \
90  mRemLibraryResource = new _libres _libresArgs; \
91  NS_ENSURE_TRUE( mRemLibraryResource, NS_ERROR_OUT_OF_MEMORY ); \
92  SB_IMPL_SECURITYCHECKEDCOMP_INIT_TAIL()
93 
94 #define SB_IMPL_SECURITYCHECKEDCOMP_INIT_LIBRES(_class, _libres, _libresArgs) \
95  SB_IMPL_SECURITYCHECKEDCOMP_INIT_MIXIN_LIBRES( _class, \
96  sbSecurityMixin, (), \
97  _libres, _libresArgs ) \
98 
99 
100 #define SB_IMPL_SECURITYCHECKEDCOMP_INIT_NOPLAYER_MIXIN( _class, _mixin, _mixinArgs ) \
101 nsresult \
102 _class::Init() \
103 { \
104  LOG(( "%s::Init()", #_class )); \
105  nsresult rv; \
106  nsRefPtr<_mixin> mixin = new _mixin _mixinArgs; \
107  NS_ENSURE_TRUE( mixin, NS_ERROR_OUT_OF_MEMORY ); \
108  /* Get the list of IIDs to pass to the security mixin */ \
109  nsIID **iids; \
110  PRUint32 iidCount; \
111  GetInterfaces( &iidCount, &iids ); \
112  /* initialize our mixin with approved interfaces, methods, properties */ \
113  rv = mixin->Init( (sbISecurityAggregator*)this, \
114  ( const nsIID** )iids, iidCount, \
115  sPublicMethods, NS_ARRAY_LENGTH(sPublicMethods), \
116  sPublicRProperties, NS_ARRAY_LENGTH(sPublicRProperties), \
117  sPublicWProperties, NS_ARRAY_LENGTH(sPublicWProperties), \
118  PR_FALSE); \
119  NS_ENSURE_SUCCESS( rv, rv ); \
120  NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(iidCount, iids); \
121  mSecurityMixin = do_QueryInterface( \
122  NS_ISUPPORTS_CAST( sbISecurityMixin*, mixin ), &rv ); \
123  NS_ENSURE_SUCCESS( rv, rv ); \
124  return NS_OK; \
125 }
126 
127 #define SB_IMPL_SECURITYCHECKEDCOMP_INIT_NOPLAYER(_class) \
128  SB_IMPL_SECURITYCHECKEDCOMP_INIT_NOPLAYER_MIXIN( _class, sbSecurityMixin, () )
129 
130 #endif // __SB_REMOTE_API_H__