Bug 1031527 - Remove dup fd from ParamTraits<MagicGrallocBufferHandle>::Read(). r...
[gecko.git] / browser / modules / Feeds.jsm
blobf3977ee5ee1c3cdfe1a8b0a885835ffc3d9c81a3
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   },