From 43caa48ecba88a60b7b0b84d19d928ada8b22b09 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 06:17:52 +0200 Subject: Bug 1038811 - Push Notifications - Firefox front end changes for preferences, and permission notification --- application/palemoon/components/nsBrowserGlue.js | 41 +++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'application/palemoon/components/nsBrowserGlue.js') diff --git a/application/palemoon/components/nsBrowserGlue.js b/application/palemoon/components/nsBrowserGlue.js index 225cddd52..3908ae81f 100644 --- a/application/palemoon/components/nsBrowserGlue.js +++ b/application/palemoon/components/nsBrowserGlue.js @@ -1751,6 +1751,42 @@ ContentPermissionPrompt.prototype = { } }, + _promptPush : function(aRequest) { + var browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties"); + var requestingURI = aRequest.principal.URI; + + var message = browserBundle.formatStringFromName("push.enablePush", + [requestingURI.host], 1); + + var actions = [ + { + stringId: "push.alwaysAllow", + action: Ci.nsIPermissionManager.ALLOW_ACTION, + expireType: null, + callback: function() {} + }, + { + stringId: "push.allowForSession", + action: Ci.nsIPermissionManager.ALLOW_ACTION, + expireType: Ci.nsIPermissionManager.EXPIRE_SESSION, + callback: function() {} + }, + { + stringId: "push.alwaysBlock", + action: Ci.nsIPermissionManager.DENY_ACTION, + expireType: null, + callback: function() {} + }] + + var options = { + learnMoreURL: Services.urlFormatter.formatURLPref("browser.push.warning.infoURL"), + }; + + this._showPrompt(aRequest, message, "push", actions, "push", + "push-notification-icon", options); + + }, + _promptGeo : function(aRequest) { var browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties"); var requestingURI = aRequest.principal.URI; @@ -1875,7 +1911,6 @@ ContentPermissionPrompt.prototype = { }, prompt: function CPP_prompt(request) { - // Only allow exactly one permission rquest here. let types = request.types.QueryInterface(Ci.nsIArray); if (types.length != 1) { @@ -1887,6 +1922,7 @@ ContentPermissionPrompt.prototype = { const kFeatureKeys = { "geolocation" : "geo", "desktop-notification" : "desktop-notification", "pointerLock" : "pointerLock", + "push" : "push" }; // Make sure that we support the request. @@ -1930,6 +1966,9 @@ ContentPermissionPrompt.prototype = { case "pointerLock": this._promptPointerLock(request, autoAllow); break; + case "push": + this._promptPush(request); + break; } }, -- cgit v1.2.3 From d6213d3f057e902316ff67b9774e349573bde90f Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 09:54:20 +0200 Subject: Bug 1192458, Part 1 - Consolidate push and desktop notification permissions --- application/palemoon/components/nsBrowserGlue.js | 47 +++--------------------- 1 file changed, 5 insertions(+), 42 deletions(-) (limited to 'application/palemoon/components/nsBrowserGlue.js') diff --git a/application/palemoon/components/nsBrowserGlue.js b/application/palemoon/components/nsBrowserGlue.js index 3908ae81f..642e27c6b 100644 --- a/application/palemoon/components/nsBrowserGlue.js +++ b/application/palemoon/components/nsBrowserGlue.js @@ -1751,42 +1751,6 @@ ContentPermissionPrompt.prototype = { } }, - _promptPush : function(aRequest) { - var browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties"); - var requestingURI = aRequest.principal.URI; - - var message = browserBundle.formatStringFromName("push.enablePush", - [requestingURI.host], 1); - - var actions = [ - { - stringId: "push.alwaysAllow", - action: Ci.nsIPermissionManager.ALLOW_ACTION, - expireType: null, - callback: function() {} - }, - { - stringId: "push.allowForSession", - action: Ci.nsIPermissionManager.ALLOW_ACTION, - expireType: Ci.nsIPermissionManager.EXPIRE_SESSION, - callback: function() {} - }, - { - stringId: "push.alwaysBlock", - action: Ci.nsIPermissionManager.DENY_ACTION, - expireType: null, - callback: function() {} - }] - - var options = { - learnMoreURL: Services.urlFormatter.formatURLPref("browser.push.warning.infoURL"), - }; - - this._showPrompt(aRequest, message, "push", actions, "push", - "push-notification-icon", options); - - }, - _promptGeo : function(aRequest) { var browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties"); var requestingURI = aRequest.principal.URI; @@ -1866,9 +1830,13 @@ ContentPermissionPrompt.prototype = { }, ]; + var options = { + learnMoreURL: Services.urlFormatter.formatURLPref("browser.push.warning.infoURL"), + }; + this._showPrompt(aRequest, message, "desktop-notification", actions, "web-notifications", - "web-notifications-notification-icon", null); + "web-notifications-notification-icon", options); }, _promptPointerLock: function CPP_promtPointerLock(aRequest, autoAllow) { @@ -1922,7 +1890,6 @@ ContentPermissionPrompt.prototype = { const kFeatureKeys = { "geolocation" : "geo", "desktop-notification" : "desktop-notification", "pointerLock" : "pointerLock", - "push" : "push" }; // Make sure that we support the request. @@ -1966,10 +1933,6 @@ ContentPermissionPrompt.prototype = { case "pointerLock": this._promptPointerLock(request, autoAllow); break; - case "push": - this._promptPush(request); - break; - } }, }; -- cgit v1.2.3 From 7b7c12e0a36bb6fc8398baec12c0c5e484b38f5a Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 10:11:19 +0200 Subject: Bug 1216684 - Notification permissions cannot be global granted/denied in private windows --- application/palemoon/components/nsBrowserGlue.js | 55 +++++++++++++++--------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'application/palemoon/components/nsBrowserGlue.js') diff --git a/application/palemoon/components/nsBrowserGlue.js b/application/palemoon/components/nsBrowserGlue.js index 642e27c6b..9c3a9fbee 100644 --- a/application/palemoon/components/nsBrowserGlue.js +++ b/application/palemoon/components/nsBrowserGlue.js @@ -1809,27 +1809,42 @@ ContentPermissionPrompt.prototype = { var message = browserBundle.formatStringFromName("webNotifications.showFromSite", [requestingURI.host], 1); - var actions = [ - { - stringId: "webNotifications.showForSession", - action: Ci.nsIPermissionManager.ALLOW_ACTION, - expireType: Ci.nsIPermissionManager.EXPIRE_SESSION, - callback: function() {}, - }, - { - stringId: "webNotifications.alwaysShow", - action: Ci.nsIPermissionManager.ALLOW_ACTION, - expireType: null, - callback: function() {}, - }, - { - stringId: "webNotifications.neverShow", - action: Ci.nsIPermissionManager.DENY_ACTION, - expireType: null, - callback: function() {}, - }, - ]; + var actions; + var browser = this._getBrowserForRequest(aRequest); + // Only show "allow for session" in PB mode, we don't + // support "allow for session" in non-PB mode. + if (PrivateBrowsingUtils.isBrowserPrivate(browser)) { + actions = [ + { + stringId: "webNotifications.showForSession", + action: Ci.nsIPermissionManager.ALLOW_ACTION, + expireType: Ci.nsIPermissionManager.EXPIRE_SESSION, + callback: function() {}, + }, + ]; + } else { + actions = [ + { + stringId: "webNotifications.showForSession", + action: Ci.nsIPermissionManager.ALLOW_ACTION, + expireType: Ci.nsIPermissionManager.EXPIRE_SESSION, + callback: function() {}, + }, + { + stringId: "webNotifications.alwaysShow", + action: Ci.nsIPermissionManager.ALLOW_ACTION, + expireType: null, + callback: function() {}, + }, + { + stringId: "webNotifications.neverShow", + action: Ci.nsIPermissionManager.DENY_ACTION, + expireType: null, + callback: function() {}, + }, + ]; + } var options = { learnMoreURL: Services.urlFormatter.formatURLPref("browser.push.warning.infoURL"), }; -- cgit v1.2.3 From 79b88b30395c2a864b33ac90be804fc301d1d458 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 10:21:03 +0200 Subject: Bug 1216271 - Display a notification upon upgrade for users who currently allow notifications for at least one site --- application/palemoon/components/nsBrowserGlue.js | 58 ++++++++++++++++++------ 1 file changed, 45 insertions(+), 13 deletions(-) (limited to 'application/palemoon/components/nsBrowserGlue.js') diff --git a/application/palemoon/components/nsBrowserGlue.js b/application/palemoon/components/nsBrowserGlue.js index 9c3a9fbee..9d7e989a2 100644 --- a/application/palemoon/components/nsBrowserGlue.js +++ b/application/palemoon/components/nsBrowserGlue.js @@ -39,6 +39,9 @@ Cu.import("resource://gre/modules/Services.jsm"); ["DateTimePickerHelper", "resource://gre/modules/DateTimePickerHelper.jsm"], ].forEach(([name, resource]) => XPCOMUtils.defineLazyModuleGetter(this, name, resource)); +XPCOMUtils.defineLazyServiceGetter(this, "AlertsService", + "@mozilla.org/alerts-service;1", "nsIAlertsService"); + const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser"; const PREF_PLUGINS_UPDATEURL = "plugins.update.url"; @@ -825,16 +828,6 @@ BrowserGlue.prototype = { if (actions.indexOf("showAlert") == -1) return; - let notifier; - try { - notifier = Cc["@mozilla.org/alerts-service;1"]. - getService(Ci.nsIAlertsService); - } - catch (e) { - // nsIAlertsService is not available for this platform - return; - } - let title = getNotifyString({propName: "alertTitle", stringName: "puAlertTitle", stringParams: [appName]}); @@ -856,10 +849,10 @@ BrowserGlue.prototype = { try { // This will throw NS_ERROR_NOT_AVAILABLE if the notification cannot // be displayed per the idl. - notifier.showAlertNotification(null, title, text, - true, url, clickCallback); + AlertsService.showAlertNotification(null, title, text, } catch (e) { + Cu.reportError(e); } }, @@ -1191,7 +1184,7 @@ BrowserGlue.prototype = { }, _migrateUI: function BG__migrateUI() { - const UI_VERSION = 15; + const UI_VERSION = 17; const BROWSER_DOCURL = "chrome://browser/content/browser.xul#"; let currentUIVersion = 0; try { @@ -1386,6 +1379,10 @@ BrowserGlue.prototype = { } } + if (currentUIVersion < 17) { + this._notifyNotificationsUpgrade(); + } + if (this._dirty) this._dataSource.QueryInterface(Ci.nsIRDFRemoteDataSource).Flush(); @@ -1396,6 +1393,41 @@ BrowserGlue.prototype = { Services.prefs.setIntPref("browser.migration.version", UI_VERSION); }, + _hasExistingNotificationPermission: function BG__hasExistingNotificationPermission() { + let enumerator = Services.perms.enumerator; + while (enumerator.hasMoreElements()) { + let permission = enumerator.getNext().QueryInterface(Ci.nsIPermission); + if (permission.type == "desktop-notification") { + return true; + } + } + return false; + }, + + _notifyNotificationsUpgrade: function BG__notifyNotificationsUpgrade() { + if (!this._hasExistingNotificationPermission()) { + return; + } + function clickCallback(subject, topic, data) { + if (topic != "alertclickcallback") + return; + let win = RecentWindow.getMostRecentBrowserWindow(); + win.openUILinkIn(data, "tab"); + } + let imageURL = "chrome://browser/skin/web-notifications-icon.svg"; + let title = gBrowserBundle.GetStringFromName("webNotifications.upgradeTitle"); + let text = gBrowserBundle.GetStringFromName("webNotifications.upgradeInfo"); + let url = Services.urlFormatter.formatURLPref("browser.push.warning.infoURL"); + + try { + AlertsService.showAlertNotification(imageURL, title, text, + true, url, clickCallback); + } + catch (e) { + Cu.reportError(e); + } + }, + _getPersist: function BG__getPersist(aSource, aProperty) { var target = this._dataSource.GetTarget(aSource, aProperty, true); if (target instanceof Ci.nsIRDFLiteral) -- cgit v1.2.3 From 38dc3017a07a701402e2e3a9fce7db6d1741fb68 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 10:22:48 +0200 Subject: Bug 1220884 - Friendlier string for the notification upgrade UI --- application/palemoon/components/nsBrowserGlue.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'application/palemoon/components/nsBrowserGlue.js') diff --git a/application/palemoon/components/nsBrowserGlue.js b/application/palemoon/components/nsBrowserGlue.js index 9d7e989a2..6bac1d223 100644 --- a/application/palemoon/components/nsBrowserGlue.js +++ b/application/palemoon/components/nsBrowserGlue.js @@ -1416,7 +1416,7 @@ BrowserGlue.prototype = { } let imageURL = "chrome://browser/skin/web-notifications-icon.svg"; let title = gBrowserBundle.GetStringFromName("webNotifications.upgradeTitle"); - let text = gBrowserBundle.GetStringFromName("webNotifications.upgradeInfo"); + let text = gBrowserBundle.GetStringFromName("webNotifications.upgradeBody"); let url = Services.urlFormatter.formatURLPref("browser.push.warning.infoURL"); try { -- cgit v1.2.3 From 2703a13f12a878395806e7381e825d01c1537d8c Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 10:23:42 +0200 Subject: Bug 1221330 - Show the app icon in the XUL upgraded notifications alert --- application/palemoon/components/nsBrowserGlue.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'application/palemoon/components/nsBrowserGlue.js') diff --git a/application/palemoon/components/nsBrowserGlue.js b/application/palemoon/components/nsBrowserGlue.js index 6bac1d223..b8de4f00d 100644 --- a/application/palemoon/components/nsBrowserGlue.js +++ b/application/palemoon/components/nsBrowserGlue.js @@ -1414,7 +1414,10 @@ BrowserGlue.prototype = { let win = RecentWindow.getMostRecentBrowserWindow(); win.openUILinkIn(data, "tab"); } - let imageURL = "chrome://browser/skin/web-notifications-icon.svg"; + // Show the application icon for XUL notifications. We assume system-level + // notifications will include their own icon. + let imageURL = this._hasSystemAlertsService() ? "" : + "chrome://branding/content/about-logo.png"; let title = gBrowserBundle.GetStringFromName("webNotifications.upgradeTitle"); let text = gBrowserBundle.GetStringFromName("webNotifications.upgradeBody"); let url = Services.urlFormatter.formatURLPref("browser.push.warning.infoURL"); @@ -1428,6 +1431,14 @@ BrowserGlue.prototype = { } }, + _hasSystemAlertsService: function() { + try { + return !!Cc["@mozilla.org/system-alerts-service;1"].getService( + Ci.nsIAlertsService); + } catch (e) {} + return false; + }, + _getPersist: function BG__getPersist(aSource, aProperty) { var target = this._dataSource.GetTarget(aSource, aProperty, true); if (target instanceof Ci.nsIRDFLiteral) -- cgit v1.2.3 From 947461bd29b5a8fdb20d3118ca538f385b242943 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 16:06:24 +0200 Subject: [follow up] Bug 1216271 - Display a notification upon upgrade for users who currently allow notifications for at least one site --- application/palemoon/components/nsBrowserGlue.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'application/palemoon/components/nsBrowserGlue.js') diff --git a/application/palemoon/components/nsBrowserGlue.js b/application/palemoon/components/nsBrowserGlue.js index b8de4f00d..543698c3e 100644 --- a/application/palemoon/components/nsBrowserGlue.js +++ b/application/palemoon/components/nsBrowserGlue.js @@ -850,6 +850,7 @@ BrowserGlue.prototype = { // This will throw NS_ERROR_NOT_AVAILABLE if the notification cannot // be displayed per the idl. AlertsService.showAlertNotification(null, title, text, + true, url, clickCallback); } catch (e) { Cu.reportError(e); @@ -1982,15 +1983,16 @@ ContentPermissionPrompt.prototype = { // Show the prompt. switch (perm.type) { - case "geolocation": - this._promptGeo(request); - break; - case "desktop-notification": - this._promptWebNotifications(request); - break; - case "pointerLock": - this._promptPointerLock(request, autoAllow); - break; + case "geolocation": + this._promptGeo(request); + break; + case "desktop-notification": + this._promptWebNotifications(request); + break; + case "pointerLock": + this._promptPointerLock(request, autoAllow); + break; + } }, }; -- cgit v1.2.3 From 1d18a1e8ef5aba0458576f6974f844afd6f2c8f6 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 17:12:33 +0200 Subject: [follow up] Bug 1216684 - Notification permissions ... in private windows - implemented "_getBrowserForRequest" function (e10 off only) --- application/palemoon/components/nsBrowserGlue.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'application/palemoon/components/nsBrowserGlue.js') diff --git a/application/palemoon/components/nsBrowserGlue.js b/application/palemoon/components/nsBrowserGlue.js index 543698c3e..6563df4e6 100644 --- a/application/palemoon/components/nsBrowserGlue.js +++ b/application/palemoon/components/nsBrowserGlue.js @@ -1689,6 +1689,16 @@ ContentPermissionPrompt.prototype = { return chromeWin; }, + _getBrowserForRequest: function (aRequest) { + let requestingWindow = aRequest.window.top; + // find the requesting browser or iframe + let browser = requestingWindow.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIDocShell) + .chromeEventHandler; + return browser; + }, + /** * Show a permission prompt. * -- cgit v1.2.3