Closed Bug 1238804 Opened 4 years ago Closed 4 years ago

<base> tag has no effect on srcdoc iframe

Categories

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

43 Branch
defect
Not set

Tracking

()

RESOLVED FIXED
mozilla46
Tracking Status
firefox46 --- fixed

People

(Reporter: thomsbg, Assigned: bzbarsky)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36

Steps to reproduce:

The <base> tag seems to have no effect on `baseURI` for iframes populated via srcdoc. For example:

iframe = document.createElement('iframe')
iframe.srcdoc = '<html><head><base href="http://www.vox.com/"></head><body><a href="/">test</a></body></html>'
document.body.appendChild(iframe)


Actual results:

Evaluating `iframe.contentDocument.baseURI` results in the URL of the parent page.


Expected results:

I expect the iframe's baseURI to be: http://www.vox.com/ (that set by the <base> tag).

Chrome + Safari both exhibit this behavior.
The basic issue here is that GetDocBaseURI() does this:

357   nsIURI* GetDocBaseURI() const
358   {
359     if (mIsSrcdocDocument && mParentDocument) {
360       return mParentDocument->GetDocBaseURI();
361     }
362     return mDocumentBaseURI ? mDocumentBaseURI : mDocumentURI;
363   }

In this case, mDocumentBaseURI is set to "http://www.vox.com/", of course.

I dunno whether this was just buggy as implemented or whether the spec has changed since, but this code clearly doesn't match the spec now.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Assignee: nobody → bzbarsky
Status: NEW → ASSIGNED
thomsbg, thank you for reporting this!
Comment on attachment 8706739 [details] [diff] [review]
Make <base> actually work in a srcdoc document

s/NOte/Note/

the comment in dom/html/HTMLSharedElement.cpp
talks about document URI, but it is now using fallback base URI per spec.
Want to fix the comment.


(I wonder if the about:blank handling in the spec is web compatible. Feels surprising to me.)
Attachment #8706739 - Flags: review?(bugs) → review+
Will fix the comments.

about:blank handling is somewhat inconsistent across browsers.  See discussion in https://github.com/whatwg/html/issues/421 about what browsers do or don't do and what the spec should say here...
https://hg.mozilla.org/mozilla-central/rev/37067b8102be
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla46
You need to log in before you can comment on or make changes to this bug.