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

Unified Diff: third_party/WebKit/Source/core/experiments/Experiments.cpp

Issue 1541983003: Force all experiment enabled checks to use ExperimentalFeatures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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/experiments/Experiments.cpp
diff --git a/third_party/WebKit/Source/core/experiments/Experiments.cpp b/third_party/WebKit/Source/core/experiments/Experiments.cpp
index b3274eef793e9c161bd66d48f8e46db1907d5dd6..33487acf448d0cfb5459cc166f735c66cfd17eb0 100644
--- a/third_party/WebKit/Source/core/experiments/Experiments.cpp
+++ b/third_party/WebKit/Source/core/experiments/Experiments.cpp
@@ -28,7 +28,7 @@ String getDisabledMessage(const String& apiName)
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.";
}
-bool hasValidAPIKey(ExecutionContext* executionContext, const String& apiName, String& errorMessage)
+bool hasValidAPIKey(ExecutionContext* executionContext, const String& apiName, String* errorMessage)
{
bool foundAnyKey = false;
String origin = getCurrentOrigin(executionContext);
@@ -44,20 +44,38 @@ bool hasValidAPIKey(ExecutionContext* executionContext, const String& apiName, S
}
}
}
- if (foundAnyKey) {
- errorMessage = "The provided key(s) are not valid for the '" + apiName + "' API.";
- } else {
- errorMessage = getDisabledMessage(apiName);
+
+ if (errorMessage) {
+ if (foundAnyKey) {
+ *errorMessage = "The provided key(s) are not valid for the '" + apiName + "' API.";
+ } else {
+ *errorMessage = getDisabledMessage(apiName);
+ }
}
return false;
}
} // namespace
+// static
bool Experiments::isApiEnabled(ExecutionContext* executionContext, const String& apiName, String& errorMessage)
{
+ return isApiEnabledImpl(executionContext, apiName, &errorMessage);
+}
+
+// static
+bool Experiments::isApiEnabled(ExecutionContext* executionContext, const String& apiName)
iclelland 2015/12/23 03:56:12 This method isn't used anywhere outside of the Exp
chasej 2015/12/23 15:58:24 At this point, I don't believe there should be any
+{
+ return isApiEnabledImpl(executionContext, apiName, nullptr);
+}
+
+// static
+bool Experiments::isApiEnabledImpl(ExecutionContext* executionContext, const String& apiName, String* errorMessage)
+{
if (!RuntimeEnabledFeatures::experimentalFrameworkEnabled()) {
- errorMessage = "Experimental Framework is not enabled.";
+ if (errorMessage) {
+ *errorMessage = "Experimental Framework is not enabled.";
+ }
return false;
}
@@ -67,13 +85,17 @@ bool Experiments::isApiEnabled(ExecutionContext* executionContext, const String&
}
// Experiments are only enabled for secure origins
- if (!executionContext->isSecureContext(errorMessage)) {
+ bool isSecure = errorMessage
+ ? executionContext->isSecureContext(*errorMessage)
+ : executionContext->isSecureContext();
+ if (!isSecure) {
return false;
}
return hasValidAPIKey(executionContext, apiName, errorMessage);
}
+// static
DOMException* Experiments::createApiDisabledException(const String& apiName)
{
return DOMException::create(NotSupportedError, getDisabledMessage(apiName));

Powered by Google App Engine
This is Rietveld 408576698