sbSecurityMixin.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_SECURITY_MIXIN_H__
28 #define __SB_SECURITY_MIXIN_H__
29 
30 #include "sbISecurityMixin.h"
31 #include "sbISecurityAggregator.h"
32 
33 #include <nsCOMPtr.h>
34 #include <nsIClassInfo.h>
35 #include <nsISecurityCheckedComponent.h>
36 #include <nsIURI.h>
37 #include <nsStringGlue.h>
38 #include <nsTArray.h>
39 #include <nsIDOMDocument.h>
40 
41 #define SONGBIRD_SECURITYMIXIN_CONTRACTID \
42  "@songbirdnest.com/remoteapi/security-mixin;1"
43 #define SONGBIRD_SECURITYMIXIN_CLASSNAME \
44  "Songbird Remote Security Mixin"
45 #define SONGBIRD_SECURITYMIXIN_CID \
46 { /* aaae98ec-386e-405e-b109-cf1a872ef6dd */ \
47  0xaaae98ec, \
48  0x386e, \
49  0x405e, \
50  {0xb1, 0x09, 0xcf, 0x1a, 0x87, 0x2e, 0xf6, 0xdd} \
51 }
52 
53 extern char* SB_CloneAllAccess();
54 
55 struct Scope;
56 
57 #define RAPI_EVENT_CLASS NS_LITERAL_STRING("Events")
58 #define RAPI_EVENT_TYPE NS_LITERAL_STRING("remoteapi")
59 
60 #define SB_EVENT_RAPI_PERMISSION_CHANGED NS_LITERAL_STRING("RemoteAPIPermissionChanged")
61 #define SB_EVENT_RAPI_PERMISSION_DENIED NS_LITERAL_STRING("RemoteAPIPermissionDenied")
62 
64  public nsIClassInfo,
65  public sbISecurityMixin
66 {
67 public:
69  NS_DECL_NSICLASSINFO
70  NS_DECL_NSISECURITYCHECKEDCOMPONENT
71  NS_DECL_SBISECURITYMIXIN
72 
74 
80  static nsresult SetPermission(nsIURI *aURI, const nsACString &aScopedName);
81 
82 protected:
83  virtual ~sbSecurityMixin();
84 
85  // helpers for resolving the prefs and permissions
86  PRBool GetPermission(nsIURI *aURI, const struct Scope* aScope);
87  PRBool GetPermissionForScopedName(const nsAString &aScopedName,
88  PRBool disableNotificationCheck = PR_FALSE);
89  PRBool GetScopedName(nsTArray<nsCString> &aStringArray,
90  const nsAString &aMethodName,
91  nsAString &aScopedName);
92 
93  const struct Scope* GetScopeForScopedName(const nsAString &aScopedName);
94 
95  // helpers for dispatching notification events
96  nsresult DispatchNotificationEvent(const char* aNotificationType,
97  const Scope* aScope,
98  PRBool aHasAccess);
99 
100  // helper function for allocating IID array
101  nsresult CopyIIDArray(PRUint32 aCount, const nsIID **aSourceArray, nsIID ***aDestArray);
102 
103  // helper function for copying over a string array
104  nsresult CopyStrArray(PRUint32 aCount, const char **aSourceArray, nsTArray<nsCString> *aDestArray);
105 
106  // non-binding ref, we don't want to keep our outer from going away
108 
109  // holders for the lists of approved methods, properties and interfaces
110  // passed in to us by the mOuter ( in our Init() method )
111  nsIID **mInterfaces;
113  PRBool mPrivileged;
114  nsTArray<nsCString> mMethods;
115  nsTArray<nsCString> mRProperties;
116  nsTArray<nsCString> mWProperties;
117  nsCOMPtr<nsIDOMDocument> mNotificationDocument;
118 };
119 
120 #endif // __SB_SECURITY_MIXIN_H__
121 
nsTArray< nsCString > mMethods
nsTArray< nsCString > mWProperties
virtual ~sbSecurityMixin()
PRBool GetScopedName(nsTArray< nsCString > &aStringArray, const nsAString &aMethodName, nsAString &aScopedName)
nsTArray< nsCString > mRProperties
PRUint32 mInterfacesCount
nsISecurityCheckedComponent
An interface for setting up nsISecurityCheckedComponent security checks.
NS_DECL_ISUPPORTS NS_DECL_NSICLASSINFO NS_DECL_NSISECURITYCHECKEDCOMPONENT NS_DECL_SBISECURITYMIXIN sbSecurityMixin()
A marker interface for objects that aggregate the security mixin.
nsresult CopyIIDArray(PRUint32 aCount, const nsIID **aSourceArray, nsIID ***aDestArray)
const struct Scope * GetScopeForScopedName(const nsAString &aScopedName)
nsresult DispatchNotificationEvent(const char *aNotificationType, const Scope *aScope, PRBool aHasAccess)
sbISecurityAggregator * mOuter
restoreHistoryPrecursor aCount
nsCOMPtr< nsIDOMDocument > mNotificationDocument
nsresult CopyStrArray(PRUint32 aCount, const char **aSourceArray, nsTArray< nsCString > *aDestArray)
char * SB_CloneAllAccess()
PRBool GetPermission(nsIURI *aURI, const struct Scope *aScope)
PRBool GetPermissionForScopedName(const nsAString &aScopedName, PRBool disableNotificationCheck=PR_FALSE)
static nsresult SetPermission(nsIURI *aURI, const nsACString &aScopedName)
Set the permission to allow for a scoped name.