35 #include "sbIPropertyArray.h"
40 #include <sbFileUtils.h>
43 #include <nsIChannel.h>
44 #include <nsIContentSniffer.h>
45 #include <nsIFileStreams.h>
46 #include <nsIFileURL.h>
47 #include <nsIIOService.h>
50 #include <nsNetUtil.h>
51 #include <nsUnicharUtils.h>
61 static PRLogModuleInfo* gLog = PR_NewLogModule(
"sbMetadataHandlerWMA");
64 if (gLog) PR_LOG(gLog, PR_LOG_WARN, args); \
68 if (gLog) PR_LOG(gLog, PR_LOG_DEBUG, args); \
71 #define __FUNCTION__ __PRETTY_FUNCTION__
80 #define COM_ENSURE_SUCCESS(_val) \
82 nsresult __rv = _val; \
84 NS_ENSURE_SUCCESS_BODY(_val, _val); \
85 return NS_ERROR_FAILURE; \
89 #define countof(_array) \
90 sizeof(_array) / sizeof(_array[0])
92 #define SB_ARTIST SB_PROPERTY_ARTISTNAME
93 #define SB_TITLE SB_PROPERTY_TRACKNAME
94 #define SB_ALBUM SB_PROPERTY_ALBUMNAME
95 #define SB_GENRE SB_PROPERTY_GENRE
96 #define SB_TRACKNO SB_PROPERTY_TRACKNUMBER
97 #define SB_VENDOR SB_PROPERTY_SOFTWAREVENDOR
98 #define SB_COPYRIGHT SB_PROPERTY_COPYRIGHT
99 #define SB_COMPOSER SB_PROPERTY_COMPOSERNAME
100 #define SB_CONDUCTOR SB_PROPERTY_CONDUCTORNAME
101 #define SB_DIRECTOR "director"
102 #define SB_BPM SB_PROPERTY_BPM
103 #define SB_LYRICS SB_PROPERTY_LYRICS
104 #define SB_YEAR SB_PROPERTY_YEAR
105 #define SB_BITRATE SB_PROPERTY_BITRATE
106 #define SB_RATING SB_PROPERTY_RATING
107 #define SB_COMMENT SB_PROPERTY_COMMENT
108 #define SB_LENGTH SB_PROPERTY_DURATION
109 #define SB_ALBUMARTIST SB_PROPERTY_ALBUMARTISTNAME
110 #define SB_PROTECTED SB_PROPERTY_ISDRMPROTECTED
112 #define WMP_ARTIST "Author"
113 #define WMP_TITLE "Title"
114 #define WMP_ALBUM "WM/AlbumTitle"
115 #define WMP_GENRE "WM/Genre"
116 #define WMP_TRACKNO "WM/TrackNumber"
117 #define WMP_VENDOR "WM/ToolName"
118 #define WMP_COPYRIGHT "Copyright"
119 #define WMP_COMPOSER "WM/Composer"
120 #define WMP_CONDUCTOR "WM/Conductor"
121 #define WMP_DIRECTOR "WM/Director"
122 #define WMP_BPM "WM/BeatsPerMinute"
123 #define WMP_LYRICS "WM/Lyrics"
124 #define WMP_YEAR "WM/Year"
125 #define WMP_BITRATE "Bitrate"
126 #define WMP_RATING "Rating"
127 #define WMP_COMMENT "Description"
128 #define WMP_LENGTH "Duration"
129 #define WMP_ALBUMARTIST "WM/AlbumArtist"
130 #define WMP_PROTECTED "Is_Protected"
135 #define SB_GN_EXTENDEDDATA "http://gracenote.com/pos/1.0#extendedData"
136 #define SB_GN_TAGID "http://gracenote.com/pos/1.0#tagId"
137 #define WMP_GN_EXTENDEDDATA "GN/ExtData"
138 #define WMP_GN_TAGID "GN/UniqueFileIdentifier"
150 #define KEY_MAP_ENTRY(_entry, _type) { NS_L(SB_##_entry), \
151 NS_L(WMP_##_entry), \
187 m_Completed(PR_FALSE)
195 NS_IMETHODIMP sbMetadataHandlerWMA::GetContractID(nsACString &aContractID)
202 sbMetadataHandlerWMA::GetChannel(
nsIChannel** _retval)
204 NS_ENSURE_ARG_POINTER(_retval);
210 sbMetadataHandlerWMA::SetChannel(
nsIChannel* aURLChannel)
216 nsCOMPtr<nsIURI> pURI;
217 rv =
m_Channel->GetURI(getter_AddRefs(pURI));
218 NS_ENSURE_SUCCESS(rv, rv);
220 nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(pURI, &rv);
222 NS_WARNING(
"WMA METADATA: Remote files not currently supported");
227 nsCOMPtr<nsIFile>
file;
228 rv = fileURL->GetFile(getter_AddRefs(file));
229 NS_ENSURE_SUCCESS(rv, rv);
233 NS_ENSURE_SUCCESS(rv, rv);
239 sbMetadataHandlerWMA::OnChannelData(
nsISupports* aChannel)
245 sbMetadataHandlerWMA::GetCompleted(PRBool* _retval)
247 NS_ENSURE_ARG_POINTER(_retval);
254 sbMetadataHandlerWMA::Close()
268 sbMetadataHandlerWMA::Vote(
const nsAString& aURL,
271 NS_ENSURE_ARG_POINTER(_retval);
272 nsAutoString strUrl(aURL);
276 ( strUrl.Find(
".wma", PR_TRUE ) != -1 ) ||
277 ( strUrl.Find(
".wmv", PR_TRUE ) != -1 ) ||
278 ( strUrl.Find(
".wm", PR_TRUE ) != -1 ) ||
279 ( strUrl.Find(
".asf", PR_TRUE ) != -1 ) ||
280 ( strUrl.Find(
".asx", PR_TRUE ) != -1 )
290 sbMetadataHandlerWMA::Read(PRInt32* _retval)
292 TRACE((
"%s[%p]", __FUNCTION__,
this));
293 NS_ENSURE_ARG_POINTER(_retval);
300 NS_ENSURE_TRUE(
m_Channel, NS_ERROR_FAILURE);
301 NS_ENSURE_TRUE(!
m_FilePath.IsEmpty(), NS_ERROR_UNEXPECTED);
302 nsresult rv = NS_ERROR_UNEXPECTED;
305 NS_ENSURE_SUCCESS(rv, rv);
310 if (NS_SUCCEEDED(rv))
316 if (NS_SUCCEEDED(rv))
319 TRACE((
"%s[%p] - failed to read data", __FUNCTION__,
this));
320 return NS_ERROR_INVALID_ARG;
324 sbMetadataHandlerWMA::Write(PRInt32 *_retval)
326 NS_ENSURE_ARG_POINTER(_retval);
327 NS_ENSURE_TRUE(!
m_FilePath.IsEmpty(), NS_ERROR_NOT_INITIALIZED);
336 nsCOMPtr<sbIMutablePropertyArray> propArray;
339 CComPtr<IWMMetadataEditor> editor;
340 hr = WMCreateEditor(&editor);
346 CComPtr<IWMHeaderInfo3>
header;
347 hr = editor->QueryInterface(&header);
351 WORD indicesSize = 0;
358 if (NS_UNLIKELY(NS_SUCCEEDED(rv))) {
364 if (NS_SUCCEEDED(rv)) {
370 NS_ENSURE_SUCCESS_BODY(rv, rv);
374 for (PRUint32
i = 0;
i < NS_ARRAY_LENGTH(kMetadataKeys); ++
i) {
375 rv = propArray->GetPropertyValue(nsDependentString(kMetadataKeys[
i].songbirdName),
377 if (NS_LIKELY(rv == NS_ERROR_NOT_AVAILABLE)) {
381 NS_ENSURE_SUCCESS(rv, rv);
384 WORD indicesCount = 0;
385 hr = header->GetAttributeIndices(0xFFFF,
386 kMetadataKeys[
i].wmpName,
391 if (indicesCount > indicesSize) {
392 indices =
reinterpret_cast<WORD*
>(NS_Alloc(
sizeof(WORD) * indicesCount));
393 NS_ENSURE_TRUE(indices, NS_ERROR_OUT_OF_MEMORY);
394 indicesSize = indicesCount;
396 indicesCount = indicesSize;
397 hr = header->GetAttributeIndices(0xFFFF,
398 kMetadataKeys[
i].wmpName,
404 const BYTE*
data = NULL;
406 DWORD dataLength = 0;
407 switch (kMetadataKeys[
i].type) {
408 case WMT_TYPE_STRING: {
409 data =
reinterpret_cast<const BYTE*
>(value.get());
410 dataLength = value.Length() *
sizeof(PRUnichar);
413 case WMT_TYPE_DWORD: {
414 DWORD* dword =
reinterpret_cast<DWORD*
>(&dataBuffer);
415 PRInt32 success = PR_sscanf(NS_ConvertUTF16toUTF8(value).BeginReading(),
418 if (NS_UNLIKELY(success < 1)) {
422 data =
reinterpret_cast<BYTE*
>(dword);
423 dataLength =
sizeof(DWORD);
426 case WMT_TYPE_QWORD: {
427 PRInt32 success = PR_sscanf(NS_ConvertUTF16toUTF8(value).BeginReading(),
430 if (NS_UNLIKELY(success < 1)) {
434 data =
reinterpret_cast<BYTE*
>(&dataBuffer);
435 dataLength =
sizeof(QWORD);
439 LOG((
"%s: don't know how to handle type %i",
441 kMetadataKeys[
i].type));
442 NS_WARNING(__FUNCTION__
": don't know how to handle type");
446 if (indicesCount > 0) {
447 if (dataLength == 0) {
448 TRACE((
"%s: Deleting %S\n", __FUNCTION__, kMetadataKeys[
i].wmpName));
449 hr = header->DeleteAttribute(0xFFFF,
452 TRACE((
"%s: Modifying %S\n", __FUNCTION__, kMetadataKeys[
i].wmpName));
453 hr = header->ModifyAttribute(0xFFFF,
455 kMetadataKeys[
i].type,
462 TRACE((
"%s: Adding %S\n", __FUNCTION__, kMetadataKeys[
i].wmpName));
464 hr = header->AddAttribute(0,
465 kMetadataKeys[
i].wmpName,
467 kMetadataKeys[
i].type,
476 hr = editor->Flush();
483 sbMetadataHandlerWMA::GetImageData(PRInt32 aType,
484 nsACString &aMimeType,
488 NS_ENSURE_ARG_POINTER(aDataLen);
489 NS_ENSURE_ARG_POINTER(aData);
490 NS_ENSURE_TRUE(!
m_FilePath.IsEmpty(), NS_ERROR_NOT_INITIALIZED);
494 if (NS_SUCCEEDED(rv)) {
500 NS_ENSURE_SUCCESS(rv, rv);
506 sbMetadataHandlerWMA::SetImageData(PRInt32 aType,
507 const nsAString &aURL)
509 NS_ENSURE_TRUE(!
m_FilePath.IsEmpty(), NS_ERROR_NOT_INITIALIZED);
514 CComPtr<IWMMetadataEditor> editor;
515 hr = WMCreateEditor(&editor);
521 CComPtr<IWMHeaderInfo3>
header;
522 hr = editor->QueryInterface(&header);
527 NS_ENSURE_SUCCESS(rv, rv);
530 hr = editor->Flush();
533 hr = editor->Close();
542 const nsAString &aURL,
543 IWMHeaderInfo3 *aHeader,
546 NS_ENSURE_ARG_POINTER(aHeader);
553 WORD indicesCount = 0;
554 hr = aHeader->GetAttributeIndices(0xFFFF,
560 indices =
reinterpret_cast<WORD*
>(NS_Alloc(
sizeof(WORD) * indicesCount));
561 NS_ENSURE_TRUE(indices, NS_ERROR_OUT_OF_MEMORY);
562 hr = aHeader->GetAttributeIndices(0xFFFF,
570 WM_PICTURE *picData = (WM_PICTURE*)data.BeginWriting();
571 WORD targetIndex =
static_cast<WORD
>(-1);
572 if (indicesCount > 0) {
575 DWORD dataLength = data.Length();
576 WMT_ATTR_DATATYPE type;
578 hr = aHeader->GetAttributeByIndexEx(0xFFFF,
584 reinterpret_cast<BYTE*
>(data.BeginWriting()),
587 if (hr == NS_E_SDK_BUFFERTOOSMALL) {
588 data.SetLength(dataLength);
589 dataLength = data.Length();
591 picData = (WM_PICTURE*)data.BeginWriting();
592 hr = aHeader->GetAttributeByIndexEx(0xFFFF,
598 reinterpret_cast<BYTE*
>(data.BeginWriting()),
603 if (type != WMT_TYPE_BINARY) {
604 LOG((
"%s: index %hu got unknown type %i", __FUNCTION__,
offset, type));
609 if (picData->bPictureType != aType) {
622 if (aURL.IsEmpty()) {
624 if (targetIndex != static_cast<WORD>(-1)) {
625 hr = aHeader->DeleteAttribute(0xFFFF, targetIndex);
637 nsCOMPtr<nsIURI>
uri;
638 rv = NS_NewURI(getter_AddRefs(uri), aURL);
639 NS_ENSURE_SUCCESS(rv, rv);
641 nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(uri, &rv);
642 NS_ENSURE_SUCCESS(rv, rv);
644 nsCOMPtr<nsIFile> artFile;
645 rv = fileURL->GetFile(getter_AddRefs(artFile));
646 NS_ENSURE_SUCCESS(rv, rv);
648 nsCString dataString;
650 NS_ENSURE_SUCCESS(rv, rv);
653 nsCString contentType;
654 nsCOMPtr<nsIContentSniffer> contentSniffer =
656 NS_ENSURE_SUCCESS(rv, rv);
658 rv = contentSniffer->GetMIMETypeFromContent(NULL,
659 reinterpret_cast<const PRUint8*>(dataString.BeginReading()),
662 NS_ENSURE_SUCCESS(rv, rv);
664 NS_ConvertASCIItoUTF16 contentTypeUnicode(contentType);
666 nsString emptyString;
667 WM_PICTURE newPicData;
668 newPicData.pwszMIMEType = contentTypeUnicode.BeginWriting();
670 newPicData.bPictureType = aType;
671 newPicData.pwszDescription = emptyString.BeginWriting();
672 newPicData.pbData =
reinterpret_cast<BYTE*
>(dataString.BeginWriting());
673 newPicData.dwDataLen = dataString.Length();
675 if (targetIndex == static_cast<WORD>(-1)) {
678 hr = aHeader->AddAttribute(0,
683 reinterpret_cast<const BYTE*>(&newPicData),
688 hr = aHeader->ModifyAttribute(0xFFFF,
692 reinterpret_cast<const BYTE*>(&newPicData),
704 NS_ENSURE_ARG_POINTER(_retval);
718 sbMetadataHandlerWMA::GetRequiresMainThread(PRBool *_retval)
720 NS_ENSURE_ARG_POINTER(_retval);
729 const nsAString &aKey)
731 TRACE((
"%s[%p]: reading %s",
732 __FUNCTION__,
this, NS_ConvertUTF16toUTF8(aKey).
get()));
738 hr = aHeaderInfo->GetAttributeIndices(0xFFFF,
743 if (FAILED(hr) || !
count) {
750 NS_ERROR(
"NS_Alloc failed!");
755 hr = aHeaderInfo->GetAttributeIndices(0xFFFF,
765 WMT_ATTR_DATATYPE type;
772 hr = aHeaderInfo->GetAttributeByIndexEx(0xFFFF,
781 NS_WARNING(
"GetAttributeByIndexEx failed");
787 data = (BYTE*) NS_Alloc(size);
789 NS_ERROR(
"NS_Alloc failed!");
794 hr = aHeaderInfo->GetAttributeByIndexEx(0xFFFF,
803 NS_WARNING(
"GetAttributeByIndexEx failed");
808 PRInt32 datatype = 0;
811 case WMT_TYPE_STRING:
812 value.Assign(reinterpret_cast<PRUnichar*>(data.
get()));
815 case WMT_TYPE_BINARY:
818 case WMT_TYPE_QWORD: {
819 PRInt64 intVal = *(
reinterpret_cast<QWORD*
>(data.
get()));
828 PRUint32 len = PR_snprintf(buf,
sizeof(buf),
"%lld", intVal);
830 value.Append(NS_ConvertASCIItoUTF16(buf, len));
834 case WMT_TYPE_DWORD: {
835 PRUint32 intVal = *(
reinterpret_cast<DWORD*
>(data.
get()));
840 value.AppendInt( intVal );
845 value.AppendInt( (PRInt32)*(reinterpret_cast<WORD*>(data.
get())) );
850 value.AppendInt( (PRInt32)*(reinterpret_cast<BOOL*>(data.
get())) );
858 NS_WARNING(
"Value given in an unsupported type");
862 TRACE((
"%s[%p]: %s -> %s",
865 NS_ConvertUTF16toUTF8(aKey).
get(),
866 NS_ConvertUTF16toUTF8(value).
get()));
875 NS_ENSURE_ARG_POINTER(aMedia);
877 CComPtr<IWMPPlayer4> player;
878 hr = player.CoCreateInstance(__uuidof(WindowsMediaPlayer),
880 CLSCTX_INPROC_SERVER);
885 hr = player->get_settings(&settings);
888 hr = settings->put_autoStart(PR_FALSE);
891 CComBSTR uiMode(_T(
"invisible"));
892 hr = player->put_uiMode(uiMode);
896 CComPtr<IWMPPlaylist> playlist;
897 CComBSTR playlistName(_T(
"SongbirdMetadataPlaylist"));
898 hr = player->newPlaylist(playlistName, NULL, &playlist);
901 hr = player->put_currentPlaylist(playlist);
904 CComBSTR uriString(aFilePath.BeginReading());
906 CComPtr<IWMPMedia> newMedia;
907 hr = player->newMedia(uriString, &newMedia);
910 CComPtr<IWMPMedia3> newMedia3;
911 hr = newMedia->QueryInterface(&newMedia3);
915 hr = playlist->appendItem(newMedia);
919 CComPtr<IWMPControls> controls;
920 hr = player->get_controls(&controls);
923 hr = controls->put_currentItem(newMedia);
926 *aMedia = newMedia3.Detach();
937 CComPtr<IWMMetadataEditor> reader;
938 HRESULT hr = WMCreateEditor(&reader);
941 nsAutoString filePath(aFilePath);
944 hr = reader->Open(filePath.get());
946 return NS_ERROR_FAILURE;
948 CComPtr<IWMHeaderInfo3> headerInfo;
949 hr = reader->QueryInterface(&headerInfo);
952 nsString
value, wmpKey;
954 for (PRUint32 index = 0; index < NS_ARRAY_LENGTH(kMetadataKeys); ++index) {
955 wmpKey.Assign(nsDependentString(kMetadataKeys[index].wmpName));
960 if (!value.IsEmpty()) {
962 sbKey.Assign(nsDependentString(kMetadataKeys[index].songbirdName));
964 if (NS_SUCCEEDED(rv)) {
968 NS_WARNING(
"AppendProperty failed!");
974 wmpKey.AssignLiteral(
"HasVideo");
977 wmpKey.AssignLiteral(
"HasAudio");
980 value = EmptyString();
982 if(hasVideo.EqualsLiteral(
"1")) {
983 value = NS_LITERAL_STRING(
"video");
985 else if(hasAudio.EqualsLiteral(
"1")) {
986 value = NS_LITERAL_STRING(
"audio");
992 if(NS_SUCCEEDED(rv)) {
996 NS_WARNING(
"AppendProperty Failed!");
999 hr = reader->Close();
1012 CComPtr<IWMPMedia3> newMedia;
1014 NS_ENSURE_SUCCESS(rv, rv);
1016 for (PRUint32 index = 0; index < NS_ARRAY_LENGTH(kMetadataKeys); ++index) {
1018 CComBSTR
key(kMetadataKeys[index].wmpName);
1019 nsAutoString metadataValue;
1020 PRUint32 metadataValueType = 0;
1026 hr = newMedia->get_duration(&duration);
1028 NS_WARNING(
"get_duration failed!");
1031 double result = duration * PR_USEC_PER_SEC;
1033 AppendInt(metadataValue, static_cast<PRUint64>(result));
1034 metadataValueType = 1;
1038 hr = newMedia->getItemInfo(key, &value);
1040 NS_WARNING(
"getItemInfo failed!");
1045 metadataValue.Assign(value.m_str, value.Length() - 3);
1048 if (value.Length() > 0) {
1049 metadataValue.AssignLiteral(
"1");
1052 metadataValue.Assign(value.m_str);
1056 if (!metadataValue.IsEmpty()) {
1058 sbKey.Assign(nsDependentString(kMetadataKeys[index].songbirdName));
1061 if (NS_SUCCEEDED(rv))
1064 NS_WARNING(
"SetValue failed!");
1069 nsString
value(NS_LITERAL_STRING(
"audio"));
1071 nsCOMPtr<nsILocalFile> localFile =
1072 do_CreateInstance(
"@mozilla.org/file/local;1", &rv);
1073 if (NS_SUCCEEDED(rv) && localFile) {
1074 rv = localFile->InitWithPath(aFilePath);
1075 if (NS_SUCCEEDED(rv)) {
1077 rv = localFile->GetLeafName(leafName);
1078 NS_ENSURE_SUCCESS(rv, rv);
1080 PRInt32 index = leafName.RFindChar(
'.');
1082 nsString extension(StringTail(leafName, leafName.Length() -1 - index));
1084 if (extension.EqualsLiteral(
"wmv") ||
1085 extension.EqualsLiteral(
"wm"))
1087 value.AssignLiteral(
"video");
1095 NS_ENSURE_SUCCESS(rv, rv);
1102 nsACString &aMimeType,
1106 CComPtr<IWMMetadataEditor> reader;
1107 HRESULT hr = WMCreateEditor(&reader);
1110 nsAutoString filePath(aFilePath);
1113 hr = reader->Open(filePath.get());
1115 TRACE((
"%s: failed to open file %s, assuming protected",
1117 NS_ConvertUTF16toUTF8(filePath).
get()));
1118 return NS_ERROR_FAILURE;
1121 CComPtr<IWMHeaderInfo3> headerInfo;
1122 hr = reader->QueryInterface(&headerInfo);
1127 hr = headerInfo->GetAttributeIndices(0xFFFF,
1133 NS_ENSURE_TRUE(count, NS_ERROR_NO_CONTENT);
1137 NS_ENSURE_TRUE(indices, NS_ERROR_OUT_OF_MEMORY);
1140 hr = headerInfo->GetAttributeIndices(0xFFFF,
1148 WMT_ATTR_DATATYPE type;
1154 hr = headerInfo->GetAttributeByIndexEx(0xFFFF,
1166 NS_ENSURE_TRUE(data, NS_ERROR_OUT_OF_MEMORY);
1169 hr = headerInfo->GetAttributeByIndexEx(0xFFFF,
1178 NS_ENSURE_TRUE(type == WMT_TYPE_BINARY, NS_ERROR_UNEXPECTED);
1181 WM_PICTURE *picData = (WM_PICTURE*)data.
get();
1182 CopyUTF16toUTF8(nsDependentString(picData->pwszMIMEType), aMimeType);
1183 *aData =
static_cast<PRUint8*
>(
SB_CloneMemory(picData->pbData, picData->dwDataLen));
1184 NS_ENSURE_TRUE(*aData, NS_ERROR_OUT_OF_MEMORY);
1185 *aDataLen = picData->dwDataLen;
1187 hr = reader->Close();
1194 nsACString &aMimeType,
1201 CComPtr<IWMPMedia3> newMedia;
1203 NS_ENSURE_SUCCESS(rv, rv);
1207 CComBSTR
key(g_wszWMPicture);
1208 hr = newMedia->getAttributeCountByType(key, NULL, &count);
1211 for (
long idx = 0; idx <
count; ++idx) {
1213 hr = newMedia->getItemInfoByType(key, NULL, idx, &var);
1216 CComPtr<IWMPMetadataPicture> picture;
1217 switch(V_VT(&var)) {
1219 hr = var.pdispVal->QueryInterface(&picture);
1221 case VT_DISPATCH | VT_BYREF:
1222 if (!var.ppdispVal) {
1223 nsresult __rv = NS_ERROR_INVALID_POINTER;
1224 NS_ENSURE_SUCCESS_BODY(hr, hr);
1227 hr = (*(var.ppdispVal))->QueryInterface(&picture);
1230 TRACE((
"%s: don't know how to deal with WM/Picture variant type %i",
1231 __FUNCTION__, var.vt));
1235 if (FAILED(hr) || NS_UNLIKELY(!picture)) {
1236 nsresult __rv = NS_ERROR_NO_INTERFACE;
1237 NS_ENSURE_SUCCESS_BODY(hr, hr);
1251 hr = picture->get_URL(&url);
1254 DWORD entrySize = 0;
1255 BOOL success = GetUrlCacheEntryInfo(url, NULL, &entrySize);
1256 NS_ENSURE_TRUE(!success && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1258 NS_ASSERTION(entrySize > 0,
"Unexpected entry size");
1261 (INTERNET_CACHE_ENTRY_INFO*)NS_Alloc(entrySize);
1262 NS_ENSURE_TRUE(cacheInfo, NS_ERROR_OUT_OF_MEMORY);
1264 cacheInfo.
get()->dwStructSize =
sizeof(INTERNET_CACHE_ENTRY_INFO);
1266 success = GetUrlCacheEntryInfo(url, cacheInfo.
get(), &entrySize);
1267 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
1270 nsCOMPtr<nsILocalFile> file =
1271 do_CreateInstance(
"@mozilla.org/file/local;1", &rv);
1272 NS_ENSURE_SUCCESS(rv, rv);
1274 rv = file->InitWithPath(nsDependentString(cacheInfo.
get()->lpszLocalFileName));
1275 NS_ENSURE_SUCCESS(rv, rv);
1278 rv = file->GetFileSize(&fileSize);
1279 NS_ENSURE_SUCCESS(rv, rv);
1282 NS_ENSURE_TRUE(fileData, NS_ERROR_OUT_OF_MEMORY);
1284 nsCOMPtr<nsIFileInputStream> fileStream =
1285 do_CreateInstance(
"@mozilla.org/network/file-input-stream;1", &rv);
1286 NS_ENSURE_SUCCESS(rv, rv);
1288 rv = fileStream->Init(file,
PR_RDONLY, -1, nsIFileInputStream::CLOSE_ON_EOF);
1289 NS_ENSURE_SUCCESS(rv, rv);
1292 rv = fileStream->Read((
char*)fileData.
get(), (PRUint32)fileSize, &bytesRead);
1293 NS_ENSURE_SUCCESS(rv, rv);
1297 rv = fileStream->Close();
1298 NS_ENSURE_SUCCESS(rv, rv);
1302 hr = picture->get_mimeType(&mimeType);
1304 aMimeType.Assign(NS_ConvertUTF16toUTF8(nsDependentString(mimeType)));
1306 *aDataLen = bytesRead;
1307 *aData = fileData.
forget();
1313 return NS_ERROR_FAILURE;
1318 sbMetadataHandlerWMA::IsDRMProtected(
const nsAString &
aPath,
1321 NS_ENSURE_ARG_POINTER(_retval);
1323 HRESULT hr = WMIsContentProtected(aPath.BeginReading(), &isProtected);
1324 *_retval = isProtected;
1325 return SUCCEEDED(hr) ?
NS_OK : NS_ERROR_FAILURE;
void * SB_CloneMemory(const void *ptr, PRSize size)
Clone a block of contiguous memory.
TCHAR const *const wmpName
PRUnichar const *const songbirdName
nsresult sbReadFile(nsIFile *aFile, nsACString &aBuffer)
An interface to carry around arrays of nsIProperty instances Note that implementations of the interfa...
const sbCreateProxiedComponent do_ProxiedGetService(const nsCID &aCID, nsresult *error=0)
#define SB_PROPERTY_CONTENTTYPE
_dialogDatepicker settings
_getSelectedPageStyle s i
#define SB_PROPERTY_PRIMARYIMAGEURL
_updateTextAndScrollDataForFrame aData