From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../app/src/main/AndroidManifest.xml | 28 ++++ .../app/src/main/assets/messaging/.eslintrc.js | 11 ++ .../app/src/main/assets/messaging/manifest.json | 22 +++ .../app/src/main/assets/messaging/messaging.js | 13 ++ .../geckoview/example/messaging/MainActivity.java | 103 ++++++++++++ .../res/drawable-v24/ic_launcher_foreground.xml | 38 +++++ .../main/res/drawable/ic_launcher_background.xml | 174 +++++++++++++++++++++ .../app/src/main/res/layout/activity_main.xml | 18 +++ .../src/main/res/mipmap-anydpi-v26/ic_launcher.xml | 9 ++ .../res/mipmap-anydpi-v26/ic_launcher_round.xml | 9 ++ .../app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 2963 bytes .../src/main/res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4905 bytes .../app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2060 bytes .../src/main/res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2783 bytes .../app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4490 bytes .../main/res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6895 bytes .../app/src/main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6387 bytes .../main/res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10413 bytes .../src/main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9128 bytes .../main/res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15132 bytes .../app/src/main/res/values/colors.xml | 10 ++ .../app/src/main/res/values/strings.xml | 7 + .../app/src/main/res/values/styles.xml | 15 ++ 23 files changed, 457 insertions(+) create mode 100644 mobile/android/examples/messaging_example/app/src/main/AndroidManifest.xml create mode 100644 mobile/android/examples/messaging_example/app/src/main/assets/messaging/.eslintrc.js create mode 100644 mobile/android/examples/messaging_example/app/src/main/assets/messaging/manifest.json create mode 100644 mobile/android/examples/messaging_example/app/src/main/assets/messaging/messaging.js create mode 100644 mobile/android/examples/messaging_example/app/src/main/java/org/mozilla/geckoview/example/messaging/MainActivity.java create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/layout/activity_main.xml create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/values/colors.xml create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/values/strings.xml create mode 100644 mobile/android/examples/messaging_example/app/src/main/res/values/styles.xml (limited to 'mobile/android/examples/messaging_example/app/src/main') diff --git a/mobile/android/examples/messaging_example/app/src/main/AndroidManifest.xml b/mobile/android/examples/messaging_example/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..a4bab45e72 --- /dev/null +++ b/mobile/android/examples/messaging_example/app/src/main/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + diff --git a/mobile/android/examples/messaging_example/app/src/main/assets/messaging/.eslintrc.js b/mobile/android/examples/messaging_example/app/src/main/assets/messaging/.eslintrc.js new file mode 100644 index 0000000000..c5fda00676 --- /dev/null +++ b/mobile/android/examples/messaging_example/app/src/main/assets/messaging/.eslintrc.js @@ -0,0 +1,11 @@ +/* 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/. */ + +"use strict"; + +module.exports = { + env: { + webextensions: true, + }, +}; diff --git a/mobile/android/examples/messaging_example/app/src/main/assets/messaging/manifest.json b/mobile/android/examples/messaging_example/app/src/main/assets/messaging/manifest.json new file mode 100644 index 0000000000..28e02ff816 --- /dev/null +++ b/mobile/android/examples/messaging_example/app/src/main/assets/messaging/manifest.json @@ -0,0 +1,22 @@ +{ + "manifest_version": 2, + "name": "messaging", + "version": "1.0", + "description": "Example messaging web extension.", + "browser_specific_settings": { + "gecko": { + "id": "messaging@example.com" + } + }, + "content_scripts": [ + { + "matches": ["*://*.twitter.com/*"], + "js": ["messaging.js"] + } + ], + "permissions": [ + "nativeMessaging", + "nativeMessagingFromContent", + "geckoViewAddons" + ] +} diff --git a/mobile/android/examples/messaging_example/app/src/main/assets/messaging/messaging.js b/mobile/android/examples/messaging_example/app/src/main/assets/messaging/messaging.js new file mode 100644 index 0000000000..f092f2096d --- /dev/null +++ b/mobile/android/examples/messaging_example/app/src/main/assets/messaging/messaging.js @@ -0,0 +1,13 @@ +/* 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/. */ + +const manifest = document.querySelector("head > link[rel=manifest]"); +if (manifest) { + fetch(manifest.href) + .then(response => response.json()) + .then(json => { + const message = { type: "WPAManifest", manifest: json }; + browser.runtime.sendNativeMessage("browser", message); + }); +} diff --git a/mobile/android/examples/messaging_example/app/src/main/java/org/mozilla/geckoview/example/messaging/MainActivity.java b/mobile/android/examples/messaging_example/app/src/main/java/org/mozilla/geckoview/example/messaging/MainActivity.java new file mode 100644 index 0000000000..1b0b13d0ad --- /dev/null +++ b/mobile/android/examples/messaging_example/app/src/main/java/org/mozilla/geckoview/example/messaging/MainActivity.java @@ -0,0 +1,103 @@ +/* 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/. */ + +package org.mozilla.geckoview.example.messaging; + +import android.os.Bundle; +import android.util.Log; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import org.json.JSONException; +import org.json.JSONObject; +import org.mozilla.gecko.util.ThreadUtils; +import org.mozilla.geckoview.GeckoResult; +import org.mozilla.geckoview.GeckoRuntime; +import org.mozilla.geckoview.GeckoRuntimeSettings; +import org.mozilla.geckoview.GeckoSession; +import org.mozilla.geckoview.GeckoView; +import org.mozilla.geckoview.WebExtension; + +// The apk file for this example can be build using the following mach command: +// +// mach gradle messaging_example:build +// +// Formatting error reported by Spotless as part of the build can be autofixed +// can be fixed using the mach command: +// +// mach gradle messaging_example:spotlessApply +// +// After the gradle task messaging_example:build runs successfully, an apk +// file will be stored in the OBJDIR/gradle/build/mobile/android/examples/messaging_example. +// subdirectories + +public class MainActivity extends AppCompatActivity { + private static GeckoRuntime sRuntime; + + private static final String EXTENSION_LOCATION = "resource://android/assets/messaging/"; + private static final String EXTENSION_ID = "messaging@example.com"; + // If you make changes to the extension you need to update this + private static final String EXTENSION_VERSION = "1.0"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + GeckoView view = findViewById(R.id.geckoview); + GeckoSession session = new GeckoSession(); + + if (sRuntime == null) { + GeckoRuntimeSettings settings = + new GeckoRuntimeSettings.Builder().remoteDebuggingEnabled(true).build(); + sRuntime = GeckoRuntime.create(this, settings); + } + + WebExtension.MessageDelegate messageDelegate = + new WebExtension.MessageDelegate() { + @Nullable + @Override + public GeckoResult onMessage( + final @NonNull String nativeApp, + final @NonNull Object message, + final @NonNull WebExtension.MessageSender sender) { + if (message instanceof JSONObject) { + JSONObject json = (JSONObject) message; + try { + if (json.has("type") && "WPAManifest".equals(json.getString("type"))) { + JSONObject manifest = json.getJSONObject("manifest"); + Log.d("MessageDelegate", "Found WPA manifest: " + manifest); + } + } catch (JSONException ex) { + Log.e("MessageDelegate", "Invalid manifest", ex); + } + } + return null; + } + }; + + // Let's make sure the extension is installed + sRuntime + .getWebExtensionController() + .ensureBuiltIn(EXTENSION_LOCATION, "messaging@example.com") + .accept( + // Set delegate that will receive messages coming from this extension. + extension -> + ThreadUtils.runOnUiThread( + new Runnable() { + @Override + public void run() { + session + .getWebExtensionController() + .setMessageDelegate(extension, messageDelegate, "browser"); + } + }), + // Something bad happened, let's log an error + e -> Log.e("MessageDelegate", "Error registering extension", e)); + + session.open(sRuntime); + view.setSession(session); + session.loadUri("https://mobile.twitter.com"); + } +} diff --git a/mobile/android/examples/messaging_example/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/mobile/android/examples/messaging_example/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000000..6e4009f3e7 --- /dev/null +++ b/mobile/android/examples/messaging_example/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + diff --git a/mobile/android/examples/messaging_example/app/src/main/res/drawable/ic_launcher_background.xml b/mobile/android/examples/messaging_example/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000000..bcab90d6ae --- /dev/null +++ b/mobile/android/examples/messaging_example/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mobile/android/examples/messaging_example/app/src/main/res/layout/activity_main.xml b/mobile/android/examples/messaging_example/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000000..87e7c0ae72 --- /dev/null +++ b/mobile/android/examples/messaging_example/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file diff --git a/mobile/android/examples/messaging_example/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000000..f39d507313 --- /dev/null +++ b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/mobile/android/examples/messaging_example/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000000..f39d507313 --- /dev/null +++ b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/mobile/android/examples/messaging_example/app/src/main/res/mipmap-hdpi/ic_launcher.png b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000000..898f3ed59a Binary files /dev/null and b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/mobile/android/examples/messaging_example/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000000..dffca3601e Binary files /dev/null and b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/mobile/android/examples/messaging_example/app/src/main/res/mipmap-mdpi/ic_launcher.png b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000000..64ba76f75e Binary files /dev/null and b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/mobile/android/examples/messaging_example/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000000..dae5e08234 Binary files /dev/null and b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000000..e5ed46597e Binary files /dev/null and b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000000..14ed0af350 Binary files /dev/null and b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000000..b0907cac3b Binary files /dev/null and b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000000..d8ae031549 Binary files /dev/null and b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000000..2c18de9e66 Binary files /dev/null and b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000000..beed3cdd2c Binary files /dev/null and b/mobile/android/examples/messaging_example/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/mobile/android/examples/messaging_example/app/src/main/res/values/colors.xml b/mobile/android/examples/messaging_example/app/src/main/res/values/colors.xml new file mode 100644 index 0000000000..8c84b9a3fc --- /dev/null +++ b/mobile/android/examples/messaging_example/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + + + #008577 + #00574B + #D81B60 + diff --git a/mobile/android/examples/messaging_example/app/src/main/res/values/strings.xml b/mobile/android/examples/messaging_example/app/src/main/res/values/strings.xml new file mode 100644 index 0000000000..88982ec38c --- /dev/null +++ b/mobile/android/examples/messaging_example/app/src/main/res/values/strings.xml @@ -0,0 +1,7 @@ + + + + MessagingExample + diff --git a/mobile/android/examples/messaging_example/app/src/main/res/values/styles.xml b/mobile/android/examples/messaging_example/app/src/main/res/values/styles.xml new file mode 100644 index 0000000000..436c5ab087 --- /dev/null +++ b/mobile/android/examples/messaging_example/app/src/main/res/values/styles.xml @@ -0,0 +1,15 @@ + + + + + + + + -- cgit v1.2.3