30 #include <nsICategoryManager.h>
31 #include <nsIDocument.h>
32 #include <nsIDOMDocument.h>
33 #include <nsIDOMDocumentEvent.h>
34 #include <nsIDOMEvent.h>
35 #include <nsIDOMEventTarget.h>
36 #include <nsIDOMWindow.h>
38 #include <nsIMutableArray.h>
39 #include <nsIObserver.h>
40 #include <nsIPrefService.h>
41 #include <nsIPresShell.h>
42 #include <nsISimpleEnumerator.h>
43 #include <nsIStringBundle.h>
44 #include <nsIStringEnumerator.h>
45 #include <nsISupportsPrimitives.h>
46 #include <nsIWindowWatcher.h>
47 #include <sbILibrary.h>
48 #include <sbILibraryConstraints.h>
49 #include <sbILibraryManager.h>
50 #include <sbIFilterableMediaListView.h>
51 #include <sbIMediaList.h>
52 #include <sbIMediaListView.h>
53 #include <sbIFileMetadataService.h>
54 #include <sbIPlaylistReader.h>
55 #include <sbIPropertyArray.h>
58 #include <sbIJobProgress.h>
61 #include <nsArrayEnumerator.h>
62 #include <nsCOMArray.h>
63 #include <nsEnumeratorUtils.h>
64 #include <nsEventDispatcher.h>
65 #include <nsNetUtil.h>
66 #include <nsServiceManagerUtils.h>
67 #include <nsStringGlue.h>
69 #include <nsTHashtable.h>
82 #include <sbILibraryStatistics.h>
89 PRLogModuleInfo* gRemoteLibraryLog = nsnull;
93 #define LOG(args) LOG_LIB(args)
94 #define TRACE(args) TRACE_LIBS(args)
105 PRBool aShouldScan) :
106 mRemotePlayer(aRemotePlayer),
107 mCallback(aCallback),
108 mShouldScan(aShouldScan)
110 NS_ASSERTION(aRemotePlayer,
"aRemotePlayer is null");
111 NS_ASSERTION(aCallback,
"aCallback is null");
116 const PRUnichar *
aData)
118 NS_ENSURE_ARG_POINTER(aSubject);
119 LOG((
"sbPlaylistReaderObserver::Observe(%s)", aTopic ));
123 nsCOMPtr<sbIMediaList> mediaList ( do_QueryInterface( aSubject, &rv ) );
124 NS_ENSURE_SUCCESS(rv, rv);
127 rv = mediaList->GetLength( &length );
128 NS_ENSURE_SUCCESS(rv, rv);
130 if (mShouldScan && length) {
132 nsCOMPtr<nsIMutableArray> mediaItems =
133 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv );
134 NS_ENSURE_SUCCESS(rv, rv);
136 for ( PRUint32 index = 0; index < length; index++ ) {
138 nsCOMPtr<sbIMediaItem> item;
139 rv = mediaList->GetItemByIndex( index, getter_AddRefs ( item ) );
140 NS_ENSURE_SUCCESS(rv, rv);
142 rv = mediaItems->AppendElement( item, PR_FALSE );
143 NS_ENSURE_SUCCESS(rv, rv);
146 nsCOMPtr<sbIFileMetadataService> metadataService =
147 do_GetService(
"@songbirdnest.com/Songbird/FileMetadataService;1", &rv );
148 NS_ENSURE_SUCCESS(rv, rv);
149 nsCOMPtr<sbIJobProgress> job;
151 rv = metadataService->Read( mediaItems, getter_AddRefs(job) );
152 NS_ENSURE_SUCCESS(rv, rv);
156 nsCOMPtr<sbIMediaList> wrappedList;
159 getter_AddRefs(wrappedList));
160 NS_ENSURE_SUCCESS(rv, rv);
161 mCallback->OnCreated(wrappedList);
175 nsRefPtr<sbRemotePlayer> mRemotePlayer;
176 nsCOMPtr<sbICreateMediaListCallback> mCallback;
191 NS_ENSURE_ARG(_retval);
201 NS_ENSURE_ARG(_retval);
204 mArray.AppendObject( aItem );
209 nsCOMArray<sbIMediaItem>& mArray;
221 length(path.Length())
223 NS_ASSERTION( item,
"Null pointer!");
231 PRBool
operator <(
const sbRemoteLibraryScopeURLSet& rhs)
const
233 return length < rhs.
length;
237 const nsCOMPtr<sbIMediaItem>
item;
256 mShouldScan(PR_TRUE),
257 mEnumerationResult(NS_ERROR_NOT_INITIALIZED),
258 mRemotePlayer(aRemotePlayer),
259 mIgnoreHiddenPlaylists(PR_TRUE),
260 mAllowDuplicates(PR_FALSE)
262 NS_ASSERTION(aRemotePlayer,
"aRemotePlayer is null");
264 if (!gRemoteLibraryLog) {
265 gRemoteLibraryLog = PR_NewLogModule(
"sbRemoteLibrary");
267 LOG_LIB((
"sbRemoteLibraryBase::sbRemoteLibraryBase()"));
273 LOG_LIB((
"sbRemoteLibraryBase::~sbRemoteLibraryBase()"));
285 LOG_LIB((
"sbRemoteLibraryBase::SetProperty( %s, %s )",
286 NS_LossyConvertUTF16toASCII(aID).
get(),
287 NS_LossyConvertUTF16toASCII(aValue).
get() ));
296 nsCOMPtr<sbIMediaItem> item( do_QueryInterface( (
sbIRemoteLibrary*)
this, &rv ) );
297 NS_ENSURE_SUCCESS( rv, rv );
300 NS_ENSURE_SUCCESS( rv, rv );
304 if ( StringBeginsWith( aID,
305 NS_LITERAL_STRING(
"http://songbirdnest.com/") ) ) {
307 LOG_LIB((
"sbRemoteLibraryBase::SetProperty() - DENIED" ));
308 return NS_ERROR_FAILURE;
316 nsCOMPtr<sbIRemoteSiteLibrary> siteLib( do_QueryInterface((
sbIRemoteLibrary*)
this, &rv ) );
317 if ( NS_FAILED(rv) || !siteLib ) {
319 LOG_LIB((
"sbRemoteLibraryBase::SetProperty() - DENIED" ));
320 return NS_ERROR_FAILURE;
326 LOG_LIB((
"sbRemoteLibraryBase::SetProperty() - ALLOWED" ));
341 NS_ENSURE_ARG_POINTER(aRemotePlayer);
344 *aRemotePlayer = nsnull;
349 NS_ENSURE_SUCCESS( rv, rv );
351 remotePlayer.swap( *aRemotePlayer );
363 sbRemoteLibraryBase::GetScanMediaOnCreation( PRBool *aShouldScan )
365 NS_ENSURE_ARG_POINTER(aShouldScan);
371 sbRemoteLibraryBase::SetScanMediaOnCreation( PRBool aShouldScan )
378 sbRemoteLibraryBase::ConnectToDefaultLibrary(
const nsAString &aLibName )
380 LOG_LIB((
"sbRemoteLibraryBase::ConnectToDefaultLibrary(guid:%s)",
381 NS_LossyConvertUTF16toASCII(aLibName).
get() ));
385 if ( NS_SUCCEEDED(rv) ) {
386 LOG_LIB((
"sbRemoteLibraryBase::ConnectToDefaultLibrary(%s) -- IS a default library",
387 NS_LossyConvertUTF16toASCII(guid).
get() ));
390 nsCOMPtr<sbILibraryManager> libManager(
391 do_GetService(
"@songbirdnest.com/Songbird/library/Manager;1", &rv ) );
392 NS_ENSURE_SUCCESS( rv, rv );
394 rv = libManager->GetLibrary( guid, getter_AddRefs(
mLibrary) );
395 NS_ENSURE_SUCCESS( rv, rv );
398 NS_ENSURE_SUCCESS(rv, rv);
404 sbRemoteLibraryBase::CreateMediaItem(
const nsAString& aURL,
407 NS_ENSURE_ARG_POINTER(_retval);
410 LOG_LIB((
"sbRemoteLibraryBase::CreateMediaItem()"));
412 nsCOMPtr<nsIURI>
uri;
413 nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL);
414 NS_ENSURE_SUCCESS(rv, rv);
418 uri->SchemeIs(
"http", &validScheme);
420 uri->SchemeIs(
"https", &validScheme);
422 return NS_ERROR_INVALID_ARG;
429 nsCOMPtr<sbIMediaItem> mediaItem;
433 getter_AddRefs(mediaItem));
434 NS_ENSURE_SUCCESS(rv, rv);
438 NS_ENSURE_SUCCESS(rv, rv);
442 nsCOMPtr<sbIFileMetadataService> metadataService =
443 do_GetService(
"@songbirdnest.com/Songbird/FileMetadataService;1", &rv );
444 NS_ASSERTION(NS_SUCCEEDED(rv),
"Failed to get FileMetadataService!");
446 if(NS_SUCCEEDED(rv)) {
447 LOG_LIB((
"sbRemoteLibraryBase::CreateMediaItem() -- doing a MD scan"));
449 nsCOMPtr<nsIMutableArray> mediaItems =
450 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
451 NS_ENSURE_SUCCESS(rv, rv);
453 rv = mediaItems->AppendElement(mediaItem, PR_FALSE);
454 NS_ENSURE_SUCCESS(rv, rv);
456 nsCOMPtr<sbIJobProgress> job;
457 rv = metadataService->Read( mediaItems, getter_AddRefs(job) );
458 NS_ENSURE_SUCCESS(rv, rv);
464 NS_ENSURE_SUCCESS(rv, rv);
473 sbRemoteLibraryBase::CreateSimpleMediaList(
const nsAString&
aName,
474 const nsAString& aSiteID,
477 NS_ENSURE_ARG(!aName.IsEmpty());
478 NS_ENSURE_ARG_POINTER(_retval);
481 if (aSiteID.IsEmpty()) {
482 siteID.Assign(aName);
485 siteID.Assign(aSiteID);
489 nsCOMPtr<sbIMediaList> mediaList;
492 nsCOMPtr<sbIWrappedMediaList> wrappedList =
493 do_QueryInterface( remMediaList, &rv );
494 NS_ENSURE_SUCCESS( rv, rv );
496 mediaList = wrappedList->GetMediaList();
497 NS_ENSURE_TRUE( mediaList, NS_ERROR_FAILURE );
501 rv =
mLibrary->CreateMediaList( NS_LITERAL_STRING(
"simple"), nsnull,
502 getter_AddRefs(mediaList) );
503 NS_ENSURE_SUCCESS( rv, rv );
506 nsCOMPtr<sbIMediaItem> listAsItem( do_QueryInterface( mediaList, &rv ) );
507 NS_ENSURE_SUCCESS( rv, rv) ;
510 NS_ENSURE_SUCCESS( rv, rv );
513 getter_AddRefs(remMediaList) );
514 NS_ENSURE_SUCCESS( rv, rv );
519 NS_ENSURE_SUCCESS( rv, rv );
524 NS_ADDREF(*_retval = remMediaList);
529 sbRemoteLibraryBase::CreateMediaListFromURL(
const nsAString& aName,
530 const nsAString& aURL,
532 const nsAString& aSiteID )
534 NS_ENSURE_ARG(!aName.IsEmpty());
535 NS_ENSURE_ARG(!aURL.IsEmpty());
538 LOG_LIB((
"sbRemoteLibraryBase::CreateMediaListFromURL(%s)",
539 NS_LossyConvertUTF16toASCII(aURL).
get() ));
542 if (aSiteID.IsEmpty()) {
543 siteID.Assign(aName);
546 siteID.Assign(aSiteID);
550 nsCOMPtr<sbIMediaList> mediaList;
553 nsCOMPtr<sbIWrappedMediaList> wrappedList =
554 do_QueryInterface( remMediaList, &rv );
555 NS_ENSURE_SUCCESS( rv, rv );
557 mediaList = wrappedList->GetMediaList();
558 NS_ENSURE_TRUE( mediaList, NS_ERROR_FAILURE );
561 rv =
mLibrary->CreateMediaList( NS_LITERAL_STRING(
"simple"), nsnull,
562 getter_AddRefs(mediaList) );
563 NS_ENSURE_SUCCESS(rv, rv);
566 nsCOMPtr<sbIMediaItem> mediaItem(do_QueryInterface(mediaList));
567 NS_ENSURE_TRUE(mediaItem, NS_ERROR_FAILURE);
570 NS_ENSURE_SUCCESS(rv, rv);
575 NS_ENSURE_SUCCESS( rv, rv );
580 nsCOMPtr<sbIPlaylistReaderManager> manager =
581 do_GetService(
"@songbirdnest.com/Songbird/PlaylistReaderManager;1",
583 NS_ENSURE_SUCCESS(rv, rv);
585 nsCOMPtr<nsIURI>
uri;
586 rv = NS_NewURI(getter_AddRefs(uri), aURL);
587 NS_ENSURE_SUCCESS(rv, rv);
591 uri->SchemeIs(
"http", &validScheme);
593 uri->SchemeIs(
"https", &validScheme);
595 return NS_ERROR_INVALID_ARG;
599 nsCOMPtr<sbIPlaylistReaderListener> lstnr =
600 do_CreateInstance(
"@songbirdnest.com/Songbird/PlaylistReaderListener;1",
602 NS_ENSURE_SUCCESS(rv, rv);
604 nsRefPtr<sbPlaylistReaderObserver> readerObserver =
606 NS_ENSURE_TRUE( readerObserver, NS_ERROR_OUT_OF_MEMORY );
608 nsCOMPtr<nsIObserver>
observer( do_QueryInterface( readerObserver, &rv ) );
609 NS_ENSURE_SUCCESS(rv, rv);
611 rv = lstnr->SetObserver(
observer );
612 NS_ENSURE_SUCCESS(rv, rv);
615 rv = manager->LoadPlaylist( uri, mediaList, EmptyString(),
true, lstnr, &dummy );
616 NS_ENSURE_SUCCESS(rv, rv);
625 NS_ENSURE_ARG(!aSiteID.IsEmpty());
626 NS_ENSURE_ARG_POINTER(_retval);
629 NS_IF_ADDREF(*_retval = list);
637 PRBool result = PR_FALSE;
638 nsCOMPtr<sbIRemoteLibrary> siteLibrary;
639 nsresult rv = aRemotePlayer->GetSiteLibrary( getter_AddRefs(siteLibrary) );
640 if ( NS_SUCCEEDED(rv) ) {
641 nsCOMPtr<sbIMediaItem> siteLibraryAsItem = do_QueryInterface(siteLibrary);
642 nsCOMPtr<sbIMediaItem> libraryAsItem = do_QueryInterface(aLibrary);
643 PRBool equal = PR_FALSE;
644 result = ( siteLibraryAsItem &&
646 NS_SUCCEEDED( siteLibraryAsItem->Equals( libraryAsItem, &equal ) ) &&
655 LOG_LIB((
"sbRemoteLibraryBase::GetPlaylists()"));
657 NS_ENSURE_ARG_POINTER(_retval);
661 nsCOMPtr<sbIMediaList> mediaList = do_QueryInterface(
mLibrary, &rv );
662 NS_ENSURE_SUCCESS( rv, rv );
667 NS_LITERAL_STRING(
"1"),
670 NS_ENSURE_SUCCESS( rv, rv );
672 nsCOMPtr<nsISimpleEnumerator> playlistEnum;
677 if ( !playlistEnum ) {
678 NS_WARNING(
"Failed to make array enumerator");
682 NS_WARNING(
"Item enumeration failed!");
691 NS_ADDREF( *_retval = playlistEnum );
709 LOG_LIB((
"sbRemoteLibraryBase::GetArtists()"));
710 NS_ENSURE_ARG_POINTER(_retval);
713 nsCOMPtr<sbIMediaListView> view;
714 rv =
mRemMediaList->CreateView( nsnull, getter_AddRefs(view) );
715 NS_ENSURE_SUCCESS( rv, rv );
717 nsCOMPtr<sbIFilterableMediaListView> filterView =
718 do_QueryInterface( view, &rv );
719 NS_ENSURE_SUCCESS( rv, rv );
721 nsRefPtr<sbScriptableFilter>
filter =
725 NS_ENSURE_TRUE( filter, NS_ERROR_OUT_OF_MEMORY );
727 NS_ADDREF(*_retval = filter);
734 LOG_LIB((
"sbRemoteLibraryBase::GetAlbums()"));
735 NS_ENSURE_ARG_POINTER(_retval);
738 nsCOMPtr<sbIMediaListView> view;
739 rv =
mRemMediaList->CreateView( nsnull, getter_AddRefs(view) );
740 NS_ENSURE_SUCCESS( rv, rv );
742 nsCOMPtr<sbIFilterableMediaListView> filterView =
743 do_QueryInterface( view, &rv );
744 NS_ENSURE_SUCCESS( rv, rv );
746 nsRefPtr<sbScriptableFilter> filter =
750 NS_ENSURE_TRUE( filter, NS_ERROR_OUT_OF_MEMORY );
752 NS_ADDREF(*_retval = filter);
759 LOG_LIB((
"sbRemoteLibraryBase::GetGenres()"));
760 NS_ENSURE_ARG_POINTER(_retval);
763 nsCOMPtr<sbIMediaListView> view;
764 rv =
mRemMediaList->CreateView( nsnull, getter_AddRefs(view) );
765 NS_ENSURE_SUCCESS( rv, rv );
767 nsCOMPtr<sbIFilterableMediaListView> filterView =
768 do_QueryInterface( view, &rv );
769 NS_ENSURE_SUCCESS( rv, rv );
771 nsRefPtr<sbScriptableFilter> filter =
775 NS_ENSURE_TRUE( filter, NS_ERROR_OUT_OF_MEMORY );
777 NS_ADDREF(*_retval = filter);
784 LOG_LIB((
"sbRemoteLibraryBase::GetYears()"));
785 NS_ENSURE_ARG_POINTER(_retval);
788 nsCOMPtr<sbIMediaListView> view;
789 rv =
mRemMediaList->CreateView( nsnull, getter_AddRefs(view) );
790 NS_ENSURE_SUCCESS( rv, rv );
792 nsCOMPtr<sbIFilterableMediaListView> filterView =
793 do_QueryInterface( view, &rv );
794 NS_ENSURE_SUCCESS( rv, rv );
796 nsRefPtr<sbScriptableFilter> filter =
800 NS_ENSURE_TRUE( filter, NS_ERROR_OUT_OF_MEMORY );
802 NS_ADDREF(*_retval = filter);
807 sbRemoteLibraryBase::GetItems(
nsISupports** _retval )
809 LOG_LIB((
"sbRemoteLibraryBase::Items()"));
810 NS_ENSURE_ARG_POINTER(_retval);
813 nsCOMPtr<sbIMediaListView> view;
814 rv =
mRemMediaList->CreateView( nsnull, getter_AddRefs(view) );
815 NS_ENSURE_SUCCESS( rv, rv );
817 nsCOMPtr<sbIFilterableMediaListView> filterView =
818 do_QueryInterface( view, &rv );
819 NS_ENSURE_SUCCESS( rv, rv );
821 nsRefPtr<sbScriptableFilterItems>
items =
823 NS_ENSURE_TRUE( items, NS_ERROR_OUT_OF_MEMORY );
831 sbRemoteLibraryBase::GetMostPlayedArtists(nsIVariant** _retval)
833 LOG_LIB((
"sbRemoteLibraryBase::GetMostPlayedArtists()"));
834 NS_ENSURE_ARG_POINTER(_retval);
837 nsCOMPtr<sbILibraryStatistics> libraryStatistics =
839 NS_ENSURE_SUCCESS( rv, rv );
843 rv = libraryStatistics->CollectDistinctValues(
847 getter_AddRefs(mostPlayedArtists));
848 NS_ENSURE_SUCCESS( rv, rv );
851 rv = mostPlayedArtists->GetLength(&count);
852 NS_ENSURE_SUCCESS(rv, rv);
854 LOG_LIB((
"sbRemoteLibraryBase::GetMostPlayedArtists() got %d artists", count));
857 nsCOMPtr<nsIWritableVariant> variant =
858 do_CreateInstance(NS_VARIANT_CONTRACTID, &rv);
859 NS_ENSURE_SUCCESS(rv, rv);
863 nsIVariant** arr = (nsIVariant**)NS_Alloc(
sizeof(nsIVariant*)*
count);
865 return NS_ERROR_OUT_OF_MEMORY;
869 for (PRUint32
i = 0;
i <
count;
i++) {
870 rv = mostPlayedArtists->QueryElementAt(
i, NS_GET_IID(nsIVariant),
872 NS_ENSURE_SUCCESS(rv, rv);
876 rv = variant->SetAsArray(nsIDataType::VTYPE_INTERFACE_IS,
877 &NS_GET_IID(nsIVariant), count, arr);
878 NS_ENSURE_SUCCESS(rv, rv);
881 rv = variant->SetAsEmptyArray();
882 NS_ENSURE_SUCCESS(rv, rv);
886 return CallQueryInterface(variant, _retval);
895 nsCOMPtr<sbILibraryConstraintBuilder> builder =
896 do_CreateInstance(
"@songbirdnest.com/Songbird/Library/ConstraintBuilder;1",
898 NS_ENSURE_SUCCESS( rv, rv );
899 return builder->Get(aConstraint);
908 already_AddRefed<sbIMediaItem>
914 already_AddRefed<sbIMediaList>
927 sbRemoteLibraryBase::OnEnumerationBegin(
sbIMediaList *aMediaList,
930 NS_ENSURE_ARG_POINTER(_retval);
933 "Someone forgot to clear mEnumerationArray!" );
935 "Someone forgot to reset mEnumerationResult!" );
942 sbRemoteLibraryBase::OnEnumeratedItem(
sbIMediaList *aMediaList,
946 NS_ENSURE_ARG_POINTER(aMediaItem);
947 NS_ENSURE_ARG_POINTER(_retval);
952 PRBool
const isSmartStoragePlaylist =
955 !propValue.IsEmpty();
957 PRBool
const isHiddenPlaylist =
960 propValue.EqualsLiteral(
"1");
978 sbRemoteLibraryBase::OnEnumerationEnd(
sbIMediaList *aMediaList,
979 nsresult aStatusCode )
994 NS_ENSURE_ARG_POINTER(aClassName);
995 *aClassName = ToNewCString( NS_LITERAL_CSTRING(
"SongbirdLibrary") );
996 NS_ENSURE_TRUE( aClassName, NS_ERROR_OUT_OF_MEMORY );
1003 NS_ENSURE_ARG_POINTER(aScriptableFlags);
1007 *aScriptableFlags = USE_JSSTUB_FOR_ADDPROPERTY |
1008 DONT_ENUM_STATIC_PROPS |
1009 DONT_ENUM_QUERY_INTERFACE |
1012 ALLOW_PROP_MODS_DURING_RESOLVE |
1013 DONT_REFLECT_INTERFACE_NAMES ;
1026 LOG_LIB((
"sbRemoteLibraryBase::NewResolve()"));
1028 if ( JSVAL_IS_STRING(
id) ) {
1029 nsDependentString jsid( (PRUnichar *)::JS_GetStringChars(JSVAL_TO_STRING(
id)),
1030 ::JS_GetStringLength(JSVAL_TO_STRING(
id)));
1031 TRACE_LIB((
" resolving %s", NS_LossyConvertUTF16toASCII(jsid).
get() ));
1037 return mRemMediaList->NewResolve( wrapper, cx, obj,
id, flags, objp, _retval );
1048 TRACE_LIB((
"sbRemoteLibraryBase::GetProperty()"));
1049 NS_ENSURE_ARG_POINTER(_retval);
1050 NS_ENSURE_ARG_POINTER(vp);
1054 if ( !JSVAL_IS_STRING(
id) ) {
1059 nsDependentString jsid( (PRUnichar *)::JS_GetStringChars(JSVAL_TO_STRING(
id)),
1060 ::JS_GetStringLength(JSVAL_TO_STRING(
id)));
1062 TRACE_LIB((
" Getting property %s", NS_LossyConvertUTF16toASCII(jsid).
get() ));
1064 nsCOMPtr<nsISupports> supports;
1067 nsCOMPtr<nsIStringEnumerator> stringEnum;
1068 if ( jsid.EqualsLiteral(
"getArtists") ) {
1069 rv = GetArtists( getter_AddRefs(stringEnum) );
1070 NS_ENSURE_SUCCESS( rv, rv );
1071 }
else if ( jsid.EqualsLiteral(
"getAlbums") ) {
1072 rv = GetAlbums( getter_AddRefs(stringEnum) );
1073 NS_ENSURE_SUCCESS( rv, rv );
1074 }
else if ( jsid.EqualsLiteral(
"getGenres") ) {
1075 rv = GetGenres( getter_AddRefs(stringEnum) );
1076 NS_ENSURE_SUCCESS( rv, rv );
1077 }
else if ( jsid.EqualsLiteral(
"getYears") ) {
1078 rv = GetYears( getter_AddRefs(stringEnum) );
1079 NS_ENSURE_SUCCESS( rv, rv );
1084 nsRefPtr<sbScriptableLibraryFunction> func =
1086 NS_ENSURE_TRUE( func, NS_ERROR_OUT_OF_MEMORY );
1092 if ( jsid.EqualsLiteral(
"getPlaylists") ) {
1093 nsCOMPtr<nsISimpleEnumerator> simpleEnum;
1094 rv = GetPlaylists( getter_AddRefs(simpleEnum) );
1095 NS_ENSURE_SUCCESS( rv, rv );
1097 nsRefPtr<sbScriptableLibraryFunction> func =
1099 NS_ENSURE_TRUE( simpleEnum, NS_ERROR_OUT_OF_MEMORY );
1110 jsid.BeginReading(),
1112 PRBool canCallMethod = NS_SUCCEEDED(rv);
1113 if (canCallMethod) {
1114 canCallMethod = !strcmp( access,
"AllAccess" );
1118 if ( !canCallMethod ) {
1119 JSAutoRequest ar(cx);
1122 nsCOMPtr<nsIStringBundleService> bundleService =
1123 do_GetService( NS_STRINGBUNDLE_CONTRACTID, &rv );
1124 NS_ENSURE_SUCCESS( rv, rv );
1125 nsCOMPtr<nsIStringBundle>
bundle;
1126 rv = bundleService->CreateBundle(
"chrome://global/locale/security/caps.properties",
1127 getter_AddRefs(bundle) );
1128 NS_ENSURE_SUCCESS( rv, rv );
1132 NS_ENSURE_SUCCESS( rv, rv );
1134 NS_ConvertASCIItoUTF16( nsDependentCString(classNameC) );
1135 NS_Free(classNameC);
1137 nsString errorMessage;
1138 const PRUnichar *formatStrings[] = {
1142 rv = bundle->FormatStringFromName( NS_LITERAL_STRING(
"CallMethodDenied").
get(),
1144 sizeof(formatStrings) /
sizeof(formatStrings[0]),
1145 getter_Copies(errorMessage) );
1146 NS_ENSURE_SUCCESS( rv, rv );
1148 JSString *jsstr = JS_NewUCStringCopyN( cx,
1149 reinterpret_cast<const jschar*>( errorMessage.get() ),
1150 errorMessage.Length() );
1152 JS_SetPendingException( cx, STRING_TO_JSVAL(jsstr) );
1154 *_retval = JS_FALSE;
1159 nsCOMPtr<nsIXPConnect> xpc;
1160 rv = wrapper->GetXPConnect( getter_AddRefs(xpc) );
1161 NS_ENSURE_SUCCESS( rv, rv );
1163 nsCOMPtr<nsIXPConnectJSObjectHolder> objHolder;
1164 rv = xpc->WrapNative( cx,
1168 getter_AddRefs(objHolder) );
1169 NS_ENSURE_SUCCESS( rv, rv );
1171 JSObject* obj = nsnull;
1172 rv = objHolder->GetJSObject( &obj );
1173 NS_ENSURE_SUCCESS( rv, rv );
1175 *vp = OBJECT_TO_JSVAL(obj);
1177 return NS_SUCCESS_I_DID_SOMETHING;
1196 nsAString &aLibraryGUID )
1200 if (!gRemoteLibraryLog) {
1201 gRemoteLibraryLog = PR_NewLogModule(
"sbRemoteLibrary");
1203 LOG_LIB((
"sbRemoteLibraryBase::GetLibraryGUID(%s)",
1204 NS_LossyConvertUTF16toASCII(aLibraryID).
get() ));
1207 nsCAutoString prefKey;
1210 if ( aLibraryID.EqualsLiteral(
"main") ) {
1211 prefKey.AssignLiteral(
"songbird.library.main");
1212 }
else if ( aLibraryID.EqualsLiteral(
"web") ) {
1213 prefKey.AssignLiteral(
"songbird.library.web");
1217 if ( prefKey.IsEmpty() ) {
1218 LOG_LIB((
"sbRemoteLibraryBase::GetLibraryGUID() -- not a default library"));
1223 return NS_ERROR_FAILURE;
1228 nsCOMPtr<nsIPrefBranch> prefService =
1230 NS_ENSURE_SUCCESS(rv, rv);
1232 nsCOMPtr<nsISupportsString> supportsString;
1233 rv = prefService->GetComplexValue( prefKey.get(),
1235 getter_AddRefs(supportsString) );
1237 if (NS_SUCCEEDED(rv)) {
1239 rv = supportsString->GetData(aLibraryGUID);
1240 NS_ENSURE_SUCCESS(rv, rv);
1246 already_AddRefed<sbIRemoteMediaList>
1249 NS_ASSERTION(!aSiteID.IsEmpty(),
"Don't give me an empty ID!");
1252 nsCOMPtr<sbIMutablePropertyArray> mutableArray =
1254 NS_ENSURE_SUCCESS( rv, nsnull );
1258 NS_ENSURE_SUCCESS( rv, nsnull );
1261 NS_LITERAL_STRING(
"1") );
1262 NS_ENSURE_SUCCESS( rv, nsnull );
1264 nsCOMArray<sbIMediaItem>
items;
1265 nsRefPtr<sbRemoteLibraryEnumCallback>
listener =
1267 NS_ENSURE_TRUE( listener, nsnull );
1269 nsCOMPtr<sbIMediaList> libList = do_QueryInterface(
mLibrary, &rv );
1270 NS_ENSURE_SUCCESS( rv, nsnull );
1272 rv = libList->EnumerateItemsByProperties( mutableArray,
1275 NS_ENSURE_SUCCESS( rv, nsnull );
1277 if (items.Count() > 0) {
1280 nsCOMPtr<sbIMediaList> list = do_QueryInterface( foundItem, &rv );
1281 NS_ASSERTION( NS_SUCCEEDED(rv),
"Failed to QI to sbIMediaList!" );
1283 nsCOMPtr<sbIRemoteMediaList> retval;
1285 NS_ENSURE_SUCCESS( rv, nsnull );
1287 return retval.forget();
1295 already_AddRefed<sbIMediaItem>
1298 nsCOMPtr<nsIURI> siteScopeURI =
mRemotePlayer->GetSiteScopeURI();
1299 NS_ENSURE_TRUE( siteScopeURI, nsnull );
1302 nsresult rv = siteScopeURI->GetHost(siteHost);
1303 NS_ENSURE_SUCCESS( rv, nsnull );
1305 PRUint32 itemCount = (PRUint32)aMediaItems.Count();
1306 NS_ASSERTION(itemCount > 0,
"Empty items list!");
1309 nsTArray<sbRemoteLibraryScopeURLSet> scopeURLSet(itemCount);
1311 for (PRUint32 itemIndex = 0; itemIndex < itemCount; itemIndex++) {
1312 const nsCOMPtr<sbIMediaItem>& item = aMediaItems.ObjectAt(itemIndex);
1317 NS_ENSURE_SUCCESS( rv, nsnull );
1319 NS_ASSERTION( !scopeURL.IsEmpty(),
"Empty scope URL" );
1321 nsCOMPtr<nsIURI> scopeURI;
1322 rv = NS_NewURI( getter_AddRefs(scopeURI), scopeURL );
1323 NS_ENSURE_SUCCESS( rv, nsnull );
1326 rv = scopeURI->GetHost(host);
1327 NS_ENSURE_SUCCESS( rv, nsnull );
1330 if (NS_FAILED(rv)) {
1335 rv = scopeURI->GetPath(path);
1336 NS_ENSURE_SUCCESS( rv, nsnull );
1340 NS_ENSURE_TRUE( newSet, nsnull );
1346 itemCount = scopeURLSet.Length();
1347 NS_ENSURE_TRUE(itemCount, nsnull);
1349 for (PRInt64 setIndex = itemCount - 1; setIndex >= 0; setIndex--) {
1354 if (NS_SUCCEEDED(rv)) {
bool operator==(sbFraction const &aLeft, sbFraction const &aRight)
static nsresult SB_WrapMediaList(sbRemotePlayer *aRemotePlayer, sbIMediaList *aMediaList, sbIMediaList **aRemoteMediaList)
#define SB_PROPERTY_MEDIALISTNAME
#define SB_PROPERTY_PLAYCOUNT
virtual already_AddRefed< sbIMediaItem > GetMediaItem()
static nsresult CheckDomain(nsACString &aDomain, nsIURI *aSiteURI)
already_AddRefed< sbIRemoteMediaList > GetMediaListBySiteID(const nsAString &aSiteID)
#define SB_PROPERTY_RAPISITEID
virtual ~sbRemoteLibraryBase()
sbOSDControlService prototype className
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
NS_IMETHODIMP Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
const NS_PREFSERVICE_CONTRACTID
sbDeviceFirmwareAutoCheckForUpdate prototype flags
readonly attribute sbIRemotePlayer remotePlayer
This interface is a composition of many of our other interfaces with the goal of exposing a more web-...
#define SB_PROPERTY_HIDDEN
PRBool mIgnoreHiddenPlaylists
#define SB_PROPERTY_RAPISCOPEURL
NS_IMPL_ISUPPORTS11(sbRemoteLibraryBase, nsISecurityCheckedComponent, nsIXPCScriptable, sbISecurityAggregator, sbIRemoteMediaList, sbIMediaList, sbIWrappedMediaList, sbIWrappedMediaItem, sbIMediaItem, sbILibraryResource, sbIRemoteLibrary, sbIScriptableFilterResult) sbRemoteLibraryBase
const nsCOMPtr< sbIMediaItem > item
static PRBool IsSiteLibrary(sbILibrary *aLibrary, sbIRemotePlayer *aRemotePlayer)
nsISecurityCheckedComponent
NS_IMETHOD GetProperty(const nsAString &aName, nsAString &_retval)
readonly attribute AString guid
The guid of this resource.
static nsresult GetLibraryGUID(const nsAString &aLibraryID, nsAString &aLibraryGUID)
NS_IMETHOD SetProperty(const nsAString &aID, const nsAString &aValue)
static nsresult CheckPath(nsACString &aPath, nsIURI *aSiteURI)
readonly attribute nsIVariant mostPlayedArtists
NS_IMETHOD GetScriptableFlags(PRUint32 *aScriptableFlags)
#define SB_PROPERTY_OUTERGUID
NS_DECL_ISUPPORTS sbPlaylistReaderObserver(sbRemotePlayer *aRemotePlayer, sbICreateMediaListCallback *aCallback, PRBool aShouldScan)
static nsresult SB_IsFromLibName(sbIMediaItem *aMediaItem, const nsAString &aLibName, PRBool *aIsFromLib)
NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, jsval id, PRUint32 flags, JSObject **objp, PRBool *_retval)
bool operator<(sbFraction const &aLeft, sbFraction const &aRight)
already_AddRefed< sbIMediaItem > FindMediaItemWithMatchingScope(const nsCOMArray< sbIMediaItem > &aMediaItems)
#define SB_PROPERTY_GENRE
A marker interface for objects that aggregate the security mixin.
nsRefPtr< sbRemoteMediaListBase > mRemMediaList
General interface to data resources.
nsCOMPtr< nsISecurityCheckedComponent > mSecurityMixin
An interface to control a media library from remote web pages.
sbRemoteLibraryScopeURLSet(const nsACString &path, sbIMediaItem *item)
The result of a filtering expression in a library.
Media library abstraction.
#define SB_PROPERTY_ARTISTNAME
nsCOMPtr< sbILibrary > mLibrary
NS_IMETHOD GetClassName(char **aClassName)
#define SB_PROPERTY_ALBUMNAME
virtual already_AddRefed< sbIMediaList > GetMediaList()
static nsresult SB_WrapMediaItem(sbRemotePlayer *aRemotePlayer, sbIMediaItem *aMediaItem, sbIMediaItem **aRemoteMediaItem)
nsCOMArray< sbIMediaItem > mEnumerationArray
nsRefPtr< sbRemotePlayer > mRemotePlayer
#define SB_PROPERTY_ISLIST
NS_IMETHODIMP OnEnumeratedItem(sbIMediaList *, sbIMediaItem *aItem, PRUint16 *_retval)
virtual nsresult InitInternalMediaList()=0
const nsCString scopePath
NS_IMETHODIMP OnEnumerationBegin(sbIMediaList *, PRUint16 *_retval)
_getSelectedPageStyle s i
Array filter(tab.attributes, function(aAttr){return(_this.xulAttributes.indexOf(aAttr.name) >-1);}).forEach(tab.removeAttribute
NS_IMETHODIMP OnEnumerationEnd(sbIMediaList *, nsresult)
readonly attribute nsISupports items
nsresult mEnumerationResult
_updateTextAndScrollDataForFrame aData
NS_DECL_ISUPPORTS sbRemoteLibraryEnumCallback(nsCOMArray< sbIMediaItem > &aArray)
const PRUint32 COLLECT_SUM