sbRemotePlaylistClickEvent.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 
28 #include "sbRemoteAPIUtils.h"
29 #include "sbRemotePlayer.h"
30 
31 #include <sbClassInfoUtils.h>
32 
33 #include <sbIPlaylistClickEvent.h>
34 
35 #include <nsComponentManagerUtils.h>
36 #include <nsIProgrammingLanguage.h>
37 #include <nsMemory.h>
38 #include <prlog.h>
39 
40 /*
41  * To log this module, set the following environment variable:
42  * NSPR_LOG_MODULES=sbRemotePlaylistClickEvent:5
43  */
44 #ifdef PR_LOGGING
45 static PRLogModuleInfo* gRemoteEventLog = nsnull;
46 #endif
47 
48 #undef LOG
49 #define LOG(args) PR_LOG(gRemoteEventLog, PR_LOG_WARN, args)
50 
51 const static char* sPublicWProperties[] = { "" };
52 
53 const static char* sPublicRProperties[] =
54 {
55  // sbIPlaylistClickEvent
56  "helper:property",
57  "helper:item",
58 
59  // nsIDOMEventTarget
60  // N/A
61 
62  // nsIDOMMouseEvent
63  "helper:button",
64  "helper:ctrlKey",
65  "helper:altKey",
66  "helper:shiftKey",
67  "helper:metaKey",
68 
69  // nsIClassInfo
70  "classinfo:classDescription",
71  "classinfo:contractID",
72  "classinfo:classID",
73  "classinfo:implementationLanguage",
74  "classinfo:flags"
75 };
76 
77 const static char* sPublicMethods[] =
78 {
79  // no applicable methods
80  ""
81 };
82 
87  nsIDOMNSEvent,
89  nsIPrivateDOMEvent,
93 
94 NS_IMPL_CI_INTERFACE_GETTER7(sbRemotePlaylistClickEvent,
102 
103 SB_IMPL_CLASSINFO_INTERFACES_ONLY(sbRemotePlaylistClickEvent)
104 
105 SB_IMPL_SECURITYCHECKEDCOMP_INIT(sbRemotePlaylistClickEvent)
106 
107 sbRemotePlaylistClickEvent::sbRemotePlaylistClickEvent( sbRemotePlayer* aRemotePlayer ) :
108  mRemotePlayer(aRemotePlayer)
109 {
110  NS_ASSERTION(aRemotePlayer, "aRemotePlayer is null");
111  MOZ_COUNT_CTOR(sbRemotePlaylistClickEvent);
112 #ifdef PR_LOGGING
113  if (!gRemoteEventLog) {
114  gRemoteEventLog = PR_NewLogModule("sbRemotePlaylistClickEvent");
115  }
116  LOG(("sbRemotePlaylistClickEvent::sbRemotePlaylistClickEvent()"));
117 #endif
118 }
119 
121 {
122  MOZ_COUNT_DTOR(sbRemotePlaylistClickEvent);
123 }
124 
125 // ---------------------------------------------------------------------------
126 //
127 // sbISecurityAggregator
128 //
129 // ---------------------------------------------------------------------------
130 
131 NS_IMETHODIMP
132 sbRemotePlaylistClickEvent::GetRemotePlayer(sbIRemotePlayer * *aRemotePlayer)
133 {
134  NS_ENSURE_STATE(mRemotePlayer);
135  NS_ENSURE_ARG_POINTER(aRemotePlayer);
136 
137  nsresult rv;
138  *aRemotePlayer = nsnull;
139 
140  nsCOMPtr<sbIRemotePlayer> remotePlayer;
141 
142  rv = mRemotePlayer->QueryInterface( NS_GET_IID( sbIRemotePlayer ), getter_AddRefs( remotePlayer ) );
143  NS_ENSURE_SUCCESS( rv, rv );
144 
145  remotePlayer.swap( *aRemotePlayer );
146 
147  return NS_OK;
148 }
149 
150 // ---------------------------------------------------------------------------
151 //
152 // sbIPlaylistClickEvent
153 //
154 // ---------------------------------------------------------------------------
155 
157  nsIDOMMouseEvent* aMouseEvent )
158 {
159  NS_ENSURE_ARG( aClickEvent );
160  NS_ENSURE_ARG( aMouseEvent );
161  nsresult rv;
162 
163  nsCOMPtr<sbIMediaItem> item;
164  rv = aClickEvent->GetItem( getter_AddRefs(item) );
165  NS_ENSURE_SUCCESS(rv, rv);
166 
167  rv = SB_WrapMediaItem(mRemotePlayer, item, getter_AddRefs(mWrappedItem));
168  NS_ENSURE_SUCCESS(rv, rv);
169 
170  rv = aClickEvent->GetProperty( mProperty );
171  NS_ENSURE_SUCCESS(rv, rv);
172 
173  mMouseEvent = aMouseEvent;
174  mNSEvent = do_QueryInterface( mMouseEvent, &rv );
175  NS_ENSURE_SUCCESS(rv, rv);
176 
177  return NS_OK;
178 }
179 
180 /*** sbIPlaylistClickEvent ***/
181 /* readonly attribute AString property; */
182 NS_IMETHODIMP sbRemotePlaylistClickEvent::GetProperty(nsAString & aProperty)
183 {
184  // make sure ::InitEvent() has succeeded properly (mNSEvent is the last thing)
185  NS_ENSURE_STATE(mNSEvent);
186 
187  aProperty.Assign(mProperty);
188  return NS_OK;
189 }
190 
191 /* readonly attribute sbIMediaItem item; */
192 NS_IMETHODIMP sbRemotePlaylistClickEvent::GetItem(sbIMediaItem * *aItem)
193 {
194  NS_ENSURE_ARG(aItem);
195 
196  if (!mWrappedItem) {
197  *aItem = nsnull;
198  return NS_OK;
199  }
200  NS_IF_ADDREF(*aItem = mWrappedItem.get());
201  return (*aItem ? NS_OK : NS_ERROR_FAILURE);
202 }
203 
204 /*** nsIPrivateDOMEvent ***/
205 // this macro forwards a method to the inner mouse event (up to one arg)
206 #define FORWARD_NSIPRIVATEDOMEVENT(_method, _type, _arg, _rettype, _default) \
207  NS_IMETHODIMP_(_rettype) sbRemotePlaylistClickEvent::_method( _type _arg ) \
208  { \
209  nsresult rv; \
210  nsCOMPtr<nsIPrivateDOMEvent> inner( do_QueryInterface(mMouseEvent, &rv) ); \
211  NS_ENSURE_SUCCESS(rv, _default); \
212  return inner->_method( _arg ); \
213  }
214 
215 FORWARD_NSIPRIVATEDOMEVENT(DuplicatePrivateData, , , nsresult, rv)
216 FORWARD_NSIPRIVATEDOMEVENT(SetTarget, nsIDOMEventTarget*, aTarget, nsresult, rv)
217 FORWARD_NSIPRIVATEDOMEVENT(IsDispatchStopped, , , PRBool, PR_FALSE)
218 FORWARD_NSIPRIVATEDOMEVENT(GetInternalNSEvent, , , nsEvent*, nsnull)
219 FORWARD_NSIPRIVATEDOMEVENT(SetTrusted, PRBool, aTrusted, nsresult, rv)
nsCOMPtr< sbIMediaItem > mWrappedItem
NS_IMPL_ISUPPORTS9(sbRemotePlaylistClickEvent, nsIClassInfo, nsIDOMEvent, nsIDOMMouseEvent, nsIDOMNSEvent, nsIDOMUIEvent, nsIPrivateDOMEvent, nsISecurityCheckedComponent, sbIPlaylistClickEvent, sbISecurityAggregator) NS_IMPL_CI_INTERFACE_GETTER7(sbRemotePlaylistClickEvent
static const char * sPublicWProperties[]
#define SB_IMPL_SECURITYCHECKEDCOMP_INIT(_class)
Definition: sbRemoteAPI.h:82
return NS_OK
static const char * sPublicRProperties[]
readonly attribute sbIRemotePlayer remotePlayer
This interface is a composition of many of our other interfaces with the goal of exposing a more web-...
an interface to maintain information about the last event that occurred
#define LOG(args)
#define FORWARD_NSIPRIVATEDOMEVENT(_method, _type, _arg, _rettype, _default)
A marker interface for objects that aggregate the security mixin.
readonly attribute sbIMediaItem item
NS_IMETHOD InitEvent(sbIPlaylistClickEvent *, nsIDOMMouseEvent *)
static nsresult GetProperty(nsIPropertyBag2 *aProperties, nsAString const &aProp, nsAString &aValue)
nsCOMPtr< nsIDOMMouseEvent > mMouseEvent
nsRefPtr< sbRemotePlayer > mRemotePlayer
nsCOMPtr< nsIDOMNSEvent > mNSEvent
static nsresult SB_WrapMediaItem(sbRemotePlayer *aRemotePlayer, sbIMediaItem *aMediaItem, sbIMediaItem **aRemoteMediaItem)
Interface that defines a single item of media in the system.
static const char * sPublicMethods[]
#define SB_IMPL_CLASSINFO_INTERFACES_ONLY(_class)