Update built-in extensions for new AC/GV API

New API (installBuiltIn/ensureBuiltin) requires
- Gecko IDs and new permissions
- Extension will only be re-installed if it has a new version

This includes a gradle task to automatically generate a
new version in manifest.json for every build so we don't
forget to update the version and end up with changes that
are never applied.
This commit is contained in:
Christian Sadilek 2020-06-04 13:18:37 -04:00
parent fab64229a5
commit 27c608d956
8 changed files with 56 additions and 7 deletions

4
.gitignore vendored
View File

@ -100,3 +100,7 @@ test_artifacts/
/build/test-tools/google-cloud-sdk/
/build/test-tools/*.jar
/build/test-tools/*.gz
# Web extensions: manifest.json files are generated
manifest.json

View File

@ -186,6 +186,10 @@ android {
// GeckoView must uncompress it before it can do anything else which
// causes a significant delay on startup.
noCompress 'ja'
// manifest.template.json is converted to manifest.json at build time.
// No need to package the template in the APK.
ignoreAssetsPattern "manifest.template.json"
}
testOptions {
@ -755,3 +759,34 @@ if (gradle.hasProperty('localProperties.autoPublish.application-services.dir'))
ext.appServicesSrcDir = gradle."localProperties.autoPublish.application-services.dir"
apply from: "../${appServicesSrcDir}/build-scripts/substitute-local-appservices.gradle"
}
// Define a reusable task for updating the versions of our built-in web extensions. We automate this
// to make sure we never forget to update the version, either in local development or for releases.
// In both cases, we want to make sure the latest version of all extensions (including their latest
// changes) are installed on first start-up.
// We're using the A-C version here as we want to uplift all built-in extensions to A-C (Once that's
// done we can also remove the task below):
// https://github.com/mozilla-mobile/android-components/issues/7249
ext.updateExtensionVersion = { task, extDir ->
configure(task) {
from extDir
include 'manifest.template.json'
rename { 'manifest.json' }
into extDir
def values = ['version': AndroidComponents.VERSION + "." + new Date().format('MMddHHmmss')]
inputs.properties(values)
expand(values)
}
}
tasks.register("updateAdsExtensionVersion", Copy) { task ->
updateExtensionVersion(task, 'src/main/assets/extensions/ads')
}
tasks.register("updateCookiesExtensionVersion", Copy) { task ->
updateExtensionVersion(task, 'src/main/assets/extensions/cookies')
}
preBuild.dependsOn updateAdsExtensionVersion
preBuild.dependsOn updateCookiesExtensionVersion

View File

@ -1,7 +1,12 @@
{
"manifest_version": 2,
"applications": {
"gecko": {
"id": "ads@mozac.org"
}
},
"name": "Mozilla Android Components - Ads",
"version": "1.0",
"version": "${version}",
"content_scripts": [
{
"matches": ["https://*/*"],
@ -16,6 +21,7 @@
],
"permissions": [
"geckoViewAddons",
"nativeMessaging"
"nativeMessaging",
"nativeMessagingFromContent"
]
}

View File

@ -1,7 +1,12 @@
{
"manifest_version": 2,
"applications": {
"gecko": {
"id": "cookies@mozac.org"
}
},
"name": "Mozilla Android Components - Cookies",
"version": "1.0",
"version": "${version}",
"content_scripts": [
{
"matches": ["https://*/*"],
@ -23,6 +28,7 @@
"permissions": [
"geckoViewAddons",
"nativeMessaging",
"nativeMessagingFromContent",
"webNavigation",
"webRequest",
"webRequestBlocking",

View File

@ -93,7 +93,6 @@ abstract class BaseSearchTelemetry {
engine.installWebExtension(
id = extensionInfo.id,
url = extensionInfo.resourceUrl,
allowContentMessaging = true,
onSuccess = { extension ->
store.flowScoped { flow -> subscribeToUpdates(flow, extension, extensionInfo) }
},

View File

@ -51,7 +51,7 @@ class AdsTelemetry(private val metrics: MetricController) : BaseSearchTelemetry(
companion object {
@VisibleForTesting
internal const val ADS_EXTENSION_ID = "mozacBrowserAds"
internal const val ADS_EXTENSION_ID = "ads@mozac.org"
@VisibleForTesting
internal const val ADS_EXTENSION_RESOURCE_URL = "resource://android/assets/extensions/ads/"
@VisibleForTesting

View File

@ -131,7 +131,7 @@ class InContentTelemetry(private val metrics: MetricController) : BaseSearchTele
companion object {
@VisibleForTesting
internal const val COOKIES_EXTENSION_ID = "BrowserCookiesExtension"
internal const val COOKIES_EXTENSION_ID = "cookies@mozac.org"
@VisibleForTesting
internal const val COOKIES_EXTENSION_RESOURCE_URL =
"resource://android/assets/extensions/cookies/"

View File

@ -44,7 +44,6 @@ class BaseSearchTelemetryTest {
engine.installWebExtension(
id = id,
url = resourceUrl,
allowContentMessaging = true,
onSuccess = any(),
onError = any()
)