| 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 void ExtensionAPI::RegisterSchemaResource(const std::string& name, | 258 void ExtensionAPI::RegisterSchemaResource(const std::string& name, |
| 259 int resource_id) { | 259 int resource_id) { |
| 260 unloaded_schemas_[name] = resource_id; | 260 unloaded_schemas_[name] = resource_id; |
| 261 } | 261 } |
| 262 | 262 |
| 263 void ExtensionAPI::RegisterDependencyProvider(const std::string& name, | 263 void ExtensionAPI::RegisterDependencyProvider(const std::string& name, |
| 264 const FeatureProvider* provider) { | 264 const FeatureProvider* provider) { |
| 265 dependency_providers_[name] = provider; | 265 dependency_providers_[name] = provider; |
| 266 } | 266 } |
| 267 | 267 |
| 268 bool ExtensionAPI::IsAnyFeatureAvailableToContext(const Feature& api, | 268 bool ExtensionAPI::IsAnyFeatureAvailableToContext( |
| 269 const Extension* extension, | 269 const Feature& api, |
| 270 Feature::Context context, | 270 const Extension* extension, |
| 271 const GURL& url) { | 271 Feature::Context context, |
| 272 Feature::SessionType session_type, |
| 273 const GURL& url) { |
| 272 FeatureProviderMap::iterator provider = dependency_providers_.find("api"); | 274 FeatureProviderMap::iterator provider = dependency_providers_.find("api"); |
| 273 CHECK(provider != dependency_providers_.end()); | 275 CHECK(provider != dependency_providers_.end()); |
| 274 | 276 |
| 275 if (api.IsAvailableToContext(extension, context, url).is_available()) | 277 if (api.IsAvailableToContext(extension, context, session_type, url) |
| 278 .is_available()) |
| 276 return true; | 279 return true; |
| 277 | 280 |
| 278 // Check to see if there are any parts of this API that are allowed in this | 281 // Check to see if there are any parts of this API that are allowed in this |
| 279 // context. | 282 // context. |
| 280 const std::vector<Feature*> features = provider->second->GetChildren(api); | 283 const std::vector<Feature*> features = provider->second->GetChildren(api); |
| 281 for (std::vector<Feature*>::const_iterator it = features.begin(); | 284 for (std::vector<Feature*>::const_iterator it = features.begin(); |
| 282 it != features.end(); | 285 it != features.end(); |
| 283 ++it) { | 286 ++it) { |
| 284 if ((*it)->IsAvailableToContext(extension, context, url).is_available()) | 287 if ((*it) |
| 288 ->IsAvailableToContext(extension, context, session_type, url) |
| 289 .is_available()) |
| 285 return true; | 290 return true; |
| 286 } | 291 } |
| 287 return false; | 292 return false; |
| 288 } | 293 } |
| 289 | 294 |
| 290 Feature::Availability ExtensionAPI::IsAvailable(const std::string& full_name, | 295 Feature::Availability ExtensionAPI::IsAvailable( |
| 291 const Extension* extension, | 296 const std::string& full_name, |
| 292 Feature::Context context, | 297 const Extension* extension, |
| 293 const GURL& url) { | 298 Feature::Context context, |
| 299 Feature::SessionType session_type, |
| 300 const GURL& url) { |
| 294 Feature* feature = GetFeatureDependency(full_name); | 301 Feature* feature = GetFeatureDependency(full_name); |
| 295 if (!feature) { | 302 if (!feature) { |
| 296 return Feature::Availability(Feature::NOT_PRESENT, | 303 return Feature::Availability(Feature::NOT_PRESENT, |
| 297 std::string("Unknown feature: ") + full_name); | 304 std::string("Unknown feature: ") + full_name); |
| 298 } | 305 } |
| 299 return feature->IsAvailableToContext(extension, context, url); | 306 return feature->IsAvailableToContext(extension, context, session_type, url); |
| 300 } | 307 } |
| 301 | 308 |
| 302 bool ExtensionAPI::IsAvailableToWebUI(const std::string& name, | 309 bool ExtensionAPI::IsAvailableToWebUI(const std::string& name, |
| 310 Feature::SessionType session_type, |
| 303 const GURL& url) { | 311 const GURL& url) { |
| 304 return IsAvailable(name, NULL, Feature::WEBUI_CONTEXT, url).is_available(); | 312 return IsAvailable(name, NULL, Feature::WEBUI_CONTEXT, session_type, url) |
| 313 .is_available(); |
| 305 } | 314 } |
| 306 | 315 |
| 307 const base::DictionaryValue* ExtensionAPI::GetSchema( | 316 const base::DictionaryValue* ExtensionAPI::GetSchema( |
| 308 const std::string& full_name) { | 317 const std::string& full_name) { |
| 309 std::string child_name; | 318 std::string child_name; |
| 310 std::string api_name = GetAPINameFromFullName(full_name, &child_name); | 319 std::string api_name = GetAPINameFromFullName(full_name, &child_name); |
| 311 | 320 |
| 312 const base::DictionaryValue* result = NULL; | 321 const base::DictionaryValue* result = NULL; |
| 313 SchemaMap::iterator maybe_schema = schemas_.find(api_name); | 322 SchemaMap::iterator maybe_schema = schemas_.find(api_name); |
| 314 if (maybe_schema != schemas_.end()) { | 323 if (maybe_schema != schemas_.end()) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 break; | 397 break; |
| 389 | 398 |
| 390 api_name_candidate = api_name_candidate.substr(0, last_dot_index); | 399 api_name_candidate = api_name_candidate.substr(0, last_dot_index); |
| 391 } | 400 } |
| 392 | 401 |
| 393 *child_name = ""; | 402 *child_name = ""; |
| 394 return std::string(); | 403 return std::string(); |
| 395 } | 404 } |
| 396 | 405 |
| 397 } // namespace extensions | 406 } // namespace extensions |
| OLD | NEW |