Bug 1682632 - part3: Restrict Extension API webidl bindings to nightly builds. r=baku,mixedpuppy

Differential Revision: https://phabricator.services.mozilla.com/D104707
This commit is contained in:
Luca Greco 2021-06-09 19:20:45 +00:00
Родитель 4fe3388358
Коммит 00d5ea766f
8 изменённых файлов: 68 добавлений и 19 удалений

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

@ -1048,21 +1048,14 @@ WEBIDL_FILES += [
]
# WebExtensions API.
# TODO: evaluate to add a MOZ_WEBEXT_... config to initially
# restrict these new bindings to nightly builds, then gradually
# include them in other channels.
WEBIDL_FILES += [
"ExtensionBrowser.webidl",
"ExtensionEventManager.webidl",
# ExtensionMockAPI is not a real WebExtensions API, and it is only enabled in tests.
"ExtensionMockAPI.webidl",
"ExtensionPort.webidl",
]
# The following is not a real WebExtensions API, it is a test WebIDL
# interface that includes a collection of the cases useful to unit
# test the API request forwarding mechanism without tying it to
# a specific WebExtensions API.
WEBIDL_FILES += ["ExtensionMockAPI.webidl"]
# We only expose our prefable test interfaces in debug builds, just to be on
# the safe side.
if CONFIG["MOZ_DEBUG"] and CONFIG["ENABLE_TESTS"]:

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

@ -124,13 +124,17 @@ MOCHITEST_MANIFESTS += [
MOCHITEST_CHROME_MANIFESTS += ["test/mochitest/chrome.ini"]
XPCSHELL_TESTS_MANIFESTS += [
"test/xpcshell/native_messaging.ini",
"test/xpcshell/webidl-api/xpcshell.ini",
"test/xpcshell/xpcshell-e10s.ini",
"test/xpcshell/xpcshell-legacy-ep.ini",
"test/xpcshell/xpcshell-remote.ini",
"test/xpcshell/xpcshell.ini",
]
# Only include tests that requires the WebExtensions WebIDL API bindings
# in builds where they are enabled (currently only on Nightly builds).
if CONFIG["MOZ_WEBEXT_WEBIDL_ENABLED"]:
XPCSHELL_TESTS_MANIFESTS += ["test/xpcshell/webidl-api/xpcshell.ini"]
SPHINX_TREES["webextensions"] = "docs"
with Files("docs/**"):

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

@ -10,6 +10,14 @@ XPCOMUtils.defineLazyModuleGetters(this, {
ExtensionTestCommon: "resource://testing-common/ExtensionTestCommon.jsm",
});
add_task(function checkExtensionsWebIDLEnabled() {
equal(
AppConstants.MOZ_WEBEXT_WEBIDL_ENABLED,
true,
"WebExtensions WebIDL bindings build time flag should be enabled"
);
});
function getBackgroundServiceWorkerRegistration(extension) {
const swm = Cc["@mozilla.org/serviceworkers/manager;1"].getService(
Ci.nsIServiceWorkerManager

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

@ -36,15 +36,8 @@ JSObject* ExtensionBrowser::WrapObject(JSContext* aCx,
nsIGlobalObject* ExtensionBrowser::GetParentObject() const { return mGlobal; }
ExtensionMockAPI* ExtensionBrowser::GetExtensionMockAPI() {
if (!mExtensionMockAPI) {
mExtensionMockAPI = new ExtensionMockAPI(mGlobal, this);
}
return mExtensionMockAPI;
}
bool ExtensionAPIAllowed(JSContext* aCx, JSObject* aGlobal) {
#ifdef MOZ_WEBEXT_WEBIDL_ENABLED
// Only expose the Extension API bindings if:
// - the context is related to a worker where the Extension API are allowed
// (currently only the extension service worker declared in the extension
@ -69,6 +62,19 @@ bool ExtensionAPIAllowed(JSContext* aCx, JSObject* aGlobal) {
MOZ_ASSERT(workerPrivate->IsServiceWorker());
return workerPrivate->ExtensionAPIAllowed();
#else
// Always return false on build where MOZ_WEBEXT_WEBIDL_ENABLED is set to
// false (currently on all channels but nightly).
return false;
#endif
}
ExtensionMockAPI* ExtensionBrowser::GetExtensionMockAPI() {
if (!mExtensionMockAPI) {
mExtensionMockAPI = new ExtensionMockAPI(mGlobal, this);
}
return mExtensionMockAPI;
}
} // namespace extensions

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

@ -29,9 +29,14 @@ EXPORTS.mozilla.extensions += [
# test the API request forwarding mechanism without tying it to
# a specific WebExtensions API.
UNIFIED_SOURCES += ["ExtensionMockAPI.cpp"]
EXPORTS.mozilla.extensions += ["ExtensionMockAPI.h"]
# Propagate the build config to be able to use it in souce code preprocessing
# (used in mozilla::extensions::ExtensionAPIAllowed to disable the webidl
# bindings in non-nightly builds).
if CONFIG["MOZ_WEBEXT_WEBIDL_ENABLED"]:
DEFINES["MOZ_WEBEXT_WEBIDL_ENABLED"] = True
include("/ipc/chromium/chromium-config.mozbuild")
LOCAL_INCLUDES += [

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

@ -300,6 +300,13 @@ this.AppConstants = Object.freeze({
false,
#endif
MOZ_WEBEXT_WEBIDL_ENABLED:
#ifdef MOZ_WEBEXT_WEBIDL_ENABLED
true,
#else
false,
#endif
MENUBAR_CAN_AUTOHIDE:
#ifdef MENUBAR_CAN_AUTOHIDE
true,

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

@ -301,6 +301,7 @@ for var in (
"MOZ_UNSIGNED_SYSTEM_SCOPE",
"MOZ_UPDATE_AGENT",
"MOZ_UPDATER",
"MOZ_WEBEXT_WEBIDL_ENABLED",
):
if CONFIG[var]:
DEFINES[var] = True

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

@ -1486,6 +1486,31 @@ def addon_sideload_allowed(value):
set_config("MOZ_ALLOW_ADDON_SIDELOAD", addon_sideload_allowed)
# WebExtensions API WebIDL bindings
# ==============================================================
@depends(milestone)
def extensions_webidl_bindings_default(milestone):
# Only enable the webidl bindings for the WebExtensions APIs
# in Nightly.
return milestone.is_nightly
option(
"--enable-extensions-webidl-bindings",
default=extensions_webidl_bindings_default,
help="WebExtensions WebIDL bindings are enabled",
)
@depends("--enable-extensions-webidl-bindings")
def extensions_webidl_enabled(value):
return bool(value)
set_config("MOZ_WEBEXT_WEBIDL_ENABLED", extensions_webidl_enabled)
# Launcher process (Windows only)
# ==============================================================