1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/modules/Feeds.jsm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,52 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +this.EXPORTED_SYMBOLS = [ "Feeds" ]; 1.11 + 1.12 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); 1.13 + 1.14 +XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils", 1.15 + "resource://gre/modules/BrowserUtils.jsm"); 1.16 + 1.17 +const Ci = Components.interfaces; 1.18 + 1.19 +this.Feeds = { 1.20 + 1.21 + /** 1.22 + * isValidFeed: checks whether the given data represents a valid feed. 1.23 + * 1.24 + * @param aLink 1.25 + * An object representing a feed with title, href and type. 1.26 + * @param aPrincipal 1.27 + * The principal of the document, used for security check. 1.28 + * @param aIsFeed 1.29 + * Whether this is already a known feed or not, if true only a security 1.30 + * check will be performed. 1.31 + */ 1.32 + isValidFeed: function(aLink, aPrincipal, aIsFeed) { 1.33 + if (!aLink || !aPrincipal) 1.34 + return false; 1.35 + 1.36 + var type = aLink.type.toLowerCase().replace(/^\s+|\s*(?:;.*)?$/g, ""); 1.37 + if (!aIsFeed) { 1.38 + aIsFeed = (type == "application/rss+xml" || 1.39 + type == "application/atom+xml"); 1.40 + } 1.41 + 1.42 + if (aIsFeed) { 1.43 + try { 1.44 + BrowserUtils.urlSecurityCheck(aLink.href, aPrincipal, 1.45 + Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL); 1.46 + return type || "application/rss+xml"; 1.47 + } 1.48 + catch(ex) { 1.49 + } 1.50 + } 1.51 + 1.52 + return null; 1.53 + }, 1.54 + 1.55 +};