| OLD | NEW |
| 1 <!-- | 1 /** |
| 2 * Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this | 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. Use of this |
| 3 * source code is governed by a BSD-style license that can be found in the | 3 * source code is governed by a BSD-style license that can be found in the |
| 4 * LICENSE file. | 4 * LICENSE file. |
| 5 --> | 5 */ |
| 6 <html> | |
| 7 <head> | |
| 8 <script> | |
| 9 // A dictionary keyed off of tabId that keeps track of data per tab (for | |
| 10 // example what feedUrl was detected in the tab). | |
| 11 var feedData = {}; | |
| 12 | 6 |
| 13 chrome.extension.onRequest.addListener(function(request, sender) { | 7 // A dictionary keyed off of tabId that keeps track of data per tab (for |
| 14 if (request.msg == "feedIcon") { | 8 // example what feedUrl was detected in the tab). |
| 15 // We have received a list of feed urls found on the page. | 9 var feedData = {}; |
| 16 // Enable the page action icon. | 10 |
| 17 feedData[sender.tab.id] = request.feeds; | 11 chrome.extension.onRequest.addListener(function(request, sender) { |
| 18 chrome.pageAction.setTitle( | 12 if (request.msg == "feedIcon") { |
| 19 { tabId: sender.tab.id, | 13 // First validate that all the URLs have the right schema. |
| 20 title: chrome.i18n.getMessage("rss_subscription_action_title")}); | 14 var input = []; |
| 21 chrome.pageAction.show(sender.tab.id); | 15 for (var i = 0; i < request.feeds.length; ++i) { |
| 22 } else if (request.msg == "feedDocument") { | 16 var a = document.createElement('a'); |
| 23 // We received word from the content script that this document | 17 a.href = request.feeds[i].href; |
| 24 // is an RSS feed (not just a document linking to the feed). | 18 if (a.protocol == "http:" || a.protocol == "https:") { |
| 25 // So, we go straight to the subscribe page in a new tab and | 19 input.push(request.feeds[i]); |
| 26 // navigate back on the current page (to get out of the xml page). | 20 } else { |
| 27 // We don't want to navigate in-place because trying to go back | 21 console.log('Warning: feed source rejected (wrong protocol): ' + |
| 28 // from the subscribe page takes us back to the xml page, which | 22 request.feeds[i].href); |
| 29 // will redirect to the subscribe page again (we don't support a | 23 } |
| 30 // location.replace equivalant in the Tab navigation system). | |
| 31 chrome.tabs.executeScript(sender.tab.id, | |
| 32 {code: "if (history.length > 1) " + | |
| 33 "history.go(-1); else window.close();"}); | |
| 34 var url = "subscribe.html?" + encodeURIComponent(request.href); | |
| 35 url = chrome.extension.getURL(url); | |
| 36 chrome.tabs.create({url: url, index: sender.tab.index}); | |
| 37 } | 24 } |
| 38 }); | |
| 39 | 25 |
| 40 chrome.tabs.onRemoved.addListener(function(tabId) { | 26 if (input.length == 0) |
| 41 delete feedData[tabId]; | 27 return; // We've rejected all the input, so abort. |
| 42 }); | |
| 43 | 28 |
| 44 // On Linux, popups aren't supported yet, so Chrome will call into us | 29 // We have received a list of feed urls found on the page. |
| 45 // when the user clicks on the icon in the OmniBox. | 30 // Enable the page action icon. |
| 46 chrome.pageAction.onClicked.addListener(function(tab) { | 31 feedData[sender.tab.id] = input; |
| 47 chrome.windows.get(tab.windowId, function(window) { | 32 chrome.pageAction.setTitle( |
| 48 // We need to know if we are the active window, because the tab may | 33 { tabId: sender.tab.id, |
| 49 // have moved to another window and we don't want to execute this | 34 title: chrome.i18n.getMessage("rss_subscription_action_title") |
| 50 // action multiple times. | 35 }); |
| 51 if (window.focused) { | 36 chrome.pageAction.show(sender.tab.id); |
| 52 // Create a new tab showing the subscription page with the right | 37 } else if (request.msg == "feedDocument") { |
| 53 // feed URL. | 38 // We received word from the content script that this document |
| 54 var url = "subscribe.html?" + | 39 // is an RSS feed (not just a document linking to the feed). |
| 55 encodeURIComponent(feedData[tab.id][0].href); | 40 // So, we go straight to the subscribe page in a new tab and |
| 56 chrome.tabs.create({url: url, windowId: window.id}); | 41 // navigate back on the current page (to get out of the xml page). |
| 57 } | 42 // We don't want to navigate in-place because trying to go back |
| 58 }); | 43 // from the subscribe page takes us back to the xml page, which |
| 59 }); | 44 // will redirect to the subscribe page again (we don't support a |
| 60 </script> | 45 // location.replace equivalant in the Tab navigation system). |
| 61 </head> | 46 chrome.tabs.executeScript(sender.tab.id, |
| 62 </html> | 47 { code: "if (history.length > 1) " + |
| 48 "history.go(-1); else window.close();" |
| 49 }); |
| 50 var url = "subscribe.html?" + encodeURIComponent(request.href); |
| 51 url = chrome.extension.getURL(url); |
| 52 chrome.tabs.create({ url: url, index: sender.tab.index }); |
| 53 } |
| 54 }); |
| 55 |
| 56 chrome.tabs.onRemoved.addListener(function(tabId) { |
| 57 delete feedData[tabId]; |
| 58 }); |
| OLD | NEW |