summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/Source/build/scripts/templates/OriginTrials.cpp.tmpl
blob: c95d7fbad9c5a1795703f366aa3913056988a916 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{% from 'macros.tmpl' import license %}
{{license()}}

#include "core/origin_trials/OriginTrials.h"

#include "core/dom/ExecutionContext.h"
#include "core/origin_trials/OriginTrialContext.h"
#include "platform/RuntimeEnabledFeatures.h"

namespace blink {

OriginTrials::OriginTrials(PassOwnPtrWillBeRawPtr<OriginTrialContext> originTrialContext)
    : m_originTrialContext(originTrialContext) {}

// static
const char* OriginTrials::supplementName()
{
   return "OriginTrials";
}

// static
OriginTrials* OriginTrials::from(ExecutionContext* host)
{
    OriginTrials* originTrials = reinterpret_cast<OriginTrials*>(WillBeHeapSupplement<ExecutionContext>::from(host, supplementName()));
    if (!originTrials) {
        originTrials = new OriginTrials(host->createOriginTrialContext());
        WillBeHeapSupplement<ExecutionContext>::provideTo(*host, supplementName(), adoptPtrWillBeNoop(originTrials));
    }
    return originTrials;
}

{% for feature in features %}
{% if feature.origin_trial_feature_name %}

// static
bool OriginTrials::{{feature.first_lowered_name}}Enabled(ExecutionContext* executionContext, String& errorMessage) {
    return OriginTrials::from(executionContext)->{{feature.first_lowered_name}}EnabledImpl(&errorMessage);
}

// static
bool OriginTrials::{{feature.first_lowered_name}}Enabled(ExecutionContext* executionContext) {
    return OriginTrials::from(executionContext)->{{feature.first_lowered_name}}EnabledImpl(nullptr);
}

{% endif %}
{% endfor %}

{% for feature in features %}
{% if feature.origin_trial_feature_name %}

bool OriginTrials::{{feature.first_lowered_name}}EnabledImpl(String* errorMessage) {
    if (RuntimeEnabledFeatures::{{feature.first_lowered_name}}Enabled())
        return true;
    if (!m_originTrialContext) return false;
    return m_originTrialContext->isFeatureEnabled("{{feature.origin_trial_feature_name}}", errorMessage);
}
{% endif %}
{% endfor %}

DEFINE_TRACE(OriginTrials)
{
    visitor->trace(m_originTrialContext);
    WillBeHeapSupplement<ExecutionContext>::trace(visitor);
}
} // namespace blink