suite/modules/Feeds.jsm
author Bill Gianopoulos <wgianopoulos@gmail.com>
Sun, 03 May 2020 08:41:59 -0400
changeset 39071 f0799dbf510175a46545e62bff136187f04cd9ab
parent 37744 8ef25eb8c092d8d57719260a8aa019e9b793dbd1
permissions -rw-r--r--
Bug 1635849 - Switch SeaMoneky build files to Python 3. r=frg Port Bug 1633037 "Remove all remaining references to $(PYTHON) across Makefiles". Port Bug 1599658 "makefiles: use py3_action instead of py_action"

/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80 filetype=javascript: */
/* 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";

var EXPORTED_SYMBOLS = [ "Feeds" ];

ChromeUtils.defineModuleGetter(this, "BrowserUtils",
  "resource://gre/modules/BrowserUtils.jsm");

var 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(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 {
        let href = BrowserUtils.makeURI(aLink.href, aLink.ownerDocument.characterSet)
        BrowserUtils.urlSecurityCheck(href, aPrincipal,
                                      Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
        return type || "application/rss+xml";
      } catch (ex) {
      }
    }

    return null;
  },

};