Bug 1477432 - Part 4: Remove the nsJSID XPCOM constructor, r=mccr8
authorNika Layzell <nika@thelayzells.com>
Wed, 18 Jul 2018 00:12:57 -0400
changeset 446899 e3b4c9cdfbd7e118ada704337d1bffa5cae93676
parent 446898 ecbe615201fab977a6d753230b146bd04a83b156
child 446900 c019316fcfd49d74775c9b458b3d611f8081ee7e
push id35053
push userapavel@mozilla.com
push dateSat, 17 Nov 2018 11:27:54 +0000
treeherdermozilla-central@e4deec61fc8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1477432
milestone65.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 1477432 - Part 4: Remove the nsJSID XPCOM constructor, r=mccr8 Nobody was using it, so it's pretty easy to remove. Differential Revision: https://phabricator.services.mozilla.com/D2281
js/xpconnect/idl/xpcjsid.idl
js/xpconnect/src/XPCComponents.cpp
js/xpconnect/src/XPCJSID.cpp
js/xpconnect/src/XPCModule.h
js/xpconnect/src/xpcprivate.h
--- a/js/xpconnect/idl/xpcjsid.idl
+++ b/js/xpconnect/idl/xpcjsid.idl
@@ -31,17 +31,8 @@ interface nsIJSIID : nsIJSID
 
 [builtinclass, scriptable, uuid(bf5eb086-9eaa-4694-aec3-fe4aac6119bd)]
 interface nsIJSCID : nsIJSID
 {
     [implicit_jscontext,optional_argc] jsval createInstance([optional] in jsval iid);
     [implicit_jscontext,optional_argc] jsval getService([optional] in jsval iid);
 };
 
-/* this goes into the C++ header verbatim. */
-%{ C++
-/********************************************************/
-// {F24A14F0-4FA1-11d3-9894-006008962422}
-#define NS_JS_ID_CID  \
-{ 0xf24a14f0, 0x4fa1, 0x11d3, \
-    { 0x98, 0x94, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
-%}
-
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -1185,22 +1185,19 @@ nsXPCComponents_ID::CallOrConstruct(nsIX
                                     const CallArgs& args, bool* _retval)
 {
     // make sure we have at least one arg
 
     if (args.length() < 1) {
         return ThrowAndFail(NS_ERROR_XPC_NOT_ENOUGH_ARGS, cx, _retval);
     }
 
-    // Do the security check if necessary
-
-    if (NS_FAILED(nsXPConnect::SecurityManager()->CanCreateInstance(cx, nsJSID::GetCID()))) {
-        // the security manager vetoed. It should have set an exception.
-        *_retval = false;
-        return NS_OK;
+    // Prevent non-chrome code from creating ID objects.
+    if (!nsContentUtils::IsCallerChrome()) {
+        return ThrowAndFail(NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED, cx, _retval);
     }
 
     // convert the first argument into a string and see if it looks like an id
 
     JSString* jsstr = ToString(cx, args[0]);
     if (!jsstr) {
         return ThrowAndFail(NS_ERROR_XPC_BAD_ID_STRING, cx, _retval);
     }
--- a/js/xpconnect/src/XPCJSID.cpp
+++ b/js/xpconnect/src/XPCJSID.cpp
@@ -14,17 +14,21 @@
 #include "mozilla/StaticPtr.h"
 
 using namespace mozilla::dom;
 using namespace JS;
 
 /***************************************************************************/
 // nsJSID
 
-NS_IMPL_CLASSINFO(nsJSID, nullptr, 0, NS_JS_ID_CID)
+#define NULL_CID                                                              \
+{ 0x00000000, 0x0000, 0x0000,                                                 \
+  { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }
+
+NS_IMPL_CLASSINFO(nsJSID, nullptr, 0, NULL_CID)
 NS_IMPL_ISUPPORTS_CI(nsJSID, nsIJSID)
 
 const char nsJSID::gNoString[] = "";
 
 nsJSID::nsJSID()
     : mID(GetInvalidIID()),
       mNumber(const_cast<char*>(gNoString)),
       mName(const_cast<char*>(gNoString))
@@ -251,20 +255,16 @@ static nsresult GetSharedScriptableHelpe
     EnsureClassObjectsInitialized();
     nsCOMPtr<nsIXPCScriptable> temp = gSharedScriptableHelperForJSIID.get();
     temp.forget(helper);
     return NS_OK;
 }
 
 /******************************************************/
 
-#define NULL_CID                                                              \
-{ 0x00000000, 0x0000, 0x0000,                                                 \
-  { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }
-
 NS_DECL_CI_INTERFACE_GETTER(nsJSIID)
 NS_IMPL_CLASSINFO(nsJSIID, GetSharedScriptableHelperForJSIID, 0, NULL_CID)
 
 NS_DECL_CI_INTERFACE_GETTER(nsJSCID)
 NS_IMPL_CLASSINFO(nsJSCID, nullptr, 0, NULL_CID)
 
 void xpc_DestroyJSxIDClassObjects()
 {
--- a/js/xpconnect/src/XPCModule.h
+++ b/js/xpconnect/src/XPCModule.h
@@ -14,23 +14,20 @@
 
 // {FE4F7592-C1FC-4662-AC83-538841318803}
 #define SCRIPTABLE_INTERFACES_CID                                             \
     {0xfe4f7592, 0xc1fc, 0x4662,                                              \
       { 0xac, 0x83, 0x53, 0x88, 0x41, 0x31, 0x88, 0x3 } }
 
 #define MOZJSSUBSCRIPTLOADER_CONTRACTID "@mozilla.org/moz/jssubscript-loader;1"
 
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSID)
 NS_GENERIC_FACTORY_CONSTRUCTOR(mozJSSubScriptLoader)
 
-NS_DEFINE_NAMED_CID(NS_JS_ID_CID);
 NS_DEFINE_NAMED_CID(MOZ_JSSUBSCRIPTLOADER_CID);
 
 #define XPCONNECT_CIDENTRIES                                                  \
-  { &kNS_JS_ID_CID, false, nullptr,  nsJSIDConstructor },                     \
   { &kMOZ_JSSUBSCRIPTLOADER_CID, false, nullptr, mozJSSubScriptLoaderConstructor },
 
 #define XPCONNECT_CONTRACTS                                                   \
   { MOZJSSUBSCRIPTLOADER_CONTRACTID, &kMOZ_JSSUBSCRIPTLOADER_CID },
 
 nsresult xpcModuleCtor();
 void xpcModuleDtor();
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -2145,18 +2145,16 @@ public:
 
 // Initialization is done on demand, and calling the destructor below is always
 // safe.
 extern void xpc_DestroyJSxIDClassObjects();
 
 class nsJSID final : public nsIJSID
 {
 public:
-    NS_DEFINE_STATIC_CID_ACCESSOR(NS_JS_ID_CID)
-
     NS_DECL_ISUPPORTS
     NS_DECL_NSIJSID
 
     void InitWithName(const nsID& id, const char* nameString);
     void SetName(const char* name);
     void   SetNameToNoString()
         {MOZ_ASSERT(!mName, "name already set"); mName = const_cast<char*>(gNoString);}
     bool NameIsSet() const {return nullptr != mName;}