sbRemotePlayer.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_PLAYER_H__
28 #define __SB_REMOTE_PLAYER_H__
29 
30 #include "sbRemoteAPI.h"
31 #include "sbRemoteMediaListBase.h"
33 #include "sbRemoteWebPlaylist.h"
34 
35 #include <sbIDataRemote.h>
36 #include <sbIDownloadDevice.h>
37 #include <sbIMediaList.h>
38 #include <sbIMediacoreEventListener.h>
39 #include <sbIMediacoreManager.h>
40 #include <sbIRemoteLibrary.h>
41 #include <sbIRemoteObserver.h>
42 #include <sbIRemotePlayer.h>
43 #include <sbISecurityAggregator.h>
44 
45 #include <nsAutoPtr.h>
46 #include <nsCOMPtr.h>
47 #include <nsDataHashtable.h>
48 #include <nsInterfaceHashtable.h>
49 #include <nsIClassInfo.h>
50 #include <nsIDOMEventListener.h>
51 #include <nsIGenericFactory.h>
52 #include <nsIIOService.h>
53 #include <nsISecurityCheckedComponent.h>
54 #include <nsIWeakReference.h>
55 #include <nsPIDOMWindow.h>
56 #include <nsStringGlue.h>
57 #include <nsWeakReference.h>
58 
59 #define SONGBIRD_REMOTEPLAYER_CONTRACTID \
60  "@songbirdnest.com/remoteapi/remoteplayer;1"
61 #define SONGBIRD_REMOTEPLAYER_CLASSNAME \
62  "Songbird Remote Player"
63 #define SONGBIRD_REMOTEPLAYER_CID \
64 { /* 645e064c-e547-444c-bb41-8f2e5b12700b */ \
65  0x645e064c, \
66  0xe547, \
67  0x444c, \
68  {0xbb, 0x41, 0x8f, 0x2e, 0x5b, 0x12, 0x70, 0x0b} \
69 }
70 
72  nsCOMPtr<sbIRemoteObserver> observer;
73  nsCOMPtr<sbIDataRemote> remote;
74 };
75 
76 class sbRemoteCommands;
77 class sbIDataRemote;
78 #ifdef METRICS_ENABLED
79 class sbIMetrics;
80 #endif
82 
84  public nsIClassInfo,
85  public nsIDOMEventListener,
87  public nsSupportsWeakReference,
90 {
92 
93 public:
94  NS_DECL_SBIREMOTEPLAYER
96  NS_DECL_NSICLASSINFO
97  NS_DECL_NSIDOMEVENTLISTENER
98  NS_FORWARD_SAFE_NSISECURITYCHECKEDCOMPONENT(mSecurityMixin)
99  NS_DECL_SBISECURITYAGGREGATOR
100  NS_DECL_SBIMEDIACOREEVENTLISTENER
101 
102  sbRemotePlayer();
103 
104  nsresult Init();
105  nsresult InitPrivileged(nsIURI* aCodebase, nsIDOMWindow* aWindow);
106 
107  static NS_METHOD Register(nsIComponentManager* aCompMgr,
108  nsIFile* aPath,
109  const char *aLoaderStr,
110  const char *aType,
111  const nsModuleComponentInfo *aInfo);
112  static NS_METHOD Unregister(nsIComponentManager* aCompMgr,
113  nsIFile* aPath,
114  const char *aLoaderStr,
115  const nsModuleComponentInfo *aInfo);
116  static nsresult DispatchEvent( nsIDOMDocument *aDocument,
117  const nsAString &aClass,
118  const nsAString &aType,
119  PRBool aIsTrusted );
120  static nsresult DispatchSecurityEvent( nsIDOMDocument *aDoc,
121  sbIRemotePlayer *aPlayer,
122  const nsAString &aClass,
123  const nsAString &aType,
124  const nsAString &aCategoryID,
125  PRBool aHasAccess,
126  PRBool aIsTrusted);
127 
128  PRBool IsPrivileged();
129 
130  static nsresult GetJSScopeNameFromScope( const nsACString &aScopeName,
131  nsAString &aJSScopeName );
132 
134 
135  static PRBool GetUserApprovalForHost( nsIURI *aURI,
136  const nsAString &aTitleKey,
137  const nsAString &aMessageKey,
138  const char* aScopedName = nsnull );
139  nsresult SetOriginScope( sbIMediaItem *aItem,
140  const nsAString& aSiteID );
141  nsresult GetSiteScopeURL(nsAString &aURL);
142  already_AddRefed<nsIURI> GetSiteScopeURI();
143 
144  already_AddRefed<nsPIDOMWindow> GetWindow();
145 
146  static already_AddRefed<nsPIDOMWindow> GetWindowFromJS();
147 
148 protected:
149  virtual ~sbRemotePlayer();
150 
151  // Helper Methods
152  nsresult InitInternal(nsPIDOMWindow* aWindow);
153  nsresult InitRemoteWebPlaylist();
154  nsresult RegisterCommands( PRBool aUseDefaultCommands );
155  nsresult UnregisterCommands();
156  nsresult ConfirmPlaybackControl();
157  nsresult GetBrowser( nsIDOMElement** aElement );
158  nsresult TakePlaybackControl( nsIURI* aURI );
159  nsresult SetDownloadScope( sbIMediaItem *aItem,
160  const nsAString& aSiteID );
161  nsresult CreateProperty( const nsAString& aPropertyType,
162  const nsAString& aPropertyID,
163  const nsAString& aDisplayName,
164  const nsAString& aButtonLabel,
165  PRInt32 aTimeType,
166  PRBool aReadonly,
167  PRBool aUserViewable,
168  PRUint32 aNullSort );
169 
170  // Event handlers for mediacore
171  nsresult OnStop();
172 
173  nsresult OnBeforeTrackChange(sbIMediacoreEvent *aEvent);
174  nsresult OnTrackChange(sbIMediacoreEvent *aEvent);
175  nsresult OnTrackIndexChange(sbIMediacoreEvent *aEvent);
176 
177  nsresult OnBeforeViewChange(sbIMediacoreEvent *aEvent);
178  nsresult OnViewChange(sbIMediacoreEvent *aEvent);
179 
180  // Data members
181  PRBool mInitialized;
183  PRBool mPrivileged;
184  nsCOMPtr<nsIWeakReference> mMM;
185  nsCOMPtr<nsIIOService> mIOService;
186 
187  // The documents for the web page and for the tabbrowser
188  nsCOMPtr<nsIDOMDocument> mContentDoc;
189  nsCOMPtr<nsIDOMDocument> mChromeDoc;
190 
191  // the remote impl for the playlist binding
193 
194  // The download device callback
196 
197  // the domain and path to use for scope
198  // @see setSiteScope()
199  nsCString mScopeDomain;
200  nsCString mScopePath;
201 
202  // the computed siteScopeURL and URI.
203  nsString mSiteScopeURL;
204  nsCOMPtr<nsIURI> mSiteScopeURI;
205 
206  // Like the site libraries, this may want to be a collection
207  // The commands registered by the page.
209 
210  // Hashtable to hold the observers registered by the webpage
211  nsDataHashtable<nsStringHashKey, sbRemoteObserver> mRemObsHash;
212 
213  // Hashtable to hold all the libraries that we generate
214  nsInterfaceHashtable<nsStringHashKey, sbIRemoteLibrary> mCachedLibraries;
215 
216  // stash these for quick reference
227 
228  // SecurityCheckedComponent vars
230 
232 #ifdef METRICS_ENABLED
233  nsCOMPtr<sbIMetrics> mMetrics;
234 #endif
235  nsCOMPtr<nsPIDOMWindow> mPrivWindow;
236 };
237 
239 {
240 public:
242  NS_DECL_SBIDEVICEBASECALLBACK
243 
246 
247  nsresult Initialize(sbRemotePlayer* aRemotePlayer);
248 
249  void Finalize();
250 
251 private:
252  nsCOMPtr<nsIWeakReference> mWeakRemotePlayer;
253  nsCOMPtr<sbIDeviceBase> mDownloadDevice;
254  nsCOMPtr<nsIURI> mCodebaseURI;
255  nsCOMPtr<nsIIOService> mIOService;
256 
257  nsresult GetItemScope( sbIMediaItem* aMediaItem,
258  nsACString& aScopeDomain,
259  nsACString& aScopePath );
260  nsresult CheckItemScope( sbIMediaItem* aMediaItem );
261 };
262 
263 #endif // __SB_REMOTE_PLAYER_H__
nsresult InitPrivileged(nsIURI *aCodebase, nsIDOMWindow *aWindow)
PRBool mUseDefaultCommands
nsCOMPtr< sbIDataRemote > mdrRepeat
nsresult OnViewChange(sbIMediacoreEvent *aEvent)
static PRBool GetUserApprovalForHost(nsIURI *aURI, const nsAString &aTitleKey, const nsAString &aMessageKey, const char *aScopedName=nsnull)
nsCOMPtr< sbIDataRemote > mdrCurrentAlbum
_updateCookies aPath
nsCString mScopePath
static already_AddRefed< nsPIDOMWindow > GetWindowFromJS()
nsresult ConfirmPlaybackControl()
nsCOMPtr< sbIDataRemote > mdrMute
nsRefPtr< sbRemoteCommands > mCommandsObject
Metrics service interface This is an interface to the songbird metrics service, used to phone home an...
Definition: sbIMetrics.idl:44
nsCOMPtr< sbIDataRemote > mdrPlaying
nsresult InitInternal(nsPIDOMWindow *aWindow)
This interface is a composition of many of our other interfaces with the goal of exposing a more web-...
already_AddRefed< nsIURI > GetSiteScopeURI()
nsCOMPtr< nsIDOMDocument > mContentDoc
nsRefPtr< sbRemoteWebPlaylist > mRemWebPlaylist
nsCOMPtr< nsPIDOMWindow > mPrivWindow
nsCOMPtr< nsIWeakReference > mMM
nsString mSiteScopeURL
nsresult SetOriginScope(sbIMediaItem *aItem, const nsAString &aSiteID)
An interface for accessing, and binding to, stored data.
[SOON TO BE DEPRECATED AFTER 0.3] The callback class for sbIDeviceBase
nsISecurityCheckedComponent
NS_DECL_ISUPPORTS NS_DECL_SBIDEVICEBASECALLBACK sbRemotePlayerDownloadCallback()
static NS_METHOD Register(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const char *aType, const nsModuleComponentInfo *aInfo)
nsDataHashtable< nsStringHashKey, sbRemoteObserver > mRemObsHash
static nsresult DispatchEvent(nsIDOMDocument *aDocument, const nsAString &aClass, const nsAString &aType, PRBool aIsTrusted)
Definition of the sbIMediacoreEvent interface.
nsCOMPtr< nsIIOService > mIOService
const nsIDOMWindow
nsresult OnBeforeViewChange(sbIMediacoreEvent *aEvent)
_collectFormDataForFrame aDocument
nsRefPtr< sbRemoteNotificationManager > mNotificationMgr
nsresult SetDownloadScope(sbIMediaItem *aItem, const nsAString &aSiteID)
nsCString mScopeDomain
nsCOMPtr< nsISecurityCheckedComponent > mSecurityMixin
nsresult InitRemoteWebPlaylist()
nsCOMPtr< nsIDOMDocument > mChromeDoc
nsCOMPtr< sbIDataRemote > mdrCurrentTrack
A marker interface for objects that aggregate the security mixin.
nsresult OnTrackChange(sbIMediacoreEvent *aEvent)
nsresult OnTrackIndexChange(sbIMediacoreEvent *aEvent)
already_AddRefed< nsPIDOMWindow > GetWindow()
nsCOMPtr< sbIDataRemote > mdrShuffle
An interface to control a media library from remote web pages.
nsCOMPtr< sbIDataRemote > mdrPosition
nsresult GetBrowser(nsIDOMElement **aElement)
nsresult OnBeforeTrackChange(sbIMediacoreEvent *aEvent)
nsCOMPtr< sbIDataRemote > mdrCurrentArtist
nsRefPtr< sbRemotePlayerDownloadCallback > mDownloadCallback
nsCOMPtr< sbIDataRemote > mdrPaused
nsresult CreateProperty(const nsAString &aPropertyType, const nsAString &aPropertyID, const nsAString &aDisplayName, const nsAString &aButtonLabel, PRInt32 aTimeType, PRBool aReadonly, PRBool aUserViewable, PRUint32 aNullSort)
nsCOMPtr< sbIDataRemote > remote
static nsresult GetJSScopeNameFromScope(const nsACString &aScopeName, nsAString &aJSScopeName)
nsresult UnregisterCommands()
nsresult RegisterCommands(PRBool aUseDefaultCommands)
nsresult TakePlaybackControl(nsIURI *aURI)
static nsresult DispatchSecurityEvent(nsIDOMDocument *aDoc, sbIRemotePlayer *aPlayer, const nsAString &aClass, const nsAString &aType, const nsAString &aCategoryID, PRBool aHasAccess, PRBool aIsTrusted)
nsresult Initialize(sbRemotePlayer *aRemotePlayer)
static NS_METHOD Unregister(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const nsModuleComponentInfo *aInfo)
Interface that defines a single item of media in the system.
sbRemoteNotificationManager * GetNotificationManager()
nsCOMPtr< sbIRemoteObserver > observer
nsInterfaceHashtable< nsStringHashKey, sbIRemoteLibrary > mCachedLibraries
nsCOMPtr< nsIURI > mSiteScopeURI
nsCOMPtr< sbIDataRemote > mdrVolume
nsIDOMEventListener
nsresult GetSiteScopeURL(nsAString &aURL)