Chromium Code Reviews| Index: third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp |
| diff --git a/third_party/WebKit/Source/core/experiments/Experiments.cpp b/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp |
| similarity index 60% |
| rename from third_party/WebKit/Source/core/experiments/Experiments.cpp |
| rename to third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp |
| index 3d0af4904586452027b5b084b158e4d464ed7dd5..779f1d5feeb5600a924d7d233c03e4eac9cfcdfd 100644 |
| --- a/third_party/WebKit/Source/core/experiments/Experiments.cpp |
| +++ b/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "core/experiments/Experiments.h" |
| +#include "core/origin_trials/OriginTrialContext.h" |
| #include "core/dom/ElementTraversal.h" |
| #include "core/dom/ExceptionCode.h" |
| @@ -11,39 +11,39 @@ |
| #include "platform/RuntimeEnabledFeatures.h" |
| #include "platform/weborigin/SecurityOrigin.h" |
| #include "public/platform/Platform.h" |
| -#include "public/platform/WebApiKeyValidator.h" |
| +#include "public/platform/WebTrialTokenValidator.h" |
| namespace blink { |
| namespace { |
| -const char* kExperimentsMetaName = "api-experiments"; |
| +const char* kTrialMetaTagName = "api-experiments"; |
| String getCurrentOrigin(ExecutionContext* executionContext) |
| { |
| return executionContext->securityOrigin()->toString(); |
| } |
| -String getDisabledMessage(const String& apiName) |
| +String getDisabledMessage(const String& featureName) |
| { |
| // TODO(chasej): Update message with URL to experiments site, when live |
| - return "The '" + apiName + "' API is currently enabled in limited experiments. Please see [Chrome experiments website URL] for information on enabling this experiment on your site."; |
| + return "The '" + featureName + "' API is currently enabled in limited experiments. Please see [Chrome experiments website URL] for information on enabling this experiment on your site."; |
|
chasej
2016/01/26 16:56:52
The message should refer to features and trials.
iclelland
2016/01/26 19:05:48
I like it -- done, thanks!
|
| } |
| -bool hasValidAPIKey(ExecutionContext* executionContext, const String& apiName, String* errorMessage, WebApiKeyValidator* validator) |
| +bool hasValidToken(ExecutionContext* executionContext, const String& featureName, String* errorMessage, WebTrialTokenValidator* validator) |
| { |
| bool foundAnyKey = false; |
|
chasej
2016/01/26 16:56:52
Should be foundAnyToken.
iclelland
2016/01/26 19:05:48
Done.
|
| String origin = getCurrentOrigin(executionContext); |
| - // When in a document, the API key is provided in a meta tag |
| + // When in a document, the token is provided in a meta tag |
| if (executionContext->isDocument()) { |
| HTMLHeadElement* head = toDocument(executionContext)->head(); |
| for (HTMLMetaElement* metaElement = head ? Traversal<HTMLMetaElement>::firstChild(*head) : 0; metaElement; metaElement = Traversal<HTMLMetaElement>::nextSibling(*metaElement)) { |
| - if (equalIgnoringCase(metaElement->name(), kExperimentsMetaName)) { |
| + if (equalIgnoringCase(metaElement->name(), kTrialMetaTagName)) { |
| foundAnyKey = true; |
| - String keyString = metaElement->content(); |
| + String tokenString = metaElement->content(); |
| // Check with the validator service to verify the signature. |
| - if (validator->validateApiKey(keyString, origin, apiName)) { |
| + if (validator->validateToken(tokenString, origin, featureName)) { |
| return true; |
| } |
| } |
| @@ -52,9 +52,9 @@ bool hasValidAPIKey(ExecutionContext* executionContext, const String& apiName, S |
| if (errorMessage) { |
| if (foundAnyKey) { |
| - *errorMessage = "The provided key(s) are not valid for the '" + apiName + "' API."; |
| + *errorMessage = "The provided token(s) are not valid for the '" + featureName + "' API."; |
|
chasej
2016/01/26 16:56:53
The error message should say "feature", instead of
iclelland
2016/01/26 19:05:48
Done.
|
| } else { |
| - *errorMessage = getDisabledMessage(apiName); |
| + *errorMessage = getDisabledMessage(featureName); |
| } |
| } |
| return false; |
| @@ -63,7 +63,7 @@ bool hasValidAPIKey(ExecutionContext* executionContext, const String& apiName, S |
| } // namespace |
| // static |
| -bool Experiments::isApiEnabled(ExecutionContext* executionContext, const String& apiName, String* errorMessage, WebApiKeyValidator* validator) |
| +bool OriginTrialContext::isFeatureEnabled(ExecutionContext* executionContext, const String& featureName, String* errorMessage, WebTrialTokenValidator* validator) |
| { |
| if (!RuntimeEnabledFeatures::experimentalFrameworkEnabled()) { |
| if (errorMessage) { |
| @@ -77,7 +77,7 @@ bool Experiments::isApiEnabled(ExecutionContext* executionContext, const String& |
| return false; |
| } |
| - // Experiments are only enabled for secure origins |
| + // Feature trials are only enabled for secure origins |
| bool isSecure = errorMessage |
| ? executionContext->isSecureContext(*errorMessage) |
| : executionContext->isSecureContext(); |
| @@ -86,7 +86,7 @@ bool Experiments::isApiEnabled(ExecutionContext* executionContext, const String& |
| } |
| if (!validator) { |
| - validator = Platform::current()->apiKeyValidator(); |
| + validator = Platform::current()->trialTokenValidator(); |
| if (!validator) { |
| if (errorMessage) { |
| *errorMessage = "Experimental Framework is not enabled."; |
| @@ -95,13 +95,13 @@ bool Experiments::isApiEnabled(ExecutionContext* executionContext, const String& |
| } |
| } |
| - return hasValidAPIKey(executionContext, apiName, errorMessage, validator); |
| + return hasValidToken(executionContext, featureName, errorMessage, validator); |
| } |
| // static |
| -DOMException* Experiments::createApiDisabledException(const String& apiName) |
| +DOMException* OriginTrialContext::createApiDisabledException(const String& featureName) |
|
chasej
2016/01/26 16:56:52
To be renamed or deleted, as per my comment in the
iclelland
2016/01/26 19:05:48
Deleted.
|
| { |
| - return DOMException::create(NotSupportedError, getDisabledMessage(apiName)); |
| + return DOMException::create(NotSupportedError, getDisabledMessage(featureName)); |
| } |
| } // namespace blink |