Bug 1171682 - Disable WebGL in safemode. r=jgilbert, a=lizzard
authorBenoit Girard <b56girard@gmail.com>
Thu, 18 Jun 2015 00:04:08 -0400
changeset 267760 7b634b5a66bfefe3b3adbc3d8aa4e13bad8e3455
parent 267759 36b1d114889658d52192a35b2d137819a6aa1408
child 267761 4f7839723f0df142abc1d29df254a69c3c17e9e0
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert, lizzard
bugs1171682
milestone39.0
Bug 1171682 - Disable WebGL in safemode. r=jgilbert, a=lizzard
dom/canvas/WebGLContext.cpp
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -863,16 +863,20 @@ WebGLContext::SetDimensions(int32_t sign
         GenerateWarning("Too many WebGL contexts created this run.");
         return NS_ERROR_FAILURE; // exit without changing the value of mGeneration
     }
 
     // Get some prefs for some preferred/overriden things
     NS_ENSURE_TRUE(Preferences::GetRootBranch(), NS_ERROR_FAILURE);
 
     bool disabled = Preferences::GetBool("webgl.disabled", false);
+
+    // TODO: When we have software webgl support we should use that instead.
+    disabled |= gfxPlatform::InSafeMode();
+
     if (disabled) {
         GenerateWarning("WebGL creation is disabled, and so disallowed here.");
         return NS_ERROR_FAILURE;
     }
 
     // Alright, now let's start trying.
     bool forceEnabled = Preferences::GetBool("webgl.force-enabled", false);
     ScopedGfxFeatureReporter reporter("WebGL", forceEnabled);
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -1825,16 +1825,32 @@ gfxPlatform::TransformPixel(const Color&
         out = Color::FromARGB(packed);
 #endif
     }
 
     else if (&out != &in)
         out = in;
 }
 
+bool
+gfxPlatform::InSafeMode()
+{
+  static bool sSafeModeInitialized = false;
+  static bool sInSafeMode = false;
+
+  if (!sSafeModeInitialized) {
+    sSafeModeInitialized = true;
+    nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
+    if (xr) {
+      xr->GetInSafeMode(&sInSafeMode);
+    }
+  }
+  return sInSafeMode;
+}
+
 void
 gfxPlatform::GetPlatformCMSOutputProfile(void *&mem, size_t &size)
 {
     mem = nullptr;
     size = 0;
 }
 
 void
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -18,16 +18,17 @@
 #include "gfxFontFamilyList.h"
 #include "gfxBlur.h"
 #include "nsRect.h"
 
 #include "qcms.h"
 
 #include "mozilla/RefPtr.h"
 #include "GfxInfoCollector.h"
+#include "nsIXULRuntime.h"
 
 #include "mozilla/layers/CompositorTypes.h"
 
 class gfxASurface;
 class gfxFont;
 class gfxFontGroup;
 struct gfxFontStyle;
 class gfxUserFontSet;
@@ -195,16 +196,17 @@ public:
      * Shut down Thebes.
      * Init() arranges for this to be called at an appropriate time.
      */
     static void Shutdown();
 
     static void InitLayersIPC();
     static void ShutdownLayersIPC();
 
+    static bool InSafeMode();
     /**
      * Create an offscreen surface of the given dimensions
      * and image format.
      */
     virtual already_AddRefed<gfxASurface>
       CreateOffscreenSurface(const IntSize& size,
                              gfxContentType contentType) = 0;