chromium/third_party/blink/renderer/build/scripts/templates/web_origin_trials.cc.tmpl

{% from 'templates/macros.tmpl' import license, source_files_for_generated_file %}
{{license()}}

{{source_files_for_generated_file(template_file, input_files)}}

#include "third_party/blink/public/web/web_origin_trials.h"

#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/public/mojom/origin_trial_feature/origin_trial_feature.mojom-shared.h"
#include "third_party/blink/public/common/origin_trials/origin_trials.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/web/web_document.h"

namespace blink {

bool WebOriginTrials::isTrialEnabled(const WebDocument* web_document, const WebString& trial) {
  if (!web_document) return false;
  if (!origin_trials::IsTrialValid(trial.Utf8()))
    return false;
  Document* document = *web_document;
  for (mojom::blink::OriginTrialFeature feature : origin_trials::FeaturesForTrial(trial.Utf8())) {
    switch (feature) {
    {% for feature in features %}
    {% if feature.origin_trial_feature_name %}
      case mojom::blink::OriginTrialFeature::k{{feature.name}}:
        if (!RuntimeEnabledFeatures::{{feature.name}}Enabled(
                document->GetExecutionContext())) {
          return false;
        }
        break;
    {% endif %}
    {% endfor %}
      default:
        break;
    }
  }
  return true;
}


} // namespace blink