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_
14 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string16.h"
16 #include "base/values.h"
17 #include "xwalk/application/browser/installer/package.h"
18 #include "xwalk/application/common/install_warning.h"
21 namespace application {
23 struct InstallWarning;
25 // Wraps the DictionaryValue form of application's manifest. Enforces access to
26 // properties of the manifest using ManifestFeatureProvider.
29 // Where an application was loaded from.
32 INTERNAL, // Load from internal application registry.
33 COMMAND_LINE, // Load from an unpacked application from command line.
43 Manifest(SourceType source_type, scoped_ptr<base::DictionaryValue> value);
46 const std::string& GetApplicationID() const { return application_id_; }
47 void SetApplicationID(const std::string& id) { application_id_ = id; }
49 SourceType GetSourceType() const { return source_type_; }
51 // Returns false and |error| will be non-empty if the manifest is malformed.
52 // |warnings| will be populated if there are keys in the manifest that cannot
53 // be specified by the application type.
54 bool ValidateManifest(std::string* error,
55 std::vector<InstallWarning>* warnings) const;
57 // The version of this application's manifest. We increase the manifest
58 // version when making breaking changes to the application system. If the
59 // manifest contains no explicit manifest version, this returns the current
61 int GetManifestVersion() const;
63 // Returns the manifest type.
64 Type GetType() const { return type_; }
66 bool IsPackaged() const { return type_ == TYPE_PACKAGED_APP; }
67 bool IsHosted() const { return type_ == TYPE_HOSTED_APP; }
69 // These access the wrapped manifest value, returning false when the property
70 // does not exist or if the manifest type can't access it.
71 bool HasKey(const std::string& key) const;
72 bool HasPath(const std::string& path) const;
73 bool Get(const std::string& path, const base::Value** out_value) const;
74 bool Get(const std::string& path, base::Value** out_value) const;
75 bool GetBoolean(const std::string& path, bool* out_value) const;
76 bool GetInteger(const std::string& path, int* out_value) const;
78 // If the path is supported by i18n, we can get a locale string from
79 // this two GetString function. The following is locale priority:
80 // Application locale (locale get from system). | high
81 // Default locale (defaultlocale attribute of widget element)
82 // Unlocalized (the element without xml:lang attribute)
83 // Auto ("en-us"(tizen is "en-gb") will be considered as a default)
84 // First (the worst case we get the first element) | low
85 bool GetString(const std::string& path, std::string* out_value) const;
86 bool GetString(const std::string& path, base::string16* out_value) const;
88 bool GetDictionary(const std::string& path,
89 const base::DictionaryValue** out_value) const;
90 bool GetList(const std::string& path,
91 const base::ListValue** out_value) const;
93 // Returns a new Manifest equal to this one, passing ownership to
95 Manifest* DeepCopy() const;
97 // Returns true if this equals the |other| manifest.
98 bool Equals(const Manifest* other) const;
100 // Gets the underlying DictionaryValue representing the manifest.
101 // Note: only use this when you KNOW you don't need the validation.
102 const base::DictionaryValue* value() const { return data_.get(); }
104 const std::string& default_locale() const {
105 return default_locale_;
108 // Update user agent locale when system locale is changed.
109 void SetSystemLocale(const std::string& locale);
113 void ParseWGTI18nEachPath(const std::string& path);
114 bool ParseWGTI18nEachElement(base::Value* value,
115 const std::string& path,
116 const std::string& locale = "");
118 // Returns true if the application can specify the given |path|.
119 bool CanAccessPath(const std::string& path) const;
120 bool CanAccessKey(const std::string& key) const;
122 // A persistent, globally unique ID. An application's ID is used in things
123 // like directory structures and URLs, and is expected to not change across
124 // versions. It is generated as a SHA-256 hash of the application's public
125 // key, or as a hash of the path in the case of unpacked applications.
126 std::string application_id_;
128 // The source the application was loaded from.
129 SourceType source_type_;
131 // The underlying dictionary representation of the manifest.
132 scoped_ptr<base::DictionaryValue> data_;
133 scoped_ptr<base::DictionaryValue> i18n_data_;
135 std::string default_locale_;
136 scoped_ptr<std::list<std::string> > user_agent_locales_;
140 DISALLOW_COPY_AND_ASSIGN(Manifest);
143 } // namespace application
146 #endif // XWALK_APPLICATION_COMMON_MANIFEST_H_