browser/modules/Feeds.jsm
author tbirdbld
Fri, 13 Feb 2015 17:51:11 -0500
branchGECKO360b1_2015021317_RELBRANCH
changeset 243774 fa98dcdc9406fa36b418b7dc97ebb6a8b7d50ef2
parent 184945 639da97e170319492d16f4036d90f87d0d26d310
child 272049 a9878c3dd8a975849c76e5770998e3bba8eb506d
permissions -rw-r--r--
Added THUNDERBIRD_36_0b1_RELEASE THUNDERBIRD_36_0b1_BUILD2 tag(s) for changeset bbb250fc79b7. DONTBUILD CLOSED TREE a=release

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

this.EXPORTED_SYMBOLS = [ "Feeds" ];

Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils",
                                  "resource://gre/modules/BrowserUtils.jsm");

const Ci = Components.interfaces;

this.Feeds = {

  /**
   * isValidFeed: checks whether the given data represents a valid feed.
   *
   * @param  aLink
   *         An object representing a feed with title, href and type.
   * @param  aPrincipal
   *         The principal of the document, used for security check.
   * @param  aIsFeed
   *         Whether this is already a known feed or not, if true only a security
   *         check will be performed.
   */
  isValidFeed: function(aLink, aPrincipal, aIsFeed) {
    if (!aLink || !aPrincipal)
      return false;

    var type = aLink.type.toLowerCase().replace(/^\s+|\s*(?:;.*)?$/g, "");
    if (!aIsFeed) {
      aIsFeed = (type == "application/rss+xml" ||
                 type == "application/atom+xml");
    }

    if (aIsFeed) {
      try {
        BrowserUtils.urlSecurityCheck(aLink.href, aPrincipal,
                                      Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
        return type || "application/rss+xml";
      }
      catch(ex) {
      }
    }

    return null;
  },

};