Skip to content

Instantly share code, notes, and snippets.

@alivedise
Created July 17, 2013 06:15
Show Gist options
  • Select an option

  • Save alivedise/6018061 to your computer and use it in GitHub Desktop.

Select an option

Save alivedise/6018061 to your computer and use it in GitHub Desktop.
Patch for 887650
# HG changeset patch
# Parent 82fafd8ee40fac3255f81cf1ae2d5c72cf75deb7
# User Alive Kuo <alive@mozilla.com>
diff --git a/b2g/chrome/content/shell.js b/b2g/chrome/content/shell.js
--- a/b2g/chrome/content/shell.js
+++ b/b2g/chrome/content/shell.js
@@ -564,17 +564,18 @@
openAppForSystemMessage: function shell_openAppForSystemMessage(msg) {
let origin = Services.io.newURI(msg.manifest, null, null).prePath;
this.sendChromeEvent({
type: 'open-app',
url: msg.uri,
manifestURL: msg.manifest,
isActivity: (msg.type == 'activity'),
target: msg.target,
- expectingSystemMessage: true
+ expectingSystemMessage: true,
+ extra: msg.extra
});
},
receiveMessage: function shell_receiveMessage(message) {
var activities = { 'content-handler': { name: 'view', response: null },
'dial-handler': { name: 'dial', response: null },
'mail-handler': { name: 'new', response: null },
'sms-handler': { name: 'new', response: null },
diff --git a/dom/activities/src/ActivitiesService.jsm b/dom/activities/src/ActivitiesService.jsm
--- a/dom/activities/src/ActivitiesService.jsm
+++ b/dom/activities/src/ActivitiesService.jsm
@@ -232,17 +232,21 @@
debug("Sending system message...");
let result = aResults.options[aChoice];
sysmm.sendMessage("activity", {
"id": aMsg.id,
"payload": aMsg.options,
"target": result.description
},
Services.io.newURI(result.description.href, null, null),
- Services.io.newURI(result.manifest, null, null));
+ Services.io.newURI(result.manifest, null, null),
+ {
+ "manifestURL": Activities.callers[aMsg.id].manifestURL,
+ "pageURL": Activities.callers[aMsg.id].pageURL
+ });
if (!result.description.returnValue) {
Activities.callers[aMsg.id].mm.sendAsyncMessage("Activity:FireSuccess", {
"id": aMsg.id,
"result": null
});
// No need to notify observers, since we don't want the caller
// to be raised on the foreground that quick.
diff --git a/dom/messages/SystemMessageInternal.js b/dom/messages/SystemMessageInternal.js
--- a/dom/messages/SystemMessageInternal.js
+++ b/dom/messages/SystemMessageInternal.js
@@ -139,39 +139,41 @@
if (this._isPageMatched(aPage, aType, aPageURL, aManifestURL)) {
page = aPage;
}
return page !== null;
}, this);
return page;
},
- sendMessage: function sendMessage(aType, aMessage, aPageURI, aManifestURI) {
+ sendMessage: function sendMessage(aType, aMessage, aPageURI, aManifestURI, aExtra) {
// Buffer system messages until the webapps' registration is ready,
// so that we can know the correct pages registered to be sent.
if (!this._webappsRegistryReady) {
this._bufferedSysMsgs.push({ how: "send",
type: aType,
msg: aMessage,
pageURI: aPageURI,
+ extra: aExtra,
manifestURI: aManifestURI });
return;
}
// Give this message an ID so that we can identify the message and
// clean it up from the pending message queue when apps receive it.
let messageID = gUUIDGenerator.generateUUID().toString();
debug("Sending " + aType + " " + JSON.stringify(aMessage) +
" for " + aPageURI.spec + " @ " + aManifestURI.spec);
let result = this._sendMessageCommon(aType,
aMessage,
messageID,
aPageURI.spec,
+ aExtra,
aManifestURI.spec);
debug("Returned status of sending message: " + result);
// Don't need to open the pages and queue the system message
// which was not allowed to be sent.
if (result === MSG_SENT_FAILURE_PERM_DENIED) {
return;
}
@@ -183,54 +185,56 @@
if (result === MSG_SENT_FAILURE_APP_NOT_RUNNING) {
// Don't open the page again if we already sent the message to it.
this._openAppPage(page, aMessage);
}
}
},
- broadcastMessage: function broadcastMessage(aType, aMessage) {
+ broadcastMessage: function broadcastMessage(aType, aMessage, aExtra) {
// Buffer system messages until the webapps' registration is ready,
// so that we can know the correct pages registered to be broadcasted.
if (!this._webappsRegistryReady) {
this._bufferedSysMsgs.push({ how: "broadcast",
type: aType,
+ extra: aExtra,
msg: aMessage });
return;
}
// Give this message an ID so that we can identify the message and
// clean it up from the pending message queue when apps receive it.
let messageID = gUUIDGenerator.generateUUID().toString();
debug("Broadcasting " + aType + " " + JSON.stringify(aMessage));
// Find pages that registered an handler for this type.
this._pages.forEach(function(aPage) {
if (aPage.type == aType) {
let result = this._sendMessageCommon(aType,
aMessage,
messageID,
aPage.uri,
- aPage.manifest);
+ aPage.manifest,
+ aExtra);
debug("Returned status of sending message: " + result);
// Don't need to open the pages and queue the system message
// which was not allowed to be sent.
if (result === MSG_SENT_FAILURE_PERM_DENIED) {
return;
}
// Queue this message in the corresponding pages.
this._queueMessage(aPage, aMessage, messageID);
if (result === MSG_SENT_FAILURE_APP_NOT_RUNNING) {
// Open app pages to handle their pending messages.
- this._openAppPage(aPage, aMessage);
+ this._openAppPage(aPage, aMessage, aExtra);
}
}
}, this);
},
registerPage: function registerPage(aType, aPageURI, aManifestURI) {
if (!aPageURI || !aManifestURI) {
throw Cr.NS_ERROR_INVALID_ARG;
@@ -495,21 +499,22 @@
// Queue the message for this page because we've never known if an app is
// opened or not. We'll clean it up when the app has already received it.
aPage.pendingMessages.push({ msg: aMessage, msgID: aMessageID });
if (aPage.pendingMessages.length > kMaxPendingMessages) {
aPage.pendingMessages.splice(0, 1);
}
},
- _openAppPage: function _openAppPage(aPage, aMessage) {
+ _openAppPage: function _openAppPage(aPage, aMessage, aExtra) {
// We don't need to send the full object to observers.
let page = { uri: aPage.uri,
manifest: aPage.manifest,
type: aPage.type,
+ extra: aExtra,
target: aMessage.target };
debug("Asking to open " + JSON.stringify(page));
Services.obs.notifyObservers(this, "system-messages-open-app", JSON.stringify(page));
},
_isPageMatched: function _isPageMatched(aPage, aType, aPageURI, aManifestURI) {
return (aPage.type === aType &&
aPage.manifest === aManifestURI &&
@@ -530,17 +535,17 @@
let data = converter.convertToByteArray(aPage[aProp], {});
hasher.update(data, data.length);
});
return hasher.finish(true);
},
_sendMessageCommon:
- function _sendMessageCommon(aType, aMessage, aMessageID, aPageURI, aManifestURI) {
+ function _sendMessageCommon(aType, aMessage, aMessageID, aPageURI, aManifestURI, aExtra) {
// Don't send the system message not granted by the app's permissions.
if (!SystemMessagePermissionsChecker
.isSystemMessagePermittedToSend(aType,
aPageURI,
aManifestURI)) {
return MSG_SENT_FAILURE_PERM_DENIED;
}
@@ -571,17 +576,18 @@
// window needs to check if the manifest/page URL is matched. Only
// *one* window should handle the system message.
let manager = target.target;
manager.sendAsyncMessage("SystemMessageManager:Message",
{ type: aType,
msg: aMessage,
manifest: aManifestURI,
uri: aPageURI,
- msgID: aMessageID });
+ msgID: aMessageID,
+ extra: aExtra});
}
}
if (!appPageIsRunning) {
// The app page isn't running and relies on the 'open-app' chrome event to
// wake it up. We still need to acquire a CPU wake lock for that page and
// expect that we will receive a "SystemMessageManager:HandleMessagesDone"
// message when the page finishes handling the system message with other
diff --git a/dom/messages/interfaces/nsISystemMessagesInternal.idl b/dom/messages/interfaces/nsISystemMessagesInternal.idl
--- a/dom/messages/interfaces/nsISystemMessagesInternal.idl
+++ b/dom/messages/interfaces/nsISystemMessagesInternal.idl
@@ -13,26 +13,28 @@
interface nsISystemMessagesInternal : nsISupports
{
/*
* Allow any internal user to broadcast a message of a given type.
* @param type The type of the message to be sent.
* @param message The message payload.
* @param pageURI The URI of the page that will be opened.
* @param manifestURI The webapp's manifest URI.
+ * @param extra Extra information
*/
- void sendMessage(in DOMString type, in jsval message, in nsIURI pageURI, in nsIURI manifestURI);
+ void sendMessage(in DOMString type, in jsval message, in nsIURI pageURI, in nsIURI manifestURI, [optional] in jsval extra);
/*
* Allow any internal user to broadcast a message of a given type.
* The application that registers the message will be launched.
* @param type The type of the message to be sent.
* @param message The message payload.
+ * @param extra Extra information
*/
- void broadcastMessage(in DOMString type, in jsval message);
+ void broadcastMessage(in DOMString type, in jsval message, [optional] in jsval extra);
/*
* Registration of a page that wants to be notified of a message type.
* @param type The message type.
* @param pageURI The URI of the page that will be opened.
* @param manifestURI The webapp's manifest URI.
*/
void registerPage(in DOMString type, in nsIURI pageURI, in nsIURI manifestURI);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment