9ce643d077800460beb24b233c754390d1a89b47
[platform/framework/web/crosswalk.git] / src / xwalk / application / browser / installer / wgt_package.cc
1 // Copyright (c) 2013 Intel Corporation. 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 "xwalk/application/browser/installer/wgt_package.h"
6
7 #include "base/file_util.h"
8 #include "third_party/libxml/chromium/libxml_utils.h"
9 #include "xwalk/application/common/id_util.h"
10
11 namespace xwalk {
12 namespace application {
13 namespace {
14 #if defined(OS_TIZEN)
15 const char kIdNodeName[] = "application";
16 #else
17 const char kIdNodeName[] = "widget";
18 #endif
19 }
20
21 WGTPackage::~WGTPackage() {
22 }
23
24 WGTPackage::WGTPackage(const base::FilePath& path)
25   : Package(path) {
26   if (!base::PathExists(path))
27     return;
28   base::FilePath extracted_path;
29   if (!Extract(&extracted_path))
30     return;
31
32   XmlReader xml;
33   if (!xml.LoadFile(extracted_path.Append(FILE_PATH_LITERAL("config.xml"))
34                     .MaybeAsASCII())) {
35     LOG(ERROR) << "Unable to load WGT package config.xml file.";
36     return;
37   }
38
39   while (!xml.SkipToElement()) {
40     if (!xml.Read()) {
41       LOG(ERROR) << "Unable to read WGT package config.xml file.";
42       return;
43     }
44   }
45
46   std::string value;
47   while (xml.Read()) {
48     std::string node_name = xml.NodeName();
49     if (node_name == kIdNodeName) {
50       xml.NodeAttribute("id", &value);
51       break;
52     }
53   }
54
55   if (!value.empty())
56     id_ = GenerateId(value);
57
58   is_valid_ = true;
59
60   scoped_ptr<ScopedStdioHandle> file(
61         new ScopedStdioHandle(base::OpenFile(path, "rb")));
62
63   file_ = file.Pass();
64 }
65
66 }  // namespace application
67 }  // namespace xwalk