mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 876397 - Inter-App Communication API (part 7, refine). r=bent
This commit is contained in:
parent
97675c3d79
commit
b9c6fa24cf
@ -10,8 +10,9 @@ Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/AppsUtils.jsm");
|
||||
|
||||
const DEBUG = false;
|
||||
function debug(aMsg) {
|
||||
// dump("-- InterAppCommService: " + Date.now() + ": " + aMsg + "\n");
|
||||
dump("-- InterAppCommService: " + Date.now() + ": " + aMsg + "\n");
|
||||
}
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "appsService",
|
||||
@ -217,12 +218,14 @@ InterAppCommService.prototype = {
|
||||
let manifestURL = aManifestURI.spec;
|
||||
let pageURL = aHandlerPageURI.spec;
|
||||
|
||||
debug("registerConnection: aKeyword: " + aKeyword +
|
||||
" manifestURL: " + manifestURL + " pageURL: " + pageURL +
|
||||
" aDescription: " + aDescription + " aAppStatus: " + aAppStatus +
|
||||
" aRules.minimumAccessLevel: " + aRules.minimumAccessLevel +
|
||||
" aRules.manifestURLs: " + aRules.manifestURLs +
|
||||
" aRules.installOrigins: " + aRules.installOrigins);
|
||||
if (DEBUG) {
|
||||
debug("registerConnection: aKeyword: " + aKeyword +
|
||||
" manifestURL: " + manifestURL + " pageURL: " + pageURL +
|
||||
" aDescription: " + aDescription + " aAppStatus: " + aAppStatus +
|
||||
" aRules.minimumAccessLevel: " + aRules.minimumAccessLevel +
|
||||
" aRules.manifestURLs: " + aRules.manifestURLs +
|
||||
" aRules.installOrigins: " + aRules.installOrigins);
|
||||
}
|
||||
|
||||
let subAppManifestURLs = this._registeredConnections[aKeyword];
|
||||
if (!subAppManifestURLs) {
|
||||
@ -240,7 +243,9 @@ InterAppCommService.prototype = {
|
||||
|
||||
_matchMinimumAccessLevel: function(aRules, aAppStatus) {
|
||||
if (!aRules || !aRules.minimumAccessLevel) {
|
||||
debug("rules.minimumAccessLevel is not available. No need to match.");
|
||||
if (DEBUG) {
|
||||
debug("rules.minimumAccessLevel is not available. No need to match.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -266,14 +271,19 @@ InterAppCommService.prototype = {
|
||||
break;
|
||||
}
|
||||
|
||||
debug("rules.minimumAccessLevel is not matched! " +
|
||||
"minAccessLevel: " + minAccessLevel + " aAppStatus : " + aAppStatus);
|
||||
if (DEBUG) {
|
||||
debug("rules.minimumAccessLevel is not matched!" +
|
||||
" minAccessLevel: " + minAccessLevel +
|
||||
" aAppStatus : " + aAppStatus);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
_matchManifestURLs: function(aRules, aManifestURL) {
|
||||
if (!aRules || !Array.isArray(aRules.manifestURLs)) {
|
||||
debug("rules.manifestURLs is not available. No need to match.");
|
||||
if (DEBUG) {
|
||||
debug("rules.manifestURLs is not available. No need to match.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -282,14 +292,19 @@ InterAppCommService.prototype = {
|
||||
return true;
|
||||
}
|
||||
|
||||
debug("rules.manifestURLs is not matched! " +
|
||||
"manifestURLs: " + manifestURLs + " aManifestURL : " + aManifestURL);
|
||||
if (DEBUG) {
|
||||
debug("rules.manifestURLs is not matched!" +
|
||||
" manifestURLs: " + manifestURLs +
|
||||
" aManifestURL : " + aManifestURL);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
_matchInstallOrigins: function(aRules, aManifestURL) {
|
||||
if (!aRules || !Array.isArray(aRules.installOrigins)) {
|
||||
debug("rules.installOrigins is not available. No need to match.");
|
||||
if (DEBUG) {
|
||||
debug("rules.installOrigins is not available. No need to match.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -301,8 +316,12 @@ InterAppCommService.prototype = {
|
||||
return true;
|
||||
}
|
||||
|
||||
debug("rules.installOrigins is not matched! aManifestURL: " + aManifestURL +
|
||||
" installOrigins: " + installOrigins + " installOrigin : " + installOrigin);
|
||||
if (DEBUG) {
|
||||
debug("rules.installOrigins is not matched!" +
|
||||
" aManifestURL: " + aManifestURL +
|
||||
" installOrigins: " + installOrigins +
|
||||
" installOrigin : " + installOrigin);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
@ -314,12 +333,16 @@ InterAppCommService.prototype = {
|
||||
// certified apps can match the rules.
|
||||
if (aPubAppStatus != Ci.nsIPrincipal.APP_STATUS_CERTIFIED ||
|
||||
aSubAppStatus != Ci.nsIPrincipal.APP_STATUS_CERTIFIED) {
|
||||
debug("Only certified apps are allowed to do connections.");
|
||||
if (DEBUG) {
|
||||
debug("Only certified apps are allowed to do connections.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!aPubRules && !aSubRules) {
|
||||
debug("Rules of publisher and subscriber are absent. No need to match.");
|
||||
if (DEBUG) {
|
||||
debug("No rules for publisher and subscriber. No need to match.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -344,19 +367,21 @@ InterAppCommService.prototype = {
|
||||
// Check developers.
|
||||
// TODO Do we really want to check this? This one seems naive.
|
||||
|
||||
debug("All rules are matched.");
|
||||
if (DEBUG) debug("All rules are matched.");
|
||||
return true;
|
||||
},
|
||||
|
||||
_dispatchMessagePorts: function(aKeyword, aPubAppManifestURL,
|
||||
aAllowedSubAppManifestURLs,
|
||||
aTarget, aOuterWindowID, aRequestID) {
|
||||
debug("_dispatchMessagePorts: aKeyword: " + aKeyword +
|
||||
" aPubAppManifestURL: " + aPubAppManifestURL +
|
||||
" aAllowedSubAppManifestURLs: " + aAllowedSubAppManifestURLs);
|
||||
if (DEBUG) {
|
||||
debug("_dispatchMessagePorts: aKeyword: " + aKeyword +
|
||||
" aPubAppManifestURL: " + aPubAppManifestURL +
|
||||
" aAllowedSubAppManifestURLs: " + aAllowedSubAppManifestURLs);
|
||||
}
|
||||
|
||||
if (aAllowedSubAppManifestURLs.length == 0) {
|
||||
debug("No apps are allowed to connect. Returning.");
|
||||
if (DEBUG) debug("No apps are allowed to connect. Returning.");
|
||||
aTarget.sendAsyncMessage("Webapps:Connect:Return:KO",
|
||||
{ oid: aOuterWindowID, requestID: aRequestID });
|
||||
return;
|
||||
@ -364,7 +389,7 @@ InterAppCommService.prototype = {
|
||||
|
||||
let subAppManifestURLs = this._registeredConnections[aKeyword];
|
||||
if (!subAppManifestURLs) {
|
||||
debug("No apps are subscribed to connect. Returning.");
|
||||
if (DEBUG) debug("No apps are subscribed to connect. Returning.");
|
||||
aTarget.sendAsyncMessage("Webapps:Connect:Return:KO",
|
||||
{ oid: aOuterWindowID, requestID: aRequestID });
|
||||
return;
|
||||
@ -374,8 +399,10 @@ InterAppCommService.prototype = {
|
||||
aAllowedSubAppManifestURLs.forEach(function(aAllowedSubAppManifestURL) {
|
||||
let subscribedInfo = subAppManifestURLs[aAllowedSubAppManifestURL];
|
||||
if (!subscribedInfo) {
|
||||
debug("The sunscribed info is not available. Skipping: " +
|
||||
aAllowedSubAppManifestURL);
|
||||
if (DEBUG) {
|
||||
debug("The sunscribed info is not available. Skipping: " +
|
||||
aAllowedSubAppManifestURL);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -405,14 +432,14 @@ InterAppCommService.prototype = {
|
||||
}, this);
|
||||
|
||||
if (messagePortIDs.length == 0) {
|
||||
debug("No apps are subscribed to connect. Returning.");
|
||||
if (DEBUG) debug("No apps are subscribed to connect. Returning.");
|
||||
aTarget.sendAsyncMessage("Webapps:Connect:Return:KO",
|
||||
{ oid: aOuterWindowID, requestID: aRequestID });
|
||||
return;
|
||||
}
|
||||
|
||||
// Return the message port IDs to open the message ports for the publisher.
|
||||
debug("messagePortIDs: " + messagePortIDs);
|
||||
if (DEBUG) debug("messagePortIDs: " + messagePortIDs);
|
||||
aTarget.sendAsyncMessage("Webapps:Connect:Return:OK",
|
||||
{ keyword: aKeyword,
|
||||
messagePortIDs: messagePortIDs,
|
||||
@ -429,7 +456,9 @@ InterAppCommService.prototype = {
|
||||
|
||||
let subAppManifestURLs = this._registeredConnections[keyword];
|
||||
if (!subAppManifestURLs) {
|
||||
debug("No apps are subscribed for this connection. Returning.")
|
||||
if (DEBUG) {
|
||||
debug("No apps are subscribed for this connection. Returning.");
|
||||
}
|
||||
this._dispatchMessagePorts(keyword, pubAppManifestURL, [],
|
||||
aTarget, outerWindowID, requestID);
|
||||
return;
|
||||
@ -449,7 +478,9 @@ InterAppCommService.prototype = {
|
||||
let appsToSelect = [];
|
||||
for (let subAppManifestURL in subAppManifestURLs) {
|
||||
if (allowedSubAppManifestURLs.indexOf(subAppManifestURL) != -1) {
|
||||
debug("Don't need to select again. Skipping: " + subAppManifestURL);
|
||||
if (DEBUG) {
|
||||
debug("Don't need to select again. Skipping: " + subAppManifestURL);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -462,7 +493,9 @@ InterAppCommService.prototype = {
|
||||
this._matchRules(pubAppManifestURL, pubAppStatus, pubRules,
|
||||
subAppManifestURL, subAppStatus, subRules);
|
||||
if (!matched) {
|
||||
debug("Rules are not matched. Skipping: " + subAppManifestURL);
|
||||
if (DEBUG) {
|
||||
debug("Rules are not matched. Skipping: " + subAppManifestURL);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -473,8 +506,11 @@ InterAppCommService.prototype = {
|
||||
}
|
||||
|
||||
if (appsToSelect.length == 0) {
|
||||
debug("No additional apps need to be selected for this connection. " +
|
||||
"Just dispatch message ports for the existing connections.");
|
||||
if (DEBUG) {
|
||||
debug("No additional apps need to be selected for this connection. " +
|
||||
"Just dispatch message ports for the existing connections.");
|
||||
}
|
||||
|
||||
this._dispatchMessagePorts(keyword, pubAppManifestURL,
|
||||
allowedSubAppManifestURLs,
|
||||
aTarget, outerWindowID, requestID);
|
||||
@ -497,7 +533,7 @@ InterAppCommService.prototype = {
|
||||
// run-time prompt from observer notification to xpcom-interface caller.
|
||||
//
|
||||
/*
|
||||
debug("appsToSelect: " + appsToSelect);
|
||||
if (DEBUG) debug("appsToSelect: " + appsToSelect);
|
||||
Services.obs.notifyObservers(null, "inter-app-comm-select-app",
|
||||
JSON.stringify({ callerID: callerID,
|
||||
manifestURL: pubAppManifestURL,
|
||||
@ -508,7 +544,7 @@ InterAppCommService.prototype = {
|
||||
// TODO Bug 897169 Simulate the return of the app-selected result by
|
||||
// the prompt, which always allows the connection. This dummy codes
|
||||
// will be removed when the UX/UI for the prompt is ready.
|
||||
debug("appsToSelect: " + appsToSelect);
|
||||
if (DEBUG) debug("appsToSelect: " + appsToSelect);
|
||||
Services.obs.notifyObservers(null, 'inter-app-comm-select-app-result',
|
||||
JSON.stringify({ callerID: callerID,
|
||||
manifestURL: pubAppManifestURL,
|
||||
@ -546,24 +582,24 @@ InterAppCommService.prototype = {
|
||||
|
||||
let allowedPubAppManifestURLs = this._allowedConnections[keyword];
|
||||
if (!allowedPubAppManifestURLs) {
|
||||
debug("keyword is not found: " + keyword);
|
||||
if (DEBUG) debug("keyword is not found: " + keyword);
|
||||
return;
|
||||
}
|
||||
|
||||
let allowedSubAppManifestURLs =
|
||||
allowedPubAppManifestURLs[pubAppManifestURL];
|
||||
if (!allowedSubAppManifestURLs) {
|
||||
debug("publisher is not found: " + pubAppManifestURL);
|
||||
if (DEBUG) debug("publisher is not found: " + pubAppManifestURL);
|
||||
return;
|
||||
}
|
||||
|
||||
let index = allowedSubAppManifestURLs.indexOf(subAppManifestURL);
|
||||
if (index == -1) {
|
||||
debug("subscriber is not found: " + subAppManifestURL);
|
||||
if (DEBUG) debug("subscriber is not found: " + subAppManifestURL);
|
||||
return;
|
||||
}
|
||||
|
||||
debug("Cancelling the connection.");
|
||||
if (DEBUG) debug("Cancelling the connection.");
|
||||
allowedSubAppManifestURLs.splice(index, 1);
|
||||
|
||||
// Clean up the parent entries if needed.
|
||||
@ -574,7 +610,7 @@ InterAppCommService.prototype = {
|
||||
}
|
||||
}
|
||||
|
||||
debug("Unregistering message ports based on this connection.");
|
||||
if (DEBUG) debug("Unregistering message ports based on this connection.");
|
||||
let messagePortIDs = [];
|
||||
for (let messagePortID in this._messagePortPairs) {
|
||||
let pair = this._messagePortPairs[messagePortID];
|
||||
@ -592,8 +628,10 @@ InterAppCommService.prototype = {
|
||||
_identifyMessagePort: function(aMessagePortID, aManifestURL) {
|
||||
let pair = this._messagePortPairs[aMessagePortID];
|
||||
if (!pair) {
|
||||
debug("Error! The message port ID is invalid: " + aMessagePortID +
|
||||
", which should have been generated by parent.");
|
||||
if (DEBUG) {
|
||||
debug("Error! The message port ID is invalid: " + aMessagePortID +
|
||||
", which should have been generated by parent.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -607,8 +645,10 @@ InterAppCommService.prototype = {
|
||||
return { pair: pair, isPublisher: false };
|
||||
}
|
||||
|
||||
debug("Error! The manifest URL is invalid: " + aManifestURL +
|
||||
", which might be a hacked app.");
|
||||
if (DEBUG) {
|
||||
debug("Error! The manifest URL is invalid: " + aManifestURL +
|
||||
", which might be a hacked app.");
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
@ -619,11 +659,13 @@ InterAppCommService.prototype = {
|
||||
|
||||
let identity = this._identifyMessagePort(messagePortID, manifestURL);
|
||||
if (!identity) {
|
||||
debug("Cannot identify the message port. Failed to register.");
|
||||
if (DEBUG) {
|
||||
debug("Cannot identify the message port. Failed to register.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
debug("Registering message port for " + manifestURL);
|
||||
if (DEBUG) debug("Registering message port for " + manifestURL);
|
||||
let pair = identity.pair;
|
||||
let isPublisher = identity.isPublisher;
|
||||
|
||||
@ -633,12 +675,14 @@ InterAppCommService.prototype = {
|
||||
sender.messageQueue = [];
|
||||
|
||||
// Check if the other port has queued messages. Deliver them if needed.
|
||||
debug("Checking if the other port used to send messages but queued.");
|
||||
if (DEBUG) {
|
||||
debug("Checking if the other port used to send messages but queued.");
|
||||
}
|
||||
let receiver = isPublisher ? pair.subscriber : pair.publisher;
|
||||
if (receiver.messageQueue) {
|
||||
while (receiver.messageQueue.length) {
|
||||
let message = receiver.messageQueue.shift();
|
||||
debug("Delivering message: " + JSON.stringify(message));
|
||||
if (DEBUG) debug("Delivering message: " + JSON.stringify(message));
|
||||
sender.target.sendAsyncMessage("InterAppMessagePort:OnMessage",
|
||||
{ message: message,
|
||||
manifestURL: sender.manifestURL,
|
||||
@ -654,21 +698,25 @@ InterAppCommService.prototype = {
|
||||
|
||||
let identity = this._identifyMessagePort(messagePortID, manifestURL);
|
||||
if (!identity) {
|
||||
debug("Cannot identify the message port. Failed to unregister.");
|
||||
if (DEBUG) {
|
||||
debug("Cannot identify the message port. Failed to unregister.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
debug("Unregistering message port for " + manifestURL);
|
||||
if (DEBUG) {
|
||||
debug("Unregistering message port for " + manifestURL);
|
||||
}
|
||||
delete this._messagePortPairs[messagePortID];
|
||||
},
|
||||
|
||||
_removeTarget: function(aTarget) {
|
||||
if (!aTarget) {
|
||||
debug("Error! aTarget cannot be null/undefined in any way.");
|
||||
if (DEBUG) debug("Error! aTarget cannot be null/undefined in any way.");
|
||||
return
|
||||
}
|
||||
|
||||
debug("Unregistering message ports based on this target.");
|
||||
if (DEBUG) debug("Unregistering message ports based on this target.");
|
||||
let messagePortIDs = [];
|
||||
for (let messagePortID in this._messagePortPairs) {
|
||||
let pair = this._messagePortPairs[messagePortID];
|
||||
@ -689,7 +737,7 @@ InterAppCommService.prototype = {
|
||||
|
||||
let identity = this._identifyMessagePort(messagePortID, manifestURL);
|
||||
if (!identity) {
|
||||
debug("Cannot identify the message port. Failed to post.");
|
||||
if (DEBUG) debug("Cannot identify the message port. Failed to post.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -698,13 +746,15 @@ InterAppCommService.prototype = {
|
||||
|
||||
let receiver = isPublisher ? pair.subscriber : pair.publisher;
|
||||
if (!receiver.target) {
|
||||
debug("The receiver's target is not ready yet. Queuing the message.");
|
||||
if (DEBUG) {
|
||||
debug("The receiver's target is not ready yet. Queuing the message.");
|
||||
}
|
||||
let sender = isPublisher ? pair.publisher : pair.subscriber;
|
||||
sender.messageQueue.push(message);
|
||||
return;
|
||||
}
|
||||
|
||||
debug("Delivering message: " + JSON.stringify(message));
|
||||
if (DEBUG) debug("Delivering message: " + JSON.stringify(message));
|
||||
receiver.target.sendAsyncMessage("InterAppMessagePort:OnMessage",
|
||||
{ manifestURL: receiver.manifestURL,
|
||||
pageURL: receiver.pageURL,
|
||||
@ -716,7 +766,7 @@ InterAppCommService.prototype = {
|
||||
let callerID = aData.callerID;
|
||||
let caller = this._promptUICallers[callerID];
|
||||
if (!caller) {
|
||||
debug("Error! Cannot find the caller.");
|
||||
if (DEBUG) debug("Error! Cannot find the caller.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -731,7 +781,7 @@ InterAppCommService.prototype = {
|
||||
let selectedApps = aData.selectedApps;
|
||||
|
||||
if (selectedApps.length == 0) {
|
||||
debug("No apps are selected to connect.")
|
||||
if (DEBUG) debug("No apps are selected to connect.")
|
||||
this._dispatchMessagePorts(keyword, manifestURL, [],
|
||||
target, outerWindowID, requestID);
|
||||
return;
|
||||
@ -762,7 +812,7 @@ InterAppCommService.prototype = {
|
||||
},
|
||||
|
||||
receiveMessage: function(aMessage) {
|
||||
debug("receiveMessage: name: " + aMessage.name);
|
||||
if (DEBUG) debug("receiveMessage: name: " + aMessage.name);
|
||||
let message = aMessage.json;
|
||||
let target = aMessage.target;
|
||||
|
||||
@ -771,7 +821,9 @@ InterAppCommService.prototype = {
|
||||
if (aMessage.name !== "child-process-shutdown" &&
|
||||
kMessages.indexOf(aMessage.name) != -1) {
|
||||
if (!target.assertContainApp(message.manifestURL)) {
|
||||
debug("Got message from a child process carrying illegal manifest URL.");
|
||||
if (DEBUG) {
|
||||
debug("Got message from a process carrying illegal manifest URL.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -812,7 +864,7 @@ InterAppCommService.prototype = {
|
||||
ppmm = null;
|
||||
break;
|
||||
case "inter-app-comm-select-app-result":
|
||||
debug("inter-app-comm-select-app-result: " + aData);
|
||||
if (DEBUG) debug("inter-app-comm-select-app-result: " + aData);
|
||||
this._handleSelectcedApps(JSON.parse(aData));
|
||||
break;
|
||||
}
|
||||
|
@ -18,8 +18,9 @@ XPCOMUtils.defineLazyServiceGetter(this, "appsService",
|
||||
"@mozilla.org/AppsService;1",
|
||||
"nsIAppsService");
|
||||
|
||||
const DEBUG = false;
|
||||
function debug(aMsg) {
|
||||
// dump("-- InterAppConnection: " + Date.now() + ": " + aMsg + "\n");
|
||||
dump("-- InterAppConnection: " + Date.now() + ": " + aMsg + "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -27,7 +28,7 @@ function debug(aMsg) {
|
||||
*/
|
||||
|
||||
function InterAppConnection() {
|
||||
debug("InterAppConnection()");
|
||||
if (DEBUG) debug("InterAppConnection()");
|
||||
this.keyword = null;
|
||||
this.publisher = null;
|
||||
this.subscriber = null;
|
||||
@ -46,8 +47,10 @@ InterAppConnection.prototype = {
|
||||
Ci.nsISupportsWeakReference]),
|
||||
|
||||
__init: function(aKeyword, aPublisher, aSubscriber) {
|
||||
debug("__init: aKeyword: " + aKeyword +
|
||||
" aPublisher: " + aPublisher + " aSubscriber: " + aSubscriber);
|
||||
if (DEBUG) {
|
||||
debug("__init: aKeyword: " + aKeyword +
|
||||
" aPublisher: " + aPublisher + " aSubscriber: " + aSubscriber);
|
||||
}
|
||||
this.keyword = aKeyword;
|
||||
this.publisher = aPublisher;
|
||||
this.subscriber = aSubscriber;
|
||||
@ -55,7 +58,7 @@ InterAppConnection.prototype = {
|
||||
|
||||
// Ci.nsIDOMGlobalPropertyInitializer implementation.
|
||||
init: function(aWindow) {
|
||||
debug("init");
|
||||
if (DEBUG) debug("init");
|
||||
|
||||
this.initDOMRequestHelper(aWindow, []);
|
||||
let principal = aWindow.document.nodePrincipal;
|
||||
@ -63,7 +66,7 @@ InterAppConnection.prototype = {
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
debug("cancel");
|
||||
if (DEBUG) debug("cancel");
|
||||
|
||||
cpmm.sendAsyncMessage("InterAppConnection:Cancel",
|
||||
{ keyword: this.keyword,
|
||||
@ -79,7 +82,7 @@ InterAppConnection.prototype = {
|
||||
*/
|
||||
|
||||
function InterAppConnectionRequest() {
|
||||
debug("InterAppConnectionRequest()");
|
||||
if (DEBUG) debug("InterAppConnectionRequest()");
|
||||
this.keyword = null;
|
||||
this.port = null;
|
||||
};
|
||||
@ -94,7 +97,7 @@ InterAppConnectionRequest.prototype = {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]),
|
||||
|
||||
__init: function(aKeyword, aPort) {
|
||||
debug("__init: aKeyword: " + aKeyword + " aPort: " + aPort);
|
||||
if (DEBUG) debug("__init: aKeyword: " + aKeyword + " aPort: " + aPort);
|
||||
this.keyword = aKeyword;
|
||||
this.port = aPort;
|
||||
}
|
||||
@ -110,13 +113,13 @@ InterAppConnectionRequest.prototype = {
|
||||
*/
|
||||
|
||||
function InterAppConnectionRequestWrapper() {
|
||||
debug("InterAppConnectionRequestWrapper()");
|
||||
if (DEBUG) debug("InterAppConnectionRequestWrapper()");
|
||||
}
|
||||
|
||||
InterAppConnectionRequestWrapper.prototype = {
|
||||
// nsISystemMessagesWrapper implementation.
|
||||
wrapMessage: function(aMessage, aWindow) {
|
||||
debug("wrapMessage: " + JSON.stringify(aMessage));
|
||||
if (DEBUG) debug("wrapMessage: " + JSON.stringify(aMessage));
|
||||
|
||||
let port = new aWindow.MozInterAppMessagePort(aMessage.keyword,
|
||||
aMessage.messagePortID, false);
|
||||
|
@ -18,8 +18,9 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
|
||||
Cu.import("resource://gre/modules/ObjectWrapper.jsm");
|
||||
|
||||
const DEBUG = false;
|
||||
function debug(aMsg) {
|
||||
// dump("-- InterAppMessagePort: " + Date.now() + ": " + aMsg + "\n");
|
||||
dump("-- InterAppMessagePort: " + Date.now() + ": " + aMsg + "\n");
|
||||
}
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
||||
@ -56,7 +57,7 @@ InterAppMessageEvent.prototype = {
|
||||
|
||||
|
||||
function InterAppMessagePort() {
|
||||
debug("InterAppMessagePort()");
|
||||
if (DEBUG) debug("InterAppMessagePort()");
|
||||
};
|
||||
|
||||
InterAppMessagePort.prototype = {
|
||||
@ -73,7 +74,7 @@ InterAppMessagePort.prototype = {
|
||||
|
||||
// Ci.nsIDOMGlobalPropertyInitializer implementation.
|
||||
init: function(aWindow) {
|
||||
debug("Calling init().");
|
||||
if (DEBUG) debug("Calling init().");
|
||||
|
||||
this.initDOMRequestHelper(aWindow, kMessages);
|
||||
|
||||
@ -87,14 +88,14 @@ InterAppMessagePort.prototype = {
|
||||
},
|
||||
|
||||
// WebIDL implementation for constructor.
|
||||
__init: function(aKeyword, aMessagePortID, aIsPublisher) {
|
||||
debug("Calling __init(): aKeyword: " + aKeyword +
|
||||
" aMessagePortID: " + aMessagePortID +
|
||||
" aIsPublisher: " + aIsPublisher);
|
||||
__init: function(aKeyword, aMessagePortID) {
|
||||
if (DEBUG) {
|
||||
debug("Calling __init(): aKeyword: " + aKeyword +
|
||||
" aMessagePortID: " + aMessagePortID);
|
||||
}
|
||||
|
||||
this._keyword = aKeyword;
|
||||
this._messagePortID = aMessagePortID;
|
||||
this._isPublisher = aIsPublisher;
|
||||
|
||||
cpmm.sendAsyncMessage("InterAppMessagePort:Register",
|
||||
{ messagePortID: this._messagePortID,
|
||||
@ -104,12 +105,12 @@ InterAppMessagePort.prototype = {
|
||||
|
||||
// DOMRequestIpcHelper implementation.
|
||||
uninit: function() {
|
||||
debug("Calling uninit().");
|
||||
if (DEBUG) debug("Calling uninit().");
|
||||
|
||||
// When the message port is uninitialized, we need to disentangle the
|
||||
// coupling ports, as if the close() method had been called.
|
||||
if (this._closed) {
|
||||
debug("close() has been called. Don't need to close again.");
|
||||
if (DEBUG) debug("close() has been called. Don't need to close again.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -117,10 +118,10 @@ InterAppMessagePort.prototype = {
|
||||
},
|
||||
|
||||
postMessage: function(aMessage) {
|
||||
debug("Calling postMessage().");
|
||||
if (DEBUG) debug("Calling postMessage().");
|
||||
|
||||
if (this._closed) {
|
||||
debug("close() has been called. Cannot post message.");
|
||||
if (DEBUG) debug("close() has been called. Cannot post message.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -132,15 +133,15 @@ InterAppMessagePort.prototype = {
|
||||
|
||||
start: function() {
|
||||
// Begin dispatching messages received on the port.
|
||||
debug("Calling start().");
|
||||
if (DEBUG) debug("Calling start().");
|
||||
|
||||
if (this._closed) {
|
||||
debug("close() has been called. Cannot call start().");
|
||||
if (DEBUG) debug("close() has been called. Cannot call start().");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._started) {
|
||||
debug("start() has been called. Don't need to start again.");
|
||||
if (DEBUG) debug("start() has been called. Don't need to start again.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -155,10 +156,10 @@ InterAppMessagePort.prototype = {
|
||||
|
||||
close: function() {
|
||||
// Disconnecting the port, so that it is no longer active.
|
||||
debug("Calling close().");
|
||||
if (DEBUG) debug("Calling close().");
|
||||
|
||||
if (this._closed) {
|
||||
debug("close() has been called. Don't need to close again.");
|
||||
if (DEBUG) debug("close() has been called. Don't need to close again.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -173,13 +174,13 @@ InterAppMessagePort.prototype = {
|
||||
},
|
||||
|
||||
get onmessage() {
|
||||
debug("Getting onmessage handler.");
|
||||
if (DEBUG) debug("Getting onmessage handler.");
|
||||
|
||||
return this.__DOM_IMPL__.getEventHandler("onmessage");
|
||||
},
|
||||
|
||||
set onmessage(aHandler) {
|
||||
debug("Setting onmessage handler.");
|
||||
if (DEBUG) debug("Setting onmessage handler.");
|
||||
|
||||
this.__DOM_IMPL__.setEventHandler("onmessage", aHandler);
|
||||
|
||||
@ -187,7 +188,7 @@ InterAppMessagePort.prototype = {
|
||||
// the port's message queue must be enabled, as if the start() method had
|
||||
// been called.
|
||||
if (this._started) {
|
||||
debug("start() has been called. Don't need to start again.");
|
||||
if (DEBUG) debug("start() has been called. Don't need to start again.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -196,7 +197,10 @@ InterAppMessagePort.prototype = {
|
||||
|
||||
_dispatchMessage: function _dispatchMessage(aMessage) {
|
||||
let wrappedMessage = ObjectWrapper.wrap(aMessage, this._window);
|
||||
debug("_dispatchMessage: wrappedMessage: " + JSON.stringify(wrappedMessage));
|
||||
if (DEBUG) {
|
||||
debug("_dispatchMessage: wrappedMessage: " +
|
||||
JSON.stringify(wrappedMessage));
|
||||
}
|
||||
|
||||
let event = new this._window
|
||||
.MozInterAppMessageEvent("message",
|
||||
@ -205,25 +209,25 @@ InterAppMessagePort.prototype = {
|
||||
},
|
||||
|
||||
receiveMessage: function(aMessage) {
|
||||
debug("receiveMessage: name: " + aMessage.name);
|
||||
if (DEBUG) debug("receiveMessage: name: " + aMessage.name);
|
||||
|
||||
let message = aMessage.json;
|
||||
if (message.manifestURL != this._manifestURL ||
|
||||
message.pageURL != this._pageURL ||
|
||||
message.messagePortID != this._messagePortID) {
|
||||
debug("The message doesn't belong to this page. Returning.");
|
||||
if (DEBUG) debug("The message doesn't belong to this page. Returning.");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (aMessage.name) {
|
||||
case "InterAppMessagePort:OnMessage":
|
||||
if (this._closed) {
|
||||
debug("close() has been called. Drop the message.");
|
||||
if (DEBUG) debug("close() has been called. Drop the message.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this._started) {
|
||||
debug("Not yet called start(). Queue up the message.");
|
||||
if (DEBUG) debug("Not yet called start(). Queue up the message.");
|
||||
this._messageQueue.push(message.message);
|
||||
return;
|
||||
}
|
||||
@ -232,7 +236,7 @@ InterAppMessagePort.prototype = {
|
||||
break;
|
||||
|
||||
default:
|
||||
debug("Error! Shouldn't fall into this case.");
|
||||
if (DEBUG) debug("Error! Shouldn't fall into this case.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
[HeaderFile="mozilla/dom/InterAppComm.h",
|
||||
Func="mozilla::dom::InterAppComm::EnabledForScope",
|
||||
Constructor(DOMString keyword, DOMString messagePortID, boolean isPublisher),
|
||||
Constructor(DOMString keyword, DOMString messagePortID),
|
||||
JSImplementation="@mozilla.org/dom/inter-app-message-port;1"]
|
||||
interface MozInterAppMessagePort : EventTarget {
|
||||
void postMessage(any message);
|
||||
|
Loading…
Reference in New Issue
Block a user