michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: this.EXPORTED_SYMBOLS = [ "Feeds" ]; michael@0: michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils", michael@0: "resource://gre/modules/BrowserUtils.jsm"); michael@0: michael@0: const Ci = Components.interfaces; michael@0: michael@0: this.Feeds = { michael@0: michael@0: /** michael@0: * isValidFeed: checks whether the given data represents a valid feed. michael@0: * michael@0: * @param aLink michael@0: * An object representing a feed with title, href and type. michael@0: * @param aPrincipal michael@0: * The principal of the document, used for security check. michael@0: * @param aIsFeed michael@0: * Whether this is already a known feed or not, if true only a security michael@0: * check will be performed. michael@0: */ michael@0: isValidFeed: function(aLink, aPrincipal, aIsFeed) { michael@0: if (!aLink || !aPrincipal) michael@0: return false; michael@0: michael@0: var type = aLink.type.toLowerCase().replace(/^\s+|\s*(?:;.*)?$/g, ""); michael@0: if (!aIsFeed) { michael@0: aIsFeed = (type == "application/rss+xml" || michael@0: type == "application/atom+xml"); michael@0: } michael@0: michael@0: if (aIsFeed) { michael@0: try { michael@0: BrowserUtils.urlSecurityCheck(aLink.href, aPrincipal, michael@0: Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL); michael@0: return type || "application/rss+xml"; michael@0: } michael@0: catch(ex) { michael@0: } michael@0: } michael@0: michael@0: return null; michael@0: }, michael@0: michael@0: };