author | William Chen <wchen@mozilla.com> |
Mon, 03 Mar 2014 12:03:23 -0800 | |
changeset 171640 | 33eb31ac3741e575df36b905a40a8fe493935175 |
parent 171639 | dd4e1e3a72a5dcc42118356d0e676ea06842be33 |
child 171641 | 085029423c2917ab4c7f0837a416cc76b9a73b57 |
push id | 26334 |
push user | kwierso@gmail.com |
push date | Tue, 04 Mar 2014 04:26:01 +0000 |
treeherder | mozilla-central@529b86b92b1d [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | mrbkap |
bugs | 976318 |
milestone | 30.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -9362,16 +9362,22 @@ nsDocument::GetTemplateContentsOwner() scriptObject, // aEventObject DocumentFlavorHTML); NS_ENSURE_SUCCESS(rv, nullptr); mTemplateContentsOwner = do_QueryInterface(domDocument); NS_ENSURE_TRUE(mTemplateContentsOwner, nullptr); mTemplateContentsOwner->SetScriptHandlingObject(scriptObject); + + // Set |doc| as the template contents owner of itself so that + // |doc| is the template contents owner of template elements created + // by |doc|. + nsDocument* doc = static_cast<nsDocument*>(mTemplateContentsOwner.get()); + doc->mTemplateContentsOwner = doc; } return mTemplateContentsOwner; } void nsDocument::RegisterHostObjectUri(const nsACString& aUri) {
--- a/content/html/content/src/HTMLTemplateElement.cpp +++ b/content/html/content/src/HTMLTemplateElement.cpp @@ -34,26 +34,18 @@ HTMLTemplateElement::HTMLTemplateElement : nsGenericHTMLElement(aNodeInfo) { SetHasWeirdParserInsertionMode(); } nsresult HTMLTemplateElement::Init() { - nsIDocument* doc = OwnerDoc(); - nsIDocument* contentsOwner = doc; - - // Used to test if the document "has a browsing context". - nsCOMPtr<nsISupports> container = doc->GetContainer(); - if (container) { - // GetTemplateContentsOwner lazily creates a document. - contentsOwner = doc->GetTemplateContentsOwner(); - NS_ENSURE_TRUE(contentsOwner, NS_ERROR_UNEXPECTED); - } + nsIDocument* contentsOwner = OwnerDoc()->GetTemplateContentsOwner(); + NS_ENSURE_TRUE(contentsOwner, NS_ERROR_UNEXPECTED); mContent = contentsOwner->CreateDocumentFragment(); mContent->SetHost(this); return NS_OK; } HTMLTemplateElement::~HTMLTemplateElement()
--- a/dom/tests/mochitest/webcomponents/test_template.html +++ b/dom/tests/mochitest/webcomponents/test_template.html @@ -45,16 +45,24 @@ ok(!document.getElementById("insidetempl is(templateEl.childNodes.length, 0, "Template element should have no children."); is(templateEl.content.childNodes.length, 1, "Template content should have 1 child <div>."); // Make sure that template is owned by different document. ok(templateEl.content.ownerDocument != templateEl.ownerDocument, "Template should be in a different document because the current document has a browsing context."); var otherTemplateEl = document.getElementById("first"); is(templateEl.content.ownerDocument, otherTemplateEl.content.ownerDocument, "Template contents within the same document should be owned by the same template contents owner."); +var htmlDoc = document.implementation.createHTMLDocument(); +var otherDocTemplateEl = htmlDoc.createElement("template"); +isnot(otherDocTemplateEl.content.ownerDocument, htmlDoc, "Template content owner should be a new document."); + +var templateOwnerDoc = otherDocTemplateEl.content.ownerDocument; +var docCreatedTemplateEl = templateOwnerDoc.createElement("template"); +is(docCreatedTemplateEl.content.ownerDocument, templateOwnerDoc, "Template content owner of template elements created by a template document should be the template document."); + // Tests for XMLSerializer templateEl = document.getElementById("justtemplate"); var serializer = new XMLSerializer(); is(serializer.serializeToString(templateEl), '<template xmlns="http://www.w3.org/1999/xhtml" id="justtemplate"></template>', "XMLSerializer should serialize template element."); templateEl = document.getElementById("first"); is(serializer.serializeToString(templateEl), '<template xmlns="http://www.w3.org/1999/xhtml" id="first">Hi<template>Bye</template></template>', "XMLSerializer should serialize template content.");