Closed Bug 616779 Opened 14 years ago Closed 14 years ago

it isn't possible to postMessage to widget's content scripts

Categories

(Add-on SDK Graveyard :: General, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: myk, Assigned: dietrich)

Details

(Whiteboard: [cherry-pick-1.0b1])

Attachments

(1 file)

It isn't possible to post a message to a widget's content scripts, because the postMessage function is not defined. It looks like the problem is that Widget acquires the Loader trait, whereas it should be acquiring the Symbiont trait, which itself acquires both Worker (which adds postMessage) and Loader. (Ultimately I think this hierarchy should be flattened such that an object like Widget that wants Symbiont, Worker, and Loader functionality should acquire them all directly, and each should provide its own independent set of functionality rather than having Symbiont acquire Worker and Loader; but that's a topic for another bug.)
Assignee: nobody → dietrich
See https://bugzilla.mozilla.org/show_bug.cgi?id=569479#c15. The problem IIRC is that Symbiont loads on construction. So we used the Loader to get the API but without loading on instanciation. Instead of tweaking Symbiont (or Loader), we could add a postMessage to widget, and pass the message on down to each per-window Symbiont.
Hm, while this seemed quite trivial, I'm getting an interesting error. When I call the symbiont's postMessage method, I get "this._port is null". File "resource://testpkgs-addon-kit-tests/test-widget.js", line 513, in testPanelWidgetMessaging widget.postMessage(origMessage); File "resource://testpkgs-addon-kit-lib/widget.js", line 208, in Widget_postMessage browserManager.updateItem(this._public, "postMessage", message); File "resource://testpkgs-addon-kit-lib/widget.js", line 276, in browserManager_updateItem this.windows.forEach(function (w) w.updateItem(item, property, value)); File "resource://testpkgs-addon-kit-lib/widget.js", line 276, in this.windows.forEach(function (w) w.updateItem(item, property, value)); File "resource://testpkgs-addon-kit-lib/widget.js", line 417, in BW_updateItem item.symbiont.postMessage(value); File "resource://testpkgs-api-utils-lib/content/worker.js", line 75, in postMessage this._port._asyncEmit('message', JSON.parse(JSON.stringify(data))); TypeError: this._port is null
Irakli or Myk: What are the conditions under which a Symbiont could have a null port? From the code, it does not appear to be a valid state.
Hm, Worker._port is only null if I try to call Worker.postMessage immediately after construction. If I wait a second, everything works as expected. However, the Worker code looks like ._port is set immediately during construction, so I'm not sure what's going on.
not about Worker really. the Widget content hasn't loaded yet, so Worker isn't finished setting up.
Attachment #496077 - Flags: review?(myk)
Comment on attachment 496077 [details] Pointer to pull request There are a few issues, which I've noted in the pull request.
Attachment #496077 - Flags: review?(myk) → review-
I went ahead and fixed the issues and pushed the changes in the interest of getting this into the tree. Original commit: https://github.com/mozilla/addon-sdk/commit/8c8bbc309428d5c7b74af18d7ceafa8bb46eb7cc Commit to fix issues: https://github.com/mozilla/addon-sdk/commit/f44cf76687d1d5e9942221d4ed4882249d482abe Extraneous private merge I wish was never added to the history: https://github.com/mozilla/addon-sdk/commit/ac77593bd1f93b1d563757bf20541c45e8cec22b Nonextraneous public merge: https://github.com/mozilla/addon-sdk/commit/2bc1aac18fec258b40382660457a9d5d38f20cc9
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Whiteboard: [cherry-pick-wanted]
Target Milestone: -- → 1.0b1
Note: I reverted the cherry-picks, as Drew and I investigated the test failures and realized that the problem is symptomatic of a potential design flaw with Widget.postMessage that will need time and deliberation to investigate and make a decision about. More soon...
Reverted cherry-picks: https://github.com/mozilla/addon-sdk/commit/4e31f49a0593a75016afa786c530f5e4211aefce https://github.com/mozilla/addon-sdk/commit/3202d4427e8eddaa8ada993796f544e6e00440df https://github.com/mozilla/addon-sdk/commit/33d5ce22bff0b66070f5a4ca13060b098635dc05 In brief, the issue is that widget -> symbiont communication via Widget.postMessage is broadcast to all the widget's symbionts, and the test doesn't take that into account when engaging in two-way communication. It assumes only a single symbiont will respond to its message. Here's a prospective fix to the test: https://github.com/mykmelez/addon-sdk/commit/9f5dd3bdd0ae8265415d205270ed65be38d8f15f But I think we need to think more about what kinds of communication we want this API to enable. Do we want broadcasts from a widget to its symbionts? Or do we perhaps want only communication between a widget and a specific symbiont (the way page-mod works)? Or both?
Page-mods need to be able to differentiate between the symbionts. In the widget case, the symbionts map directly to windows, and I'm pretty sure (but not totally) that we want widget state to be mirrored across all windows. I think that in the common case, the overhead of having to manage symbiont per window is extraneous to what the widget author is trying to do.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Running the full test suite or just these two tests: $ cfx test -b /Applications/Minefield.app -v -f "test-widget|test-windows" fails (failure text below). This patch adds a widget.destroy() to fix the test: <https://github.com/mozilla/addon-sdk/pull/90> ... File "resource://addon-kit-addon-kit-tests/test-widget.js", line 507, in widget.postMessage(origMessage); File "resource://addon-kit-addon-kit-lib/widget.js", line 205, in Widget_postMessage browserManager.updateItem(this._public, "postMessage", message); File "resource://addon-kit-addon-kit-lib/widget.js", line 273, in browserManager_updateItem this.windows.forEach(function (w) w.updateItem(item, property, value)); File "resource://addon-kit-addon-kit-lib/widget.js", line 273, in this.windows.forEach(function (w) w.updateItem(item, property, value)); File "resource://addon-kit-addon-kit-lib/widget.js", line 414, in BW_updateItem item.symbiont.postMessage(value); File "resource://addon-kit-api-utils-lib/content/worker.js", line 75, in postMessage this._port._asyncEmit('message', JSON.parse(JSON.stringify(data))); TypeError: this._port is null
(In reply to comment #14) > This patch adds a widget.destroy() to fix the test: > <https://github.com/mozilla/addon-sdk/pull/90> Thanks for the test failure fix! I have reviewed and pulled it. Fix commit: https://github.com/mozilla/addon-sdk/commit/2e2a26d2f9b9765b065197d2ce1b3ac5a6552a6c Merge commit: https://github.com/mozilla/addon-sdk/commit/8f6fffe75cc5c473fd48f7ddc6d7a6c99cf896d4 Leaving this bug open, however, pending a fix for the issue with making it possible to postMessage to a widget's content scripts.
So the initial bug behing this bugzilla item is fixed. Providing a window specific access to widgets is another feature discussed in bug 630962.
Status: REOPENED → RESOLVED
Closed: 14 years ago14 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: