Bug 1033391 - Enable GeometryUtils APIs in privileged code. r=smaug, r=roc, a=sledru
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Thu, 03 Jul 2014 14:23:14 +0100
changeset 209104 9234fae30e387995cbd70ce44043729926bdd9c2
parent 209103 883f4666206ee53f5834be6d1361e264f62bd487
child 209105 0bca394227a75948b90591d532b34a15ab8085fc
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, roc, sledru
bugs1033391
milestone32.0a2
Bug 1033391 - Enable GeometryUtils APIs in privileged code. r=smaug, r=roc, a=sledru
content/base/public/nsINode.h
content/base/src/nsINode.cpp
dom/webidl/GeometryUtils.webidl
--- a/content/base/public/nsINode.h
+++ b/content/base/public/nsINode.h
@@ -391,16 +391,22 @@ public:
    *
    * @param aFlags what types you want to test for (see above)
    * @return whether the content matches ALL flags passed in
    */
   virtual bool IsNodeOfType(uint32_t aFlags) const = 0;
 
   virtual JSObject* WrapObject(JSContext *aCx) MOZ_OVERRIDE;
 
+  /**
+   * returns true if we are in priviliged code or
+   * layout.css.getBoxQuads.enabled == true.
+   */
+  static bool HasBoxQuadsSupport(JSContext* aCx, JSObject* /* unused */);
+
 protected:
   /**
    * WrapNode is called from WrapObject to actually wrap this node, WrapObject
    * does some additional checks and fix-up that's common to all nodes. WrapNode
    * should just call the DOM binding's Wrap function.
    */
   virtual JSObject* WrapNode(JSContext *aCx)
   {
--- a/content/base/src/nsINode.cpp
+++ b/content/base/src/nsINode.cpp
@@ -86,16 +86,17 @@
 #include "nsString.h"
 #include "nsStyleConsts.h"
 #include "nsSVGFeatures.h"
 #include "nsSVGUtils.h"
 #include "nsTextNode.h"
 #include "nsUnicharUtils.h"
 #include "nsXBLBinding.h"
 #include "nsXBLPrototypeBinding.h"
+#include "mozilla/Preferences.h"
 #include "prprf.h"
 #include "xpcpublic.h"
 #include "nsCSSRuleProcessor.h"
 #include "nsCSSParser.h"
 #include "HTMLLegendElement.h"
 #include "nsWrapperCacheInlines.h"
 #include "WrapperFactory.h"
 #include "DocumentType.h"
@@ -2731,8 +2732,15 @@ nsINode::GetAttributes()
 bool
 EventTarget::DispatchEvent(Event& aEvent,
                            ErrorResult& aRv)
 {
   bool result = false;
   aRv = DispatchEvent(&aEvent, &result);
   return result;
 }
+
+bool
+nsINode::HasBoxQuadsSupport(JSContext* aCx, JSObject* /* unused */)
+{
+  return xpc::AccessCheck::isChrome(js::GetContextCompartment(aCx)) ||
+         Preferences::GetBool("layout.css.getBoxQuads.enabled");
+}
--- a/dom/webidl/GeometryUtils.webidl
+++ b/dom/webidl/GeometryUtils.webidl
@@ -18,24 +18,24 @@ dictionary BoxQuadOptions {
 
 dictionary ConvertCoordinateOptions {
   CSSBoxType fromBox = "border";
   CSSBoxType toBox = "border";
 };
 
 [NoInterfaceObject]
 interface GeometryUtils {
-  [Throws, Pref="layout.css.getBoxQuads.enabled"]
+  [Throws, Func="nsINode::HasBoxQuadsSupport"]
   sequence<DOMQuad> getBoxQuads(optional BoxQuadOptions options);
   [Throws, Pref="layout.css.convertFromNode.enabled"]
   DOMQuad convertQuadFromNode(DOMQuad quad, GeometryNode from, optional ConvertCoordinateOptions options);
   [Throws, Pref="layout.css.convertFromNode.enabled"]
   DOMQuad convertRectFromNode(DOMRectReadOnly rect, GeometryNode from, optional ConvertCoordinateOptions options);
   [Throws, Pref="layout.css.convertFromNode.enabled"]
   DOMPoint convertPointFromNode(DOMPointInit point, GeometryNode from, optional ConvertCoordinateOptions options);
 };
 
 Text implements GeometryUtils;
 Element implements GeometryUtils;
 // PseudoElement implements GeometryUtils;
 Document implements GeometryUtils;
 
-typedef (Text or Element /* or PseudoElement */ or Document) GeometryNode;
\ No newline at end of file
+typedef (Text or Element /* or PseudoElement */ or Document) GeometryNode;