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

--HG--
extra : rebase_source : 1bf47ad1cb8b662ff598c261dae872bc4710e170
This commit is contained in:
Benjamin Smedberg 2015-05-01 10:23:44 -04:00
Родитель d0b4507ce1
Коммит 573f0e2266
13 изменённых файлов: 84 добавлений и 42 удалений

Просмотреть файл

@ -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<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[] = {
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;

Просмотреть файл

@ -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");

Просмотреть файл

@ -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");

Просмотреть файл

@ -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();

Просмотреть файл

@ -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<nsIObserver> telemetryThing =
do_GetService("@mozilla.org/testing/startup-cache-telemetry.js");

Просмотреть файл

@ -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<nsIFile> manifest =
CloneAndAppend(subdir, "chrome.manifest");
XRE_AddManifestLocation(NS_COMPONENT_LOCATION, manifest);
XRE_AddManifestLocation(NS_EXTENSION_LOCATION, manifest);
}
}

Просмотреть файл

@ -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
};

Просмотреть файл

@ -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.",

Просмотреть файл

@ -418,14 +418,14 @@ nsComponentManagerImpl::Init()
ComponentLocation* cl = sModuleLocations->AppendElement();
nsCOMPtr<nsIFile> lf = CloneAndAppend(greDir,
NS_LITERAL_CSTRING("chrome.manifest"));
cl->type = NS_COMPONENT_LOCATION;
cl->type = NS_APP_LOCATION;
cl->location.Init(lf);
nsRefPtr<nsZipArchive> 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 */);
}

Просмотреть файл

@ -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<nsIFile>(GetRegDirectory(regPath, "core", "component.manifest")));
XRE_AddManifestLocation(NS_COMPONENT_LOCATION,
XRE_AddManifestLocation(NS_EXTENSION_LOCATION,
nsCOMPtr<nsIFile>(GetRegDirectory(regPath, "extension", "extComponent.manifest")));
XRE_AddJarManifestLocation(NS_COMPONENT_LOCATION,
XRE_AddJarManifestLocation(NS_EXTENSION_LOCATION,
nsCOMPtr<nsIFile>(GetRegDirectory(regPath, "extension2.jar", nullptr)));
ScopedXPCOM xpcom("RegistrationOrder");
if (xpcom.failed())

Просмотреть файл

@ -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);

Просмотреть файл

@ -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"));

Просмотреть файл

@ -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);