Bug 842372 - Part 1: Implement nsINode::ShouldExposeUserData. r=bholley
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sat, 23 Feb 2013 13:46:05 +0900
changeset 122718 b2045d4808bf562c52ce668c8597595898505c66
parent 122717 be239b15a0f1334b216985bd91e6f89834c43b48
child 122719 6b597b71926503de2713b34313eebe67a9fd796c
push id23459
push userVYV03354@nifty.ne.jp
push dateSat, 23 Feb 2013 04:46:33 +0000
treeherdermozilla-inbound@6b597b719265 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs842372
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 842372 - Part 1: Implement nsINode::ShouldExposeUserData. r=bholley
content/base/public/nsINode.h
content/base/src/nsINode.cpp
--- a/content/base/public/nsINode.h
+++ b/content/base/public/nsINode.h
@@ -1130,16 +1130,22 @@ public:
 
   nsresult GetUserData(const nsAString& aKey, nsIVariant** aResult)
   {
     NS_IF_ADDREF(*aResult = GetUserData(aKey));
   
     return NS_OK;
   }
 
+  /**
+   * Control if GetUserData and SetUserData methods will be exposed to
+   * unprivileged content.
+   */
+  static bool ShouldExposeUserData(JSContext* aCx, JSObject* /* unused */);
+
   void LookupPrefix(const nsAString& aNamespace, nsAString& aResult);
   bool IsDefaultNamespace(const nsAString& aNamespaceURI)
   {
     nsAutoString defaultNamespace;
     LookupNamespaceURI(EmptyString(), defaultNamespace);
     return aNamespaceURI.Equals(defaultNamespace);
   }
   void LookupNamespaceURI(const nsAString& aNamespacePrefix,
--- a/content/base/src/nsINode.cpp
+++ b/content/base/src/nsINode.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * Base class for all DOM nodes.
  */
 
 #include "nsINode.h"
 
+#include "AccessCheck.h"
 #include "jsapi.h"
 #include "mozAutoDocUpdate.h"
 #include "mozilla/CORSMode.h"
 #include "mozilla/Likely.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/Util.h"
 #include "nsAsyncDOMEvent.h"
 #include "nsAttrValueOrString.h"
@@ -91,16 +92,17 @@
 #include "nsSVGFeatures.h"
 #include "nsSVGUtils.h"
 #include "nsTextNode.h"
 #include "nsUnicharUtils.h"
 #include "nsXBLBinding.h"
 #include "nsXBLInsertionPoint.h"
 #include "nsXBLPrototypeBinding.h"
 #include "prprf.h"
+#include "xpcprivate.h" // XBLScopesEnabled
 #include "xpcpublic.h"
 #include "nsCSSRuleProcessor.h"
 #include "nsCSSParser.h"
 #include "HTMLLegendElement.h"
 #include "nsWrapperCacheInlines.h"
 #include "WrapperFactory.h"
 #include "DocumentType.h"
 #include <algorithm>
@@ -714,16 +716,26 @@ nsINode::GetUserData(JSContext* aCx, con
 
   JS::Value result;
   JSAutoCompartment ac(aCx, GetWrapper());
   aError = nsContentUtils::XPConnect()->VariantToJS(aCx, GetWrapper(), data,
                                                     &result);
   return result;
 }
 
+//static
+bool
+nsINode::ShouldExposeUserData(JSContext* aCx, JSObject* /* unused */)
+{
+  JSCompartment* compartment = js::GetContextCompartment(aCx);
+  return xpc::AccessCheck::isChrome(compartment) ||
+         xpc::IsXBLScope(compartment) ||
+         !XPCJSRuntime::Get()->XBLScopesEnabled();
+}
+
 uint16_t
 nsINode::CompareDocumentPosition(nsINode& aOtherNode) const
 {
   if (this == &aOtherNode) {
     return 0;
   }
 
   nsAutoTArray<const nsINode*, 32> parents1, parents2;