diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-07-18 08:24:24 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-07-18 08:24:24 +0200 |
commit | fc61780b35af913801d72086456f493f63197da6 (patch) | |
tree | f85891288a7bd988da9f0f15ae64e5c63f00d493 /application/basilisk/modules/Feeds.jsm | |
parent | 69f7f9e5f1475891ce11cc4f431692f965b0cd30 (diff) | |
parent | 50d3e596bbe89c95615f96eb71f6bc5be737a1db (diff) | |
download | UXP-fc61780b35af913801d72086456f493f63197da6.tar UXP-fc61780b35af913801d72086456f493f63197da6.tar.gz UXP-fc61780b35af913801d72086456f493f63197da6.tar.lz UXP-fc61780b35af913801d72086456f493f63197da6.tar.xz UXP-fc61780b35af913801d72086456f493f63197da6.zip |
Merge commit '50d3e596bbe89c95615f96eb71f6bc5be737a1db' into Basilisk-releasev2018.07.18
# Conflicts:
# browser/app/profile/firefox.js
# browser/components/preferences/jar.mn
Diffstat (limited to 'application/basilisk/modules/Feeds.jsm')
-rw-r--r-- | application/basilisk/modules/Feeds.jsm | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/application/basilisk/modules/Feeds.jsm b/application/basilisk/modules/Feeds.jsm new file mode 100644 index 000000000..179d2b83d --- /dev/null +++ b/application/basilisk/modules/Feeds.jsm @@ -0,0 +1,104 @@ +/* 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"); +Components.utils.import("resource://gre/modules/Services.jsm"); + +XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils", + "resource://gre/modules/BrowserUtils.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow", + "resource:///modules/RecentWindow.jsm"); + +const { interfaces: Ci, classes: Cc } = Components; + +this.Feeds = { + init() { + let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager); + mm.addMessageListener("WCCR:registerProtocolHandler", this); + mm.addMessageListener("WCCR:registerContentHandler", this); + + Services.ppmm.addMessageListener("WCCR:setAutoHandler", this); + Services.ppmm.addMessageListener("FeedConverter:addLiveBookmark", this); + }, + + receiveMessage(aMessage) { + let data = aMessage.data; + switch (aMessage.name) { + case "WCCR:registerProtocolHandler": { + let registrar = Cc["@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"]. + getService(Ci.nsIWebContentHandlerRegistrar); + registrar.registerProtocolHandler(data.protocol, data.uri, data.title, + aMessage.target); + break; + } + + case "WCCR:registerContentHandler": { + let registrar = Cc["@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"]. + getService(Ci.nsIWebContentHandlerRegistrar); + registrar.registerContentHandler(data.contentType, data.uri, data.title, + aMessage.target); + break; + } + + case "WCCR:setAutoHandler": { + let registrar = Cc["@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"]. + getService(Ci.nsIWebContentConverterService); + registrar.setAutoHandler(data.contentType, data.handler); + break; + } + + case "FeedConverter:addLiveBookmark": { + let topWindow = RecentWindow.getMostRecentBrowserWindow(); + topWindow.PlacesCommandHook.addLiveBookmark(data.spec, data.title, data.subtitle) + .catch(Components.utils.reportError); + break; + } + } + }, + + /** + * 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) { + // re-create the principal as it may be a CPOW. + // once this can't be a CPOW anymore, we should just use aPrincipal instead + // of creating a new one. + let principalURI = BrowserUtils.makeURIFromCPOW(aPrincipal.URI); + let principalToCheck = + Services.scriptSecurityManager.createCodebasePrincipal(principalURI, aPrincipal.originAttributes); + try { + BrowserUtils.urlSecurityCheck(aLink.href, principalToCheck, + Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL); + return type || "application/rss+xml"; + } + catch (ex) { + } + } + + return null; + }, + +}; |