Skip to content

Commit

Permalink
Bug 1642345 - Add 'source' field to WebNotification r=geckoview-revie…
Browse files Browse the repository at this point in the history
…wers,agi,esawin

Differential Revision: https://phabricator.services.mozilla.com/D78168
  • Loading branch information
snorp committed Jun 8, 2020
1 parent 6db3ee9 commit d81477f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions mobile/android/geckoview/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -87,6 +93,7 @@ public class WebNotification {
this.textDirection = textDirection;
this.lang = lang;
this.requireInteraction = requireInteraction;
this.source = source;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
14 changes: 8 additions & 6 deletions widget/android/AndroidAlerts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -76,12 +77,13 @@ 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);

nsAutoString host;
nsAlertsUtils::GetSourceHostPort(principal, host);
nsCString spec;
rv = uri->GetDisplaySpec(spec);
NS_ENSURE_SUCCESS(rv, NS_OK);

if (aPersistentData.IsEmpty() && aAlertListener) {
if (!sListenerMap) {
Expand All @@ -92,7 +94,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);
Expand Down

0 comments on commit d81477f

Please sign in to comment.