mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 697314 - Defer importing xpinstall permissions until necessary. r=Mossop
--HG-- rename : toolkit/mozapps/extensions/test/xpcshell/test_bug578467.js => toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js
This commit is contained in:
parent
313b0c24ef
commit
dd75fd5804
@ -6,6 +6,8 @@
|
|||||||
const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
|
const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
|
||||||
const nsICookiePermission = Components.interfaces.nsICookiePermission;
|
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, perm)
|
||||||
{
|
{
|
||||||
this.host = host;
|
this.host = host;
|
||||||
@ -183,6 +185,7 @@ var gPermissionManager = {
|
|||||||
|
|
||||||
var os = Components.classes["@mozilla.org/observer-service;1"]
|
var os = Components.classes["@mozilla.org/observer-service;1"]
|
||||||
.getService(Components.interfaces.nsIObserverService);
|
.getService(Components.interfaces.nsIObserverService);
|
||||||
|
os.notifyObservers(null, NOTIFICATION_FLUSH_PERMISSIONS, this._type);
|
||||||
os.addObserver(this, "perm-changed", false);
|
os.addObserver(this, "perm-changed", false);
|
||||||
|
|
||||||
this._loadPermissions();
|
this._loadPermissions();
|
||||||
|
@ -102,6 +102,7 @@ const KEY_APP_SYSTEM_LOCAL = "app-system-local";
|
|||||||
const KEY_APP_SYSTEM_SHARE = "app-system-share";
|
const KEY_APP_SYSTEM_SHARE = "app-system-share";
|
||||||
const KEY_APP_SYSTEM_USER = "app-system-user";
|
const KEY_APP_SYSTEM_USER = "app-system-user";
|
||||||
|
|
||||||
|
const NOTIFICATION_FLUSH_PERMISSIONS = "flush-pending-permissions";
|
||||||
const XPI_PERMISSION = "install";
|
const XPI_PERMISSION = "install";
|
||||||
|
|
||||||
const RDFURI_INSTALL_MANIFEST_ROOT = "urn:mozilla:install-manifest";
|
const RDFURI_INSTALL_MANIFEST_ROOT = "urn:mozilla:install-manifest";
|
||||||
@ -1952,6 +1953,7 @@ var XPIProvider = {
|
|||||||
|
|
||||||
Services.prefs.addObserver(PREF_EM_MIN_COMPAT_APP_VERSION, this, false);
|
Services.prefs.addObserver(PREF_EM_MIN_COMPAT_APP_VERSION, this, false);
|
||||||
Services.prefs.addObserver(PREF_EM_MIN_COMPAT_PLATFORM_VERSION, this, false);
|
Services.prefs.addObserver(PREF_EM_MIN_COMPAT_PLATFORM_VERSION, this, false);
|
||||||
|
Services.obs.addObserver(this, NOTIFICATION_FLUSH_PERMISSIONS, false);
|
||||||
|
|
||||||
let flushCaches = this.checkForChanges(aAppChanged, aOldAppVersion,
|
let flushCaches = this.checkForChanges(aAppChanged, aOldAppVersion,
|
||||||
aOldPlatformVersion);
|
aOldPlatformVersion);
|
||||||
@ -3322,10 +3324,6 @@ var XPIProvider = {
|
|||||||
aOldPlatformVersion) {
|
aOldPlatformVersion) {
|
||||||
LOG("checkForChanges");
|
LOG("checkForChanges");
|
||||||
|
|
||||||
// Import the website installation permissions if the application has changed
|
|
||||||
if (aAppChanged !== false)
|
|
||||||
this.importPermissions();
|
|
||||||
|
|
||||||
// Keep track of whether and why we need to open and update the database at
|
// Keep track of whether and why we need to open and update the database at
|
||||||
// startup time.
|
// startup time.
|
||||||
let updateReasons = [];
|
let updateReasons = [];
|
||||||
@ -3521,6 +3519,7 @@ var XPIProvider = {
|
|||||||
if (aUri.schemeIs("chrome") || aUri.schemeIs("file"))
|
if (aUri.schemeIs("chrome") || aUri.schemeIs("file"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
this.importPermissions();
|
||||||
|
|
||||||
let permission = Services.perms.testPermission(aUri, XPI_PERMISSION);
|
let permission = Services.perms.testPermission(aUri, XPI_PERMISSION);
|
||||||
if (permission == Ci.nsIPermissionManager.DENY_ACTION)
|
if (permission == Ci.nsIPermissionManager.DENY_ACTION)
|
||||||
@ -3849,15 +3848,24 @@ var XPIProvider = {
|
|||||||
* @see nsIObserver
|
* @see nsIObserver
|
||||||
*/
|
*/
|
||||||
observe: function XPI_observe(aSubject, aTopic, aData) {
|
observe: function XPI_observe(aSubject, aTopic, aData) {
|
||||||
switch (aData) {
|
if (aTopic == NOTIFICATION_FLUSH_PERMISSIONS) {
|
||||||
case PREF_EM_MIN_COMPAT_APP_VERSION:
|
if (!aData || aData == XPI_PERMISSION) {
|
||||||
case PREF_EM_MIN_COMPAT_PLATFORM_VERSION:
|
this.importPermissions();
|
||||||
this.minCompatibleAppVersion = Prefs.getCharPref(PREF_EM_MIN_COMPAT_APP_VERSION,
|
}
|
||||||
null);
|
return;
|
||||||
this.minCompatiblePlatformVersion = Prefs.getCharPref(PREF_EM_MIN_COMPAT_PLATFORM_VERSION,
|
}
|
||||||
null);
|
|
||||||
this.updateAddonAppDisabledStates();
|
if (aTopic == "nsPref:changed") {
|
||||||
break;
|
switch (aData) {
|
||||||
|
case PREF_EM_MIN_COMPAT_APP_VERSION:
|
||||||
|
case PREF_EM_MIN_COMPAT_PLATFORM_VERSION:
|
||||||
|
this.minCompatibleAppVersion = Prefs.getCharPref(PREF_EM_MIN_COMPAT_APP_VERSION,
|
||||||
|
null);
|
||||||
|
this.minCompatiblePlatformVersion = Prefs.getCharPref(PREF_EM_MIN_COMPAT_PLATFORM_VERSION,
|
||||||
|
null);
|
||||||
|
this.updateAddonAppDisabledStates();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Tests that xpinstall.[whitelist|blacklist].add preferences are emptied when
|
|
||||||
// converted into permissions on startup with new profile
|
|
||||||
|
|
||||||
const PREF_XPI_WHITELIST_PERMISSIONS = "xpinstall.whitelist.add";
|
|
||||||
const PREF_XPI_BLACKLIST_PERMISSIONS = "xpinstall.blacklist.add";
|
|
||||||
|
|
||||||
function run_test() {
|
|
||||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
|
|
||||||
|
|
||||||
// Create own preferences to test
|
|
||||||
Services.prefs.setCharPref("xpinstall.whitelist.add.EMPTY", "");
|
|
||||||
Services.prefs.setCharPref("xpinstall.whitelist.add.TEST", "whitelist.example.com");
|
|
||||||
Services.prefs.setCharPref("xpinstall.blacklist.add.EMPTY", "");
|
|
||||||
Services.prefs.setCharPref("xpinstall.blacklist.add.TEST", "blacklist.example.com");
|
|
||||||
|
|
||||||
// Get list of preferences to check
|
|
||||||
var whitelistPreferences = Services.prefs.getChildList(PREF_XPI_WHITELIST_PERMISSIONS, {});
|
|
||||||
var blacklistPreferences = Services.prefs.getChildList(PREF_XPI_BLACKLIST_PERMISSIONS, {});
|
|
||||||
var preferences = whitelistPreferences.concat(blacklistPreferences);
|
|
||||||
|
|
||||||
startupManager();
|
|
||||||
|
|
||||||
// Check preferences were emptied
|
|
||||||
preferences.forEach(function(aPreference) {
|
|
||||||
try {
|
|
||||||
do_check_eq(Services.prefs.getCharPref(aPreference), "");
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
// Successfully emptied
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,71 @@
|
|||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Tests that xpinstall.[whitelist|blacklist].add preferences are emptied when
|
||||||
|
// converted into permissions.
|
||||||
|
|
||||||
|
const PREF_XPI_WHITELIST_PERMISSIONS = "xpinstall.whitelist.add";
|
||||||
|
const PREF_XPI_BLACKLIST_PERMISSIONS = "xpinstall.blacklist.add";
|
||||||
|
|
||||||
|
function do_check_permission_prefs(preferences) {
|
||||||
|
// Check preferences were emptied
|
||||||
|
for (let pref of preferences) {
|
||||||
|
try {
|
||||||
|
do_check_eq(Services.prefs.getCharPref(pref), "");
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
// Successfully emptied
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clear_imported_preferences_cache() {
|
||||||
|
let scope = Components.utils.import("resource://gre/modules/PermissionsUtils.jsm", {});
|
||||||
|
scope.gImportedPrefBranches.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_test() {
|
||||||
|
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
|
||||||
|
|
||||||
|
// Create own preferences to test
|
||||||
|
Services.prefs.setCharPref("xpinstall.whitelist.add.EMPTY", "");
|
||||||
|
Services.prefs.setCharPref("xpinstall.whitelist.add.TEST", "whitelist.example.com");
|
||||||
|
Services.prefs.setCharPref("xpinstall.blacklist.add.EMPTY", "");
|
||||||
|
Services.prefs.setCharPref("xpinstall.blacklist.add.TEST", "blacklist.example.com");
|
||||||
|
|
||||||
|
// Get list of preferences to check
|
||||||
|
var whitelistPreferences = Services.prefs.getChildList(PREF_XPI_WHITELIST_PERMISSIONS, {});
|
||||||
|
var blacklistPreferences = Services.prefs.getChildList(PREF_XPI_BLACKLIST_PERMISSIONS, {});
|
||||||
|
var preferences = whitelistPreferences.concat(blacklistPreferences);
|
||||||
|
|
||||||
|
startupManager();
|
||||||
|
|
||||||
|
// Permissions are imported lazily - act as thought we're checking an install,
|
||||||
|
// to trigger on-deman importing of the permissions.
|
||||||
|
let url = Services.io.newURI("http://example.com/file.xpi", null, null);
|
||||||
|
AddonManager.isInstallAllowed("application/x-xpinstall", url);
|
||||||
|
do_check_permission_prefs(preferences);
|
||||||
|
|
||||||
|
|
||||||
|
// Import can also be triggerred by an observer notification by any other area
|
||||||
|
// of code, such as a permissions management UI.
|
||||||
|
|
||||||
|
// First, request to flush all permissions
|
||||||
|
clear_imported_preferences_cache();
|
||||||
|
Services.prefs.setCharPref("xpinstall.whitelist.add.TEST2", "whitelist2.example.com");
|
||||||
|
Services.obs.notifyObservers(null, "flush-pending-permissions", "install");
|
||||||
|
do_check_permission_prefs(preferences);
|
||||||
|
|
||||||
|
// Then, request to flush just install permissions
|
||||||
|
clear_imported_preferences_cache();
|
||||||
|
Services.prefs.setCharPref("xpinstall.whitelist.add.TEST3", "whitelist3.example.com");
|
||||||
|
Services.obs.notifyObservers(null, "flush-pending-permissions", "");
|
||||||
|
do_check_permission_prefs(preferences);
|
||||||
|
|
||||||
|
// And a request to flush some other permissions sholdn't flush install permissions
|
||||||
|
clear_imported_preferences_cache();
|
||||||
|
Services.prefs.setCharPref("xpinstall.whitelist.add.TEST4", "whitelist4.example.com");
|
||||||
|
Services.obs.notifyObservers(null, "flush-pending-permissions", "lolcats");
|
||||||
|
do_check_eq(Services.prefs.getCharPref("xpinstall.whitelist.add.TEST4"), "whitelist4.example.com");
|
||||||
|
}
|
@ -122,7 +122,6 @@ fail-if = os == "android"
|
|||||||
[test_bug569138.js]
|
[test_bug569138.js]
|
||||||
[test_bug570173.js]
|
[test_bug570173.js]
|
||||||
[test_bug576735.js]
|
[test_bug576735.js]
|
||||||
[test_bug578467.js]
|
|
||||||
[test_bug587088.js]
|
[test_bug587088.js]
|
||||||
[test_bug594058.js]
|
[test_bug594058.js]
|
||||||
[test_bug595081.js]
|
[test_bug595081.js]
|
||||||
@ -205,6 +204,7 @@ skip-if = os == "android"
|
|||||||
[test_migrate_max_version.js]
|
[test_migrate_max_version.js]
|
||||||
[test_onPropertyChanged_appDisabled.js]
|
[test_onPropertyChanged_appDisabled.js]
|
||||||
[test_permissions.js]
|
[test_permissions.js]
|
||||||
|
[test_permissions_prefs.js]
|
||||||
[test_plugins.js]
|
[test_plugins.js]
|
||||||
[test_pluginchange.js]
|
[test_pluginchange.js]
|
||||||
[test_pluginBlocklistCtp.js]
|
[test_pluginBlocklistCtp.js]
|
||||||
|
Loading…
Reference in New Issue
Block a user