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

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: Update comments to explain class design and code generation Created 4 years, 11 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/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..011e381d9c648ab5d0cc4636e5749d27e26e3b4b 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,26 @@ 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
-bool Experiments::isApiEnabled(ExecutionContext* executionContext, const String& apiName, String& errorMessage)
+// static
+bool Experiments::isApiEnabled(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 +73,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