Bug 457296 - Allow nsIPermissionManager to accept mailto URLs. r=jdm.

This commit is contained in:
Mike Conley 2013-11-18 23:34:00 -05:00
Родитель b25b13f3bc
Коммит c5eff3cccc
3 изменённых файлов: 53 добавлений и 0 удалений

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

@ -132,6 +132,20 @@ GetHostForPrincipal(nsIPrincipal* aPrincipal, nsACString& aHost)
return NS_OK;
}
// For the mailto scheme, we use the path of the URI. We have to chop off the
// query part if one exists, so we eliminate everything after a ?.
bool isMailTo = false;
if (NS_SUCCEEDED(uri->SchemeIs("mailto", &isMailTo)) && isMailTo) {
rv = uri->GetPath(aHost);
NS_ENSURE_SUCCESS(rv, rv);
int32_t spart = aHost.FindChar('?', 0);
if (spart >= 0) {
aHost.Cut(spart, aHost.Length() - spart);
}
return NS_OK;
}
// Some entries like "file://" uses the origin.
rv = aPrincipal->GetOrigin(getter_Copies(aHost));
if (NS_SUCCEEDED(rv) && !aHost.IsEmpty()) {

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

@ -0,0 +1,38 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function run_test() {
// initialize the permission manager service
const kTestAddr = "test@example.org";
const kType = "test-mailto";
const kCapability = 1;
// make a mailto: URI with parameters
let uri = Services.io.newURI("mailto:" + kTestAddr + "?subject=test", null,
null);
// add a permission entry for that URI
Services.permissions.add(uri, kType, kCapability);
do_check_true(permission_exists(kTestAddr, kType, kCapability));
Services.permissions.removeAll();
uri = Services.io.newURI("mailto:" + kTestAddr, null, null);
Services.permissions.add(uri, kType, kCapability);
do_check_true(permission_exists(kTestAddr, kType, kCapability));
Services.permissions.removeAll();
}
function permission_exists(aHost, aType, aCapability) {
let e = Services.permissions.enumerator;
while (e.hasMoreElements()) {
let perm = e.getNext().QueryInterface(Ci.nsIPermission);
if (perm.host == aHost &&
perm.type == aType &&
perm.capability == aCapability) {
return true;
}
}
return false;
}

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

@ -27,6 +27,7 @@ skip-if = debug == true
[test_permmanager_idn.js]
[test_permmanager_subdomains.js]
[test_permmanager_local_files.js]
[test_permmanager_mailto.js]
[test_permmanager_cleardata.js]
[test_schema_2_migration.js]
[test_schema_3_migration.js]