2014-02-09 01:41:30 +00:00
|
|
|
/* 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";
|
|
|
|
|
2018-02-23 19:50:01 +00:00
|
|
|
var EXPORTED_SYMBOLS = [ "Feeds" ];
|
2014-02-09 01:41:30 +00:00
|
|
|
|
2018-01-29 23:20:18 +00:00
|
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
2014-02-09 01:41:30 +00:00
|
|
|
|
2018-01-29 23:20:18 +00:00
|
|
|
ChromeUtils.defineModuleGetter(this, "BrowserUtils",
|
|
|
|
"resource://gre/modules/BrowserUtils.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "RecentWindow",
|
|
|
|
"resource:///modules/RecentWindow.jsm");
|
2014-02-09 01:41:30 +00:00
|
|
|
|
2018-02-23 19:50:01 +00:00
|
|
|
var Feeds = {
|
2017-04-23 20:02:49 +00:00
|
|
|
// Listeners are added in nsBrowserGlue.js
|
2015-08-01 00:03:37 +00:00
|
|
|
receiveMessage(aMessage) {
|
2016-01-04 23:59:44 +00:00
|
|
|
let data = aMessage.data;
|
2015-08-01 00:03:37 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-01-04 23:59:44 +00:00
|
|
|
|
|
|
|
case "WCCR:setAutoHandler": {
|
|
|
|
let registrar = Cc["@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"].
|
2016-02-23 16:53:49 +00:00
|
|
|
getService(Ci.nsIWebContentConverterService);
|
2016-01-04 23:59:44 +00:00
|
|
|
registrar.setAutoHandler(data.contentType, data.handler);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "FeedConverter:addLiveBookmark": {
|
|
|
|
let topWindow = RecentWindow.getMostRecentBrowserWindow();
|
|
|
|
topWindow.PlacesCommandHook.addLiveBookmark(data.spec, data.title, data.subtitle)
|
2018-02-28 17:51:33 +00:00
|
|
|
.catch(Cu.reportError);
|
2016-01-04 23:59:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-08-01 00:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
2014-02-09 01:41:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-12-29 23:34:54 +00:00
|
|
|
isValidFeed(aLink, aPrincipal, aIsFeed) {
|
2014-02-09 01:41:30 +00:00
|
|
|
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 {
|
2017-08-11 00:19:35 +00:00
|
|
|
let href = BrowserUtils.makeURI(aLink.href, aLink.ownerDocument.characterSet);
|
|
|
|
BrowserUtils.urlSecurityCheck(href, aPrincipal,
|
2014-02-09 01:41:30 +00:00
|
|
|
Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
|
|
|
|
return type || "application/rss+xml";
|
2016-12-31 02:47:25 +00:00
|
|
|
} catch (ex) {
|
2014-02-09 01:41:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|