browser/modules/Feeds.jsm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 };

mercurial