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"
19 namespace application {
21 // Wraps the DictionaryValue form of application's manifest. Enforces access to
22 // properties of the manifest using ManifestFeatureProvider.
31 explicit Manifest(scoped_ptr<base::DictionaryValue> value);
34 const std::string& GetApplicationID() const { return application_id_; }
35 void SetApplicationID(const std::string& id) { application_id_ = id; }
37 // Returns false and |error| will be non-empty if the manifest is malformed.
38 // |warnings| will be populated if there are keys in the manifest that cannot
39 // be specified by the application type.
40 bool ValidateManifest(std::string* error) const;
42 // Returns the manifest type.
43 Type GetType() const { return type_; }
45 bool IsPackaged() const { return type_ == TYPE_PACKAGED_APP; }
46 bool IsHosted() const { return type_ == TYPE_HOSTED_APP; }
48 // These access the wrapped manifest value, returning false when the property
49 // does not exist or if the manifest type can't access it.
50 bool HasKey(const std::string& key) const;
51 bool HasPath(const std::string& path) const;
52 bool Get(const std::string& path, const base::Value** out_value) const;
53 bool Get(const std::string& path, base::Value** out_value) const;
54 bool GetBoolean(const std::string& path, bool* out_value) const;
55 bool GetInteger(const std::string& path, int* out_value) const;
57 // If the path is supported by i18n, we can get a locale string from
58 // this two GetString function. The following is locale priority:
59 // Application locale (locale get from system). | high
60 // Default locale (defaultlocale attribute of widget element)
61 // Unlocalized (the element without xml:lang attribute)
62 // Auto ("en-us"(tizen is "en-gb") will be considered as a default)
63 // First (the worst case we get the first element) | low
64 bool GetString(const std::string& path, std::string* out_value) const;
65 bool GetString(const std::string& path, base::string16* out_value) const;
67 bool GetDictionary(const std::string& path,
68 const base::DictionaryValue** out_value) const;
69 bool GetList(const std::string& path,
70 const base::ListValue** out_value) const;
72 // Returns a new Manifest equal to this one, passing ownership to
74 Manifest* DeepCopy() const;
76 // Returns true if this equals the |other| manifest.
77 bool Equals(const Manifest* other) const;
79 // Gets the underlying DictionaryValue representing the manifest.
80 // Note: only use this when you KNOW you don't need the validation.
81 const base::DictionaryValue* value() const { return data_.get(); }
83 const std::string& default_locale() const {
84 return default_locale_;
87 // Update user agent locale when system locale is changed.
88 void SetSystemLocale(const std::string& locale);
92 void ParseWGTI18nEachPath(const std::string& path);
93 bool ParseWGTI18nEachElement(base::Value* value,
94 const std::string& path,
95 const std::string& locale = "");
97 // Returns true if the application can specify the given |path|.
98 bool CanAccessPath(const std::string& path) const;
99 bool CanAccessKey(const std::string& key) const;
101 // A persistent, globally unique ID. An application's ID is used in things
102 // like directory structures and URLs, and is expected to not change across
104 std::string application_id_;
106 #if defined(OS_TIZEN)
107 // Unique package id for tizen platform
108 std::string package_id_;
111 // The underlying dictionary representation of the manifest.
112 scoped_ptr<base::DictionaryValue> data_;
113 scoped_ptr<base::DictionaryValue> i18n_data_;
115 std::string default_locale_;
116 scoped_ptr<std::list<std::string> > user_agent_locales_;
120 DISALLOW_COPY_AND_ASSIGN(Manifest);
123 } // namespace application
126 #endif // XWALK_APPLICATION_COMMON_MANIFEST_H_