OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/extensions/manifest.h" | 5 #include "chrome/common/extensions/manifest.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/common/extensions/extension_manifest_constants.h" | 13 #include "chrome/common/extensions/extension_manifest_constants.h" |
14 #include "chrome/common/extensions/extension_error_utils.h" | 14 #include "chrome/common/extensions/extension_error_utils.h" |
15 #include "chrome/common/extensions/simple_feature_provider.h" | 15 #include "chrome/common/extensions/simple_feature_provider.h" |
16 | 16 |
17 namespace errors = extension_manifest_errors; | 17 namespace errors = extension_manifest_errors; |
18 namespace keys = extension_manifest_keys; | 18 namespace keys = extension_manifest_keys; |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
21 | 21 |
22 Manifest::Manifest(Extension::Location location, | 22 Manifest::Manifest(Extension::Location location, |
23 scoped_ptr<DictionaryValue> value) | 23 scoped_ptr<DictionaryValue> value) |
24 : location_(location), | 24 : location_(location), |
25 value_(value.Pass()), | 25 value_(value.Pass()), |
26 type_(Extension::TYPE_UNKNOWN) { | 26 type_(Extension::TYPE_UNKNOWN) { |
27 if (value_->HasKey(keys::kTheme)) { | 27 if (value_->HasKey(keys::kTheme)) { |
28 type_ = Extension::TYPE_THEME; | 28 type_ = Extension::TYPE_THEME; |
| 29 } else if (value_->HasKey(keys::kApp)) { |
| 30 if (value_->Get(keys::kWebURLs, NULL) || |
| 31 value_->Get(keys::kLaunchWebURL, NULL)) { |
| 32 type_ = Extension::TYPE_HOSTED_APP; |
| 33 } else if (value_->Get(keys::kPlatformAppBackground, NULL)) { |
| 34 type_ = Extension::TYPE_PLATFORM_APP; |
| 35 } else { |
| 36 type_ = Extension::TYPE_PACKAGED_APP; |
| 37 } |
29 } else { | 38 } else { |
30 bool is_platform_app = false; | 39 type_ = Extension::TYPE_EXTENSION; |
31 if (value_->GetBoolean(keys::kPlatformApp, &is_platform_app) && | |
32 is_platform_app) { | |
33 type_ = Extension::TYPE_PLATFORM_APP; | |
34 } else if (value_->HasKey(keys::kApp)) { | |
35 if (value_->Get(keys::kWebURLs, NULL) || | |
36 value_->Get(keys::kLaunchWebURL, NULL)) { | |
37 type_ = Extension::TYPE_HOSTED_APP; | |
38 } else { | |
39 type_ = Extension::TYPE_PACKAGED_APP; | |
40 } | |
41 } else { | |
42 type_ = Extension::TYPE_EXTENSION; | |
43 } | |
44 } | 40 } |
45 CHECK_NE(type_, Extension::TYPE_UNKNOWN); | 41 CHECK_NE(type_, Extension::TYPE_UNKNOWN); |
46 } | 42 } |
47 | 43 |
48 Manifest::~Manifest() { | 44 Manifest::~Manifest() { |
49 } | 45 } |
50 | 46 |
51 void Manifest::ValidateManifest(std::string* error, | 47 void Manifest::ValidateManifest(std::string* error, |
52 std::vector<std::string>* warnings) const { | 48 std::vector<std::string>* warnings) const { |
53 *error = ""; | 49 *error = ""; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 warnings->push_back(base::StringPrintf("Unrecognized manifest key '%s'.", | 82 warnings->push_back(base::StringPrintf("Unrecognized manifest key '%s'.", |
87 (*key).c_str())); | 83 (*key).c_str())); |
88 } | 84 } |
89 } | 85 } |
90 } | 86 } |
91 | 87 |
92 bool Manifest::HasKey(const std::string& key) const { | 88 bool Manifest::HasKey(const std::string& key) const { |
93 return CanAccessKey(key) && value_->HasKey(key); | 89 return CanAccessKey(key) && value_->HasKey(key); |
94 } | 90 } |
95 | 91 |
| 92 bool Manifest::HasPath(const std::string& path) const { |
| 93 Value* ignored = NULL; |
| 94 return CanAccessPath(path) && value_->Get(path, &ignored); |
| 95 } |
| 96 |
96 bool Manifest::Get( | 97 bool Manifest::Get( |
97 const std::string& path, Value** out_value) const { | 98 const std::string& path, Value** out_value) const { |
98 return CanAccessPath(path) && value_->Get(path, out_value); | 99 return CanAccessPath(path) && value_->Get(path, out_value); |
99 } | 100 } |
100 | 101 |
101 bool Manifest::GetBoolean( | 102 bool Manifest::GetBoolean( |
102 const std::string& path, bool* out_value) const { | 103 const std::string& path, bool* out_value) const { |
103 return CanAccessPath(path) && value_->GetBoolean(path, out_value); | 104 return CanAccessPath(path) && value_->GetBoolean(path, out_value); |
104 } | 105 } |
105 | 106 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(key); | 164 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(key); |
164 if (!feature) | 165 if (!feature) |
165 return true; | 166 return true; |
166 | 167 |
167 return Feature::IS_AVAILABLE == feature->IsAvailableToManifest( | 168 return Feature::IS_AVAILABLE == feature->IsAvailableToManifest( |
168 extension_id_, type_, Feature::ConvertLocation(location_), | 169 extension_id_, type_, Feature::ConvertLocation(location_), |
169 GetManifestVersion()); | 170 GetManifestVersion()); |
170 } | 171 } |
171 | 172 |
172 } // namespace extensions | 173 } // namespace extensions |
OLD | NEW |