Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Unified Diff: third_party/WebKit/Source/core/origin_trials/OriginTrialsBase.cpp

Issue 1833063002: Store the list of trial tokens in OriginTrialContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/origin_trials/OriginTrialsBase.cpp
diff --git a/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp b/third_party/WebKit/Source/core/origin_trials/OriginTrialsBase.cpp
similarity index 73%
rename from third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
rename to third_party/WebKit/Source/core/origin_trials/OriginTrialsBase.cpp
index 6d3f81da71111c51b9c5f3b4e3e81f5b73e912e3..2c13003ab0cee7f233afe2ebfd7e877a55263f56 100644
--- a/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
+++ b/third_party/WebKit/Source/core/origin_trials/OriginTrialsBase.cpp
@@ -2,12 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "core/origin_trials/OriginTrialContext.h"
+#include "core/origin_trials/OriginTrialsBase.h"
-#include "core/dom/ElementTraversal.h"
-#include "core/dom/ExceptionCode.h"
-#include "core/html/HTMLHeadElement.h"
-#include "core/html/HTMLMetaElement.h"
+#include "core/dom/ExecutionContext.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "platform/weborigin/SecurityOrigin.h"
#include "public/platform/Platform.h"
@@ -31,11 +28,23 @@ String getInvalidTokenMessage(const String& featureName)
} // namespace
-const char OriginTrialContext::kTrialHeaderName[] = "origin-trial";
+OriginTrialsBase::~OriginTrialsBase() {}
-OriginTrialContext::OriginTrialContext() {}
+void OriginTrialsBase::addToken(const String& token)
+{
+ m_tokens.append(token);
+}
+
+DEFINE_TRACE(OriginTrialsBase)
+{
+ visitor->trace(m_host);
+}
+
+OriginTrialsBase::OriginTrialsBase(ExecutionContext* host) : m_host(host)
+{
+}
-bool OriginTrialContext::isFeatureEnabled(const String& featureName, String* errorMessage, WebTrialTokenValidator* validator)
+bool OriginTrialsBase::isFeatureEnabled(const String& featureName, String* errorMessage, WebTrialTokenValidator* validator)
{
if (!RuntimeEnabledFeatures::experimentalFrameworkEnabled()) {
// TODO(iclelland): Set an error message here, the first time the
@@ -45,8 +54,8 @@ bool OriginTrialContext::isFeatureEnabled(const String& featureName, String* err
// Feature trials are only enabled for secure origins
bool isSecure = errorMessage
- ? getExecutionContext()->isSecureContext(*errorMessage)
- : getExecutionContext()->isSecureContext();
+ ? m_host->isSecureContext(*errorMessage)
+ : m_host->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
@@ -65,14 +74,9 @@ bool OriginTrialContext::isFeatureEnabled(const String& featureName, String* err
}
}
- return hasValidToken(getTokens(), featureName, errorMessage, validator);
-}
-
-bool OriginTrialContext::hasValidToken(Vector<String> tokens, const String& featureName, String* errorMessage, WebTrialTokenValidator* validator)
-{
- WebSecurityOrigin origin(getExecutionContext()->getSecurityOrigin());
- for (const String& token : tokens) {
+ WebSecurityOrigin origin(m_host->getSecurityOrigin());
+ for (const String& token : m_tokens) {
// Check with the validator service to verify the signature.
if (validator->validateToken(token, origin, featureName)) {
return true;
@@ -90,7 +94,7 @@ bool OriginTrialContext::hasValidToken(Vector<String> tokens, const String& feat
return false;
}
- if (tokens.size()) {
+ if (m_tokens.size()) {
*errorMessage = getInvalidTokenMessage(featureName);
} else {
*errorMessage = getDisabledMessage(featureName);
@@ -99,8 +103,4 @@ bool OriginTrialContext::hasValidToken(Vector<String> tokens, const String& feat
return false;
}
-DEFINE_TRACE(OriginTrialContext)
-{
-}
-
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698