54 #include <sbFileUtils.h>
55 #include <sbIDeviceProperties.h>
56 #include <sbIDirectoryEnumerator.h>
64 #include <nsIDOMNamedNodeMap.h>
65 #include <nsIDOMNodeList.h>
66 #include <nsIDOMParser.h>
67 #include <nsIDOMSerializer.h>
68 #include <nsIMutableArray.h>
69 #include <nsIPropertyBag2.h>
70 #include <nsIScriptSecurityManager.h>
71 #include <nsISupportsPrimitives.h>
72 #include <nsIWritablePropertyBag.h>
73 #include <nsIXMLHttpRequest.h>
75 #include <nsNetUtil.h>
76 #include <nsServiceManagerUtils.h>
77 #include <nsThreadUtils.h>
78 #include <nsUnicharUtils.h>
79 #include <nsVersionComparator.h>
94 const char* aExtensionsList)
96 NS_ENSURE_ARG_POINTER(aDeviceXMLInfoSpecList);
100 Log(
"URI list:\n%s", aDeviceXMLInfoSpecList);
104 nsTArray<nsCString>
uris;
106 NS_LITERAL_CSTRING(
" "),
109 if (!aExtensionsList) {
110 aExtensionsList =
"";
115 const PRUint32 COUNT = uris.Length();
116 for (PRUint32
i = 0;
i < COUNT;
i++) {
117 const nsCString & uriStr = uris[
i];
120 if (uriStr.IsEmpty()) {
125 nsCOMPtr<nsIURI>
uri;
126 rv =
SB_NewURI(getter_AddRefs(uri), uriStr);
127 LogIfFailed(rv,
"Invalid URI\n%s", uriStr.get());
128 NS_ENSURE_SUCCESS(rv, rv);
131 rv =
Read(uri, NS_ConvertUTF8toUTF16(nsDependentCString(aExtensionsList)));
132 LogIfFailed(rv,
"while reading device info from\n%s", uriStr.get());
133 NS_ENSURE_SUCCESS(rv, rv);
145 const nsAString & aExtensionsList)
147 NS_ENSURE_ARG_POINTER(aDeviceXMLInfoURI);
152 rv = aDeviceXMLInfoURI->GetSpec(spec);
153 Log(
"Reading %s", spec.BeginReading());
157 nsCOMPtr<nsIFileURL> fileUrl = do_QueryInterface(aDeviceXMLInfoURI);
159 nsCOMPtr<nsIFile>
file;
160 rv = fileUrl->GetFile(getter_AddRefs(file));
161 NS_ENSURE_SUCCESS(rv, rv);
163 rv =
Read(file, aExtensionsList);
164 NS_ENSURE_SUCCESS(rv, rv);
169 nsCOMPtr<nsIInputStream> inputStream;
170 rv = NS_OpenURI(getter_AddRefs(inputStream), aDeviceXMLInfoURI);
171 NS_ENSURE_SUCCESS(rv, rv);
174 rv =
Read(inputStream);
175 inputStream->Close();
176 NS_ENSURE_SUCCESS(rv, rv);
188 const nsAString & aExtensionsList)
190 NS_ENSURE_ARG_POINTER(aDeviceXMLInfoFile);
195 rv = aDeviceXMLInfoFile->GetPath(path);
197 path = NS_LITERAL_STRING(
"Unknown path");
202 PRBool isDir = PR_FALSE;
203 rv = aDeviceXMLInfoFile->IsDirectory(&isDir);
204 NS_ENSURE_SUCCESS(rv, rv);
206 Log(
"Searching directory %s",
207 NS_LossyConvertUTF16toASCII(path).BeginReading());
211 nsString acceptExts(aExtensionsList);
212 acceptExts.Trim(
" ");
213 Log(
"Extension List: %s",
214 NS_LossyConvertUTF16toASCII(acceptExts).BeginReading());
215 if (acceptExts.IsEmpty()) {
222 ToLowerCase(acceptExts);
223 acceptExts.Insert(
' ', 0);
224 acceptExts.Append(
' ');
227 nsCOMPtr<sbIDirectoryEnumerator> scanner =
229 NS_ENSURE_SUCCESS(rv, rv);
231 rv = scanner->SetFilesOnly(PR_TRUE);
232 NS_ENSURE_SUCCESS(rv, rv);
233 rv = scanner->Enumerate(aDeviceXMLInfoFile);
234 NS_ENSURE_SUCCESS(rv, rv);
237 PRBool more = PR_FALSE;
238 while(NS_SUCCEEDED(rv = scanner->HasMoreElements(&more)) && more)
241 nsCOMPtr<nsIFile> child;
242 rv = scanner->GetNext(getter_AddRefs(child));
243 NS_ENSURE_SUCCESS(rv, rv);
247 rv = child->GetLeafName(extension);
248 NS_ENSURE_SUCCESS(rv, rv);
249 extension.Cut(0, extension.RFindChar(
'.') + 1);
250 ToLowerCase(extension);
251 extension.Insert(
' ', 0);
252 extension.Append(
' ');
256 if (acceptExts.Find(extension) != -1) {
257 rv =
Read(child, aExtensionsList);
260 "Could not read device XML info from file in search directory");
263 NS_ENSURE_SUCCESS(rv, rv);
268 nsCOMPtr<nsIInputStream> inputStream;
270 NS_ENSURE_SUCCESS(rv, rv);
272 Log(
"Parsing file %s",
273 NS_LossyConvertUTF16toASCII(path).BeginReading());
275 rv =
Read(inputStream);
276 inputStream->Close();
277 NS_ENSURE_SUCCESS(rv, rv);
289 NS_ENSURE_ARG_POINTER(aDeviceXMLInfoStream);
291 nsresult rv = NS_ERROR_UNEXPECTED;
292 nsCOMPtr<nsIDOMParser> parser =
293 do_CreateInstance(NS_DOMPARSER_CONTRACTID, &rv);
294 NS_ENSURE_SUCCESS(rv, rv);
296 PRUint32 streamSize = 0;
297 rv = aDeviceXMLInfoStream->Available(&streamSize);
298 NS_ENSURE_SUCCESS(rv, rv);
300 nsCOMPtr<nsIDOMDocument> document;
301 rv = parser->ParseFromStream(aDeviceXMLInfoStream,
305 getter_AddRefs(document));
306 NS_ENSURE_SUCCESS(rv, rv);
309 NS_ENSURE_SUCCESS(rv, rv);
322 NS_ENSURE_ARG_POINTER(aDeviceXMLInfoDocument);
328 nsCOMPtr<nsIDOMNodeList> nodeList;
329 rv = aDeviceXMLInfoDocument->GetElementsByTagNameNS
331 NS_LITERAL_STRING(
"deviceinfo"),
332 getter_AddRefs(nodeList));
333 NS_ENSURE_SUCCESS(rv, rv);
337 rv = nodeList->GetLength(&nodeCount);
338 NS_ENSURE_SUCCESS(rv, rv);
339 for (PRUint32
i = 0;
i < nodeCount;
i++) {
341 nsCOMPtr<nsIDOMNode>
node;
342 rv = nodeList->Item(
i, getter_AddRefs(node));
343 NS_ENSURE_SUCCESS(rv, rv);
347 nsString foundVersion;
348 nsCOMPtr<nsIDOMNode> deviceNode;
349 rv = DeviceMatchesDeviceInfoNode(node,
351 getter_AddRefs(deviceNode));
352 NS_ENSURE_SUCCESS(rv, rv);
353 if (foundVersion.IsEmpty()) {
358 if (mDeviceInfoVersion.IsEmpty() ||
360 NS_LossyConvertUTF16toASCII(foundVersion).
get(),
361 NS_LossyConvertUTF16toASCII(mDeviceInfoVersion).
get()) > 0)
367 if (mLogDeviceInfo) {
368 nsCOMPtr<nsIDOMSerializer> serializer =
369 do_CreateInstance(
"@mozilla.org/xmlextras/xmlserializer;1");
372 nsString fullXml(NS_LITERAL_STRING(
"<ERROR PRINTING deviceinfo NODE>"));
374 serializer->SerializeToString(node, fullXml);
378 nsString deviceXml(NS_LITERAL_STRING(
"<ERROR PRINTING device NODE>"));
379 if (deviceNode && serializer) {
380 serializer->SerializeToString(deviceNode, deviceXml);
383 nsCAutoString curVersUtf8 = NS_ConvertUTF16toUTF8(mDeviceInfoVersion);
384 nsCAutoString foundVersUtf8 = NS_ConvertUTF16toUTF8(foundVersion);
394 Log(
"%s deviceinfo version %s%s%s:\n%s%s%s",
395 mDeviceInfoElement ?
"REPLACED" :
"FOUND",
397 mDeviceInfoElement ?
" with " :
"",
400 NS_ConvertUTF16toUTF8(fullXml).get(),
402 deviceNode ?
"\n\nMATCHING device element:\n" :
"",
403 deviceNode ? NS_ConvertUTF16toUTF8(deviceXml).get() :
"");
406 mDeviceInfoVersion.Assign(foundVersion);
407 mDeviceInfoElement = do_QueryInterface(node, &rv);
408 NS_ENSURE_SUCCESS(rv, rv);
410 mDeviceElement = do_QueryInterface(deviceNode, &rv);
411 NS_ENSURE_SUCCESS(rv, rv);
414 mDeviceElement = nsnull;
432 NS_ENSURE_ARG_POINTER(aDeviceInfoPresent);
435 if (mDeviceInfoElement)
436 *aDeviceInfoPresent = PR_TRUE;
438 *aDeviceInfoPresent = PR_FALSE;
452 NS_ENSURE_ARG_POINTER(aDeviceInfoElement);
453 NS_IF_ADDREF(*aDeviceInfoElement = mDeviceInfoElement);
467 aDefaultName.SetIsVoid(PR_TRUE);
470 if (!mDeviceInfoElement)
473 nsTArray< nsCOMPtr<nsIDOMNode> > deviceNameNodeList;
474 rv = GetDeviceInfoNodes(NS_LITERAL_STRING(
"name"),
476 NS_ENSURE_SUCCESS(rv, rv);
479 PRUint32 nodeCount = deviceNameNodeList.Length();
483 nsCOMPtr<nsIDOMElement> deviceNameElement =
484 do_QueryInterface(deviceNameNodeList[0], &rv);
485 NS_ENSURE_SUCCESS(rv, rv);
488 rv = deviceNameElement->GetAttribute(NS_LITERAL_STRING(
"value"),
490 NS_ENSURE_SUCCESS(rv, rv);
503 nsAString& aFolderURL)
508 aFolderURL.SetIsVoid(PR_TRUE);
511 if (!mDeviceInfoElement)
515 nsTArray< nsCOMPtr<nsIDOMNode> > folderNodeList;
516 rv = GetDeviceInfoNodes(NS_LITERAL_STRING(
"folder"), folderNodeList);
517 NS_ENSURE_SUCCESS(rv, rv);
520 PRUint32 nodeCount = folderNodeList.Length();
521 for (PRUint32
i = 0;
i < nodeCount;
i++) {
523 nsCOMPtr<nsIDOMElement> folderElement;
524 folderElement = do_QueryInterface(folderNodeList[
i], &rv);
529 nsAutoString folderType;
530 rv = folderElement->GetAttribute(NS_LITERAL_STRING(
"type"), folderType);
533 if (folderType.Equals(aFolderType)) {
534 rv = folderElement->GetAttribute(NS_LITERAL_STRING(
"url"), aFolderURL);
535 NS_ENSURE_SUCCESS(rv, rv);
551 nsAString& aFolderURL)
556 static const char* folderContentTypeMap[] = {
568 aFolderURL.Truncate();
571 if (aContentType >= NS_ARRAY_LENGTH(folderContentTypeMap))
575 nsAutoString folderType;
576 folderType.AssignLiteral(folderContentTypeMap[aContentType]);
577 if (folderType.IsEmpty())
582 NS_ENSURE_SUCCESS(rv, rv);
595 NS_ENSURE_ARG_POINTER(aImportRules);
600 *aImportRules = NULL;
603 if (!mDeviceInfoElement) {
612 nsTArray< nsCOMPtr<nsIDOMNode> > importNodeList;
613 rv = GetDeviceInfoNodes(NS_LITERAL_STRING(
"import"), importNodeList);
614 NS_ENSURE_SUCCESS(rv, rv);
620 nsCOMPtr<nsIMutableArray> rules =
621 do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
622 NS_ENSURE_SUCCESS(rv, rv);
625 PRUint32 nodeCount = importNodeList.Length();
626 for (PRUint32
i = 0;
i < nodeCount;
i++) {
628 nsCOMPtr<nsIDOMElement> importElement;
629 importElement = do_QueryInterface(importNodeList[
i], &rv);
635 nsAutoString urlAttr;
636 rv = importElement->GetAttribute(NS_LITERAL_STRING(
"url"), urlAttr);
639 if (urlAttr.IsEmpty())
643 nsAutoString typeAttr;
644 rv = importElement->GetAttribute(NS_LITERAL_STRING(
"type"), typeAttr);
647 if (typeAttr.IsEmpty())
651 nsCOMPtr<nsIMutableArray> rule =
652 do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
653 NS_ENSURE_SUCCESS(rv, rv);
656 nsCOMPtr<nsISupportsString> folder =
657 do_CreateInstance(
"@mozilla.org/supports-string;1", &rv);
658 NS_ENSURE_SUCCESS(rv, rv);
659 rv = folder->SetData(urlAttr);
660 NS_ENSURE_SUCCESS(rv, rv);
661 rv = rule->AppendElement(folder, PR_FALSE);
662 NS_ENSURE_SUCCESS(rv, rv);
665 nsCOMPtr<nsISupportsString> importType =
666 do_CreateInstance(
"@mozilla.org/supports-string;1", &rv);
667 NS_ENSURE_SUCCESS(rv, rv);
668 rv = importType->SetData(typeAttr);
669 NS_ENSURE_SUCCESS(rv, rv);
670 rv = rule->AppendElement(importType, PR_FALSE);
671 NS_ENSURE_SUCCESS(rv, rv);
674 rv = rules->AppendElement(rule, PR_FALSE);
675 NS_ENSURE_SUCCESS(rv, rv);
679 NS_ADDREF(*aImportRules = rules.get());
693 aExcludedFolders.Truncate();
696 if (!mDeviceInfoElement)
700 nsTArray< nsCOMPtr<nsIDOMNode> > excludeNodeList;
701 rv = GetDeviceInfoNodes(NS_LITERAL_STRING(
"excludefolder"), excludeNodeList);
702 NS_ENSURE_SUCCESS(rv, rv);
705 PRUint32 nodeCount = excludeNodeList.Length();
706 const char * delimiter =
"";
707 for (PRUint32
i = 0;
i < nodeCount;
i++) {
709 nsCOMPtr<nsIDOMElement> excludeElement;
710 excludeElement = do_QueryInterface(excludeNodeList[
i], &rv);
711 if (NS_SUCCEEDED(rv)) {
717 rv = excludeElement->GetAttribute(NS_LITERAL_STRING(
"url"), excludeStr);
718 NS_ENSURE_SUCCESS(rv, rv);
719 if (excludeStr.Length() > 0 && excludeStr[0] == L
'/') {
720 excludeStr.Cut(0, 1);
722 if (!excludeStr.IsEmpty()) {
723 aExcludedFolders.AppendLiteral(delimiter);
724 aExcludedFolders.Append(excludeStr);
731 rv = excludeElement->GetAttribute(NS_LITERAL_STRING(
"match"), excludeStr);
732 NS_ENSURE_SUCCESS(rv, rv);
733 if (!excludeStr.IsEmpty() && excludeStr.Find(
"/") == -1) {
734 aExcludedFolders.AppendLiteral(delimiter);
735 aExcludedFolders.AppendLiteral(
"/");
736 aExcludedFolders.Append(excludeStr);
737 aExcludedFolders.AppendLiteral(
"/");
755 NS_ENSURE_ARG_POINTER(aMountTimeout);
761 if (!mDeviceInfoElement)
762 return NS_ERROR_NOT_AVAILABLE;
765 nsTArray< nsCOMPtr<nsIDOMNode> > mountTimeoutNodeList;
766 rv = GetDeviceInfoNodes(NS_LITERAL_STRING(
"mounttimeout"),
767 mountTimeoutNodeList);
768 NS_ENSURE_SUCCESS(rv, rv);
771 PRUint32 nodeCount = mountTimeoutNodeList.Length();
773 return NS_ERROR_NOT_AVAILABLE;
776 nsCOMPtr<nsIDOMElement> mountTimeoutElement;
777 mountTimeoutElement = do_QueryInterface(mountTimeoutNodeList[0], &rv);
778 NS_ENSURE_SUCCESS(rv, rv);
781 nsAutoString mountTimeoutString;
782 rv = mountTimeoutElement->GetAttribute(NS_LITERAL_STRING(
"value"),
784 NS_ENSURE_SUCCESS(rv, rv);
787 PRUint32 mountTimeout;
788 mountTimeout = mountTimeoutString.ToInteger(&rv);
789 NS_ENSURE_SUCCESS(rv, rv);
790 *aMountTimeout = mountTimeout;
804 NS_ENSURE_ARG_POINTER(aOutSupportsReformat);
805 *aOutSupportsReformat = PR_FALSE;
808 NS_ENSURE_TRUE(mDeviceInfoElement, NS_ERROR_NOT_AVAILABLE);
811 nsTArray< nsCOMPtr<nsIDOMNode> > supportsFormatNodeList;
812 rv = GetDeviceInfoNodes(NS_LITERAL_STRING(
"supportsreformat"),
813 supportsFormatNodeList);
814 NS_ENSURE_SUCCESS(rv, rv);
817 PRUint32 nodeCount = supportsFormatNodeList.Length();
821 nsCOMPtr<nsIDOMElement> supportsFormatElement =
822 do_QueryInterface(supportsFormatNodeList[0], &rv);
823 NS_ENSURE_SUCCESS(rv, rv);
826 nsString supportsFormatValue;
827 rv = supportsFormatElement->GetAttribute(NS_LITERAL_STRING(
"value"),
828 supportsFormatValue);
829 NS_ENSURE_SUCCESS(rv, rv);
831 if (supportsFormatValue.Equals(NS_LITERAL_STRING(
"true"),
832 CaseInsensitiveCompare)) {
833 *aOutSupportsReformat = PR_TRUE;
851 NS_ENSURE_ARG_POINTER(aOnlyMountMediaFolders);
852 NS_ASSERTION(NS_IsMainThread(),
"not on main thread");
858 *aOnlyMountMediaFolders = PR_FALSE;
861 if (!mDeviceInfoElement)
865 nsTArray< nsCOMPtr<nsIDOMNode> > onlyMountMediaFoldersNodeList;
866 rv = GetDeviceInfoNodes(NS_LITERAL_STRING(
"onlymountmediafolders"),
867 onlyMountMediaFoldersNodeList);
868 NS_ENSURE_SUCCESS(rv, rv);
871 PRUint32 nodeCount = onlyMountMediaFoldersNodeList.Length();
876 nsCOMPtr<nsIDOMElement> onlyMountMediaFoldersElement;
877 onlyMountMediaFoldersElement =
878 do_QueryInterface(onlyMountMediaFoldersNodeList[0], &rv);
879 NS_ENSURE_SUCCESS(rv, rv);
882 nsAutoString valueString;
883 rv = onlyMountMediaFoldersElement->GetAttribute(NS_LITERAL_STRING(
"value"),
885 NS_ENSURE_SUCCESS(rv, rv);
888 *aOnlyMountMediaFolders = valueString.Equals(NS_LITERAL_STRING(
"true"),
889 CaseInsensitiveCompare);
904 NS_ENSURE_ARG_POINTER(aStorageDeviceInfoList);
905 NS_ASSERTION(NS_IsMainThread(),
"not on main thread");
912 if (!mDeviceInfoElement)
913 return NS_ERROR_NOT_AVAILABLE;
916 nsTArray< nsCOMPtr<nsIDOMNode> > storageNodeList;
917 rv = GetDeviceInfoNodes(NS_LITERAL_STRING(
"storage"), storageNodeList);
918 NS_ENSURE_SUCCESS(rv, rv);
921 nsCOMPtr<nsIMutableArray> storageDeviceInfoList =
922 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
923 NS_ENSURE_SUCCESS(rv, rv);
926 PRUint32 nodeCount = storageNodeList.Length();
927 for (PRUint32 nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex) {
929 nsCOMPtr<nsIDOMNode> storageDeviceNode = storageNodeList[nodeIndex];
933 PRUint32 attributeCount;
934 rv = storageDeviceNode->GetAttributes(getter_AddRefs(attributes));
935 NS_ENSURE_SUCCESS(rv, rv);
936 rv = attributes->GetLength(&attributeCount);
937 NS_ENSURE_SUCCESS(rv, rv);
940 nsCOMPtr<nsIWritablePropertyBag> storageDeviceInfo =
941 do_CreateInstance(
"@mozilla.org/hash-property-bag;1", &rv);
942 NS_ENSURE_SUCCESS(rv, rv);
945 for (PRUint32 attributeIndex = 0;
946 attributeIndex < attributeCount;
949 nsCOMPtr<nsIDOMNode> attribute;
950 rv = attributes->Item(attributeIndex, getter_AddRefs(attribute));
951 NS_ENSURE_SUCCESS(rv, rv);
954 nsAutoString attributeName;
955 rv = attribute->GetNodeName(attributeName);
956 NS_ENSURE_SUCCESS(rv, rv);
959 nsAutoString attributeValue;
960 rv = attribute->GetNodeValue(attributeValue);
961 NS_ENSURE_SUCCESS(rv, rv);
964 storageDeviceInfo->SetProperty(attributeName,
966 NS_ENSURE_SUCCESS(rv, rv);
970 rv = storageDeviceInfoList->AppendElement(storageDeviceInfo, PR_FALSE);
971 NS_ENSURE_SUCCESS(rv, rv);
975 rv = CallQueryInterface(storageDeviceInfoList, aStorageDeviceInfoList);
976 NS_ENSURE_SUCCESS(rv, rv);
993 aDeviceIconURL.SetIsVoid(PR_TRUE);
996 if (!mDeviceInfoElement)
1000 nsTArray< nsCOMPtr<nsIDOMNode> > deviceIconNodeList;
1001 rv = GetDeviceInfoNodes(NS_LITERAL_STRING(
"deviceicon"),
1002 deviceIconNodeList);
1003 NS_ENSURE_SUCCESS(rv, rv);
1006 PRUint32 nodeCount = deviceIconNodeList.Length();
1011 nsCOMPtr<nsIDOMElement> deviceIconElement;
1012 deviceIconElement = do_QueryInterface(deviceIconNodeList[0], &rv);
1013 NS_ENSURE_SUCCESS(rv, rv);
1016 rv = deviceIconElement->GetAttribute(NS_LITERAL_STRING(
"url"),
1018 NS_ENSURE_SUCCESS(rv, rv);
1058 sbDeviceXMLInfo::DeviceMatchesDeviceInfoNode(nsIDOMNode* aDeviceInfoNode,
1059 nsAString & aFoundVersion,
1060 nsIDOMNode** aDeviceNode)
1063 NS_ENSURE_ARG_POINTER(aDeviceInfoNode);
1071 *aDeviceNode = nsnull;
1075 nsCOMPtr<nsIDOMNode> devicesNode;
1076 nsCOMPtr<nsIDOMNodeList> devicesNodeList;
1077 nsCOMPtr<nsIDOMElement>
1078 deviceInfoElement = do_QueryInterface(aDeviceInfoNode, &rv);
1079 NS_ENSURE_SUCCESS(rv, rv);
1080 rv = deviceInfoElement->GetElementsByTagNameNS
1082 NS_LITERAL_STRING(
"devices"),
1083 getter_AddRefs(devicesNodeList));
1084 NS_ENSURE_SUCCESS(rv, rv);
1085 rv = devicesNodeList->GetLength(&nodeCount);
1086 NS_ENSURE_SUCCESS(rv, rv);
1088 rv = GetDeviceInfoVersion(deviceInfoElement, aFoundVersion);
1089 NS_ENSURE_SUCCESS(rv, rv);
1092 rv = devicesNodeList->Item(0, getter_AddRefs(devicesNode));
1093 NS_ENSURE_SUCCESS(rv, rv);
1098 aFoundVersion.Truncate();
1103 nsCOMPtr<sbIDeviceProperties> deviceProperties;
1104 rv = mDevice->GetProperties(getter_AddRefs(deviceProperties));
1105 NS_ENSURE_SUCCESS(rv, rv);
1106 nsCOMPtr<nsIPropertyBag2> properties;
1107 rv = deviceProperties->GetProperties(getter_AddRefs(properties));
1108 NS_ENSURE_SUCCESS(rv, rv);
1111 nsCOMPtr<nsIDOMNodeList> childNodeList;
1112 rv = devicesNode->GetChildNodes(getter_AddRefs(childNodeList));
1113 NS_ENSURE_SUCCESS(rv, rv);
1114 if (!childNodeList) {
1116 aFoundVersion.Truncate();
1121 rv = childNodeList->GetLength(&nodeCount);
1122 NS_ENSURE_SUCCESS(rv, rv);
1123 for (PRUint32 nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex) {
1125 nsCOMPtr<nsIDOMNode> childNode;
1126 rv = childNodeList->Item(nodeIndex, getter_AddRefs(childNode));
1127 NS_ENSURE_SUCCESS(rv, rv);
1131 rv = childNode->GetNodeName(nodeName);
1132 NS_ENSURE_SUCCESS(rv, rv);
1133 if (!nodeName.EqualsLiteral(
"device")) {
1139 rv = DeviceMatchesDeviceNode(childNode, properties, &matches);
1140 NS_ENSURE_SUCCESS(rv, rv);
1142 rv = GetDeviceInfoVersion(deviceInfoElement, aFoundVersion);
1143 NS_ENSURE_SUCCESS(rv, rv);
1145 childNode.forget(aDeviceNode);
1151 aFoundVersion.Truncate();
1161 nsresult sbDeviceXMLInfo::GetDeviceInfoVersion(
1162 nsIDOMElement * aDeviceInfoElement,
1163 nsAString & aVersion)
1165 NS_ENSURE_ARG_POINTER(aDeviceInfoElement);
1169 NS_NAMED_LITERAL_STRING(VERSION_ATTR,
"version");
1173 aVersion.Truncate();
1174 aDeviceInfoElement->GetAttribute(VERSION_ATTR, aVersion);
1175 if (!aVersion.IsEmpty())
1181 nsCOMPtr<nsIDOMNode> parentNode;
1182 rv = aDeviceInfoElement->GetParentNode(getter_AddRefs(parentNode));
1183 NS_ENSURE_SUCCESS(rv, rv);
1184 nsCOMPtr<nsIDOMElement> parent =
1185 do_QueryInterface(parentNode, &rv);
1186 NS_ENSURE_SUCCESS(rv, rv);
1188 parent->GetAttribute(VERSION_ATTR, aVersion);
1189 if (!aVersion.IsEmpty())
1195 aVersion.AssignLiteral(
"0");
1205 sbDeviceXMLInfo::DeviceMatchesDeviceNode(nsIDOMNode* aDeviceNode,
1206 nsIPropertyBag2* aDeviceProperties,
1207 PRBool* aDeviceMatches)
1209 NS_ENSURE_ARG_POINTER(aDeviceNode);
1210 NS_ENSURE_ARG_POINTER(aDeviceProperties);
1211 NS_ENSURE_ARG_POINTER(aDeviceMatches);
1217 rv = aDeviceNode->GetAttributes(getter_AddRefs(attributes));
1218 NS_ENSURE_SUCCESS(rv, rv);
1221 PRBool matches = PR_TRUE;
1222 PRUint32 attributeCount;
1223 rv = attributes->GetLength(&attributeCount);
1224 NS_ENSURE_SUCCESS(rv, rv);
1225 for (PRUint32 attributeIndex = 0;
1226 attributeIndex < attributeCount;
1229 nsCOMPtr<nsIDOMNode> attribute;
1230 rv = attributes->Item(attributeIndex, getter_AddRefs(attribute));
1231 NS_ENSURE_SUCCESS(rv, rv);
1234 nsAutoString attributeName;
1235 rv = attribute->GetNodeName(attributeName);
1236 NS_ENSURE_SUCCESS(rv, rv);
1239 nsAutoString attributeValue;
1240 rv = attribute->GetNodeValue(attributeValue);
1241 NS_ENSURE_SUCCESS(rv, rv);
1245 deviceKey.Append(attributeName);
1249 rv = aDeviceProperties->HasKey(deviceKey, &hasKey);
1250 NS_ENSURE_SUCCESS(rv, rv);
1257 nsCOMPtr<nsIVariant> deviceValue;
1258 rv = aDeviceProperties->Get(deviceKey, getter_AddRefs(deviceValue));
1259 NS_ENSURE_SUCCESS(rv, rv);
1265 NS_ENSURE_SUCCESS(rv, rv);
1273 *aDeviceMatches = matches;
1285 sbDeviceXMLInfo::GetDeviceInfoNodes
1286 (
const nsAString& aNameSpace,
1287 const nsAString& aTagName,
1288 nsTArray< nsCOMPtr<nsIDOMNode> >& aNodeList)
1297 nsCOMPtr<nsIDOMNodeList> nodeList;
1298 PRUint32 nodeCount = 0;
1299 PRBool areDeviceNodeDescendants = PR_TRUE;
1300 if (mDeviceElement) {
1301 rv = mDeviceElement->GetElementsByTagNameNS(aNameSpace,
1303 getter_AddRefs(nodeList));
1304 NS_ENSURE_SUCCESS(rv, rv);
1305 rv = nodeList->GetLength(&nodeCount);
1306 NS_ENSURE_SUCCESS(rv, rv);
1312 if (mDeviceInfoElement && (!nodeList || !nodeCount)) {
1313 areDeviceNodeDescendants = PR_FALSE;
1314 rv = mDeviceInfoElement->GetElementsByTagNameNS(aNameSpace,
1316 getter_AddRefs(nodeList));
1317 NS_ENSURE_SUCCESS(rv, rv);
1318 rv = nodeList->GetLength(&nodeCount);
1319 NS_ENSURE_SUCCESS(rv, rv);
1323 success = aNodeList.SetCapacity(nodeCount);
1324 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
1325 for (PRUint32
i = 0;
i < nodeCount; ++
i) {
1327 nsCOMPtr<nsIDOMNode>
node;
1328 rv = nodeList->Item(
i, getter_AddRefs(node));
1329 NS_ENSURE_SUCCESS(rv, rv);
1332 if (!areDeviceNodeDescendants) {
1333 PRBool isDeviceNodeDescendant;
1334 rv = IsDeviceNodeDescendant(node, &isDeviceNodeDescendant);
1335 NS_ENSURE_SUCCESS(rv, rv);
1336 if (isDeviceNodeDescendant)
1341 NS_ENSURE_TRUE(aNodeList.AppendElement(node), NS_ERROR_OUT_OF_MEMORY);
1354 sbDeviceXMLInfo::GetDeviceInfoNodes(
const nsAString& aTagName,
1355 nsTArray< nsCOMPtr<nsIDOMNode> >& aNodeList)
1369 sbDeviceXMLInfo::IsDeviceNodeDescendant(nsIDOMNode* aNode,
1370 PRBool* aIsDeviceNodeDescendant)
1373 NS_ENSURE_ARG_POINTER(aNode);
1374 NS_ENSURE_ARG_POINTER(aIsDeviceNodeDescendant);
1380 *aIsDeviceNodeDescendant = PR_FALSE;
1383 nsCOMPtr<nsIDOMNode> node = aNode;
1384 while (node && (node != mDeviceInfoElement)) {
1386 nsAutoString namespaceURI;
1387 nsAutoString localName;
1388 rv = node->GetNamespaceURI(namespaceURI);
1389 NS_ENSURE_SUCCESS(rv, rv);
1390 rv = node->GetLocalName(localName);
1391 NS_ENSURE_SUCCESS(rv, rv);
1396 localName.Equals(NS_LITERAL_STRING(
"device"))) {
1397 *aIsDeviceNodeDescendant = PR_TRUE;
1402 nsCOMPtr<nsIDOMNode> parentNode;
1403 rv = node->GetParentNode(getter_AddRefs(parentNode));
1404 NS_ENSURE_SUCCESS(rv, rv);
1405 node = parentNode.forget();
1412 void sbDeviceXMLInfo::Log(
const char * aFmt, ...)
1414 if (mLogDeviceInfo) {
1416 va_start(args, aFmt);
1417 LogArgs(aFmt, args);
1422 void sbDeviceXMLInfo::LogIfFailed(nsresult aRV,
const char * aPrintf, ...)
1425 if (NS_SUCCEEDED(aRV)) {
1430 if (!mLogDeviceInfo) {
1436 va_start(etc, aPrintf);
1438 PR_vsmprintf(aPrintf ? aPrintf :
"while loading device info", etc);
1442 nsString
msg(NS_LITERAL_STRING(
"sbDeviceXMLInfo "));
1445 msg.AppendLiteral(
":\nERROR [0x");
1446 msg.AppendInt(aRV, 16);
1447 msg.AppendLiteral(
"]\n");
1448 msg.Append(NS_ConvertUTF8toUTF16(why));
1449 PR_smprintf_free(why);
1456 void sbDeviceXMLInfo::LogArgs(
const char * aFmt,
1459 char *
msg = PR_vsmprintf(aFmt, aArgs);
1461 "sbDeviceXMLInfo %s:\n%s",
1464 PR_smprintf_free(msg);
nsresult Read(const char *aDeviceXMLInfoSpecList, const char *aExtensionsList=nsnull)
nsresult sbVariantsEqual(nsIVariant *aVariant1, nsIVariant *aVariant2, PRBool *aEqual)
nsresult sbOpenInputStream(nsAString const &aPath, nsIInputStream **aStream)
Songbird Variant Utility Definitions.
nsresult GetStorageDeviceInfoList(nsIArray **aStorageDeviceInfoList)
Songbird Variant Utility Definitions.
nsresult GetDeviceInfoElement(nsIDOMElement **aDeviceInfoElement)
static nsresult SB_NewURI(nsIURI **aURI, const nsACString &aSpec, const char *aCharSet=nsnull, nsIURI *aBaseURI=nsnull)
#define SB_DIRECTORYENUMERATOR_CONTRACTID
nsresult GetDeviceIcon(nsAString &aDeviceIconURL)
nsresult GetDeviceFolder(const nsAString &aFolderType, nsAString &aFolderURL)
static void Error(char const *aCategory, nsAString const &aMessage, nsAString const &aSource=nsString(), PRUint32 aLine=0)
sbDeviceXMLInfo(sbIDevice *aDevice=nsnull)
nsresult GetDefaultName(nsAString &aDefaultName)
nsresult GetDeviceInfoPresent(PRBool *aDeviceInfoPresent)
virtual ~sbDeviceXMLInfo()
#define SB_DEVICE_PROPERTY_BASE
nsresult GetOnlyMountMediaFolders(PRBool *aOnlyMountMediaFolders)
static void Message(char const *aFmt,...)
void nsCString_Split(const nsACString &aString, const nsACString &aDelimiter, nsTArray< nsCString > &aSubStringArray)
static nsCString GetDeviceIdentifier(sbIDevice *aDevice)
nsresult GetDoesDeviceSupportReformat(PRBool *aOutSupportsReformat)
nsresult GetMountTimeout(PRUint32 *aMountTimeout)
#define SB_DEVICE_INFO_NS
nsresult GetImportRules(nsIArray **aImportRules)
Songbird Device XML Info Definitions.
_getSelectedPageStyle s i
nsresult GetExcludedFolders(nsAString &aExcludedFolders)