| {% from 'templates/macros.tmpl' import license, source_files_for_generated_file %} |
| {{license()}} |
| |
| {{source_files_for_generated_file(template_file, input_files)}} |
| |
| #ifndef {{header_guard}} |
| #define {{header_guard}} |
| |
| #include <string> |
| |
| #include "third_party/blink/renderer/platform/platform_export.h" |
| #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" |
| |
| #define ASSERT_ORIGIN_TRIAL(feature) \ |
| static_assert(std::is_same<decltype(::blink::RuntimeEnabledFeatures:: \ |
| feature##EnabledByRuntimeFlag()), \ |
| bool>(), \ |
| #feature " must be part of an origin trial"); |
| |
| namespace blink { |
| |
| enum class OriginTrialFeature : int32_t { |
| // For testing |
| kNonExisting = 0, |
| |
| {% for feature in features %} |
| {% if feature.origin_trial_feature_name %} |
| k{{feature.name}}, |
| {% endif %} |
| {% endfor %} |
| }; |
| |
| // A pure virtual interface for checking the availability of origin trial |
| // features in a context. |
| class PLATFORM_EXPORT FeatureContext { |
| public: |
| virtual bool FeatureEnabled(OriginTrialFeature) const = 0; |
| }; |
| |
| // A class that stores static enablers for all experimental features. |
| |
| class PLATFORM_EXPORT RuntimeEnabledFeatures { |
| STATIC_ONLY(RuntimeEnabledFeatures); |
| public: |
| class PLATFORM_EXPORT Backup { |
| public: |
| explicit Backup(); |
| void Restore(); |
| |
| private: |
| {% for feature in features %} |
| bool {{feature.data_member_name}}; |
| {% endfor %} |
| }; |
| |
| {% for feature_set in feature_sets %} |
| static void Set{{feature_set|capitalize}}FeaturesEnabled(bool); |
| {% endfor %} |
| static void SetOriginTrialControlledFeaturesEnabled(bool); |
| |
| static void SetFeatureEnabledFromString(const std::string& name, bool enabled); |
| |
| {% for feature in features %} |
| {% if not feature.in_origin_trial %} |
| static void Set{{feature.name}}Enabled(bool enabled) { {{feature.data_member_name}} = enabled; } |
| static bool {{feature.name}}Enabled() { |
| {% for depends_on in feature.depends_on %} |
| if (!{{depends_on}}Enabled()) |
| return false; |
| {% endfor %} |
| {% for implied_by in feature.implied_by %} |
| if ({{implied_by}}Enabled()) |
| return true; |
| {% endfor %} |
| return {{feature.data_member_name}}; |
| } |
| static bool {{feature.name}}Enabled(const FeatureContext*) { return {{feature.name}}Enabled(); } |
| |
| {% endif %} |
| {% endfor %} |
| |
| // Origin-trial-enabled features: |
| // |
| // These features are currently part of an origin trial (see |
| // https://www.chromium.org/blink/origin-trials). <feature>EnabledByRuntimeFlag() |
| // can be used to test whether the feature is unconditionally enabled |
| // (for example, by starting the browser with the appropriate command-line flag). |
| // However, that is almost always the incorrect check. Most renderer code should |
| // be calling <feature>Enabled(const FeatureContext*) instead, to test if the |
| // feature is enabled in a given context. |
| |
| {% for feature in origin_trial_controlled_features %} |
| static void Set{{feature.name}}Enabled(bool enabled) { {{feature.data_member_name}} = enabled; } |
| static bool {{feature.name}}EnabledByRuntimeFlag() { return {{feature.name}}Enabled(nullptr); } |
| static bool {{feature.name}}Enabled(const FeatureContext*); |
| |
| {% endfor %} |
| |
| private: |
| friend class RuntimeEnabledFeaturesTestHelpers; |
| |
| {% for feature in features %} |
| static bool {{feature.data_member_name}}; |
| {% endfor %} |
| }; |
| |
| } // namespace blink |
| |
| #endif // {{header_guard}} |