diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-19 22:42:38 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-19 22:42:38 +0000 |
commit | d922d0034bf1a8c8584fa3bbfd54ff94ae1ede92 (patch) | |
tree | e8821ffef0de908390b7e02ced5ff0ac04642b68 /chrome | |
parent | 2f25166d30d865f92e1c68e2489070d924f8da7d (diff) | |
download | chromium_src-d922d0034bf1a8c8584fa3bbfd54ff94ae1ede92.zip chromium_src-d922d0034bf1a8c8584fa3bbfd54ff94ae1ede92.tar.gz chromium_src-d922d0034bf1a8c8584fa3bbfd54ff94ae1ede92.tar.bz2 |
Add the RSS page action extension.
BUG=12060
TEST=Enable this extension, browse to a page with a Feed and an RSS icon should show up in the Omnibox. Clicking it brings you to a subscribe page. No feed preview is displayed.
Review URL: http://codereview.chromium.org/115536
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16425 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
6 files changed, 132 insertions, 0 deletions
diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16.png b/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16.png Binary files differnew file mode 100644 index 0000000..4d5673f --- /dev/null +++ b/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16.png diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-64x64.png b/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-64x64.png Binary files differnew file mode 100644 index 0000000..3eebee5 --- /dev/null +++ b/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-64x64.png diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/feed_finder.js b/chrome/test/data/extensions/samples/subscribe_page_action/feed_finder.js new file mode 100644 index 0000000..91cea10 --- /dev/null +++ b/chrome/test/data/extensions/samples/subscribe_page_action/feed_finder.js @@ -0,0 +1,24 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+if (window == top) {
+ findFeeds();
+ window.addEventListener("focus", findFeeds);
+}
+
+function findFeeds() {
+ // Find all the RSS link elements.
+ var result = document.evaluate(
+ '//link[@rel="alternate"][contains(@type, "rss") or ' +
+ 'contains(@type, "atom") or contains(@type, "rdf")]',
+ document, null, 0, null);
+
+ var feeds = [];
+ var item;
+ while (item = result.iterateNext())
+ feeds.push(item.href);
+
+ // Notify the extension of the feed URLs we found.
+ chrome.extension.connect().postMessage(feeds);
+}
diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/manifest.json b/chrome/test/data/extensions/samples/subscribe_page_action/manifest.json new file mode 100644 index 0000000..0121968 --- /dev/null +++ b/chrome/test/data/extensions/samples/subscribe_page_action/manifest.json @@ -0,0 +1,26 @@ +{
+ "name": "RSS Subscription Extension",
+ "description": "Adds one-click subscription to your toolbar",
+ "version": "1.0",
+ "permissions": [
+ "http://*/*"
+ ],
+ "toolstrips": [
+ "toolstrip.html"
+ ],
+ "content_scripts": [
+ {
+ "matches": ["http://*/*"],
+ "js": ["feed_finder.js"]
+ }
+ ],
+ "page_actions": [
+ {
+ "id": "RssPageAction",
+ "name": "The PageAction for RSS subscriptions",
+ "tooltip": "Click to subscribe to this feed",
+ "icon": "feed-icon-16x16.png",
+ "type": "tab"
+ }
+ ]
+}
\ No newline at end of file diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/subscribe.html b/chrome/test/data/extensions/samples/subscribe_page_action/subscribe.html new file mode 100644 index 0000000..ec4e3b7 --- /dev/null +++ b/chrome/test/data/extensions/samples/subscribe_page_action/subscribe.html @@ -0,0 +1,24 @@ +<html>
+<head>
+<title>Subscribe to feed</title>
+
+<script type="text/javascript">
+ function navigate() {
+ var select = document.getElementById("readers");
+ // Grab the URL from the querystring, removing question mark at the front.
+ var feed_url = document.location.search.substring(1);
+ var url = select.options[select.selectedIndex].value + feed_url;
+ document.location = url;
+ }
+</script>
+</head>
+
+<body>
+ <img src="feed-icon-64x64.png" align="absmiddle" />
+ Subscribe to this feed using:
+ <select id="readers">
+ <option value="http://www.google.com/reader/view/feed/">Google</option>
+ </select>
+ <button onclick="navigate();">Subscribe Now</button>
+</body>
+</html>
diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/toolstrip.html b/chrome/test/data/extensions/samples/subscribe_page_action/toolstrip.html new file mode 100644 index 0000000..10185b1 --- /dev/null +++ b/chrome/test/data/extensions/samples/subscribe_page_action/toolstrip.html @@ -0,0 +1,58 @@ +<html>
+<script>
+ // The Page Action ID.
+ var pageActionId = "RssPageAction";
+
+ // The window this Page Action is associated with.
+ var windowId = -1;
+
+ // The TabId this Page Action is associated with.
+ var tabId = -1;
+
+ // The URL of the page that contains the feed.
+ var pageUrl = "";
+
+ // The feed URL found on the page.
+ var feedUrl = "";
+
+ chrome.self.onConnect.addListener(function(port) {
+ windowId = port.tab.windowId;
+ tabId = port.tab.id;
+ pageUrl = port.tab.url;
+
+ // 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.
+ 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) {
+ chrome.pageActions.enableForTab(pageActionId,
+ {tabId: tabId, url: pageUrl});
+ }
+ });
+ });
+
+ // Chrome will call into us when the user clicks on the icon in the OmniBox.
+ chrome.pageActions.onExecute.addListener(function(reply) {
+ chrome.windows.getCurrent(function(window) {
+ chrome.tabs.get(reply.data.tabId, function(tab) {
+ if (window.focused) {
+ // 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 (reply.pageActionId == pageActionId &&
+ reply.data.tabUrl == pageUrl) {
+ // Create a new tab showing the subscription page with the right
+ // feed URL.
+ var url = "http://www.google.com/reader/view/feed/" + feedUrl;
+ chrome.tabs.create({url: "subscribe.html?" + feedUrl,
+ windowId: windowId});
+ }
+ }
+ });
+ });
+ });
+</script>
+</html>
|