|
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/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 this.EXPORTED_SYMBOLS = [ "Feeds" ]; |
|
8 |
|
9 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
10 |
|
11 XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils", |
|
12 "resource://gre/modules/BrowserUtils.jsm"); |
|
13 |
|
14 const Ci = Components.interfaces; |
|
15 |
|
16 this.Feeds = { |
|
17 |
|
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; |
|
32 |
|
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 } |
|
38 |
|
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 } |
|
48 |
|
49 return null; |
|
50 }, |
|
51 |
|
52 }; |