Bug 1217712 - Part 1 - reject session request to packaged app with no "presentation" permission. r=seanlin.

This commit is contained in:
Shih-Chiang Chien 2015-10-23 09:32:29 +08:00
parent 82b187fea0
commit b74566e061
3 changed files with 64 additions and 22 deletions

View File

@ -30,19 +30,34 @@ function PresentationRequestUIGlue() {
SystemAppProxy.addEventListener("mozPresentationContentEvent", aEvent => {
let detail = aEvent.detail;
if (detail.type != "presentation-receiver-launched") {
return;
}
switch (detail.type) {
case "presentation-receiver-launched": {
let sessionId = detail.id;
let resolver = this._resolvers[sessionId];
if (!resolver) {
debug("No correspondent resolver for session ID: " + sessionId);
return;
}
let sessionId = detail.id;
let resolver = this._resolvers[sessionId];
if (!resolver) {
debug("No correspondent resolver for session ID: " + sessionId);
return;
}
delete this._resolvers[sessionId];
resolver.resolve(detail.frame);
break;
}
case "presentation-receiver-permission-denied": {
let sessionId = detail.id;
let resolver = this._resolvers[sessionId];
if (!resolver) {
debug("No correspondent resolver for session ID: " + sessionId);
return;
}
delete this._resolvers[sessionId];
resolver(detail.frame);
delete this._resolvers[sessionId];
resolver.reject();
break;
}
default:
return;
}
});
}
@ -50,7 +65,10 @@ PresentationRequestUIGlue.prototype = {
sendRequest: function(aUrl, aSessionId) {
return new Promise(function(aResolve, aReject) {
this._resolvers[aSessionId] = aResolve;
this._resolvers[aSessionId] = {
resolve: aResolve,
reject: aReject,
};
SystemAppProxy._sendCustomEvent("mozPresentationChromeEvent",
{ type: "presentation-launch-receiver",

View File

@ -20,16 +20,13 @@ SystemAppProxy.addEventListener('mozPresentationChromeEvent', function(aEvent) {
addMessageListener('trigger-ui-glue', function(aData) {
var promise = glue.sendRequest(aData.url, aData.sessionId);
promise.then(function(aFrame){
promise.then(function(aFrame) {
sendAsyncMessage('iframe-resolved', aFrame);
}).catch(function() {
sendAsyncMessage('iframe-rejected');
});
});
addMessageListener('trigger-presentation-content-event', function(aData) {
var detail = {
type: 'presentation-receiver-launched',
id: aData.sessionId,
frame: aData.frame
};
SystemAppProxy._sendCustomEvent('mozPresentationContentEvent', detail);
addMessageListener('trigger-presentation-content-event', function(aDetail) {
SystemAppProxy._sendCustomEvent('mozPresentationContentEvent', aDetail);
});

View File

@ -4,7 +4,7 @@
- http://creativecommons.org/publicdomain/zero/1.0/ -->
<head>
<meta charset="utf-8">
<title>Test for Presentation Device Selection</title>
<title>Test for Presentation UI Glue</title>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
@ -57,14 +57,41 @@ function testReceiverLaunched() {
document.body.appendChild(iframe);
gScript.sendAsyncMessage('trigger-presentation-content-event',
{ sessionId : sessionId,
{ type: 'presentation-receiver-launched',
id: sessionId,
frame: iframe });
});
}
function testLaunchError() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('presentation-launch-receiver', function launchReceiverHandler(aDetail) {
gScript.removeMessageListener('presentation-launch-receiver', launchReceiverHandler);
ok(true, "A presentation-launch-receiver mozPresentationChromeEvent should be received.");
is(aDetail.url, url, "Url should be the same.");
is(aDetail.id, sessionId, "Session ID should be the same.");
gScript.addMessageListener('iframe-rejected', function iframeRejectedHandler() {
gScript.removeMessageListener('iframe-rejected', iframeRejectedHandler);
ok(true, "The promise should be rejected.");
aResolve();
});
gScript.sendAsyncMessage('trigger-presentation-content-event',
{ type: 'presentation-receiver-permission-denied',
id: sessionId });
});
gScript.sendAsyncMessage('trigger-ui-glue',
{ url: url,
sessionId : sessionId });
});
}
function runTests() {
testLaunchReceiver()
.then(testReceiverLaunched)
.then(testLaunchError)
.then(function() {
info('test finished, teardown');
gScript.destroy();