Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: chrome/test/data/extensions/subscribe_page_action/popup.js

Issue 12843037: Convert the RSS extension to event pages to avoid a dedicated background process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 function feedLink(url) { 5 function feedLink(url) {
6 var feed_link = document.createElement('a'); 6 var feed_link = document.createElement('a');
7 feed_link.href = url; 7 feed_link.href = url;
8 feed_link.addEventListener("click", onClick); 8 feed_link.addEventListener("click", onClick);
9 return feed_link; 9 return feed_link;
10 } 10 }
11 11
12 function main() { 12 function main() {
13 chrome.tabs.getSelected(null, function(tab) { 13 chrome.tabs.getSelected(null, function(tab) {
not at google - send to devlin 2013/04/08 04:39:55 null should be unnecessary now
Finnur 2013/04/08 12:59:24 Done.
14 var feeds = chrome.extension.getBackgroundPage().feedData[tab.id]; 14 chrome.storage.local.get(tab.id.toString(), function(result) {
not at google - send to devlin 2013/04/08 04:39:55 ditto
15 if (feeds.length == 1) { 15 var feeds = result[tab.id];
16 // Only one feed, no need for a bubble; go straight to the subscribe page. 16 if (feeds.length == 1) {
17 preview(feeds[0].href); 17 // Only one feed, no need for a bubble; go straight to the subscribe
18 } else { 18 // page.
19 var content = document.getElementById('content'); 19 preview(feeds[0].href);
20 var heading = document.getElementById('heading'); 20 } else {
21 heading.innerText = 21 var content = document.getElementById('content');
22 chrome.i18n.getMessage("rss_subscription_action_title"); 22 var heading = document.getElementById('heading');
23 content.appendChild(document.createElement('br')); 23 heading.innerText =
24 chrome.i18n.getMessage("rss_subscription_action_title");
25 content.appendChild(document.createElement('br'));
24 26
25 var feed_list = document.createElement('table'); 27 var feed_list = document.createElement('table');
26 feed_list.style.width = "400"; 28 feed_list.style.width = "400";
27 for (var i = 0; i < feeds.length; ++i) { 29 for (var i = 0; i < feeds.length; ++i) {
28 // Create an RSS image and the anhor encapsulating it. 30 // Create an RSS image and the anhor encapsulating it.
29 var img_link = feedLink(feeds[i].href); 31 var img_link = feedLink(feeds[i].href);
30 var img = document.createElement('img'); 32 var img = document.createElement('img');
31 img.src = "feed-icon-16x16.png"; 33 img.src = "feed-icon-16x16.png";
32 img_link.appendChild(img); 34 img_link.appendChild(img);
33 35
34 // Create a text node and the anchor encapsulating it. 36 // Create a text node and the anchor encapsulating it.
35 var text_link = feedLink(feeds[i].href); 37 var text_link = feedLink(feeds[i].href);
36 text_link.appendChild(document.createTextNode(feeds[i].title)); 38 text_link.appendChild(document.createTextNode(feeds[i].title));
37 39
38 // Add the data to a row in the table. 40 // Add the data to a row in the table.
39 var tr = document.createElement('tr'); 41 var tr = document.createElement('tr');
40 tr.className = "feedList"; 42 tr.className = "feedList";
41 var td = document.createElement('td'); 43 var td = document.createElement('td');
42 td.width = "16"; 44 td.width = "16";
43 td.appendChild(img_link); 45 td.appendChild(img_link);
44 var td2 = document.createElement('td'); 46 var td2 = document.createElement('td');
45 td2.appendChild(text_link); 47 td2.appendChild(text_link);
46 tr.appendChild(td); 48 tr.appendChild(td);
47 tr.appendChild(td2); 49 tr.appendChild(td2);
48 feed_list.appendChild(tr); 50 feed_list.appendChild(tr);
51 }
52
53 content.appendChild(feed_list);
49 } 54 }
50 55 });
51 content.appendChild(feed_list);
52 }
53 }); 56 });
54 } 57 }
55 58
56 function onClick(event) { 59 function onClick(event) {
57 var a = event.currentTarget; 60 var a = event.currentTarget;
58 preview(a.href); 61 preview(a.href);
59 } 62 }
60 63
61 function preview(feed_url) { 64 function preview(feed_url) {
62 // See if we need to skip the preview page and subscribe directly. 65 // See if we need to skip the preview page and subscribe directly.
63 var url = ""; 66 var url = "";
64 if (window.localStorage && window.localStorage.showPreviewPage == "No") { 67 if (window.localStorage && window.localStorage.showPreviewPage == "No") {
65 // Skip the preview. 68 // Skip the preview.
66 url = window.localStorage.defaultReader.replace("%s", escape(feed_url)); 69 url = window.localStorage.defaultReader.replace("%s", escape(feed_url));
67 } else { 70 } else {
68 // Show the preview page. 71 // Show the preview page.
69 url = "subscribe.html?" + encodeURIComponent(feed_url); 72 url = "subscribe.html?" + encodeURIComponent(feed_url);
70 } 73 }
71 chrome.tabs.create({ url: url }); 74 chrome.tabs.create({ url: url });
72 window.close(); 75 window.close();
73 } 76 }
74 77
75 // Init on DOM ready. 78 // Init on DOM ready.
76 document.addEventListener('DOMContentLoaded', main); 79 document.addEventListener('DOMContentLoaded', main);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698