Bug 1173666 - Expose the URL of the page that calls mozApps.connect to the app exposing the port. r=ferjm, r=baku

This commit is contained in:
Carmen Jimenez 2015-07-05 08:45:00 -04:00
parent 9faabadda5
commit d686c71044
4 changed files with 28 additions and 11 deletions

View File

@ -393,11 +393,13 @@ this.InterAppCommService = {
_dispatchMessagePorts: function(aKeyword, aPubAppManifestURL,
aAllowedSubAppManifestURLs,
aTarget, aOuterWindowID, aRequestID) {
aTarget, aOuterWindowID, aRequestID,
aPubPageURL) {
if (DEBUG) {
debug("_dispatchMessagePorts: aKeyword: " + aKeyword +
" aPubAppManifestURL: " + aPubAppManifestURL +
" aAllowedSubAppManifestURLs: " + aAllowedSubAppManifestURLs);
" aAllowedSubAppManifestURLs: " + aAllowedSubAppManifestURLs +
" aPubPageURL: " + aPubPageURL);
}
if (aAllowedSubAppManifestURLs.length == 0) {
@ -444,7 +446,8 @@ this.InterAppCommService = {
// Fire system message to deliver the message port to the subscriber.
messenger.sendMessage("connection",
{ keyword: aKeyword,
messagePortID: messagePortID },
messagePortID: messagePortID,
pubPageURL: aPubPageURL},
Services.io.newURI(subscribedInfo.pageURL, null, null),
Services.io.newURI(subscribedInfo.manifestURL, null, null));
@ -530,6 +533,7 @@ this.InterAppCommService = {
_connect: function(aMessage, aTarget) {
let keyword = aMessage.keyword;
let pubRules = aMessage.rules;
let pubPageURL = aMessage.pubPageURL;
let pubAppManifestURL = aMessage.manifestURL;
let outerWindowID = aMessage.outerWindowID;
let requestID = aMessage.requestID;
@ -540,7 +544,7 @@ this.InterAppCommService = {
debug("No apps are subscribed for this connection. Returning.");
}
this._dispatchMessagePorts(keyword, pubAppManifestURL, [],
aTarget, outerWindowID, requestID);
aTarget, outerWindowID, requestID, pubPageURL);
return;
}
@ -588,7 +592,7 @@ this.InterAppCommService = {
this._dispatchMessagePorts(keyword, pubAppManifestURL,
allowedSubAppManifestURLs,
aTarget, outerWindowID, requestID);
aTarget, outerWindowID, requestID, pubPageURL);
return;
}
@ -606,17 +610,19 @@ this.InterAppCommService = {
if (glue) {
glue.selectApps(callerID, pubAppManifestURL, keyword, appsToSelect).then(
function(aData) {
aData.pubPageURL = pubPageURL;
this._handleSelectedApps(aData);
}.bind(this),
function(aError) {
if (DEBUG) {
debug("Error occurred in the UI glue component. " + aError)
debug("Error occurred in the UI glue component. " + aError);
}
// Resolve the caller as if there were no selected apps.
this._handleSelectedApps({ callerID: callerID,
keyword: keyword,
manifestURL: pubAppManifestURL,
pubPageURL: pubPageURL,
selectedApps: [] });
}.bind(this)
);
@ -629,6 +635,7 @@ this.InterAppCommService = {
this._handleSelectedApps({ callerID: callerID,
keyword: keyword,
manifestURL: pubAppManifestURL,
pubPageURL: pubPageURL,
selectedApps: [] });
}
},
@ -865,6 +872,7 @@ this.InterAppCommService = {
let target = caller.target;
let pubAppManifestURL = aData.manifestURL;
let pubPageURL = aData.pubPageURL;
let keyword = aData.keyword;
let selectedApps = aData.selectedApps;
@ -889,7 +897,7 @@ this.InterAppCommService = {
// including the old connections and the newly selected connection.
this._dispatchMessagePorts(keyword, pubAppManifestURL,
allowedSubAppManifestURLs,
target, outerWindowID, requestID);
target, outerWindowID, requestID, pubPageURL);
},
receiveMessage: function(aMessage) {

View File

@ -86,6 +86,7 @@ function InterAppConnectionRequest() {
if (DEBUG) debug("InterAppConnectionRequest()");
this.keyword = null;
this.port = null;
this.from = null;
};
InterAppConnectionRequest.prototype = {
@ -97,10 +98,12 @@ InterAppConnectionRequest.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]),
__init: function(aKeyword, aPort) {
if (DEBUG) debug("__init: aKeyword: " + aKeyword + " aPort: " + aPort);
__init: function(aKeyword, aPort, aFrom) {
if (DEBUG) debug("__init: aKeyword: " + aKeyword + " aPort: " + aPort +
" aFrom: " + aFrom);
this.keyword = aKeyword;
this.port = aPort;
this.from = aFrom;
}
};
@ -124,7 +127,8 @@ InterAppConnectionRequestWrapper.prototype = {
let port = new aWindow.MozInterAppMessagePort(aMessage.messagePortID);
let connectionRequest =
new aWindow.MozInterAppConnectionRequest(aMessage.keyword, port);
new aWindow.MozInterAppConnectionRequest(aMessage.keyword, port,
aMessage.pubPageURL);
return connectionRequest;
},

View File

@ -610,10 +610,12 @@ WebappsApplication.prototype = {
this.addMessageListeners(["Webapps:Connect:Return:OK",
"Webapps:Connect:Return:KO"]);
return this.createPromise(function (aResolve, aReject) {
let from = this._window.location.origin + this._window.location.pathname;
cpmm.sendAsyncMessage("Webapps:Connect", {
keyword: aKeyword,
rules: aRules,
manifestURL: this.manifestURL,
pubPageURL: from,
outerWindowID: this._id,
topWindowID: this._topId,
requestID: this.getPromiseResolverId({

View File

@ -4,10 +4,13 @@
[HeaderFile="mozilla/dom/InterAppComm.h",
Func="mozilla::dom::InterAppComm::EnabledForScope",
Constructor(DOMString keyword, MozInterAppMessagePort port),
Constructor(DOMString keyword, MozInterAppMessagePort port,
DOMString from),
JSImplementation="@mozilla.org/dom/inter-app-connection-request;1"]
interface MozInterAppConnectionRequest {
readonly attribute DOMString keyword;
readonly attribute MozInterAppMessagePort port;
readonly attribute DOMString from;
};