sbRemoteSecurityEvent.cpp
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 #include "sbRemoteSecurityEvent.h"
28 #include "sbRemoteAPIUtils.h"
29 #include "sbRemotePlayer.h"
30 
31 #include <sbClassInfoUtils.h>
32 
33 #include <sbIRemoteSecurityEvent.h>
34 
35 #include <nsComponentManagerUtils.h>
36 #include <nsIDOMDocumentEvent.h>
37 #include <nsIProgrammingLanguage.h>
38 #include <nsMemory.h>
39 #include <prlog.h>
40 
41 /*
42  * To log this module, set the following environment variable:
43  * NSPR_LOG_MODULES=sbRemoteSecurityEvent:5
44  */
45 #ifdef PR_LOGGING
46 static PRLogModuleInfo* gRemoteEventLog = nsnull;
47 #endif
48 
49 #undef LOG
50 #define LOG(args) PR_LOG(gRemoteEventLog, PR_LOG_WARN, args)
51 
52 const static char* sPublicWProperties[] = { "" };
53 
54 const static char* sPublicRProperties[] =
55 {
56  // sbIRemoteSecurityEvent
57  "helper:siteScope",
58  "helper:category",
59  "helper:categoryID",
60  "helper:hasAccess",
61 
62  // nsIDOMEvent
63  "helper:type",
64 
65  // nsIClassInfo
66  "classinfo:classDescription",
67  "classinfo:contractID",
68  "classinfo:classID",
69  "classinfo:implementationLanguage",
70  "classinfo:flags"
71 };
72 
73 const static char* sPublicMethods[] = {
74  ""
75 };
76 
80  nsIDOMNSEvent,
81  nsIPrivateDOMEvent,
86 
93 
94 SB_IMPL_CLASSINFO_INTERFACES_ONLY(sbRemoteSecurityEvent)
95 
97 
98 sbRemoteSecurityEvent::sbRemoteSecurityEvent() :
99  mHasAccess(PR_FALSE)
100 {
101  MOZ_COUNT_CTOR(sbRemoteSecurityEvent);
102 #ifdef PR_LOGGING
103  if (!gRemoteEventLog) {
104  gRemoteEventLog = PR_NewLogModule("sbRemoteSecurityEvent");
105  }
106  LOG(("sbRemoteMediaItemStatusEvent::sbRemoteMediaItemStatusEvent()"));
107 #endif
108 }
109 
111 {
112  MOZ_COUNT_DTOR(sbRemoteSecurityEvent);
113 }
114 
115 // ---------------------------------------------------------------------------
116 //
117 // sbISecurityAggregator
118 //
119 // ---------------------------------------------------------------------------
120 
121 NS_IMETHODIMP
122 sbRemoteSecurityEvent::GetRemotePlayer(sbIRemotePlayer * *aRemotePlayer)
123 {
124  return NS_ERROR_NOT_IMPLEMENTED;
125 }
126 
127 // ---------------------------------------------------------------------------
128 //
129 // sbIRemoteSecurityEvent
130 //
131 // ---------------------------------------------------------------------------
132 
134  nsIURI *aScopeURI,
135  const nsAString& aSecurityCategory,
136  const nsAString& aSecurityCategoryID,
137  PRBool aHasAccessToCategory )
138 {
139  NS_ENSURE_ARG_POINTER( aEvent );
140  NS_ENSURE_ARG_POINTER( aScopeURI );
141 
142  nsresult rv;
143 
144  mEvent = aEvent;
145 
146  mNSEvent = do_QueryInterface( mEvent, &rv );
147  NS_ENSURE_SUCCESS( rv, rv );
148 
149  mHasAccess = aHasAccessToCategory;
150  mCategory = aSecurityCategory;
151  mCategoryID = aSecurityCategoryID;
152 
153  mScopeURI = aScopeURI;
154 
155  return NS_OK;
156 }
157 
158 /*** sbRemoteSecurityEvent ***/
159 /* attribute nsIURI siteScope; */
160 NS_IMETHODIMP sbRemoteSecurityEvent::GetSiteScope(nsIURI * *aSiteScope)
161 {
162  NS_ENSURE_ARG_POINTER(aSiteScope);
163 
164  *aSiteScope = mScopeURI;
165  NS_ADDREF( *aSiteScope );
166 
167  return NS_OK;
168 }
169 
170 /* attribute AString category; */
171 NS_IMETHODIMP sbRemoteSecurityEvent::GetCategory(nsAString & aCategory)
172 {
173  aCategory = mCategory;
174  return NS_OK;
175 }
176 
177 /* attribute AString categoryID */
178 NS_IMETHODIMP sbRemoteSecurityEvent::GetCategoryID(nsAString & aCategoryID)
179 {
180  aCategoryID = mCategoryID;
181  return NS_OK;
182 }
183 
184 /* attribute boolean hasAccess; */
185 NS_IMETHODIMP sbRemoteSecurityEvent::GetHasAccess(PRBool *aHasAccess)
186 {
187  NS_ENSURE_ARG_POINTER(aHasAccess);
188  *aHasAccess = mHasAccess;
189  return NS_OK;
190 }
191 
192 /* void Init (in nsIDOMDocument aDoc, in AString aCategory, in AString aCategoryID, in boolean aHasAccess); */
193 NS_IMETHODIMP
194 sbRemoteSecurityEvent::InitSecurityEvent(nsIDOMDocument *aDoc,
195  nsIURI *aSiteScope,
196  const nsAString & aCategory,
197  const nsAString & aCategoryID,
198  PRBool aHasAccess)
199 {
200  NS_ENSURE_ARG_POINTER(aSiteScope);
201 
203 
204  nsresult rv;
205 
206  //change interfaces to create the event
207  nsCOMPtr<nsIDOMDocumentEvent>
208  docEvent( do_QueryInterface( aDoc, &rv ) );
209  NS_ENSURE_SUCCESS( rv , rv );
210 
211  //create the event
212  nsCOMPtr<nsIDOMEvent> event;
213  docEvent->CreateEvent( RAPI_EVENT_CLASS, getter_AddRefs(event) );
214  NS_ENSURE_STATE(event);
215 
216  // XXXredfive - this looks suspect, if access we say permission changed?
217  rv = event->InitEvent( aHasAccess ? SB_EVENT_RAPI_PERMISSION_CHANGED : SB_EVENT_RAPI_PERMISSION_DENIED,
218  PR_TRUE,
219  PR_TRUE );
220  NS_ENSURE_SUCCESS( rv , rv );
221 
222  //use the document for a target.
223  nsCOMPtr<nsIDOMEventTarget>
224  eventTarget( do_QueryInterface( aDoc, &rv ) );
225  NS_ENSURE_SUCCESS( rv, rv );
226 
227  //make the event untrusted
228  nsCOMPtr<nsIPrivateDOMEvent> privEvt( do_QueryInterface( event, &rv ) );
229  NS_ENSURE_SUCCESS( rv, rv );
230  privEvt->SetTrusted(PR_TRUE);
231 
232  return sbRemoteSecurityEvent::InitEvent(event,
233  aSiteScope,
234  aCategory,
235  aCategoryID,
236  aHasAccess);
237 }
238 
239 /*** nsIPrivateDOMEvent ***/
240 // this macro forwards a method to the inner event (up to one arg)
241 #define FORWARD_NSIPRIVATEDOMEVENT(_method, _type, _arg, _rettype, _default) \
242  NS_IMETHODIMP_(_rettype) sbRemoteSecurityEvent::_method( _type _arg ) \
243  { \
244  nsresult rv; \
245  nsCOMPtr<nsIPrivateDOMEvent> inner( do_QueryInterface(mEvent, &rv) ); \
246  NS_ENSURE_SUCCESS(rv, _default); \
247  return inner->_method( _arg ); \
248  }
249 
250 FORWARD_NSIPRIVATEDOMEVENT(DuplicatePrivateData, , , nsresult, rv)
251 FORWARD_NSIPRIVATEDOMEVENT(SetTarget, nsIDOMEventTarget*, aTarget, nsresult, rv)
252 FORWARD_NSIPRIVATEDOMEVENT(IsDispatchStopped, , , PRBool, PR_FALSE)
253 FORWARD_NSIPRIVATEDOMEVENT(GetInternalNSEvent, , , nsEvent*, nsnull)
254 FORWARD_NSIPRIVATEDOMEVENT(SetTrusted, PRBool, aTrusted, nsresult, rv)
#define SB_IMPL_SECURITYCHECKEDCOMP_INIT_NOPLAYER(_class)
Definition: sbRemoteAPI.h:127
return NS_OK
NS_IMETHOD InitEvent(nsIDOMEvent *, nsIURI *, const nsAString &, const nsAString &, PRBool)
#define SB_EVENT_RAPI_PERMISSION_DENIED
var event
This interface is a composition of many of our other interfaces with the goal of exposing a more web-...
#define RAPI_EVENT_CLASS
NS_DECL_ISUPPORTS NS_DECL_NSICLASSINFO NS_DECL_SBISECURITYAGGREGATOR NS_DECL_SBIREMOTESECURITYEVENT virtual NS_DECL_SBIMUTABLEREMOTESECURITYEVENT nsresult Init()
nsCOMPtr< nsIDOMNSEvent > mNSEvent
NS_IMPL_ISUPPORTS8(sbRemoteSecurityEvent, nsIClassInfo, nsIDOMEvent, nsIDOMNSEvent, nsIPrivateDOMEvent, nsISecurityCheckedComponent, sbIRemoteSecurityEvent, sbIMutableRemoteSecurityEvent, sbISecurityAggregator) NS_IMPL_CI_INTERFACE_GETTER5(sbRemoteSecurityEvent
#define LOG(args)
A marker interface for objects that aggregate the security mixin.
static const char * sPublicMethods[]
nsISecurityCheckedComponent
static const char * sPublicRProperties[]
NS_INTERFACE_MAP_END NS_IMPL_CI_INTERFACE_GETTER5(sbLocalDatabaseMediaItem, nsIClassInfo, nsISupportsWeakReference, nsIRequestObserver, sbILibraryResource, sbIMediaItem) sbLocalDatabaseMediaItem
#define SB_EVENT_RAPI_PERMISSION_CHANGED
#define SB_IMPL_CLASSINFO_INTERFACES_ONLY(_class)
An interface to maintain information about the last security event that occurred. ...
nsCOMPtr< nsIDOMEvent > mEvent
static const char * sPublicWProperties[]
#define FORWARD_NSIPRIVATEDOMEVENT(_method, _type, _arg, _rettype, _default)
nsCOMPtr< nsIURI > mScopeURI