This source file includes following definitions.
- IsAvailableToManifest
- IsAvailableToContext
- IsIdInWhitelist
- IsBlockedInServiceWorker
- GetContexts
- IsInternal
- GetAvailabilityMessage
#include "extensions/common/features/complex_feature.h"
namespace extensions {
ComplexFeature::ComplexFeature(scoped_ptr<FeatureList> features) {
DCHECK_GT(features->size(), 0UL);
features_.swap(*features);
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
std::set<Feature::Context>* first_contexts = features_[0]->GetContexts();
bool first_is_internal = features_[0]->IsInternal();
bool first_blocked_in_service_worker =
features_[0]->IsBlockedInServiceWorker();
for (FeatureList::const_iterator it = features_.begin() + 1;
it != features_.end();
++it) {
DCHECK(*first_contexts == *(*it)->GetContexts())
<< "Complex feature must have consistent values of "
"contexts across all sub features.";
DCHECK(first_is_internal == (*it)->IsInternal())
<< "Complex feature must have consistent values of "
"internal across all sub features.";
DCHECK(first_blocked_in_service_worker == (*it)->IsBlockedInServiceWorker())
<< "Complex feature must have consistent values of "
"blocked_in_service_worker across all sub features.";
}
#endif
}
ComplexFeature::~ComplexFeature() {
}
Feature::Availability ComplexFeature::IsAvailableToManifest(
const std::string& extension_id, Manifest::Type type, Location location,
int manifest_version, Platform platform) const {
Feature::Availability first_availability =
features_[0]->IsAvailableToManifest(
extension_id, type, location, manifest_version, platform);
if (first_availability.is_available())
return first_availability;
for (FeatureList::const_iterator it = features_.begin() + 1;
it != features_.end(); ++it) {
Availability availability = (*it)->IsAvailableToManifest(
extension_id, type, location, manifest_version, platform);
if (availability.is_available())
return availability;
}
return first_availability;
}
Feature::Availability ComplexFeature::IsAvailableToContext(
const Extension* extension,
Context context,
const GURL& url,
Platform platform) const {
Feature::Availability first_availability =
features_[0]->IsAvailableToContext(extension, context, url, platform);
if (first_availability.is_available())
return first_availability;
for (FeatureList::const_iterator it = features_.begin() + 1;
it != features_.end(); ++it) {
Availability availability =
(*it)->IsAvailableToContext(extension, context, url, platform);
if (availability.is_available())
return availability;
}
return first_availability;
}
bool ComplexFeature::IsIdInWhitelist(const std::string& extension_id) const {
for (FeatureList::const_iterator it = features_.begin();
it != features_.end();
++it) {
if ((*it)->IsIdInWhitelist(extension_id))
return true;
}
return false;
}
bool ComplexFeature::IsBlockedInServiceWorker() const {
return features_[0]->IsBlockedInServiceWorker();
}
std::set<Feature::Context>* ComplexFeature::GetContexts() {
return features_[0]->GetContexts();
}
bool ComplexFeature::IsInternal() const {
return features_[0]->IsInternal();
}
std::string ComplexFeature::GetAvailabilityMessage(AvailabilityResult result,
Manifest::Type type,
const GURL& url,
Context context) const {
if (result == IS_AVAILABLE)
return std::string();
return features_[0]->GetAvailabilityMessage(result, type, url, context);
}
}