Merge b2g-inbound to m-c a=merge

This commit is contained in:
Wes Kocher 2014-10-20 18:14:19 -07:00
Родитель bc6781c19d 4837874d57
Коммит d09bbdb8a9
3 изменённых файлов: 190 добавлений и 28 удалений

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

@ -248,6 +248,7 @@ ContactManager.prototype = {
let type = "contacts-" + access; let type = "contacts-" + access;
let permValue = let permValue =
Services.perms.testExactPermissionFromPrincipal(principal, type); Services.perms.testExactPermissionFromPrincipal(principal, type);
DEBUG && debug("Existing permission " + permValue);
if (permValue == Ci.nsIPermissionManager.ALLOW_ACTION) { if (permValue == Ci.nsIPermissionManager.ALLOW_ACTION) {
if (aAllowCallback) { if (aAllowCallback) {
aAllowCallback(); aAllowCallback();
@ -256,7 +257,7 @@ ContactManager.prototype = {
} else if (permValue == Ci.nsIPermissionManager.DENY_ACTION || } else if (permValue == Ci.nsIPermissionManager.DENY_ACTION ||
permValue == Ci.nsIPermissionManager.UNKNOWN_ACTION) { permValue == Ci.nsIPermissionManager.UNKNOWN_ACTION) {
if (aCancelCallback) { if (aCancelCallback) {
aCancelCallback(); aCancelCallback("PERMISSION_DENIED");
} }
return; return;
} }
@ -276,15 +277,13 @@ ContactManager.prototype = {
types: typeArray, types: typeArray,
principal: principal, principal: principal,
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionRequest]), QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionRequest]),
allow: aAllowCallback || allow: function() {
function() { aAllowCallback && aAllowCallback();
if (DEBUG) DEBUG && debug("Permission granted. Access " + access +"\n");
debug("Default allow contacts callback. " + access +"\n");
}, },
cancel: aCancelCallback || cancel: function() {
function() { aCancelCallback && aCancelCallback("PERMISSION_DENIED");
if (DEBUG) DEBUG && debug("Permission denied. Access " + access +"\n");
debug("Default cancel contacts callback. " + access +"\n");
}, },
window: this._window window: this._window
}; };
@ -336,9 +335,17 @@ ContactManager.prototype = {
let options = { contact: newContact, reason: reason }; let options = { contact: newContact, reason: reason };
let allowCallback = function() { let allowCallback = function() {
cpmm.sendAsyncMessage("Contact:Save", {requestID: requestID, options: options}); cpmm.sendAsyncMessage("Contact:Save", {
}.bind(this) requestID: requestID,
this.askPermission(reason, request, allowCallback); options: options
});
}.bind(this);
let cancelCallback = function(reason) {
Services.DOMRequest.fireErrorAsync(request, reason);
};
this.askPermission(reason, request, allowCallback, cancelCallback);
return request; return request;
}, },
@ -346,10 +353,19 @@ ContactManager.prototype = {
if (DEBUG) debug("find! " + JSON.stringify(aOptions)); if (DEBUG) debug("find! " + JSON.stringify(aOptions));
let request = this.createRequest(); let request = this.createRequest();
let options = { findOptions: aOptions }; let options = { findOptions: aOptions };
let allowCallback = function() { let allowCallback = function() {
cpmm.sendAsyncMessage("Contacts:Find", {requestID: this.getRequestId({request: request, reason: "find"}), options: options}); cpmm.sendAsyncMessage("Contacts:Find", {
}.bind(this) requestID: this.getRequestId({request: request, reason: "find"}),
this.askPermission("find", request, allowCallback); options: options
});
}.bind(this);
let cancelCallback = function(reason) {
Services.DOMRequest.fireErrorAsync(request, reason);
};
this.askPermission("find", request, allowCallback, cancelCallback);
return request; return request;
}, },
@ -369,11 +385,19 @@ ContactManager.prototype = {
getAll: function CM_getAll(aOptions) { getAll: function CM_getAll(aOptions) {
if (DEBUG) debug("getAll: " + JSON.stringify(aOptions)); if (DEBUG) debug("getAll: " + JSON.stringify(aOptions));
let [cursorId, cursor] = this.createCursor(); let [cursorId, cursor] = this.createCursor();
let allowCallback = function() { let allowCallback = function() {
cpmm.sendAsyncMessage("Contacts:GetAll", { cpmm.sendAsyncMessage("Contacts:GetAll", {
cursorId: cursorId, findOptions: aOptions}); cursorId: cursorId,
findOptions: aOptions
});
}.bind(this); }.bind(this);
this.askPermission("find", cursor, allowCallback);
let cancelCallback = function(reason) {
Services.DOMRequest.fireErrorAsync(cursor, reason);
};
this.askPermission("find", cursor, allowCallback, cancelCallback);
return cursor; return cursor;
}, },
@ -412,10 +436,19 @@ ContactManager.prototype = {
} }
let options = { id: id }; let options = { id: id };
let allowCallback = function() { let allowCallback = function() {
cpmm.sendAsyncMessage("Contact:Remove", {requestID: this.getRequestId({request: request, reason: "remove"}), options: options}); cpmm.sendAsyncMessage("Contact:Remove", {
requestID: this.getRequestId({request: request, reason: "remove"}),
options: options
});
}.bind(this); }.bind(this);
this.askPermission("remove", request, allowCallback);
let cancelCallback = function(reason) {
Services.DOMRequest.fireErrorAsync(request, reason);
};
this.askPermission("remove", request, allowCallback, cancelCallback);
return request; return request;
}, },
@ -423,10 +456,19 @@ ContactManager.prototype = {
if (DEBUG) debug("clear"); if (DEBUG) debug("clear");
let request = this.createRequest(); let request = this.createRequest();
let options = {}; let options = {};
let allowCallback = function() { let allowCallback = function() {
cpmm.sendAsyncMessage("Contacts:Clear", {requestID: this.getRequestId({request: request, reason: "remove"}), options: options}); cpmm.sendAsyncMessage("Contacts:Clear", {
requestID: this.getRequestId({request: request, reason: "remove"}),
options: options
});
}.bind(this); }.bind(this);
this.askPermission("remove", request, allowCallback);
let cancelCallback = function(reason) {
Services.DOMRequest.fireErrorAsync(request, reason);
};
this.askPermission("remove", request, allowCallback, cancelCallback);
return request; return request;
}, },
@ -439,8 +481,8 @@ ContactManager.prototype = {
}); });
}.bind(this); }.bind(this);
let cancelCallback = function() { let cancelCallback = function(reason) {
Services.DOMRequest.fireError(request, ""); Services.DOMRequest.fireErrorAsync(request, reason);
}; };
this.askPermission("revision", request, allowCallback, cancelCallback); this.askPermission("revision", request, allowCallback, cancelCallback);
@ -456,8 +498,8 @@ ContactManager.prototype = {
}); });
}.bind(this); }.bind(this);
let cancelCallback = function() { let cancelCallback = function(reason) {
Services.DOMRequest.fireError(request, ""); Services.DOMRequest.fireErrorAsync(request, reason);
}; };
this.askPermission("count", request, allowCallback, cancelCallback); this.askPermission("count", request, allowCallback, cancelCallback);

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

@ -21,4 +21,4 @@ skip-if = (toolkit == 'gonk' && debug) #debug-only failure
support-files = support-files =
test_migration_chrome.js test_migration_chrome.js
skip-if = os == "android" skip-if = os == "android"
[test_permission_denied.html]

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

@ -0,0 +1,120 @@
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1081873
-->
<head>
<title>Test for Bug 1081873</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1081873">Mozilla Bug 1081873</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
"use strict";
SpecialPowers.addPermission("contacts-write", false, document);
SpecialPowers.addPermission("contacts-read", false, document);
SpecialPowers.addPermission("contacts-create", false, document);
function onUnexpectedSuccess() {
ok(false, "Unexpected success");
next();
}
function onExpectedError(event) {
is(event.target.error.name, PERMISSION_DENIED, "Expected PERMISSION_DENIED");
next();
}
const PERMISSION_DENIED = "PERMISSION_DENIED";
var index = 0;
function next() {
info("Step " + index);
if (index >= steps.length) {
ok(false, "Shouldn't get here!");
return;
}
try {
var i = index++;
steps[i]();
} catch(ex) {
ok(false, "Caught exception", ex);
}
}
var steps = [
function() {
ok(true, "Add contact without permission");
var req = navigator.mozContacts.save(new mozContact({}));
req.onsuccess = onUnexpectedSuccess;
req.onerror = onExpectedError;
},
function() {
ok(true, "Find contact without permission");
var req = navigator.mozContacts.find({});
req.onsuccess = onUnexpectedSuccess;
req.onerror = onExpectedError;
},
function() {
ok(true, "Get all contacts without permission");
var req = navigator.mozContacts.getAll();
req.onsuccess = onUnexpectedSuccess;
req.onerror = onExpectedError;
},
function() {
ok(true, "Remove contact without permission");
var req = navigator.mozContacts.remove("aId");
req.onsuccess = onUnexpectedSuccess;
req.onerror = onExpectedError;
},
function() {
ok(true, "Clear contacts without permission");
var req = navigator.mozContacts.clear();
req.onsuccess = onUnexpectedSuccess;
req.onerror = onExpectedError;
},
function() {
ok(true, "Get revision without permission");
var req = navigator.mozContacts.getRevision();
req.onsuccess = onUnexpectedSuccess;
req.onerror = onExpectedError;
},
function() {
ok(true, "Get count without permission");
var req = navigator.mozContacts.getCount();
req.onsuccess = onUnexpectedSuccess;
req.onerror = function() {
is(req.error.name, PERMISSION_DENIED, "Expected PERMISSION_DENIED");
SimpleTest.finish();
};
}
];
SimpleTest.waitForExplicitFinish();
const DENY = SpecialPowers.Ci.nsIPermissionManager.DENY_ACTION;
var interval = setInterval(function() {
if (!SpecialPowers.testPermission("contacts-read", DENY, document) ||
!SpecialPowers.testPermission("contacts-write", DENY, document) ||
!SpecialPowers.testPermission("contacts-create", DENY, document)) {
return;
}
clearInterval(interval);
next();
}, 1000);
</script>
</pre>
</body>
</html>