Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: chrome/common/extensions/manifest.cc

Issue 10536084: Add a warning when developing an extension that uses old manifest version. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: blonk Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 26 matching lines...) Expand all
37 } 37 }
38 } else { 38 } else {
39 type_ = Extension::TYPE_EXTENSION; 39 type_ = Extension::TYPE_EXTENSION;
40 } 40 }
41 CHECK_NE(type_, Extension::TYPE_UNKNOWN); 41 CHECK_NE(type_, Extension::TYPE_UNKNOWN);
42 } 42 }
43 43
44 Manifest::~Manifest() { 44 Manifest::~Manifest() {
45 } 45 }
46 46
47 void Manifest::ValidateManifest(std::string* error, 47 void Manifest::ValidateManifest(
48 std::vector<std::string>* warnings) const { 48 std::string* error,
49 Extension::InstallWarningVector* warnings) const {
49 *error = ""; 50 *error = "";
50 if (type_ == Extension::TYPE_PLATFORM_APP && GetManifestVersion() < 2) { 51 if (type_ == Extension::TYPE_PLATFORM_APP && GetManifestVersion() < 2) {
51 *error = errors::kPlatformAppNeedsManifestVersion2; 52 *error = errors::kPlatformAppNeedsManifestVersion2;
52 return; 53 return;
53 } 54 }
54 55
55 // Check every feature to see if its in the manifest. Note that this means 56 // Check every feature to see if its in the manifest. Note that this means
56 // we will ignore keys that are not features; we do this for forward 57 // we will ignore keys that are not features; we do this for forward
57 // compatibility. 58 // compatibility.
58 // TODO(aa): Consider having an error here in the case of strict error 59 // TODO(aa): Consider having an error here in the case of strict error
59 // checking to let developers know when they screw up. 60 // checking to let developers know when they screw up.
60 61
61 std::set<std::string> feature_names = 62 std::set<std::string> feature_names =
62 SimpleFeatureProvider::GetManifestFeatures()->GetAllFeatureNames(); 63 SimpleFeatureProvider::GetManifestFeatures()->GetAllFeatureNames();
63 for (std::set<std::string>::iterator feature_name = feature_names.begin(); 64 for (std::set<std::string>::iterator feature_name = feature_names.begin();
64 feature_name != feature_names.end(); ++feature_name) { 65 feature_name != feature_names.end(); ++feature_name) {
65 // Use Get instead of HasKey because the former uses path expansion. 66 // Use Get instead of HasKey because the former uses path expansion.
66 if (!value_->Get(*feature_name, NULL)) 67 if (!value_->Get(*feature_name, NULL))
67 continue; 68 continue;
68 69
69 Feature* feature = 70 Feature* feature =
70 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(*feature_name); 71 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(*feature_name);
71 Feature::Availability result = feature->IsAvailableToManifest( 72 Feature::Availability result = feature->IsAvailableToManifest(
72 extension_id_, type_, Feature::ConvertLocation(location_), 73 extension_id_, type_, Feature::ConvertLocation(location_),
73 GetManifestVersion()); 74 GetManifestVersion());
74 if (result != Feature::IS_AVAILABLE) 75 if (result != Feature::IS_AVAILABLE)
75 warnings->push_back(feature->GetErrorMessage(result)); 76 warnings->push_back(Extension::InstallWarning(
77 Extension::InstallWarning::FORMAT_TEXT,
78 feature->GetErrorMessage(result)));
76 } 79 }
77 80
78 // Also generate warnings for keys that are not features. 81 // Also generate warnings for keys that are not features.
79 for (DictionaryValue::key_iterator key = value_->begin_keys(); 82 for (DictionaryValue::key_iterator key = value_->begin_keys();
80 key != value_->end_keys(); ++key) { 83 key != value_->end_keys(); ++key) {
81 if (!SimpleFeatureProvider::GetManifestFeatures()->GetFeature(*key)) { 84 if (!SimpleFeatureProvider::GetManifestFeatures()->GetFeature(*key)) {
82 warnings->push_back(base::StringPrintf("Unrecognized manifest key '%s'.", 85 warnings->push_back(Extension::InstallWarning(
83 (*key).c_str())); 86 Extension::InstallWarning::FORMAT_TEXT,
87 base::StringPrintf("Unrecognized manifest key '%s'.",
88 (*key).c_str())));
84 } 89 }
85 } 90 }
86 } 91 }
87 92
88 bool Manifest::HasKey(const std::string& key) const { 93 bool Manifest::HasKey(const std::string& key) const {
89 return CanAccessKey(key) && value_->HasKey(key); 94 return CanAccessKey(key) && value_->HasKey(key);
90 } 95 }
91 96
92 bool Manifest::HasPath(const std::string& path) const { 97 bool Manifest::HasPath(const std::string& path) const {
93 Value* ignored = NULL; 98 Value* ignored = NULL;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(key); 169 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(key);
165 if (!feature) 170 if (!feature)
166 return true; 171 return true;
167 172
168 return Feature::IS_AVAILABLE == feature->IsAvailableToManifest( 173 return Feature::IS_AVAILABLE == feature->IsAvailableToManifest(
169 extension_id_, type_, Feature::ConvertLocation(location_), 174 extension_id_, type_, Feature::ConvertLocation(location_),
170 GetManifestVersion()); 175 GetManifestVersion());
171 } 176 }
172 177
173 } // namespace extensions 178 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/manifest.h ('k') | chrome/common/extensions/manifest_tests/extension_manifest_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698