28 #include <nsIHttpChannel.h>
29 #include <nsIIOService.h>
30 #include <nsILocalFile.h>
31 #include <nsIMultiPartChannel.h>
32 #include <nsIProperties.h>
33 #include <nsIPropertyBag2.h>
34 #include <nsITextToSubURI.h>
36 #include <nsIUTF8ConverterService.h>
37 #include <nsIVariant.h>
39 #include <nsAppDirectoryServiceDefs.h>
40 #include <nsAutoLock.h>
42 #include <nsHashKeys.h>
43 #include <nsServiceManagerUtils.h>
47 #include <sbIDevice.h>
48 #include <sbIDeviceEventTarget.h>
49 #include <sbIDeviceProperties.h>
57 #define FIRMWARE_FILE_PREF "firmware.cache.file"
58 #define FIRMWARE_VERSION_PREF "firmware.cache.version"
59 #define FIRMWARE_READABLE_PREF "firmware.cache.readableVersion"
60 #define FIRMWARE_CACHE_ROOT_NAME "firmware_cache"
61 #define FIRMWARE_CACHE_LAYOUT_VERSION_2_NAME "v2"
62 #define FIRMWARE_CACHE_CURRENT_VERSION_NAME FIRMWARE_CACHE_LAYOUT_VERSION_2_NAME
67 if( (c >= (
unsigned char)
'A') && (c <= (
unsigned char)
'Z') ) {
68 return (PRInt32)(c - (
unsigned char)
'A');
70 else if( (c >= (
unsigned char)
'a') && (c <= (
unsigned char)
'z') ) {
71 return ((PRInt32)(c - (
unsigned char)
'a') +26);
73 else if( (c >= (
unsigned char)
'0') && (c <= (
unsigned char)
'9') ) {
74 return ((PRInt32)(c - (
unsigned char)
'0') +52);
76 else if( (
unsigned char)
'+' == c ) {
79 else if( (
unsigned char)
'/' == c ) {
90 PRUint32 b32 = (PRUint32)0;
94 for( i = 0; i < 4; i++ ) {
103 dest[0] = (
unsigned char)((b32 >> 16) & 0xFF);
104 dest[1] = (
unsigned char)((b32 >> 8) & 0xFF);
105 dest[2] = (
unsigned char)((b32 ) & 0xFF);
112 unsigned char *dest )
114 PRUint32 b32 = (PRUint32)0;
123 b32 = (PRUint32)bits;
131 b32 |= (PRUint32)bits;
139 ubits = (PRUint32)bits;
142 dest[0] = (
unsigned char)((b32 >> 8) & 0xFF);
143 dest[1] = (
unsigned char)((b32 ) & 0xFF);
150 unsigned char *dest )
161 ubits = (PRUint32)bits;
169 ubits = (PRUint32)bits;
172 dest[0] = (
unsigned char)b32;
180 unsigned char *dest )
182 PRStatus rv = PR_SUCCESS;
184 while( srclen >= 4 ) {
186 if( PR_SUCCESS != rv ) {
209 PR_NOT_REACHED(
"coding error");
221 PRBool allocated = PR_FALSE;
223 if( (
char *)0 == src ) {
228 srclen = strlen(src);
231 if( srclen && (0 == (srclen & 3)) ) {
232 if( (
char)
'=' == src[ srclen-1 ] ) {
233 if( (
char)
'=' == src[ srclen-2 ] ) {
242 if( (
char *)0 == dest ) {
243 PRUint32 destlen = ((srclen * 3) / 4);
244 dest = (
char *)PR_MALLOC(destlen + 1);
245 if( (
char *)0 == dest ) {
248 dest[ destlen ] = (char)0;
252 status =
decode((
const unsigned char *)src, srclen, (
unsigned char *)dest);
253 if( PR_SUCCESS != status ) {
254 if( PR_TRUE == allocated ) {
266 NS_NAMED_LITERAL_CSTRING(DISPOSITION_ATTACHEMENT,
"attachment");
267 NS_NAMED_LITERAL_CSTRING(DISPOSITION_FILENAME,
"filename=");
269 nsCAutoString unicodeDisposition(contentDisposition);
270 unicodeDisposition.StripWhitespace();
272 PRInt32
pos = unicodeDisposition.Find(DISPOSITION_ATTACHEMENT,
273 CaseInsensitiveCompare);
275 return EmptyCString();
277 pos = unicodeDisposition.Find(DISPOSITION_FILENAME,
278 CaseInsensitiveCompare);
280 return EmptyCString();
282 pos += DISPOSITION_FILENAME.Length();
287 if(unicodeDisposition.CharAt(pos) ==
'"') {
290 endPos = unicodeDisposition.FindChar(
'\"', pos);
293 return EmptyCString();
297 endPos = unicodeDisposition.FindChar(
';', pos);
300 endPos = unicodeDisposition.Length();
304 nsCString filename(Substring(unicodeDisposition, pos, endPos - pos));
307 if(StringBeginsWith(filename, NS_LITERAL_CSTRING(
"=?")) &&
308 StringEndsWith(filename, NS_LITERAL_CSTRING(
"?="))) {
311 nsCOMPtr<nsIUTF8ConverterService> convServ =
312 do_GetService(
"@mozilla.org/intl/utf8converterservice;1", &rv);
313 NS_ENSURE_SUCCESS(rv, EmptyCString());
316 endPos = filename.FindChar(
'?', pos);
319 return EmptyCString();
322 nsCAutoString
charset(Substring(filename, pos, endPos - pos));
326 endPos = filename.FindChar(
'?', pos);
329 return EmptyCString();
331 nsCAutoString encoding(Substring(filename, pos, endPos - pos));
334 ToLowerCase(encoding);
337 if(!encoding.EqualsLiteral(
"b") &&
338 !encoding.EqualsLiteral(
"q")) {
339 return EmptyCString();
343 endPos = filename.FindChar(
'?', pos);
346 filename.CharAt(endPos + 1) !=
'=')
347 return EmptyCString();
349 nsCAutoString convertedFilename;
350 nsCAutoString filenameToDecode(Substring(filename, pos, endPos - pos));
352 if(encoding.EqualsLiteral(
"b")) {
353 char *
str =
SB_Base64Decode(filenameToDecode.get(), filenameToDecode.Length(), nsnull);
355 nsDependentCString strToConvert(str);
356 rv = convServ->ConvertStringToUTF8(strToConvert, charset.get(), PR_TRUE, convertedFilename);
360 else if(encoding.EqualsLiteral(
"q")) {
361 NS_WARNING(
"XXX: No support for Q encoded strings!");
364 if(NS_SUCCEEDED(rv)) {
365 filename = convertedFilename;
370 nsDependentCString(FILE_ILLEGAL_CHARACTERS),
380 nsCAutoString originCharset;
381 nsresult rv = aURI->GetOriginCharset(originCharset);
382 NS_ENSURE_SUCCESS(rv, rv);
385 nsCOMPtr<nsITextToSubURI> textToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
386 NS_ENSURE_SUCCESS(rv, rv);
388 return textToSubURI->UnEscapeURIForUI(originCharset, aFragment, aResult);
396 if (NS_SUCCEEDED(rv)) {
397 aResult = NS_ConvertUTF16toUTF8(result);
419 NS_ENSURE_ARG_POINTER(aDevice);
420 NS_ENSURE_ARG_POINTER(aHandler);
422 NS_ENSURE_FALSE(mDevice, NS_ERROR_ALREADY_INITIALIZED);
423 NS_ENSURE_FALSE(mHandler, NS_ERROR_ALREADY_INITIALIZED);
426 mListener = aListener;
429 nsresult rv = NS_ERROR_UNEXPECTED;
432 NS_ENSURE_SUCCESS(rv, rv);
434 rv = mDownloader->SetListener(
this);
435 NS_ENSURE_SUCCESS(rv, rv);
438 NS_ENSURE_SUCCESS(rv, rv);
442 getter_AddRefs(mDeviceCacheDir));
443 NS_ENSURE_SUCCESS(rv, rv);
450 const nsAString &aCacheDirName,
454 NS_ENSURE_ARG_POINTER(aDevice);
455 NS_ENSURE_ARG_POINTER(aHandler);
457 NS_ENSURE_FALSE(mDevice, NS_ERROR_ALREADY_INITIALIZED);
458 NS_ENSURE_FALSE(mHandler, NS_ERROR_ALREADY_INITIALIZED);
461 mListener = aListener;
464 nsresult rv = NS_ERROR_UNEXPECTED;
467 NS_ENSURE_SUCCESS(rv, rv);
469 rv = mDownloader->SetListener(
this);
470 NS_ENSURE_SUCCESS(rv, rv);
473 NS_ENSURE_SUCCESS(rv, rv);
477 getter_AddRefs(mDeviceCacheDir));
478 NS_ENSURE_SUCCESS(rv, rv);
487 nsresult rv = NS_ERROR_UNEXPECTED;
488 nsCOMPtr<nsIProperties> directoryService =
489 do_GetService(
"@mozilla.org/file/directory_service;1", &rv);
490 NS_ENSURE_SUCCESS(rv, rv);
492 nsCOMPtr<nsIFile> localDataDir;
493 rv = directoryService->Get(NS_APP_USER_PROFILE_LOCAL_50_DIR,
495 getter_AddRefs(localDataDir));
496 NS_ENSURE_SUCCESS(rv, rv);
501 getter_AddRefs(localDataDir));
502 NS_ENSURE_SUCCESS(rv, rv);
505 NS_ENSURE_TRUE(localDataDir, NS_ERROR_UNEXPECTED);
507 nsCOMPtr<nsIFile> cacheDir;
508 rv = localDataDir->Clone(getter_AddRefs(cacheDir));
509 NS_ENSURE_SUCCESS(rv, rv);
512 rv = cacheDir->Append(firmwareCacheName);
513 NS_ENSURE_SUCCESS(rv, rv);
520 nsCOMPtr<nsIFile> cacheVersionDir;
521 rv = cacheDir->Clone(getter_AddRefs(cacheVersionDir));
522 NS_ENSURE_SUCCESS(rv, rv);
525 rv = cacheVersionDir->Append(versionName);
526 NS_ENSURE_SUCCESS(rv, rv);
529 PRBool exists = PR_FALSE;
530 PRBool isDirectory = PR_FALSE;
532 rv = cacheVersionDir->Exists(&exists);
533 NS_ENSURE_SUCCESS(rv, rv);
536 rv = cacheVersionDir->IsDirectory(&isDirectory);
537 NS_ENSURE_SUCCESS(rv, rv);
547 rv = cacheDir->Exists(&exists);
548 NS_ENSURE_SUCCESS(rv, rv);
550 rv = cacheDir->Remove(PR_TRUE);
551 NS_ENSURE_SUCCESS(rv, rv);
554 rv = cacheVersionDir->Create(nsIFile::DIRECTORY_TYPE, 0755);
555 NS_ENSURE_SUCCESS(rv, rv);
558 PRBool isReadable = PR_FALSE;
559 PRBool isWritable = PR_FALSE;
561 rv = cacheVersionDir->IsReadable(&isReadable);
562 NS_ENSURE_SUCCESS(rv, rv);
564 rv = cacheVersionDir->IsWritable(&isWritable);
565 NS_ENSURE_SUCCESS(rv, rv);
567 NS_ENSURE_TRUE(isReadable, NS_ERROR_FAILURE);
568 NS_ENSURE_TRUE(isWritable, NS_ERROR_FAILURE);
570 cacheVersionDir.forget(aCacheRoot);
580 NS_ENSURE_ARG_POINTER(aDevice);
581 NS_ENSURE_ARG_POINTER(aCacheRoot);
582 NS_ENSURE_ARG_POINTER(aCacheDir);
584 nsCOMPtr<sbIDeviceProperties> properties;
585 nsresult rv = aDevice->GetProperties(getter_AddRefs(properties));
586 NS_ENSURE_SUCCESS(rv, rv);
588 nsString deviceDirStr;
589 rv = properties->GetVendorName(deviceDirStr);
590 NS_ENSURE_SUCCESS(rv, rv);
592 nsCOMPtr<nsIVariant> modelNumber;
593 rv = properties->GetModelNumber(getter_AddRefs(modelNumber));
594 NS_ENSURE_SUCCESS(rv, rv);
596 nsString modelNumberStr;
597 rv = modelNumber->GetAsAString(modelNumberStr);
598 NS_ENSURE_SUCCESS(rv, rv);
600 deviceDirStr.AppendLiteral(
" ");
601 deviceDirStr.Append(modelNumberStr);
604 NS_ENSURE_SUCCESS(rv, rv);
611 const nsAString &aCacheDirName,
615 NS_ENSURE_ARG_POINTER(aCacheRoot);
616 NS_ENSURE_ARG_POINTER(aCacheDir);
618 nsCOMPtr<nsIFile> deviceCacheDir;
619 nsresult rv = aCacheRoot->Clone(getter_AddRefs(deviceCacheDir));
620 NS_ENSURE_SUCCESS(rv, rv);
622 rv = deviceCacheDir->Append(aCacheDirName);
623 NS_ENSURE_SUCCESS(rv, rv);
625 PRBool exists = PR_FALSE;
626 PRBool isDirectory = PR_FALSE;
628 rv = deviceCacheDir->Exists(&exists);
629 NS_ENSURE_SUCCESS(rv, rv);
632 rv = deviceCacheDir->Create(nsIFile::DIRECTORY_TYPE, 0755);
633 NS_ENSURE_SUCCESS(rv, rv);
636 rv = deviceCacheDir->IsDirectory(&isDirectory);
637 NS_ENSURE_SUCCESS(rv, rv);
640 rv = deviceCacheDir->Create(nsIFile::DIRECTORY_TYPE, 0755);
641 NS_ENSURE_SUCCESS(rv, rv);
644 PRBool isReadable = PR_FALSE;
645 PRBool isWritable = PR_FALSE;
647 rv = deviceCacheDir->IsReadable(&isReadable);
648 NS_ENSURE_SUCCESS(rv, rv);
650 rv = deviceCacheDir->IsWritable(&isWritable);
651 NS_ENSURE_SUCCESS(rv, rv);
653 NS_ENSURE_TRUE(isReadable, NS_ERROR_FAILURE);
654 NS_ENSURE_TRUE(isWritable, NS_ERROR_FAILURE);
656 deviceCacheDir.forget(aCacheDir);
666 nsString cacheDirName;
667 cacheDirName.SetIsVoid(PR_TRUE);
672 aCachedFirmwareUpdate);
673 NS_ENSURE_SUCCESS(rv, rv);
681 const nsAString &aCacheDirName,
685 NS_ENSURE_ARG_POINTER(aDevice);
686 NS_ENSURE_ARG_POINTER(aFirmwareUpdate);
688 nsCOMPtr<nsIFile> cacheRoot;
690 NS_ENSURE_SUCCESS(rv, rv);
692 nsCOMPtr<nsIFile> deviceCache;
693 if(aCacheDirName.IsVoid() || aCacheDirName.IsEmpty()) {
696 getter_AddRefs(deviceCache));
697 NS_ENSURE_SUCCESS(rv, rv);
702 getter_AddRefs(deviceCache));
703 NS_ENSURE_SUCCESS(rv, rv);
706 nsCOMPtr<nsIFile> firmwareFile;
707 rv = aFirmwareUpdate->GetFirmwareImageFile(getter_AddRefs(firmwareFile));
708 NS_ENSURE_SUCCESS(rv, rv);
710 nsString firmwareReadableVersion;
711 rv = aFirmwareUpdate->GetFirmwareReadableVersion(firmwareReadableVersion);
712 NS_ENSURE_SUCCESS(rv, rv);
714 PRUint32 firmwareVersion = 0;
715 rv = aFirmwareUpdate->GetFirmwareVersion(&firmwareVersion);
716 NS_ENSURE_SUCCESS(rv, rv);
719 rv = firmwareFile->GetLeafName(leafName);
720 NS_ENSURE_SUCCESS(rv, rv);
722 nsCOMPtr<nsIFile> finalDestFile;
723 rv = deviceCache->Clone(getter_AddRefs(finalDestFile));
724 NS_ENSURE_SUCCESS(rv, rv);
726 rv = finalDestFile->Append(leafName);
727 NS_ENSURE_SUCCESS(rv, rv);
729 PRBool exists = PR_FALSE;
730 rv = finalDestFile->Exists(&exists);
731 NS_ENSURE_SUCCESS(rv, rv);
734 rv = finalDestFile->Remove(PR_FALSE);
735 NS_ENSURE_SUCCESS(rv, rv);
738 rv = firmwareFile->CopyTo(deviceCache, leafName);
739 NS_ENSURE_SUCCESS(rv, rv);
741 nsString firmwarePath;
742 rv = deviceCache->GetPath(firmwarePath);
743 NS_ENSURE_SUCCESS(rv, rv);
745 nsCOMPtr<nsILocalFile> newFirmwareFile;
746 rv = NS_NewLocalFile(firmwarePath, PR_FALSE, getter_AddRefs(newFirmwareFile));
747 NS_ENSURE_SUCCESS(rv, rv);
749 rv = newFirmwareFile->Append(leafName);
750 NS_ENSURE_SUCCESS(rv, rv);
752 nsCOMPtr<nsIVariant> firmwareVersionVariant =
755 firmwareVersionVariant);
756 NS_ENSURE_SUCCESS(rv, rv);
758 nsCOMPtr<nsIVariant> firmwareReadableVariant =
761 firmwareReadableVariant);
762 NS_ENSURE_SUCCESS(rv, rv);
764 nsString newFirmwareFilePath;
765 rv = newFirmwareFile->GetPath(newFirmwareFilePath);
766 NS_ENSURE_SUCCESS(rv, rv);
768 nsCOMPtr<nsIVariant> firmwareFileVariant =
771 firmwareFileVariant);
772 NS_ENSURE_SUCCESS(rv, rv);
774 nsCOMPtr<sbIDeviceFirmwareUpdate> firmwareUpdate =
776 NS_ENSURE_SUCCESS(rv, rv);
778 rv = firmwareUpdate->Init(newFirmwareFile,
779 firmwareReadableVersion,
781 NS_ENSURE_SUCCESS(rv, rv);
783 firmwareUpdate.forget(aCachedFirmwareUpdate);
792 NS_ENSURE_ARG_POINTER(aNewDir);
794 NS_ENSURE_TRUE(!aDirName.IsEmpty(), NS_ERROR_INVALID_ARG);
796 nsCOMPtr<nsIFile> cacheRoot;
799 NS_ENSURE_SUCCESS(rv, rv);
801 nsCOMPtr<nsIFile> cacheDir;
802 rv = cacheRoot->Clone(getter_AddRefs(cacheDir));
803 NS_ENSURE_SUCCESS(rv, rv);
805 rv = cacheDir->Append(aDirName);
806 NS_ENSURE_SUCCESS(rv, rv);
808 PRBool exists = PR_FALSE;
809 PRBool isDirectory = PR_FALSE;
811 rv = cacheDir->Exists(&exists);
812 NS_ENSURE_SUCCESS(rv, rv);
815 rv = cacheDir->Create(nsIFile::DIRECTORY_TYPE, 0755);
816 NS_ENSURE_SUCCESS(rv, rv);
819 rv = cacheDir->IsDirectory(&isDirectory);
820 NS_ENSURE_SUCCESS(rv, rv);
823 rv = cacheDir->Create(nsIFile::DIRECTORY_TYPE, 0755);
824 NS_ENSURE_SUCCESS(rv, rv);
827 PRBool isReadable = PR_FALSE;
828 PRBool isWritable = PR_FALSE;
830 rv = cacheDir->IsReadable(&isReadable);
831 NS_ENSURE_SUCCESS(rv, rv);
833 rv = cacheDir->IsWritable(&isWritable);
834 NS_ENSURE_SUCCESS(rv, rv);
836 NS_ENSURE_TRUE(isReadable, NS_ERROR_FAILURE);
837 NS_ENSURE_TRUE(isWritable, NS_ERROR_FAILURE);
839 cacheDir.forget(aNewDir);
847 NS_ENSURE_STATE(mDevice);
848 NS_ENSURE_STATE(mDeviceCacheDir);
849 NS_ENSURE_STATE(mHandler);
851 nsCOMPtr<nsIVariant> firmwareVersion;
854 getter_AddRefs(firmwareVersion));
855 NS_ENSURE_SUCCESS(rv, PR_FALSE);
857 PRInt32 unsignedVersion = 0;
858 rv = firmwareVersion->GetAsInt32(&unsignedVersion);
859 NS_ENSURE_SUCCESS(rv, PR_FALSE);
861 PRUint32 prefVersion =
static_cast<PRUint32
>(unsignedVersion);
863 PRUint32 handlerVersion = 0;
864 rv = mHandler->GetLatestFirmwareVersion(&handlerVersion);
865 NS_ENSURE_SUCCESS(rv, PR_FALSE);
867 if(prefVersion < handlerVersion) {
871 nsCOMPtr<nsIVariant> firmwareFilePath;
873 getter_AddRefs(firmwareFilePath));
874 NS_ENSURE_SUCCESS(rv, rv);
877 rv = firmwareFilePath->GetAsAString(filePath);
878 NS_ENSURE_SUCCESS(rv, rv);
880 nsCOMPtr<nsILocalFile> localFile;
881 rv = NS_NewLocalFile(filePath, PR_FALSE, getter_AddRefs(localFile));
883 PRBool exists = PR_FALSE;
884 rv = localFile->Exists(&exists);
885 NS_ENSURE_SUCCESS(rv, rv);
891 nsCOMPtr<nsIURI> firmwareURI;
892 rv = mHandler->GetLatestFirmwareLocation(getter_AddRefs(firmwareURI));
893 NS_ENSURE_TRUE(firmwareURI, NS_ERROR_UNEXPECTED);
895 nsCOMPtr<nsIURL> firmwareURL = do_QueryInterface(firmwareURI, &rv);
896 NS_ENSURE_SUCCESS(rv, rv);
898 nsCString newFileName;
899 rv = firmwareURL->GetFileName(newFileName);
900 NS_ENSURE_SUCCESS(rv, rv);
902 nsString localFileName;
903 rv = localFile->GetLeafName(localFileName);
904 NS_ENSURE_SUCCESS(rv, rv);
906 if(!localFileName.EqualsLiteral(newFileName.BeginReading())) {
916 NS_ENSURE_ARG_POINTER(aFile);
918 nsCOMPtr<nsIVariant> firmwareFilePath;
920 getter_AddRefs(firmwareFilePath));
921 NS_ENSURE_SUCCESS(rv, rv);
924 rv = firmwareFilePath->GetAsAString(filePath);
925 NS_ENSURE_SUCCESS(rv, rv);
927 nsCOMPtr<nsILocalFile> localFile;
928 rv = NS_NewLocalFile(filePath, PR_FALSE, getter_AddRefs(localFile));
930 PRBool exists = PR_FALSE;
931 rv = localFile->Exists(&exists);
932 NS_ENSURE_SUCCESS(rv, rv);
935 return NS_ERROR_FAILURE;
938 NS_ADDREF(*aFile = localFile);
946 NS_ENSURE_STATE(mDownloader);
947 NS_ENSURE_STATE(mDevice);
948 NS_ENSURE_STATE(mHandler);
949 NS_ENSURE_STATE(mDeviceCacheDir);
950 NS_ENSURE_FALSE(mIsBusy, NS_ERROR_FAILURE);
954 nsresult rv = NS_ERROR_UNEXPECTED;
959 rv = mDeviceCacheDir->Remove(PR_TRUE);
960 NS_ENSURE_SUCCESS(rv, rv);
962 rv = mDeviceCacheDir->Create(nsIFile::DIRECTORY_TYPE, 0755);
963 NS_ENSURE_SUCCESS(rv, rv);
965 nsCOMPtr<nsIURI> firmwareURI;
966 rv = mHandler->GetLatestFirmwareLocation(getter_AddRefs(firmwareURI));
967 NS_ENSURE_TRUE(firmwareURI, NS_ERROR_UNEXPECTED);
969 rv = mDownloader->SetSourceURI(firmwareURI);
970 NS_ENSURE_SUCCESS(rv, rv);
972 rv = mDownloader->Start();
973 NS_ENSURE_SUCCESS(rv, rv);
979 NS_ENSURE_SUCCESS(rv, rv);
982 nsCOMPtr<nsIFile>
file;
984 NS_ENSURE_SUCCESS(rv, rv);
986 nsCOMPtr<sbIDeviceFirmwareUpdate> firmwareUpdate =
988 NS_ENSURE_SUCCESS(rv, rv);
990 PRUint32 firmwareVersion = 0;
991 nsString firmwareReadableVersion;
993 rv = mHandler->GetLatestFirmwareVersion(&firmwareVersion);
994 NS_ENSURE_SUCCESS(rv, rv);
996 rv = mHandler->GetLatestFirmwareReadableVersion(firmwareReadableVersion);
997 NS_ENSURE_SUCCESS(rv, rv);
999 rv = firmwareUpdate->Init(file,
1000 firmwareReadableVersion,
1002 NS_ENSURE_SUCCESS(rv, rv);
1008 NS_ENSURE_SUCCESS(rv, rv);
1010 nsCOMPtr<nsIVariant> firmwareUpdateVariant =
1013 firmwareUpdateVariant,
1015 NS_ENSURE_SUCCESS(rv, rv);
1026 NS_ENSURE_STATE(mDownloader);
1028 nsresult rv = NS_ERROR_UNEXPECTED;
1031 rv = mDownloader->Cancel();
1032 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Couldn't cancel download");
1037 nsCOMPtr<sbIFileDownloaderListener> grip(
this);
1038 rv = mDownloader->SetListener(nsnull);
1039 NS_ENSURE_SUCCESS(rv, rv);
1047 NS_ENSURE_STATE(mDownloader);
1048 NS_ENSURE_STATE(mDevice);
1050 PRUint32 percentComplete = 0;
1051 nsresult rv = mDownloader->GetPercentComplete(&percentComplete);
1052 NS_ENSURE_SUCCESS(rv, rv);
1054 nsCOMPtr<nsIVariant>
data =
1060 NS_ENSURE_SUCCESS(rv, rv);
1068 NS_ENSURE_STATE(mDownloader);
1069 NS_ENSURE_STATE(mDevice);
1071 PRBool success = PR_FALSE;
1072 nsresult rv = mDownloader->GetSucceeded(&success);
1073 NS_ENSURE_SUCCESS(rv, rv);
1082 NS_ENSURE_SUCCESS(rv, rv);
1084 nsCOMPtr<sbIFileDownloaderListener> grip(
this);
1085 rv = mDownloader->SetListener(nsnull);
1086 NS_ENSURE_SUCCESS(rv, rv);
1093 nsCOMPtr<nsIRequest> request;
1094 rv = mDownloader->GetRequest(getter_AddRefs(request));
1095 NS_ENSURE_TRUE(request, NS_ERROR_UNEXPECTED);
1097 nsCString contentDisposition;
1098 nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(request));
1100 httpChannel->GetResponseHeader(NS_LITERAL_CSTRING(
"content-disposition"),
1101 contentDisposition);
1105 if(contentDisposition.IsEmpty()) {
1106 nsCOMPtr<nsIMultiPartChannel> multipartChannel(do_QueryInterface(request));
1107 if(multipartChannel) {
1108 multipartChannel->GetContentDisposition(contentDisposition);
1113 if(!contentDisposition.IsEmpty()) {
1117 nsCOMPtr<nsIURI> firmwareURI;
1119 mHandler->GetLatestFirmwareLocation(getter_AddRefs(firmwareURI));
1120 NS_ENSURE_TRUE(firmwareURI, NS_ERROR_UNEXPECTED);
1122 nsCOMPtr<nsIURL>
url(do_QueryInterface(firmwareURI));
1124 nsCString extension;
1125 url->GetFileExtension(extension);
1128 extension.Trim(
".", PR_FALSE);
1130 nsCAutoString leafName;
1131 url->GetFileBaseName(leafName);
1133 if(!leafName.IsEmpty()) {
1136 filename = leafName;
1140 if(!extension.IsEmpty()) {
1141 filename.AppendLiteral(
".");
1142 filename.Append(extension);
1148 nsCOMPtr<nsIFile>
file;
1149 rv = mDownloader->GetDestinationFile(getter_AddRefs(file));
1150 NS_ENSURE_SUCCESS(rv, rv);
1152 NS_ConvertUTF8toUTF16 filename16(filename);
1153 rv = file->MoveTo(mDeviceCacheDir, filename16);
1154 NS_ENSURE_SUCCESS(rv, rv);
1156 nsString firmwarePath;
1157 rv = mDeviceCacheDir->GetPath(firmwarePath);
1158 NS_ENSURE_SUCCESS(rv, rv);
1160 nsCOMPtr<nsILocalFile> firmwareFile;
1161 rv = NS_NewLocalFile(firmwarePath, PR_FALSE, getter_AddRefs(firmwareFile));
1162 NS_ENSURE_SUCCESS(rv, rv);
1164 rv = firmwareFile->Append(filename16);
1165 NS_ENSURE_SUCCESS(rv, rv);
1167 nsCOMPtr<sbIDeviceFirmwareUpdate> firmwareUpdate =
1169 NS_ENSURE_SUCCESS(rv, rv);
1171 PRUint32 firmwareVersion = 0;
1172 nsString firmwareReadableVersion;
1174 rv = mHandler->GetLatestFirmwareVersion(&firmwareVersion);
1175 NS_ENSURE_SUCCESS(rv, rv);
1177 rv = mHandler->GetLatestFirmwareReadableVersion(firmwareReadableVersion);
1178 NS_ENSURE_SUCCESS(rv, rv);
1180 rv = firmwareUpdate->Init(firmwareFile,
1181 firmwareReadableVersion,
1183 NS_ENSURE_SUCCESS(rv, rv);
1185 nsCOMPtr<nsIVariant> firmwareVersionVariant =
1188 firmwareVersionVariant);
1189 NS_ENSURE_SUCCESS(rv, rv);
1191 nsCOMPtr<nsIVariant> firmwareReadableVariant =
1194 firmwareReadableVariant);
1195 NS_ENSURE_SUCCESS(rv, rv);
1197 nsString firmwareFilePath;
1198 rv = firmwareFile->GetPath(firmwareFilePath);
1199 NS_ENSURE_SUCCESS(rv, rv);
1201 nsCOMPtr<nsIVariant> firmwareFileVariant =
1204 firmwareFileVariant);
1205 NS_ENSURE_SUCCESS(rv, rv);
1207 nsCOMPtr<sbIFileDownloaderListener> grip(
this);
1208 rv = mDownloader->SetListener(nsnull);
1209 NS_ENSURE_SUCCESS(rv, rv);
1218 NS_ENSURE_SUCCESS(rv, rv);
1228 NS_ENSURE_STATE(mDevice);
1229 NS_ENSURE_ARG_POINTER(aEvent);
1231 nsresult rv = NS_ERROR_UNEXPECTED;
1232 nsCOMPtr<sbIDeviceManager2> deviceManager =
1233 do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;2", &rv);
1234 NS_ENSURE_SUCCESS(rv, rv);
1236 rv = deviceManager->CreateEvent(aType,
1242 NS_ENSURE_SUCCESS(rv, rv);
1251 NS_ENSURE_STATE(mDevice);
1252 NS_ENSURE_ARG_POINTER(aEvent);
1254 nsresult rv = NS_ERROR_UNEXPECTED;
1255 nsCOMPtr<sbIDeviceEventListener>
listener = mListener;
1257 NS_ENSURE_STATE(mDevice);
1258 nsCOMPtr<sbIDeviceEventTarget>
target = do_QueryInterface(mDevice, &rv);
1259 NS_ENSURE_SUCCESS(rv, rv);
1261 PRBool dispatched = PR_FALSE;
1262 rv = target->DispatchEvent(aEvent, aAsync, &dispatched);
1263 NS_ENSURE_SUCCESS(rv, rv);
1265 NS_WARN_IF_FALSE(dispatched,
"Event not dispatched");
1268 rv = listener->OnDeviceEvent(aEvent);
1269 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Error while calling listener.");
1280 nsCOMPtr<sbIDeviceEvent> deviceEvent;
1282 NS_ENSURE_SUCCESS(rv, rv);
1285 NS_ENSURE_SUCCESS(rv, rv);
1295 sbDeviceFirmwareDownloader::OnProgress()
1298 NS_ENSURE_SUCCESS(rv, rv);
1304 sbDeviceFirmwareDownloader::OnComplete()
1307 NS_ENSURE_SUCCESS(rv, rv);
const unsigned long EVENT_FIRMWARE_DOWNLOAD_ERROR
Firmware download error.
#define FIRMWARE_CACHE_CURRENT_VERSION_NAME
#define FIRMWARE_FILE_PREF
const unsigned long EVENT_FIRMWARE_DOWNLOAD_END
Firmware download end.
static nsresult CacheFirmwareUpdate(sbIDevice *aDevice, sbIDeviceFirmwareUpdate *aFirmwareUpdate, sbIDeviceFirmwareUpdate **aCachedFirmwareUpdate)
static PRStatus decode(const unsigned char *src, PRUint32 srclen, unsigned char *dest)
void nsCString_ReplaceChars(nsACString &aOldString, const nsACString &aOldChars, const char aNewChar)
#define FIRMWARE_VERSION_PREF
NS_IMPL_THREADSAFE_ISUPPORTS1(sbDeviceFirmwareDownloader, sbIFileDownloaderListener) sbDeviceFirmwareDownloader
PRBool IsAlreadyInCache()
#define SB_DEVICEFIRMWAREUPDATE_CONTRACTID
nsresult SendDeviceEvent(sbIDeviceEvent *aEvent, PRBool aAsync=PR_TRUE)
static PRInt32 codetovalue(unsigned char c)
static PRStatus decode3to2(const unsigned char *src, unsigned char *dest)
Songbird Variant Utility Definitions.
#define SB_FILEDOWNLOADER_CONTRACTID
static nsresult CreateCacheDirForDevice(sbIDevice *aDevice, nsIFile *aCacheRoot, nsIFile **aCacheDir)
static char * SB_Base64Decode(const char *src, PRUint32 srclen, char *dest)
#define FIRMWARE_READABLE_PREF
static nsresult CreateDirInCacheRoot(const nsAString &aDirName, nsIFile **aNewDir)
nsresult Init(sbIDevice *aDevice, sbIDeviceEventListener *aListener, sbIDeviceFirmwareHandler *aHandler)
nsresult HandleComplete()
const unsigned long STATE_IDLE
static nsresult CreateCacheRoot(nsIFile **aCacheRoot)
static PRStatus decode4to3(const unsigned char *src, unsigned char *dest)
nsresult GetCachedFile(nsIFile **aFile)
const unsigned long EVENT_FIRMWARE_DOWNLOAD_PROGRESS
Firmware download progress.
nsresult CreateDeviceEvent(PRUint32 aType, nsIVariant *aData, sbIDeviceEvent **aEvent)
#define FIRMWARE_CACHE_ROOT_NAME
virtual ~sbDeviceFirmwareDownloader()
static PRStatus decode2to1(const unsigned char *src, unsigned char *dest)
_getSelectedPageStyle s i
static nsresult UnescapeFragment(const nsACString &aFragment, nsIURI *aURI, nsAString &aResult)
nsresult HandleProgress()
_updateTextAndScrollDataForFrame aData
const unsigned long EVENT_FIRMWARE_DOWNLOAD_START
Firmware download start.
static nsCString GetContentDispositionFilename(const nsACString &contentDisposition)