Upstream version 11.39.252.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / common / package / package.h
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 #ifndef XWALK_APPLICATION_COMMON_PACKAGE_PACKAGE_H_
6 #define XWALK_APPLICATION_COMMON_PACKAGE_PACKAGE_H_
7
8 #include <string>
9
10 #include "base/files/file_path.h"
11 #include "base/files/scoped_file.h"
12 #include "base/files/scoped_temp_dir.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "xwalk/application/common/manifest.h"
15
16 namespace xwalk {
17 namespace application {
18
19 // Base class for all types of packages (right now .wgt and .xpk)
20 // The actual zip file, id, is_valid_, source_path_ are common in all packages
21 // specifics like signature checking for XPK are taken care of in
22 //  XPKPackage::Validate()
23 class Package {
24  public:
25   virtual ~Package();
26   bool IsValid() const { return is_valid_; }
27   const std::string& Id() const { return id_; }
28   const std::string& name() const { return name_; }
29   // Returns the type of the manifest which the package contains.
30   Manifest::Type manifest_type() const { return manifest_type_; }
31   // Factory method for creating a package
32   static scoped_ptr<Package> Create(const base::FilePath& path);
33   // The function will unzip the XPK/WGT file and return the target path where
34   // to decompress by the parameter |target_path|.
35   virtual bool ExtractToTemporaryDir(base::FilePath* result_path);
36   // The function will unzip the XPK/WGT file to the given folder.
37   virtual bool ExtractTo(const base::FilePath& target_path);
38
39  protected:
40   Package(const base::FilePath& source_path, Manifest::Type manifest_type);
41   // Unzipping of the zipped file happens in a temporary directory
42   bool CreateTempDirectory();
43   scoped_ptr<base::ScopedFILE> file_;
44
45   bool is_valid_;
46   base::FilePath source_path_;
47   std::string id_;
48   std::string name_;
49   // Temporary directory for unpacking.
50   base::ScopedTempDir temp_dir_;
51   // Represent if the package has been extracted.
52   bool is_extracted_;
53   Manifest::Type manifest_type_;
54 };
55
56 }  // namespace application
57 }  // namespace xwalk
58
59 #endif  // XWALK_APPLICATION_COMMON_PACKAGE_PACKAGE_H_