From b0d7b1bb38ba3c6940d17c6974b5295d9a10e161 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 05:39:27 +0200 Subject: Bug 996448 - Lazify the loading of PluralForm.jsm everywhere --- application/palemoon/components/preferences/aboutPermissions.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'application/palemoon/components') diff --git a/application/palemoon/components/preferences/aboutPermissions.js b/application/palemoon/components/preferences/aboutPermissions.js index 31b48f88e..99c9d44ad 100644 --- a/application/palemoon/components/preferences/aboutPermissions.js +++ b/application/palemoon/components/preferences/aboutPermissions.js @@ -6,13 +6,16 @@ var Ci = Components.interfaces; var Cc = Components.classes; var Cu = Components.utils; +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); -Cu.import("resource://gre/modules/PluralForm.jsm"); Cu.import("resource://gre/modules/DownloadUtils.jsm"); Cu.import("resource://gre/modules/AddonManager.jsm"); Cu.import("resource://gre/modules/NetUtil.jsm"); Cu.import("resource://gre/modules/ForgetAboutSite.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", + "resource://gre/modules/PluralForm.jsm"); + var gFaviconService = Cc["@mozilla.org/browser/favicon-service;1"]. getService(Ci.nsIFaviconService); -- cgit v1.2.3 From c86fbfd0313ae6bd6c54ea8f4a28b42f7852b38c Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 05:40:26 +0200 Subject: Bug 1115293 - Use "use strict" --- application/palemoon/components/preferences/aboutPermissions.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'application/palemoon/components') diff --git a/application/palemoon/components/preferences/aboutPermissions.js b/application/palemoon/components/preferences/aboutPermissions.js index 99c9d44ad..416bcdf34 100644 --- a/application/palemoon/components/preferences/aboutPermissions.js +++ b/application/palemoon/components/preferences/aboutPermissions.js @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + var Ci = Components.interfaces; var Cc = Components.classes; var Cu = Components.utils; -- cgit v1.2.3 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 +++++++++++++++++++++- .../components/preferences/aboutPermissions.js | 19 ++++++++-- .../components/preferences/aboutPermissions.xul | 20 +++++++++++ 3 files changed, 77 insertions(+), 3 deletions(-) (limited to 'application/palemoon/components') 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; } }, diff --git a/application/palemoon/components/preferences/aboutPermissions.js b/application/palemoon/components/preferences/aboutPermissions.js index 416bcdf34..0c3f8b823 100644 --- a/application/palemoon/components/preferences/aboutPermissions.js +++ b/application/palemoon/components/preferences/aboutPermissions.js @@ -449,6 +449,19 @@ var PermissionDefaults = { let value = (aValue != this.DENY); Services.prefs.setBoolPref("full-screen-api.pointer-lock.enabled", value); }, + + get push() { + if (!Services.prefs.getBoolPref("dom.push.enabled")) { + return this.DENY; + } + // We always ask for permission to push with a specific site, + // so there is no global ALLOW. + return this.UNKNOWN; + }, + set push(aValue) { + let value = (aValue != this.DENY); + Services.prefs.setBoolPref("dom.push.enabled", value); + }, } /** @@ -488,13 +501,13 @@ var AboutPermissions = { */ _supportedPermissions: ["password", "image", "popup", "cookie", "desktop-notification", "install", "geo", "indexedDB", - "fullscreen", "pointerLock"], + "fullscreen", "pointerLock", "push"], /** * Permissions that don't have a global "Allow" option. */ _noGlobalAllow: ["desktop-notification", "geo", "indexedDB", "fullscreen", - "pointerLock"], + "pointerLock", "push"], /** * Permissions that don't have a global "Deny" option. @@ -543,6 +556,7 @@ var AboutPermissions = { Services.prefs.addObserver("plugins.click_to_play", this, false); Services.prefs.addObserver("full-screen-api.enabled", this, false); Services.prefs.addObserver("full-screen-api.pointer-lock.enabled", this, false); + Services.prefs.addObserver("dom.push.enabled", this, false); Services.prefs.addObserver("permissions.places-sites-limit", this, false); Services.obs.addObserver(this, "perm-changed", false); @@ -695,6 +709,7 @@ var AboutPermissions = { Services.prefs.removeObserver("plugins.click_to_play", this, false); Services.prefs.removeObserver("full-screen-api.enabled", this, false); Services.prefs.removeObserver("full-screen-api.pointer-lock.enabled", this, false); + Services.prefs.removeObserver("dom.push.enabled", this, false); Services.prefs.removeObserver("permissions.places-sites-limit", this, false); Services.obs.removeObserver(this, "perm-changed"); diff --git a/application/palemoon/components/preferences/aboutPermissions.xul b/application/palemoon/components/preferences/aboutPermissions.xul index bd5a205c7..279de8d9b 100644 --- a/application/palemoon/components/preferences/aboutPermissions.xul +++ b/application/palemoon/components/preferences/aboutPermissions.xul @@ -391,6 +391,26 @@ + + + + + + -- cgit v1.2.3 From 62779a4b8dc7ddd4ba406bd0245ae6f7386b2f2f Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 06:19:39 +0200 Subject: Bug 1038811 - Push Notifications (observer) --- application/palemoon/components/preferences/aboutPermissions.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'application/palemoon/components') diff --git a/application/palemoon/components/preferences/aboutPermissions.js b/application/palemoon/components/preferences/aboutPermissions.js index 0c3f8b823..73d51909b 100644 --- a/application/palemoon/components/preferences/aboutPermissions.js +++ b/application/palemoon/components/preferences/aboutPermissions.js @@ -552,6 +552,7 @@ var AboutPermissions = { Services.prefs.addObserver("dom.webnotifications.enabled", this, false); Services.prefs.addObserver("xpinstall.whitelist.required", this, false); Services.prefs.addObserver("geo.enabled", this, false); + Services.prefs.addObserver("dom.push.enabled", this, false); Services.prefs.addObserver("dom.indexedDB.enabled", this, false); Services.prefs.addObserver("plugins.click_to_play", this, false); Services.prefs.addObserver("full-screen-api.enabled", this, false); @@ -705,6 +706,7 @@ var AboutPermissions = { Services.prefs.removeObserver("dom.webnotifications.enabled", this, false); Services.prefs.removeObserver("xpinstall.whitelist.required", this, false); Services.prefs.removeObserver("geo.enabled", this, false); + Services.prefs.removeObserver("dom.push.enabled", this, false); Services.prefs.removeObserver("dom.indexedDB.enabled", this, false); Services.prefs.removeObserver("plugins.click_to_play", this, false); Services.prefs.removeObserver("full-screen-api.enabled", this, false); -- cgit v1.2.3 From e33d1d875e14056204214378bbee3923bce8219c Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 06:32:22 +0200 Subject: Bug 956151 - Remove the perm attribute in permissions.js --- application/palemoon/components/preferences/permissions.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'application/palemoon/components') diff --git a/application/palemoon/components/preferences/permissions.js b/application/palemoon/components/preferences/permissions.js index 785e26d5e..0723a44cb 100644 --- a/application/palemoon/components/preferences/permissions.js +++ b/application/palemoon/components/preferences/permissions.js @@ -8,13 +8,12 @@ const nsICookiePermission = Components.interfaces.nsICookiePermission; const NOTIFICATION_FLUSH_PERMISSIONS = "flush-pending-permissions"; -function Permission(host, rawHost, type, capability, perm) +function Permission(host, rawHost, type, capability) { this.host = host; this.rawHost = rawHost; this.type = type; this.capability = capability; - this.perm = perm; } var gPermissionManager = { @@ -105,7 +104,7 @@ var gPermissionManager = { // Avoid calling the permission manager if the capability settings are // the same. Otherwise allow the call to the permissions manager to // update the listbox for us. - exists = this._permissions[i].perm == aCapability; + exists = this._permissions[i].capability == capabilityString; break; } } @@ -337,8 +336,7 @@ var gPermissionManager = { var p = new Permission(host, (host.charAt(0) == ".") ? host.substring(1,host.length) : host, aPermission.type, - capabilityString, - aPermission.capability); + capabilityString); this._permissions.push(p); } }, -- cgit v1.2.3 From 90e7b450997fcf0e48034dbec4402f9f68027b0b Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 06:33:40 +0200 Subject: Bug 1006461 - Fix handling of permission notifications in preference dialogs --- application/palemoon/components/preferences/permissions.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'application/palemoon/components') diff --git a/application/palemoon/components/preferences/permissions.js b/application/palemoon/components/preferences/permissions.js index 0723a44cb..25d86fabf 100644 --- a/application/palemoon/components/preferences/permissions.js +++ b/application/palemoon/components/preferences/permissions.js @@ -203,6 +203,11 @@ var gPermissionManager = { { if (aTopic == "perm-changed") { var permission = aSubject.QueryInterface(Components.interfaces.nsIPermission); + + // Ignore unrelated permission types. + if (permission.type != this._type) + return; + if (aData == "added") { this._addPermissionToList(permission); ++this._view._rowCount; -- cgit v1.2.3 From 522095380fc6cf3b214746802012fccb8f1071bd Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 06:35:21 +0200 Subject: Bug 431901 - Update preference dialogs to treat backspace and delete equivalently on Mac OS X --- application/palemoon/components/preferences/cookies.js | 7 ++++++- application/palemoon/components/preferences/jar.mn | 4 ++-- application/palemoon/components/preferences/permissions.js | 7 ++++++- 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'application/palemoon/components') diff --git a/application/palemoon/components/preferences/cookies.js b/application/palemoon/components/preferences/cookies.js index ea7e7d4e2..d493a0056 100644 --- a/application/palemoon/components/preferences/cookies.js +++ b/application/palemoon/components/preferences/cookies.js @@ -725,8 +725,13 @@ var gCookiesWindow = { }, onCookieKeyPress: function (aEvent) { - if (aEvent.keyCode == 46) + if (aEvent.keyCode == KeyEvent.DOM_VK_DELETE +#ifdef XP_MACOSX + || aEvent.keyCode == KeyEvent.DOM_VK_BACK_SPACE +#endif + ) { this.deleteCookie(); + } }, _lastSortProperty : "", diff --git a/application/palemoon/components/preferences/jar.mn b/application/palemoon/components/preferences/jar.mn index a27784305..c1f7a5511 100644 --- a/application/palemoon/components/preferences/jar.mn +++ b/application/palemoon/components/preferences/jar.mn @@ -15,7 +15,7 @@ browser.jar: * content/browser/preferences/applicationManager.js * content/browser/preferences/colors.xul * content/browser/preferences/cookies.xul - content/browser/preferences/cookies.js +* content/browser/preferences/cookies.js content/browser/preferences/content.xul content/browser/preferences/content.js * content/browser/preferences/connection.xul @@ -29,7 +29,7 @@ browser.jar: * content/browser/preferences/main.xul content/browser/preferences/main.js * content/browser/preferences/permissions.xul - content/browser/preferences/permissions.js +* content/browser/preferences/permissions.js * content/browser/preferences/preferences.xul content/browser/preferences/privacy.xul content/browser/preferences/privacy.js diff --git a/application/palemoon/components/preferences/permissions.js b/application/palemoon/components/preferences/permissions.js index 25d86fabf..30c1db8be 100644 --- a/application/palemoon/components/preferences/permissions.js +++ b/application/palemoon/components/preferences/permissions.js @@ -283,8 +283,13 @@ var gPermissionManager = { onPermissionKeyPress: function (aEvent) { - if (aEvent.keyCode == 46) + if (aEvent.keyCode == KeyEvent.DOM_VK_DELETE +#ifdef XP_MACOSX + || aEvent.keyCode == KeyEvent.DOM_VK_BACK_SPACE +#endif + ) { this.onPermissionDeleted(); + } }, _lastPermissionSortColumn: "", -- cgit v1.2.3 From b688bdfa9aae1806f151b76abca7ea65228ec816 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 06:42:11 +0200 Subject: Bug 574460 - Fix handling of permission deletion notifications in preference dialogs --- .../palemoon/components/preferences/permissions.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'application/palemoon/components') diff --git a/application/palemoon/components/preferences/permissions.js b/application/palemoon/components/preferences/permissions.js index 30c1db8be..015f96a32 100644 --- a/application/palemoon/components/preferences/permissions.js +++ b/application/palemoon/components/preferences/permissions.js @@ -238,10 +238,17 @@ var gPermissionManager = { } this._tree.treeBoxObject.invalidate(); } - // No UI other than this window causes this method to be sent a "deleted" - // notification, so we don't need to implement it since Delete is handled - // directly by the Permission Removal handlers. If that ever changes, those - // implementations will have to move into here. + else if (aData == "deleted") { + for (var i = 0; i < this._permissions.length; i++) { + if (this._permissions[i].host == permission.host) { + this._permissions.splice(i, 1); + this._view._rowCount--; + this._tree.treeBoxObject.rowCountChanged(this._view.rowCount - 1, -1); + this._tree.treeBoxObject.invalidate(); + break; + } + } + } } }, -- cgit v1.2.3 From 0bea8f9effeed045e645bf951995e6ed480bdf0f Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 26 Apr 2018 07:06:14 +0200 Subject: Bug 340432 - Add the ability to cancel site permission changes --- application/palemoon/components/preferences/jar.mn | 2 +- .../palemoon/components/preferences/permissions.js | 233 +++++++++++++-------- .../components/preferences/permissions.xul | 16 +- 3 files changed, 156 insertions(+), 95 deletions(-) (limited to 'application/palemoon/components') diff --git a/application/palemoon/components/preferences/jar.mn b/application/palemoon/components/preferences/jar.mn index c1f7a5511..798a2dae4 100644 --- a/application/palemoon/components/preferences/jar.mn +++ b/application/palemoon/components/preferences/jar.mn @@ -28,7 +28,7 @@ browser.jar: content/browser/preferences/languages.js * content/browser/preferences/main.xul content/browser/preferences/main.js -* content/browser/preferences/permissions.xul + content/browser/preferences/permissions.xul * content/browser/preferences/permissions.js * content/browser/preferences/preferences.xul content/browser/preferences/privacy.xul diff --git a/application/palemoon/components/preferences/permissions.js b/application/palemoon/components/preferences/permissions.js index 015f96a32..8f0387b7d 100644 --- a/application/palemoon/components/preferences/permissions.js +++ b/application/palemoon/components/preferences/permissions.js @@ -3,12 +3,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +Components.utils.import("resource://gre/modules/Services.jsm"); + const nsIPermissionManager = Components.interfaces.nsIPermissionManager; const nsICookiePermission = Components.interfaces.nsICookiePermission; const NOTIFICATION_FLUSH_PERMISSIONS = "flush-pending-permissions"; -function Permission(host, rawHost, type, capability) +function Permission(host, rawHost, type, capability) { this.host = host; this.rawHost = rawHost; @@ -17,18 +19,19 @@ function Permission(host, rawHost, type, capability) } var gPermissionManager = { - _type : "", - _permissions : [], - _pm : Components.classes["@mozilla.org/permissionmanager;1"] - .getService(Components.interfaces.nsIPermissionManager), - _bundle : null, - _tree : null, - + _type : "", + _permissions : [], + _permissionsToAdd : new Map(), + _permissionsToDelete : new Map(), + _bundle : null, + _tree : null, + _observerRemoved : false, + _view: { _rowCount: 0, - get rowCount() - { - return this._rowCount; + get rowCount() + { + return this._rowCount; }, getCellText: function (aRow, aColumn) { @@ -56,7 +59,7 @@ var gPermissionManager = { return ""; } }, - + _getCapabilityString: function (aCapability) { var stringKey = null; @@ -76,44 +79,48 @@ var gPermissionManager = { } return this._bundle.getString(stringKey); }, - + addPermission: function (aCapability) { var textbox = document.getElementById("url"); var host = textbox.value.replace(/^\s*([-\w]*:\/+)?/, ""); // trim any leading space and scheme try { - var ioService = Components.classes["@mozilla.org/network/io-service;1"] - .getService(Components.interfaces.nsIIOService); - var uri = ioService.newURI("http://"+host, null, null); + var uri = Services.io.newURI("http://" + host, null, null); host = uri.host; } catch(ex) { - var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Components.interfaces.nsIPromptService); var message = this._bundle.getString("invalidURI"); var title = this._bundle.getString("invalidURITitle"); - promptService.alert(window, title, message); + Services.prompt.alert(window, title, message); return; } var capabilityString = this._getCapabilityString(aCapability); // check whether the permission already exists, if not, add it - var exists = false; + let hostExists = false; + let capabilityExists = false; for (var i = 0; i < this._permissions.length; ++i) { if (this._permissions[i].rawHost == host) { - // Avoid calling the permission manager if the capability settings are - // the same. Otherwise allow the call to the permissions manager to - // update the listbox for us. - exists = this._permissions[i].capability == capabilityString; + hostExists = true; + capabilityExists = this._permissions[i].capability == capabilityString; + if (!capabilityExists) { + this._permissions[i].capability = capabilityString; + } break; } } - if (!exists) { - host = (host.charAt(0) == ".") ? host.substring(1,host.length) : host; - var uri = ioService.newURI("http://" + host, null, null); - this._pm.add(uri, this._type, aCapability); + + let permissionParams = {host: host, type: this._type, capability: aCapability}; + if (!hostExists) { + this._permissionsToAdd.set(host, permissionParams); + this._addPermission(permissionParams); + } + else if (!capabilityExists) { + this._permissionsToAdd.set(host, permissionParams); + this._handleCapabilityChange(); } + textbox.value = ""; textbox.focus(); @@ -123,14 +130,58 @@ var gPermissionManager = { // enable "remove all" button as needed document.getElementById("removeAllPermissions").disabled = this._permissions.length == 0; }, - + + _removePermission: function(aPermission) + { + this._removePermissionFromList(aPermission.host); + + // If this permission was added during this session, let's remove + // it from the pending adds list to prevent calls to the + // permission manager. + let isNewPermission = this._permissionsToAdd.delete(aPermission.host); + + if (!isNewPermission) { + this._permissionsToDelete.set(aPermission.host, aPermission); + } + + }, + + _handleCapabilityChange: function () + { + // Re-do the sort, if the status changed from Block to Allow + // or vice versa, since if we're sorted on status, we may no + // longer be in order. + if (this._lastPermissionSortColumn.id == "statusCol") { + this._resortPermissions(); + } + this._tree.treeBoxObject.invalidate(); + }, + + _addPermission: function(aPermission) + { + this._addPermissionToList(aPermission); + ++this._view._rowCount; + this._tree.treeBoxObject.rowCountChanged(this._view.rowCount - 1, 1); + // Re-do the sort, since we inserted this new item at the end. + this._resortPermissions(); + }, + + _resortPermissions: function() + { + gTreeUtils.sort(this._tree, this._view, this._permissions, + this._lastPermissionSortColumn, + this._permissionsComparator, + this._lastPermissionSortColumn, + !this._lastPermissionSortAscending); // keep sort direction + }, + onHostInput: function (aSiteField) { document.getElementById("btnSession").disabled = !aSiteField.value; document.getElementById("btnBlock").disabled = !aSiteField.value; document.getElementById("btnAllow").disabled = !aSiteField.value; }, - + onWindowKeyPress: function (aEvent) { if (aEvent.keyCode == KeyEvent.DOM_VK_ESCAPE) @@ -142,14 +193,14 @@ var gPermissionManager = { if (aEvent.keyCode == KeyEvent.DOM_VK_RETURN) document.getElementById("btnAllow").click(); }, - + onLoad: function () { this._bundle = document.getElementById("bundlePreferences"); var params = window.arguments[0]; this.init(params); }, - + init: function (aParams) { if (this._type) { @@ -159,14 +210,14 @@ var gPermissionManager = { this._type = aParams.permissionType; this._manageCapability = aParams.manageCapability; - + var permissionsText = document.getElementById("permissionsText"); while (permissionsText.hasChildNodes()) permissionsText.removeChild(permissionsText.firstChild); permissionsText.appendChild(document.createTextNode(aParams.introText)); document.title = aParams.windowTitle; - + document.getElementById("btnBlock").hidden = !aParams.blockVisible; document.getElementById("btnSession").hidden = !aParams.sessionVisible; document.getElementById("btnAllow").hidden = !aParams.allowVisible; @@ -184,21 +235,23 @@ var gPermissionManager = { var os = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService); - os.notifyObservers(null, NOTIFICATION_FLUSH_PERMISSIONS, this._type); - os.addObserver(this, "perm-changed", false); + Services.obs.notifyObservers(null, NOTIFICATION_FLUSH_PERMISSIONS, this._type); + Services.obs.addObserver(this, "perm-changed", false); this._loadPermissions(); - + urlField.focus(); }, - + uninit: function () { - var os = Components.classes["@mozilla.org/observer-service;1"] - .getService(Components.interfaces.nsIObserverService); - os.removeObserver(this, "perm-changed"); + if (!this._observerRemoved) { + Services.obs.removeObserver(this, "perm-changed"); + + this._observerRemoved = true; + } }, - + observe: function (aSubject, aTopic, aData) { if (aTopic == "perm-changed") { @@ -209,15 +262,7 @@ var gPermissionManager = { return; if (aData == "added") { - this._addPermissionToList(permission); - ++this._view._rowCount; - this._tree.treeBoxObject.rowCountChanged(this._view.rowCount - 1, 1); - // Re-do the sort, since we inserted this new item at the end. - gTreeUtils.sort(this._tree, this._view, this._permissions, - this._lastPermissionSortColumn, - this._permissionsComparator, - this._lastPermissionSortColumn, - !this._lastPermissionSortAscending); // keep sort direction + this._addPermission(permission); } else if (aData == "changed") { for (var i = 0; i < this._permissions.length; ++i) { @@ -226,32 +271,14 @@ var gPermissionManager = { break; } } - // Re-do the sort, if the status changed from Block to Allow - // or vice versa, since if we're sorted on status, we may no - // longer be in order. - if (this._lastPermissionSortColumn == "statusCol") { - gTreeUtils.sort(this._tree, this._view, this._permissions, - this._lastPermissionSortColumn, - this._permissionsComparator, - this._lastPermissionSortColumn, - !this._lastPermissionSortAscending); // keep sort direction - } - this._tree.treeBoxObject.invalidate(); + this._handleCapabilityChange(); } else if (aData == "deleted") { - for (var i = 0; i < this._permissions.length; i++) { - if (this._permissions[i].host == permission.host) { - this._permissions.splice(i, 1); - this._view._rowCount--; - this._tree.treeBoxObject.rowCountChanged(this._view.rowCount - 1, -1); - this._tree.treeBoxObject.invalidate(); - break; - } - } + this._removePermissionFromList(permission); } } }, - + onPermissionSelected: function () { var hasSelection = this._tree.view.selection.count > 0; @@ -268,8 +295,8 @@ var gPermissionManager = { gTreeUtils.deleteSelectedItems(this._tree, this._view, this._permissions, removedPermissions); for (var i = 0; i < removedPermissions.length; ++i) { var p = removedPermissions[i]; - this._pm.remove(p.host, p.type); - } + this._removePermission(p); + } document.getElementById("removePermission").disabled = !this._permissions.length; document.getElementById("removeAllPermissions").disabled = !this._permissions.length; }, @@ -282,12 +309,12 @@ var gPermissionManager = { gTreeUtils.deleteAll(this._tree, this._view, this._permissions, removedPermissions); for (var i = 0; i < removedPermissions.length; ++i) { var p = removedPermissions[i]; - this._pm.remove(p.host, p.type); - } + this._removePermission(p); + } document.getElementById("removePermission").disabled = true; document.getElementById("removeAllPermissions").disabled = true; }, - + onPermissionKeyPress: function (aEvent) { if (aEvent.keyCode == KeyEvent.DOM_VK_DELETE @@ -298,7 +325,7 @@ var gPermissionManager = { this.onPermissionDeleted(); } }, - + _lastPermissionSortColumn: "", _lastPermissionSortAscending: false, _permissionsComparator : function (a, b) @@ -309,16 +336,35 @@ var gPermissionManager = { onPermissionSort: function (aColumn) { - this._lastPermissionSortAscending = gTreeUtils.sort(this._tree, - this._view, + this._lastPermissionSortAscending = gTreeUtils.sort(this._tree, + this._view, this._permissions, aColumn, this._permissionsComparator, - this._lastPermissionSortColumn, + this._lastPermissionSortColumn, this._lastPermissionSortAscending); this._lastPermissionSortColumn = aColumn; }, - + + onApplyChanges: function() + { + // Stop observing permission changes since we are about + // to write out the pending adds/deletes and don't need + // to update the UI + this.uninit(); + + for (let permissionParams of this._permissionsToAdd.values()) { + let uri = Services.io.newURI("http://" + permissionParams.host, null, null); + Services.perms.add(uri, permissionParams.type, permissionParams.capability); + } + + for (let p of this._permissionsToDelete.values()) { + Services.perms.remove(p.host, p.type); + } + + window.close(); + }, + _loadPermissions: function () { this._tree = document.getElementById("permissionsTree"); @@ -326,12 +372,12 @@ var gPermissionManager = { // load permissions into a table var count = 0; - var enumerator = this._pm.enumerator; + var enumerator = Services.perms.enumerator; while (enumerator.hasMoreElements()) { var nextPermission = enumerator.getNext().QueryInterface(Components.interfaces.nsIPermission); this._addPermissionToList(nextPermission); } - + this._view._rowCount = this._permissions.length; // sort and display the table @@ -341,7 +387,7 @@ var gPermissionManager = { // disable "remove all" button if there are none document.getElementById("removeAllPermissions").disabled = this._permissions.length == 0; }, - + _addPermissionToList: function (aPermission) { if (aPermission.type == this._type && @@ -355,15 +401,28 @@ var gPermissionManager = { aPermission.type, capabilityString); this._permissions.push(p); - } + } }, - + setHost: function (aHost) { document.getElementById("url").value = aHost; } }; + _removePermissionFromList: function (aHost) + { + for (let i = 0; i < this._permissions.length; ++i) { + if (this._permissions[i].host == aHost) { + this._permissions.splice(i, 1); + this._view._rowCount--; + this._tree.treeBoxObject.rowCountChanged(this._view.rowCount - 1, -1); + this._tree.treeBoxObject.invalidate(); + break; + } + } + }, + function setHost(aHost) { gPermissionManager.setHost(aHost); diff --git a/application/palemoon/components/preferences/permissions.xul b/application/palemoon/components/preferences/permissions.xul index fd550e8f7..8f24c8946 100644 --- a/application/palemoon/components/preferences/permissions.xul +++ b/application/palemoon/components/preferences/permissions.xul @@ -62,8 +62,8 @@ - - + +