Bug 1373739 - Disable WebGL in headless mode. r?bdahl
MozReview-Commit-ID: LWe9hRh7zXX
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -676,16 +676,25 @@ WebGLContext::CreateAndInitGLWith(FnCrea
return true;
}
bool
WebGLContext::CreateAndInitGL(bool forceEnabled,
std::vector<FailureReason>* const out_failReasons)
{
+ // Can't use WebGL in headless mode.
+ if (gfxPlatform::IsHeadless()) {
+ FailureReason reason;
+ reason.info = "Can't use WebGL in headless mode (https://bugzil.la/1375585).";
+ out_failReasons->push_back(reason);
+ GenerateWarning("%s", reason.info.BeginReading());
+ return false;
+ }
+
// WebGL2 is separately blocked:
if (IsWebGL2()) {
const nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
const auto feature = nsIGfxInfo::FEATURE_WEBGL2;
FailureReason reason;
if (IsFeatureInBlacklist(gfxInfo, feature, &reason.key)) {
reason.info = "Refused to create WebGL2 context because of blacklist"
--- a/testing/web-platform/tests/WebIDL/current-realm.html
+++ b/testing/web-platform/tests/WebIDL/current-realm.html
@@ -105,18 +105,23 @@
assert_global(obj)
}, val)
})
;["2d", "webgl"].forEach(function(val) {
test(function() {
var c = self[0].document.createElement("canvas"),
obj = c.getContext(val)
+
+ // WebGL might not be enabled in this environment
+ if (!obj && val === "webgl") {
+ return;
+ }
+
assert_global(obj)
-
obj = HTMLCanvasElement.prototype.getContext.call(c, val)
assert_global(obj)
}, "getContext " + val)
})
;[["createImageData", 5, 5],
["getImageData", 5, 5, 5, 5]].forEach(function(val) {
test(function() {