Upstream version 7.35.141.0
[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   type_ = WGT;
29   base::FilePath extracted_path;
30   if (!Extract(&extracted_path))
31     return;
32
33   XmlReader xml;
34   if (!xml.LoadFile(extracted_path.Append(FILE_PATH_LITERAL("config.xml"))
35                     .MaybeAsASCII())) {
36     LOG(ERROR) << "Unable to load WGT package config.xml file.";
37     return;
38   }
39
40   while (!xml.SkipToElement()) {
41     if (!xml.Read()) {
42       LOG(ERROR) << "Unable to read WGT package config.xml file.";
43       return;
44     }
45   }
46
47   std::string value;
48   while (xml.Read()) {
49     std::string node_name = xml.NodeName();
50     if (node_name == kIdNodeName) {
51       xml.NodeAttribute("id", &value);
52       break;
53     }
54   }
55
56   if (!value.empty())
57     id_ = GenerateId(value);
58
59   is_valid_ = true;
60
61   scoped_ptr<ScopedStdioHandle> file(
62         new ScopedStdioHandle(base::OpenFile(path, "rb")));
63
64   file_ = file.Pass();
65 }
66
67 }  // namespace application
68 }  // namespace xwalk