| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 * Copyright (c) 2010 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 | |
| 4 * LICENSE file. | |
| 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 | |
| 13 chrome.extension.onRequest.addListener(function(request, sender) { | |
| 14 if (request.msg == "feedIcon") { | |
| 15 // We have received a list of feed urls found on the page. | |
| 16 // Enable the page action icon. | |
| 17 feedData[sender.tab.id] = request.feeds; | |
| 18 chrome.pageAction.setTitle( | |
| 19 { tabId: sender.tab.id, | |
| 20 title: chrome.i18n.getMessage("rss_subscription_action_title")}); | |
| 21 chrome.pageAction.show(sender.tab.id); | |
| 22 } else if (request.msg == "feedDocument") { | |
| 23 // We received word from the content script that this document | |
| 24 // is an RSS feed (not just a document linking to the feed). | |
| 25 // So, we go straight to the subscribe page in a new tab and | |
| 26 // navigate back on the current page (to get out of the xml page). | |
| 27 // We don't want to navigate in-place because trying to go back | |
| 28 // from the subscribe page takes us back to the xml page, which | |
| 29 // will redirect to the subscribe page again (we don't support a | |
| 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 } | |
| 38 }); | |
| 39 | |
| 40 chrome.tabs.onRemoved.addListener(function(tabId) { | |
| 41 delete feedData[tabId]; | |
| 42 }); | |
| 43 | |
| 44 // On Linux, popups aren't supported yet, so Chrome will call into us | |
| 45 // when the user clicks on the icon in the OmniBox. | |
| 46 chrome.pageAction.onClicked.addListener(function(tab) { | |
| 47 chrome.windows.get(tab.windowId, function(window) { | |
| 48 // We need to know if we are the active window, because the tab may | |
| 49 // have moved to another window and we don't want to execute this | |
| 50 // action multiple times. | |
| 51 if (window.focused) { | |
| 52 // Create a new tab showing the subscription page with the right | |
| 53 // feed URL. | |
| 54 var url = "subscribe.html?" + | |
| 55 encodeURIComponent(feedData[tab.id][0].href); | |
| 56 chrome.tabs.create({url: url, windowId: window.id}); | |
| 57 } | |
| 58 }); | |
| 59 }); | |
| 60 </script> | |
| 61 </head> | |
| 62 </html> | |
| OLD | NEW |