Commit 27c608d9 authored by Christian Sadilek's avatar Christian Sadilek
Browse files

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.
parent fab64229
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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
+35 −0
Original line number Diff line number Diff line
@@ -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
+8 −2
Original line number Diff line number Diff line
{
  "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"
  ]
}
+7 −1
Original line number Diff line number Diff line
{
  "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",
+0 −1
Original line number Diff line number Diff line
@@ -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) }
            },
Loading