Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 this.EXPORTED_SYMBOLS = [ "Feeds" ];
9 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
11 XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils",
12 "resource://gre/modules/BrowserUtils.jsm");
14 const Ci = Components.interfaces;
16 this.Feeds = {
18 /**
19 * isValidFeed: checks whether the given data represents a valid feed.
20 *
21 * @param aLink
22 * An object representing a feed with title, href and type.
23 * @param aPrincipal
24 * The principal of the document, used for security check.
25 * @param aIsFeed
26 * Whether this is already a known feed or not, if true only a security
27 * check will be performed.
28 */
29 isValidFeed: function(aLink, aPrincipal, aIsFeed) {
30 if (!aLink || !aPrincipal)
31 return false;
33 var type = aLink.type.toLowerCase().replace(/^\s+|\s*(?:;.*)?$/g, "");
34 if (!aIsFeed) {
35 aIsFeed = (type == "application/rss+xml" ||
36 type == "application/atom+xml");
37 }
39 if (aIsFeed) {
40 try {
41 BrowserUtils.urlSecurityCheck(aLink.href, aPrincipal,
42 Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
43 return type || "application/rss+xml";
44 }
45 catch(ex) {
46 }
47 }
49 return null;
50 },
52 };