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

This commit is contained in:
Benjamin Smedberg 2015-05-01 10:23:44 -04:00
parent a347201a38
commit 25916a65c0
13 changed files with 84 additions and 42 deletions

View File

@ -27,6 +27,7 @@
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsJSPrincipals.h" #include "nsJSPrincipals.h"
#include "xpcpublic.h" #include "xpcpublic.h"
#include "xpcprivate.h"
#include "BackstagePass.h" #include "BackstagePass.h"
#include "nsIScriptSecurityManager.h" #include "nsIScriptSecurityManager.h"
#include "nsIPrincipal.h" #include "nsIPrincipal.h"
@ -632,6 +633,35 @@ SimulateActivityCallback(JSContext* cx, unsigned argc, jsval* vp)
return true; 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<JSObject*> arg1(cx, &args[0].toObject());
nsCOMPtr<nsIFile> 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[] = { static const JSFunctionSpec glob_functions[] = {
JS_FS("print", Print, 0,0), JS_FS("print", Print, 0,0),
JS_FS("readline", ReadLine, 1,0), JS_FS("readline", ReadLine, 1,0),
@ -652,6 +682,7 @@ static const JSFunctionSpec glob_functions[] = {
JS_FS("btoa", Btoa, 1,0), JS_FS("btoa", Btoa, 1,0),
JS_FS("setInterruptCallback", SetInterruptCallback, 1,0), JS_FS("setInterruptCallback", SetInterruptCallback, 1,0),
JS_FS("simulateActivityCallback", SimulateActivityCallback, 1,0), JS_FS("simulateActivityCallback", SimulateActivityCallback, 1,0),
JS_FS("registerAppManifest", RegisterAppManifest, 1, 0),
JS_FS_END JS_FS_END
}; };
@ -1341,7 +1372,7 @@ XRE_XPCShellMain(int argc, char** argv, char** envp)
printf("Couldn't get manifest file.\n"); printf("Couldn't get manifest file.\n");
return 1; return 1;
} }
XRE_AddManifestLocation(NS_COMPONENT_LOCATION, lf); XRE_AddManifestLocation(NS_APP_LOCATION, lf);
argc -= 2; argc -= 2;
argv += 2; argv += 2;

View File

@ -8,8 +8,8 @@ const Ci = Components.interfaces;
function run_test() { function run_test() {
// Load the component manifests. // Load the component manifests.
Components.manager.autoRegister(do_get_file('../components/native/xpctest.manifest')); registerAppManifest(do_get_file('../components/native/xpctest.manifest'));
Components.manager.autoRegister(do_get_file('../components/js/xpctest.manifest')); registerAppManifest(do_get_file('../components/js/xpctest.manifest'));
// Test for each component. // Test for each component.
test_component_readwrite("@mozilla.org/js/xpc/test/native/ObjectReadWrite;1"); test_component_readwrite("@mozilla.org/js/xpc/test/native/ObjectReadWrite;1");

View File

@ -8,8 +8,8 @@ const Ci = Components.interfaces;
function run_test() { function run_test() {
// Load the component manifests. // Load the component manifests.
Components.manager.autoRegister(do_get_file('../components/native/xpctest.manifest')); registerAppManifest(do_get_file('../components/native/xpctest.manifest'));
Components.manager.autoRegister(do_get_file('../components/js/xpctest.manifest')); registerAppManifest(do_get_file('../components/js/xpctest.manifest'));
// Test for each component. // Test for each component.
test_component("@mozilla.org/js/xpc/test/native/Params;1"); test_component("@mozilla.org/js/xpc/test/native/Params;1");

View File

@ -16,8 +16,8 @@ function getConsoleMessages() {
function run_test() { function run_test() {
// Load the component manifests. // Load the component manifests.
Cm.autoRegister(do_get_file('../components/native/xpctest.manifest')); registerAppManifest(do_get_file('../components/native/xpctest.manifest'));
Cm.autoRegister(do_get_file('../components/js/xpctest.manifest')); registerAppManifest(do_get_file('../components/js/xpctest.manifest'));
// and the tests. // and the tests.
test_simple(); test_simple();

View File

@ -438,7 +438,7 @@ int main(int argc, char** argv)
NS_LITERAL_CSTRING("TestStartupCacheTelemetry.manifest")); NS_LITERAL_CSTRING("TestStartupCacheTelemetry.manifest"));
#endif #endif
XRE_AddManifestLocation(NS_COMPONENT_LOCATION, manifest); XRE_AddManifestLocation(NS_APP_LOCATION, manifest);
nsCOMPtr<nsIObserver> telemetryThing = nsCOMPtr<nsIObserver> telemetryThing =
do_GetService("@mozilla.org/testing/startup-cache-telemetry.js"); do_GetService("@mozilla.org/testing/startup-cache-telemetry.js");

View File

@ -635,7 +635,7 @@ nsXREDirProvider::LoadExtensionBundleDirectories()
RegisterExtensionInterpositions(parser); RegisterExtensionInterpositions(parser);
LoadExtensionDirectories(parser, "ExtensionDirs", mExtensionDirectories, LoadExtensionDirectories(parser, "ExtensionDirs", mExtensionDirectories,
NS_COMPONENT_LOCATION); NS_EXTENSION_LOCATION);
LoadExtensionDirectories(parser, "ThemeDirs", mThemeDirectories, LoadExtensionDirectories(parser, "ThemeDirs", mThemeDirectories,
NS_SKIN_LOCATION); NS_SKIN_LOCATION);
} }
@ -667,7 +667,7 @@ nsXREDirProvider::LoadAppBundleDirs()
nsCOMPtr<nsIFile> manifest = nsCOMPtr<nsIFile> manifest =
CloneAndAppend(subdir, "chrome.manifest"); CloneAndAppend(subdir, "chrome.manifest");
XRE_AddManifestLocation(NS_COMPONENT_LOCATION, manifest); XRE_AddManifestLocation(NS_EXTENSION_LOCATION, manifest);
} }
} }

View File

@ -240,15 +240,19 @@ XRE_API(nsresult,
* @param aFileCount the number of items in the aFiles array. * @param aFileCount the number of items in the aFiles array.
* @note appdir/components is registered automatically. * @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. * 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 * NS_SKIN_LOCATION specifies a location to search for chrome manifest files
* which are only allowed to register only skin packages and style overlays. * which are only allowed to register only skin packages and style overlays.
*/ */
enum NSLocationType enum NSLocationType
{ {
NS_COMPONENT_LOCATION, NS_APP_LOCATION,
NS_EXTENSION_LOCATION,
NS_SKIN_LOCATION, NS_SKIN_LOCATION,
NS_BOOTSTRAPPED_LOCATION NS_BOOTSTRAPPED_LOCATION
}; };

View File

@ -57,8 +57,10 @@ struct ManifestDirective
const char* directive; const char* directive;
int argc; int argc;
// Some directives should only be delivered for NS_COMPONENT_LOCATION // Binary components are only allowed for APP locations.
// manifests. bool apponly;
// Some directives should only be delivered for APP or EXTENSION locations.
bool componentonly; bool componentonly;
bool ischrome; bool ischrome;
@ -89,55 +91,55 @@ struct ManifestDirective
}; };
static const ManifestDirective kParsingTable[] = { static const ManifestDirective kParsingTable[] = {
{ {
"manifest", 1, false, true, true, false, "manifest", 1, false, false, true, true, false,
&nsComponentManagerImpl::ManifestManifest, nullptr, XPTONLY_MANIFEST &nsComponentManagerImpl::ManifestManifest, nullptr, XPTONLY_MANIFEST
}, },
{ {
"binary-component", 1, true, false, false, false, "binary-component", 1, true, true, false, false, false,
&nsComponentManagerImpl::ManifestBinaryComponent, nullptr, nullptr &nsComponentManagerImpl::ManifestBinaryComponent, nullptr, nullptr
}, },
{ {
"interfaces", 1, true, false, false, false, "interfaces", 1, false, true, false, false, false,
&nsComponentManagerImpl::ManifestXPT, nullptr, XPTONLY_XPT &nsComponentManagerImpl::ManifestXPT, nullptr, XPTONLY_XPT
}, },
{ {
"component", 2, true, false, false, false, "component", 2, false, true, false, false, false,
&nsComponentManagerImpl::ManifestComponent, nullptr, nullptr &nsComponentManagerImpl::ManifestComponent, nullptr, nullptr
}, },
{ {
"contract", 2, true, false, false, false, "contract", 2, false, true, false, false, false,
&nsComponentManagerImpl::ManifestContract, nullptr, nullptr, true &nsComponentManagerImpl::ManifestContract, nullptr, nullptr, true
}, },
{ {
"category", 3, true, false, false, false, "category", 3, false, true, false, false, false,
&nsComponentManagerImpl::ManifestCategory, nullptr, nullptr &nsComponentManagerImpl::ManifestCategory, nullptr, nullptr
}, },
{ {
"content", 2, true, true, true, true, "content", 2, false, true, true, true, true,
nullptr, &nsChromeRegistry::ManifestContent, nullptr nullptr, &nsChromeRegistry::ManifestContent, nullptr
}, },
{ {
"locale", 3, true, true, true, false, "locale", 3, false, true, true, true, false,
nullptr, &nsChromeRegistry::ManifestLocale, nullptr nullptr, &nsChromeRegistry::ManifestLocale, nullptr
}, },
{ {
"skin", 3, false, true, true, false, "skin", 3, false, false, true, true, false,
nullptr, &nsChromeRegistry::ManifestSkin, nullptr nullptr, &nsChromeRegistry::ManifestSkin, nullptr
}, },
{ {
"overlay", 2, true, true, false, false, "overlay", 2, false, true, true, false, false,
nullptr, &nsChromeRegistry::ManifestOverlay, nullptr nullptr, &nsChromeRegistry::ManifestOverlay, nullptr
}, },
{ {
"style", 2, false, true, false, false, "style", 2, false, false, true, false, false,
nullptr, &nsChromeRegistry::ManifestStyle, nullptr nullptr, &nsChromeRegistry::ManifestStyle, nullptr
}, },
{ {
"override", 2, true, true, true, false, "override", 2, false, true, true, true, false,
nullptr, &nsChromeRegistry::ManifestOverride, nullptr nullptr, &nsChromeRegistry::ManifestOverride, nullptr
}, },
{ {
"resource", 2, true, true, true, false, "resource", 2, false, true, true, true, false,
nullptr, &nsChromeRegistry::ManifestResource, nullptr nullptr, &nsChromeRegistry::ManifestResource, nullptr
} }
}; };
@ -655,6 +657,12 @@ ParseManifest(NSLocationType aType, FileLocation& aFile, char* aBuf,
continue; 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) { if (directive->componentonly && NS_SKIN_LOCATION == aType) {
LogMessageWithContext(aFile, line, LogMessageWithContext(aFile, line,
"Skin manifest not allowed to use '%s' directive.", "Skin manifest not allowed to use '%s' directive.",

View File

@ -418,14 +418,14 @@ nsComponentManagerImpl::Init()
ComponentLocation* cl = sModuleLocations->AppendElement(); ComponentLocation* cl = sModuleLocations->AppendElement();
nsCOMPtr<nsIFile> lf = CloneAndAppend(greDir, nsCOMPtr<nsIFile> lf = CloneAndAppend(greDir,
NS_LITERAL_CSTRING("chrome.manifest")); NS_LITERAL_CSTRING("chrome.manifest"));
cl->type = NS_COMPONENT_LOCATION; cl->type = NS_APP_LOCATION;
cl->location.Init(lf); cl->location.Init(lf);
nsRefPtr<nsZipArchive> greOmnijar = nsRefPtr<nsZipArchive> greOmnijar =
mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE); mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE);
if (greOmnijar) { if (greOmnijar) {
cl = sModuleLocations->AppendElement(); cl = sModuleLocations->AppendElement();
cl->type = NS_COMPONENT_LOCATION; cl->type = NS_APP_LOCATION;
cl->location.Init(greOmnijar, "chrome.manifest"); cl->location.Init(greOmnijar, "chrome.manifest");
} }
@ -433,7 +433,7 @@ nsComponentManagerImpl::Init()
appDir->Equals(greDir, &equals); appDir->Equals(greDir, &equals);
if (!equals) { if (!equals) {
cl = sModuleLocations->AppendElement(); cl = sModuleLocations->AppendElement();
cl->type = NS_COMPONENT_LOCATION; cl->type = NS_APP_LOCATION;
lf = CloneAndAppend(appDir, NS_LITERAL_CSTRING("chrome.manifest")); lf = CloneAndAppend(appDir, NS_LITERAL_CSTRING("chrome.manifest"));
cl->location.Init(lf); cl->location.Init(lf);
} }
@ -442,7 +442,7 @@ nsComponentManagerImpl::Init()
mozilla::Omnijar::GetReader(mozilla::Omnijar::APP); mozilla::Omnijar::GetReader(mozilla::Omnijar::APP);
if (appOmnijar) { if (appOmnijar) {
cl = sModuleLocations->AppendElement(); cl = sModuleLocations->AppendElement();
cl->type = NS_COMPONENT_LOCATION; cl->type = NS_APP_LOCATION;
cl->location.Init(appOmnijar, "chrome.manifest"); cl->location.Init(appOmnijar, "chrome.manifest");
} }
@ -1712,7 +1712,7 @@ NS_IMETHODIMP
nsComponentManagerImpl::AutoRegister(nsIFile* aLocation) nsComponentManagerImpl::AutoRegister(nsIFile* aLocation)
{ {
#if !defined(MOZILLA_XPCOMRT_API) #if !defined(MOZILLA_XPCOMRT_API)
XRE_AddManifestLocation(NS_COMPONENT_LOCATION, aLocation); XRE_AddManifestLocation(NS_EXTENSION_LOCATION, aLocation);
return NS_OK; return NS_OK;
#else #else
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
@ -2151,7 +2151,7 @@ nsComponentManagerImpl::XPTOnlyManifestManifest(
char* file = aArgv[0]; char* file = aArgv[0];
FileLocation f(aCx.mFile, file); FileLocation f(aCx.mFile, file);
DoRegisterManifest(NS_COMPONENT_LOCATION, f, false, true); DoRegisterManifest(NS_APP_LOCATION, f, false, true);
} }
/* static */ /* static */
@ -2175,7 +2175,7 @@ nsComponentManagerImpl::PreloadXPT(nsIFile* aFile)
MOZ_ASSERT(!nsComponentManagerImpl::gComponentManager); MOZ_ASSERT(!nsComponentManagerImpl::gComponentManager);
FileLocation location(aFile, "chrome.manifest"); FileLocation location(aFile, "chrome.manifest");
DoRegisterManifest(NS_COMPONENT_LOCATION, location, DoRegisterManifest(NS_APP_LOCATION, location,
false, true /* aXPTOnly */); false, true /* aXPTOnly */);
} }

View File

@ -170,11 +170,11 @@ int main(int argc, char** argv)
const char *regPath = argv[1]; const char *regPath = argv[1];
#endif #endif
XRE_AddManifestLocation(NS_COMPONENT_LOCATION, XRE_AddManifestLocation(NS_EXTENSION_LOCATION,
nsCOMPtr<nsIFile>(GetRegDirectory(regPath, "core", "component.manifest"))); nsCOMPtr<nsIFile>(GetRegDirectory(regPath, "core", "component.manifest")));
XRE_AddManifestLocation(NS_COMPONENT_LOCATION, XRE_AddManifestLocation(NS_EXTENSION_LOCATION,
nsCOMPtr<nsIFile>(GetRegDirectory(regPath, "extension", "extComponent.manifest"))); nsCOMPtr<nsIFile>(GetRegDirectory(regPath, "extension", "extComponent.manifest")));
XRE_AddJarManifestLocation(NS_COMPONENT_LOCATION, XRE_AddJarManifestLocation(NS_EXTENSION_LOCATION,
nsCOMPtr<nsIFile>(GetRegDirectory(regPath, "extension2.jar", nullptr))); nsCOMPtr<nsIFile>(GetRegDirectory(regPath, "extension2.jar", nullptr)));
ScopedXPCOM xpcom("RegistrationOrder"); ScopedXPCOM xpcom("RegistrationOrder");
if (xpcom.failed()) if (xpcom.failed())

View File

@ -25,7 +25,7 @@ function run_test() {
cs.registerListener(kConsoleListener); cs.registerListener(kConsoleListener);
let manifest = do_get_file('bug656331.manifest'); let manifest = do_get_file('bug656331.manifest');
Components.manager.autoRegister(manifest); registerAppManifest(manifest);
do_check_false("{f18fb09b-28b4-4435-bc5b-8027f18df743}" in Components.classesByID); do_check_false("{f18fb09b-28b4-4435-bc5b-8027f18df743}" in Components.classesByID);

View File

@ -5,7 +5,7 @@ const Ci = Components.interfaces;
function run_test() { function run_test() {
let manifest = do_get_file('testcompnoaslr.manifest'); let manifest = do_get_file('testcompnoaslr.manifest');
Components.manager.autoRegister(manifest); registerAppManifest(manifest);
var sysInfo = Cc["@mozilla.org/system-info;1"]. var sysInfo = Cc["@mozilla.org/system-info;1"].
getService(Ci.nsIPropertyBag2); getService(Ci.nsIPropertyBag2);
var ver = parseFloat(sysInfo.getProperty("version")); var ver = parseFloat(sysInfo.getProperty("version"));

View File

@ -56,10 +56,9 @@ function run_test()
cs.registerListener(kConsoleListener); cs.registerListener(kConsoleListener);
var manifest = do_get_file('compmgr_warnings.manifest'); var manifest = do_get_file('compmgr_warnings.manifest');
Components.manager.QueryInterface(Ci.nsIComponentRegistrar). registerAppManifest(manifest);
autoRegister(manifest);
manifest = do_get_file('testcomponent.manifest'); manifest = do_get_file('testcomponent.manifest');
Components.manager.autoRegister(manifest); registerAppManifest(manifest);
run_deferred_event(function() { run_deferred_event(function() {
cs.unregisterListener(kConsoleListener); cs.unregisterListener(kConsoleListener);