From 25916a65c0bba547c1af5e1e81be6b7eb3471dac Mon Sep 17 00:00:00 2001 From: Benjamin Smedberg Date: Fri, 1 May 2015 10:23:44 -0400 Subject: [PATCH] Bug 1159737 Stop supporting binary XPCOM components except built into the application. r=froydnj sr=bz Some xpcshell tests of binary functionality need to register binary components. Expose a function "registerAppManifest" in the xpcshell environment to make this available to tests without exposing it to addons. r=bholley --- js/xpconnect/src/XPCShellImpl.cpp | 33 ++++++++++++++++++- js/xpconnect/tests/unit/test_attributes.js | 4 +-- js/xpconnect/tests/unit/test_params.js | 4 +-- js/xpconnect/tests/unit/test_returncode.js | 4 +-- startupcache/test/TestStartupCache.cpp | 2 +- toolkit/xre/nsXREDirProvider.cpp | 4 +-- xpcom/build/nsXULAppAPI.h | 8 +++-- xpcom/components/ManifestParser.cpp | 38 +++++++++++++--------- xpcom/components/nsComponentManager.cpp | 14 ++++---- xpcom/tests/TestRegistrationOrder.cpp | 6 ++-- xpcom/tests/unit/test_bug656331.js | 2 +- xpcom/tests/unit/test_comp_no_aslr.js | 2 +- xpcom/tests/unit/test_compmgr_warnings.js | 5 ++- 13 files changed, 84 insertions(+), 42 deletions(-) diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp index 1bf90a19aca..fc139297bc8 100644 --- a/js/xpconnect/src/XPCShellImpl.cpp +++ b/js/xpconnect/src/XPCShellImpl.cpp @@ -27,6 +27,7 @@ #include "nsAutoPtr.h" #include "nsJSPrincipals.h" #include "xpcpublic.h" +#include "xpcprivate.h" #include "BackstagePass.h" #include "nsIScriptSecurityManager.h" #include "nsIPrincipal.h" @@ -632,6 +633,35 @@ SimulateActivityCallback(JSContext* cx, unsigned argc, jsval* vp) return true; } +static bool +RegisterAppManifest(JSContext* cx, unsigned argc, jsval* vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (args.length() != 1) { + JS_ReportError(cx, "Wrong number of arguments"); + return false; + } + if (!args[0].isObject()) { + JS_ReportError(cx, "Expected object as argument 1 to registerAppManifest"); + return false; + } + + Rooted arg1(cx, &args[0].toObject()); + nsCOMPtr file; + nsresult rv = nsXPConnect::XPConnect()-> + WrapJS(cx, arg1, NS_GET_IID(nsIFile), getter_AddRefs(file)); + if (NS_FAILED(rv)) { + XPCThrower::Throw(rv, cx); + return false; + } + rv = XRE_AddManifestLocation(NS_APP_LOCATION, file); + if (NS_FAILED(rv)) { + XPCThrower::Throw(rv, cx); + return false; + } + return true; +} + static const JSFunctionSpec glob_functions[] = { JS_FS("print", Print, 0,0), JS_FS("readline", ReadLine, 1,0), @@ -652,6 +682,7 @@ static const JSFunctionSpec glob_functions[] = { JS_FS("btoa", Btoa, 1,0), JS_FS("setInterruptCallback", SetInterruptCallback, 1,0), JS_FS("simulateActivityCallback", SimulateActivityCallback, 1,0), + JS_FS("registerAppManifest", RegisterAppManifest, 1, 0), JS_FS_END }; @@ -1341,7 +1372,7 @@ XRE_XPCShellMain(int argc, char** argv, char** envp) printf("Couldn't get manifest file.\n"); return 1; } - XRE_AddManifestLocation(NS_COMPONENT_LOCATION, lf); + XRE_AddManifestLocation(NS_APP_LOCATION, lf); argc -= 2; argv += 2; diff --git a/js/xpconnect/tests/unit/test_attributes.js b/js/xpconnect/tests/unit/test_attributes.js index c033728b7bd..53bebf8650a 100644 --- a/js/xpconnect/tests/unit/test_attributes.js +++ b/js/xpconnect/tests/unit/test_attributes.js @@ -8,8 +8,8 @@ const Ci = Components.interfaces; function run_test() { // Load the component manifests. - Components.manager.autoRegister(do_get_file('../components/native/xpctest.manifest')); - Components.manager.autoRegister(do_get_file('../components/js/xpctest.manifest')); + registerAppManifest(do_get_file('../components/native/xpctest.manifest')); + registerAppManifest(do_get_file('../components/js/xpctest.manifest')); // Test for each component. test_component_readwrite("@mozilla.org/js/xpc/test/native/ObjectReadWrite;1"); diff --git a/js/xpconnect/tests/unit/test_params.js b/js/xpconnect/tests/unit/test_params.js index dbe2ae4a0cf..8c2317a5a7d 100644 --- a/js/xpconnect/tests/unit/test_params.js +++ b/js/xpconnect/tests/unit/test_params.js @@ -8,8 +8,8 @@ const Ci = Components.interfaces; function run_test() { // Load the component manifests. - Components.manager.autoRegister(do_get_file('../components/native/xpctest.manifest')); - Components.manager.autoRegister(do_get_file('../components/js/xpctest.manifest')); + registerAppManifest(do_get_file('../components/native/xpctest.manifest')); + registerAppManifest(do_get_file('../components/js/xpctest.manifest')); // Test for each component. test_component("@mozilla.org/js/xpc/test/native/Params;1"); diff --git a/js/xpconnect/tests/unit/test_returncode.js b/js/xpconnect/tests/unit/test_returncode.js index 5aeb68076a9..ea3a6109963 100644 --- a/js/xpconnect/tests/unit/test_returncode.js +++ b/js/xpconnect/tests/unit/test_returncode.js @@ -16,8 +16,8 @@ function getConsoleMessages() { function run_test() { // Load the component manifests. - Cm.autoRegister(do_get_file('../components/native/xpctest.manifest')); - Cm.autoRegister(do_get_file('../components/js/xpctest.manifest')); + registerAppManifest(do_get_file('../components/native/xpctest.manifest')); + registerAppManifest(do_get_file('../components/js/xpctest.manifest')); // and the tests. test_simple(); diff --git a/startupcache/test/TestStartupCache.cpp b/startupcache/test/TestStartupCache.cpp index 122950c82b6..4ae876906df 100644 --- a/startupcache/test/TestStartupCache.cpp +++ b/startupcache/test/TestStartupCache.cpp @@ -438,7 +438,7 @@ int main(int argc, char** argv) NS_LITERAL_CSTRING("TestStartupCacheTelemetry.manifest")); #endif - XRE_AddManifestLocation(NS_COMPONENT_LOCATION, manifest); + XRE_AddManifestLocation(NS_APP_LOCATION, manifest); nsCOMPtr telemetryThing = do_GetService("@mozilla.org/testing/startup-cache-telemetry.js"); diff --git a/toolkit/xre/nsXREDirProvider.cpp b/toolkit/xre/nsXREDirProvider.cpp index 44933c0f84d..6bb3d5a3701 100644 --- a/toolkit/xre/nsXREDirProvider.cpp +++ b/toolkit/xre/nsXREDirProvider.cpp @@ -635,7 +635,7 @@ nsXREDirProvider::LoadExtensionBundleDirectories() RegisterExtensionInterpositions(parser); LoadExtensionDirectories(parser, "ExtensionDirs", mExtensionDirectories, - NS_COMPONENT_LOCATION); + NS_EXTENSION_LOCATION); LoadExtensionDirectories(parser, "ThemeDirs", mThemeDirectories, NS_SKIN_LOCATION); } @@ -667,7 +667,7 @@ nsXREDirProvider::LoadAppBundleDirs() nsCOMPtr manifest = CloneAndAppend(subdir, "chrome.manifest"); - XRE_AddManifestLocation(NS_COMPONENT_LOCATION, manifest); + XRE_AddManifestLocation(NS_EXTENSION_LOCATION, manifest); } } diff --git a/xpcom/build/nsXULAppAPI.h b/xpcom/build/nsXULAppAPI.h index d26b8da7fb5..230520c8b8a 100644 --- a/xpcom/build/nsXULAppAPI.h +++ b/xpcom/build/nsXULAppAPI.h @@ -240,15 +240,19 @@ XRE_API(nsresult, * @param aFileCount the number of items in the aFiles array. * @note appdir/components is registered automatically. * - * NS_COMPONENT_LOCATION specifies a location to search for binary XPCOM + * NS_APP_LOCATION specifies a location to search for binary XPCOM * components as well as component/chrome manifest files. * + * NS_EXTENSION_LOCATION excludes binary XPCOM components but allows other + * manifest instructions. + * * NS_SKIN_LOCATION specifies a location to search for chrome manifest files * which are only allowed to register only skin packages and style overlays. */ enum NSLocationType { - NS_COMPONENT_LOCATION, + NS_APP_LOCATION, + NS_EXTENSION_LOCATION, NS_SKIN_LOCATION, NS_BOOTSTRAPPED_LOCATION }; diff --git a/xpcom/components/ManifestParser.cpp b/xpcom/components/ManifestParser.cpp index be7e8b28d03..e3b44f46a19 100644 --- a/xpcom/components/ManifestParser.cpp +++ b/xpcom/components/ManifestParser.cpp @@ -57,8 +57,10 @@ struct ManifestDirective const char* directive; int argc; - // Some directives should only be delivered for NS_COMPONENT_LOCATION - // manifests. + // Binary components are only allowed for APP locations. + bool apponly; + + // Some directives should only be delivered for APP or EXTENSION locations. bool componentonly; bool ischrome; @@ -89,55 +91,55 @@ struct ManifestDirective }; static const ManifestDirective kParsingTable[] = { { - "manifest", 1, false, true, true, false, + "manifest", 1, false, false, true, true, false, &nsComponentManagerImpl::ManifestManifest, nullptr, XPTONLY_MANIFEST }, { - "binary-component", 1, true, false, false, false, + "binary-component", 1, true, true, false, false, false, &nsComponentManagerImpl::ManifestBinaryComponent, nullptr, nullptr }, { - "interfaces", 1, true, false, false, false, + "interfaces", 1, false, true, false, false, false, &nsComponentManagerImpl::ManifestXPT, nullptr, XPTONLY_XPT }, { - "component", 2, true, false, false, false, + "component", 2, false, true, false, false, false, &nsComponentManagerImpl::ManifestComponent, nullptr, nullptr }, { - "contract", 2, true, false, false, false, + "contract", 2, false, true, false, false, false, &nsComponentManagerImpl::ManifestContract, nullptr, nullptr, true }, { - "category", 3, true, false, false, false, + "category", 3, false, true, false, false, false, &nsComponentManagerImpl::ManifestCategory, nullptr, nullptr }, { - "content", 2, true, true, true, true, + "content", 2, false, true, true, true, true, nullptr, &nsChromeRegistry::ManifestContent, nullptr }, { - "locale", 3, true, true, true, false, + "locale", 3, false, true, true, true, false, nullptr, &nsChromeRegistry::ManifestLocale, nullptr }, { - "skin", 3, false, true, true, false, + "skin", 3, false, false, true, true, false, nullptr, &nsChromeRegistry::ManifestSkin, nullptr }, { - "overlay", 2, true, true, false, false, + "overlay", 2, false, true, true, false, false, nullptr, &nsChromeRegistry::ManifestOverlay, nullptr }, { - "style", 2, false, true, false, false, + "style", 2, false, false, true, false, false, nullptr, &nsChromeRegistry::ManifestStyle, nullptr }, { - "override", 2, true, true, true, false, + "override", 2, false, true, true, true, false, nullptr, &nsChromeRegistry::ManifestOverride, nullptr }, { - "resource", 2, true, true, true, false, + "resource", 2, false, true, true, true, false, nullptr, &nsChromeRegistry::ManifestResource, nullptr } }; @@ -655,6 +657,12 @@ ParseManifest(NSLocationType aType, FileLocation& aFile, char* aBuf, continue; } + if (directive->apponly && NS_APP_LOCATION != aType) { + LogMessageWithContext(aFile, line, + "Only application manifests may use the '%s' directive.", token); + continue; + } + if (directive->componentonly && NS_SKIN_LOCATION == aType) { LogMessageWithContext(aFile, line, "Skin manifest not allowed to use '%s' directive.", diff --git a/xpcom/components/nsComponentManager.cpp b/xpcom/components/nsComponentManager.cpp index 11c297d12e3..7436f486c32 100644 --- a/xpcom/components/nsComponentManager.cpp +++ b/xpcom/components/nsComponentManager.cpp @@ -418,14 +418,14 @@ nsComponentManagerImpl::Init() ComponentLocation* cl = sModuleLocations->AppendElement(); nsCOMPtr lf = CloneAndAppend(greDir, NS_LITERAL_CSTRING("chrome.manifest")); - cl->type = NS_COMPONENT_LOCATION; + cl->type = NS_APP_LOCATION; cl->location.Init(lf); nsRefPtr greOmnijar = mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE); if (greOmnijar) { cl = sModuleLocations->AppendElement(); - cl->type = NS_COMPONENT_LOCATION; + cl->type = NS_APP_LOCATION; cl->location.Init(greOmnijar, "chrome.manifest"); } @@ -433,7 +433,7 @@ nsComponentManagerImpl::Init() appDir->Equals(greDir, &equals); if (!equals) { cl = sModuleLocations->AppendElement(); - cl->type = NS_COMPONENT_LOCATION; + cl->type = NS_APP_LOCATION; lf = CloneAndAppend(appDir, NS_LITERAL_CSTRING("chrome.manifest")); cl->location.Init(lf); } @@ -442,7 +442,7 @@ nsComponentManagerImpl::Init() mozilla::Omnijar::GetReader(mozilla::Omnijar::APP); if (appOmnijar) { cl = sModuleLocations->AppendElement(); - cl->type = NS_COMPONENT_LOCATION; + cl->type = NS_APP_LOCATION; cl->location.Init(appOmnijar, "chrome.manifest"); } @@ -1712,7 +1712,7 @@ NS_IMETHODIMP nsComponentManagerImpl::AutoRegister(nsIFile* aLocation) { #if !defined(MOZILLA_XPCOMRT_API) - XRE_AddManifestLocation(NS_COMPONENT_LOCATION, aLocation); + XRE_AddManifestLocation(NS_EXTENSION_LOCATION, aLocation); return NS_OK; #else return NS_ERROR_NOT_IMPLEMENTED; @@ -2151,7 +2151,7 @@ nsComponentManagerImpl::XPTOnlyManifestManifest( char* file = aArgv[0]; FileLocation f(aCx.mFile, file); - DoRegisterManifest(NS_COMPONENT_LOCATION, f, false, true); + DoRegisterManifest(NS_APP_LOCATION, f, false, true); } /* static */ @@ -2175,7 +2175,7 @@ nsComponentManagerImpl::PreloadXPT(nsIFile* aFile) MOZ_ASSERT(!nsComponentManagerImpl::gComponentManager); FileLocation location(aFile, "chrome.manifest"); - DoRegisterManifest(NS_COMPONENT_LOCATION, location, + DoRegisterManifest(NS_APP_LOCATION, location, false, true /* aXPTOnly */); } diff --git a/xpcom/tests/TestRegistrationOrder.cpp b/xpcom/tests/TestRegistrationOrder.cpp index 6a76f29436d..588358406bb 100644 --- a/xpcom/tests/TestRegistrationOrder.cpp +++ b/xpcom/tests/TestRegistrationOrder.cpp @@ -170,11 +170,11 @@ int main(int argc, char** argv) const char *regPath = argv[1]; #endif - XRE_AddManifestLocation(NS_COMPONENT_LOCATION, + XRE_AddManifestLocation(NS_EXTENSION_LOCATION, nsCOMPtr(GetRegDirectory(regPath, "core", "component.manifest"))); - XRE_AddManifestLocation(NS_COMPONENT_LOCATION, + XRE_AddManifestLocation(NS_EXTENSION_LOCATION, nsCOMPtr(GetRegDirectory(regPath, "extension", "extComponent.manifest"))); - XRE_AddJarManifestLocation(NS_COMPONENT_LOCATION, + XRE_AddJarManifestLocation(NS_EXTENSION_LOCATION, nsCOMPtr(GetRegDirectory(regPath, "extension2.jar", nullptr))); ScopedXPCOM xpcom("RegistrationOrder"); if (xpcom.failed()) diff --git a/xpcom/tests/unit/test_bug656331.js b/xpcom/tests/unit/test_bug656331.js index 2f7108e01b2..9a077866f4b 100644 --- a/xpcom/tests/unit/test_bug656331.js +++ b/xpcom/tests/unit/test_bug656331.js @@ -25,7 +25,7 @@ function run_test() { cs.registerListener(kConsoleListener); let manifest = do_get_file('bug656331.manifest'); - Components.manager.autoRegister(manifest); + registerAppManifest(manifest); do_check_false("{f18fb09b-28b4-4435-bc5b-8027f18df743}" in Components.classesByID); diff --git a/xpcom/tests/unit/test_comp_no_aslr.js b/xpcom/tests/unit/test_comp_no_aslr.js index ae5b7999194..f6f2890100c 100644 --- a/xpcom/tests/unit/test_comp_no_aslr.js +++ b/xpcom/tests/unit/test_comp_no_aslr.js @@ -5,7 +5,7 @@ const Ci = Components.interfaces; function run_test() { let manifest = do_get_file('testcompnoaslr.manifest'); - Components.manager.autoRegister(manifest); + registerAppManifest(manifest); var sysInfo = Cc["@mozilla.org/system-info;1"]. getService(Ci.nsIPropertyBag2); var ver = parseFloat(sysInfo.getProperty("version")); diff --git a/xpcom/tests/unit/test_compmgr_warnings.js b/xpcom/tests/unit/test_compmgr_warnings.js index 30451c12d5d..07ea748d806 100644 --- a/xpcom/tests/unit/test_compmgr_warnings.js +++ b/xpcom/tests/unit/test_compmgr_warnings.js @@ -56,10 +56,9 @@ function run_test() cs.registerListener(kConsoleListener); var manifest = do_get_file('compmgr_warnings.manifest'); - Components.manager.QueryInterface(Ci.nsIComponentRegistrar). - autoRegister(manifest); + registerAppManifest(manifest); manifest = do_get_file('testcomponent.manifest'); - Components.manager.autoRegister(manifest); + registerAppManifest(manifest); run_deferred_event(function() { cs.unregisterListener(kConsoleListener);