diff --git a/ubiquity/modules/default_feed_plugin.js b/ubiquity/modules/default_feed_plugin.js index f4765d30..593745bd 100644 --- a/ubiquity/modules/default_feed_plugin.js +++ b/ubiquity/modules/default_feed_plugin.js @@ -74,7 +74,7 @@ function DefaultFeedPlugin(feedManager, messageService, webJsm, baseLocalUri, infos) { for each (let info in infos) { - let uri = Utils.url(baseUri + info.page); + let uri = Utils.uri(baseUri + info.page); if (!feedManager.isUnsubscribedFeed(uri)) { let lcs = new LocalUriCodeSource(baseLocalUri + info.source); @@ -88,30 +88,30 @@ function DefaultFeedPlugin(feedManager, messageService, webJsm, } }; - this.onSubscribeClick = function DFP_onSubscribeClick(targetDoc, - commandsUrl, - mimetype) { - var {location} = targetDoc; + this.onSubscribeClick = function DFP_onSubscribeClick(pageUrl, targetLink) { + var doc = targetLink.ownerDocument; + var title = targetLink.title || Utils.gist.getName(doc) || doc.title; + var commandsUrl = targetLink.href; // Clicking on "subscribe" takes them to the warning page: - var title = Utils.gist.getName(targetDoc) || targetDoc.title; var confirmUrl = CONFIRM_URL + Utils.paramsToString({ - url: location.href, + url: pageUrl, sourceUrl: commandsUrl, title: title, }); - if (!isTrustedUrl(commandsUrl, mimetype)) { + if (!isTrustedUrl(commandsUrl, targetLink.type)) { Utils.openUrlInBrowser(confirmUrl); return; } function onSuccess(data) { feedManager.addSubscribedFeed({ - url: location.href, + url: pageUrl, sourceUrl: commandsUrl, title: title, canAutoUpdate: true, - sourceCode: data}); + sourceCode: data, + }); Utils.openUrlInBrowser(confirmUrl); } @@ -119,7 +119,9 @@ function DefaultFeedPlugin(feedManager, messageService, webJsm, webJsm.jQuery.ajax({ url: commandsUrl, dataType: "text", - success: onSuccess}); + success: onSuccess, + error: Utils.log, + }); else onSuccess(""); }; diff --git a/ubiquity/modules/feedmanager.js b/ubiquity/modules/feedmanager.js index 3452dadc..7d08e71f 100644 --- a/ubiquity/modules/feedmanager.js +++ b/ubiquity/modules/feedmanager.js @@ -77,13 +77,13 @@ const DEFAULT_FEED_TYPE = "commands"; function FeedManager(annSvc) { this._annSvc = annSvc; - this._plugins = {}; - this._feeds = {}; + this._plugins = {__proto__: null}; + this._feeds = {__proto__: null}; this._hub = new EventHub(); this._hub.attachMethods(this); } -var FMgrProto = FeedManager.prototype = {}; +var FMgrProto = FeedManager.prototype; // === {{{FeedManager#registerPlugin()}}} === // Registers a feed plugin with the feed manager. For an example feed @@ -163,7 +163,7 @@ FMgrProto.getFeedForUrl = function FMgr_getFeedForUrl(url) { FMgrProto.addSubscribedFeed = function FMgr_addSubscribedFeed(info) { let annSvc = this._annSvc; - let uri = Utils.url(info.url); + let uri = Utils.uri(info.url); let expiration = annSvc[info.isBuiltIn ? "EXPIRE_SESSION" : "EXPIRE_NEVER"]; annSvc.removePageAnnotation(uri, FEED_UNSUBSCRIBED_ANNO); @@ -189,6 +189,7 @@ FMgrProto.addSubscribedFeed = function FMgr_addSubscribedFeed(info) { new Date().toUTCString(), 0, expiration); this._hub.notifyListeners("subscribe", uri); + return this; }; // === {{{FeedManager#isSubscribedFeed()}}} === @@ -222,59 +223,42 @@ FMgrProto.isUnsubscribedFeed = function FMgr_isSubscribedFeed(uri) ( FMgrProto.installToWindow = function FMgr_installToWindow(window) { var self = this; - function onPageWithCommands(plugin, pageUrl, commandsUrl, document, - mimetype) { - if (!self.isSubscribedFeed(pageUrl)) - self.showNotification(plugin, document, commandsUrl, mimetype); + function onRelatedPage(plugin, pageUrl, link) { + if (self.isSubscribedFeed(pageUrl) || + self.isSubscribedFeed(link.href)) return; + + Utils.notify({ + target: link.ownerDocument, + label: (plugin.notifyMessage || + L("ubiquity.feedmanager.newcommandfound")), + value: "ubiquity_notify_feed_available", + priority: "INFO_MEDIUM", + buttons: [{ + accessKey: "S", + callback: function onSubscribeClick(notification, button) { + plugin.onSubscribeClick(pageUrl, link); + }, + label: L("ubiquity.feedmanager.subscribe"), + }]}); } // Watch for any tags of the form // on pages and add annotations for them if they exist. - function onLinkAdded(event) { + window.addEventListener("DOMLinkAdded", function onLinkAdded(event) { var {target} = event; - if (!(target.rel in self._plugins) || !target.href) - return; + if (!(target.rel in self._plugins) || !target.href) return; var pageUrl = target.baseURI; var hashIndex = pageUrl.indexOf("#"); - if (hashIndex !== -1) - pageUrl = pageUrl.slice(0, hashIndex); + if (hashIndex !== -1) pageUrl = pageUrl.slice(0, hashIndex); - onPageWithCommands(self._plugins[target.rel], - pageUrl, - target.href, - target.ownerDocument, - target.type); - } - - window.addEventListener("DOMLinkAdded", onLinkAdded, false); + onRelatedPage(self._plugins[target.rel], pageUrl, target); + }, false); for each (let plugin in this._plugins) if ("installToWindow" in plugin) plugin.installToWindow(window); }; -// TODO: Add Documentation for this -FMgrProto.showNotification = function showNotification(plugin, - targetDoc, - commandsUrl, - mimetype, - notify_message) { - Utils.notify({ - target: targetDoc, - label: (notify_message || - plugin.notify_message || - L("ubiquity.feedmanager.newcommandfound")), - value: "ubiquity_notify_commands_available", - priority: "INFO_MEDIUM", - buttons: [{ - accessKey: "S", - callback: function onSubscribeClick(notification, button) { - plugin.onSubscribeClick(targetDoc, commandsUrl, mimetype); - }, - label: L("ubiquity.feedmanager.subscribe"), - }]}); -}; - // === {{{FeedManager#finalize()}}} === // Performs any necessary cleanup on the feed manager. Should be // called when the feed manager no longer needs to be used. diff --git a/ubiquity/modules/locked_down_feed_plugin.js b/ubiquity/modules/locked_down_feed_plugin.js index 89ac45cf..e8cb0590 100644 --- a/ubiquity/modules/locked_down_feed_plugin.js +++ b/ubiquity/modules/locked_down_feed_plugin.js @@ -77,18 +77,16 @@ function LockedDownFeedPlugin(feedManager, messageService, webJsm) { this.type = "locked-down-commands"; - // === {{{LDFP#onSubscribeClick()}}} === + // === {{{LDFP#onSubscribeClick(pageUrl, targetLink)}}} === // // This method is called by the feed manager whenever the user clicks // the "Subscribe..." button for any LDFP feed that they're presented // with. // - // * {{{targetDoc}}} is the HTML document of the page with a - // {{{}}} tag. - // * {{{commandsUrl}}} is the URL pointed to by the {{{href}}} - // attribute of the aforementioned {{{}}} tag. - // * {{{mimetype}}} is the MIME type specified by the {{{type}}} - // attribute of the aforementioned {{{}}} tag. + // * {{{pageUrl}}} is the URL of the page that includes {{{targetLink}}}. + // Its fragment (hash) part is stripped beforehand. + // * {{{targetLink}}} is the {{{}}} + // DOM element. // // This function has no return value. // @@ -97,14 +95,14 @@ function LockedDownFeedPlugin(feedManager, messageService, webJsm) { // the user to the feed and then displays a non-modal message // confirming the subscription. - this.onSubscribeClick = function LDFP_onSubscribeClick(targetDoc, - commandsUrl, - mimetype) { - feedManager.addSubscribedFeed({url: targetDoc.location.href, - title: targetDoc.title, - sourceUrl: commandsUrl, - type: this.type, - canAutoUpdate: true}); + this.onSubscribeClick = function LDFP_onSubscribeClick(pageUrl, targetLink) { + feedManager.addSubscribedFeed({ + url: pageUrl, + title: targetLink.title || targetLink.ownerDocument.title, + sourceUrl: targetLink.href, + type: this.type, + canAutoUpdate: true, + }); //errorToLocalize messageService.displayMessage("Subscription successful!"); };