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

Side by Side Diff: extensions/common/features/manifest_feature.cc

Issue 2150193002: [Extensions] Add a SimpleFeature::Validate function (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tests Created 4 years, 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/common/features/manifest_feature.h" 5 #include "extensions/common/features/manifest_feature.h"
6 6
7 #include "extensions/common/manifest.h" 7 #include "extensions/common/manifest.h"
8 8
9 namespace extensions { 9 namespace extensions {
10 10
(...skipping 16 matching lines...) Expand all
27 return availability; 27 return availability;
28 28
29 // We know we can skip manifest()->GetKey() here because we just did the same 29 // We know we can skip manifest()->GetKey() here because we just did the same
30 // validation it would do above. 30 // validation it would do above.
31 if (extension && !extension->manifest()->value()->HasKey(name())) 31 if (extension && !extension->manifest()->value()->HasKey(name()))
32 return CreateAvailability(NOT_PRESENT, extension->GetType()); 32 return CreateAvailability(NOT_PRESENT, extension->GetType());
33 33
34 return CreateAvailability(IS_AVAILABLE); 34 return CreateAvailability(IS_AVAILABLE);
35 } 35 }
36 36
37 std::string ManifestFeature::Parse(const base::DictionaryValue* value) { 37 bool ManifestFeature::Validate(std::string* error) {
38 std::string error = SimpleFeature::Parse(value); 38 if (!SimpleFeature::Validate(error))
39 if (!error.empty()) 39 return false;
40 return error;
41 40
42 if (extension_types()->empty()) { 41 if (extension_types()->empty()) {
43 return name() + ": Manifest features must specify at least one " + 42 *error = name() + ": Manifest features must specify at least one " +
44 "value for extension_types."; 43 "value for extension_types.";
44 return false;
45 } 45 }
46 46
47 if (value->HasKey("contexts")) 47 if (!contexts()->empty()) {
48 return name() + ": Manifest features do not support contexts."; 48 *error = name() + ": Manifest features do not support contexts.";
49 return false;
50 }
49 51
50 return std::string(); 52 return true;
51 } 53 }
52 54
53 } // namespace extensions 55 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698