| Index: third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
|
| diff --git a/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp b/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
|
| index 72f663aed4953be7ebc31ef4585fa438584c59ce..6d3f81da71111c51b9c5f3b4e3e81f5b73e912e3 100644
|
| --- a/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
|
| +++ b/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
|
| @@ -4,7 +4,10 @@
|
|
|
| #include "core/origin_trials/OriginTrialContext.h"
|
|
|
| -#include "core/dom/ExecutionContext.h"
|
| +#include "core/dom/ElementTraversal.h"
|
| +#include "core/dom/ExceptionCode.h"
|
| +#include "core/html/HTMLHeadElement.h"
|
| +#include "core/html/HTMLMetaElement.h"
|
| #include "platform/RuntimeEnabledFeatures.h"
|
| #include "platform/weborigin/SecurityOrigin.h"
|
| #include "public/platform/Platform.h"
|
| @@ -28,31 +31,9 @@
|
|
|
| } // namespace
|
|
|
| -OriginTrialContext::OriginTrialContext(ExecutionContext* host) : m_host(host)
|
| -{
|
| -}
|
| +const char OriginTrialContext::kTrialHeaderName[] = "origin-trial";
|
|
|
| -// static
|
| -const char* OriginTrialContext::supplementName()
|
| -{
|
| - return "OriginTrialContext";
|
| -}
|
| -
|
| -// static
|
| -OriginTrialContext* OriginTrialContext::from(ExecutionContext* host)
|
| -{
|
| - OriginTrialContext* originTrials = static_cast<OriginTrialContext*>(Supplement<ExecutionContext>::from(host, supplementName()));
|
| - if (!originTrials) {
|
| - originTrials = new OriginTrialContext(host);
|
| - Supplement<ExecutionContext>::provideTo(*host, supplementName(), originTrials);
|
| - }
|
| - return originTrials;
|
| -}
|
| -
|
| -void OriginTrialContext::addToken(const String& token)
|
| -{
|
| - m_tokens.append(token);
|
| -}
|
| +OriginTrialContext::OriginTrialContext() {}
|
|
|
| bool OriginTrialContext::isFeatureEnabled(const String& featureName, String* errorMessage, WebTrialTokenValidator* validator)
|
| {
|
| @@ -64,8 +45,8 @@
|
|
|
| // Feature trials are only enabled for secure origins
|
| bool isSecure = errorMessage
|
| - ? m_host->isSecureContext(*errorMessage)
|
| - : m_host->isSecureContext();
|
| + ? getExecutionContext()->isSecureContext(*errorMessage)
|
| + : getExecutionContext()->isSecureContext();
|
| if (!isSecure) {
|
| // The execution context should always set a message here, if a valid
|
| // pointer was passed in. If it does not, then we should find out why
|
| @@ -84,9 +65,14 @@
|
| }
|
| }
|
|
|
| + return hasValidToken(getTokens(), featureName, errorMessage, validator);
|
| +}
|
|
|
| - WebSecurityOrigin origin(m_host->getSecurityOrigin());
|
| - for (const String& token : m_tokens) {
|
| +bool OriginTrialContext::hasValidToken(Vector<String> tokens, const String& featureName, String* errorMessage, WebTrialTokenValidator* validator)
|
| +{
|
| + WebSecurityOrigin origin(getExecutionContext()->getSecurityOrigin());
|
| +
|
| + for (const String& token : tokens) {
|
| // Check with the validator service to verify the signature.
|
| if (validator->validateToken(token, origin, featureName)) {
|
| return true;
|
| @@ -104,7 +90,7 @@
|
| return false;
|
| }
|
|
|
| - if (m_tokens.size()) {
|
| + if (tokens.size()) {
|
| *errorMessage = getInvalidTokenMessage(featureName);
|
| } else {
|
| *errorMessage = getDisabledMessage(featureName);
|
| @@ -115,7 +101,6 @@
|
|
|
| DEFINE_TRACE(OriginTrialContext)
|
| {
|
| - visitor->trace(m_host);
|
| }
|
|
|
| } // namespace blink
|
|
|