50 #include <nsArrayUtils.h>
51 #include <nsAutoLock.h>
52 #include <nsComponentManagerUtils.h>
54 #include <nsIDOMWindow.h>
55 #include <nsILocalFile.h>
56 #include <nsINetUtil.h>
57 #include <nsIProperties.h>
58 #include <nsIStandardURL.h>
59 #include <nsIFileURL.h>
60 #include <nsISupportsPrimitives.h>
61 #include <nsITreeView.h>
62 #include <nsISupportsPrimitives.h>
64 #include <nsIUTF8ConverterService.h>
65 #include <nsIWindowWatcher.h>
66 #include <nsIResumableChannel.h>
67 #include <nsServiceManagerUtils.h>
68 #include <nsNetUtil.h>
69 #include <nsUnicharUtils.h>
74 #include <sbILibraryManager.h>
75 #include <sbILocalDatabaseLibrary.h>
76 #include <sbIFileMetadataService.h>
77 #include <sbIJobProgress.h>
78 #include <sbIPropertyManager.h>
108 #define SB_DOWNLOAD_DEVICE_CATEGORY \
109 NS_LITERAL_STRING("Songbird Download Device").get()
110 #define SB_DOWNLOAD_DEVICE_ID "download"
111 #define SB_DOWNLOAD_DIR_DR "download.folder"
112 #define SB_TMP_DIR "Songbird"
113 #define SB_DOWNLOAD_TMP_DIR "DownloadDevice"
114 #define SB_DOWNLOAD_LIST_NAME \
115 "&chrome://songbird/locale/songbird.properties#device.download"
116 #define SB_STRING_BUNDLE_CHROME_URL \
117 "chrome://songbird/locale/songbird.properties"
118 #define SB_DOWNLOAD_COL_SPEC \
119 "http://songbirdnest.com/data/1.0#trackName 179 http://songbirdnest.com/data/1.0#artistName 115 http://songbirdnest.com/data/1.0#albumName 115 http://songbirdnest.com/data/1.0#originPageImage 43 http://songbirdnest.com/data/1.0#downloadDetails 266 http://songbirdnest.com/data/1.0#downloadButton 73"
121 #define SB_PREF_DOWNLOAD_MEDIALIST "songbird.library.download"
122 #define SB_PREF_WEB_LIBRARY "songbird.library.web"
123 #define SB_DOWNLOAD_CUSTOM_TYPE "download"
124 #define SB_DOWNLOAD_PROGRESS_UPDATE_PERIOD_MS 1000
125 #define SB_DOWNLOAD_IDLE_TIMEOUT_MS (60*1000)
126 #define SB_DOWNLOAD_PROGRESS_TIMER_MS 1000
136 static PRLogModuleInfo* gLog = PR_NewLogModule(
"sbDownloadDevice");
137 #define TRACE(args) PR_LOG(gLog, PR_LOG_DEBUG, args)
138 #define LOG(args) PR_LOG(gLog, PR_LOG_WARN, args)
152 if( (c >= (
unsigned char)
'A') && (c <= (
unsigned char)
'Z') )
154 return (PRInt32)(c - (
unsigned char)
'A');
156 else if( (c >= (
unsigned char)
'a') && (c <= (
unsigned char)
'z') )
158 return ((PRInt32)(c - (
unsigned char)
'a') +26);
160 else if( (c >= (
unsigned char)
'0') && (c <= (
unsigned char)
'9') )
162 return ((PRInt32)(c - (
unsigned char)
'0') +52);
164 else if( (
unsigned char)
'+' == c )
168 else if( (
unsigned char)
'/' == c )
180 unsigned char *dest )
182 PRUint32 b32 = (PRUint32)0;
186 for( i = 0; i < 4; i++ )
198 dest[0] = (
unsigned char)((b32 >> 16) & 0xFF);
199 dest[1] = (
unsigned char)((b32 >> 8) & 0xFF);
200 dest[2] = (
unsigned char)((b32 ) & 0xFF);
207 unsigned char *dest )
209 PRUint32 b32 = (PRUint32)0;
219 b32 = (PRUint32)bits;
228 b32 |= (PRUint32)bits;
237 ubits = (PRUint32)bits;
240 dest[0] = (
unsigned char)((b32 >> 8) & 0xFF);
241 dest[1] = (
unsigned char)((b32 ) & 0xFF);
248 unsigned char *dest )
260 ubits = (PRUint32)bits;
269 ubits = (PRUint32)bits;
272 dest[0] = (
unsigned char)b32;
278 static PRStatus
decode(
const unsigned char *src,
280 unsigned char *dest )
282 PRStatus rv = PR_SUCCESS;
287 if( PR_SUCCESS != rv )
312 PR_NOT_REACHED(
"coding error");
324 PRBool allocated = PR_FALSE;
326 if( (
char *)0 == src )
333 srclen = strlen(src);
336 if( srclen && (0 == (srclen & 3)) )
338 if( (
char)
'=' == src[ srclen-1 ] )
340 if( (
char)
'=' == src[ srclen-2 ] )
351 if( (
char *)0 == dest )
353 PRUint32 destlen = ((srclen * 3) / 4);
354 dest = (
char *)PR_MALLOC(destlen + 1);
355 if( (
char *)0 == dest )
359 dest[ destlen ] = (char)0;
363 status =
decode((
const unsigned char *)src, srclen, (
unsigned char *)dest);
364 if( PR_SUCCESS != status )
366 if( PR_TRUE == allocated )
380 NS_NAMED_LITERAL_CSTRING(DISPOSITION_ATTACHEMENT,
"attachment");
381 NS_NAMED_LITERAL_CSTRING(DISPOSITION_FILENAME,
"filename=");
383 nsCAutoString unicodeDisposition(contentDisposition);
384 unicodeDisposition.StripWhitespace();
386 PRInt32
pos = unicodeDisposition.Find(DISPOSITION_ATTACHEMENT,
387 CaseInsensitiveCompare);
389 return EmptyCString();
391 pos = unicodeDisposition.Find(DISPOSITION_FILENAME,
392 CaseInsensitiveCompare);
394 return EmptyCString();
396 pos += DISPOSITION_FILENAME.Length();
401 if(unicodeDisposition.CharAt(pos) ==
'"') {
404 endPos = unicodeDisposition.FindChar(
'\"', pos);
407 return EmptyCString();
411 endPos = unicodeDisposition.FindChar(
';', pos);
414 endPos = unicodeDisposition.Length();
418 nsCString filename(Substring(unicodeDisposition, pos, endPos - pos));
421 if(StringBeginsWith(filename, NS_LITERAL_CSTRING(
"=?")) &&
422 StringEndsWith(filename, NS_LITERAL_CSTRING(
"?="))) {
425 nsCOMPtr<nsIUTF8ConverterService> convServ =
426 do_GetService(
"@mozilla.org/intl/utf8converterservice;1", &rv);
427 NS_ENSURE_SUCCESS(rv, EmptyCString());
430 endPos = filename.FindChar(
'?', pos);
433 return EmptyCString();
436 nsCAutoString
charset(Substring(filename, pos, endPos - pos));
440 endPos = filename.FindChar(
'?', pos);
443 return EmptyCString();
445 nsCAutoString encoding(Substring(filename, pos, endPos - pos));
448 ToLowerCase(encoding);
451 if(!encoding.EqualsLiteral(
"b") &&
452 !encoding.EqualsLiteral(
"q")) {
453 return EmptyCString();
457 endPos = filename.FindChar(
'?', pos);
460 filename.CharAt(endPos + 1) !=
'=')
461 return EmptyCString();
463 nsCAutoString convertedFilename;
464 nsCAutoString filenameToDecode(Substring(filename, pos, endPos - pos));
466 if(encoding.EqualsLiteral(
"b")) {
467 char *
str =
SB_Base64Decode(filenameToDecode.get(), filenameToDecode.Length(), nsnull);
469 nsDependentCString strToConvert(str);
470 rv = convServ->ConvertStringToUTF8(strToConvert, charset.get(), PR_TRUE, convertedFilename);
474 else if(encoding.EqualsLiteral(
"q")) {
475 NS_WARNING(
"XXX: No support for Q encoded strings!");
478 if(NS_SUCCEEDED(rv)) {
479 filename = convertedFilename;
483 ReplaceChars(filename, nsDependentCString(FILE_ILLEGAL_CHARACTERS),
'_');
516 mpDeviceMonitor(nsnull)
542 NS_IMETHODIMP sbDownloadDevice::Observe(
545 const PRUnichar *
aData)
550 NS_ENSURE_ARG_POINTER(aTopic);
552 if (!strcmp(
"quit-application-granted", aTopic)) {
554 if (mpDownloadSession)
556 mpDownloadSession->Shutdown();
557 mpDownloadSession = nsnull;
561 nsCOMPtr<nsIObserverService> obsSvc =
562 do_GetService(
"@mozilla.org/observer-service;1", &rv);
563 NS_ENSURE_SUCCESS(rv, rv);
564 rv = obsSvc->RemoveObserver(
this, aTopic);
565 NS_ENSURE_SUCCESS(rv, rv);
569 return NS_ERROR_NOT_IMPLEMENTED;
583 NS_IMETHODIMP sbDownloadDevice::Initialize()
585 nsCOMPtr<sbIPropertyManager>
587 nsCOMPtr<sbIURIPropertyInfo>
589 nsCOMPtr<sbILibraryManager> pLibraryManager;
594 NS_ENSURE_SUCCESS(rv, rv);
601 NS_ENSURE_SUCCESS(rv, rv);
604 mpDeviceMonitor = nsAutoMonitor::NewMonitor
605 (
"sbDownloadDevice::mpDeviceMonitor");
606 NS_ENSURE_TRUE(mpDeviceMonitor, NS_ERROR_OUT_OF_MEMORY);
609 mpIOService = do_GetService(
"@mozilla.org/network/io-service;1", &rv);
610 NS_ENSURE_SUCCESS(rv, rv);
614 NS_ENSURE_SUCCESS(rv, rv);
618 do_GetService(
"@songbirdnest.com/Songbird/library/Manager;1", &rv);
619 NS_ENSURE_SUCCESS(rv, rv);
623 nsCOMPtr<nsIStringBundleService>
624 pStringBundleService;
627 pStringBundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
628 NS_ENSURE_SUCCESS(rv, rv);
630 getter_AddRefs(mpStringBundle));
631 NS_ENSURE_SUCCESS(rv, rv);
635 rv = mpStringBundle->GetStringFromName
636 (NS_LITERAL_STRING(
"device.download.queued").
get(),
637 getter_Copies(mQueuedStr));
638 NS_ENSURE_SUCCESS(rv, rv);
641 rv = pLibraryManager->GetMainLibrary(getter_AddRefs(mpMainLibrary));
642 NS_ENSURE_SUCCESS(rv, rv);
646 nsCOMPtr<nsISupportsString> pSupportsString;
647 nsAutoString webLibraryGUID;
652 getter_AddRefs(pSupportsString));
653 NS_ENSURE_SUCCESS(rv, rv);
654 rv = pSupportsString->GetData(webLibraryGUID);
655 NS_ENSURE_SUCCESS(rv, rv);
658 rv = pLibraryManager->GetLibrary(webLibraryGUID,
659 getter_AddRefs(mpWebLibrary));
660 NS_ENSURE_SUCCESS(rv, rv);
664 rv = InitializeDownloadMediaList();
665 NS_ENSURE_SUCCESS(rv, rv);
669 rv = mpMainLibrary->AddListener
675 NS_ENSURE_SUCCESS(rv, rv);
679 NS_ENSURE_SUCCESS(rv, rv);
683 nsCOMPtr<nsIProperties> pProperties;
684 PRUint32 permissions;
688 pProperties = do_GetService(
"@mozilla.org/file/directory_service;1",
690 NS_ENSURE_SUCCESS(rv, rv);
691 rv = pProperties->Get(
"TmpD",
693 getter_AddRefs(mpTmpDownloadDir));
694 NS_ENSURE_SUCCESS(rv, rv);
695 rv = mpTmpDownloadDir->GetPermissions(&permissions);
696 NS_ENSURE_SUCCESS(rv, rv);
699 rv = mpTmpDownloadDir->Append(NS_LITERAL_STRING(
SB_TMP_DIR));
700 NS_ENSURE_SUCCESS(rv, rv);
701 rv = mpTmpDownloadDir->Exists(&exists);
702 NS_ENSURE_SUCCESS(rv, rv);
705 rv = mpTmpDownloadDir->Create(nsIFile::DIRECTORY_TYPE, permissions);
706 NS_ENSURE_SUCCESS(rv, rv);
712 NS_ENSURE_SUCCESS(rv, rv);
713 rv = mpTmpDownloadDir->Exists(&exists);
714 NS_ENSURE_SUCCESS(rv, rv);
717 rv = mpTmpDownloadDir->Remove(PR_TRUE);
718 if (NS_SUCCEEDED(rv))
723 rv = mpTmpDownloadDir->Create(nsIFile::DIRECTORY_TYPE, permissions);
724 NS_ENSURE_SUCCESS(rv, rv);
730 nsCOMPtr<nsIObserverService> obsSvc =
731 do_GetService(
"@mozilla.org/observer-service;1", &rv);
732 NS_ENSURE_SUCCESS(rv, rv);
733 rv = obsSvc->AddObserver(
this,
"quit-application-granted", PR_FALSE);
734 NS_ENSURE_SUCCESS(rv, rv);
738 nsCOMPtr<nsIThreadPool> threadPool =
739 do_CreateInstance(
"@mozilla.org/thread-pool;1", &rv);
740 NS_ENSURE_SUCCESS(rv, rv);
742 rv = threadPool->SetIdleThreadLimit(0);
743 NS_ENSURE_SUCCESS(rv, rv);
745 rv = threadPool->SetIdleThreadTimeout(60000);
746 NS_ENSURE_SUCCESS(rv, rv);
748 rv = threadPool->SetThreadLimit(1);
749 NS_ENSURE_SUCCESS(rv, rv);
752 threadPool.forget(getter_AddRefs(mFileMoveThreadPool));
768 NS_IMETHODIMP sbDownloadDevice::Finalize()
774 nsAutoMonitor mon(mpDeviceMonitor);
777 if (mpDownloadSession)
779 mpDownloadSession->Shutdown();
780 mpDownloadSession = nsnull;
788 mpMainLibrary->RemoveListener(
this);
791 FinalizeDownloadMediaList();
795 if (mpDeviceMonitor) {
796 nsAutoMonitor::DestroyMonitor(mpDeviceMonitor);
797 mpDeviceMonitor = nsnull;
800 mpMainLibrary = nsnull;
801 mpWebLibrary = nsnull;
844 NS_IMETHODIMP sbDownloadDevice::GetLibrary(
845 const nsAString &aDeviceIdentifier,
861 const nsAString &aDeviceIdentifier,
865 nsAutoMonitor mon(mpDeviceMonitor);
884 NS_IMETHODIMP sbDownloadDevice::GetTransferLocation(
885 const nsAString &aDeviceIdentifier,
887 nsIURI **aTransferLocationURI)
889 LOG((
"1: GetTransferLocation\n"));
891 return (NS_ERROR_NOT_IMPLEMENTED);
918 NS_IMETHODIMP sbDownloadDevice::TransferItems(
919 const nsAString &aDeviceIdentifier,
920 nsIArray *aMediaItems,
921 nsIURI *aDestinationPath,
922 PRUint32 aDeviceOperation,
923 PRBool aBeginTransferNow,
925 PRUint32 *aItemCount)
927 nsCOMPtr<sbIMediaItem> pMediaItem;
933 NS_ENSURE_ARG_POINTER(aMediaItems);
938 return (NS_ERROR_NOT_IMPLEMENTED);
941 ClearCompletedItems();
945 rv = aMediaItems->GetLength(&itemCount);
946 NS_ENSURE_SUCCESS(rv, rv);
947 for (i = 0; i < itemCount; i++)
950 pMediaItem = do_QueryElementAt(aMediaItems, i, &rv);
955 rv = EnqueueItem(pMediaItem);
960 mpDeviceLibraryListener->SetIgnoreListener(PR_TRUE);
961 mpDownloadMediaList->Remove(pMediaItem);
962 mpDeviceLibraryListener->SetIgnoreListener(PR_FALSE);
967 rv = RunTransferQueue();
968 NS_ENSURE_SUCCESS(rv, rv);
978 NS_IMETHODIMP sbDownloadDevice::UpdateItems(
979 const nsAString &aDeviceIdentifier,
980 nsIArray *aMediaItems,
981 PRUint32 *aItemCount)
997 NS_IMETHODIMP sbDownloadDevice::DeleteItems(
998 const nsAString &aDeviceIdentifier,
999 nsIArray *aMediaItems,
1000 PRUint32 *aItemCount)
1002 nsCOMPtr<sbIMediaItem> pMediaItem;
1003 PRUint32 arrayLength;
1006 PRBool cancelSession = PR_FALSE;
1007 PRUint32 itemCount = 0;
1009 nsresult result =
NS_OK;
1012 NS_ENSURE_ARG_POINTER(aMediaItems);
1013 NS_ENSURE_ARG_POINTER(aItemCount);
1016 nsAutoMonitor mon(mpDeviceMonitor);
1019 result = aMediaItems->GetLength(&arrayLength);
1020 for (i = 0; (NS_SUCCEEDED(result) && (i < arrayLength)); i++)
1023 pMediaItem = do_QueryElementAt(aMediaItems, i, &result);
1026 if (NS_SUCCEEDED(result))
1030 if (NS_SUCCEEDED(result1))
1035 if (NS_SUCCEEDED(result))
1037 nsCOMPtr<sbIMediaItem> statusTarget;
1038 nsresult rv = GetStatusTarget(pMediaItem,
1039 getter_AddRefs(statusTarget));
1040 NS_ENSURE_SUCCESS(rv, rv);
1042 if (property.value->GetMode() !=
1049 if (NS_SUCCEEDED(result) && mpDownloadSession && !cancelSession)
1051 result1 = pMediaItem->Equals(mpDownloadSession->mpMediaItem,
1053 if (NS_SUCCEEDED(result1) && equals)
1054 cancelSession = PR_TRUE;
1062 result1 = CancelSession();
1063 if (NS_SUCCEEDED(result1))
1068 *aItemCount = itemCount;
1082 NS_IMETHODIMP sbDownloadDevice::DeleteAllItems(
1083 const nsAString &aDeviceIdentifier,
1084 PRUint32 *aItemCount)
1086 nsCOMPtr<sbIMediaItem> pMediaItem;
1087 PRUint32 itemCount = 0;
1089 nsresult result =
NS_OK;
1092 NS_ENSURE_ARG_POINTER(aItemCount);
1095 nsAutoMonitor mon(mpDeviceMonitor);
1098 while (GetNextTransferItem(getter_AddRefs(pMediaItem)))
1102 if (mpDownloadSession)
1104 result1 = CancelSession();
1105 if (NS_SUCCEEDED(result1))
1110 *aItemCount = itemCount;
1121 NS_IMETHODIMP sbDownloadDevice::BeginTransfer(
1122 const nsAString &aDeviceIdentifier,
1125 LOG((
"1: BeginTransfer\n"));
1127 return (NS_ERROR_NOT_IMPLEMENTED);
1142 NS_IMETHODIMP sbDownloadDevice::CancelTransfer(
1143 const nsAString &aDeviceIdentifier,
1144 nsIArray *aMediaItems,
1145 PRUint32 *aNumItems)
1147 LOG((
"1: CancelTransfer\n"));
1149 return (NS_ERROR_NOT_IMPLEMENTED);
1163 NS_IMETHODIMP sbDownloadDevice::SuspendTransfer(
1164 const nsAString &aDeviceIdentifier,
1165 PRUint32 *aNumItems)
1167 PRUint32 numItems = 0;
1171 NS_ENSURE_ARG_POINTER(aNumItems);
1174 nsAutoMonitor mon(mpDeviceMonitor);
1177 if (mpDownloadSession)
1179 rv = mpDownloadSession->Suspend();
1180 NS_ENSURE_SUCCESS(rv, rv);
1182 NS_ENSURE_SUCCESS(rv, rv);
1187 *aNumItems = numItems;
1203 NS_IMETHODIMP sbDownloadDevice::ResumeTransfer(
1204 const nsAString &aDeviceIdentifier,
1205 PRUint32 *aNumItems)
1207 PRUint32 numItems = 0;
1211 NS_ENSURE_ARG_POINTER(aNumItems);
1214 nsAutoMonitor mon(mpDeviceMonitor);
1217 if (mpDownloadSession)
1219 rv = mpDownloadSession->Resume();
1220 NS_ENSURE_SUCCESS(rv, rv);
1222 NS_ENSURE_SUCCESS(rv, rv);
1227 *aNumItems = numItems;
1241 NS_IMETHODIMP sbDownloadDevice::GetUsedSpace(
1242 const nsAString &aDeviceIdentifier,
1243 PRInt64 *aUsedSpace)
1245 LOG((
"1: GetUsedSpace\n"));
1247 return (NS_ERROR_NOT_IMPLEMENTED);
1259 NS_IMETHODIMP sbDownloadDevice::GetAvailableSpace(
1260 const nsAString &aDeviceIdentifier,
1261 PRInt64 *aAvailableSpace)
1263 LOG((
"1: GetAvailableSpace\n"));
1265 return (NS_ERROR_NOT_IMPLEMENTED);
1279 NS_IMETHODIMP sbDownloadDevice::GetSupportedFormats(
1280 const nsAString &aDeviceIdentifier,
1281 nsIArray **aSupportedFormats)
1283 LOG((
"1: GetSupportedFormats\n"));
1285 return (NS_ERROR_NOT_IMPLEMENTED);
1297 NS_IMETHODIMP sbDownloadDevice::IsDownloadSupported(
1298 const nsAString &aDeviceIdentifier,
1299 PRBool *aDownloadSupported)
1301 LOG((
"1: IsDownloadSupported\n"));
1303 return (NS_ERROR_NOT_IMPLEMENTED);
1317 NS_IMETHODIMP sbDownloadDevice::IsUploadSupported(
1318 const nsAString &aDeviceIdentifier,
1319 PRBool *aUploadSupported)
1321 LOG((
"1: IsUploadSupported\n"));
1323 return (NS_ERROR_NOT_IMPLEMENTED);
1335 NS_IMETHODIMP sbDownloadDevice::IsDeleteSupported(
1336 const nsAString &aDeviceIdentifier,
1337 PRBool *aDeleteSupported)
1339 LOG((
"1: IsDeleteSupported\n"));
1341 return (NS_ERROR_NOT_IMPLEMENTED);
1356 NS_IMETHODIMP sbDownloadDevice::IsUpdateSupported(
1357 const nsAString &aDeviceIdentifier,
1358 PRBool *aUpdateSupported)
1360 LOG((
"1: IsUpdateSupported\n"));
1362 return (NS_ERROR_NOT_IMPLEMENTED);
1374 NS_IMETHODIMP sbDownloadDevice::IsEjectSupported(
1375 const nsAString &aDeviceIdentifier,
1376 PRBool *aEjectSupported)
1378 LOG((
"1: IsEjectSupported\n"));
1380 return (NS_ERROR_NOT_IMPLEMENTED);
1392 NS_IMETHODIMP sbDownloadDevice::EjectDevice(
1393 const nsAString &aDeviceIdentifier,
1396 LOG((
"1: EjectDevice\n"));
1398 return (NS_ERROR_NOT_IMPLEMENTED);
1406 NS_IMETHODIMP sbDownloadDevice::GetName(
1409 LOG((
"1: GetName\n"));
1411 return (NS_ERROR_NOT_IMPLEMENTED);
1414 NS_IMETHODIMP sbDownloadDevice::SetName(
1415 const nsAString &aName)
1417 LOG((
"1: SetName\n"));
1419 return (NS_ERROR_NOT_IMPLEMENTED);
1422 NS_IMETHODIMP sbDownloadDevice::GetDeviceCategory(
1423 nsAString &aDeviceCategory)
1429 NS_IMETHODIMP sbDownloadDevice::GetDeviceIdentifiers(
1432 LOG((
"1: GetDeviceIdentifiers\n"));
1434 return (NS_ERROR_NOT_IMPLEMENTED);
1437 NS_IMETHODIMP sbDownloadDevice::GetDeviceCount(
1438 PRUint32 *aDeviceCount)
1440 LOG((
"1: GetDeviceCount\n"));
1442 return (NS_ERROR_NOT_IMPLEMENTED);
1456 NS_IMETHODIMP sbDownloadDevice::ClearCompletedItems()
1458 nsCOMPtr<sbIMediaItem> pMediaItem;
1464 rv = mpDownloadMediaList->GetLength(&itemCount);
1465 NS_ENSURE_SUCCESS(rv, rv);
1469 for (i = itemCount - 1; i >= 0; i--)
1472 rv= mpDownloadMediaList->GetItemByIndex(i, getter_AddRefs(pMediaItem));
1478 if ( property.value->GetMode()
1481 mpDeviceLibraryListener->SetIgnoreListener(PR_TRUE);
1482 rv = mpDownloadMediaList->Remove(pMediaItem);
1483 mpDeviceLibraryListener->SetIgnoreListener(PR_FALSE);
1487 NS_WARNING(
"Failed to remove completed download item.\n");
1499 NS_IMETHODIMP sbDownloadDevice::GetDownloadMediaList(
1505 NS_ENSURE_ARG_POINTER(aDownloadMediaList);
1508 rv = InitializeDownloadMediaList();
1509 NS_ENSURE_SUCCESS(rv, rv);
1512 NS_ADDREF(*aDownloadMediaList = mpDownloadMediaList);
1517 NS_IMETHODIMP sbDownloadDevice::GetCompletedItemCount(
1518 PRUint32 *aCompletedItemCount)
1520 nsCOMPtr<sbIMediaItem> pMediaItem;
1527 NS_ENSURE_ARG_POINTER(aCompletedItemCount);
1530 rv = mpDownloadMediaList->GetLength(&itemCount);
1531 NS_ENSURE_SUCCESS(rv, rv);
1535 for (i = 0; i < itemCount; i++)
1538 rv= mpDownloadMediaList->GetItemByIndex(i, getter_AddRefs(pMediaItem));
1539 NS_ENSURE_SUCCESS(rv, rv);
1543 if ( property.value->GetMode()
1546 completedItemCount++;
1572 NS_IMETHODIMP sbDownloadDevice::OnItemAdded(
1579 NS_ENSURE_ARG_POINTER(_retval);
1595 NS_IMETHODIMP sbDownloadDevice::OnBeforeItemRemoved(
1602 NS_ENSURE_ARG_POINTER(_retval);
1618 NS_IMETHODIMP sbDownloadDevice::OnAfterItemRemoved(
1628 NS_ENSURE_ARG_POINTER(aMediaItem);
1629 NS_ENSURE_ARG_POINTER(_retval);
1632 rv = mpDownloadMediaList->Equals(aMediaItem, &isEqual);
1633 if (NS_SUCCEEDED(rv) && isEqual)
1634 InitializeDownloadMediaList();
1636 *_retval = PR_FALSE;
1652 NS_IMETHODIMP sbDownloadDevice::OnItemUpdated(
1659 NS_ENSURE_ARG_POINTER(_retval);
1665 NS_IMETHODIMP sbDownloadDevice::OnItemMoved(
1667 PRUint32 aFromIndex,
1672 NS_ENSURE_ARG_POINTER(_retval);
1688 NS_IMETHODIMP sbDownloadDevice::OnListCleared(
1690 PRBool aExcludeLists,
1694 NS_ENSURE_ARG_POINTER(_retval);
1697 InitializeDownloadMediaList();
1699 *_retval = PR_FALSE;
1713 NS_IMETHODIMP sbDownloadDevice::OnBeforeListCleared(
1715 PRBool aExcludeLists,
1719 NS_ENSURE_ARG_POINTER(_retval);
1721 *_retval = PR_FALSE;
1726 sbDownloadDevice::CreatePlaylists(
const nsAString &aDeviceIdentifier,
1727 nsIArray *aMediaLists,
1728 PRUint32 *aItemCount)
1734 sbDownloadDevice::DeletePlaylists(
const nsAString &aDeviceIdentifier,
1735 nsIArray *aMediaLists,
1736 PRUint32 *aItemCount)
1742 sbDownloadDevice::AddToPlaylist(
const nsAString &aDeviceIdentifier,
1744 nsIArray *aMediaLists,
1745 PRUint32 aBeforeIndex,
1746 PRUint32 *aItemCount)
1752 sbDownloadDevice::RemoveFromPlaylist(
const nsAString &aDeviceIdentifier,
1756 PRUint32 *aItemCount)
1762 sbDownloadDevice::ClearPlaylist(
const nsAString &aDeviceIdentifier,
1764 PRUint32 *aItemCount)
1770 sbDownloadDevice::MovePlaylistItem(
const nsAString &aDeviceIdentifier,
1772 PRUint32 aFromIndex,
1774 PRUint32 *aItemCount)
1790 NS_IMETHODIMP sbDownloadDevice::OnBatchBegin(
1808 NS_IMETHODIMP sbDownloadDevice::OnBatchEnd(
1834 nsresult sbDownloadDevice::InitializeDownloadMediaList()
1836 nsAutoString downloadMediaListGUID;
1837 nsCOMPtr<sbIMediaItem> pMediaItem;
1841 NS_ENSURE_STATE(mpDeviceMonitor);
1842 nsAutoMonitor mon(mpDeviceMonitor);
1845 if (mpDownloadMediaList)
1848 rv = mpDownloadMediaList->GetGuid(downloadMediaListGUID);
1849 NS_ENSURE_SUCCESS(rv, rv);
1850 rv = mpMainLibrary->GetMediaItem(downloadMediaListGUID,
1851 getter_AddRefs(pMediaItem));
1852 if (NS_SUCCEEDED(rv))
1856 FinalizeDownloadMediaList();
1860 GetDownloadMediaList();
1863 if (!mpDownloadMediaList)
1868 rv = DeleteAllItems(mDeviceIdentifier, &itemCount);
1869 NS_ENSURE_SUCCESS(rv, rv);
1872 rv = CreateDownloadMediaList();
1873 NS_ENSURE_SUCCESS(rv, rv);
1877 rv = UpdateDownloadMediaList();
1878 NS_ENSURE_SUCCESS(rv, rv);
1882 NS_ENSURE_TRUE(mpDeviceLibraryListener, NS_ERROR_OUT_OF_MEMORY);
1883 rv = mpDeviceLibraryListener->Init(mDeviceIdentifier,
this);
1884 NS_ENSURE_SUCCESS(rv, rv);
1887 rv = mpDownloadMediaList->AddListener
1888 (mpDeviceLibraryListener,
1894 NS_ENSURE_SUCCESS(rv, rv);
1896 mpDeviceLibraryListener);
1897 NS_ENSURE_SUCCESS(rv, rv);
1910 void sbDownloadDevice::FinalizeDownloadMediaList()
1913 if (mpDownloadMediaList && mpDeviceLibraryListener)
1914 mpDownloadMediaList->RemoveListener(mpDeviceLibraryListener);
1915 mpDownloadMediaList = nsnull;
1916 mpDeviceLibraryListener = nsnull;
1926 nsresult sbDownloadDevice::CreateDownloadMediaList()
1928 nsAutoString downloadMediaListGUID;
1932 rv = mpMainLibrary->CreateMediaList(NS_LITERAL_STRING(
"simple"),
1934 getter_AddRefs(mpDownloadMediaList));
1935 NS_ENSURE_SUCCESS(rv, rv);
1939 rv = mpDownloadMediaList->GetGuid(downloadMediaListGUID);
1940 NS_ENSURE_SUCCESS(rv, rv);
1941 rv = mpMainLibrary->SetProperty
1943 downloadMediaListGUID);
1944 NS_ENSURE_SUCCESS(rv, rv);
1956 void sbDownloadDevice::GetDownloadMediaList()
1958 nsCOMPtr<nsISupportsString> pSupportsString;
1959 nsCOMPtr<sbIMediaItem> pMediaItem;
1960 nsAutoString downloadMediaListGUID;
1964 rv = mpMainLibrary->GetProperty
1966 downloadMediaListGUID);
1967 if (NS_FAILED(rv) || downloadMediaListGUID.IsEmpty())
1973 getter_AddRefs(pSupportsString));
1974 if (NS_FAILED(rv))
return;
1975 rv = pSupportsString->GetData(downloadMediaListGUID);
1976 if (NS_FAILED(rv))
return;
1979 mpMainLibrary->SetProperty
1981 downloadMediaListGUID);
1985 rv = mpMainLibrary->GetMediaItem(downloadMediaListGUID,
1986 getter_AddRefs(pMediaItem));
1987 if (NS_FAILED(rv))
return;
1988 mpDownloadMediaList = do_QueryInterface(pMediaItem, &rv);
1990 mpDownloadMediaList = nsnull;
2000 nsresult sbDownloadDevice::UpdateDownloadMediaList()
2006 NS_ENSURE_SUCCESS(rv, rv);
2009 nsAutoString downloadColSpec;
2011 rv = mpDownloadMediaList->SetProperty
2014 NS_ENSURE_SUCCESS(rv, rv);
2017 rv = mpDownloadMediaList->SetProperty
2022 rv = mpDownloadMediaList->SetProperty
2024 NS_LITERAL_STRING(
"0"));
2026 NS_ENSURE_SUCCESS(rv, rv);
2047 nsresult sbDownloadDevice::EnqueueItem(
2053 rv = SetTransferDestination(apMediaItem);
2054 NS_ENSURE_SUCCESS(rv, rv);
2057 nsCOMPtr<sbIMediaItem> statusTarget;
2058 rv = GetStatusTarget(apMediaItem, getter_AddRefs(statusTarget));
2059 NS_ENSURE_SUCCESS(rv, rv);
2064 rv = apMediaItem->SetProperty
2067 NS_ENSURE_SUCCESS(rv, rv);
2070 rv = statusTarget->SetProperty
2073 NS_ENSURE_SUCCESS(rv, rv);
2078 nsAutoMonitor mon(mpDeviceMonitor);
2080 NS_ENSURE_SUCCESS(rv, rv);
2094 nsresult sbDownloadDevice::RunTransferQueue()
2096 nsCOMPtr<sbIMediaItem> pMediaItem;
2097 PRBool initiated = PR_FALSE;
2098 nsresult result =
NS_OK;
2101 nsAutoMonitor mon(mpDeviceMonitor);
2104 while ( !mpDownloadSession
2105 && GetNextTransferItem(getter_AddRefs(pMediaItem)))
2109 if (!mpDownloadSession)
2110 result = NS_ERROR_OUT_OF_MEMORY;
2111 if (NS_SUCCEEDED(result))
2112 result = mpDownloadSession->Initiate();
2113 if (NS_SUCCEEDED(result))
2114 initiated = PR_TRUE;
2116 initiated = PR_FALSE;
2123 if (!initiated && mpDownloadSession)
2124 mpDownloadSession = nsnull;
2128 if (mpDownloadSession)
2130 if (!mpDownloadSession->IsSuspended())
2158 PRBool sbDownloadDevice::GetNextTransferItem(
2161 nsCOMPtr<sbIMediaItem> pMediaItem;
2162 nsresult result =
NS_OK;
2166 getter_AddRefs(pMediaItem));
2167 if (NS_SUCCEEDED(result))
2171 if (NS_SUCCEEDED(result))
2173 NS_ADDREF(*appMediaItem = pMediaItem);
2190 nsresult sbDownloadDevice::ResumeTransfers()
2192 nsCOMPtr<sbIMediaItem> pMediaItem;
2194 PRUint32 queuedCount = 0;
2196 nsresult itemResult;
2197 nsresult result =
NS_OK;
2199 result = mpDownloadMediaList->GetLength(&itemCount);
2202 for (i = 0; (NS_SUCCEEDED(result) && (i < itemCount)); i++)
2205 itemResult = mpDownloadMediaList->GetItemByIndex
2206 (i, getter_AddRefs(pMediaItem));
2207 NS_ENSURE_SUCCESS(itemResult, itemResult);
2212 if (property.value->GetMode() !=
2215 nsAutoMonitor mon(mpDeviceMonitor);
2217 if (NS_SUCCEEDED(itemResult))
2224 if (queuedCount > 0)
2242 nsresult sbDownloadDevice::SetTransferDestination(
2243 nsCOMPtr<sbIMediaItem> pMediaItem)
2246 nsCOMPtr<nsIFile> pDstFile;
2247 nsCOMPtr<nsIURI> pDstURI;
2248 nsCOMPtr<sbIDownloadDeviceHelper>
2251 nsresult propertyResult;
2252 nsAutoString contentType;
2253 nsresult result =
NS_OK;
2256 propertyResult = pMediaItem->GetProperty
2259 if (NS_SUCCEEDED(propertyResult) && !dstProp.IsEmpty())
2265 if (NS_SUCCEEDED(result))
2267 pDownloadHelper = do_GetService
2268 (
"@songbirdnest.com/Songbird/DownloadDeviceHelper;1",
2272 if (NS_SUCCEEDED(result))
2273 result = pMediaItem->GetContentType (contentType);
2275 if (NS_SUCCEEDED(result))
2276 result = pDownloadHelper->GetDownloadFolder(contentType,
2277 getter_AddRefs(pDstFile));
2284 if (NS_SUCCEEDED(result))
2285 result = mpIOService->NewFileURI(pDstFile, getter_AddRefs(pDstURI));
2287 if (NS_SUCCEEDED(result))
2288 result = pDstURI->GetSpec(dstSpec);
2291 if (NS_SUCCEEDED(result))
2293 result = pMediaItem->SetProperty
2295 NS_ConvertUTF8toUTF16(dstSpec));
2309 nsresult sbDownloadDevice::CancelSession()
2311 nsresult result =
NS_OK;
2314 if (mpDownloadSession)
2316 mpDownloadSession->Shutdown();
2317 mpDownloadSession = nsnull;
2337 void sbDownloadDevice::SessionCompleted(
2344 nsAutoMonitor mon(mpDeviceMonitor);
2350 if (apDownloadSession == mpDownloadSession)
2351 mpDownloadSession = nsnull;
2374 nsresult sbDownloadDevice::GetTmpFile(
2375 nsIFile **ppTmpFile)
2377 nsCOMPtr<nsIFile> pTmpFile;
2378 nsString tmpFileName;
2381 nsresult result =
NS_OK;
2388 result = mpTmpDownloadDir->Clone(getter_AddRefs(pTmpFile));
2391 if (NS_SUCCEEDED(result))
2393 tmpFileName.AssignLiteral(
"tmp");
2394 tmpFileName.AppendInt(fileNum++);
2395 result = pTmpFile->Append(tmpFileName);
2399 if (NS_SUCCEEDED(result))
2400 result = pTmpFile->Exists(&exists);
2402 while (exists && NS_SUCCEEDED(result));
2405 if (NS_SUCCEEDED(result))
2406 NS_ADDREF(*ppTmpFile = pTmpFile);
2423 nsresult sbDownloadDevice::MakeFileUnique(
2426 nsCOMPtr<nsIFile> pUniqueFile;
2427 nsAutoString leafName;
2428 nsAutoString uniqueLeafName;
2429 PRInt32 extOffset = -1;
2430 nsAutoString uniqueStr;
2431 PRInt32 uniqueNum = 1;
2433 nsresult result =
NS_OK;
2436 result = apFile->Exists(&exists);
2437 if (NS_FAILED(result) || !exists)
2441 if (NS_SUCCEEDED(result))
2442 result = apFile->Clone(getter_AddRefs(pUniqueFile));
2445 if (NS_SUCCEEDED(result))
2446 result = pUniqueFile->GetLeafName(leafName);
2447 if (NS_SUCCEEDED(result))
2448 extOffset = leafName.RFindChar(
'.');
2451 while (NS_SUCCEEDED(result) && exists)
2454 uniqueStr.AssignLiteral(
"_");
2455 uniqueStr.AppendInt(uniqueNum++);
2456 uniqueStr.AppendLiteral(
"_");
2459 uniqueLeafName.Assign(leafName);
2460 if (extOffset == -1)
2461 uniqueLeafName.Append(uniqueStr);
2463 uniqueLeafName.Insert(uniqueStr, extOffset);
2466 result = pUniqueFile->SetLeafName(uniqueLeafName);
2467 if (NS_SUCCEEDED(result))
2468 result = pUniqueFile->Exists(&exists);
2471 if (exists && (uniqueNum > 1000))
2472 result = NS_ERROR_FILE_TOO_BIG;
2476 if (NS_SUCCEEDED(result))
2477 result = apFile->SetLeafName(uniqueLeafName);
2492 nsresult sbDownloadDevice::OpenDialog(
2494 nsIDialogParamBlock *apDialogPB)
2496 nsCOMPtr<nsIWindowWatcher> pWindowWatcher;
2497 nsCOMPtr<nsIDOMWindow> pActiveWindow;
2498 nsCOMPtr<nsIDOMWindow> pWindow;
2499 nsCOMPtr<sbIDataRemote> pDataRemote;
2500 nsCAutoString chromeFeatures;
2501 PRBool accessibilityEnabled;
2502 nsresult result =
NS_OK;
2505 pWindowWatcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &result);
2508 if (NS_SUCCEEDED(result))
2509 result = pWindowWatcher->GetActiveWindow(getter_AddRefs(pActiveWindow));
2512 if (NS_SUCCEEDED(result))
2514 pDataRemote = do_CreateInstance
2515 (
"@songbirdnest.com/Songbird/DataRemote;1",
2518 if (NS_SUCCEEDED(result))
2520 result = pDataRemote->Init(NS_LITERAL_STRING(
"accessibility.enabled"),
2523 if (NS_SUCCEEDED(result))
2524 result = pDataRemote->GetBoolValue(&accessibilityEnabled);
2527 if (NS_SUCCEEDED(result))
2529 chromeFeatures = NS_LITERAL_CSTRING
2530 (
"chrome,centerscreen,modal=yes,resizable=no");
2531 if (accessibilityEnabled)
2532 chromeFeatures.AppendLiteral(
",titlebar=yes");
2534 chromeFeatures.AppendLiteral(
",titlebar=no");
2538 if (NS_SUCCEEDED(result))
2540 pWindowWatcher->OpenWindow(pActiveWindow,
2543 chromeFeatures.get(),
2545 getter_AddRefs(pWindow));
2552 nsresult sbDownloadDevice::GetStatusTarget(
2556 NS_ASSERTION(apMediaItem,
"apMediaItem is null");
2557 NS_ASSERTION(apStatusTarget,
"apStatusTaret is null");
2563 NS_ENSURE_SUCCESS(rv, rv);
2564 PRInt32
pos = target.FindChar(
',');
2566 nsDependentSubstring mediaItemGuid(target, pos + 1);
2568 nsString originalItemGuid;
2569 rv = apMediaItem->GetGuid(originalItemGuid);
2570 NS_ENSURE_SUCCESS(rv, rv);
2572 if (originalItemGuid.Equals(mediaItemGuid)) {
2573 *apStatusTarget = nsnull;
2578 do_GetService(
"@songbirdnest.com/Songbird/library/Manager;1", &rv);
2579 NS_ENSURE_SUCCESS(rv, rv);
2581 nsDependentSubstring libraryGuid(target, 0, pos);
2582 nsCOMPtr<sbILibrary> library;
2583 rv = libraryManager->GetLibrary(libraryGuid, getter_AddRefs(library));
2584 if (rv != NS_ERROR_NOT_AVAILABLE) {
2585 NS_ENSURE_SUCCESS(rv, rv);
2586 rv = library->GetItemByGuid(mediaItemGuid, apStatusTarget);
2587 if (rv != NS_ERROR_NOT_AVAILABLE) {
2588 NS_ENSURE_SUCCESS(rv, rv);
2591 NS_WARNING(
"Status target media item not found");
2592 *apStatusTarget = nsnull;
2596 NS_WARNING(
"Status target library not found");
2597 *apStatusTarget = nsnull;
2619 #include <nsIChannel.h>
2639 mpMediaItem(pMediaItem),
2640 mpSessionLock(nsnull),
2641 mpDownloadDevice(pDownloadDevice),
2642 mShutdown(PR_FALSE),
2643 mSuspended(PR_FALSE),
2644 mInitialProgressBytes(0),
2645 mLastProgressBytes(0)
2647 TRACE((
"sbDownloadSession[0x%.8x] - ctor",
this));
2664 nsAutoLock::DestroyLock(mpSessionLock);
2666 TRACE((
"sbDownloadSession[0x%.8x] - dtor",
this));
2677 TRACE((
"sbDownloadSession[0x%.8x] - Initiate",
this));
2678 nsCOMPtr<sbILibraryManager> pLibraryManager;
2679 nsCOMPtr<nsIURI> pDstURI;
2682 nsCOMPtr<nsILocalFile> pDstFile;
2684 nsCOMPtr<nsIURI> pURI;
2685 nsCOMPtr<nsIStandardURL> pStandardURL;
2690 do_GetService(
"@songbirdnest.com/Songbird/library/Manager;1", &rv);
2691 NS_ENSURE_SUCCESS(rv, rv);
2693 pLibraryManager = do_GetService
2694 (
"@songbirdnest.com/Songbird/library/Manager;1",
2696 NS_ENSURE_SUCCESS(rv, rv);
2699 nsCOMPtr<nsIStringBundleService>
2700 pStringBundleService;
2703 pStringBundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID,
2705 NS_ENSURE_SUCCESS(rv, rv);
2707 rv = pStringBundleService->CreateBundle
2709 getter_AddRefs(mpStringBundle));
2710 NS_ENSURE_SUCCESS(rv, rv);
2713 rv = mpStringBundle->GetStringFromName
2714 (NS_LITERAL_STRING(
"device.download.complete").
get(),
2715 getter_Copies(mCompleteStr));
2716 NS_ENSURE_SUCCESS(rv, rv);
2718 rv = mpStringBundle->GetStringFromName
2719 (NS_LITERAL_STRING(
"device.download.error").
get(),
2720 getter_Copies(mErrorStr));
2721 NS_ENSURE_SUCCESS(rv, rv);
2724 mpSessionLock = nsAutoLock::NewLock(
"sbDownloadSession::mpSessionLock");
2726 return NS_ERROR_OUT_OF_MEMORY;
2729 rv = mpDownloadDevice->GetTmpFile(getter_AddRefs(mpTmpFile));
2730 NS_ENSURE_SUCCESS(rv, rv);
2736 nsAutoString currentOriginURL;
2739 if (currentOriginURL.IsEmpty()) {
2740 nsCOMPtr<nsIURI> pSrcURI;
2742 rv =
mpMediaItem->GetContentSrc(getter_AddRefs(pSrcURI));
2743 NS_ENSURE_SUCCESS(rv, rv);
2745 rv = pSrcURI->GetSpec(srcSpec);
2746 NS_ENSURE_SUCCESS(rv, rv);
2754 NS_WARNING(
"Failed to set originURL, this item may be duplicated later \
2755 because its origin cannot be tracked!");
2761 rv = sbDownloadDevice::GetStatusTarget(
mpMediaItem,
2762 getter_AddRefs(mpStatusTarget));
2763 NS_ENSURE_SUCCESS(rv, rv);
2769 if (NS_SUCCEEDED(rv) && dstSpec.IsEmpty())
2770 rv = NS_ERROR_FAILURE;
2771 NS_ENSURE_SUCCESS(rv, rv);
2773 rv = NS_NewURI(getter_AddRefs(mpDstURI), dstSpec);
2774 NS_ENSURE_SUCCESS(rv, rv);
2778 nsCOMPtr<nsIFileURL> pFileURL;
2779 nsCOMPtr<nsIFile> pFile;
2780 pFileURL = do_QueryInterface(mpDstURI, &rv);
2781 NS_ENSURE_SUCCESS(rv, rv);
2782 rv = pFileURL->GetFile(getter_AddRefs(pFile));
2783 NS_ENSURE_SUCCESS(rv, rv);
2784 pDstFile = do_QueryInterface(pFile, &rv);
2785 NS_ENSURE_SUCCESS(rv, rv);
2789 rv = pDstFile->Clone(getter_AddRefs(mpDstFile));
2790 NS_ENSURE_SUCCESS(rv, rv);
2793 rv = pLibraryManager->GetMainLibrary(getter_AddRefs(mpDstLibrary));
2794 NS_ENSURE_SUCCESS(rv, rv);
2797 rv =
mpMediaItem->GetContentSrc(getter_AddRefs(mpSrcURI));
2798 NS_ENSURE_SUCCESS(rv, rv);
2801 rv = SetUpRequest();
2802 NS_ENSURE_SUCCESS(rv, rv);
2805 mIdleTimer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
2806 NS_ENSURE_SUCCESS(rv, rv);
2809 mProgressTimer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
2810 NS_ENSURE_SUCCESS(rv, rv);
2821 nsresult sbDownloadSession::SetUpRequest()
2826 mpWebBrowser = do_CreateInstance
2827 (
"@mozilla.org/embedding/browser/nsWebBrowserPersist;1",
2829 NS_ENSURE_SUCCESS(rv, rv);
2832 nsCOMPtr<nsIInterfaceRequestor> ir(do_QueryInterface(mpWebBrowser));
2833 rv = NS_NewChannel(getter_AddRefs(mpRequest), mpSrcURI, nsnull, nsnull, ir);
2834 NS_ENSURE_SUCCESS(rv, rv);
2836 if (!mEntityID.IsEmpty())
2839 nsCOMPtr<nsIFile> clone;
2840 if (NS_FAILED(mpTmpFile->Clone(getter_AddRefs(clone))) ||
2841 NS_FAILED(clone->GetFileSize(&mInitialProgressBytes)))
2843 NS_WARNING(
"Restarting download instead of resuming: failed \
2844 determining how much is already downloaded!");
2845 mInitialProgressBytes = 0;
2848 if (mInitialProgressBytes)
2850 nsCOMPtr<nsIResumableChannel> resumableChannel(do_QueryInterface(mpRequest));
2851 if (resumableChannel &&
2852 NS_SUCCEEDED(resumableChannel->ResumeAt(mInitialProgressBytes, mEntityID)))
2855 rv = mpWebBrowser->SetPersistFlags(nsIWebBrowserPersist::PERSIST_FLAGS_APPEND_TO_FILE);
2856 NS_ENSURE_SUCCESS(rv, rv);
2860 NS_WARNING(
"Restarting download instead of resuming: \
2861 nsIResumableChannel.ResumeAt failed");
2862 mInitialProgressBytes = 0;
2868 mLastUpdate = PR_Now();
2869 rv = mpWebBrowser->SetProgressListener(
this);
2870 NS_ENSURE_SUCCESS(rv, rv);
2873 rv = mpWebBrowser->SaveChannel(mpRequest, mpTmpFile);
2876 NS_WARNING(
"Failed initiating download");
2877 mpWebBrowser->SetProgressListener(nsnull);
2890 TRACE((
"sbDownloadSession[0x%.8x] - Suspend",
this));
2891 NS_ENSURE_STATE(!mShutdown);
2896 nsAutoLock lock(mpSessionLock);
2903 mEntityID.Truncate();
2904 nsCOMPtr<nsIResumableChannel> resumable(do_QueryInterface(mpRequest));
2906 resumable->GetEntityID(mEntityID);
2908 if (!mEntityID.IsEmpty())
2912 NS_ENSURE_SUCCESS(rv, rv);
2915 mpWebBrowser->SetProgressListener(nsnull);
2916 mpWebBrowser = nsnull;
2921 rv = mpRequest->Suspend();
2922 NS_ENSURE_SUCCESS(rv, rv);
2932 mSuspended = PR_TRUE;
2946 TRACE((
"sbDownloadSession[0x%.8x] - Resume",
this));
2947 NS_ENSURE_STATE(!mShutdown);
2952 nsAutoLock lock(mpSessionLock);
2959 if (!mEntityID.IsEmpty())
2961 rv = SetUpRequest();
2962 NS_ENSURE_SUCCESS(rv, rv);
2966 rv = mpRequest->Resume();
2967 NS_ENSURE_SUCCESS(rv, rv);
2977 mSuspended = PR_FALSE;
2991 TRACE((
"sbDownloadSession[0x%.8x] - Shutdown",
this));
2999 if (!mpSessionLock) {
3004 nsAutoLock lock(mpSessionLock);
3011 nsRefPtr<sbDownloadSession> kungFuDeathGrip(
this);
3014 mShutdown = PR_TRUE;
3019 mpWebBrowser->CancelSave();
3020 mpWebBrowser->SetProgressListener(nsnull);
3021 mpWebBrowser = nsnull;
3039 nsAutoLock lock(mpSessionLock);
3052 nsIWebProgressListener,
3085 nsIWebProgress *aWebProgress,
3086 nsIRequest *aRequest,
3087 PRUint32 aStateFlags,
3090 TRACE((
"sbDownloadSession[0x%.8x] - OnStateChange "
3091 "aWebProgress 0x%.8x aRequest 0x%.8x "
3092 "aStateFlags 0x%.8x aStatus 0x%.8x",
3093 this, aWebProgress, aRequest, aStateFlags, aStatus));
3095 PRBool complete = PR_FALSE;
3096 nsresult status = aStatus;
3097 nsresult result =
NS_OK;
3101 nsRefPtr<sbDownloadSession> kungFuDeathGrip(
this);
3106 nsAutoLock lock(mpSessionLock);
3108 if (aStateFlags & STATE_START) {
3111 }
else if (aStateFlags & STATE_STOP) {
3117 if (!(aStateFlags & STATE_STOP) || mShutdown)
3127 if (NS_SUCCEEDED(status))
3129 nsCOMPtr<nsIHttpChannel> pHttpChannel;
3130 PRBool requestSucceeded;
3133 pHttpChannel = do_QueryInterface(aRequest, &result);
3136 if (NS_SUCCEEDED(result))
3137 result = pHttpChannel->GetRequestSucceeded(&requestSucceeded);
3138 if (NS_SUCCEEDED(result) && !requestSucceeded)
3139 status = NS_ERROR_UNEXPECTED;
3146 if (NS_SUCCEEDED(result) && NS_SUCCEEDED(status))
3148 result = CompleteTransfer(aRequest);
3149 if (NS_SUCCEEDED(result))
3166 nsAutoString statusStr;
3168 statusStr.Assign(mCompleteStr);
3170 statusStr.Assign(mErrorStr);
3171 mpMediaItem->SetProperty
3176 mpStatusTarget->SetProperty
3184 mpDownloadDevice->SessionCompleted(
this, status);
3189 nsAutoLock lock(mpSessionLock);
3195 mpWebBrowser->CancelSave();
3196 mpWebBrowser->SetProgressListener(nsnull);
3198 mpWebBrowser = nsnull;
3199 mpMediaItem = nsnull;
3234 NS_IMETHODIMP sbDownloadSession::OnProgressChange(
3235 nsIWebProgress *aWebProgress,
3236 nsIRequest *aRequest,
3237 PRInt32 aCurSelfProgress,
3238 PRInt32 aMaxSelfProgress,
3239 PRInt32 aCurTotalProgress,
3240 PRInt32 aMaxTotalProgress)
3242 TRACE((
"sbDownloadSession[0x%.8x] - OnProgressChange "
3243 "aWebProgress 0x%.8x aRequest 0x%.8x "
3244 "aCurSelfProgress %d aMaxSelfProgress %d "
3245 "aCurTotalProgress %d aMaxTotalProgress %d",
3246 this, aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress,
3247 aCurTotalProgress, aMaxTotalProgress));
3253 UpdateProgress(aCurSelfProgress, aMaxSelfProgress);
3275 NS_IMETHODIMP sbDownloadSession::OnLocationChange(
3276 nsIWebProgress *aWebProgress,
3277 nsIRequest *aRequest,
3280 TRACE((
"sbDownloadSession[0x%.8x] - OnLocationChange "
3281 "aWebProgress 0x%.8x aRequest 0x%.8x aLocation 0x%.8x",
3282 this, aWebProgress, aRequest, aLocation));
3306 NS_IMETHODIMP sbDownloadSession::OnStatusChange(
3307 nsIWebProgress *aWebProgress,
3308 nsIRequest *aRequest,
3310 const PRUnichar *aMessage)
3312 TRACE((
"sbDownloadSession[0x%.8x] - OnStatusChange "
3313 "aWebProgress 0x%.8x aRequest 0x%.8x aStatus 0x%.8x aMessage '%s'",
3314 this, aWebProgress, aRequest, aStatus, aMessage));
3339 NS_IMETHODIMP sbDownloadSession::OnSecurityChange(
3340 nsIWebProgress *aWebProgress,
3341 nsIRequest *aRequest,
3344 TRACE((
"sbDownloadSession[0x%.8x] - OnSecurityChange "
3345 "aWebProgress 0x%.8x aRequest 0x%.8x aState 0x%.8x",
3346 this, aWebProgress, aRequest, aState));
3357 NS_IMETHODIMP sbDownloadSession::Notify(nsITimer* aTimer)
3359 if (aTimer == mIdleTimer) {
3364 }
else if (aTimer == mProgressTimer) {
3365 UpdateProgress(mLastProgressBytes, mLastProgressBytesMax);
3383 nsresult sbDownloadSession::CompleteTransfer(nsIRequest* aRequest)
3385 nsCOMPtr<nsIFile> pFileDir;
3388 nsCOMPtr<nsIURI> pSrcURI;
3389 nsCOMPtr<sbIMediaList> pDstMediaList;
3390 nsresult result =
NS_OK;
3391 PRBool bIsDirectory;
3392 PRBool bChangedDstFile = PR_FALSE;
3395 nsCString mimeFilename;
3396 nsCOMPtr<nsIHttpChannel> httpChannel =
3397 do_QueryInterface(aRequest, &result);
3398 if (NS_SUCCEEDED(result)) {
3399 nsCAutoString contentDisposition;
3400 result = httpChannel->GetResponseHeader(
3401 NS_LITERAL_CSTRING(
"content-disposition"),
3402 contentDisposition);
3403 if (NS_SUCCEEDED(result)) {
3410 result = mpDstFile->IsDirectory(&bIsDirectory);
3411 if (result == NS_ERROR_FILE_NOT_FOUND || result == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)
3413 bIsDirectory = PR_FALSE;
3416 NS_ENSURE_SUCCESS(result, result);
3424 nsCString escFileName(mimeFilename);
3425 if (escFileName.IsEmpty()) {
3427 nsCOMPtr<nsIURI> pFinalSrcURI;
3429 nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest, &result);
3430 NS_ENSURE_SUCCESS(result, result);
3432 result = channel->GetURI(getter_AddRefs(pFinalSrcURI));
3433 NS_ENSURE_SUCCESS(result, result);
3436 nsCOMPtr<nsIURL> pFinalSrcURL = do_QueryInterface(pFinalSrcURI, &result);
3437 NS_ENSURE_SUCCESS(result, result);
3439 result = pFinalSrcURL->GetFileName(escFileName);
3440 NS_ENSURE_SUCCESS(result, result);
3444 nsCOMPtr<nsINetUtil> netUtil;
3445 netUtil = do_GetService(
"@mozilla.org/network/util;1", &result);
3446 NS_ENSURE_SUCCESS(result, result);
3447 nsCString leafCName;
3448 result = netUtil->UnescapeString(escFileName,
3449 nsINetUtil::ESCAPE_URL_SKIP_CONTROL,
3451 NS_ENSURE_SUCCESS(result, result);
3454 nsString leafName = NS_ConvertUTF8toUTF16(leafCName);
3455 if (leafName.IsEmpty()) {
3457 leafName.Assign(NS_ConvertUTF8toUTF16(escFileName));
3458 if (leafName.IsEmpty()) {
3460 leafName.AssignLiteral(
"unnamed");
3465 nsString illegalChars(NS_ConvertASCIItoUTF16(FILE_ILLEGAL_CHARACTERS));
3466 illegalChars.AppendLiteral(FILE_PATH_SEPARATOR);
3470 result = mpDstFile->Append(leafName);
3471 NS_ENSURE_SUCCESS(result, result);
3474 result = sbDownloadDevice::MakeFileUnique(mpDstFile);
3475 NS_ENSURE_SUCCESS(result, result);
3477 bChangedDstFile = PR_TRUE;
3482 result = mpDstFile->GetLeafName(fileName);
3483 NS_ENSURE_SUCCESS(result, result);
3484 if (fileName.RFindChar(
'.') == -1) {
3485 PRInt32 extension = mimeFilename.RFindChar(
'.');
3486 if (extension != -1) {
3488 NS_ConvertUTF8toUTF16(Substring(mimeFilename, extension)));
3489 result = mpDstFile->SetLeafName(fileName);
3490 NS_ENSURE_SUCCESS(result, result);
3492 bChangedDstFile = PR_TRUE;
3496 if (bChangedDstFile) {
3498 nsCOMPtr<nsIURI> pDstURI;
3499 result = mpLibraryUtils->GetFileContentURI(mpDstFile,
3500 getter_AddRefs(mpDstURI));
3501 NS_ENSURE_SUCCESS(result, result);
3504 result = mpDstURI->GetSpec(dstCSpec);
3505 NS_ENSURE_SUCCESS(result, result);
3512 NS_ENSURE_SUCCESS(result, result);
3516 if (NS_SUCCEEDED(result))
3517 result =
mpMediaItem->GetContentSrc(getter_AddRefs(pSrcURI));
3518 if (NS_SUCCEEDED(result))
3519 result = pSrcURI->GetSpec(srcSpec);
3522 if (NS_SUCCEEDED(result)) {
3527 if (NS_SUCCEEDED(result))
3528 pDstMediaList = do_QueryInterface(mpDstLibrary, &result);
3529 if (NS_SUCCEEDED(result))
3533 if (NS_SUCCEEDED(result))
3534 result = mpDstFile->GetParent(getter_AddRefs(pFileDir));
3535 if (NS_SUCCEEDED(result)) {
3536 nsRefPtr<sbDownloadSessionMoveHandler> moveHandler;
3541 NS_ENSURE_TRUE(moveHandler, NS_ERROR_OUT_OF_MEMORY);
3543 result = mpDownloadDevice->mFileMoveThreadPool->Dispatch(moveHandler,
3544 nsIEventTarget::DISPATCH_NORMAL);
3548 if (NS_SUCCEEDED(result))
3550 nsRefPtr<WebLibraryUpdater> pWebLibraryUpdater;
3551 nsCOMPtr<sbIMediaList> pWebMediaList;
3554 if (NS_SUCCEEDED(result))
3556 pWebMediaList = do_QueryInterface(mpDownloadDevice->mpWebLibrary,
3561 if (NS_SUCCEEDED(result))
3563 pWebLibraryUpdater =
new WebLibraryUpdater(
this);
3564 if (!pWebLibraryUpdater)
3565 result = NS_ERROR_OUT_OF_MEMORY;
3567 if (NS_SUCCEEDED(result))
3569 result = pWebMediaList->EnumerateItemsByProperty
3571 NS_ConvertUTF8toUTF16(srcSpec),
3592 nsresult sbDownloadSession::UpdateDstLibraryMetadata()
3594 nsCOMPtr<sbIMediaList> pDstMediaList;
3596 nsRefPtr<LibraryMetadataUpdater>
3597 pLibraryMetadataUpdater;
3598 nsString durationStr;
3600 PRBool updateDstLibraryMetadata = PR_TRUE;
3602 nsresult result =
NS_OK;
3607 if (NS_SUCCEEDED(result1) && durationStr.IsEmpty())
3608 result = NS_ERROR_FAILURE;
3610 if (NS_SUCCEEDED(result1))
3611 duration = durationStr.ToInteger(&result1);
3613 if (NS_SUCCEEDED(result1) && (duration > 0))
3614 updateDstLibraryMetadata = PR_FALSE;
3617 if (updateDstLibraryMetadata)
3620 result = mpDstURI->GetSpec(dstSpec);
3623 if (NS_SUCCEEDED(result))
3625 pLibraryMetadataUpdater =
new LibraryMetadataUpdater();
3626 if (!pLibraryMetadataUpdater)
3627 result = NS_ERROR_OUT_OF_MEMORY;
3631 if (NS_SUCCEEDED(result))
3632 pDstMediaList = do_QueryInterface(mpDstLibrary, &result);
3633 if (NS_SUCCEEDED(result))
3635 result = pDstMediaList->EnumerateItemsByProperty
3637 NS_ConvertUTF8toUTF16(dstSpec),
3638 pLibraryMetadataUpdater,
3657 void sbDownloadSession::UpdateProgress(
3659 PRUint64 aProgressMax)
3662 aProgress += mInitialProgressBytes;
3663 aProgressMax += mInitialProgressBytes;
3668 property.value->SetCurrent(aProgress);
3669 property.value->SetTotal(aProgressMax);
3672 UpdateDownloadDetails(aProgress, aProgressMax);
3686 void sbDownloadSession::UpdateDownloadDetails(
3688 PRUint64 aProgressMax)
3690 nsAutoString progressStr;
3692 PRUint64 elapsedUSecs;
3693 PRUint32 remainingSecs;
3698 elapsedUSecs = now - mLastUpdate;
3703 * PR_USEC_PER_MSEC)))
3709 UpdateDownloadRate(aProgress, elapsedUSecs);
3714 remainingSecs = (PRUint32)
3715 ((
double(aProgressMax) -
double(aProgress)) / mRate + 0.5);
3723 rv = FormatProgress(progressStr,
3729 progressStr.AssignLiteral(
"???");
3736 mpStatusTarget->SetProperty
3743 mLastProgressBytes = aProgress;
3744 mLastProgressBytesMax = aProgressMax;
3760 void sbDownloadSession::UpdateDownloadRate(
3762 PRUint64 aElapsedUSecs)
3765 PRUint64 dlByteCount;
3770 elapsedSecs = double(aElapsedUSecs) / PR_USEC_PER_SEC;
3771 if (elapsedSecs <= 0.0)
3775 dlByteCount = aProgress - mLastProgressBytes;
3776 rate = double(dlByteCount) / elapsedSecs;
3779 if (mLastProgressBytes)
3780 mRate = 0.9 * mRate + 0.1 * rate;
3799 nsresult sbDownloadSession::FormatProgress(
3800 nsString &aProgressStr,
3802 PRUint64 aProgressMax,
3804 PRUint32 aRemSeconds)
3806 nsAutoString byteProgressStr;
3807 nsAutoString rateStr;
3808 nsAutoString timeStr;
3809 const PRUnichar *stringList[3];
3813 rv = FormatByteProgress(byteProgressStr, aProgress, aProgressMax);
3814 NS_ENSURE_SUCCESS(rv, rv);
3815 stringList[0] = byteProgressStr.get();
3818 rv = FormatRate(rateStr, aRate);
3819 NS_ENSURE_SUCCESS(rv, rv);
3820 stringList[1] = rateStr.get();
3823 rv = FormatTime(timeStr, aRemSeconds);
3824 NS_ENSURE_SUCCESS(rv, rv);
3825 stringList[2] = timeStr.get();
3828 rv = mpStringBundle->FormatStringFromName
3829 (NS_LITERAL_STRING(
"device.download.statusFormat").
get(),
3832 getter_Copies(aProgressStr));
3833 NS_ENSURE_SUCCESS(rv, rv);
3849 nsresult sbDownloadSession::FormatRate(
3856 PR_snprintf(rateStr,
sizeof(rateStr),
"%.1f", aRate / 1024.0 + 0.05);
3857 aRateStr.AssignLiteral(rateStr);
3874 nsresult sbDownloadSession::FormatByteProgress(
3875 nsString &aByteProgressStr,
3885 char bytesValStr[32];
3886 char bytesMaxValStr[32];
3887 nsAutoString bytesValNSStr;
3888 nsAutoString bytesMaxValNSStr;
3889 nsAutoString stringName;
3890 const PRUnichar *stringList[2];
3894 bytesKB = double(aBytes) / 1024.0;
3895 bytesMB = bytesKB / 1024.0;
3898 bytesMaxKB = double(aBytesMax) / 1024.0;
3899 bytesMaxMB = bytesMaxKB / 1024.0;
3904 stringName.AssignLiteral(
"device.download.statusFormatMBMB");
3906 bytesMaxVal = bytesMaxMB;
3908 else if (bytesMaxMB >= 1.0)
3910 stringName.AssignLiteral(
"device.download.statusFormatKBMB");
3912 bytesMaxVal = bytesMaxMB;
3916 stringName.AssignLiteral(
"device.download.statusFormatKBKB");
3918 bytesMaxVal = bytesMaxKB;
3922 PR_snprintf(bytesValStr,
sizeof(bytesValStr),
"%.1f", bytesVal);
3923 bytesValNSStr.AssignLiteral(bytesValStr);
3924 stringList[0] = bytesValNSStr.get();
3927 PR_snprintf(bytesMaxValStr,
sizeof(bytesMaxValStr),
"%.1f", bytesMaxVal);
3928 bytesMaxValNSStr.AssignLiteral(bytesMaxValStr);
3929 stringList[1] = bytesMaxValNSStr.get();
3932 rv = mpStringBundle->FormatStringFromName(stringName.get(),
3935 getter_Copies(aByteProgressStr));
3936 NS_ENSURE_SUCCESS(rv, rv);
3952 nsresult sbDownloadSession::FormatTime(
3956 nsAutoString stringName;
3960 nsAutoString hoursStr,
3963 const PRUnichar *stringList[3];
3970 hours = aSeconds / 3600;
3971 hoursStr.AppendInt(hours);
3972 seconds -= hours * 3600;
3975 minutes = aSeconds / 60;
3976 if (hours && minutes < 10)
3977 minutesStr.AssignLiteral(
"0");
3978 minutesStr.AppendInt(minutes);
3979 seconds -= minutes * 60;
3983 secondsStr.AssignLiteral(
"0");
3984 secondsStr.AppendInt(seconds);
3989 stringName.AssignLiteral(
"device.download.longTimeFormat");
3990 stringList[0] = hoursStr.get();
3991 stringList[1] = minutesStr.get();
3992 stringList[2] = secondsStr.get();
3996 stringName.AssignLiteral(
"device.download.shortTimeFormat");
3997 stringList[0] = minutesStr.get();
3998 stringList[1] = secondsStr.get();
4002 rv = mpStringBundle->FormatStringFromName(stringName.get(),
4005 getter_Copies(aTimeStr));
4006 NS_ENSURE_SUCCESS(rv, rv);
4015 nsresult sbDownloadSession::StartTimers()
4017 mProgressTimer->Cancel();
4019 nsITimer::TYPE_REPEATING_SLACK);
4021 mIdleTimer->Cancel();
4023 nsITimer::TYPE_ONE_SHOT);
4032 nsresult sbDownloadSession::StopTimers()
4034 if(mProgressTimer) {
4035 mProgressTimer->Cancel();
4039 mIdleTimer->Cancel();
4049 nsresult sbDownloadSession::ResetTimers()
4051 mProgressTimer->Cancel();
4053 nsITimer::TYPE_REPEATING_SLACK);
4055 mIdleTimer->Cancel();
4057 nsITimer::TYPE_ONE_SHOT);
4089 nsresult result =
NS_OK;
4092 NS_ENSURE_ARG_POINTER(_retval);
4095 mpMediaItemArray = do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &result);
4098 if (NS_SUCCEEDED(result))
4116 NS_IMETHODIMP sbDownloadSession::LibraryMetadataUpdater::OnEnumeratedItem(
4121 nsresult result =
NS_OK;
4124 NS_ENSURE_ARG_POINTER(_retval);
4127 result = mpMediaItemArray->AppendElement(aMediaItem, PR_FALSE);
4143 NS_IMETHODIMP sbDownloadSession::LibraryMetadataUpdater::OnEnumerationEnd(
4145 nsresult aStatusCode)
4147 nsCOMPtr<sbIFileMetadataService>
4149 nsCOMPtr<sbIJobProgress> pMetadataJob;
4150 nsresult result =
NS_OK;
4153 pMetadataService = do_GetService
4154 (
"@songbirdnest.com/Songbird/FileMetadataService;1",
4156 if (NS_SUCCEEDED(result))
4158 result = pMetadataService->Read(mpMediaItemArray,
4159 getter_AddRefs(pMetadataJob));
4192 nsresult result =
NS_OK;
4210 NS_IMETHODIMP sbDownloadSession::WebLibraryUpdater::OnEnumeratedItem(
4215 nsresult result =
NS_OK;
4218 aMediaItem->SetContentSrc(mpDownloadSession->mpDstURI);
4234 NS_IMETHODIMP sbDownloadSession::WebLibraryUpdater::OnEnumerationEnd(
4236 nsresult aStatusCode)
4238 nsresult result =
NS_OK;
4247 mMediaItem(aMediaItem),
4248 mStatusTarget(aStatusTarget),
4249 mReadOnly(aReadOnly)
4251 NS_ASSERTION(mMediaItem,
"mMediaItem is null");
4255 nsString propertyValue;
4259 NS_ASSERTION(
value,
"value is null");
4264 if (!mReadOnly &&
value) {
4265 nsString propertyValue;
4266 value->GetValue(propertyValue);
4271 NS_ASSERTION(NS_SUCCEEDED(rv),
"SetProperty failed");
4273 if (mStatusTarget) {
4276 NS_ASSERTION(NS_SUCCEEDED(rv),
"SetProperty failed");
4287 nsresult rv = NS_ERROR_UNEXPECTED;
4289 rv = mSourceFile->MoveTo(mDestinationPath, mDestinationFileName);
4290 NS_ENSURE_SUCCESS(rv, rv);
4292 nsCOMPtr<sbIFileMetadataService> metadataService;
4293 nsCOMPtr<sbIJobProgress> metadataJob;
4296 nsCOMPtr<nsIMutableArray> itemArray =
4297 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
4300 NS_ENSURE_SUCCESS(rv, rv);
4304 do_GetService(
"@songbirdnest.com/Songbird/FileMetadataService;1", &rv);
4305 NS_ENSURE_SUCCESS(rv, rv);
4307 return metadataService->Read(itemArray,
4308 getter_AddRefs(metadataJob));
nsresult RemoveItemFromTransferQueue(const nsAString &aDeviceIdentifier, sbIMediaItem *aMediaItem)
Remove an item from the internal transfer queue.
const unsigned long OP_UPLOAD
Device Operation Constants.
void ReplaceChars(nsAString &aOldString, const nsAString &aOldChars, const PRUnichar aNewChar)
nsCOMPtr< sbIMediaItem > mpMediaItem
NS_IMPL_ISUPPORTS4(sbDownloadDevice, nsIObserver, sbIDeviceBase, sbIDownloadDevice, sbIMediaListListener) sbDownloadDevice
#define SB_DOWNLOAD_DEVICE_CATEGORY
friend class sbDownloadSession
nsresult SetDeviceState(const nsAString &aDeviceIdentifier, PRUint32 aDeviceState)
#define SB_PROPERTY_ORIGINURL
static PRStatus decode2to1(const unsigned char *src, unsigned char *dest)
const NS_PREFSERVICE_CONTRACTID
nsresult GetDeviceState(const nsAString &aDeviceIdentifier, PRUint32 *aDeviceState)
#define SB_DOWNLOAD_DEVICE_ID
NS_IMPL_THREADSAFE_ISUPPORTS2(sbDownloadSession, nsIWebProgressListener, nsITimerCallback) NS_IMETHODIMP sbDownloadSession
#define SB_DOWNLOAD_CUSTOM_TYPE
#define SB_STRING_BUNDLE_CHROME_URL
nsresult GetLibraryForDevice(const nsAString &aDeviceIdentifier, sbILibrary **aDeviceLibrary)
Get the library instance for a device.
#define SB_PROPERTY_ISSORTABLE
[SOON TO BE DEPRECATED AFTER 0.3] The callback class for sbIDeviceBase
static PRStatus decode(const unsigned char *src, PRUint32 srclen, unsigned char *dest)
nsresult CreateTransferQueue(const nsAString &aDeviceIdentifier)
Create an internal transfer queue for a device instance.
#define SB_DOWNLOAD_PROGRESS_TIMER_MS
#define SB_DOWNLOAD_COL_SPEC
#define SB_DOWNLOAD_LIST_NAME
[SOON TO BE DEPRECATED AFTER 0.3] Base interface for all supported devices.
#define SB_DOWNLOAD_TMP_DIR
nsresult InitDeviceState(const nsAString &aDeviceIdentifier)
readonly attribute unsigned long completedItemCount
The number of completed download items.
static PRStatus decode4to3(const unsigned char *src, unsigned char *dest)
nsresult RemoveTransferQueue(const nsAString &aDeviceIdentifier)
Remove an internal transfer queue for a device instance.
virtual ~sbDownloadDevice()
const PRUint32 STATE_IDLE
#define SB_PROPERTY_DESTINATION
nsresult AddCallback(sbIDeviceBaseCallback *aCallback)
#define SB_PROPERTY_DURATION
nsresult SetListenerForDeviceLibrary(const nsAString &aDeviceIdentifier, sbIMediaListListener *aMediaListListener)
#define SB_PROPERTY_DEFAULTCOLUMNSPEC
nsresult AddItemToTransferQueue(const nsAString &aDeviceIdentifier, sbIMediaItem *aMediaItem)
Add an item to the internal transfer queue.
NS_IMPL_THREADSAFE_ISUPPORTS1(sbDownloadSessionMoveHandler, nsIRunnable) NS_IMETHODIMP sbDownloadSessionMoveHandler
nsresult GetNextItemFromTransferQueue(const nsAString &aDeviceIdentifier, sbIMediaItem **aMediaItem)
Get the next item in the transfer queue.
static PRStatus decode3to2(const unsigned char *src, unsigned char *dest)
Media library abstraction.
nsresult Init()
Initialize the base device class for use.
static PRInt32 codetovalue(unsigned char c)
#define SB_PROPERTY_DOWNLOADBUTTON
#define SB_PREF_WEB_LIBRARY
#define SB_DOWNLOAD_IDLE_TIMEOUT_MS
nsresult RemoveCallback(sbIDeviceBaseCallback *aCallback)
void DoTransferStartCallback(sbIMediaItem *aMediaItem)
const PRUint32 STATE_DOWNLOADING
char * SB_Base64Decode(const char *src, PRUint32 srclen, char *dest)
NS_DECL_ISUPPORTS NS_DECL_NSIWEBPROGRESSLISTENER NS_DECL_NSITIMERCALLBACK sbDownloadSession(sbDownloadDevice *pDownloadDevice, sbIMediaItem *pMediaItem)
Songbird DownloadDevice Interface.
#define SB_PROPERTY_DOWNLOAD_STATUS_TARGET
const PRUint32 STATE_DOWNLOAD_PAUSED
virtual ~sbDownloadSession()
#define SB_DOWNLOAD_PROGRESS_UPDATE_PERIOD_MS
nsCString GetContentDispositionFilename(const nsACString &contentDisposition)
void DoTransferCompleteCallback(sbIMediaItem *aMediaItem, PRInt32 aStatus)
NS_IMPL_ISUPPORTS1(sbDownloadSession::LibraryMetadataUpdater, sbIMediaListEnumerationListener) NS_IMETHODIMP sbDownloadSession
Called when enumeration is about to begin.
#define SB_PROPERTY_CUSTOMTYPE
#define SB_PROPERTY_CONTENTURL
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
_getSelectedPageStyle s i
#define SB_PROPERTY_DOWNLOAD_MEDIALIST_GUID
#define SB_PROPERTY_DOWNLOAD_DETAILS
#define SB_PREF_DOWNLOAD_MEDIALIST
nsCOMPtr< sbIMediaItem > mDestinationItem
Songbird DownloadDevice Component Definition.
_updateTextAndScrollDataForFrame aData