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

Side by Side Diff: extensions/common/extension_api.cc

Issue 109683007: Pass a Feature* to IsAnyFeatureAvailableToContext instead of a string name. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update extension_api_stub.cc Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « extensions/common/extension_api.h ('k') | extensions/common/extension_api_stub.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 void ExtensionAPI::RegisterSchemaResource(const std::string& name, 269 void ExtensionAPI::RegisterSchemaResource(const std::string& name,
270 int resource_id) { 270 int resource_id) {
271 unloaded_schemas_[name] = resource_id; 271 unloaded_schemas_[name] = resource_id;
272 } 272 }
273 273
274 void ExtensionAPI::RegisterDependencyProvider(const std::string& name, 274 void ExtensionAPI::RegisterDependencyProvider(const std::string& name,
275 FeatureProvider* provider) { 275 FeatureProvider* provider) {
276 dependency_providers_[name] = provider; 276 dependency_providers_[name] = provider;
277 } 277 }
278 278
279 bool ExtensionAPI::IsAnyFeatureAvailableToContext(const std::string& api_name, 279 bool ExtensionAPI::IsAnyFeatureAvailableToContext(const Feature& api,
280 const Extension* extension, 280 const Extension* extension,
281 Feature::Context context, 281 Feature::Context context,
282 const GURL& url) { 282 const GURL& url) {
283 FeatureProviderMap::iterator provider = dependency_providers_.find("api"); 283 FeatureProviderMap::iterator provider = dependency_providers_.find("api");
284 CHECK(provider != dependency_providers_.end()); 284 CHECK(provider != dependency_providers_.end());
285 const std::vector<std::string>& features = 285 const std::vector<std::string>& features =
286 provider->second->GetAllFeatureNames(); 286 provider->second->GetAllFeatureNames();
287 287
288 // Check to see if there are any parts of this API that are allowed in this 288 // Check to see if there are any parts of this API that are allowed in this
289 // context. 289 // context.
290 for (std::vector<std::string>::const_iterator i = features.begin(); 290 for (std::vector<std::string>::const_iterator i = features.begin();
291 i != features.end(); ++i) { 291 i != features.end(); ++i) {
292 const std::string& feature_name = *i; 292 const std::string& feature_name = *i;
293 if (feature_name != api_name && feature_name.find(api_name + ".") == 0) { 293 if (feature_name != api.name() &&
294 feature_name.find(api.name() + ".") == 0) {
294 if (IsAvailable(feature_name, extension, context, url).is_available()) 295 if (IsAvailable(feature_name, extension, context, url).is_available())
295 return true; 296 return true;
296 } 297 }
297 } 298 }
298 return IsAvailable(api_name, extension, context, url).is_available(); 299 return IsAvailable(api.name(), extension, context, url).is_available();
299 } 300 }
300 301
301 Feature::Availability ExtensionAPI::IsAvailable(const std::string& full_name, 302 Feature::Availability ExtensionAPI::IsAvailable(const std::string& full_name,
302 const Extension* extension, 303 const Extension* extension,
303 Feature::Context context, 304 Feature::Context context,
304 const GURL& url) { 305 const GURL& url) {
305 Feature* feature = GetFeatureDependency(full_name); 306 Feature* feature = GetFeatureDependency(full_name);
306 CHECK(feature) << full_name; 307 CHECK(feature) << full_name;
307 308
308 Feature::Availability availability = 309 Feature::Availability availability =
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 break; 409 break;
409 410
410 api_name_candidate = api_name_candidate.substr(0, last_dot_index); 411 api_name_candidate = api_name_candidate.substr(0, last_dot_index);
411 } 412 }
412 413
413 *child_name = ""; 414 *child_name = "";
414 return std::string(); 415 return std::string();
415 } 416 }
416 417
417 } // namespace extensions 418 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/extension_api.h ('k') | extensions/common/extension_api_stub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698