28 #include <nsIAppStartupNotifier.h>
29 #include <nsIClassInfoImpl.h>
30 #include <nsIDOMDocument.h>
31 #include <nsIDOMElement.h>
32 #include <nsIDOMEventTarget.h>
33 #include <nsIDOMWindow.h>
34 #include <nsIDOMXULElement.h>
35 #include <nsIMutableArray.h>
36 #include <nsIObserverService.h>
37 #include <nsIProgrammingLanguage.h>
38 #include <nsISupportsPrimitives.h>
39 #include <nsIThread.h>
41 #include <nsArrayUtils.h>
42 #include <nsAutoLock.h>
43 #include <nsAutoPtr.h>
44 #include <nsComponentManagerUtils.h>
46 #include <nsServiceManagerUtils.h>
47 #include <nsThreadUtils.h>
51 #include <sbIMediacore.h>
52 #include <sbIMediacoreBalanceControl.h>
53 #include <sbIMediacoreCapabilities.h>
54 #include <sbIMediacoreFactory.h>
55 #include <sbIMediacorePlaybackControl.h>
56 #include <sbIMediacoreSequencer.h>
57 #include <sbIMediacoreSimpleEqualizer.h>
58 #include <sbIMediacoreVolumeControl.h>
59 #include <sbIMediacoreVotingParticipant.h>
61 #include <sbIPrompter.h>
62 #include <sbIWindowWatcher.h>
73 #define NS_PROFILE_STARTUP_OBSERVER_ID "profile-after-change"
74 #define NS_QUIT_APPLICATION_GRANTED_OBSERVER_ID "quit-application-granted"
75 #define NS_PROFILE_SHUTDOWN_OBSERVER_ID "profile-before-change"
78 #define SB_CORE_HASHTABLE_SIZE (4)
79 #define SB_FACTORY_HASHTABLE_SIZE (4)
82 #define SB_CORE_BASE_NAME "mediacore"
83 #define SB_CORE_NAME_SUFFIX "@core.songbirdnest.com"
85 #define SB_EQUALIZER_DEFAULT_BAND_COUNT \
86 sbBaseMediacoreMultibandEqualizer::EQUALIZER_BAND_COUNT_DEFAULT
88 #define SB_EQUALIZER_BANDS \
89 sbBaseMediacoreMultibandEqualizer::EQUALIZER_BANDS_10
91 #define SB_EQUALIZER_DEFAULT_BAND_GAIN (0.0)
94 #define SB_PVW_CHROME_URL "chrome://songbird/content/xul/videoWindow.xul"
96 #define SB_PVW_NAME "VideoWindow"
98 #define SB_PVW_ELEMENT_ID "video-box"
105 static PRLogModuleInfo* gMediacoreManager = nsnull;
106 #define TRACE(args) PR_LOG(gMediacoreManager, PR_LOG_DEBUG, args)
107 #define LOG(args) PR_LOG(gMediacoreManager, PR_LOG_WARN, args)
129 sbIMediacoreEventTarget,
130 sbIMediacoreFactoryRegistrar,
132 nsISupportsWeakReference)
141 sbMediacoreManager::sbMediacoreManager()
144 , mFullscreen(PR_FALSE)
145 , mVideoWindowMonitor(nsnull)
146 , mLastVideoWindow(0)
150 NS_WARN_IF_FALSE(mBaseEventTarget,
"mBaseEventTarget is null, may be out of memory");
153 if (!gMediacoreManager)
154 gMediacoreManager = PR_NewLogModule(
"sbMediacoreManager");
157 TRACE((
"sbMediacoreManager[0x%x] - Created",
this));
162 TRACE((
"sbMediacoreManager[0x%x] - Destroyed",
this));
165 nsAutoMonitor::DestroyMonitor(
mMonitor);
176 nsIMutableArray *
array = (nsIMutableArray*)aArray;
178 nsCOMPtr<nsISupports> supports = do_QueryInterface(aData, &rv);
179 NS_ENSURE_SUCCESS(rv, PL_DHASH_STOP);
181 rv = array->AppendElement(aData,
false);
182 NS_ENSURE_SUCCESS(rv, PL_DHASH_STOP);
184 return PL_DHASH_NEXT;
188 PLDHashOperator sbMediacoreManager::EnumerateIntoArrayStringKey(
189 const nsAString& aKey,
193 TRACE((
"sbMediacoreManager[0x%x] - EnumerateIntoArray (String)"));
198 PLDHashOperator sbMediacoreManager::EnumerateIntoArrayISupportsKey(
203 TRACE((
"sbMediacoreManager[0x%x] - EnumerateIntoArray (nsISupports)"));
208 PLDHashOperator sbMediacoreManager::EnumerateIntoArrayUint32Key(
209 const PRUint32 &aKey,
213 TRACE((
"sbMediacoreManager[0x%x] - EnumerateIntoArray (PRUint32)"));
220 TRACE((
"sbMediacoreManager[0x%x] - Init",
this));
222 mMonitor = nsAutoMonitor::NewMonitor(
"sbMediacoreManager::mMonitor");
223 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_OUT_OF_MEMORY);
226 nsAutoMonitor::NewMonitor(
"sbMediacoreManager::mVideoWindowMonitor");
230 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
233 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
236 nsresult rv = NS_ERROR_UNEXPECTED;
238 nsCOMPtr<nsISimpleEnumerator> categoryEnum;
240 nsCOMPtr<nsICategoryManager>
cm =
241 do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
242 NS_ENSURE_SUCCESS(rv, rv);
245 getter_AddRefs(categoryEnum));
246 NS_ENSURE_SUCCESS(rv, rv);
249 while (NS_SUCCEEDED(categoryEnum->HasMoreElements(&hasMore)) &&
252 nsCOMPtr<nsISupports> ptr;
253 if (NS_SUCCEEDED(categoryEnum->GetNext(getter_AddRefs(ptr))) &&
256 nsCOMPtr<nsISupportsCString> stringValue(do_QueryInterface(ptr));
258 nsCString factoryName;
259 nsresult rv = NS_ERROR_UNEXPECTED;
262 NS_SUCCEEDED(stringValue->GetData(factoryName))) {
266 factoryName.get(), &contractId);
267 NS_ENSURE_SUCCESS(rv, rv);
269 nsCOMPtr<sbIMediacoreFactory> factory =
270 do_CreateInstance(contractId , &rv);
272 NS_ENSURE_SUCCESS(rv, rv);
274 rv = RegisterFactory(factory);
275 NS_ENSURE_SUCCESS(rv, rv);
280 nsRefPtr<sbMediacoreSequencer>
sequencer;
282 NS_ENSURE_TRUE(sequencer, NS_ERROR_OUT_OF_MEMORY);
284 rv = sequencer->Init();
285 NS_ENSURE_SUCCESS(rv, rv);
290 NS_ENSURE_SUCCESS(rv, rv);
293 NS_ENSURE_SUCCESS(rv, rv);
296 NS_ENSURE_SUCCESS(rv, rv);
304 TRACE((
"sbMediacoreManager[0x%x] - PreShutdown",
this));
305 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
310 nsCOMPtr<sbIMediacoreStatus>
status;
312 nsresult rv = GetStatus(getter_AddRefs(status));
313 NS_ENSURE_SUCCESS(rv, rv);
316 rv = status->GetState(&state);
317 NS_ENSURE_SUCCESS(rv, rv);
321 rv = GetPlaybackControl(getter_AddRefs(playbackControl));
322 NS_ENSURE_SUCCESS(rv, rv);
324 rv = playbackControl->Stop();
325 NS_ENSURE_SUCCESS(rv, rv);
335 TRACE((
"sbMediacoreManager[0x%x] - Shutdown",
this));
336 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
343 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Failed to stop sequencer.");
349 NS_ENSURE_SUCCESS(rv, rv);
354 NS_ENSURE_SUCCESS(rv, rv);
359 NS_ENSURE_SUCCESS(rv, rv);
364 NS_ENSURE_SUCCESS(rv, rv);
367 nsCOMPtr<nsIMutableArray> mutableArray =
368 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
369 NS_ENSURE_SUCCESS(rv, rv);
377 rv = mutableArray->GetLength(&length);
378 NS_ENSURE_SUCCESS(rv, rv);
380 for(PRUint32 current = 0; current < length; ++current) {
381 nsCOMPtr<sbIDataRemote>
dataRemote = do_QueryElementAt(mutableArray, current, &rv);
382 NS_ENSURE_SUCCESS(rv, rv);
384 rv = dataRemote->Unbind();
385 NS_ENSURE_SUCCESS(rv, rv);
388 rv = mutableArray->Clear();
389 NS_ENSURE_SUCCESS(rv, rv);
391 mCores.EnumerateRead(sbMediacoreManager::EnumerateIntoArrayStringKey,
394 rv = mutableArray->GetLength(&length);
395 NS_ENSURE_SUCCESS(rv, rv);
397 for(PRUint32 current = 0; current < length; ++current) {
398 nsCOMPtr<sbIMediacore> core = do_QueryElementAt(mutableArray, current, &rv);
399 NS_ENSURE_SUCCESS(rv, rv);
401 rv = core->Shutdown();
402 NS_ASSERTION(NS_SUCCEEDED(rv),
403 "Failed to Shutdown a Mediacore. This may cause problems during final shutdown.");
417 TRACE((
"sbMediacoreManager[0x%x] - GenerateInstanceName",
this));
418 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
437 TRACE((
"sbMediacoreManager[0x%x] - VoteWithURIOrChannel",
this));
438 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
439 NS_ENSURE_TRUE(aURI || aChannel, NS_ERROR_INVALID_ARG);
441 nsRefPtr<sbMediacoreVotingChain> votingChain;
443 NS_ENSURE_TRUE(votingChain, NS_ERROR_OUT_OF_MEMORY);
445 nsresult rv = votingChain->Init();
446 NS_ENSURE_SUCCESS(rv, rv);
452 rv = GetInstances(getter_AddRefs(instances));
453 NS_ENSURE_SUCCESS(rv, rv);
456 rv = instances->GetLength(&length);
457 NS_ENSURE_SUCCESS(rv, rv);
460 for(PRUint32 current = 0; current < length; ++current) {
461 nsCOMPtr<sbIMediacoreVotingParticipant> votingParticipant =
462 do_QueryElementAt(instances, current, &rv);
463 NS_ENSURE_SUCCESS(rv, rv);
468 rv = votingParticipant->VoteWithURI(aURI, &result);
469 NS_ENSURE_SUCCESS(rv, rv);
472 rv = votingParticipant->VoteWithChannel(aChannel, &result);
473 NS_ENSURE_SUCCESS(rv, rv);
477 nsCOMPtr<sbIMediacore> mediacore =
478 do_QueryInterface(votingParticipant, &rv);
479 NS_ENSURE_SUCCESS(rv, rv);
481 rv = votingChain->AddVoteResult(result, mediacore);
482 NS_ENSURE_SUCCESS(rv, rv);
491 NS_ADDREF(*_retval = votingChain);
498 rv = GetFactories(getter_AddRefs(factories));
499 NS_ENSURE_SUCCESS(rv, rv);
502 rv = factories->GetLength(&length);
503 NS_ENSURE_SUCCESS(rv, rv);
505 for(PRUint32 current = 0; current < length; ++current) {
506 nsCOMPtr<sbIMediacoreFactory> factory =
507 do_QueryElementAt(factories, current, &rv);
508 NS_ENSURE_SUCCESS(rv, rv);
510 nsString mediacoreInstanceName;
513 nsCOMPtr<sbIMediacore> mediacore;
514 rv = CreateMediacoreWithFactory(factory,
515 mediacoreInstanceName,
516 getter_AddRefs(mediacore));
518 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Failed to create mediacore.");
527 nsCOMPtr<sbIMediacoreVotingParticipant> votingParticipant =
528 do_QueryInterface(mediacore, &rv);
529 NS_ENSURE_SUCCESS(rv, rv);
534 rv = votingParticipant->VoteWithURI(aURI, &result);
535 NS_ENSURE_SUCCESS(rv, rv);
538 rv = votingParticipant->VoteWithChannel(aChannel, &result);
539 NS_ENSURE_SUCCESS(rv, rv);
543 rv = votingChain->AddVoteResult(result, mediacore);
544 NS_ENSURE_SUCCESS(rv, rv);
548 NS_ADDREF(*_retval = votingChain);
560 nsresult rv = NS_ERROR_UNEXPECTED;
563 nullString.SetIsVoid(PR_TRUE);
566 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
569 do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1", &rv);
570 NS_ENSURE_SUCCESS(rv, rv);
575 NS_ENSURE_SUCCESS(rv, rv);
577 nsString eqEnabledStr;
579 NS_ENSURE_SUCCESS(rv, rv);
582 if(!eqEnabledStr.IsEmpty()) {
584 NS_ENSURE_SUCCESS(rv, rv);
590 NS_ENSURE_SUCCESS(rv, rv);
592 LOG((
"[sbMediacoreManager] - Initializing eq enabled from data remote, enabled: %s",
593 eqEnabled ?
"true" :
"false"));
597 nsCOMPtr<sbIMediacoreEqualizerBand> band;
598 rv = GetBand(
i, getter_AddRefs(band));
599 NS_ENSURE_SUCCESS(rv, rv);
608 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
610 nsresult rv = NS_ERROR_UNEXPECTED;
614 nsCOMPtr<sbIMediacoreMultibandEqualizer>
equalizer =
616 NS_ENSURE_SUCCESS(rv, rv);
620 rv = equalizer->SetEqEnabled(aEqEnabled);
621 NS_ENSURE_SUCCESS(rv, rv);
625 nsCOMPtr<nsISimpleEnumerator>
bands;
626 rv = GetBands(getter_AddRefs(bands));
627 NS_ENSURE_SUCCESS(rv, rv);
629 rv = equalizer->SetBands(bands);
630 NS_ENSURE_SUCCESS(rv, rv);
638 NS_ENSURE_SUCCESS(rv, rv);
646 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
648 nsresult rv = NS_ERROR_UNEXPECTED;
652 nsCOMPtr<sbIMediacoreMultibandEqualizer>
equalizer =
654 NS_ENSURE_SUCCESS(rv, rv);
658 rv = equalizer->GetBandCount(aBandCount);
659 NS_ENSURE_SUCCESS(rv, rv);
673 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
675 nsresult rv = NS_ERROR_UNEXPECTED;
679 nsCOMPtr<sbIMediacoreMultibandEqualizer>
equalizer =
681 NS_ENSURE_SUCCESS(rv, rv);
685 nsCOMPtr<sbIMediacoreEqualizerBand> band;
686 rv = equalizer->GetBand(aBandIndex, getter_AddRefs(band));
687 NS_ENSURE_SUCCESS(rv, rv);
689 PRUint32 bandIndex = 0, bandFrequency = 0;
690 double bandGain = 0.0;
692 rv = band->GetValues(&bandIndex, &bandFrequency, &bandGain);
693 NS_ENSURE_SUCCESS(rv, rv);
695 rv = aBand->Init(bandIndex, bandFrequency, bandGain);
696 NS_ENSURE_SUCCESS(rv, rv);
699 nsCOMPtr<sbIDataRemote> bandRemote;
701 NS_ENSURE_SUCCESS(rv, rv);
703 nsString bandRemoteValue;
704 rv = bandRemote->GetStringValue(bandRemoteValue);
705 NS_ENSURE_SUCCESS(rv, rv);
707 NS_ConvertUTF16toUTF8 gainStr(bandRemoteValue);
710 if((PR_sscanf(gainStr.BeginReading(),
"%lg", &gain) != 1) ||
711 (gain > 1.0 || gain < -1.0)) {
715 rv = bandRemote->SetStringValue(NS_ConvertUTF8toUTF16(gainStr));
716 NS_ENSURE_SUCCESS(rv, rv);
720 NS_ENSURE_SUCCESS(rv, rv);
729 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
731 nsresult rv = NS_ERROR_UNEXPECTED;
735 nsCOMPtr<sbIMediacoreMultibandEqualizer>
equalizer =
737 NS_ENSURE_SUCCESS(rv, rv);
741 rv = equalizer->SetBand(aBand);
742 NS_ENSURE_SUCCESS(rv, rv);
749 NS_ENSURE_SUCCESS(rv, rv);
759 NS_ENSURE_ARG_POINTER(aRemote);
762 nsresult rv = NS_ERROR_UNEXPECTED;
763 nsCOMPtr<sbIDataRemote> bandRemote;
768 NS_ENSURE_SUCCESS(rv, rv);
771 bandRemote.forget(aRemote);
779 NS_ENSURE_ARG_POINTER(aBand);
782 PRUint32 bandIndex = 0, bandFrequency = 0;
783 double bandGain = 0.0;
785 nsresult rv = aBand->GetValues(&bandIndex, &bandFrequency, &bandGain);
786 NS_ENSURE_SUCCESS(rv, rv);
788 nsCOMPtr<sbIDataRemote> bandRemote;
793 NS_ENSURE_SUCCESS(rv, rv);
796 nsCString bandGainStr;
799 NS_ConvertUTF8toUTF16 gainStr(bandGainStr);
800 rv = bandRemote->SetStringValue(gainStr);
801 NS_ENSURE_SUCCESS(rv, rv);
811 NS_ENSURE_ARG_POINTER(aRemote);
814 nsresult rv = NS_ERROR_UNEXPECTED;
817 nullString.SetIsVoid(PR_TRUE);
819 nsCOMPtr<sbIDataRemote> bandRemote =
820 do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1", &rv);
821 NS_ENSURE_SUCCESS(rv, rv);
824 bandRemoteName.AppendInt(aBandIndex);
826 rv = bandRemote->Init(bandRemoteName, nullString);
827 NS_ENSURE_SUCCESS(rv, rv);
830 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
832 bandRemote.forget(aRemote);
840 nsresult rv = NS_ERROR_UNEXPECTED;
843 nullString.SetIsVoid(PR_TRUE);
846 do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1", &rv);
847 NS_ENSURE_SUCCESS(rv, rv);
851 NS_ENSURE_SUCCESS(rv, rv);
854 NS_ENSURE_SUCCESS(rv, rv);
875 nullString.SetIsVoid(PR_TRUE);
877 nsresult rv = NS_ERROR_UNEXPECTED;
879 do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1", &rv);
880 NS_ENSURE_SUCCESS(rv, rv);
885 NS_ENSURE_SUCCESS(rv, rv);
889 NS_ENSURE_SUCCESS(rv, rv);
891 NS_ConvertUTF16toUTF8 volStr(volumeStr);
894 if((PR_sscanf(volStr.BeginReading(),
"%lg", &
volume) != 1) ||
895 (volume > 1 || volume < 0)) {
901 LOG((
"[sbMediacoreManager] - Initializing volume from data remote, volume: %s",
902 volStr.BeginReading()));
905 NS_ENSURE_SUCCESS(rv, rv);
908 do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1", &rv);
909 NS_ENSURE_SUCCESS(rv, rv);
914 NS_ENSURE_SUCCESS(rv, rv);
918 NS_ENSURE_SUCCESS(rv, rv);
920 PRBool
mute = PR_FALSE;
921 if(!muteStr.IsEmpty()) {
923 NS_ENSURE_SUCCESS(rv, rv);
929 NS_ENSURE_SUCCESS(rv, rv);
931 LOG((
"[sbMediacoreManager] - Initializing mute from data remote, mute: %d",
940 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
942 nsresult rv = NS_ERROR_UNEXPECTED;
948 NS_ENSURE_SUCCESS(rv, rv);
952 rv = volumeControl->SetMute(aMute);
953 NS_ENSURE_SUCCESS(rv, rv);
960 NS_ENSURE_SUCCESS(rv, rv);
968 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
970 nsresult rv = NS_ERROR_UNEXPECTED;
978 NS_ENSURE_SUCCESS(rv, rv);
982 rv = volumeControl->SetVolume(aVolume);
983 NS_ENSURE_SUCCESS(rv, rv);
990 NS_ENSURE_SUCCESS(rv, rv);
998 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1004 NS_ConvertUTF8toUTF16 volumeStr(volume);
1006 NS_ENSURE_SUCCESS(rv, rv);
1016 sbMediacoreManager::GetPrimaryCore(
sbIMediacore * *aPrimaryCore)
1018 TRACE((
"sbMediacoreManager[0x%x] - GetPrimaryCore",
this));
1019 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1020 NS_ENSURE_ARG_POINTER(aPrimaryCore);
1028 sbMediacoreManager::GetBalanceControl(
1031 TRACE((
"sbMediacoreManager[0x%x] - GetBalanceControl",
this));
1032 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1033 NS_ENSURE_ARG_POINTER(aBalanceControl);
1035 *aBalanceControl = nsnull;
1043 nsresult rv = NS_ERROR_UNEXPECTED;
1046 NS_ENSURE_SUCCESS(rv, rv);
1048 balanceControl.forget(aBalanceControl);
1054 sbMediacoreManager::GetVolumeControl(
1057 TRACE((
"sbMediacoreManager[0x%x] - GetVolumeControl",
this));
1058 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1059 NS_ENSURE_ARG_POINTER(aVolumeControl);
1063 nsresult rv = NS_ERROR_UNEXPECTED;
1066 NS_ENSURE_SUCCESS(rv, rv);
1068 volumeControl.forget(aVolumeControl);
1074 sbMediacoreManager::GetEqualizer(
1077 TRACE((
"sbMediacoreManager[0x%x] - GetEqualizer",
this));
1078 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1079 NS_ENSURE_ARG_POINTER(aEqualizer);
1081 *aEqualizer = nsnull;
1085 nsresult rv = NS_ERROR_UNEXPECTED;
1086 nsCOMPtr<sbIMediacoreMultibandEqualizer>
equalizer =
1088 NS_ENSURE_SUCCESS(rv, rv);
1090 equalizer.forget(aEqualizer);
1096 sbMediacoreManager::GetPlaybackControl(
1099 TRACE((
"sbMediacoreManager[0x%x] - GetPlaybackControl",
this));
1100 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1101 NS_ENSURE_ARG_POINTER(aPlaybackControl);
1103 *aPlaybackControl = nsnull;
1111 nsresult rv = NS_ERROR_UNEXPECTED;
1114 NS_ENSURE_SUCCESS(rv, rv);
1116 playbackControl.forget(aPlaybackControl);
1122 sbMediacoreManager::GetCapabilities(
1125 TRACE((
"sbMediacoreManager[0x%x] - GetCapabilities",
this));
1126 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1127 NS_ENSURE_ARG_POINTER(aCapabilities);
1129 *aCapabilities = nsnull;
1137 nsresult rv = NS_ERROR_UNEXPECTED;
1138 nsCOMPtr<sbIMediacoreCapabilities> volumeControl =
1140 NS_ENSURE_SUCCESS(rv, rv);
1142 volumeControl.forget(aCapabilities);
1150 TRACE((
"sbMediacoreManager[0x%x] - GetStatus",
this));
1151 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1152 NS_ENSURE_ARG_POINTER(aStatus);
1154 nsresult rv = NS_ERROR_UNEXPECTED;
1156 nsCOMPtr<sbIMediacoreStatus>
status =
1158 NS_ENSURE_SUCCESS(rv, rv);
1160 status.forget(aStatus);
1168 TRACE((
"sbMediacoreManager[0x%x] - GetVideo",
this));
1169 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1170 NS_ENSURE_ARG_POINTER(aVideo);
1180 nsresult rv = NS_ERROR_UNEXPECTED;
1183 NS_ENSURE_SUCCESS(rv, rv);
1185 videoWindow.forget(aVideo);
1191 sbMediacoreManager::GetSequencer(
1194 TRACE((
"sbMediacoreManager[0x%x] - GetSequencer",
this));
1195 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1196 NS_ENSURE_ARG_POINTER(aSequencer);
1198 nsresult rv = NS_ERROR_UNEXPECTED;
1200 nsCOMPtr<sbIMediacoreSequencer>
sequencer =
1202 NS_ENSURE_SUCCESS(rv, rv);
1204 sequencer.forget(aSequencer);
1210 sbMediacoreManager::SetSequencer(
1213 TRACE((
"sbMediacoreManager[0x%x] - SetSequencer",
this));
1214 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1216 return NS_ERROR_NOT_IMPLEMENTED;
1220 sbMediacoreManager::GetPrimaryVideoWindow(PRBool aCreate,
1221 PRUint32 aWidthHint,
1222 PRUint32 aHeightHint,
1225 TRACE((
"sbMediacoreManager[0x%x] - GetVideoWindow",
this));
1227 NS_ENSURE_ARG_POINTER(aVideo);
1229 nsresult rv = NS_ERROR_UNEXPECTED;
1232 PRBool hintValid = PR_FALSE;
1233 if(aWidthHint > 0 && aHeightHint > 0) {
1234 hintValid = PR_TRUE;
1241 nsCOMPtr<sbIMediacoreVideoWindow> videoWindow =
1243 NS_ENSURE_SUCCESS(rv, rv);
1245 videoWindow.forget(aVideo);
1255 nsCOMPtr<sbIPrompter> prompter =
1257 NS_ENSURE_SUCCESS(rv, rv);
1259 rv = prompter->SetParentWindowType(NS_LITERAL_STRING(
"Songbird:Main"));
1260 NS_ENSURE_SUCCESS(rv, rv);
1262 rv = prompter->SetWaitForWindow(PR_TRUE);
1263 NS_ENSURE_SUCCESS(rv, rv);
1268 nsString windowName;
1272 nsCOMPtr<nsIDOMWindow> domWindow;
1273 rv = prompter->OpenWindow(nsnull,
1276 NS_LITERAL_STRING(
"chrome,centerscreen,resizable"),
1278 getter_AddRefs(domWindow));
1279 NS_ENSURE_SUCCESS(rv, rv);
1283 PRBool mainThread = NS_IsMainThread();
1284 nsCOMPtr<nsIThread>
target;
1286 rv = NS_GetMainThread(getter_AddRefs(target));
1287 NS_ENSURE_SUCCESS(rv, rv);
1295 nsCOMPtr<sbIWindowWatcher> windowWatcher =
1297 NS_ENSURE_SUCCESS(rv, rv);
1299 rv = windowWatcher->WaitForWindow(NS_LITERAL_STRING(
"Songbird:Core"));
1300 NS_ENSURE_SUCCESS(rv, rv);
1302 nsCOMPtr<nsIDOMWindow> grip;
1303 domWindow.swap(grip);
1308 NS_PROXY_SYNC | NS_PROXY_ALWAYS,
1309 getter_AddRefs(domWindow));
1310 NS_ENSURE_SUCCESS(rv, rv);
1312 nsCOMPtr<nsIDOMEventTarget> domTarget = do_QueryInterface(domWindow, &rv);
1313 NS_ENSURE_SUCCESS(rv, rv);
1315 nsCOMPtr<nsIDOMEventTarget> proxiedDomTarget;
1317 NS_GET_IID(nsIDOMEventTarget),
1319 NS_PROXY_SYNC | NS_PROXY_ALWAYS,
1320 getter_AddRefs(proxiedDomTarget));
1321 NS_ENSURE_SUCCESS(rv, rv);
1323 nsRefPtr<sbMediacoreVideoWindowListener> videoWindowListener;
1325 NS_ENSURE_TRUE(videoWindowListener, NS_ERROR_OUT_OF_MEMORY);
1327 rv = videoWindowListener->Init(
this, domTarget);
1328 NS_ENSURE_SUCCESS(rv, rv);
1330 rv = proxiedDomTarget->AddEventListener(NS_LITERAL_STRING(
"unload"),
1331 videoWindowListener,
1333 NS_ENSURE_SUCCESS(rv, rv);
1339 nsRefPtr<sbMediacoreVideoWindowListener> videoWindowListener;
1341 NS_ENSURE_TRUE(videoWindowListener, NS_ERROR_OUT_OF_MEMORY);
1343 nsCOMPtr<nsIDOMEventTarget> domTarget = do_QueryInterface(domWindow, &rv);
1344 NS_ENSURE_SUCCESS(rv, rv);
1346 rv = videoWindowListener->Init(
this, domTarget);
1347 NS_ENSURE_SUCCESS(rv, rv);
1349 rv = domTarget->AddEventListener(NS_LITERAL_STRING(
"resize"),
1350 videoWindowListener,
1352 NS_ENSURE_SUCCESS(rv, rv);
1354 PRBool processed = PR_FALSE;
1355 while(!videoWindowListener->IsWindowReady()) {
1356 rv = target->ProcessNextEvent(PR_FALSE, &processed);
1357 NS_ENSURE_SUCCESS(rv, rv);
1360 rv = domTarget->RemoveEventListener(NS_LITERAL_STRING(
"resize"),
1361 videoWindowListener,
1363 NS_ENSURE_SUCCESS(rv, rv);
1366 NS_ENSURE_TRUE(videoWindowListener->IsWindowReady(), NS_ERROR_FAILURE);
1368 rv = domTarget->AddEventListener(NS_LITERAL_STRING(
"unload"),
1369 videoWindowListener,
1371 NS_ENSURE_SUCCESS(rv, rv);
1374 nsCOMPtr<nsIDOMDocument> domDoc;
1376 rv = domWindow->GetDocument(getter_AddRefs(domDoc));
1377 NS_ENSURE_SUCCESS(rv, rv);
1380 nsCOMPtr<nsIDOMDocument> grip;
1384 NS_GET_IID(nsIDOMDocument),
1386 NS_PROXY_SYNC | NS_PROXY_ALWAYS,
1387 getter_AddRefs(domDoc));
1388 NS_ENSURE_SUCCESS(rv, rv);
1391 nsCOMPtr<nsIDOMElement> domElement;
1393 getter_AddRefs(domElement));
1394 NS_ENSURE_SUCCESS(rv, rv);
1396 NS_ENSURE_TRUE(domElement, NS_ERROR_UNEXPECTED);
1398 nsCOMPtr<nsIDOMXULElement> domXulElement =
1399 do_QueryInterface(domElement, &rv);
1400 NS_ENSURE_SUCCESS(rv, rv);
1407 nsCOMPtr<sbIMediacoreVideoWindow> videoWindow =
1409 NS_ENSURE_SUCCESS(rv, rv);
1411 videoWindow.forget(aVideo);
1421 sbMediacoreManager::SetPrimaryCore(
sbIMediacore * aPrimaryCore)
1423 TRACE((
"sbMediacoreManager[0x%x] - SetPrimaryCore",
this));
1424 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1425 NS_ENSURE_ARG_POINTER(aPrimaryCore);
1430 nsresult rv = NS_ERROR_UNEXPECTED;
1432 nsCOMPtr<sbIMediacoreVolumeControl> volumeControl =
1434 NS_ENSURE_SUCCESS(rv, rv);
1437 nsCOMPtr<sbIMediacoreMultibandEqualizer> equalizer =
1446 rv = volumeControl->SetVolume(
mVolume);
1447 NS_ENSURE_SUCCESS(rv, rv);
1449 rv = volumeControl->SetMute(
mMute);
1450 NS_ENSURE_SUCCESS(rv, rv);
1459 NS_ENSURE_SUCCESS(rv, rv);
1464 nsCOMPtr<nsISimpleEnumerator>
bands;
1465 rv = GetBands(getter_AddRefs(bands));
1466 NS_ENSURE_SUCCESS(rv, rv);
1468 rv = equalizer->SetBands(bands);
1469 NS_ENSURE_SUCCESS(rv, rv);
1481 sbMediacoreManager::GetFactories(nsIArray * *aFactories)
1483 TRACE((
"sbMediacoreManager[0x%x] - GetFactories",
this));
1484 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1485 NS_ENSURE_ARG_POINTER(aFactories);
1487 nsresult rv = NS_ERROR_UNEXPECTED;
1489 nsCOMPtr<nsIMutableArray> mutableArray =
1490 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
1491 NS_ENSURE_SUCCESS(rv, rv);
1494 mFactories.EnumerateRead(sbMediacoreManager::EnumerateIntoArrayISupportsKey,
1495 mutableArray.get());
1497 PRUint32 length = 0;
1498 rv = mutableArray->GetLength(&length);
1499 NS_ENSURE_SUCCESS(rv, rv);
1502 return NS_ERROR_FAILURE;
1505 nsCOMPtr<nsIArray>
array = do_QueryInterface(mutableArray, &rv);
1506 NS_ENSURE_SUCCESS(rv, rv);
1508 array.forget(aFactories);
1514 sbMediacoreManager::GetInstances(nsIArray * *aInstances)
1516 TRACE((
"sbMediacoreManager[0x%x] - GetInstances",
this));
1517 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1518 NS_ENSURE_ARG_POINTER(aInstances);
1520 nsresult rv = NS_ERROR_UNEXPECTED;
1522 nsCOMPtr<nsIMutableArray> mutableArray =
1523 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
1524 NS_ENSURE_SUCCESS(rv, rv);
1528 mCores.EnumerateRead(sbMediacoreManager::EnumerateIntoArrayStringKey,
1529 mutableArray.get());
1531 PRUint32 length = 0;
1532 rv = mutableArray->GetLength(&length);
1533 NS_ENSURE_SUCCESS(rv, rv);
1535 if(length <
mCores.Count()) {
1536 return NS_ERROR_FAILURE;
1539 rv = CallQueryInterface(mutableArray, aInstances);
1540 NS_ENSURE_SUCCESS(rv, rv);
1546 sbMediacoreManager::CreateMediacore(
const nsAString & aContractID,
1547 const nsAString & aInstanceName,
1550 TRACE((
"sbMediacoreManager[0x%x] - CreateMediacore",
this));
1551 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1552 NS_ENSURE_ARG_POINTER(_retval);
1554 nsresult rv = NS_ERROR_UNEXPECTED;
1555 NS_ConvertUTF16toUTF8 contractId(aContractID);
1557 nsCOMPtr<sbIMediacoreFactory> coreFactory =
1558 do_CreateInstance(contractId.BeginReading(), &rv);
1559 NS_ENSURE_SUCCESS(rv, rv);
1561 nsCOMPtr<sbIMediacore> core;
1562 rv = GetMediacore(aInstanceName, getter_AddRefs(core));
1564 if(NS_SUCCEEDED(rv)) {
1565 core.forget(_retval);
1571 rv = coreFactory->Create(aInstanceName, _retval);
1572 NS_ENSURE_SUCCESS(rv, rv);
1574 PRBool success =
mCores.Put(aInstanceName, *_retval);
1575 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
1582 const nsAString & aInstanceName,
1585 TRACE((
"sbMediacoreManager[0x%x] - CreateMediacoreWithFactory",
this));
1586 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1587 NS_ENSURE_ARG_POINTER(aFactory);
1588 NS_ENSURE_ARG_POINTER(_retval);
1590 nsCOMPtr<sbIMediacore> core;
1591 nsresult rv = GetMediacore(aInstanceName, getter_AddRefs(core));
1593 if(NS_SUCCEEDED(rv)) {
1594 core.forget(_retval);
1598 rv = aFactory->Create(aInstanceName, _retval);
1599 NS_ENSURE_SUCCESS(rv, rv);
1601 PRBool success =
mCores.Put(aInstanceName, *_retval);
1602 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
1608 sbMediacoreManager::GetMediacore(
const nsAString & aInstanceName,
1611 TRACE((
"%s[%p] (%s)", __FUNCTION__,
this,
1612 NS_ConvertUTF16toUTF8(aInstanceName).
get()));
1613 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1614 NS_ENSURE_ARG_POINTER(_retval);
1616 nsCOMPtr<sbIMediacore> core;
1620 PRBool success =
mCores.Get(aInstanceName, getter_AddRefs(core));
1621 NS_ENSURE_TRUE(success, NS_ERROR_NOT_AVAILABLE);
1623 core.forget(_retval);
1629 sbMediacoreManager::DestroyMediacore(
const nsAString & aInstanceName)
1631 TRACE((
"sbMediacoreManager[0x%x] - DestroyMediacore",
this));
1632 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1634 nsCOMPtr<sbIMediacore> core;
1638 PRBool success =
mCores.Get(aInstanceName, getter_AddRefs(core));
1639 NS_ENSURE_TRUE(success, NS_ERROR_NOT_AVAILABLE);
1640 NS_ENSURE_TRUE(core, NS_ERROR_UNEXPECTED);
1642 nsresult rv = core->Shutdown();
1643 NS_ENSURE_SUCCESS(rv, rv);
1645 mCores.Remove(aInstanceName);
1653 TRACE((
"sbMediacoreManager[0x%x] - RegisterFactory",
this));
1654 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1655 NS_ENSURE_ARG_POINTER(aFactory);
1659 PRBool success =
mFactories.Put(aFactory, aFactory);
1660 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
1668 TRACE((
"sbMediacoreManager[0x%x] - UnregisterFactory",
this));
1669 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1670 NS_ENSURE_ARG_POINTER(aFactory);
1685 sbMediacoreManager::GetFullscreen(PRBool *aFullscreen)
1687 TRACE((
"sbMediacoreManager[0x%x] - GetFullscreen",
this));
1688 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1689 NS_ENSURE_ARG_POINTER(aFullscreen);
1694 nsresult rv = NS_ERROR_UNEXPECTED;;
1696 nsCOMPtr<sbIMediacoreVideoWindow> videoWindow =
1699 if(NS_SUCCEEDED(rv)) {
1700 rv = videoWindow->GetFullscreen(aFullscreen);
1701 NS_ENSURE_SUCCESS(rv, rv);
1708 NS_ENSURE_SUCCESS(rv, rv);
1721 sbMediacoreManager::SetFullscreen(PRBool aFullscreen)
1723 TRACE((
"sbMediacoreManager[0x%x] - SetFullscreen",
this));
1724 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1726 nsresult rv = NS_ERROR_UNEXPECTED;
1730 nsCOMPtr<sbIMediacoreVideoWindow> videoWindow =
1733 if(NS_SUCCEEDED(rv)) {
1734 rv = videoWindow->SetFullscreen(aFullscreen);
1735 NS_ENSURE_SUCCESS(rv, rv);
1742 NS_ENSURE_SUCCESS(rv, rv);
1748 sbMediacoreManager::GetVideoWindow(nsIDOMXULElement * *aVideoWindow)
1750 TRACE((
"sbMediacoreManager[0x%x] - GetVideoWindow",
this));
1751 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1752 NS_ENSURE_ARG_POINTER(aVideoWindow);
1761 sbMediacoreManager::SetVideoWindow(nsIDOMXULElement * aVideoWindow)
1763 TRACE((
"sbMediacoreManager[0x%x] - SetVideoWindow",
this));
1764 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1765 NS_ENSURE_ARG_POINTER(aVideoWindow);
1779 sbMediacoreManager::VoteWithURI(nsIURI *aURI,
1782 TRACE((
"sbMediacoreManager[0x%x] - VoteWithURI",
this));
1783 NS_ENSURE_ARG_POINTER(aURI);
1784 NS_ENSURE_ARG_POINTER(_retval);
1787 NS_ENSURE_SUCCESS(rv, rv);
1793 sbMediacoreManager::VoteWithChannel(
nsIChannel *aChannel,
1796 TRACE((
"sbMediacoreManager[0x%x] - VoteWithChannel",
this));
1797 NS_ENSURE_ARG_POINTER(aChannel);
1798 NS_ENSURE_ARG_POINTER(_retval);
1801 NS_ENSURE_SUCCESS(rv, rv);
1811 NS_IMETHODIMP sbMediacoreManager::Observe(
nsISupports *aSubject,
1813 const PRUnichar *aData)
1815 TRACE((
"sbMediacoreManager[0x%x] - Observe",
this));
1817 nsresult rv = NS_ERROR_UNEXPECTED;
1819 if (!strcmp(aTopic, APPSTARTUP_CATEGORY)) {
1821 nsCOMPtr<nsIObserverService> obsSvc =
1822 do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
1823 NS_ENSURE_SUCCESS(rv, rv);
1826 do_QueryInterface(NS_ISUPPORTS_CAST(
nsIObserver*,
this), &rv);
1827 NS_ENSURE_SUCCESS(rv, rv);
1830 NS_ENSURE_SUCCESS(rv, rv);
1833 NS_ENSURE_SUCCESS(rv, rv);
1836 NS_ENSURE_SUCCESS(rv, rv);
1843 NS_ENSURE_SUCCESS(rv, rv);
1856 nsCOMPtr<nsIObserverService> obsSvc =
1857 do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
1858 NS_ENSURE_SUCCESS(rv, rv);
1860 nsCOMPtr<nsIObserver> observer =
1861 do_QueryInterface(NS_ISUPPORTS_CAST(
nsIObserver*,
this), &rv);
1862 NS_ENSURE_SUCCESS(rv, rv);
1865 NS_ENSURE_SUCCESS(rv, rv);
1868 NS_ENSURE_SUCCESS(rv, rv);
1875 nsCOMPtr<nsIObserverService> obsSvc =
1876 do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
1877 NS_ENSURE_SUCCESS(rv, rv);
1879 nsCOMPtr<nsIObserver> observer =
1880 do_QueryInterface(NS_ISUPPORTS_CAST(
nsIObserver*,
this), &rv);
1881 NS_ENSURE_SUCCESS(rv, rv);
1884 NS_ENSURE_SUCCESS(rv, rv);
1887 NS_ENSURE_SUCCESS(rv, rv);
1890 NS_ENSURE_SUCCESS(rv, rv);
1897 sbMediacoreManager::CreateEvent(PRUint32 aType,
1903 NS_ENSURE_ARG_POINTER(aOrigin);
1904 NS_ENSURE_ARG_POINTER(retval);
1939 sbMediacoreVideoWindowListener::sbMediacoreVideoWindowListener()
1940 : mWindowReady(PR_FALSE)
1950 nsIDOMEventTarget *aTarget)
1952 NS_ENSURE_ARG_POINTER(aManager);
1953 NS_ENSURE_ARG_POINTER(aTarget);
1962 sbMediacoreVideoWindowListener::HandleEvent(
nsIDOMEvent *aEvent)
1964 NS_ENSURE_TRUE(
mManager, NS_ERROR_NOT_INITIALIZED);
1967 nsresult rv = aEvent->GetType(eventType);
1968 NS_ENSURE_SUCCESS(rv, rv);
1970 if(eventType.EqualsLiteral(
"resize")) {
1973 else if(eventType.EqualsLiteral(
"unload")) {
1974 rv =
mManager->VideoWindowUnloaded();
1975 NS_ENSURE_SUCCESS(rv, rv);
1977 nsCOMPtr<nsIDOMEventListener> grip(
this);
1978 rv =
mTarget->RemoveEventListener(NS_LITERAL_STRING(
"unload"),
1981 NS_ENSURE_SUCCESS(rv, rv);
nsresult do_GetProxyForObject(nsIEventTarget *aTarget, REFNSIID aIID, nsISupports *aObj, PRInt32 aProxyType, void **aProxyObject)
#define SONGBIRD_PROMPTER_CONTRACTID
An interface for accessing, and binding to, stored data.
NS_IMPL_THREADSAFE_RELEASE(sbRequestItem)
NS_IMPL_THREADSAFE_ADDREF(sbRequestItem)
#define SB_WINDOWWATCHER_CONTRACTID
StringArrayEnumerator prototype hasMore
_getSelectedPageStyle s i
function dataRemote(aKey, aRoot)
_updateTextAndScrollDataForFrame aData