summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-09 23:48:06 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-09 23:48:06 +0000
commit300e84b6650e61c3ad44711794d26eda4ba049f1 (patch)
tree6e78dbe9a731dd4ecfa4f8a5d66ab8451f26b62c /chrome/test
parente2d8667b7a2bb47a25ddd9a74cbd627bf17b5c7e (diff)
downloadchromium_src-300e84b6650e61c3ad44711794d26eda4ba049f1.zip
chromium_src-300e84b6650e61c3ad44711794d26eda4ba049f1.tar.gz
chromium_src-300e84b6650e61c3ad44711794d26eda4ba049f1.tar.bz2
Add support for multiple feeds on a page by listing all the feeds
in a dropdown from the page action icon when you click on the icon. If the page has only one feed, the dropdown does not appear and the extension works as before. BUG=None TEST=Test this on a page with multiple feeds and make sure a dropdown appears when you click on the RSS icon and that clicking each feed name takes you to the extension 'subscribe?' page. Review URL: http://codereview.chromium.org/475007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34202 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/background.html31
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/feed_finder.js2
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/manifest.json9
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/popup.html89
4 files changed, 100 insertions, 31 deletions
diff --git a/chrome/test/data/extensions/subscribe_page_action/background.html b/chrome/test/data/extensions/subscribe_page_action/background.html
index a5d6772..6d0bfc1 100644
--- a/chrome/test/data/extensions/subscribe_page_action/background.html
+++ b/chrome/test/data/extensions/subscribe_page_action/background.html
@@ -9,39 +9,18 @@
var tab = port.sender.tab;
// This will get called from the content script using PostMessage.
- // |feedUrls| is a list of URL feeds found on the page. We only need 1 to
- // enable the PageAction icon in the Omnibox.
+ // |feedUrls| is a list of URL feeds found on the page.
port.onMessage.addListener(function(feedUrls) {
- feedUrl = feedUrls[0];
- // Let Chrome know that the PageAction needs to be enabled for this tabId
- // and for the url of this page.
- if (feedUrl) {
- feedData[tab.id] = { pageUrl: tab.url,
- feedUrl: feedUrl };
-
+ feedData[tab.id] = feedUrls;
+ if (feedUrls.length > 0) {
chrome.pageAction.setTitle({ tabId: tab.id,
- title: "Click to subscribe..." });
+ title: "Click to subscribe..."
+ });
chrome.pageAction.show(tab.id);
}
});
});
- // Chrome will call into us when the user clicks on the icon in the OmniBox.
- chrome.pageAction.onClicked.addListener(function(tab) {
- chrome.windows.get(tab.windowId, function(window) {
- // We need to know if we are the active window, because the tab may
- // have moved to another window and we don't want to execute this
- // action multiple times.
- if (window.focused) {
- // Create a new tab showing the subscription page with the right
- // feed URL.
- var url = "subscribe.html?" +
- encodeURIComponent(feedData[tab.id].feedUrl);
- chrome.tabs.create({url: url, windowId: window.id});
- }
- });
- });
-
chrome.tabs.onRemoved.addListener(function(reply) {
feedData[reply.tabId] = null;
});
diff --git a/chrome/test/data/extensions/subscribe_page_action/feed_finder.js b/chrome/test/data/extensions/subscribe_page_action/feed_finder.js
index 5261264..6d9c590 100644
--- a/chrome/test/data/extensions/subscribe_page_action/feed_finder.js
+++ b/chrome/test/data/extensions/subscribe_page_action/feed_finder.js
@@ -15,7 +15,7 @@ function findFeeds() {
var feeds = [];
var item;
while (item = result.iterateNext())
- feeds.push(item.href);
+ feeds.push({"href": item.href, "title": item.title});
// Notify the extension of the feed URLs we found.
chrome.extension.connect().postMessage(feeds);
diff --git a/chrome/test/data/extensions/subscribe_page_action/manifest.json b/chrome/test/data/extensions/subscribe_page_action/manifest.json
index 20886c1..3b79832 100644
--- a/chrome/test/data/extensions/subscribe_page_action/manifest.json
+++ b/chrome/test/data/extensions/subscribe_page_action/manifest.json
@@ -1,7 +1,7 @@
{
- "name": "RSS Subscription Extension",
- "description": "Adds one-click subscription to your toolbar",
- "version": "1.6.6",
+ "name": "RSS Subscription Extension (by Google)",
+ "description": "Adds one-click subscription to your toolbar.",
+ "version": "1.7",
"permissions": [
"tabs",
"http://*/*"
@@ -16,6 +16,7 @@
"icons": { "128": "feed-icon-128x128.png" },
"page_action": {
"default_title": "Subscribe to this feed",
- "default_icon": "feed-icon-16x16.png"
+ "default_icon": "feed-icon-16x16.png",
+ "popup": "popup.html"
}
}
diff --git a/chrome/test/data/extensions/subscribe_page_action/popup.html b/chrome/test/data/extensions/subscribe_page_action/popup.html
new file mode 100644
index 0000000..67b9339
--- /dev/null
+++ b/chrome/test/data/extensions/subscribe_page_action/popup.html
@@ -0,0 +1,89 @@
+<html>
+<head>
+<style>
+ body {
+ overflow-x: hidden;
+ }
+
+ .heading {
+ font-family: Helvetica, Arial;
+ font-size: small;
+ font-weight: bold;
+ margin-left: 2px;
+ }
+
+ .feedList {
+ font-family: Helvetica, Arial;
+ font-size: small;
+ vertical-align: bottom;
+ }
+</style>
+<script>
+function feedLink(url) {
+ var feed_link = document.createElement('a');
+ feed_link.href = url;
+ feed_link.addEventListener("click", onClick);
+ return feed_link;
+}
+
+function main() {
+ chrome.tabs.getSelected(null, function(tab) {
+ var feeds = chrome.extension.getBackgroundPage().feedData[tab.id];
+ if (feeds.length == 1) {
+ // Only one feed, no need for a bubble; go straight to the subscribe page.
+ preview(feeds[0].href);
+ } else {
+ var content = document.getElementById('content');
+ var heading = document.getElementById('heading');
+ heading.innerText = "Select feed:"
+ content.appendChild(document.createElement('br'));
+
+ var feed_list = document.createElement('table');
+ feed_list.style.width = "400";
+ for (var i = 0; i < feeds.length; ++i) {
+ // Create an RSS image and the anhor encapsulating it.
+ var img_link = feedLink(feeds[i].href);
+ var img = document.createElement('img');
+ img.src = "feed-icon-16x16.png"
+ img_link.appendChild(img);
+
+ // Create a text node and the anchor encapsulating it.
+ var text_link = feedLink(feeds[i].href);
+ text_link.appendChild(document.createTextNode(feeds[i].title));
+
+ // Add the data to a row in the table.
+ var tr = document.createElement('tr');
+ tr.className = "feedList";
+ var td = document.createElement('td');
+ td.width = "16";
+ td.appendChild(img_link);
+ var td2 = document.createElement('td');
+ td2.appendChild(text_link);
+ tr.appendChild(td);
+ tr.appendChild(td2);
+ feed_list.appendChild(tr);
+ }
+
+ content.appendChild(feed_list);
+ }
+ });
+}
+
+function onClick(event) {
+ var a = event.currentTarget;
+ preview(a.href);
+}
+
+function preview(feed_url) {
+ var url = "subscribe.html?" + encodeURIComponent(feed_url);
+ chrome.tabs.create({ url: url });
+ window.close();
+}
+</script>
+</head>
+<body onload="javascript:main()">
+ <div id="content">
+ <span id="heading" class="heading">Loading...</span>
+ </div>
+</body>
+</html>