Bug 930243 - Add a processType flag to chrome manifest directives (r=froydnj)

This commit is contained in:
Bill McCloskey 2014-10-07 11:46:24 -07:00
parent 8045050edd
commit 008e00e231
9 changed files with 94 additions and 1 deletions

View File

@ -213,6 +213,7 @@ class Flags(OrderedDict):
'platform': Flag,
'xpcnativewrappers': Flag,
'tablet': Flag,
'process': StringFlag,
}
RE = re.compile(r'([!<>=]+)')

View File

@ -35,6 +35,7 @@ class ManifestEntry(object):
'abi',
'xpcnativewrappers',
'tablet',
'process',
]
def __init__(self, base, *flags):

View File

@ -493,10 +493,14 @@ ParseManifest(NSLocationType aType, FileLocation& aFile, char* aBuf,
NS_NAMED_LITERAL_STRING(kOs, "os");
NS_NAMED_LITERAL_STRING(kOsVersion, "osversion");
NS_NAMED_LITERAL_STRING(kABI, "abi");
NS_NAMED_LITERAL_STRING(kProcess, "process");
#if defined(MOZ_WIDGET_ANDROID)
NS_NAMED_LITERAL_STRING(kTablet, "tablet");
#endif
NS_NAMED_LITERAL_STRING(kMain, "main");
NS_NAMED_LITERAL_STRING(kContent, "content");
// Obsolete
NS_NAMED_LITERAL_STRING(kXPCNativeWrappers, "xpcnativewrappers");
@ -505,6 +509,7 @@ ParseManifest(NSLocationType aType, FileLocation& aFile, char* aBuf,
nsAutoString geckoVersion;
nsAutoString osTarget;
nsAutoString abi;
nsAutoString process;
nsCOMPtr<nsIXULAppInfo> xapp;
if (!aXPTOnly) {
@ -578,6 +583,12 @@ ParseManifest(NSLocationType aType, FileLocation& aFile, char* aBuf,
}
#endif
if (XRE_GetProcessType() == GeckoProcessType_Content) {
process = kContent;
} else {
process = kMain;
}
// Because contracts must be registered after CIDs, we save and process them
// at the end.
nsTArray<CachedDirective> contracts;
@ -669,6 +680,7 @@ ParseManifest(NSLocationType aType, FileLocation& aFile, char* aBuf,
TriState stOsVersion = eUnspecified;
TriState stOs = eUnspecified;
TriState stABI = eUnspecified;
TriState stProcess = eUnspecified;
#if defined(MOZ_WIDGET_ANDROID)
TriState stTablet = eUnspecified;
#endif
@ -683,6 +695,7 @@ ParseManifest(NSLocationType aType, FileLocation& aFile, char* aBuf,
if (CheckStringFlag(kApplication, wtoken, appID, stApp) ||
CheckStringFlag(kOs, wtoken, osTarget, stOs) ||
CheckStringFlag(kABI, wtoken, abi, stABI) ||
CheckStringFlag(kProcess, wtoken, process, stProcess) ||
CheckVersionFlag(kOsVersion, wtoken, osVersion, stOsVersion) ||
CheckVersionFlag(kAppVersion, wtoken, appVersion, stAppVersion) ||
CheckVersionFlag(kGeckoVersion, wtoken, geckoVersion, stGeckoVersion)) {
@ -726,7 +739,8 @@ ParseManifest(NSLocationType aType, FileLocation& aFile, char* aBuf,
#ifdef MOZ_WIDGET_ANDROID
stTablet == eBad ||
#endif
stABI == eBad) {
stABI == eBad ||
stProcess == eBad) {
continue;
}

View File

@ -0,0 +1,21 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.import("resource:///modules/XPCOMUtils.jsm");
function TestProcessDirective() {}
TestProcessDirective.prototype = {
/* Boilerplate */
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsISupportsString]),
contractID: "@mozilla.org/xpcom/tests/ChildProcessDirectiveTest;1",
classID: Components.ID("{4bd1ba60-45c4-11e4-916c-0800200c9a66}"),
type: Components.interfaces.nsISupportsString.TYPE_STRING,
data: "child process",
toString: function() {
return this.data;
}
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestProcessDirective]);

View File

@ -0,0 +1,21 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.import("resource:///modules/XPCOMUtils.jsm");
function TestProcessDirective() {}
TestProcessDirective.prototype = {
/* Boilerplate */
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsISupportsString]),
contractID: "@mozilla.org/xpcom/tests/MainProcessDirectiveTest;1",
classID: Components.ID("{9b6f4160-45be-11e4-916c-0800200c9a66}"),
type: Components.interfaces.nsISupportsString.TYPE_STRING,
data: "main process",
toString: function() {
return this.data;
}
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestProcessDirective]);

View File

@ -0,0 +1,5 @@
component {9b6f4160-45be-11e4-916c-0800200c9a66} main_process_directive_service.js process=main
contract @mozilla.org/xpcom/tests/MainProcessDirectiveTest;1 {9b6f4160-45be-11e4-916c-0800200c9a66} process=main
component {4bd1ba60-45c4-11e4-916c-0800200c9a66} child_process_directive_service.js process=content
contract @mozilla.org/xpcom/tests/ChildProcessDirectiveTest;1 {4bd1ba60-45c4-11e4-916c-0800200c9a66} process=content

View File

@ -0,0 +1,25 @@
const Ci = Components.interfaces;
const Cc = Components.classes;
Components.utils.import("resource:///modules/Services.jsm");
function run_test()
{
Components.manager.autoRegister(do_get_file("data/process_directive.manifest"));
let isChild = Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
if (isChild) {
do_check_false("@mozilla.org/xpcom/tests/MainProcessDirectiveTest;1" in Cc);
} else {
let svc = Cc["@mozilla.org/xpcom/tests/MainProcessDirectiveTest;1"].createInstance(Ci.nsISupportsString);
do_check_eq(svc.data, "main process");
}
if (!isChild) {
do_check_false("@mozilla.org/xpcom/tests/ChildProcessDirectiveTest;1" in Cc);
} else {
let svc = Cc["@mozilla.org/xpcom/tests/ChildProcessDirectiveTest;1"].createInstance(Ci.nsISupportsString);
do_check_eq(svc.data, "child process");
}
}

View File

@ -0,0 +1,3 @@
function run_test() {
run_test_in_child("test_process_directives.js");
}

View File

@ -49,6 +49,8 @@ fail-if = os == "android"
# bug 704368: test causes harness to be killed on debug Linux64
skip-if = os == "win" || (os == "linux" && debug && bits == 64)
[test_pipe.js]
[test_process_directives.js]
[test_process_directives_child.js]
[test_storagestream.js]
[test_streams.js]
[test_seek_multiplex.js]