зеркало из https://github.com/mozilla/pjs.git
Bug 383746 - Page Info RSS section should use code in browser.js to enumerate page feeds. Patch by Ehsan Akhgari <ehsan.akhgari@gmail.com>. r=mano.
This commit is contained in:
Родитель
8631fed5b4
Коммит
686bfd33ae
|
@ -20,6 +20,7 @@
|
|||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -39,19 +40,24 @@ function initFeedTab()
|
|||
{
|
||||
const feedTypes = {
|
||||
"application/rss+xml": gBundle.getString("feedRss"),
|
||||
"application/atom+xml": gBundle.getString("feedAtom")
|
||||
"application/atom+xml": gBundle.getString("feedAtom"),
|
||||
"text/xml": gBundle.getString("feedXML"),
|
||||
"application/xml": gBundle.getString("feedXML"),
|
||||
"application/rdf+xml": gBundle.getString("feedXML")
|
||||
};
|
||||
|
||||
// get the feeds
|
||||
var linkNodes = gDocument.getElementsByTagName("link");
|
||||
var length = linkNodes.length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
if (linkNodes[i].rel == "alternate" &&
|
||||
linkNodes[i].type in feedTypes &&
|
||||
linkNodes[i].href) {
|
||||
addRow(linkNodes[i].title,
|
||||
feedTypes[linkNodes[i].type],
|
||||
linkNodes[i].href);
|
||||
var feed = recognizeFeedFromLink(linkNodes[i], gDocument.nodePrincipal);
|
||||
if (feed) {
|
||||
var type = feed.type;
|
||||
if (type in feedTypes)
|
||||
type = feedTypes[type];
|
||||
else
|
||||
type = feedTypes["application/rss+xml"];
|
||||
addRow(feed.title, type, feed.href);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#
|
||||
# Contributor(s):
|
||||
# Alec Flett <alecf@netscape.com>
|
||||
# Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -579,3 +580,71 @@ function openNewWindowWith(aURL, aDocument, aPostData, aAllowThirdPartyFixup)
|
|||
aURL, charsetArg, referrerURI, aPostData,
|
||||
aAllowThirdPartyFixup);
|
||||
}
|
||||
|
||||
/**
|
||||
* recognizeFeedFromLink: recognizes RSS/ATOM feeds from DOM link elements.
|
||||
*
|
||||
* @param aLink
|
||||
* The DOM link element to check for representing a feed.
|
||||
* @param aPrincipal
|
||||
* The principal of the document, used for security check.
|
||||
* @return object
|
||||
* The feed object containing href, type, and title properties,
|
||||
* if successful, otherwise null.
|
||||
*/
|
||||
function recognizeFeedFromLink(aLink, aPrincipal)
|
||||
{
|
||||
if (!aLink || !aPrincipal)
|
||||
return null;
|
||||
|
||||
var erel = aLink.rel;
|
||||
var etype = aLink.type;
|
||||
var etitle = aLink.title;
|
||||
const rssTitleRegex = /(^|\s)rss($|\s)/i;
|
||||
var rels = {};
|
||||
|
||||
if (erel) {
|
||||
for each (var relValue in erel.split(/\s+/))
|
||||
rels[relValue] = true;
|
||||
}
|
||||
var isFeed = rels.feed;
|
||||
|
||||
if (!isFeed && (!rels.alternate || rels.stylesheet || !etype))
|
||||
return null;
|
||||
|
||||
if (!isFeed) {
|
||||
// Use type value
|
||||
etype = etype.replace(/^\s+/, "");
|
||||
etype = etype.replace(/\s+$/, "");
|
||||
etype = etype.replace(/\s*;.*/, "");
|
||||
etype = etype.toLowerCase();
|
||||
isFeed = (etype == "application/rss+xml" ||
|
||||
etype == "application/atom+xml");
|
||||
if (!isFeed) {
|
||||
// really slimy: general XML types with magic letters in the title
|
||||
isFeed = ((etype == "text/xml" || etype == "application/xml" ||
|
||||
etype == "application/rdf+xml") && rssTitleRegex.test(etitle));
|
||||
}
|
||||
}
|
||||
|
||||
if (isFeed) {
|
||||
try {
|
||||
urlSecurityCheck(aLink.href,
|
||||
aPrincipal,
|
||||
Components.interfaces.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
|
||||
}
|
||||
catch (ex) {
|
||||
dump(ex.message);
|
||||
return null; // doesn't pass security check
|
||||
}
|
||||
|
||||
// successful! return the feed
|
||||
return {
|
||||
href: aLink.href,
|
||||
type: etype,
|
||||
title: aLink.title
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
# Contributor(s):
|
||||
# Daniel Brooks <db48x@yahoo.com>
|
||||
# Mike Kowalski <mikejk@ameritech.net>
|
||||
# Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -68,6 +69,7 @@ generalSiteIdentity=This web site is owned by %S\nThis has been verified by %S
|
|||
|
||||
feedRss=RSS
|
||||
feedAtom=Atom
|
||||
feedXML=XML
|
||||
|
||||
securityCertText=This web site provides a certificate to verify its identity.
|
||||
securityNoIdentity=This web site does not supply identity information.
|
||||
|
|
Загрузка…
Ссылка в новой задаче