Closed Bug 989098 Opened 10 years ago Closed 10 years ago

Improve EventDispatcher/Messaging.jsm

Categories

(Firefox for Android Graveyard :: General, defect)

All
Android
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 31

People

(Reporter: bnicholson, Assigned: bnicholson)

References

Details

Attachments

(1 file, 2 obsolete files)

We can make several improvements to our messaging:
1) Prevent double JSON.parsing. We parse the result at [1] to get the GUID. We then dispatch the string, rather than the parsed data, at [2]. That means we need to call JSON.parse all over again, which is inefficient.
2) Allow passing more than just JSONObjects in the API. For example, in bug 946022, I'd like to pass null data for a response. If we change sendResponse to accept an Object instead of a JSONObject, we can send anything supported by JSONObject#put (null, strings, JSONArray, etc).

[1] http://hg.mozilla.org/mozilla-central/file/bb4dd9872236/mobile/android/modules/Messaging.jsm#l22
[2] http://hg.mozilla.org/mozilla-central/file/bb4dd9872236/mobile/android/modules/Messaging.jsm#l30
Attachment #8398155 - Flags: review?(wjohnston)
One more advantage: we no longer expose the __guid__ property in the data for response listeners.
Comment on attachment 8398154 [details] [diff] [review]
Part 1: Use wrapper object to pass generic objects in sendResponse

Review of attachment 8398154 [details] [diff] [review]:
-----------------------------------------------------------------

This will break the tree, so make sure you fold these when you land 'em.

::: mobile/android/base/EventDispatcher.java
@@ +117,5 @@
>          try {
> +            JSONObject wrapper = new JSONObject();
> +            wrapper.put(GUID, message.getString(GUID));
> +            wrapper.put("response", error);
> +            GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent(message.getString("type") + ":Error", wrapper.toString()));

We should probably just delegate both of these to one private function that takes the suffix for the message.
Attachment #8398154 - Flags: review?(wjohnston) → review+
Made suggested changes. I'll just fold these now so I don't forget.
Attachment #8398154 - Attachment is obsolete: true
Attachment #8398155 - Attachment is obsolete: true
Attachment #8398155 - Flags: review?(wjohnston)
Attachment #8398175 - Flags: review?(wjohnston)
Comment on attachment 8398155 [details] [diff] [review]
Part 2: Update response listeners to accept parsed JSON

Review of attachment 8398155 [details] [diff] [review]:
-----------------------------------------------------------------

You should send out a newsgroup post when you land these, since they'll likely break WIP patches by people in ways that aren't obvious.

::: mobile/android/modules/Prompt.jsm
@@ +160,1 @@
>        Services.obs.removeObserver(this, "Prompt:Return", false);

You might as well remove this while you're here. And flip aData->data if you want.
Attachment #8398155 - Attachment is obsolete: false
Attachment #8398155 - Flags: review+
Comment on attachment 8398175 [details] [diff] [review]
Use wrapper object to pass generic objects in sendResponse

Review of attachment 8398175 [details] [diff] [review]:
-----------------------------------------------------------------

Err. I think I broke things. r+ for everyone.
Attachment #8398175 - Flags: review?(wjohnston) → review+
Attachment #8398155 - Attachment is obsolete: true
https://hg.mozilla.org/mozilla-central/rev/1bf54f059927
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 31
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: