1 // Copyright (c) 2012 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.
5 #ifndef XWALK_APPLICATION_COMMON_MANIFEST_H_
6 #define XWALK_APPLICATION_COMMON_MANIFEST_H_
13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string16.h"
15 #include "base/values.h"
16 #include "xwalk/application/common/install_warning.h"
19 namespace application {
21 struct InstallWarning;
23 // Wraps the DictionaryValue form of application's manifest. Enforces access to
24 // properties of the manifest using ManifestFeatureProvider.
27 // Where an application was loaded from.
30 INTERNAL, // Load from internal application registry.
31 COMMAND_LINE, // Load from an unpacked application from command line.
47 Manifest(SourceType source_type, scoped_ptr<base::DictionaryValue> value);
50 const std::string& GetApplicationID() const { return application_id_; }
51 void SetApplicationID(const std::string& id) { application_id_ = id; }
53 SourceType GetSourceType() const { return source_type_; }
55 // Returns false and |error| will be non-empty if the manifest is malformed.
56 // |warnings| will be populated if there are keys in the manifest that cannot
57 // be specified by the application type.
58 bool ValidateManifest(std::string* error,
59 std::vector<InstallWarning>* warnings) const;
61 // The version of this application's manifest. We increase the manifest
62 // version when making breaking changes to the application system. If the
63 // manifest contains no explicit manifest version, this returns the current
65 int GetManifestVersion() const;
67 // Returns the manifest type.
68 Type GetType() const { return type_; }
70 bool IsPackaged() const { return type_ == TYPE_PACKAGED_APP; }
71 bool IsHosted() const { return type_ == TYPE_HOSTED_APP; }
73 PackageType GetPackageType() const { return package_type_; }
75 // These access the wrapped manifest value, returning false when the property
76 // does not exist or if the manifest type can't access it.
77 bool HasKey(const std::string& key) const;
78 bool HasPath(const std::string& path) const;
79 bool Get(const std::string& path, const base::Value** out_value) const;
80 bool GetBoolean(const std::string& path, bool* out_value) const;
81 bool GetInteger(const std::string& path, int* out_value) const;
82 bool GetString(const std::string& path, std::string* out_value) const;
83 bool GetString(const std::string& path, base::string16* out_value) const;
84 bool GetDictionary(const std::string& path,
85 const base::DictionaryValue** out_value) const;
86 bool GetList(const std::string& path,
87 const base::ListValue** out_value) const;
89 // Returns a new Manifest equal to this one, passing ownership to
91 Manifest* DeepCopy() const;
93 // Returns true if this equals the |other| manifest.
94 bool Equals(const Manifest* other) const;
96 // Gets the underlying DictionaryValue representing the manifest.
97 // Note: only use this when you KNOW you don't need the validation.
98 const base::DictionaryValue* value() const { return data_.get(); }
101 // Returns true if the application can specify the given |path|.
102 bool CanAccessPath(const std::string& path) const;
103 bool CanAccessKey(const std::string& key) const;
105 // A persistent, globally unique ID. An application's ID is used in things
106 // like directory structures and URLs, and is expected to not change across
107 // versions. It is generated as a SHA-256 hash of the application's public
108 // key, or as a hash of the path in the case of unpacked applications.
109 std::string application_id_;
111 // The source the application was loaded from.
112 SourceType source_type_;
114 // The underlying dictionary representation of the manifest.
115 scoped_ptr<base::DictionaryValue> data_;
119 PackageType package_type_;
121 DISALLOW_COPY_AND_ASSIGN(Manifest);
124 } // namespace application
127 #endif // XWALK_APPLICATION_COMMON_MANIFEST_H_