Bug 668030. Warn when enablePrivilege is used. r=sicking
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 28 Jun 2011 21:05:45 -0400
changeset 71952 2cb11a5daaf519d2c86cfd9d4514d7f78db9589d
parent 71951 59a6f55244764c2a0c1e4c251234730694f480b3
child 71953 072083211e32fec7aaba944f086937d5949c91da
push id299
push userbzbarsky@mozilla.com
push dateWed, 29 Jun 2011 01:07:23 +0000
treeherdermozilla-inbound@2cb11a5daaf5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs668030
milestone7.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 668030. Warn when enablePrivilege is used. r=sicking
caps/src/Makefile.in
caps/src/nsSecurityManagerFactory.cpp
content/base/public/nsDeprecatedOperationList.h
content/base/src/nsDocument.cpp
dom/locales/en-US/chrome/dom/dom.properties
--- a/caps/src/Makefile.in
+++ b/caps/src/Makefile.in
@@ -56,10 +56,11 @@ CPPSRCS		= \
 		nsJSPrincipals.cpp \
 		nsScriptSecurityManager.cpp \
 		nsSecurityManagerFactory.cpp \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
 INCLUDES	+= -I$(srcdir)/../include \
-		   -I$(topsrcdir)/js/src/xpconnect/src
+		   -I$(topsrcdir)/js/src/xpconnect/src \
+		   -I$(topsrcdir)/dom/base
 
--- a/caps/src/nsSecurityManagerFactory.cpp
+++ b/caps/src/nsSecurityManagerFactory.cpp
@@ -48,16 +48,20 @@
 #include "nsICategoryManager.h"
 #include "nsXPIDLString.h"
 #include "nsCOMPtr.h"
 #include "nsIServiceManager.h"
 #include "nsString.h"
 #include "nsNetCID.h"
 #include "nsIClassInfoImpl.h"
 #include "jsobj.h"
+#include "nsJSUtils.h"
+#include "nsPIDOMWindow.h"
+#include "nsIScriptGlobalObject.h"
+#include "nsIDocument.h"
 
 ///////////////////////
 // nsSecurityNameSet //
 ///////////////////////
 
 nsSecurityNameSet::nsSecurityNameSet()
 {
 }
@@ -152,16 +156,33 @@ netscape_security_enablePrivilege(JSCont
     JSObject *obj = JS_THIS_OBJECT(cx, vp);
     if (!obj)
         return JS_FALSE;
 
     JSAutoByteString cap;
     if (!getBytesArgument(cx, obj, 0, argc, JS_ARGV(cx, vp), &cap))
         return JS_FALSE;
 
+    // Can't use nsContentUtils::GetDocumentFromCaller because that
+    // depends on various XPConnect stuff that's not set up here.
+    {
+        JSAutoEnterCompartment ac;
+        if (ac.enter(cx, obj)) {
+            nsCOMPtr<nsPIDOMWindow> win =
+                do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(cx, obj));
+            if (win) {
+                nsCOMPtr<nsIDocument> doc =
+                    do_QueryInterface(win->GetExtantDocument());
+                if (doc) {
+                    doc->WarnOnceAbout(nsIDocument::eEnablePrivilege);
+                }
+            }
+        }
+    }
+
     nsresult rv;
     nsCOMPtr<nsIScriptSecurityManager> securityManager = 
              do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
     if (NS_FAILED(rv)) 
         return JS_FALSE;
 
     //    NS_ASSERTION(cx == GetCurrentContext(), "unexpected context");
 
--- a/content/base/public/nsDeprecatedOperationList.h
+++ b/content/base/public/nsDeprecatedOperationList.h
@@ -65,8 +65,9 @@ DEPRECATED_OPERATION(ReplaceChild)
 DEPRECATED_OPERATION(RemoveChild)
 DEPRECATED_OPERATION(AppendChild)
 DEPRECATED_OPERATION(CloneNode)
 DEPRECATED_OPERATION(OwnerDocument)
 DEPRECATED_OPERATION(Normalize)
 DEPRECATED_OPERATION(IsSupported)
 DEPRECATED_OPERATION(IsEqualNode)
 DEPRECATED_OPERATION(TextContent)
+DEPRECATED_OPERATION(EnablePrivilege)
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -8134,17 +8134,17 @@ nsDocument::FindImageMap(const nsAString
 static const char* kWarnings[] = {
 #include "nsDeprecatedOperationList.h"
 };
 #undef DEPRECATED_OPERATION
 
 void
 nsIDocument::WarnOnceAbout(DeprecatedOperations aOperation)
 {
-  PR_STATIC_ASSERT(NS_ARRAY_LENGTH(kWarnings) < 32);
+  PR_STATIC_ASSERT(NS_ARRAY_LENGTH(kWarnings) <= 32);
   if (mWarnedAbout & (1 << aOperation)) {
     return;
   }
   mWarnedAbout |= (1 << aOperation);
   nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
                                   kWarnings[aOperation],
                                   nsnull, 0,
                                   nsnull,
--- a/dom/locales/en-US/chrome/dom/dom.properties
+++ b/dom/locales/en-US/chrome/dom/dom.properties
@@ -102,8 +102,9 @@ ReplaceChildWarning=Use of attributes' r
 RemoveChildWarning=Use of attributes' removeChild() is deprecated. Use value instead.
 AppendChildWarning=Use of attributes' appendChild() is deprecated. Use value instead.
 CloneNodeWarning=Use of attributes' cloneNode() is deprecated.
 OwnerDocumentWarning=Use of attributes' ownerDocument attribute is deprecated.
 NormalizeWarning=Use of attributes' normalize() is deprecated.
 IsSupportedWarning=Use of attributes' isSupported() is deprecated.
 IsEqualNodeWarning=Use of attributes' isEqualNode() is deprecated.
 TextContentWarning=Use of attributes' textContent attribute is deprecated. Use value instead.
+EnablePrivilegeWarning=Use of enablePrivilege is deprecated.  Please use code that runs with the system principal (e.g. an extension) instead.