Bug 420700 - Calling createContextualFragment affects subsequent setting of innerHTML. r+sr=jst, a=blocking1.9+.

This commit is contained in:
bent.mozilla%gmail.com 2008-03-06 20:14:35 +00:00
Родитель 5069bec594
Коммит ed9e41df06
9 изменённых файлов: 72 добавлений и 14 удалений

Просмотреть файл

@ -901,10 +901,13 @@ public:
*
* @param aContextNode the node which is used to resolve namespaces
* @param aFragment the string which is parsed to a DocumentFragment
* @param aWillOwnFragment is PR_TRUE if ownership of the fragment should be
* transferred to the caller.
* @param aReturn [out] the created DocumentFragment
*/
static nsresult CreateContextualFragment(nsIDOMNode* aContextNode,
const nsAString& aFragment,
PRBool aWillOwnFragment,
nsIDOMDocumentFragment** aReturn);
/**

Просмотреть файл

@ -3354,6 +3354,7 @@ nsContentUtils::IsValidNodeName(nsIAtom *aLocalName, nsIAtom *aPrefix,
nsresult
nsContentUtils::CreateContextualFragment(nsIDOMNode* aContextNode,
const nsAString& aFragment,
PRBool aWillOwnFragment,
nsIDOMDocumentFragment** aReturn)
{
NS_ENSURE_ARG(aContextNode);
@ -3499,7 +3500,7 @@ nsContentUtils::CreateContextualFragment(nsIDOMNode* aContextNode,
rv = parser->ParseFragment(aFragment, nsnull, tagStack,
!bHTML, contentType, mode);
if (NS_SUCCEEDED(rv)) {
rv = sink->GetFragment(aReturn);
rv = sink->GetFragment(aWillOwnFragment, aReturn);
}
document->SetFragmentParser(parser);

Просмотреть файл

@ -1794,8 +1794,9 @@ nsRange::CreateContextualFragment(const nsAString& aFragment,
nsIDOMDocumentFragment** aReturn)
{
nsCOMPtr<nsIDOMNode> start = do_QueryInterface(mStartParent);
return
mIsPositioned
? nsContentUtils::CreateContextualFragment(start, aFragment, aReturn)
: NS_ERROR_FAILURE;
if (mIsPositioned) {
return nsContentUtils::CreateContextualFragment(start, aFragment, PR_TRUE,
aReturn);
}
return NS_ERROR_FAILURE;
}

Просмотреть файл

@ -175,6 +175,7 @@ _TEST_FILES = test_bug5141.html \
test_bug417384.html \
test_bug418214.html \
test_bug420609.xhtml \
test_bug420700.html \
$(NULL)
libs:: $(_TEST_FILES)

Просмотреть файл

@ -0,0 +1,36 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=420700
-->
<head>
<title>Test for Bug 420700</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=420700">Mozilla Bug 420700</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
var r = document.createRange();
r.selectNode(document.documentElement);
var df = r.createContextualFragment("<p>BAD</p>");
var display = document.getElementById("display");
display.innerHTML = "<p>GOOD</p>";
var p = display.firstChild;
is(p.textContent, "GOOD", "createContextualFragment tests");
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -746,6 +746,7 @@ nsGenericHTMLElement::SetInnerHTML(const nsAString& aInnerHTML)
nsCOMPtr<nsIDOMNode> thisNode(do_QueryInterface(static_cast<nsIContent *>
(this)));
nsresult rv = nsContentUtils::CreateContextualFragment(thisNode, aInnerHTML,
PR_FALSE,
getter_AddRefs(df));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIDOMNode> tmpNode;

Просмотреть файл

@ -119,7 +119,8 @@ public:
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode);
// nsIFragmentContentSink
NS_IMETHOD GetFragment(nsIDOMDocumentFragment** aFragment);
NS_IMETHOD GetFragment(PRBool aWillOwnFragment,
nsIDOMDocumentFragment** aFragment);
NS_IMETHOD SetTargetDocument(nsIDocument* aDocument);
NS_IMETHOD WillBuildContent();
NS_IMETHOD DidBuildContent();
@ -608,10 +609,15 @@ nsHTMLFragmentContentSink::AddDocTypeDecl(const nsIParserNode& aNode)
}
NS_IMETHODIMP
nsHTMLFragmentContentSink::GetFragment(nsIDOMDocumentFragment** aFragment)
nsHTMLFragmentContentSink::GetFragment(PRBool aWillOwnFragment,
nsIDOMDocumentFragment** aFragment)
{
if (mRoot) {
return CallQueryInterface(mRoot, aFragment);
nsresult rv = CallQueryInterface(mRoot, aFragment);
if (NS_SUCCEEDED(rv) && aWillOwnFragment) {
mRoot = nsnull;
}
return rv;
}
*aFragment = nsnull;

Просмотреть файл

@ -102,7 +102,8 @@ public:
// nsIXMLContentSink
// nsIFragmentContentSink
NS_IMETHOD GetFragment(nsIDOMDocumentFragment** aFragment);
NS_IMETHOD GetFragment(PRBool aWillOwnFragment,
nsIDOMDocumentFragment** aFragment);
NS_IMETHOD SetTargetDocument(nsIDocument* aDocument);
NS_IMETHOD WillBuildContent();
NS_IMETHOD DidBuildContent();
@ -400,14 +401,19 @@ nsXMLFragmentContentSink::StartLayout()
////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsXMLFragmentContentSink::GetFragment(nsIDOMDocumentFragment** aFragment)
nsXMLFragmentContentSink::GetFragment(PRBool aWillOwnFragment,
nsIDOMDocumentFragment** aFragment)
{
*aFragment = nsnull;
if (mParseError) {
//XXX PARSE_ERR from DOM3 Load and Save would be more appropriate
return NS_ERROR_DOM_SYNTAX_ERR;
} else if (mRoot) {
return CallQueryInterface(mRoot, aFragment);
nsresult rv = CallQueryInterface(mRoot, aFragment);
if (NS_SUCCEEDED(rv) && aWillOwnFragment) {
mRoot = nsnull;
}
return rv;
} else {
return NS_OK;
}

Просмотреть файл

@ -43,8 +43,8 @@ class nsIDOMDocumentFragment;
class nsIDocument;
#define NS_I_FRAGMENT_CONTENT_SINK_IID \
{ 0x2cec7263, 0x9dd0, 0x4413, \
{ 0xb6, 0x68, 0x6f, 0xf0, 0xa1, 0x40, 0xc1, 0xbe } }
{ 0x1ecdb30d, 0x1f10, 0x45d2, \
{ 0xa4, 0xf4, 0xec, 0xbc, 0x03, 0x52, 0x9a, 0x7e } }
/**
* The fragment sink allows a client to parse a fragment of sink, possibly
@ -60,8 +60,11 @@ public:
* a fragment content sink. The value returned will be null
* if the content sink hasn't yet received parser notifications.
*
* If aWillOwnFragment is PR_TRUE then the sink should drop its
* ownership of the fragment.
*/
NS_IMETHOD GetFragment(nsIDOMDocumentFragment** aFragment) = 0;
NS_IMETHOD GetFragment(PRBool aWillOwnFragment,
nsIDOMDocumentFragment** aFragment) = 0;
/**
* This method is used to set the target document for this fragment