Closed Bug 615617 Opened 14 years ago Closed 14 years ago

GetDocumentMetadata does not return data from META elements added by scripts (breaks jQuery Mobile)

Categories

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

defect
Not set
normal

Tracking

()

RESOLVED FIXED
Tracking Status
fennec 2.0+ ---

People

(Reporter: mbrubeck, Assigned: blassey)

References

()

Details

(Keywords: compat, mobile)

Attachments

(1 file)

nsDOMWindowUtils::GetDocumentMetadata (which uses nsIDocument::GetHeaderData) does not return any values from <meta> nodes inserted with JavaScript.

For example, http://jquerymobile.com/demos/1.0a2/ inserts a <meta name="viewport"> element into the <head>.  Fennec receives a DOMMetaAdded event when the element is inserted, but GetDocumentMetadata does not return the added values.
tracking-fennec: --- → ?
Keywords: compat, mobile
tracking-fennec: ? → 2.0+
For some <meta> elements GetDocumentMetadata _should_ ignore dynamically-added ones.  For example, http-equiv="content-type".

What's the list of metas that need to be handled dynamically here?
(In reply to comment #1)
> For some <meta> elements GetDocumentMetadata _should_ ignore dynamically-added
> ones.  For example, http-equiv="content-type".
> 
> What's the list of metas that need to be handled dynamically here?

Just <meta name="viewport"> would be fine.
OK.  So I assume GetDocumentMetadata should reflect the first <meta name="viewport"> in the DOM?  Should it restrict to <head>, or just anywhere in the DOM?
That might be fine.  The only cases I've found in the wild are pages that have no <meta name="viewport"> in the HTML, and then add one to <head> on "load".  There's no standard or spec for this, so I'll do some testing later today to see what WebKit and other browsers do for comparison.
The WebKit browsers in Android 2.2 and iOS 4 (tested on iPad) use the contents of the last <meta name="viewport">, rather than the first.

However, meta elements inserted dynamically always override any existing viewport settings, even if the dynamic element is inserted higher in the DOM than the existing one.

Meta elements in the body are treated the same as in the head, and elements can be inserted using appendChild (both during and after the "load" event), or written using document.write.

Test cases at http://limpet.net/test/vp0.html through http://limpet.net/test/vp9.html
Opera Mobile for Android behaves the same as WebKit for all the test cases in comment 5.
Ugh, hysteresis.  That's really annoying.  :(

I guess you could just hack nsHTMLMetaElement::BindToTree to update the document metadata to get this behavior, right?  The "use the last" behavior is just a consequence of "whenever something is inserted it overrides the value", since the parser mostly inserts in tree order.
Blocks: 616348
(In reply to comment #1)
> What's the list of metas that need to be handled dynamically here?

Would it be better to have a black list of metas that shouldn't be handled dynamically?
Hard to say.  Dynamic handling costs.  Depending on how it's implemented, it could cost on any DOM mutation, and the longer the list the more cost.

Matt, what happens when you _remove_ a <meta name="viewport"> from the DOM in webkit?  I bet it doesn't change the viewport at that point....
Attached patch patchSplinter Review
Assignee: nobody → blassey.bugs
Attachment #495790 - Flags: review?(bzbarsky)
You can take the hunk in nsContentSink that also does this out now, right?

Also s/nsnull/kNamespaceID_None/
Comment on attachment 495790 [details] [diff] [review]
patch

r=me with those two changes, though duplicating the webkit bugginess here makes me really sad.  Can we talk to them about fixing that?
Attachment #495790 - Flags: review?(bzbarsky) → review+
pushed http://hg.mozilla.org/mozilla-central/rev/ded653253911
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
(In reply to comment #12)
> Can we talk to them about fixing that?

filed bug 617331
(In reply to comment #9)
> Matt, what happens when you _remove_ a <meta name="viewport"> from the DOM in
> webkit?  I bet it doesn't change the viewport at that point....

That's correct.  Removing the <meta> element does not change the viewport in WebKit.  Test case at http://limpet.net/test/vp10.html
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: