| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extension_api.h" | 5 #include "extensions/common/extension_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 base::JSON_PARSE_RFC | base::JSON_DETACHABLE_CHILDREN, // options | 44 base::JSON_PARSE_RFC | base::JSON_DETACHABLE_CHILDREN, // options |
| 45 NULL, // error code | 45 NULL, // error code |
| 46 &error_message)); | 46 &error_message)); |
| 47 | 47 |
| 48 // Tracking down http://crbug.com/121424 | 48 // Tracking down http://crbug.com/121424 |
| 49 char buf[128]; | 49 char buf[128]; |
| 50 base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'", name.c_str(), | 50 base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'", name.c_str(), |
| 51 result.get() ? static_cast<int>(result->GetType()) : -1, | 51 result.get() ? static_cast<int>(result->GetType()) : -1, |
| 52 error_message.c_str()); | 52 error_message.c_str()); |
| 53 | 53 |
| 54 CHECK(result.get()) << error_message << " for schema " << schema; | 54 CHECK(result.get()); |
| 55 CHECK(result->IsType(base::Value::Type::DICTIONARY)) << " for schema " | 55 CHECK(result->IsType(base::Value::Type::DICTIONARY)); |
| 56 << schema; | |
| 57 return base::DictionaryValue::From(std::move(result)); | 56 return base::DictionaryValue::From(std::move(result)); |
| 58 } | 57 } |
| 59 | 58 |
| 60 const base::DictionaryValue* FindListItem(const base::ListValue* list, | 59 const base::DictionaryValue* FindListItem(const base::ListValue* list, |
| 61 const std::string& property_name, | 60 const std::string& property_name, |
| 62 const std::string& property_value) { | 61 const std::string& property_value) { |
| 63 for (size_t i = 0; i < list->GetSize(); ++i) { | 62 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 64 const base::DictionaryValue* item = NULL; | 63 const base::DictionaryValue* item = NULL; |
| 65 CHECK(list->GetDictionary(i, &item)) | 64 CHECK(list->GetDictionary(i, &item)); |
| 66 << property_value << "/" << property_name; | |
| 67 std::string value; | 65 std::string value; |
| 68 if (item->GetString(property_name, &value) && value == property_value) | 66 if (item->GetString(property_name, &value) && value == property_value) |
| 69 return item; | 67 return item; |
| 70 } | 68 } |
| 71 | 69 |
| 72 return NULL; | 70 return NULL; |
| 73 } | 71 } |
| 74 | 72 |
| 75 const base::DictionaryValue* GetSchemaChild( | 73 const base::DictionaryValue* GetSchemaChild( |
| 76 const base::DictionaryValue* schema_node, | 74 const base::DictionaryValue* schema_node, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 190 } |
| 193 | 191 |
| 194 if (check_alias != CheckAliasStatus::ALLOWED) | 192 if (check_alias != CheckAliasStatus::ALLOWED) |
| 195 return false; | 193 return false; |
| 196 | 194 |
| 197 const std::string& alias_name = api.alias(); | 195 const std::string& alias_name = api.alias(); |
| 198 if (alias_name.empty()) | 196 if (alias_name.empty()) |
| 199 return false; | 197 return false; |
| 200 | 198 |
| 201 const Feature* alias = provider->second->GetFeature(alias_name); | 199 const Feature* alias = provider->second->GetFeature(alias_name); |
| 202 CHECK(alias) << "Cannot find alias feature " << alias_name | 200 // Cannot find alias feature |alias_name| for API feature |api.name()| |
| 203 << " for API feature " << api.name(); | 201 CHECK(alias); |
| 204 return IsAnyFeatureAvailableToContext(*alias, extension, context, url, | 202 return IsAnyFeatureAvailableToContext(*alias, extension, context, url, |
| 205 CheckAliasStatus::NOT_ALLOWED); | 203 CheckAliasStatus::NOT_ALLOWED); |
| 206 } | 204 } |
| 207 | 205 |
| 208 Feature::Availability ExtensionAPI::IsAvailable(const std::string& full_name, | 206 Feature::Availability ExtensionAPI::IsAvailable(const std::string& full_name, |
| 209 const Extension* extension, | 207 const Extension* extension, |
| 210 Feature::Context context, | 208 Feature::Context context, |
| 211 const GURL& url, | 209 const GURL& url, |
| 212 CheckAliasStatus check_alias) { | 210 CheckAliasStatus check_alias) { |
| 213 Feature* feature = GetFeatureDependency(full_name); | 211 Feature* feature = GetFeatureDependency(full_name); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 std::string child_name; | 346 std::string child_name; |
| 349 GetAPINameFromFullName(full_name, &child_name); | 347 GetAPINameFromFullName(full_name, &child_name); |
| 350 std::string full_alias_name = alias + "." + child_name; | 348 std::string full_alias_name = alias + "." + child_name; |
| 351 Feature* alias_feature = provider->second->GetFeature(full_alias_name); | 349 Feature* alias_feature = provider->second->GetFeature(full_alias_name); |
| 352 | 350 |
| 353 // If there is no child feature, use the alias API feature to check | 351 // If there is no child feature, use the alias API feature to check |
| 354 // availability. | 352 // availability. |
| 355 if (!alias_feature) | 353 if (!alias_feature) |
| 356 alias_feature = provider->second->GetFeature(alias); | 354 alias_feature = provider->second->GetFeature(alias); |
| 357 | 355 |
| 358 CHECK(alias_feature) << "Cannot find alias feature " << alias | 356 // Cannot find alias feature |alias| for API feature |feature->name()| |
| 359 << " for API feature " << feature->name(); | 357 CHECK(alias_feature); |
| 360 | 358 |
| 361 return alias_feature->IsAvailableToContext(extension, context, url); | 359 return alias_feature->IsAvailableToContext(extension, context, url); |
| 362 } | 360 } |
| 363 | 361 |
| 364 } // namespace extensions | 362 } // namespace extensions |
| OLD | NEW |