OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/extensions/requirements_provider_impl.h" |
| 6 |
| 7 #include "base/string16.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 10 #include "chrome/common/extensions/manifest.h" |
| 11 |
| 12 namespace keys = extension_manifest_keys; |
| 13 |
| 14 namespace extensions { |
| 15 |
| 16 // static |
| 17 RequirementsProvider* RequirementsProvider::Create() { |
| 18 return new RequirementsProviderImpl(); |
| 19 } |
| 20 |
| 21 RequirementsProviderImpl::RequirementsProviderImpl() { |
| 22 } |
| 23 |
| 24 bool RequirementsProviderImpl::Supports(const Manifest& manifest, |
| 25 string16* error) { |
| 26 DictionaryValue* requirements_value = NULL; |
| 27 manifest.GetDictionary(keys::kRequirements, &requirements_value); |
| 28 if (!requirements_value) |
| 29 return true; |
| 30 |
| 31 for (DictionaryValue::key_iterator it = requirements_value->begin_keys(); |
| 32 it != requirements_value->end_keys(); ++it) { |
| 33 DictionaryValue* requirement_value; |
| 34 requirements_value->GetDictionaryWithoutPathExpansion( |
| 35 *it, &requirement_value); |
| 36 if (!requirement_value) |
| 37 continue; |
| 38 |
| 39 if (*it == "plugins") { |
| 40 #if defined(OS_CHROMEOS) |
| 41 // TODO(eriq): i18n |
| 42 *error = ASCIIToUTF16("Plugins are not supported on CHROMEOS"); |
| 43 return false; |
| 44 #endif |
| 45 } else if (*it == "foo") { |
| 46 ListValue* features; |
| 47 requirement_value->GetListWithoutPathExpansion("features", &features); |
| 48 if (!features) |
| 49 continue; |
| 50 std::string feature; |
| 51 features->GetString(0, &feature); |
| 52 if (feature != "bar") { |
| 53 *error = ASCIIToUTF16( |
| 54 "Requirement 'foo' only supports the feature 'bar'"); |
| 55 return false; |
| 56 } |
| 57 } |
| 58 } |
| 59 |
| 60 return true; |
| 61 } |
| 62 |
| 63 } // namespace extensions |
OLD | NEW |