Bug 1608588 - Auto-deny `desktop-notification` permission appropriately r=geckoview-reviewers,esawin

This causes us to automatically deny the `desktop-notification`
permission if there is no user interaction, like desktop Firefox. This is
not enforced if the `dom.webnotifications.requireuserinteraction`
preference is set to `false`

Differential Revision: https://phabricator.services.mozilla.com/D60758

--HG--
extra : moz-landing-system : lando
This commit is contained in:
James Willcox 2020-01-23 18:02:49 +00:00
Родитель ab51b2424c
Коммит 415b58b0a0
5 изменённых файлов: 19 добавлений и 0 удалений

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

@ -236,6 +236,19 @@ GeckoViewPermission.prototype = {
}
let perm = types.queryElementAt(0, Ci.nsIContentPermissionType);
if (
perm.type === "desktop-notification" &&
!aRequest.isHandlingUserInput &&
Services.prefs.getBoolPref(
"dom.webnotifications.requireuserinteraction",
true
)
) {
// We need user interaction and don't have it.
aRequest.cancel();
return;
}
let dispatcher = GeckoViewUtils.getDispatcherForWindow(
aRequest.window ? aRequest.window : aRequest.element.ownerGlobal
);

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

@ -21,6 +21,8 @@ class OpenWindowTest : BaseSessionTest() {
@Before
fun setup() {
sessionRule.setPrefsUntilTestEnd(mapOf("dom.webnotifications.requireuserinteraction" to false))
// Grant "desktop notification" permission
mainSession.delegateUntilTestEnd(object : Callbacks.PermissionDelegate {
override fun onContentPermissionRequest(session: GeckoSession, uri: String?, type: Int, callback: GeckoSession.PermissionDelegate.Callback) {

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

@ -219,6 +219,7 @@ class PermissionDelegateTest : BaseSessionTest() {
}
@Test fun notification() {
sessionRule.setPrefsUntilTestEnd(mapOf("dom.webnotifications.requireuserinteraction" to false))
mainSession.loadTestPath(HELLO_HTML_PATH)
mainSession.waitForPageStop()

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

@ -21,6 +21,8 @@ class WebNotificationTest : BaseSessionTest() {
mainSession.loadTestPath(HELLO_HTML_PATH)
mainSession.waitForPageStop()
sessionRule.setPrefsUntilTestEnd(mapOf("dom.webnotifications.requireuserinteraction" to false))
// Grant "desktop notification" permission
mainSession.delegateUntilTestEnd(object : Callbacks.PermissionDelegate {
override fun onContentPermissionRequest(session: GeckoSession, uri: String?, type: Int, callback: GeckoSession.PermissionDelegate.Callback) {

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

@ -57,6 +57,7 @@ class WebPushTest : BaseSessionTest() {
@Before
fun setup() {
sessionRule.setPrefsUntilTestEnd(mapOf("dom.webnotifications.requireuserinteraction" to false))
// Grant "desktop notification" permission
mainSession.delegateUntilTestEnd(object : Callbacks.PermissionDelegate {
override fun onContentPermissionRequest(session: GeckoSession, uri: String?, type: Int, callback: GeckoSession.PermissionDelegate.Callback) {