Closed Bug 585240 Opened 14 years ago Closed 14 years ago

Can't add message handlers by setting the onmessage property

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: adob321, Assigned: smaug)

Details

(Keywords: testcase)

Attachments

(2 files)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.458.1 Safari/534.3
Build Identifier: Mozilla/5.0 (X11; Linux i686; rv:2.0b4pre) Gecko/20100806 Minefield/4.0b4pre

The window.onmessage event handler does not fire when the postMessage function is called.

Reproducible: Always

Steps to Reproduce:
1. Open an html file containing the following:

<script>
	window.onmessage = function(event) {
		alert(event.data);
	}
	
	window.postMessage("hello", "*");
</script>
Actual Results:  
Nothing happens.

Expected Results:  
A message box containing the words "hello".

Works as expected in Chrome.
Attached file HTML testcase
OS: Linux → All
Hardware: x86 → All
I can reproduce on Mozilla/5.0 (Macintosh; Intel Mac OS X 10.5; rv:2.0b6pre) Gecko/20100904 Firefox/4.0b6pre, seems valid.
Status: UNCONFIRMED → NEW
Component: General → DOM
Ever confirmed: true
Keywords: testcase
Product: Firefox → Core
QA Contact: general → general
Summary: onmessage event handler does not fire → onmessage event handler does not fire when using window.postMessage to post a message to itself
Version: unspecified → Trunk
This has nothing to do with posting a message to itself, and everything to do with "onmessage" not being a property of windows in Gecko.  Using

  addEventListener("message", function() { /* whatever */ }, false);

works fine.
Summary: onmessage event handler does not fire when using window.postMessage to post a message to itself → Can't add message handlers by setting the onmessage property
Oops! Thanks for correcting me, bz!
Just adding to nsContentUtils::InitializeEventTable might be good enough to make this work....
Add onmessage to nsDOMClassInfo...
Assignee: nobody → Olli.Pettay
Attached patch patchSplinter Review
Attachment #472289 - Flags: review?(jwalden+bmo)
Comment on attachment 472289 [details] [diff] [review]
patch

I don't know much about the on*-property code, but going from the diff it seems plausible.  rs=me seems about the right level of confidence.

What I presume is a big filter to check a string against a gazillion on*-names looks like it wants some sort of gperf-hash-like thing; I'm vaguely curious if anyone's ever filed a bug on doing that.

It would be marginally better form, I think, to use location.href instead of "*" for the target origin.
Attachment #472289 - Flags: review?(jwalden+bmo) → review+
We should just add onfoo properties to the interfaces, but that is larger change
than what I want to do in this bug.
Attachment #472289 - Flags: approval2.0?
Attachment #472289 - Flags: approval2.0? → approval2.0+
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: