From 5d037e3e4327fe09738ce0958eceb05bdc4aa8c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A3o=20Gottwald?= Date: Fri, 15 May 2015 19:20:18 +0200 Subject: [PATCH] Bug 1165306 - Clean up ContentPermissionPrompt.prototype._showPrompt by removing pointerLock-specific code. r=paolo --HG-- extra : rebase_source : 0b2560bc173e577279610af4104974e77bc33642 --- browser/components/nsBrowserGlue.js | 67 ++++++++++++----------------- 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index b7788cb70ed1..c55776099b89 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -2346,11 +2346,6 @@ ContentPermissionPrompt.prototype = { */ _showPrompt: function CPP_showPrompt(aRequest, aMessage, aPermission, aActions, aNotificationId, aAnchorId, aOptions) { - function onFullScreen() { - popup.remove(); - } - - var browser = this._getBrowserForRequest(aRequest); var chromeWin = browser.ownerDocument.defaultView; var requestPrincipal = aRequest.principal; @@ -2397,43 +2392,15 @@ ContentPermissionPrompt.prototype = { popupNotificationActions[0] : null; var secondaryActions = popupNotificationActions.splice(1); - // Only allow exactly one permission rquest here. + // Only allow exactly one permission request here. let types = aRequest.types.QueryInterface(Ci.nsIArray); if (types.length != 1) { aRequest.cancel(); return; } - let perm = types.queryElementAt(0, Ci.nsIContentPermissionType); - - if (perm.type == "pointerLock") { - // If there's no mainAction, this is the autoAllow warning prompt. - let autoAllow = !mainAction; - - if (!aOptions) - aOptions = {}; - - aOptions.removeOnDismissal = autoAllow; - aOptions.eventCallback = type => { - if (type == "removed") { - browser.removeEventListener("mozfullscreenchange", onFullScreen, true); - if (autoAllow) { - aRequest.allow(); - } - } - } - - } - - var popup = chromeWin.PopupNotifications.show(browser, aNotificationId, aMessage, aAnchorId, - mainAction, secondaryActions, aOptions); - if (perm.type == "pointerLock") { - // pointerLock is automatically allowed in fullscreen mode (and revoked - // upon exit), so if the page enters fullscreen mode after requesting - // pointerLock (but before the user has granted permission), we should - // remove the now-impotent notification. - browser.addEventListener("mozfullscreenchange", onFullScreen, true); - } + return chromeWin.PopupNotifications.show(browser, aNotificationId, aMessage, aAnchorId, + mainAction, secondaryActions, aOptions); }, _promptPush : function(aRequest) { @@ -2591,12 +2558,34 @@ ContentPermissionPrompt.prototype = { ]; } - this._showPrompt(aRequest, message, "pointerLock", actions, "pointerLock", - "pointerLock-notification-icon", null); + function onFullScreen() { + notification.remove(); + } + + let options = {}; + options.removeOnDismissal = autoAllow; + options.eventCallback = type => { + if (type == "removed") { + notification.browser.removeEventListener("mozfullscreenchange", onFullScreen, true); + if (autoAllow) { + aRequest.allow(); + } + } + } + + let notification = + this._showPrompt(aRequest, message, "pointerLock", actions, "pointerLock", + "pointerLock-notification-icon", options); + + // pointerLock is automatically allowed in fullscreen mode (and revoked + // upon exit), so if the page enters fullscreen mode after requesting + // pointerLock (but before the user has granted permission), we should + // remove the now-impotent notification. + notification.browser.addEventListener("mozfullscreenchange", onFullScreen, true); }, prompt: function CPP_prompt(request) { - // Only allow exactly one permission rquest here. + // Only allow exactly one permission request here. let types = request.types.QueryInterface(Ci.nsIArray); if (types.length != 1) { request.cancel();