forked from mirrors/gecko-dev
I'm not entirely certain that we need to pass the charset here, but it seems like it might be needed based on my reading of the code. This also fixes a test to mock a link node better (we must have an ownerDocument that will have a characterSet). MozReview-Commit-ID: 5L1dKocNX0h --HG-- extra : rebase_source : ce768f8144b83ac8e1d78dd7e2a362bd253028fc
90 lines
3.2 KiB
JavaScript
90 lines
3.2 KiB
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";
|
|
|
|
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 = {
|
|
// Listeners are added in nsBrowserGlue.js
|
|
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(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;
|
|
},
|
|
|
|
};
|