Bug 436801 - Support XHTML in feed titles. r=sayrer,adw

This commit is contained in:
Nicholas Wilson 2013-04-26 23:57:49 -07:00
Родитель 089cb45b06
Коммит 21013ebf88
4 изменённых файлов: 178 добавлений и 5 удалений

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

@ -44,7 +44,7 @@ function makeURI(aURLSpec, aCharset) {
return null;
}
const XML_NS = "http://www.w3.org/XML/1998/namespace"
const XML_NS = "http://www.w3.org/XML/1998/namespace";
const HTML_NS = "http://www.w3.org/1999/xhtml";
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const TYPE_MAYBE_FEED = "application/vnd.mozilla.maybe.feed";
@ -169,11 +169,15 @@ FeedWriter.prototype = {
_setContentText: function FW__setContentText(id, text) {
this._contentSandbox.element = this._document.getElementById(id);
this._contentSandbox.textNode = this._document.createTextNode(text);
this._contentSandbox.textNode = text.createDocumentFragment(this._contentSandbox.element);
var codeStr =
"while (element.hasChildNodes()) " +
" element.removeChild(element.firstChild);" +
"element.appendChild(textNode);";
if (text.base) {
this._contentSandbox.spec = text.base.spec;
codeStr += "element.setAttributeNS('" + XML_NS + "', 'base', spec);";
}
Cu.evalInSandbox(codeStr, this._contentSandbox);
this._contentSandbox.element = null;
this._contentSandbox.textNode = null;
@ -361,7 +365,7 @@ FeedWriter.prototype = {
_setTitleText: function FW__setTitleText(container) {
if (container.title) {
var title = container.title.plainText();
this._setContentText(TITLE_ID, title);
this._setContentText(TITLE_ID, container.title);
this._contentSandbox.document = this._document;
this._contentSandbox.title = title;
var codeStr = "document.title = title;"
@ -370,7 +374,7 @@ FeedWriter.prototype = {
var feed = container.QueryInterface(Ci.nsIFeed);
if (feed && feed.subtitle)
this._setContentText(SUBTITLE_ID, container.subtitle.plainText());
this._setContentText(SUBTITLE_ID, container.subtitle);
},
/**
@ -439,7 +443,11 @@ FeedWriter.prototype = {
// If the entry has a title, make it a link
if (entry.title) {
var a = this._document.createElementNS(HTML_NS, "a");
a.appendChild(this._document.createTextNode(entry.title.plainText()));
var span = this._document.createElementNS(HTML_NS, "span");
a.appendChild(span);
if (entry.title.base)
span.setAttributeNS(XML_NS, "base", entry.title.base.spec);
span.appendChild(entry.title.createDocumentFragment(a));
// Entries are not required to have links, so entry.link can be null.
if (entry.link)

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

@ -18,6 +18,8 @@ MOCHITEST_FILES = bug408328-data.xml \
bug494328-data.xml \
test_bug589543.html \
bug589543-data.xml \
test_bug436801.html \
bug436801-data.xml \
test_registerHandler.html \
valid-feed.xml \
valid-unsniffable-feed.xml \

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

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="http://www.example.com/">
<title type="xhtml" xml:base="/foo/bar/">
<div xmlns="http://www.w3.org/1999/xhtml">Example of a <em>special</em> feed (<img height="20px" src="baz.png" alt="base test sprite"/>)</div>
</title>
<subtitle type="html" xml:base="/foo/bar/">
<![CDATA[
With a <em>special</em> subtitle (<img height="20px" src="baz.png" alt="base test sprite"/>)
]]>
</subtitle>
<link href="http://example.org/"/>
<updated>2010-09-02T18:30:02Z</updated>
<author>
<name>John Doe</name>
</author>
<id>urn:uuid:22906062-ecbd-46e2-b6a7-3039506a398f</id>
<entry>
<title type="xhtml" xml:base="/foo/bar/">
<div xmlns="http://www.w3.org/1999/xhtml">Some <abbr title="Extensible Hyper-text Mark-up Language">XHTML</abbr> examples (<img height="20px" src="baz.png" alt="base test sprite"/>)</div>
</title>
<id>urn:uuid:b48083a7-71a7-4c9c-8515-b7c0d22955e7</id>
<updated>2010-09-02T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>
<entry>
<title type="html" xml:base="/foo/bar/">
<![CDATA[
Some <abbr title="Hyper-text Mark-up Language">HTML</abbr> examples (<img height="20px" src="baz.png" alt="base test sprite"/>)
]]>
</title>
<id>urn:uuid:1424967a-280a-414d-b0ab-8b11c4ac1bb7</id>
<updated>2010-09-02T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>
</feed>

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

@ -0,0 +1,119 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=436801
-->
<head>
<title>Test feed preview subscribe UI</title>
<script type="text/javascript" src="/MochiKit/packed.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=436801">Mozilla Bug 436801</a>
<p id="display"><iframe id="testFrame" src="bug436801-data.xml"></iframe></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
addLoadEvent(function () {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var doc = $("testFrame").contentDocument;
checkNode(doc.getElementById("feedTitleText"), [
"ELEMENT", "h1", { "xml:base": "http://www.example.com/foo/bar/" }, [
["TEXT", "Example of a "],
["ELEMENT", "em", [
["TEXT", "special"],
]],
["TEXT", " feed ("],
["ELEMENT", "img", { "src": "baz.png" }],
["TEXT", ")"],
]
]);
checkNode(doc.getElementById("feedSubtitleText"), [
"ELEMENT", "h2", { "xml:base": "http://www.example.com/foo/bar/" }, [
["TEXT", "With a "],
["ELEMENT", "em", [
["TEXT", "special"],
]],
["TEXT", " subtitle ("],
["ELEMENT", "img", { "src": "baz.png" }],
["TEXT", ")"],
]
]);
checkNode(doc.querySelector(".entry").firstChild.firstChild.firstChild, [
"ELEMENT", "span", { "xml:base": "http://www.example.com/foo/bar/" }, [
["TEXT", "Some "],
["ELEMENT", "abbr", { title: "Extensible Hyper-text Mark-up Language" }, [
["TEXT", "XHTML"],
]],
["TEXT", " examples ("],
["ELEMENT", "img", { "src": "baz.png" }],
["TEXT", ")"],
]
]);
checkNode(doc.querySelectorAll(".entry")[1].firstChild.firstChild.firstChild, [
"ELEMENT", "span", { "xml:base": "http://www.example.com/foo/bar/" }, [
["TEXT", "Some "],
["ELEMENT", "abbr", { title: "Hyper-text Mark-up Language" }, [
["TEXT", "HTML"],
]],
["TEXT", " examples ("],
["ELEMENT", "img", { "src": "baz.png" }],
["TEXT", ")"],
]
]);
});
addLoadEvent(SimpleTest.finish);
function checkNode(node, schema) {
var typeName = schema.shift() + "_NODE";
var type = Node[typeName];
is(node.nodeType, type, "Node should be expected type " + typeName);
if (type == Node.TEXT_NODE) {
var text = schema.shift();
is(node.data, text, "Text should match");
return;
}
// type == Node.ELEMENT_NODE
var tag = schema.shift();
is(node.localName, tag, "Element should have expected tag");
while (schema.length) {
var val = schema.shift();
if (Array.isArray(val))
var childSchema = val;
else
var attrSchema = val;
}
if (attrSchema) {
var nsTable = {
xml: "http://www.w3.org/XML/1998/namespace",
};
for (var name in attrSchema) {
var [ns, nsName] = name.split(":");
var val = nsName ? node.getAttributeNS(nsTable[ns], nsName) :
node.getAttribute(name);
is(val, attrSchema[name], "Attribute " + name + " should match");
}
}
if (childSchema) {
var numChildren = node.childNodes.length;
is(childSchema.length, numChildren,
"Element should have expected number of children");
for (var i = 0; i < numChildren; i++)
checkNode(node.childNodes[i], childSchema[i]);
}
}
</script>
</pre>
</body>
</html>