1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/utility/media_galleries/itunes_pref_parser_win.h" 6 7 #include "base/base64.h" 8 #include "base/strings/string_util.h" 9 #include "chrome/common/media_galleries/itunes_xml_utils.h" 10 #include "third_party/libxml/chromium/libxml_utils.h" 11 12 namespace itunes { 13 14 base::FilePath::StringType FindLibraryLocationInPrefXml( 15 const std::string& pref_xml_data) { 16 XmlReader reader; 17 base::FilePath::StringType result; 18 19 if (!reader.Load(pref_xml_data)) 20 return result; 21 22 // Find the plist node and then search within that tag. 23 if (!SeekToNodeAtCurrentDepth(&reader, "plist")) 24 return result; 25 if (!reader.Read()) 26 return result; 27 28 if (!SeekToNodeAtCurrentDepth(&reader, "dict")) 29 return result; 30 31 if (!SeekInDict(&reader, "User Preferences")) 32 return result; 33 34 if (!SeekToNodeAtCurrentDepth(&reader, "dict")) 35 return result; 36 37 if (!SeekInDict(&reader, "iTunes Library XML Location:1")) 38 return result; 39 40 if (!SeekToNodeAtCurrentDepth(&reader, "data")) 41 return result; 42 43 std::string pref_value; 44 if (!reader.ReadElementContent(&pref_value)) 45 return result; 46 // The data is a base64 encoded wchar_t*. Because Base64Decode uses 47 // std::strings, the result has to be casted to a wchar_t*. 48 std::string data; 49 if (!base::Base64Decode(CollapseWhitespaceASCII(pref_value, true), &data)) 50 return result; 51 return base::FilePath::StringType( 52 reinterpret_cast<const wchar_t*>(data.data()), data.size() / 2); 53 } 54 55 } // namespace itunes 56