|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 XPCOMUtils.defineLazyModuleGetter(this, "Feeds", |
|
7 "resource:///modules/Feeds.jsm"); |
|
8 |
|
9 function initFeedTab() |
|
10 { |
|
11 const feedTypes = { |
|
12 "application/rss+xml": gBundle.getString("feedRss"), |
|
13 "application/atom+xml": gBundle.getString("feedAtom"), |
|
14 "text/xml": gBundle.getString("feedXML"), |
|
15 "application/xml": gBundle.getString("feedXML"), |
|
16 "application/rdf+xml": gBundle.getString("feedXML") |
|
17 }; |
|
18 |
|
19 // get the feeds |
|
20 var linkNodes = gDocument.getElementsByTagName("link"); |
|
21 var length = linkNodes.length; |
|
22 for (var i = 0; i < length; i++) { |
|
23 var link = linkNodes[i]; |
|
24 if (!link.href) |
|
25 continue; |
|
26 |
|
27 var rel = link.rel && link.rel.toLowerCase(); |
|
28 var rels = {}; |
|
29 if (rel) { |
|
30 for each (let relVal in rel.split(/\s+/)) |
|
31 rels[relVal] = true; |
|
32 } |
|
33 |
|
34 if (rels.feed || (link.type && rels.alternate && !rels.stylesheet)) { |
|
35 var type = Feeds.isValidFeed(link, gDocument.nodePrincipal, "feed" in rels); |
|
36 if (type) { |
|
37 type = feedTypes[type] || feedTypes["application/rss+xml"]; |
|
38 addRow(link.title, type, link.href); |
|
39 } |
|
40 } |
|
41 } |
|
42 |
|
43 var feedListbox = document.getElementById("feedListbox"); |
|
44 document.getElementById("feedTab").hidden = feedListbox.getRowCount() == 0; |
|
45 } |
|
46 |
|
47 function onSubscribeFeed() |
|
48 { |
|
49 var listbox = document.getElementById("feedListbox"); |
|
50 openUILinkIn(listbox.selectedItem.getAttribute("feedURL"), "current", |
|
51 { ignoreAlt: true }); |
|
52 } |
|
53 |
|
54 function addRow(name, type, url) |
|
55 { |
|
56 var item = document.createElement("richlistitem"); |
|
57 item.setAttribute("feed", "true"); |
|
58 item.setAttribute("name", name); |
|
59 item.setAttribute("type", type); |
|
60 item.setAttribute("feedURL", url); |
|
61 document.getElementById("feedListbox").appendChild(item); |
|
62 } |