Bug 1373739 - Disable WebGL in headless mode. r?bdahl draft
authorMichael Smith <michael@spinda.net>
Thu, 22 Jun 2017 10:13:12 -0700
changeset 620644 2115944296bffca3d3b075d86e136882f5613174
parent 618576 87824406b9feb420a3150720707b424d7cee5915
child 620645 df073d68225b28d8da4385b5c5aa2835aabe912e
push id72121
push userbmo:lists@spinda.net
push dateThu, 03 Aug 2017 18:54:01 +0000
reviewersbdahl
bugs1373739
milestone56.0a1
Bug 1373739 - Disable WebGL in headless mode. r?bdahl MozReview-Commit-ID: LWe9hRh7zXX
dom/canvas/WebGLContext.cpp
testing/web-platform/tests/WebIDL/current-realm.html
--- 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() {