Commit 8869b45a authored by Ian Neal's avatar Ian Neal Committed by Frank-Rainer Grahl

Bug 1576126 - Port Bug 961529 "Add Feeds module" to SeaMonkey. r=frg a=frg

parent 3b3162fb
......@@ -1317,36 +1317,6 @@ function disablePopupBlockerNotifications()
Services.prefs.setBoolPref("privacy.popups.showBrowserMessage", false);
}
/**
* isValidFeed: checks whether the given data represents a valid feed.
*
* @param aData
* An object representing a feed with title, href and type.
* @param aPrincipal
* The principal of the document, used for security check.
* @param aIsFeed
* Whether this is already a known feed or not, if true only a security
* check will be performed.
*/
function isValidFeed(aData, aPrincipal, aIsFeed)
{
if (!aData || !aPrincipal)
return null;
var type = aData.type.toLowerCase().replace(/^\s+|\s*(?:;.*)?$/g, "");
if (aIsFeed || /^application\/(?:atom|rss)\+xml$/.test(type)) {
try {
urlSecurityCheck(aData.href, aPrincipal,
Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
return type || "application/rss+xml";
}
catch(ex) {
}
}
return null;
}
// Used as an onclick handler for UI elements with link-like behavior.
// e.g. onclick="checkForMiddleClick(this, event);"
function checkForMiddleClick(node, event) {
......
......@@ -2,6 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
XPCOMUtils.defineLazyModuleGetter(this, "Feeds",
"resource:///modules/Feeds.jsm");
/**
* LinkToolbarHandler is a Singleton that displays LINK elements
* and nodeLists of LINK elements in the Link Toolbar. It
......@@ -82,7 +85,7 @@ function(relAttribute, element)
isFeed = true;
// fall through
case "alternate":
if (isValidFeed(element, element.nodePrincipal, isFeed)) {
if (Feeds.isValidFeed(element, element.nodePrincipal, isFeed)) {
return "feed";
}
......
......@@ -3,6 +3,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
XPCOMUtils.defineLazyModuleGetter(this, "Feeds",
"resource:///modules/Feeds.jsm");
function initFeedTab()
{
const feedTypes = {
......@@ -25,7 +28,7 @@ function initFeedTab()
var isFeed = /(?:^|\s)feed(?:\s|$)/i.test(rel);
if (isFeed || (/(?:^|\s)alternate(?:\s|$)/i.test(rel) &&
!/(?:^|\s)stylesheet(?:\s|$)/i.test(rel))) {
var type = isValidFeed(link, link.nodePrincipal, isFeed);
var type = Feeds.isValidFeed(link, link.nodePrincipal, isFeed);
if (type) {
if (type in feedTypes)
type = feedTypes[type];
......
XPCOMUtils.defineLazyModuleGetter(this, "Feeds",
"resource:///modules/Feeds.jsm");
function test() {
var ioserv = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
......@@ -7,8 +10,15 @@ function test() {
var principal = secman.createCodebasePrincipal(exampleUri, {});
function testIsFeed(aTitle, aHref, aType, aKnown) {
var link = { title: aTitle, href: aHref, type: aType };
return isValidFeed(link, principal, aKnown);
var link = {
title: aTitle,
href: aHref,
type: aType,
ownerDocument: {
characterSet: "UTF-8"
}
};
return Feeds.isValidFeed(link, principal, aKnown);
}
var href = "http://example.com/feed/";
......
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var EXPORTED_SYMBOLS = [ "Feeds" ];
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils",
"resource://gre/modules/BrowserUtils.jsm");
var Feeds = {
/**
* isValidFeed: checks whether the given data represents a valid feed.
*
* @param aLink
* An object representing a feed with title, href and type.
* @param aPrincipal
* The principal of the document, used for security check.
* @param aIsFeed
* Whether this is already a known feed or not, if true only a security
* check will be performed.
*/
isValidFeed(aLink, aPrincipal, aIsFeed) {
if (!aLink || !aPrincipal)
return false;
var type = aLink.type.toLowerCase().replace(/^\s+|\s*(?:;.*)?$/g, "");
if (!aIsFeed) {
aIsFeed = (type == "application/rss+xml" ||
type == "application/atom+xml");
}
if (aIsFeed) {
try {
let href = BrowserUtils.makeURI(aLink.href, aLink.ownerDocument.characterSet)
BrowserUtils.urlSecurityCheck(href, aPrincipal,
Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
return type || "application/rss+xml";
} catch (ex) {
}
}
return null;
},
};
......@@ -6,6 +6,7 @@
XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
EXTRA_JS_MODULES += [
'Feeds.jsm',
'PermissionUI.jsm',
'RecentWindow.jsm',
'Sanitizer.jsm',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment