Bug 1642345 - Add 'source' field to WebNotification r=geckoview-reviewers,agi,esawin

Differential Revision: https://phabricator.services.mozilla.com/D78168
This commit is contained in:
James Willcox 2020-06-09 13:47:53 +00:00
Родитель 6b86e22f72
Коммит ed11539ff5
7 изменённых файлов: 27 добавлений и 10 удалений

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

@ -1703,6 +1703,7 @@ package org.mozilla.geckoview {
field @Nullable public final String imageUrl;
field @Nullable public final String lang;
field @NonNull public final boolean requireInteraction;
field @NonNull public final String source;
field @NonNull public final String tag;
field @Nullable public final String text;
field @Nullable public final String textDirection;

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

@ -56,6 +56,7 @@ class WebNotificationTest : BaseSessionTest() {
assertThat("Direction should match", notification.textDirection, equalTo("ltr"))
assertThat("Require Interaction should match", notification.requireInteraction,
equalTo(requireInteraction))
assertThat("Source should match", notification.source, equalTo(createTestUrl(HELLO_HTML_PATH)))
notificationResult.complete(null)
}
})

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

@ -19,7 +19,6 @@ import org.mozilla.geckoview.*
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.RejectedPromiseException
import org.mozilla.geckoview.test.util.Callbacks
import java.math.BigInteger
import java.security.KeyPair
import java.security.KeyPairGenerator
import java.security.SecureRandom
@ -169,6 +168,7 @@ class WebPushTest : BaseSessionTest() {
override fun onShowNotification(notification: WebNotification) {
assertThat("Title should match", notification.title, equalTo(expectedTitle))
assertThat("Body should match", notification.text, equalTo(expectedBody))
assertThat("Source should match", notification.source, endsWith("sw.js"))
notificationResult.complete(null)
}
})

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

@ -74,11 +74,17 @@ public class WebNotification {
*/
public final @NonNull boolean requireInteraction;
/**
* This is the URL of the page or Service Worker that generated the notification.
*/
public final @NonNull String source;
@WrapForJNI
/* package */ WebNotification(@Nullable final String title, @NonNull final String tag,
@Nullable final String cookie, @Nullable final String text,
@Nullable final String imageUrl, @Nullable final String textDirection,
@Nullable final String lang, @NonNull final boolean requireInteraction) {
@Nullable final String lang, @NonNull final boolean requireInteraction,
@NonNull final String source) {
this.tag = tag;
this.mCookie = cookie;
this.title = title;
@ -87,6 +93,7 @@ public class WebNotification {
this.textDirection = textDirection;
this.lang = lang;
this.requireInteraction = requireInteraction;
this.source = source;
}
/**

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

@ -17,8 +17,12 @@ exclude: true
- Added `runtime.openOptionsPage` support. For `options_ui.open_in_new_tab` ==
`false`, [`TabDelegate.onOpenOptionsPage`][79.1] is called.
([bug 1618058]({{bugzilla}}1619766))
- Added [`WebNotification.source`][79.2], which is the URL of the page
or Service Worker that created the notification.
[79.1]: {{javadoc_uri}}/WebExtension.TabDelegate.html#onOpenOptionsPage-org.mozilla.geckoview.WebExtension-
[79.2]: {{javadoc_uri}}/WebNotification.html#source
## v78
- Added [`WebExtensionController.installBuiltIn`][78.1] that allows installing an
@ -719,4 +723,4 @@ exclude: true
[65.24]: {{javadoc_uri}}/CrashReporter.html#sendCrashReport-android.content.Context-android.os.Bundle-java.lang.String-
[65.25]: {{javadoc_uri}}/GeckoResult.html
[api-version]: c75d02b7653f49b0d301d95a50f6d559dca1c48c
[api-version]: 820c4bbc052bd8b8b19c2460c3996b86e1786ff7

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

@ -1,4 +1,5 @@
[DEFAULT]
skip-if = os == 'android' # We don't use XUL alerts on Android
support-files =
image.gif
image.png
@ -7,7 +8,7 @@ support-files =
# Synchronous tests like test_alerts.html must come before
# asynchronous tests like test_alerts_noobserve.html!
[test_alerts.html]
skip-if = toolkit == 'android' || (os == "win" && debug) # Bug 1407296
(os == "win" && debug) # Bug 1407296
[test_alerts_noobserve.html]
[test_alerts_requireinteraction.html]
skip-if = (verify && (os == 'linux'))

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

@ -6,7 +6,8 @@
#include "AndroidAlerts.h"
#include "mozilla/java/GeckoRuntimeWrappers.h"
#include "mozilla/java/WebNotificationWrappers.h"
#include "nsAlertsUtils.h"
#include "nsIPrincipal.h"
#include "nsIURI.h"
namespace mozilla {
namespace widget {
@ -76,12 +77,14 @@ AndroidAlerts::ShowPersistentNotification(const nsAString& aPersistentData,
rv = aAlert->GetRequireInteraction(&requireInteraction);
NS_ENSURE_SUCCESS(rv, NS_OK);
nsCOMPtr<nsIPrincipal> principal;
rv = aAlert->GetPrincipal(getter_AddRefs(principal));
nsCOMPtr<nsIURI> uri;
rv = aAlert->GetURI(getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, NS_OK);
MOZ_ASSERT(uri);
nsAutoString host;
nsAlertsUtils::GetSourceHostPort(principal, host);
nsCString spec;
rv = uri->GetDisplaySpec(spec);
NS_ENSURE_SUCCESS(rv, NS_OK);
if (aPersistentData.IsEmpty() && aAlertListener) {
if (!sListenerMap) {
@ -92,7 +95,7 @@ AndroidAlerts::ShowPersistentNotification(const nsAString& aPersistentData,
}
java::WebNotification::LocalRef notification = notification->New(
title, name, cookie, text, imageUrl, dir, lang, requireInteraction);
title, name, cookie, text, imageUrl, dir, lang, requireInteraction, spec);
java::GeckoRuntime::LocalRef runtime = java::GeckoRuntime::GetInstance();
if (runtime != NULL) {
runtime->NotifyOnShow(notification);