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

Unified Diff: third_party/WebKit/Source/core/origin_trials/OriginTrialContext.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/OriginTrialContext.cpp
diff --git a/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp b/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
deleted file mode 100644
index 6d3f81da71111c51b9c5f3b4e3e81f5b73e912e3..0000000000000000000000000000000000000000
--- a/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// 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/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"
-#include "public/platform/WebSecurityOrigin.h"
-#include "public/platform/WebTrialTokenValidator.h"
-
-namespace blink {
-
-namespace {
-
-String getDisabledMessage(const String& featureName)
-{
- // TODO(chasej): Update message with URL to experiments site, when live
- return "The '" + featureName + "' feature is currently enabled in limited trials. Please see [Phosphor console URL] for information on enabling a trial for your site.";
-}
-
-String getInvalidTokenMessage(const String& featureName)
-{
- return "The provided token(s) are not valid for the '" + featureName + "' feature.";
-}
-
-} // namespace
-
-const char OriginTrialContext::kTrialHeaderName[] = "origin-trial";
-
-OriginTrialContext::OriginTrialContext() {}
-
-bool OriginTrialContext::isFeatureEnabled(const String& featureName, String* errorMessage, WebTrialTokenValidator* validator)
-{
- if (!RuntimeEnabledFeatures::experimentalFrameworkEnabled()) {
- // TODO(iclelland): Set an error message here, the first time the
- // context is accessed in this renderer.
- return false;
- }
-
- // Feature trials are only enabled for secure origins
- bool isSecure = errorMessage
- ? 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
- // not, and decide whether the OriginTrialContext should be using its
- // own error messages for this case.
- DCHECK(!errorMessage || !errorMessage->isEmpty());
- return false;
- }
-
- if (!validator) {
- validator = Platform::current()->trialTokenValidator();
- if (!validator) {
- // TODO(iclelland): Set an error message here, the first time the
- // context is accessed in this renderer.
- return false;
- }
- }
-
- 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) {
- // Check with the validator service to verify the signature.
- if (validator->validateToken(token, origin, featureName)) {
- return true;
- }
- }
-
- if (!errorMessage)
- return false;
-
- // If an error message has already been generated in this context, for this
- // feature, do not generate another one. (This avoids cluttering the console
- // with error messages on every attempt to access the feature.)
- if (m_errorMessageGeneratedForFeature.contains(featureName)) {
- *errorMessage = "";
- return false;
- }
-
- if (tokens.size()) {
- *errorMessage = getInvalidTokenMessage(featureName);
- } else {
- *errorMessage = getDisabledMessage(featureName);
- }
- m_errorMessageGeneratedForFeature.add(featureName);
- return false;
-}
-
-DEFINE_TRACE(OriginTrialContext)
-{
-}
-
-} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698