42 #include <sbIDataRemote.h>
43 #include <sbIDeviceManager.h>
44 #include <sbIDownloadDevice.h>
45 #include <sbILibrary.h>
46 #include <sbIMediacoreEvent.h>
47 #include <sbIMediacoreEventTarget.h>
48 #include <sbIMediacoreManager.h>
49 #include <sbIMediacorePlaybackControl.h>
50 #include <sbIMediacoreSequencer.h>
51 #include <sbIMediacoreVolumeControl.h>
52 #include <sbIMediaList.h>
53 #include <sbIMediaListView.h>
54 #ifdef METRICS_ENABLED
55 #include <sbIMetrics.h>
57 #include <sbIRemoteAPIService.h>
58 #include <sbIPlaylistClickEvent.h>
59 #include <sbIPlaylistCommands.h>
60 #include <sbITabBrowser.h>
61 #include <sbIPropertyInfo.h>
62 #include <sbIPropertyManager.h>
65 #include <sbIPropertyBuilder.h>
68 #include <nsAutoPtr.h>
69 #include <nsDOMJSUtils.h>
71 #include <nsICategoryManager.h>
72 #include <nsIContentViewer.h>
73 #include <nsIDocShell.h>
74 #include <nsIDocShellTreeItem.h>
75 #include <nsIDocShellTreeOwner.h>
76 #include <nsIDocument.h>
77 #include <nsIDOMDocument.h>
78 #include <nsIDOMDocumentEvent.h>
79 #include <nsIDOMElement.h>
80 #include <nsIDOMEvent.h>
81 #include <nsIDOMEventTarget.h>
82 #include <nsIDOMMouseEvent.h>
83 #include <nsIDOMNodeList.h>
84 #include <nsIDOMNSEvent.h>
85 #include <nsIDOMWindow.h>
86 #include <nsPIDOMWindow.h>
87 #include <nsIDOMWindowInternal.h>
88 #include <nsIDOMXULDocument.h>
89 #include <nsIDOMXULElement.h>
90 #include <nsIInterfaceRequestorUtils.h>
91 #include <nsIJSContextStack.h>
92 #include <nsIPrefBranch.h>
93 #include <nsIPresShell.h>
94 #include <nsIPrivateDOMEvent.h>
95 #include <nsIPromptService.h>
96 #include <nsIScriptGlobalObject.h>
97 #include <nsIScriptNameSpaceManager.h>
98 #include <nsIStringBundle.h>
99 #include <nsITreeSelection.h>
100 #include <nsITreeView.h>
102 #include <nsIVariant.h>
103 #include <nsIWindowMediator.h>
104 #include <nsMemory.h>
105 #include <nsNetUtil.h>
106 #include <nsServiceManagerUtils.h>
107 #include <nsStringGlue.h>
111 #include <sbIDeviceBase.h>
112 #include <sbIDeviceManager.h>
113 #include <sbILibraryManager.h>
114 #include <nsIDialogParamBlock.h>
115 #include <nsISupportsPrimitives.h>
116 #include <nsIWindowWatcher.h>
123 static PRLogModuleInfo* gRemotePlayerLog = nsnull;
128 #define LOG(args) PR_LOG(gRemotePlayerLog, PR_LOG_WARN, args)
129 #define TRACE(args) PR_LOG(gRemotePlayerLog, PR_LOG_DEBUG, args)
131 #define __FUNCTION__ __PRETTY_FUNCTION__
137 {
"playback_control:position" };
140 {
"site:apiVersionMajor",
141 "site:apiVersionMinor",
151 "library_read:playlists",
156 "site:downloadMediaList",
157 "playback_read:currentArtist",
158 "playback_read:currentAlbum",
159 "playback_read:currentTrack",
161 "classinfo:classDescription",
162 "classinfo:contractID",
164 "classinfo:implementationLanguage",
168 {
"playback_control:play",
169 "playback_control:playMediaList",
170 "playback_control:stop",
171 "playback_control:pause",
172 "playback_control:previous",
173 "playback_control:next",
174 "playback_control:playURL",
175 "library_write:downloadItem",
176 "library_write:downloadList",
177 "library_write:downloadSelected",
179 "library_read:libraries",
180 "playback_read:removeListener",
181 "playback_read:addListener",
182 "site:supportsVersion",
183 "site:createTextProperty",
184 "site:createDateTimeProperty",
185 "site:createURIProperty",
186 "site:createNumberProperty",
187 "site:createImageProperty",
188 "site:createRatingsProperty",
189 "site:createButtonProperty",
190 "site:createDownloadButtonProperty",
202 "metadata.position.str",
203 "metadata.length.str",
206 "playlist.shuffle.disabled",
210 "faceplate.paused" };
217 { {
"Control Playback",
"playback_control:" },
218 {
"Read Current",
"playback_read:" },
219 {
"Read Library",
"library_read:" },
220 {
"Modify Library",
"library_write:" } };
223 #define RAPI_EVENT_CLASS NS_LITERAL_STRING("Events")
224 #define RAPI_EVENT_TYPE NS_LITERAL_STRING("remoteapi")
225 #define RAPI_EVENT_TYPE_DOWNLOADSTART NS_LITERAL_STRING("downloadstart")
226 #define RAPI_EVENT_TYPE_DOWNLOADCOMPLETE NS_LITERAL_STRING("downloadcomplete")
227 #define RAPI_EVENT_TYPE_BEFORETRACKCHANGE NS_LITERAL_STRING("beforetrackchange")
228 #define RAPI_EVENT_TYPE_TRACKCHANGE NS_LITERAL_STRING("trackchange")
229 #define RAPI_EVENT_TYPE_TRACKINDEXCHANGE NS_LITERAL_STRING("trackindexchange")
230 #define RAPI_EVENT_TYPE_BEFOREVIEW NS_LITERAL_STRING("beforeviewchange")
231 #define RAPI_EVENT_TYPE_VIEW NS_LITERAL_STRING("viewchange")
232 #define RAPI_EVENT_TYPE_STOP NS_LITERAL_STRING("playbackstopped")
233 #define SB_PREFS_ROOT NS_LITERAL_STRING("songbird.")
234 #define SB_EVENT_CMNDS_UP NS_LITERAL_STRING("playlist-commands-updated")
235 #define SB_WEB_TABBROWSER NS_LITERAL_STRING("sb-tabbrowser")
237 #define SB_LIB_NAME_MAIN "main"
238 #define SB_LIB_NAME_WEB "web"
240 #define SB_DATAREMOTE_FACEPLATE_STATUS NS_LITERAL_STRING("faceplate.status.override.text")
242 #define RAPI_VERSION_MAJOR 1
243 #define RAPI_VERSION_MINOR 0
251 LOG((
"UnbindAndRelease(%s, %x %x)", PromiseFlatString(aKey).
get(), aRemObs.observer.get(), aRemObs.remote.get()));
252 NS_ASSERTION(&aRemObs,
"GAH! Hashtable contains a null entry");
253 NS_ASSERTION(aRemObs.remote,
"GAH! Container contains a null remote");
254 NS_ASSERTION(aRemObs.observer,
"GAH! Container contains a null observer");
256 aRemObs.remote->Unbind();
257 return PL_DHASH_REMOVE;
267 mStack = do_GetService(
"@mozilla.org/js/xpc/ContextStack;1");
269 nsresult rv =
mStack->Push(nsnull);
284 operator PRBool()
const
286 return mStack ? PR_TRUE : PR_FALSE ;
302 NS_ENSURE_ARG(_retval);
312 NS_ENSURE_ARG(_retval);
315 mArray.AppendObject( aItem );
320 nsCOMArray<sbIMediaItem>& mArray;
334 nsISecurityCheckedComponent,
337 nsISupportsWeakReference,
338 sbIMediacoreEventListener,
344 nsIProgrammingLanguage::CPLUSPLUS,
348 sbRemotePlayer::sbRemotePlayer() :
350 mPrivileged(PR_FALSE)
353 if (!gRemotePlayerLog) {
354 gRemotePlayerLog = PR_NewLogModule(
"sbRemotePlayer");
357 LOG((
"sbRemotePlayer::sbRemotePlayer()"));
362 LOG((
"sbRemotePlayer::~sbRemotePlayer()"));
378 LOG((
"sbRemotePlayer::Init()"));
390 NS_ENSURE_TRUE(privWindow, NS_ERROR_UNEXPECTED);
395 NS_ENSURE_SUCCESS(rv, rv);
403 LOG((
"sbRemotePlayer::InitPrivileged()"));
405 NS_ASSERTION(aCodebase,
"aCodebase is null");
406 NS_ASSERTION(aWindow,
"aWindow is null");
411 NS_ENSURE_SUCCESS(rv, rv);
414 rv = aCodebase->GetSpec(spec);
415 NS_ENSURE_SUCCESS(rv, rv);
419 nsCOMPtr<nsPIDOMWindow> privWindow = do_QueryInterface(aWindow, &rv);
420 NS_ENSURE_SUCCESS(rv, rv);
425 NS_ENSURE_SUCCESS(rv, rv);
433 LOG((
"sbRemotePlayer::InitInternal()"));
435 NS_ASSERTION(aWindow,
"aWindow is null");
440 nsCOMPtr<nsISupportsWeakReference> weakRef =
442 NS_ENSURE_SUCCESS(rv, rv);
444 rv = weakRef->GetWeakReference(getter_AddRefs(
mMM));
445 NS_ENSURE_SUCCESS(rv, rv);
447 mIOService = do_GetService(
"@mozilla.org/network/io-service;1", &rv);
448 NS_ENSURE_SUCCESS( rv, rv );
451 NS_ENSURE_TRUE( success, NS_ERROR_FAILURE );
454 NS_ENSURE_TRUE( success, NS_ERROR_FAILURE );
457 NS_ENSURE_TRUE( mixin, NS_ERROR_OUT_OF_MEMORY );
462 GetInterfaces(&iidCount, &iids);
466 (
const nsIID**)iids, iidCount,
471 NS_ENSURE_SUCCESS( rv, rv );
472 NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(iidCount, iids);
476 NS_ENSURE_SUCCESS( rv, rv );
488 rv = mixin->SetNotificationDocument(
mContentDoc );
489 NS_ENSURE_SUCCESS( rv, rv );
495 NS_ENSURE_STATE(docShell);
497 nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryInterface(docShell, &rv);
498 NS_ENSURE_SUCCESS(rv, rv);
500 nsCOMPtr<nsIDocShellTreeItem> rootItem;
501 rv = treeItem->GetRootTreeItem(getter_AddRefs(rootItem));
502 NS_ENSURE_SUCCESS(rv, rv);
504 nsCOMPtr<nsIDocShell> rootShell = do_QueryInterface(rootItem, &rv);
505 NS_ENSURE_SUCCESS(rv, rv);
507 nsCOMPtr<nsIContentViewer> contentViewer;
508 rv = rootShell->GetContentViewer(getter_AddRefs(contentViewer));
509 NS_ENSURE_SUCCESS(rv, rv);
511 rv = contentViewer->GetDOMDocument(getter_AddRefs(
mChromeDoc));
512 NS_ENSURE_SUCCESS(rv, rv);
515 LOG((
"sbRemotePlayer::Init() -- registering unload listener"));
518 NS_ENSURE_STATE(eventTarget);
519 eventTarget->AddEventListener( NS_LITERAL_STRING(
"unload"),
this , PR_TRUE );
521 LOG((
"sbRemotePlayer::Init() -- registering PlaylistCellClick listener"));
522 eventTarget->AddEventListener( NS_LITERAL_STRING(
"PlaylistCellClick"),
this , PR_TRUE );
524 LOG((
"sbRemotePlayer::Init() -- registering RemoteAPIPermissionDenied listener"));
527 LOG((
"sbRemotePlayer::Init() -- registering RemoteAPIPermissionChanged listener"));
534 NS_ENSURE_SUCCESS(rv, rv);
537 LOG((
"sbRemotePlayer::Init() -- registering playback listener"));
538 nsCOMPtr<sbIMediacoreEventTarget>
target =
539 do_QueryReferent(
mMM, &rv);
540 NS_ENSURE_SUCCESS(rv, rv);
542 rv = target->AddListener(
this);
543 NS_ENSURE_SUCCESS(rv, rv);
549 NS_ENSURE_SUCCESS(rv, rv);
551 #ifdef METRICS_ENABLED
553 mMetrics = do_CreateInstance(
"@songbirdnest.com/Songbird/Metrics;1", &rv);
554 NS_ENSURE_SUCCESS(rv, rv);
557 rv = mMetrics->MetricsInc(NS_LITERAL_STRING(
"rapi.sessionStarted"),
560 NS_ENSURE_SUCCESS(rv, rv);
577 NS_ENSURE_ARG_POINTER(aRemotePlayer);
580 *aRemotePlayer = nsnull;
585 NS_ENSURE_SUCCESS( rv, rv );
587 remotePlayer.swap( *aRemotePlayer );
599 sbRemotePlayer::SupportsVersion(
const nsAString &aAPIVersion,
600 PRBool *aSupportsVersion )
602 NS_ENSURE_ARG_POINTER(aSupportsVersion);
603 NS_ENSURE_TRUE(!aAPIVersion.IsEmpty(), NS_ERROR_INVALID_ARG);
605 *aSupportsVersion = PR_FALSE;
607 nsTArray<nsString> substrings;
610 nsresult rv = NS_ERROR_UNEXPECTED;
611 PRInt32 majorVersion = substrings[0].ToInteger(&rv);
612 NS_ENSURE_SUCCESS(rv, rv);
623 if(substrings.Length() > 1) {
624 PRInt32 minorVersion = substrings[1].ToInteger(&rv);
625 NS_ENSURE_SUCCESS(rv, rv);
628 *aSupportsVersion = PR_TRUE;
634 *aSupportsVersion = PR_TRUE;
641 sbRemotePlayer::GetApiVersionMajor( PRUint32 *aApiVersionMajor )
643 NS_ENSURE_ARG_POINTER(aApiVersionMajor);
651 sbRemotePlayer::GetApiVersionMinor( PRUint32 *aApiVersionMinor )
653 NS_ENSURE_ARG_POINTER(aApiVersionMinor);
661 sbRemotePlayer::GetName( nsAString &
aName )
663 LOG((
"sbRemotePlayer::GetName()"));
664 aName.AssignLiteral(
"Songbird");
681 sbRemotePlayer::Libraries(
const nsAString &aLibraryID,
684 NS_ENSURE_ARG_POINTER(aLibrary);
685 LOG((
"sbRemotePlayer::Libraries(%s)",
686 NS_LossyConvertUTF16toASCII(aLibraryID).
get() ));
696 nsRefPtr<sbRemoteLibrary> library;
701 LOG((
"sbRemotePlayer::Libraries() - creating main library"));
703 NS_ENSURE_TRUE( library, NS_ERROR_OUT_OF_MEMORY );
707 LOG((
"sbRemotePlayer::Libraries() - creating web library"));
709 NS_ENSURE_TRUE( library, NS_ERROR_OUT_OF_MEMORY );
713 return NS_ERROR_INVALID_ARG;
716 rv = library->Init();
717 NS_ENSURE_SUCCESS( rv, rv );
719 rv = library->ConnectToDefaultLibrary( aLibraryID );
720 NS_ENSURE_SUCCESS( rv, rv );
722 nsCOMPtr<sbIRemoteLibrary> remoteLibrary =
724 NS_ENSURE_SUCCESS( rv, rv );
729 NS_WARNING(
"Failed to cache remoteLibrary!");
732 NS_ADDREF( *aLibrary = remoteLibrary );
737 sbRemotePlayer::SetSiteScope(
const nsACString & aDomain,
const nsACString &
aPath)
742 NS_WARNING(
"sbRemotePlayer::SetSiteScope() - skipping multiple site library checks");
744 NS_ENSURE_TRUE(
mScopeDomain.IsVoid(), NS_ERROR_ALREADY_INITIALIZED );
745 NS_ENSURE_TRUE(
mScopePath.IsVoid(), NS_ERROR_ALREADY_INITIALIZED );
748 nsCString domain(aDomain);
749 nsCString
path(aPath);
750 nsCOMPtr<nsIURI> codebaseURI;
751 nsCOMPtr<sbISecurityMixin> mixin = do_QueryInterface(
mSecurityMixin, &rv );
752 NS_ENSURE_SUCCESS( rv, rv );
753 rv = mixin->GetCodebase( getter_AddRefs(codebaseURI) );
754 NS_ENSURE_SUCCESS( rv, rv );
757 NS_ENSURE_SUCCESS( rv, rv );
766 sbRemotePlayer::GetSiteScope(nsIURI * *aURI)
768 NS_ENSURE_ARG_POINTER(aURI);
779 LOG((
"sbRemotePlayer::GetSiteLibrary(%s)",
mScopePath.BeginReading() ));
788 nsString siteLibraryFilename;
791 siteLibraryFilename );
792 NS_ENSURE_SUCCESS( rv, rv );
798 nsRefPtr<sbRemoteSiteLibrary> library;
800 NS_ENSURE_TRUE( library, NS_ERROR_OUT_OF_MEMORY );
802 rv = library->Init();
803 NS_ENSURE_SUCCESS( rv, rv );
806 NS_ENSURE_SUCCESS( rv, rv );
808 nsCOMPtr<sbIRemoteLibrary> remoteLibrary(
811 NS_ENSURE_SUCCESS( rv, rv );
813 PRBool success =
mCachedLibraries.Put( siteLibraryFilename, remoteLibrary );
814 NS_ENSURE_TRUE( success, NS_ERROR_FAILURE );
816 NS_ADDREF( *aSiteLibrary = remoteLibrary );
823 NS_ENSURE_ARG_POINTER(aCommandsObject);
825 LOG((
"sbRemotePlayer::GetCommands()"));
829 LOG((
"sbRemotePlayer::GetCommands() -- creating it"));
834 NS_ENSURE_SUCCESS( rv, rv );
853 nsCOMPtr<sbIPlaylistCommandsManager> mgr(
854 do_GetService(
"@songbirdnest.com/Songbird/PlaylistCommandsManager;1", &rv ) );
855 NS_ENSURE_SUCCESS( rv, rv );
858 NS_ENSURE_TRUE( commands, NS_ERROR_UNEXPECTED );
863 NS_ENSURE_SUCCESS( rv, rv );
864 rv = mgr->RegisterPlaylistCommandsMediaItem( NS_LITERAL_STRING(
"remote-test-guid"),
865 NS_LITERAL_STRING(
"library"),
867 NS_ASSERTION( NS_SUCCEEDED(rv),
868 "Failed to register commands in playlistcommandsmanager" );
869 rv = mgr->RegisterPlaylistCommandsMediaItem( NS_LITERAL_STRING(
"remote-test-guid"),
870 NS_LITERAL_STRING(
"simple"),
872 NS_ASSERTION( NS_SUCCEEDED(rv),
873 "Failed to register commands in playlistcommandsmanager" );
881 sbRemotePlayer::OnCommandsChanged()
883 LOG((
"sbRemotePlayer::OnCommandsChanged()"));
886 NS_ENSURE_SUCCESS( rv, rv );
906 LOG((
"sbRemotePlayer::GetWebPlaylist()"));
907 NS_ENSURE_ARG_POINTER(aWebPlaylist);
912 NS_ENSURE_SUCCESS( rv, rv );
915 nsCOMPtr<sbIRemoteWebPlaylist> remotePlaylist( do_QueryInterface(
917 NS_ENSURE_SUCCESS( rv, rv );
919 NS_ADDREF( *aWebPlaylist = remotePlaylist );
926 LOG((
"sbRemotePlayer::GetDownloadMediaList()"));
927 NS_ENSURE_ARG_POINTER(aDownloadMediaList);
930 nsCOMPtr<sbIDownloadDeviceHelper> dh(
931 do_GetService(
"@songbirdnest.com/Songbird/DownloadDeviceHelper;1", &rv ));
932 NS_ENSURE_SUCCESS( rv, rv );
935 rv = dh->GetDownloadMediaList(getter_AddRefs(downloadMediaList));
936 NS_ENSURE_SUCCESS( rv, rv );
939 NS_ENSURE_SUCCESS( rv, rv );
947 LOG((
"sbRemotePlayer::DownloadItem()"));
949 NS_ENSURE_ARG_POINTER(aItem);
954 nsCOMPtr<sbIMediaList> listcheck (do_QueryInterface(aItem));
955 NS_ENSURE_FALSE( listcheck, NS_ERROR_INVALID_ARG );
957 nsCOMPtr<sbIMediaItem> item;
960 nsCOMPtr<sbIWrappedMediaItem> wrappedItem(do_QueryInterface( aItem, &rv ));
961 if (NS_SUCCEEDED(rv)) {
962 item = wrappedItem->GetMediaItem();
963 NS_ASSERTION( item,
"GetMediaItem returned null!" );
969 nsCOMPtr<sbIDownloadDeviceHelper> dh(
970 do_GetService(
"@songbirdnest.com/Songbird/DownloadDeviceHelper;1", &rv ));
971 NS_ENSURE_SUCCESS( rv, rv );
974 dh->DownloadItem(item);
984 LOG((
"sbRemotePlayer::DownloadList()"));
986 NS_ENSURE_ARG_POINTER(aList);
988 nsCOMPtr<sbIMediaList> list;
992 nsCOMPtr<sbIWrappedMediaList> wrappedList(do_QueryInterface( aList, &rv ));
993 if (NS_SUCCEEDED(rv)) {
994 list = wrappedList->GetMediaList();
995 NS_ASSERTION( list,
"GetMediaList returned null!" );
998 list = do_QueryInterface( aList, &rv );
999 NS_ENSURE_SUCCESS( rv, rv );
1002 nsCOMPtr<sbIDownloadDeviceHelper> dh(
1003 do_GetService(
"@songbirdnest.com/Songbird/DownloadDeviceHelper;1", &rv ));
1004 NS_ENSURE_SUCCESS( rv, rv );
1007 dh->DownloadAll(list);
1015 LOG((
"sbRemotePlayer::DownloadSelected()"));
1017 NS_ENSURE_ARG_POINTER(aWebPlaylist);
1019 nsCOMPtr<nsISimpleEnumerator> selection;
1020 nsresult rv = aWebPlaylist->GetSelection( getter_AddRefs(selection) );
1021 NS_ENSURE_SUCCESS( rv, rv );
1025 nsRefPtr<sbUnwrappingSimpleEnumerator> wrapper(
1027 NS_ENSURE_TRUE( wrapper, NS_ERROR_OUT_OF_MEMORY );
1029 nsCOMPtr<sbIDownloadDeviceHelper> dh =
1030 do_GetService(
"@songbirdnest.com/Songbird/DownloadDeviceHelper;1", &rv );
1031 NS_ENSURE_SUCCESS( rv, rv );
1034 dh->DownloadSome(wrapper);
1040 sbRemotePlayer::GetCurrentArtist( nsAString &aCurrentArtist )
1042 LOG((
"sbRemotePlayer::GetCurrentArtist()"));
1046 do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1", &rv );
1047 NS_ENSURE_SUCCESS( rv, rv );
1050 NS_ENSURE_SUCCESS( rv, rv );
1056 sbRemotePlayer::GetCurrentAlbum( nsAString &aCurrentAlbum )
1058 LOG((
"sbRemotePlayer::GetCurrentAlbum()"));
1062 do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1", &rv );
1063 NS_ENSURE_SUCCESS( rv, rv );
1066 NS_ENSURE_SUCCESS( rv, rv );
1072 sbRemotePlayer::GetCurrentTrack( nsAString &aCurrentTrack )
1074 LOG((
"sbRemotePlayer::GetCurrentTrack()"));
1078 do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1", &rv );
1079 NS_ENSURE_SUCCESS( rv, rv );
1082 NS_ENSURE_SUCCESS( rv, rv );
1088 sbRemotePlayer::GetPlaying( PRBool *aPlaying )
1090 LOG((
"sbRemotePlayer::GetPlaying()"));
1091 NS_ENSURE_ARG_POINTER(aPlaying);
1094 mdrPlaying = do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1",
1096 NS_ENSURE_SUCCESS( rv, rv );
1097 rv =
mdrPlaying->Init( NS_LITERAL_STRING(
"faceplate.playing"),
1099 NS_ENSURE_SUCCESS( rv, rv );
1105 sbRemotePlayer::GetPaused( PRBool *aPaused )
1107 LOG((
"sbRemotePlayer::GetPaused()"));
1108 NS_ENSURE_ARG_POINTER(aPaused);
1111 mdrPaused = do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1",
1113 NS_ENSURE_SUCCESS( rv, rv );
1114 rv =
mdrPaused->Init( NS_LITERAL_STRING(
"faceplate.paused"),
1116 NS_ENSURE_SUCCESS( rv, rv );
1118 return mdrPaused->GetBoolValue(aPaused);
1122 sbRemotePlayer::GetRepeat( PRInt64 *aRepeat )
1124 LOG((
"sbRemotePlayer::GetRepeat()"));
1125 NS_ENSURE_ARG_POINTER(aRepeat);
1128 mdrRepeat = do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1",
1130 NS_ENSURE_SUCCESS( rv, rv );
1131 rv =
mdrRepeat->Init( NS_LITERAL_STRING(
"playlist.repeat"),
1133 NS_ENSURE_SUCCESS( rv, rv );
1139 sbRemotePlayer::GetShuffle( PRBool *aShuffle )
1141 LOG((
"sbRemotePlayer::GetShuffle()"));
1142 NS_ENSURE_ARG_POINTER(aShuffle);
1145 mdrShuffle = do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1",
1147 NS_ENSURE_SUCCESS( rv, rv );
1148 rv =
mdrShuffle->Init( NS_LITERAL_STRING(
"playlist.shuffle"),
1150 NS_ENSURE_SUCCESS( rv, rv );
1156 sbRemotePlayer::GetPosition( PRInt64 *aPosition )
1158 LOG((
"sbRemotePlayer::GetPosition()"));
1159 NS_ENSURE_ARG_POINTER(aPosition);
1162 mdrPosition = do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1",
1164 NS_ENSURE_SUCCESS( rv, rv );
1165 rv =
mdrPosition->Init( NS_LITERAL_STRING(
"metadata.position"),
1167 NS_ENSURE_SUCCESS( rv, rv );
1173 sbRemotePlayer::SetPosition( PRInt64 aPosition )
1175 LOG((
"sbRemotePlayer::SetPosition()"));
1176 NS_ENSURE_ARG_POINTER(aPosition);
1179 NS_ENSURE_SUCCESS( rv, rv );
1181 nsCOMPtr<sbIMediacoreManager> mediaCoreMgr =
1183 NS_ENSURE_SUCCESS(rv, rv);
1185 nsCOMPtr<sbIMediacorePlaybackControl> playbackControl;
1186 rv = mediaCoreMgr->GetPlaybackControl(getter_AddRefs(playbackControl));
1187 NS_ENSURE_SUCCESS(rv, rv);
1189 rv = playbackControl->SetPosition(aPosition);
1190 NS_ENSURE_SUCCESS(rv, rv);
1196 sbRemotePlayer::GetDuration( PRUint64 *aDuration )
1198 LOG((
"sbRemotePlayer::GetDuration()"));
1199 NS_ENSURE_ARG_POINTER(aDuration);
1202 nsCOMPtr<sbIMediacoreManager> mediaCoreMgr =
1204 NS_ENSURE_SUCCESS(rv, rv);
1206 nsCOMPtr<sbIMediacorePlaybackControl> playbackControl;
1207 rv = mediaCoreMgr->GetPlaybackControl(getter_AddRefs(playbackControl));
1208 NS_ENSURE_SUCCESS(rv, rv);
1212 if ( playbackControl ) {
1213 rv = playbackControl->GetDuration(aDuration);
1214 NS_ENSURE_SUCCESS(rv, rv);
1221 sbRemotePlayer::GetVolume( PRInt64 *aVolume )
1223 LOG((
"sbRemotePlayer::GetVolume()"));
1224 NS_ENSURE_ARG_POINTER(aVolume);
1227 nsCOMPtr<sbIMediacoreManager> mediaCoreMgr =
1229 NS_ENSURE_SUCCESS(rv, rv);
1231 nsCOMPtr<sbIMediacoreVolumeControl> volumeControl;
1232 rv = mediaCoreMgr->GetVolumeControl(getter_AddRefs(volumeControl));
1233 NS_ENSURE_SUCCESS(rv, rv);
1236 rv = volumeControl->GetVolume(&volume);
1237 NS_ENSURE_SUCCESS(rv, rv);
1239 *aVolume = (PRInt64)(volume * 255);
1241 if (NS_UNLIKELY(*aVolume < 0)) {
1244 if (NS_UNLIKELY(*aVolume > 255)) {
1251 sbRemotePlayer::GetMute( PRBool *aMute )
1253 LOG((
"sbRemotePlayer::GetMute()"));
1254 NS_ENSURE_ARG_POINTER(aMute);
1257 mdrMute = do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1",
1259 NS_ENSURE_SUCCESS( rv, rv );
1261 NS_ENSURE_SUCCESS( rv, rv );
1263 return mdrMute->GetBoolValue(aMute);
1267 sbRemotePlayer::AddListener(
const nsAString &aKey,
1270 LOG((
"sbRemotePlayer::AddListener()"));
1271 NS_ENSURE_ARG_POINTER(aObserver);
1275 for (PRInt32 index = 0 ; index < length; index++ ) {
1280 if ( index == (length-1) )
1281 return NS_ERROR_FAILURE;
1285 nsCOMPtr<sbIDataRemote> dr =
1286 do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1", &rv );
1287 NS_ENSURE_SUCCESS( rv, rv );
1289 NS_ENSURE_SUCCESS( rv, rv );
1290 rv = dr->BindRemoteObserver( aObserver, PR_FALSE );
1291 NS_ENSURE_SUCCESS( rv, rv );
1297 NS_ENSURE_TRUE( success, NS_ERROR_OUT_OF_MEMORY );
1303 sbRemotePlayer::RemoveListener(
const nsAString &aKey,
1306 NS_ENSURE_ARG_POINTER(aObserver);
1307 LOG((
"sbRemotePlayer::RemoveListener(%s %x)",
1308 PromiseFlatString(aKey).
get(), aObserver));
1313 if ( remObs.
observer == aObserver ) {
1314 LOG((
"sbRemotePlayer::RemoveListener(%s %x) -- found observer",
1315 NS_LossyConvertUTF16toASCII(aKey).
get(), aObserver ));
1321 LOG((
"sbRemotePlayer::RemoveListener(%s %x) -- did NOT find observer",
1322 PromiseFlatString(aKey).
get(), aObserver ));
1330 NS_ENSURE_ARG_POINTER(aWeakRef);
1337 nsCOMPtr<sbIMediacoreManager> manager =
1338 do_QueryReferent(aWeakRef, &rv);
1339 NS_ENSURE_SUCCESS(rv, rv);
1345 sbRemotePlayer::Play()
1347 LOG((
"sbRemotePlayer::Play()"));
1348 NS_ENSURE_STATE(
mMM);
1351 NS_ENSURE_SUCCESS( rv, rv );
1355 PRBool isPaused = PR_FALSE;
1357 rv = GetPaused( &isPaused );
1358 NS_ENSURE_SUCCESS( rv, rv );
1361 nsCOMPtr<sbIMediacoreManager> manager =
1362 do_QueryReferent(
mMM, &rv);
1363 NS_ENSURE_SUCCESS(rv, rv);
1365 nsCOMPtr<sbIMediacorePlaybackControl> playbackControl;
1366 rv = manager->GetPlaybackControl(getter_AddRefs(playbackControl));
1367 NS_ENSURE_SUCCESS(rv, rv);
1369 if ( playbackControl ) {
1370 rv = playbackControl->Play();
1371 NS_ENSURE_SUCCESS(rv, rv);
1379 NS_ENSURE_SUCCESS( rv, rv );
1382 nsCOMPtr<sbIMediaListView> mediaListView;
1384 NS_ENSURE_SUCCESS( rv, rv );
1388 if (!mediaListView) {
1393 rv = mediaListView->GetTreeView( getter_AddRefs(treeView) );
1394 if ( NS_FAILED(rv) ) {
1395 NS_WARNING(
"Got list view but did not get tree view! Falling back to standard play.");
1399 nsCOMPtr<nsITreeSelection> treeSelection;
1400 rv = treeView->GetSelection( getter_AddRefs(treeSelection) );
1401 if ( NS_FAILED(rv) || !treeSelection ) {
1402 NS_WARNING(
"Got tree view but did not get selection in view. Falling back to standard play.");
1407 treeSelection->GetCurrentIndex(&index);
1411 nsCOMPtr<sbIMediacoreManager> manager =
1412 do_QueryReferent(
mMM, &rv);
1413 NS_ENSURE_SUCCESS(rv, rv);
1415 nsCOMPtr<sbIMediacoreSequencer> sequencer;
1416 rv = manager->GetSequencer(getter_AddRefs(sequencer));
1417 NS_ENSURE_SUCCESS(rv, rv);
1419 rv = sequencer->PlayView( mediaListView, index, PR_FALSE);
1420 NS_ENSURE_SUCCESS( rv, rv );
1423 NS_ENSURE_SUCCESS( rv, rv );
1431 LOG((
"sbRemotePlayer::PlayMediaList()"));
1432 NS_ENSURE_ARG_POINTER(aList);
1433 NS_ENSURE_STATE(
mMM);
1436 NS_ENSURE_SUCCESS( rv, rv );
1439 nsCOMPtr<sbIMediaListView> mediaListView;
1440 rv = aList->GetView( getter_AddRefs(mediaListView) );
1443 if (!mediaListView) {
1444 nsCOMPtr<sbIMediaList> list( do_QueryInterface( aList, &rv ) );
1445 NS_ENSURE_SUCCESS( rv, rv );
1447 rv = list->CreateView( nsnull, getter_AddRefs(mediaListView) );
1448 NS_ENSURE_SUCCESS( rv, rv );
1454 nsCOMPtr<sbIMediacoreManager> manager =
1455 do_QueryReferent(
mMM, &rv);
1456 NS_ENSURE_SUCCESS(rv, rv);
1458 nsCOMPtr<sbIMediacoreSequencer> sequencer;
1459 rv = manager->GetSequencer(getter_AddRefs(sequencer));
1460 NS_ENSURE_SUCCESS(rv, rv);
1462 rv = sequencer->PlayView( mediaListView, aIndex, PR_FALSE);
1463 NS_ENSURE_SUCCESS( rv, rv );
1466 NS_ENSURE_SUCCESS( rv, rv );
1472 sbRemotePlayer::PlayURL(
const nsAString &aURL )
1474 LOG((
"sbRemotePlayer::PlayURL()"));
1475 NS_ENSURE_STATE(
mMM);
1478 NS_ENSURE_SUCCESS( rv, rv );
1480 nsCOMPtr<sbIMediacoreManager> manager =
1481 do_QueryReferent(
mMM, &rv);
1482 NS_ENSURE_SUCCESS(rv, rv);
1484 nsCOMPtr<sbIMediacoreSequencer> sequencer;
1485 rv = manager->GetSequencer(getter_AddRefs(sequencer));
1486 NS_ENSURE_SUCCESS(rv, rv);
1488 nsCOMPtr<nsIURI>
uri;
1489 rv =
mIOService->NewURI(NS_ConvertUTF16toUTF8(aURL),
1492 getter_AddRefs(uri));
1493 NS_ENSURE_SUCCESS(rv, rv);
1495 rv = sequencer->PlayURL(uri);
1496 NS_ENSURE_SUCCESS( rv, rv );
1499 NS_ENSURE_SUCCESS( rv, rv );
1505 sbRemotePlayer::Stop()
1507 LOG((
"sbRemotePlayer::Stop()"));
1508 NS_ENSURE_STATE(
mMM);
1511 NS_ENSURE_SUCCESS( rv, rv );
1513 nsCOMPtr<sbIMediacoreManager> manager =
1514 do_QueryReferent(
mMM, &rv);
1515 NS_ENSURE_SUCCESS(rv, rv);
1517 nsCOMPtr<sbIMediacorePlaybackControl> playbackControl;
1518 rv = manager->GetPlaybackControl(getter_AddRefs(playbackControl));
1519 NS_ENSURE_SUCCESS(rv, rv);
1521 if ( playbackControl ) {
1522 rv = playbackControl->Stop();
1523 NS_ENSURE_SUCCESS(rv, rv);
1527 NS_ENSURE_SUCCESS( rv, rv );
1533 sbRemotePlayer::Pause()
1535 LOG((
"sbRemotePlayer::Pause()"));
1536 NS_ENSURE_STATE(
mMM);
1539 NS_ENSURE_SUCCESS( rv, rv );
1541 nsCOMPtr<sbIMediacoreManager> manager =
1542 do_QueryReferent(
mMM, &rv);
1543 NS_ENSURE_SUCCESS(rv, rv);
1545 nsCOMPtr<sbIMediacorePlaybackControl> playbackControl;
1546 rv = manager->GetPlaybackControl(getter_AddRefs(playbackControl));
1547 NS_ENSURE_SUCCESS(rv, rv);
1549 if ( playbackControl ) {
1550 rv = playbackControl->Pause();
1551 NS_ENSURE_SUCCESS(rv, rv);
1555 NS_ENSURE_SUCCESS( rv, rv );
1561 sbRemotePlayer::Next()
1563 LOG((
"sbRemotePlayer::Next()"));
1564 NS_ENSURE_STATE(
mMM);
1567 NS_ENSURE_SUCCESS( rv, rv );
1569 nsCOMPtr<sbIMediacoreManager> manager =
1570 do_QueryReferent(
mMM, &rv);
1571 NS_ENSURE_SUCCESS(rv, rv);
1573 nsCOMPtr<sbIMediacoreSequencer> sequencer;
1574 rv = manager->GetSequencer(getter_AddRefs(sequencer));
1575 NS_ENSURE_SUCCESS(rv, rv);
1577 rv = sequencer->Next(PR_FALSE);
1578 NS_ENSURE_SUCCESS( rv, rv );
1581 NS_ENSURE_SUCCESS( rv, rv );
1587 sbRemotePlayer::Previous()
1589 LOG((
"sbRemotePlayer::Previous()"));
1590 NS_ENSURE_STATE(
mMM);
1593 NS_ENSURE_SUCCESS( rv, rv );
1595 nsCOMPtr<sbIMediacoreManager> manager =
1596 do_QueryReferent(
mMM, &rv);
1597 NS_ENSURE_SUCCESS(rv, rv);
1599 nsCOMPtr<sbIMediacoreSequencer> sequencer;
1600 rv = manager->GetSequencer(getter_AddRefs(sequencer));
1601 NS_ENSURE_SUCCESS(rv, rv);
1603 rv = sequencer->Previous(PR_FALSE);
1604 NS_ENSURE_SUCCESS( rv, rv );
1607 NS_ENSURE_SUCCESS( rv, rv );
1613 sbRemotePlayer::FireEventToContent(
const nsAString &aClass,
1614 const nsAString &aType )
1616 LOG((
"sbRemotePlayer::FireEventToContent(%s, %s)",
1617 NS_LossyConvertUTF16toASCII(aClass).
get(),
1618 NS_LossyConvertUTF16toASCII(aType).
get() ));
1624 sbRemotePlayer::FireMediaItemStatusEventToContent(
const nsAString &aClass,
1625 const nsAString &aType,
1629 LOG((
"sbRemotePlayer::FireMediaItemStatusEventToContent(%s, %s)",
1630 NS_LossyConvertUTF16toASCII(aClass).
get(),
1631 NS_LossyConvertUTF16toASCII(aType).
get() ));
1632 NS_ENSURE_ARG_POINTER(aMediaItem);
1636 nsCOMPtr<sbISecurityMixin> mixin = do_QueryInterface(
mSecurityMixin, &rv);
1637 NS_ENSURE_SUCCESS(rv, rv);
1639 nsCOMPtr<nsIDOMDocument>
doc;
1640 mixin->GetNotificationDocument(getter_AddRefs(doc));
1641 NS_ENSURE_STATE(doc);
1644 nsCOMPtr<nsIDOMDocumentEvent>
1645 docEvent( do_QueryInterface( doc, &rv ) );
1646 NS_ENSURE_SUCCESS( rv , rv );
1649 nsCOMPtr<nsIDOMEvent>
event;
1650 docEvent->CreateEvent( aClass, getter_AddRefs(event) );
1651 NS_ENSURE_STATE(event);
1652 rv =
event->InitEvent( aType, PR_TRUE, PR_TRUE );
1653 NS_ENSURE_SUCCESS( rv , rv );
1656 nsCOMPtr<nsIDOMEventTarget>
1658 NS_ENSURE_SUCCESS( rv, rv );
1661 nsCOMPtr<nsIPrivateDOMEvent> privEvt( do_QueryInterface( event, &rv ) );
1662 NS_ENSURE_SUCCESS( rv, rv );
1663 privEvt->SetTrusted(PR_FALSE);
1666 nsRefPtr<sbRemoteMediaItemStatusEvent>
1668 rv = remoteEvent->Init();
1669 NS_ENSURE_SUCCESS( rv, rv );
1670 rv = remoteEvent->InitEvent( event, aMediaItem, aStatus );
1671 NS_ENSURE_SUCCESS( rv, rv );
1675 return eventTarget->DispatchEvent( remoteEvent, &dummy );
1687 NS_ENSURE_ARG_POINTER(aEvent);
1690 nsresult rv = aEvent->GetType(&type);
1691 NS_ENSURE_SUCCESS(rv, rv);
1697 NS_ENSURE_SUCCESS(rv, rv);
1703 NS_ENSURE_SUCCESS(rv, rv);
1709 NS_ENSURE_SUCCESS(rv, rv);
1715 NS_ENSURE_SUCCESS(rv, rv);
1721 NS_ENSURE_SUCCESS(rv, rv);
1737 LOG((
"sbRemotePlayer::OnStop()"));
1741 NS_ENSURE_SUCCESS( rv, rv );
1749 LOG((
"sbRemotePlayer::OnBeforeTrackChange()"));
1750 NS_ENSURE_ARG_POINTER(aEvent);
1752 nsCOMPtr<nsIVariant>
data;
1753 nsresult rv = aEvent->GetData(getter_AddRefs(data));
1754 NS_ENSURE_SUCCESS(rv, rv);
1756 nsCOMPtr<nsISupports> supports;
1757 rv = data->GetAsISupports(getter_AddRefs(supports));
1758 NS_ENSURE_SUCCESS(rv, rv);
1760 nsCOMPtr<sbIMediaItem> item = do_QueryInterface(supports, &rv);
1761 NS_ENSURE_SUCCESS(rv, rv);
1767 NS_ENSURE_SUCCESS(rv, rv);
1775 LOG((
"sbRemotePlayer::OnTrackChange()"));
1776 NS_ENSURE_ARG_POINTER(aEvent);
1778 nsCOMPtr<nsIVariant>
data;
1779 nsresult rv = aEvent->GetData(getter_AddRefs(data));
1780 NS_ENSURE_SUCCESS(rv, rv);
1782 nsCOMPtr<nsISupports> supports;
1783 rv = data->GetAsISupports(getter_AddRefs(supports));
1784 NS_ENSURE_SUCCESS(rv, rv);
1786 nsCOMPtr<sbIMediaItem> item = do_QueryInterface(supports, &rv);
1787 NS_ENSURE_SUCCESS(rv, rv);
1793 NS_ENSURE_SUCCESS(rv, rv);
1800 LOG((
"sbRemotePlayer::OnTrackIndexChange()"));
1801 NS_ENSURE_ARG_POINTER(aEvent);
1803 nsCOMPtr<nsIVariant>
data;
1804 nsresult rv = aEvent->GetData(getter_AddRefs(data));
1805 NS_ENSURE_SUCCESS(rv, rv);
1807 nsCOMPtr<nsISupports> supports;
1808 rv = data->GetAsISupports(getter_AddRefs(supports));
1809 NS_ENSURE_SUCCESS(rv, rv);
1811 nsCOMPtr<sbIMediaItem> item = do_QueryInterface(supports, &rv);
1812 NS_ENSURE_SUCCESS(rv, rv);
1818 NS_ENSURE_SUCCESS(rv, rv);
1825 LOG((
"sbRemotePlayer::OnViewChange()"));
1826 NS_ENSURE_ARG_POINTER(aEvent);
1830 NS_ENSURE_SUCCESS(rv, rv);
1837 LOG((
"sbRemotePlayer::OnViewChange()"));
1838 NS_ENSURE_ARG_POINTER(aEvent);
1842 NS_ENSURE_SUCCESS(rv, rv);
1854 sbRemotePlayer::HandleEvent(
nsIDOMEvent *aEvent )
1856 LOG((
"sbRemotePlayer::HandleEvent() this: %08x",
this ));
1857 NS_ENSURE_ARG_POINTER(aEvent);
1859 aEvent->GetType(type);
1860 if ( type.EqualsLiteral(
"unload") ) {
1861 LOG((
"sbRemotePlayer::HandleEvent() - unload event"));
1864 nsRefPtr<sbRemotePlayer> kungFuDeathGrip(
this);
1867 nsCOMPtr<nsIDOMNSEvent> nsEvent( do_QueryInterface( aEvent, &rv ) );
1868 if ( NS_FAILED(rv) )
1871 nsCOMPtr<nsIDOMEventTarget> originalEventTarget;
1872 rv = nsEvent->GetOriginalTarget( getter_AddRefs(originalEventTarget) );
1873 NS_ENSURE_SUCCESS( rv, rv );
1875 if ( !SameCOMIdentity( originalEventTarget,
mContentDoc ) ) {
1882 rv =
eventTarget->RemoveEventListener( NS_LITERAL_STRING(
"unload"),
1885 NS_ASSERTION( NS_SUCCEEDED(rv),
1886 "Failed to remove unload listener from document" );
1888 rv =
eventTarget->RemoveEventListener( NS_LITERAL_STRING(
"PlaylistCellClick"),
1891 NS_ASSERTION( NS_SUCCEEDED(rv),
1892 "Failed to remove PlaylistCellClick listener from document" );
1897 NS_ASSERTION( NS_SUCCEEDED(rv),
1898 "Failed to remove RemoteAPIPermissionDenied listener from document" );
1903 NS_ASSERTION( NS_SUCCEEDED(rv),
1904 "Failed to remove RemoteAPIPermissionChanged listener from document" );
1906 nsCOMPtr<sbIMediacoreEventTarget>
target =
1907 do_QueryReferent(
mMM, &rv);
1908 NS_ASSERTION( NS_SUCCEEDED(rv),
1909 "Failed to get event target to remove playback listener" );
1911 rv = target->RemoveListener(
this);
1912 NS_ASSERTION( NS_SUCCEEDED(rv),
"Failed to remove playback listener" );
1924 }
else if ( type.EqualsLiteral(
"PlaylistCellClick") ) {
1925 LOG((
"sbRemotePlayer::HandleEvent() - PlaylistCellClick event"));
1929 nsCOMPtr<nsIDOMNSEvent> srcEvent( do_QueryInterface(aEvent, &rv) );
1930 NS_ENSURE_SUCCESS(rv, rv);
1932 nsCOMPtr<nsIDOMEventTarget> srcEventTarget;
1933 rv = srcEvent->GetOriginalTarget( getter_AddRefs(srcEventTarget) );
1934 NS_ENSURE_SUCCESS(rv, rv);
1936 nsCOMPtr<sbIPlaylistWidget> playlist( do_QueryInterface(srcEventTarget, &rv) );
1944 NS_ENSURE_SUCCESS( rv, rv );
1948 nsCOMPtr<sbIPlaylistWidget> playlistWidget;
1949 rv =
mRemWebPlaylist->GetPlaylistWidget( getter_AddRefs(playlistWidget) );
1950 NS_ENSURE_SUCCESS(rv, rv);
1953 if ( !SameCOMIdentity( playlist, playlistWidget ) ) {
1958 nsCOMPtr<sbIPlaylistClickEvent> playlistClickEvent;
1959 rv = playlist->GetLastClickEvent( getter_AddRefs(playlistClickEvent) );
1960 NS_ENSURE_SUCCESS(rv, rv);
1963 nsCOMPtr<nsIDOMDocumentEvent> docEvent( do_QueryInterface(
mContentDoc, &rv) );
1964 NS_ENSURE_SUCCESS(rv, rv);
1966 nsCOMPtr<nsIDOMEvent> newEvent;
1967 rv = docEvent->CreateEvent( NS_LITERAL_STRING(
"mouseevent"), getter_AddRefs(newEvent) );
1968 NS_ENSURE_SUCCESS(rv, rv);
1970 PRBool
ctrlKey = PR_FALSE, altKey = PR_FALSE,
1971 shiftKey = PR_FALSE, metaKey = PR_FALSE;
1972 PRUint16 button = 0;
1973 nsCOMPtr<nsIDOMMouseEvent> srcMouseEvent( do_QueryInterface(playlistClickEvent, &rv) );
1974 if (NS_SUCCEEDED(rv)) {
1975 srcMouseEvent->GetCtrlKey(&ctrlKey);
1976 srcMouseEvent->GetAltKey(&altKey);
1977 srcMouseEvent->GetShiftKey(&shiftKey);
1978 srcMouseEvent->GetMetaKey(&metaKey);
1979 srcMouseEvent->GetButton(&button);
1981 LOG((
"sbRemotePlayer::HandleEvent() - no mouse event for PlaylistCellClick"));
1984 nsCOMPtr<nsIDOMMouseEvent> newMouseEvent( do_QueryInterface(newEvent, &rv) );
1985 NS_ENSURE_SUCCESS(rv, rv);
1986 rv = newMouseEvent->InitMouseEvent( NS_LITERAL_STRING(
"PlaylistCellClick"),
2000 NS_ENSURE_SUCCESS(rv, rv);
2003 nsCOMPtr<nsIPrivateDOMEvent> privEvt( do_QueryInterface( newEvent, &rv ) );
2004 NS_ENSURE_SUCCESS( rv, rv );
2005 privEvt->SetTrusted( PR_TRUE );
2009 NS_ENSURE_TRUE(remoteEvent, NS_ERROR_OUT_OF_MEMORY);
2011 rv = remoteEvent->Init();
2012 NS_ENSURE_SUCCESS(rv, rv);
2014 rv = remoteEvent->InitEvent( playlistClickEvent, newMouseEvent );
2015 NS_ENSURE_SUCCESS(rv, rv);
2019 nsCOMPtr<nsIDOMEventTarget> destEventTarget = do_QueryInterface(
mContentDoc, &rv );
2020 NS_ENSURE_SUCCESS(rv, rv);
2021 rv = destEventTarget->DispatchEvent( remoteEvent, &dummy );
2022 NS_ENSURE_SUCCESS(rv, rv);
2035 nsCOMPtr<nsIDOMNSEvent> nsEvent( do_QueryInterface( aEvent, &rv ) );
2036 if ( NS_FAILED(rv) )
2039 nsCOMPtr<nsIDOMEventTarget> originalEventTarget;
2040 rv = nsEvent->GetOriginalTarget( getter_AddRefs(originalEventTarget) );
2041 NS_ENSURE_SUCCESS( rv, rv );
2043 PRBool allow = PR_FALSE;
2044 if ( SameCOMIdentity( originalEventTarget,
mChromeDoc ) ) {
2045 LOG((
" - target IS this chromeDoc - ALLOWING " ));
2049 nsCOMPtr<nsIDOMXULElement> domXULElement (
2050 do_QueryInterface(originalEventTarget) );
2051 if (domXULElement) {
2055 nsCOMPtr<nsIDOMNode> targetNotification (
2056 do_QueryInterface(originalEventTarget) );
2057 NS_ENSURE_TRUE( targetNotification, NS_ERROR_OUT_OF_MEMORY );
2059 nsCOMPtr<nsIDOMNode> targetNotificationBox;
2060 rv = targetNotification->GetParentNode(
2061 getter_AddRefs(targetNotificationBox) );
2062 NS_ENSURE_SUCCESS( rv, rv );
2065 nsCOMPtr<nsIDOMElement> selfBrowser;
2066 rv =
GetBrowser( getter_AddRefs(selfBrowser) );
2067 NS_ENSURE_SUCCESS( rv, rv );
2069 nsCOMPtr<nsIDOMNode> selfBrowserNode ( do_QueryInterface( selfBrowser ) );
2070 NS_ENSURE_TRUE( selfBrowserNode, NS_ERROR_OUT_OF_MEMORY );
2072 nsCOMPtr<nsIDOMNode> selfNotificationBox;
2073 rv = selfBrowserNode->GetParentNode(
2074 getter_AddRefs(selfNotificationBox) );
2075 NS_ENSURE_SUCCESS( rv, rv );
2077 if ( SameCOMIdentity( selfNotificationBox, targetNotificationBox ) ) {
2078 LOG((
" - target IS this notificationbox - ALLOWING " ));
2087 value.AssignLiteral(
"dismissed");
2090 value.AssignLiteral(
"preferences");
2093 nsCOMPtr<sbIRemoteSecurityEvent> securityEvent =
2094 do_QueryInterface(aEvent, &rv);
2096 if ( NS_SUCCEEDED( rv ) ) {
2098 nsAutoString categoryID;
2099 rv = securityEvent->GetCategoryID(categoryID);
2100 NS_ENSURE_SUCCESS( rv, rv );
2103 rv = securityEvent->GetHasAccess(&hasAccess);
2104 NS_ENSURE_SUCCESS( rv, rv );
2106 nsCOMPtr<sbISecurityMixin> mixin = do_QueryInterface(
mSecurityMixin, &rv);
2107 NS_ENSURE_SUCCESS( rv, rv );
2109 nsCOMPtr<nsIDOMDocument>
doc;
2110 rv = mixin->GetNotificationDocument(getter_AddRefs(doc));
2111 NS_ENSURE_SUCCESS( rv, rv );
2120 #ifdef METRICS_ENABLED
2121 rv = mMetrics->MetricsInc(NS_LITERAL_STRING(
"rapi.notification"),
2124 NS_ENSURE_SUCCESS( rv, rv );
2128 LOG((
"sbRemotePlayer::HandleEvent() - %s",
2129 NS_LossyConvertUTF16toASCII(type).
get() ));
2135 #ifdef METRICS_ENABLED
2136 rv = mMetrics->MetricsInc(NS_LITERAL_STRING(
"rapi.notification"),
2139 NS_ENSURE_SUCCESS( rv, rv );
2143 LOG((
"sbRemotePlayer::HandleEvent() - Some other event"));
2154 LOG((
"sbRemotePlayer::UnregisterCommands()"));
2160 nsCOMPtr<sbIPlaylistCommandsManager> mgr(
2161 do_GetService(
"@songbirdnest.com/Songbird/PlaylistCommandsManager;1", &rv ) );
2162 NS_ENSURE_SUCCESS( rv, rv );
2165 NS_ENSURE_TRUE( commands, NS_ERROR_UNEXPECTED );
2167 rv = mgr->UnregisterPlaylistCommandsMediaItem( NS_LITERAL_STRING(
"remote-test-guid"),
2168 NS_LITERAL_STRING(
"library"),
2170 NS_ASSERTION( NS_SUCCEEDED(rv),
2171 "Failed to unregister commands from playlistcommandsmanager" );
2173 rv = mgr->UnregisterPlaylistCommandsMediaItem( NS_LITERAL_STRING(
"remote-test-guid"),
2174 NS_LITERAL_STRING(
"simple"),
2176 NS_ASSERTION( NS_SUCCEEDED(rv),
2177 "Failed to unregister commands from playlistcommandsmanager" );
2191 LOG((
"sbRemotePlayer::ConfirmPlaybackControl()"));
2202 nsCOMPtr<sbISecurityMixin> securityMixin =
2204 NS_ENSURE_SUCCESS( rv, rv );
2205 nsCOMPtr<nsIURI> codebaseURI;
2206 rv = securityMixin->GetCodebase( getter_AddRefs(codebaseURI) );
2207 NS_ENSURE_SUCCESS( rv, rv );
2214 return NS_ERROR_FAILURE;
2217 rv = GetPlaying( &isPlaying );
2218 NS_ENSURE_SUCCESS( rv, rv );
2222 LOG((
"sbRemotePlayer::ConfirmPlaybackControl() -- not playing, allow"));
2227 nsCOMPtr<sbIRemoteAPIService> remoteAPIService =
2228 do_GetService(
"@songbirdnest.com/remoteapi/remoteapiservice;1", &rv );
2229 NS_ENSURE_SUCCESS( rv, rv );
2230 PRBool hasPlaybackControl;
2231 rv = remoteAPIService->HasPlaybackControl( codebaseURI, &hasPlaybackControl );
2232 NS_ENSURE_SUCCESS( rv, rv );
2233 if ( hasPlaybackControl ) {
2234 LOG((
"sbRemotePlayer::ConfirmPlaybackControl() -- URI has control, allow"));
2241 NS_LITERAL_STRING(
"rapi.playback_control.blocked.title"),
2242 NS_LITERAL_STRING(
"rapi.playback_control.blocked.message") );
2249 const nsAString &aTitleKey,
2250 const nsAString &aMessageKey,
2251 const char* aScopedName )
2253 LOG((
"sbRemotePlayer::GetUserApprovalForHost(URI)"));
2254 NS_ENSURE_ARG_POINTER(aURI);
2255 NS_ASSERTION(!aTitleKey.IsEmpty(),
"Title Key empty!!!!");
2256 NS_ASSERTION(!aMessageKey.IsEmpty(),
"Message key empty!!!!");
2260 nsCOMPtr<nsIPrefBranch> prefService =
2261 do_GetService(
"@mozilla.org/preferences-service;1", &rv);
2262 if (NS_SUCCEEDED(rv)) {
2263 PRBool shouldPrompt;
2264 rv = prefService->GetBoolPref(
"songbird.rapi.promptForApproval",
2266 if (NS_SUCCEEDED(rv) && !shouldPrompt) {
2267 LOG((
"sbRemotePlayer::GetUserApprovalForHost(URI) - shouldn't prompt or failed"));
2271 LOG((
"sbRemotePlayer::GetUserApprovalForHost(URI) - here"));
2274 rv = aURI->GetHost(hostUTF8);
2275 NS_ENSURE_SUCCESS( rv, rv );
2277 if ( hostUTF8.IsEmpty() ) {
2279 rv = aURI->GetSpec(hostUTF8);
2280 NS_ENSURE_SUCCESS( rv, rv );
2282 NS_ConvertUTF8toUTF16 host(hostUTF8);
2284 nsCOMPtr<nsIStringBundleService> sbs =
2285 do_GetService( NS_STRINGBUNDLE_CONTRACTID, &rv );
2286 NS_ENSURE_SUCCESS( rv, PR_FALSE );
2289 nsCOMPtr<nsIStringBundle>
bundle;
2290 rv = sbs->CreateBundle(
"chrome://branding/locale/brand.properties",
2291 getter_AddRefs(bundle) );
2292 NS_ENSURE_SUCCESS( rv, PR_FALSE );
2295 rv = bundle->GetStringFromName( NS_LITERAL_STRING(
"brandShortName").
get(),
2296 getter_Copies(branding) );
2297 NS_ENSURE_SUCCESS( rv, PR_FALSE );
2300 rv = sbs->CreateBundle(
"chrome://songbird/locale/songbird.properties",
2301 getter_AddRefs(bundle) );
2302 NS_ENSURE_SUCCESS( rv, PR_FALSE );
2304 const PRUnichar *formatParams[1] = {0};
2305 formatParams[0] = branding.BeginReading();
2308 rv = bundle->FormatStringFromName( aMessageKey.BeginReading(),
2310 NS_ARRAY_LENGTH(formatParams),
2311 getter_Copies(message) );
2312 NS_ENSURE_SUCCESS( rv, PR_FALSE );
2315 rv = bundle->GetStringFromName( aTitleKey.BeginReading(),
2316 getter_Copies(title) );
2317 NS_ENSURE_SUCCESS( rv, PR_FALSE );
2320 rv = bundle->GetStringFromName( NS_LITERAL_STRING(
"rapi.permissions.allow.deny").
get(),
2321 getter_Copies(allowDeny) );
2322 NS_ENSURE_SUCCESS( rv, PR_FALSE );
2324 nsString allowAlways;
2325 rv = bundle->GetStringFromName( NS_LITERAL_STRING(
"rapi.permissions.allow.always").
get(),
2326 getter_Copies(allowAlways) );
2327 NS_ENSURE_SUCCESS( rv, PR_FALSE );
2330 rv = bundle->GetStringFromName( NS_LITERAL_STRING(
"rapi.permissions.allow.once").
get(),
2331 getter_Copies(allowOnce) );
2332 NS_ENSURE_SUCCESS( rv, PR_FALSE );
2334 LOG((
"sbRemotePlayer::GetUserApprovalForHost(URI) - there"));
2338 do_GetService(
"@mozilla.org/embedcomp/prompt-service;1", &rv );
2339 NS_ENSURE_SUCCESS( rv, PR_FALSE );
2343 nsCOMPtr<nsIDOMWindow>
window = do_QueryInterface( jsWindow, &rv );
2344 NS_ENSURE_SUCCESS( rv, PR_FALSE );
2349 buttons = nsIPromptService::BUTTON_POS_0 * nsIPromptService::BUTTON_TITLE_IS_STRING +
2350 nsIPromptService::BUTTON_POS_1 * nsIPromptService::BUTTON_TITLE_IS_STRING +
2351 nsIPromptService::BUTTON_POS_2 * nsIPromptService::BUTTON_TITLE_IS_STRING +
2352 nsIPromptService::BUTTON_POS_1_DEFAULT;
2356 buttons = nsIPromptService::BUTTON_POS_0 * nsIPromptService::BUTTON_TITLE_YES +
2357 nsIPromptService::BUTTON_POS_1 * nsIPromptService::BUTTON_TITLE_NO;
2359 LOG((
"sbRemotePlayer::GetUserApprovalForHost(URI) - where"));
2364 rv = promptService->ConfirmEx( window,
2365 title.BeginReading(),
2366 message.BeginReading(),
2368 allowOnce.BeginReading(),
2369 allowDeny.BeginReading(),
2370 allowAlways.BeginReading(),
2374 NS_ENSURE_SUCCESS( rv, PR_FALSE );
2376 PRBool retval = PR_FALSE;
2377 #ifdef METRICS_ENABLED
2378 nsString metricsCategory;
2379 metricsCategory.AssignLiteral(
"rapi.prompt.");
2383 metricsCategory.AppendLiteral(
"always");
2389 metricsCategory.AppendLiteral(
"once");
2394 metricsCategory.AppendLiteral(
"deny");
2399 nsCOMPtr<sbIMetrics> metrics =
2400 do_CreateInstance(
"@songbirdnest.com/Songbird/Metrics;1", &rv);
2401 NS_ENSURE_SUCCESS(rv, rv);
2403 nsCString
name(aScopedName);
2404 rv = metrics->MetricsInc(metricsCategory,
2405 NS_ConvertASCIItoUTF16(name),
2407 NS_ENSURE_SUCCESS(rv, rv);
2409 #endif // METRICS_ENABLED
2420 nsCOMPtr<nsIDOMNodeList> tabBrowserElementList;
2422 getter_AddRefs(tabBrowserElementList) );
2423 NS_ENSURE_STATE(tabBrowserElementList);
2424 nsCOMPtr<nsIDOMNode> tabBrowserElement;
2425 rv = tabBrowserElementList->Item( 0, getter_AddRefs(tabBrowserElement) );
2426 NS_ENSURE_STATE(tabBrowserElement);
2427 NS_ENSURE_SUCCESS( rv, rv );
2430 nsCOMPtr<sbITabBrowser>
tabbrowser( do_QueryInterface( tabBrowserElement,
2432 NS_ENSURE_SUCCESS( rv, rv );
2434 rv = tabbrowser->GetBrowserForDocument(
mContentDoc, aElement );
2435 NS_ENSURE_SUCCESS( rv, rv );
2444 nsCOMPtr<nsIURI> uri = aURI;
2447 if ( NS_UNLIKELY(!uri) ) {
2448 nsCOMPtr<sbISecurityMixin> securityMixin =
2450 NS_ENSURE_SUCCESS( rv, rv );
2451 rv = securityMixin->GetCodebase( getter_AddRefs(uri) );
2452 NS_ENSURE_SUCCESS( rv, rv );
2455 nsCOMPtr<sbIRemoteAPIService> remoteAPIService =
2456 do_GetService(
"@songbirdnest.com/remoteapi/remoteapiservice;1", &rv );
2457 NS_ENSURE_SUCCESS( rv, rv );
2459 rv = remoteAPIService->TakePlaybackControl( uri, nsnull );
2460 NS_ENSURE_SUCCESS( rv, rv );
2471 already_AddRefed<nsPIDOMWindow>
2474 LOG((
"sbRemotePlayer::GetWindowFromJS()"));
2478 nsCOMPtr<nsIJSContextStack> stack =
2479 do_GetService(
"@mozilla.org/js/xpc/ContextStack;1");
2482 LOG((
"sbRemotePlayer::GetWindowFromJS() -- NO STACK!!!"));
2487 if (NS_FAILED(stack->Peek(&cx)) || !cx) {
2488 LOG((
"sbRemotePlayer::GetWindowFromJS() -- NO CONTEXT!!!"));
2493 nsCOMPtr<nsIScriptContext> scCx = GetScriptContextFromJSContext(cx);
2494 NS_ENSURE_TRUE(scCx, nsnull);
2497 nsCOMPtr<nsPIDOMWindow>
win = do_QueryInterface( scCx->GetGlobalObject() );
2498 NS_ENSURE_TRUE( win, nsnull );
2499 NS_ADDREF( win.get() );
2503 already_AddRefed<nsPIDOMWindow>
2506 LOG((
"sbRemotePlayer::GetWindow()"));
2516 const nsAString &aClass,
2517 const nsAString &aType,
2520 LOG((
"sbRemotePlayer::DispatchEvent(%s, %s)",
2521 NS_LossyConvertUTF16toASCII(aClass).
get(),
2522 NS_LossyConvertUTF16toASCII(aType).
get() ));
2526 nsCOMPtr<nsIDOMDocumentEvent> docEvent( do_QueryInterface( aDoc, &rv ) );
2527 NS_ENSURE_SUCCESS( rv , rv );
2530 nsCOMPtr<nsIDOMEvent>
event;
2531 docEvent->CreateEvent( aClass, getter_AddRefs(event) );
2532 NS_ENSURE_STATE(event);
2533 rv =
event->InitEvent( aType, PR_TRUE, PR_TRUE );
2534 NS_ENSURE_SUCCESS( rv , rv );
2537 nsCOMPtr<nsIDOMEventTarget>
eventTarget( do_QueryInterface( aDoc, &rv ) );
2538 NS_ENSURE_SUCCESS( rv, rv );
2541 nsCOMPtr<nsIPrivateDOMEvent> privEvt( do_QueryInterface( event, &rv ) );
2542 NS_ENSURE_SUCCESS( rv, rv );
2543 privEvt->SetTrusted(aIsTrusted);
2547 return eventTarget->DispatchEvent( event, &dummy );
2553 const nsAString &aClass,
2554 const nsAString &aType,
2555 const nsAString &aCategoryID,
2559 LOG((
"sbRemotePlayer::DispatchSecurityEvent(%s, %s)",
2560 NS_LossyConvertUTF16toASCII(aClass).
get(),
2561 NS_LossyConvertUTF16toASCII(aType).
get() ));
2563 NS_ENSURE_ARG_POINTER(aDoc);
2564 NS_ENSURE_ARG_POINTER(aPlayer);
2569 nsCOMPtr<nsIDOMDocumentEvent>
2570 docEvent( do_QueryInterface( aDoc, &rv ) );
2571 NS_ENSURE_SUCCESS( rv , rv );
2574 nsCOMPtr<nsIDOMEvent>
event;
2575 docEvent->CreateEvent( aClass, getter_AddRefs(event) );
2576 NS_ENSURE_STATE(event);
2577 rv =
event->InitEvent( aType, PR_TRUE, PR_TRUE );
2578 NS_ENSURE_SUCCESS( rv , rv );
2581 nsCOMPtr<nsIDOMEventTarget>
2583 NS_ENSURE_SUCCESS( rv, rv );
2586 nsCOMPtr<nsIPrivateDOMEvent> privEvt( do_QueryInterface( event, &rv ) );
2587 NS_ENSURE_SUCCESS( rv, rv );
2588 privEvt->SetTrusted(aIsTrusted);
2592 securityEvent->Init();
2594 nsAutoString category;
2597 nsCOMPtr<nsIURI> scopeURI;
2598 rv = aPlayer->GetSiteScope( getter_AddRefs( scopeURI ) );
2599 NS_ENSURE_SUCCESS( rv, rv );
2601 rv = securityEvent->InitEvent( event, scopeURI, category, aCategoryID, aHasAccess );
2602 NS_ENSURE_SUCCESS( rv, rv );
2606 return eventTarget->DispatchEvent( securityEvent, &dummy );
2617 nsAString &aJSScopeName )
2627 return NS_ERROR_INVALID_ARG;
2634 LOG((
"sbRemotePlayer::InitRemoteWebPlaylist()"));
2638 return NS_ERROR_FAILURE;
2641 nsCOMPtr<nsIDOMNodeList> tabBrowserElementList;
2643 getter_AddRefs(tabBrowserElementList) );
2644 NS_ENSURE_STATE(tabBrowserElementList);
2645 nsCOMPtr<nsIDOMNode> tabBrowserElement;
2646 rv = tabBrowserElementList->Item( 0, getter_AddRefs(tabBrowserElement) );
2647 NS_ENSURE_STATE(tabBrowserElement);
2648 NS_ENSURE_SUCCESS( rv, rv );
2651 nsCOMPtr<sbITabBrowser>
tabbrowser( do_QueryInterface( tabBrowserElement,
2653 NS_ENSURE_SUCCESS( rv, rv );
2656 nsCOMPtr<sbITabBrowserTab> browserTab;
2657 tabbrowser->GetTabForDocument(
mContentDoc, getter_AddRefs(browserTab) );
2658 NS_ENSURE_STATE(browserTab);
2661 nsCOMPtr<nsIDOMElement> playlist;
2662 browserTab->GetPlaylist( getter_AddRefs(playlist) );
2663 NS_ENSURE_STATE(playlist);
2665 nsCOMPtr<sbIPlaylistWidget> playlistWidget ( do_QueryInterface( playlist,
2667 NS_ENSURE_SUCCESS( rv, rv );
2670 nsRefPtr<sbRemoteWebPlaylist> pWebPlaylist =
2672 NS_ENSURE_TRUE( pWebPlaylist, NS_ERROR_FAILURE );
2674 rv = pWebPlaylist->Init();
2675 NS_ENSURE_SUCCESS( rv, rv );
2698 NS_ENSURE_TRUE( scopeURI, NS_ERROR_FAILURE );
2700 nsCString scopeSpec;
2701 nsresult rv = scopeURI->GetSpec(scopeSpec);
2702 NS_ENSURE_SUCCESS( rv, rv );
2709 already_AddRefed<nsIURI>
2723 NS_ENSURE_SUCCESS( rv, nsnull);
2727 nsCOMPtr<sbISecurityMixin> mixin = do_QueryInterface(
mSecurityMixin, &rv );
2728 NS_ENSURE_SUCCESS( rv, nsnull );
2730 nsCOMPtr<nsIURI> codebaseURI;
2731 rv = mixin->GetCodebase( getter_AddRefs(codebaseURI) );
2732 NS_ENSURE_SUCCESS( rv, nsnull );
2735 nsCString scopeSpec;
2736 rv = codebaseURI->GetScheme(scopeSpec);
2737 NS_ENSURE_SUCCESS( rv, nsnull );
2739 scopeSpec.AppendLiteral(
":");
2741 nsCOMPtr<nsIURI> scopeURI;
2742 rv =
mIOService->NewURI( scopeSpec, nsnull, nsnull, getter_AddRefs(scopeURI) );
2743 NS_ENSURE_SUCCESS( rv, nsnull );
2746 NS_ENSURE_SUCCESS( rv, nsnull );
2749 NS_ENSURE_SUCCESS( rv, nsnull );
2751 scopeURI = NS_TryToMakeImmutable( scopeURI, &rv );
2752 NS_ENSURE_SUCCESS( rv, nsnull );
2755 return scopeURI.forget();
2760 const nsAString& aSiteID )
2762 LOG((
"sbRemotePlayer::SetDownloadScope()" ));
2763 NS_ASSERTION(aItem,
"aItem is null");
2764 NS_ASSERTION( !aSiteID.IsEmpty(),
"aSiteID is empty!" );
2769 nsCOMPtr<sbIMediaItem> mediaItem;
2770 nsCOMPtr<sbIWrappedMediaItem> wrappedMediaItem = do_QueryInterface( aItem,
2772 if (NS_SUCCEEDED(rv)) {
2773 mediaItem = wrappedMediaItem->GetMediaItem();
2774 NS_ENSURE_TRUE( mediaItem, NS_ERROR_FAILURE );
2779 nsString siteScopeURL;
2781 NS_ENSURE_SUCCESS(rv, rv);
2785 NS_ENSURE_SUCCESS( rv, rv );
2789 NS_ENSURE_SUCCESS( rv, rv );
2796 const nsAString& aSiteID )
2798 LOG((
"sbRemotePlayer::SetOriginScope()"));
2799 NS_ASSERTION( aItem,
"aItem is null" );
2800 NS_ASSERTION( !aSiteID.IsEmpty(),
"aSiteID is empty!" );
2803 NS_ENSURE_SUCCESS( rv, rv );
2807 NS_ENSURE_SUCCESS( rv, rv );
2810 NS_ENSURE_SUCCESS( rv, rv );
2824 const char *aLoaderStr,
2826 const nsModuleComponentInfo *aInfo )
2830 nsCOMPtr<nsICategoryManager> catMan(
2831 do_GetService(NS_CATEGORYMANAGER_CONTRACTID) );
2833 return NS_ERROR_FAILURE;
2836 rv = catMan->AddCategoryEntry( JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY,
2850 const char *aLoaderStr,
2851 const nsModuleComponentInfo *aInfo )
2855 nsCOMPtr<nsICategoryManager> catMan(
2856 do_GetService(NS_CATEGORYMANAGER_CONTRACTID) );
2858 return NS_ERROR_FAILURE;
2860 rv = catMan->DeleteCategoryEntry( JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY,
2868 const nsAString& aPropertyID,
2869 const nsAString& aDisplayName,
2870 const nsAString& aButtonLabel,
2873 PRBool aUserViewable,
2874 PRUint32 aNullSort )
2877 nsCString viewable = aUserViewable? NS_LITERAL_CSTRING(
"TRUE") : NS_LITERAL_CSTRING(
"FALSE");
2878 nsCString readonly = aReadonly? NS_LITERAL_CSTRING(
"TRUE") : NS_LITERAL_CSTRING(
"FALSE");
2879 LOG((
"sbRemotePlayer::CreateProperty(%s, %s, %s, %s, viewable:%s, :reado%s)",
2880 NS_LossyConvertUTF16toASCII(aPropertyType).
get(),
2881 NS_LossyConvertUTF16toASCII(aPropertyID).
get(),
2882 NS_LossyConvertUTF16toASCII(aDisplayName).
get(),
2883 NS_LossyConvertUTF16toASCII(aButtonLabel).
get(),
2889 nsCOMPtr<sbIPropertyManager> propMngr(
2891 NS_ENSURE_SUCCESS( rv, rv );
2894 nsCOMPtr<sbIPropertyInfo> info;
2895 propMngr->HasProperty( aPropertyID, &hasProp );
2901 if (aPropertyType.EqualsLiteral(
"text") ||
2902 aPropertyType.EqualsLiteral(
"datetime") ||
2903 aPropertyType.EqualsLiteral(
"uri") ||
2904 aPropertyType.EqualsLiteral(
"number")) {
2905 if ( aPropertyType.EqualsLiteral(
"text") ){
2907 }
else if ( aPropertyType.EqualsLiteral(
"datetime") ) {
2909 NS_ENSURE_SUCCESS( rv, rv );
2911 nsCOMPtr<sbIDatetimePropertyInfo> dtInfo( do_QueryInterface( info, &rv ) );
2912 NS_ENSURE_SUCCESS( rv, rv );
2914 rv = dtInfo->SetTimeType(aTimeType);
2915 NS_ENSURE_SUCCESS( rv, rv );
2917 }
else if ( aPropertyType.EqualsLiteral(
"uri") ) {
2919 }
else if ( aPropertyType.EqualsLiteral(
"number") ) {
2922 NS_ENSURE_SUCCESS( rv, rv );
2926 rv = info->SetId(aPropertyID);
2927 NS_ENSURE_SUCCESS( rv, rv );
2928 rv = info->SetDisplayName(aDisplayName);
2929 NS_ENSURE_SUCCESS( rv, rv );
2930 rv = info->SetUserViewable(aUserViewable);
2931 NS_ENSURE_SUCCESS( rv, rv );
2933 rv = info->SetUserEditable(aReadonly ? PR_FALSE : PR_TRUE);
2934 NS_ENSURE_SUCCESS( rv, rv );
2935 rv = info->SetNullSort(aNullSort);
2936 NS_ENSURE_SUCCESS( rv, rv );
2941 nsCOMPtr<sbIPropertyBuilder> builder;
2942 if (aPropertyType.EqualsLiteral(
"button")) {
2943 LOG((
"sbRemotePlayer::CreateProperty() - using a button builder" ));
2946 NS_ENSURE_SUCCESS(rv, rv);
2948 nsCOMPtr<sbISimpleButtonPropertyBuilder> buttonBuilder (
2949 do_QueryInterface(builder));
2950 NS_ENSURE_STATE(buttonBuilder);
2952 rv = buttonBuilder->SetLabel(aButtonLabel);
2953 NS_ENSURE_SUCCESS(rv, rv);
2955 else if (aPropertyType.EqualsLiteral(
"image")) {
2956 LOG((
"sbRemotePlayer::CreateProperty() - using a image builder" ));
2959 NS_ENSURE_SUCCESS(rv, rv);
2961 else if (aPropertyType.EqualsLiteral(
"downloadbutton")) {
2962 LOG((
"sbRemotePlayer::CreateProperty() - using a downloadbutton builder" ));
2965 NS_ENSURE_SUCCESS(rv, rv);
2967 nsCOMPtr<sbIDownloadButtonPropertyBuilder> dlBuilder (
2968 do_QueryInterface(builder));
2969 NS_ENSURE_STATE(dlBuilder);
2971 rv = dlBuilder->SetLabel(aButtonLabel);
2972 NS_ENSURE_SUCCESS(rv, rv);
2974 else if (aPropertyType.EqualsLiteral(
"rating")) {
2975 LOG((
"sbRemotePlayer::CreateProperty() - using a rating builder" ));
2978 NS_ENSURE_SUCCESS(rv, rv);
2982 return NS_ERROR_FAILURE;
2987 rv = builder->SetPropertyID(aPropertyID);
2988 NS_ENSURE_SUCCESS(rv, rv);
2989 rv = builder->SetDisplayName(aDisplayName);
2990 NS_ENSURE_SUCCESS(rv, rv);
2991 rv = builder->SetRemoteReadable(PR_TRUE);
2992 NS_ENSURE_SUCCESS(rv, rv);
2993 rv = builder->SetRemoteWritable(PR_TRUE);
2994 NS_ENSURE_SUCCESS(rv, rv);
2995 rv = builder->SetUserViewable(aUserViewable);
2996 NS_ENSURE_SUCCESS( rv, rv );
2997 rv = builder->SetUserEditable(aReadonly ? PR_FALSE : PR_TRUE);
2998 NS_ENSURE_SUCCESS( rv, rv );
2999 rv = builder->Get(getter_AddRefs(info));
3000 NS_ENSURE_SUCCESS(rv, rv);
3006 if (NS_SUCCEEDED(rv) ) {
3007 LOG((
"sbRemotePlayer::CreateProperty() - we have a propertyInfo item" ));
3008 rv = info->SetRemoteWritable(PR_TRUE);
3009 if ( NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED ) {
3013 rv = info->SetRemoteReadable(PR_TRUE);
3014 if ( NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED ) {
3018 LOG((
"sbRemotePlayer::CreateProperty() - we DONT have a propertyInfo item" ));
3022 rv = propMngr->AddPropertyInfo(info);
3023 NS_ENSURE_SUCCESS( rv, rv );
3031 sbRemotePlayer::CreateTextProperty(
const nsAString& aPropertyID,
3032 const nsAString& aDisplayName,
3034 PRBool aUserViewable,
3035 PRUint32 aNullSort )
3048 sbRemotePlayer::CreateDateTimeProperty(
const nsAString& aPropertyID,
3049 const nsAString& aDisplayName,
3052 PRBool aUserViewable,
3053 PRUint32 aNullSort )
3066 sbRemotePlayer::CreateURIProperty(
const nsAString& aPropertyID,
3067 const nsAString& aDisplayName,
3069 PRBool aUserViewable,
3083 sbRemotePlayer::CreateNumberProperty(
const nsAString& aPropertyID,
3084 const nsAString& aDisplayName,
3086 PRBool aUserViewable,
3087 PRUint32 aNullSort )
3100 sbRemotePlayer::CreateImageProperty(
const nsAString& aPropertyID,
3101 const nsAString& aDisplayName,
3103 PRBool aUserViewable,
3104 PRUint32 aNullSort )
3117 sbRemotePlayer::CreateRatingsProperty(
const nsAString& aPropertyID,
3118 const nsAString& aDisplayName,
3120 PRBool aUserViewable,
3121 PRUint32 aNullSort )
3134 sbRemotePlayer::CreateButtonProperty(
const nsAString& aPropertyID,
3135 const nsAString& aDisplayName,
3136 const nsAString& aButtonLabel,
3138 PRBool aUserViewable,
3139 PRUint32 aNullSort )
3152 sbRemotePlayer::CreateDownloadButtonProperty(
const nsAString& aPropertyID,
3153 const nsAString& aDisplayName,
3154 const nsAString& aButtonLabel,
3156 PRBool aUserViewable,
3157 PRUint32 aNullSort )
3170 sbRemotePlayer::HasAccess(
const nsAString& aRemotePermCategory,
3173 nsCOMPtr<sbISecurityMixin> mixin;
3179 PRInt32 iIndex = -1;
3197 return mixin->GetPermissionForScopedNameWrapper( mCategory, _retval );
3210 LOG((
"sbRemotePlayerDownloadCallback::sbRemotePlayerDownloadCallback()"));
3215 LOG((
"sbRemotePlayerDownloadCallback::~sbRemotePlayerDownloadCallback()"));
3221 LOG((
"sbRemotePlayerDownloadCallback::Initialize()"));
3222 NS_ASSERTION(aRemotePlayer,
"aRemotePlayer is null");
3227 mWeakRemotePlayer = do_GetWeakReference
3229 NS_ENSURE_SUCCESS(rv, rv);
3232 nsCOMPtr<sbISecurityMixin> mixin =
3234 NS_ENSURE_SUCCESS( rv, rv );
3235 rv = mixin->GetCodebase( getter_AddRefs(mCodebaseURI) );
3238 mIOService = do_GetService(
"@mozilla.org/network/io-service;1", &rv);
3241 nsCOMPtr<sbIDeviceManager> deviceManager;
3242 PRBool hasDeviceForCategory;
3244 deviceManager = do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;1",
3246 NS_ENSURE_SUCCESS(rv, rv);
3247 rv = deviceManager->HasDeviceForCategory
3248 (NS_LITERAL_STRING(
"Songbird Download Device"), &hasDeviceForCategory);
3249 NS_ENSURE_SUCCESS(rv, rv);
3250 NS_ENSURE_TRUE(hasDeviceForCategory, NS_ERROR_UNEXPECTED);
3251 rv = deviceManager->GetDeviceByCategory
3252 (NS_LITERAL_STRING(
"Songbird Download Device"),
3253 getter_AddRefs(mDownloadDevice));
3254 NS_ENSURE_SUCCESS(rv, rv);
3255 rv = mDownloadDevice->AddCallback(
this);
3256 NS_ENSURE_SUCCESS(rv, rv);
3264 LOG((
"sbRemotePlayerDownloadCallback::Finalize()"));
3266 if (mDownloadDevice)
3267 mDownloadDevice->RemoveCallback(
this);
3277 sbRemotePlayerDownloadCallback::OnDeviceConnect
3278 (
const nsAString &aDeviceIdentifier )
3284 sbRemotePlayerDownloadCallback::OnDeviceDisconnect
3285 (
const nsAString &aDeviceIdentifier )
3291 sbRemotePlayerDownloadCallback::OnTransferStart(
sbIMediaItem* aMediaItem )
3293 LOG((
"sbRemotePlayer::OnTransferStart()"));
3294 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
3298 rv = CheckItemScope( aMediaItem );
3302 nsCOMPtr<sbIRemotePlayer> remotePlayer =
3303 do_QueryReferent(mWeakRemotePlayer, &rv);
3304 NS_ENSURE_SUCCESS(rv, rv);
3306 rv = remotePlayer->FireMediaItemStatusEventToContent
3311 NS_ENSURE_SUCCESS(rv, rv);
3317 sbRemotePlayerDownloadCallback::OnTransferComplete(
sbIMediaItem* aMediaItem,
3320 LOG((
"sbRemotePlayer::OnTransferComplete()"));
3321 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
3325 rv = CheckItemScope( aMediaItem );
3329 nsCOMPtr<sbIRemotePlayer> remotePlayer =
3330 do_QueryReferent(mWeakRemotePlayer, &rv);
3331 NS_ENSURE_SUCCESS(rv, rv);
3333 rv = remotePlayer->FireMediaItemStatusEventToContent
3338 NS_ENSURE_SUCCESS(rv, rv);
3344 sbRemotePlayerDownloadCallback::OnStateChanged
3345 (
const nsAString &aDeviceIdentifier,
3352 sbRemotePlayerDownloadCallback::CheckItemScope(
sbIMediaItem* aMediaItem )
3354 LOG((
"sbRemotePlayer::CheckItemScope()"));
3358 nsCAutoString scopeDomain;
3359 nsCAutoString scopePath;
3360 rv = GetItemScope( aMediaItem, scopeDomain, scopePath );
3361 NS_ENSURE_SUCCESS(rv, rv);
3370 sbRemotePlayerDownloadCallback::GetItemScope(
sbIMediaItem* aMediaItem,
3371 nsACString& aScopeDomain,
3372 nsACString& aScopePath )
3374 LOG((
"sbRemotePlayer::GetItemScope()"));
3375 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
3379 nsAutoString scopeSpec;
3382 if (NS_FAILED(rv) || scopeSpec.IsEmpty()) {
3386 if (NS_FAILED(rv) || scopeSpec.IsEmpty())
3391 nsCOMPtr<nsIURI> scopeURI;
3392 rv = mIOService->NewURI( NS_ConvertUTF16toUTF8(scopeSpec),
3395 getter_AddRefs(scopeURI) );
3396 NS_ENSURE_SUCCESS(rv, rv);
3400 NS_ENSURE_SUCCESS(rv, rv);
#define SONGBIRD_REMOTEPLAYER_CLASSNAME
nsresult InitPrivileged(nsIURI *aCodebase, nsIDOMWindow *aWindow)
static const char * sPublicRProperties[]
PRBool mUseDefaultCommands
static nsresult SB_WrapMediaList(sbRemotePlayer *aRemotePlayer, sbIMediaList *aMediaList, sbIMediaList **aRemoteMediaList)
An interface to control a media list from remote web pages.
nsCOMPtr< sbIDataRemote > mdrRepeat
nsresult OnViewChange(sbIMediacoreEvent *aEvent)
static PRBool GetUserApprovalForHost(nsIURI *aURI, const nsAString &aTitleKey, const nsAString &aMessageKey, const char *aScopedName=nsnull)
readonly attribute sbIRemoteMediaList downloadMediaList
nsCOMPtr< sbIDataRemote > mdrCurrentAlbum
friend class sbRemotePlayerDownloadCallback
#define RAPI_EVENT_TYPE_TRACKCHANGE
static already_AddRefed< nsPIDOMWindow > GetWindowFromJS()
nsresult ConfirmPlaybackControl()
#define SB_TEXTPROPERTYINFO_CONTRACTID
#define SB_PROPERTY_RAPISITEID
#define SB_DOWNLOADBUTTONPROPERTYBUILDER_CONTRACTID
nsCOMPtr< sbIDataRemote > mdrMute
PR_STATIC_CALLBACK(PRBool) FindElementCallback(void *aElement
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
#define SB_URIPROPERTYINFO_CONTRACTID
virtual ~sbRemotePlayerDownloadCallback()
#define SB_EVENT_RAPI_PERMISSION_DENIED
nsRefPtr< sbRemoteCommands > mCommandsObject
function doc() browser.contentDocument
static nsresult CheckURI(nsACString &aDomain, nsACString &aPath, nsIURI *aURI)
nsCOMPtr< sbIDataRemote > mdrPlaying
readonly attribute long long volume
The volume on a range from 0 to 255.
#define SONGBIRD_REMOTEPLAYER_CONTRACTID
boolean hasAccess(in AString aRemotePermCataegory)
Check if the code has access to a category.
nsCOMPtr< nsIJSContextStack > mStack
UnbindAndRelease(const nsAString &aKey, sbRemoteObserver &aRemObs, void *userArg)
#define SB_NUMBERPROPERTYINFO_CONTRACTID
readonly attribute sbIRemotePlayer remotePlayer
nsresult InitInternal(nsPIDOMWindow *aWindow)
This interface is a composition of many of our other interfaces with the goal of exposing a more web-...
#define SB_IMAGEPROPERTYBUILDER_CONTRACTID
already_AddRefed< nsIURI > GetSiteScopeURI()
NS_INTERFACE_MAP_END NS_IMPL_CI_INTERFACE_GETTER6(sbDeviceLibrary, nsIClassInfo, sbIDeviceLibrary, sbILibrary, sbIMediaList, sbIMediaItem, sbILibraryResource) sbDeviceLibrary
nsCOMPtr< nsIDOMDocument > mContentDoc
nsRefPtr< sbRemoteWebPlaylist > mRemWebPlaylist
#define SB_SIMPLEBUTTONPROPERTYBUILDER_CONTRACTID
nsCOMPtr< nsPIDOMWindow > mPrivWindow
sbOSDControlService prototype QueryInterface
#define SB_PROPERTY_RAPISCOPEURL
nsCOMPtr< nsIWeakReference > mMM
#define RAPI_VERSION_MAJOR
virtual ~sbRemotePlayer()
static const char * sPublicWProperties[]
nsresult SetOriginScope(sbIMediaItem *aItem, const nsAString &aSiteID)
[SOON TO BE DEPRECATED AFTER 0.3] The callback class for sbIDeviceBase
#define SONGBIRD_REMOTEPLAYER_CID
static NS_METHOD Register(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const char *aType, const nsModuleComponentInfo *aInfo)
nsISecurityCheckedComponent
#define SB_PROPERTYMANAGER_CONTRACTID
An interface for setting up nsISecurityCheckedComponent security checks.
#define RAPI_EVENT_TYPE_BEFORETRACKCHANGE
NS_IMETHODIMP OnEnumerationBegin(sbIMediaList *, PRUint16 *_retval)
#define RAPI_EVENT_TYPE_STOP
nsDataHashtable< nsStringHashKey, sbRemoteObserver > mRemObsHash
#define RAPI_EVENT_TYPE_DOWNLOADSTART
static const char * sPublicMethods[]
static nsresult DispatchEvent(nsIDOMDocument *aDocument, const nsAString &aClass, const nsAString &aType, PRBool aIsTrusted)
nsCOMPtr< nsIIOService > mIOService
#define RAPI_VERSION_MINOR
An interface for a sandbox library created by the website.
static nsresult StandardPlay(nsIWeakReference *aWeakRef)
#define SB_PROPERTY_ORIGINPAGE
nsresult OnBeforeViewChange(sbIMediacoreEvent *aEvent)
nsRefPtr< sbRemoteNotificationManager > mNotificationMgr
nsresult SetDownloadScope(sbIMediaItem *aItem, const nsAString &aSiteID)
An interface to specify playlist commands from remote web pages.
nsCOMPtr< nsISecurityCheckedComponent > mSecurityMixin
nsresult InitRemoteWebPlaylist()
return e ctrlKey(chr<' '||!chars||chars.indexOf(chr)>-1)
nsCOMPtr< nsIDOMDocument > mChromeDoc
nsCOMPtr< sbIDataRemote > mdrCurrentTrack
A marker interface for objects that aggregate the security mixin.
void nsString_Split(const nsAString &aString, const nsAString &aDelimiter, nsTArray< nsString > &aSubStringArray)
nsresult OnTrackChange(sbIMediacoreEvent *aEvent)
nsresult OnTrackIndexChange(sbIMediacoreEvent *aEvent)
sbISecurityAggregator SB_IMPL_CLASSINFO(sbRemotePlayer,"@songbirdnest.com/remoteapi/remoteplayer;1","Songbird Remote Player", nsIProgrammingLanguage::CPLUSPLUS, 0, kRemotePlayerCID) sbRemotePlayer
static const char * sPublicMetadata[]
already_AddRefed< nsPIDOMWindow > GetWindow()
nsCOMPtr< sbIDataRemote > mdrShuffle
#define SB_DATETIMEPROPERTYINFO_CONTRACTID
An interface to control a media library from remote web pages.
#define SB_RATINGPROPERTYBUILDER_CONTRACTID
nsCOMPtr< sbIDataRemote > mdrPosition
#define RAPI_EVENT_TYPE_TRACKINDEXCHANGE
NS_IMETHODIMP OnEnumerationEnd(sbIMediaList *, nsresult)
#define RAPI_EVENT_TYPE_BEFOREVIEW
readonly attribute sbIRemoteCommands commands
The collection of commands associated with the current page.
nsresult GetBrowser(nsIDOMElement **aElement)
static NS_DEFINE_CID(kRemotePlayerCID,{0x645e064c, 0xe547, 0x444c,{0xbb, 0x41, 0x8f, 0x2e, 0x5b, 0x12, 0x70, 0x0b}})
#define SB_WEB_TABBROWSER
An interface that represents the set of command buttons and context menu items available on a display...
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)
readonly attribute AString name
The name of the player.
nsCOMPtr< sbIDataRemote > remote
NS_IMPL_ISUPPORTS7(sbRemotePlayer, nsIClassInfo, nsISecurityCheckedComponent, sbIRemotePlayer, nsIDOMEventListener, nsISupportsWeakReference, sbIMediacoreEventListener, sbISecurityAggregator) NS_IMPL_CI_INTERFACE_GETTER6(sbRemotePlayer
static nsresult GetFilenameForSiteLibrary(const nsACString &aDomain, const nsACString &aPath, nsAString &_retval)
static nsresult GetJSScopeNameFromScope(const nsACString &aScopeName, nsAString &aJSScopeName)
nsresult UnregisterCommands()
nsresult RegisterCommands(PRBool aUseDefaultCommands)
#define SB_EVENT_RAPI_PERMISSION_CHANGED
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)
nsresult GetMainLibrary(sbILibrary **aMainLibrary)
#define RAPI_EVENT_TYPE_DOWNLOADCOMPLETE
sbRemoteNotificationManager * GetNotificationManager()
nsCOMPtr< sbIRemoteObserver > observer
#define RAPI_EVENT_TYPE_VIEW
nsInterfaceHashtable< nsStringHashKey, sbIRemoteLibrary > mCachedLibraries
nsCOMPtr< nsIURI > mSiteScopeURI
_getSelectedPageStyle s i
NS_IMETHODIMP OnEnumeratedItem(sbIMediaList *, sbIMediaItem *aItem, PRUint16 *_retval)
nsresult GetSiteScopeURL(nsAString &aURL)
Lightweight Observer style interface for use with sbIRemotePlayer::addListener.
NS_DECL_ISUPPORTS sbRemotePlayerEnumCallback(nsCOMArray< sbIMediaItem > &aArray)
static const char * sPublicCategoryConversions[][2]
static nsresult SetPermission(nsIURI *aURI, const nsACString &aScopedName)
Set the permission to allow for a scoped name.