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/common/extensions/api/extension_api_feature.h" |
| 6 |
| 7 #include "base/values.h" |
| 8 |
| 9 namespace extensions { |
| 10 |
| 11 namespace { |
| 12 |
| 13 const char* kChildKinds[] = { |
| 14 "functions", |
| 15 "events" |
| 16 }; |
| 17 |
| 18 } // namespace |
| 19 |
| 20 ExtensionAPIFeature::ExtensionAPIFeature() { |
| 21 } |
| 22 |
| 23 ExtensionAPIFeature::~ExtensionAPIFeature() { |
| 24 } |
| 25 |
| 26 std::set<std::string>* ExtensionAPIFeature::dependencies() { |
| 27 return &dependencies_; |
| 28 } |
| 29 |
| 30 void ExtensionAPIFeature::Parse(const DictionaryValue* schema) { |
| 31 Feature::Parse(schema); |
| 32 |
| 33 ParseSet(schema, "dependencies", &dependencies_); |
| 34 |
| 35 for (size_t i = 0; i < arraysize(kChildKinds); ++i) { |
| 36 ListValue* child_list = NULL; |
| 37 schema->GetList(kChildKinds[i], &child_list); |
| 38 if (!child_list) |
| 39 continue; |
| 40 |
| 41 for (size_t j = 0; j < child_list->GetSize(); ++j) { |
| 42 DictionaryValue* child = NULL; |
| 43 CHECK(child_list->GetDictionary(j, &child)); |
| 44 |
| 45 scoped_ptr<ExtensionAPIFeature> child_feature(new ExtensionAPIFeature()); |
| 46 child_feature->Parse(child); |
| 47 if (child_feature->IsEmpty()) |
| 48 continue; // no need to store no-op features |
| 49 |
| 50 std::string child_name; |
| 51 CHECK(child->GetString("name", &child_name)); |
| 52 child_feature->set_name(name() + "." + child_name); |
| 53 CHECK(child_features_.insert( |
| 54 std::make_pair(child_name, |
| 55 make_linked_ptr(child_feature.release()))).second); |
| 56 } |
| 57 } |
| 58 } |
| 59 |
| 60 Feature* ExtensionAPIFeature::GetChild(const std::string& child_name) const { |
| 61 ChildFeatureMap::const_iterator iter = child_features_.find(child_name); |
| 62 if (iter != child_features_.end()) { |
| 63 ExtensionAPIFeature* result = iter->second.get(); |
| 64 result->dependencies()->insert(std::string("api:") + name()); |
| 65 return result; |
| 66 } else { |
| 67 return NULL; |
| 68 } |
| 69 } |
| 70 |
| 71 } // namespace extensions |
OLD | NEW |