Bug 1509047 - Part 4: Add support for PermissionPromptPrototype.onBeforeShow() cancelling a prompt r=johannh

Depends on D12864

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2018-11-28 22:02:52 +00:00
Родитель b21e92dda4
Коммит 27fa0d6ad7
2 изменённых файлов: 18 добавлений и 12 удалений

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

@ -253,8 +253,12 @@ var PermissionPromptPrototype = {
* be called just before. Subclasses may want to override this
* in order to, for example, bump a counter Telemetry probe for
* how often a particular permission request is seen.
*
* If this returns false, it cancels the process of showing the prompt. In
* that case, it is the responsibility of the onBeforeShow() implementation
* to ensure that allow() or cancel() are called on the object appropriately.
*/
onBeforeShow() {},
onBeforeShow() { return true; },
/**
* If the prompt was shown to the user, this callback will be called just
@ -440,14 +444,15 @@ var PermissionPromptPrototype = {
return false;
};
this.onBeforeShow();
chromeWin.PopupNotifications.show(this.browser,
this.notificationID,
this.message,
this.anchorID,
mainAction,
secondaryActions,
options);
if (this.onBeforeShow() !== false) {
chromeWin.PopupNotifications.show(this.browser,
this.notificationID,
this.message,
this.anchorID,
mainAction,
secondaryActions,
options);
}
},
};
@ -590,6 +595,7 @@ GeolocationPermissionPrompt.prototype = {
let secHistogram = Services.telemetry.getHistogramById("SECURITY_UI");
const SHOW_REQUEST = Ci.nsISecurityUITelemetry.WARNING_GEOLOCATION_REQUEST;
secHistogram.add(SHOW_REQUEST);
return true;
},
};
@ -826,9 +832,6 @@ MIDIPermissionPrompt.prototype = {
action: Ci.nsIPermissionManager.DENY_ACTION,
}];
},
onBeforeShow() {
},
};
PermissionUI.MIDIPermissionPrompt = MIDIPermissionPrompt;
@ -911,6 +914,7 @@ AutoplayPermissionPrompt.prototype = {
};
this.browser.addEventListener(
"DOMAudioPlaybackStarted", this.handlePlaybackStart);
return true;
},
};

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

@ -294,6 +294,7 @@ add_task(async function test_on_before_show() {
promptActions: [mainAction],
onBeforeShow() {
beforeShown = true;
return true;
},
};
@ -353,6 +354,7 @@ add_task(async function test_no_request() {
promptActions: [mainAction, secondaryAction],
onBeforeShow() {
beforeShown = true;
return true;
},
};