summaryrefslogtreecommitdiffstats
path: root/chrome/test/data
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-01 21:57:00 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-01 21:57:00 +0000
commitd7eaf5753249cbb6e95441b07e00a6349c7afe89 (patch)
tree7d03c6ce6a182a52465ad4d8f410117c2430a6bf /chrome/test/data
parent92ac30171a8334bc1691096abccf004ed02d0d42 (diff)
downloadchromium_src-d7eaf5753249cbb6e95441b07e00a6349c7afe89.zip
chromium_src-d7eaf5753249cbb6e95441b07e00a6349c7afe89.tar.gz
chromium_src-d7eaf5753249cbb6e95441b07e00a6349c7afe89.tar.bz2
PageActions can now specify multiple icons and switch between them
using optional parameters to enableForTab. BUG=http://crbug.com/11906 TEST=None Review URL: http://codereview.chromium.org/149046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19772 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/data')
-rw-r--r--chrome/test/data/extensions/page_action.crxbin6515 -> 16810 bytes
-rw-r--r--chrome/test/data/extensions/samples/subscribe_page_action/background.html51
-rw-r--r--chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16-subscribed.pngbin0 -> 450 bytes
-rw-r--r--chrome/test/data/extensions/samples/subscribe_page_action/manifest.json5
4 files changed, 51 insertions, 5 deletions
diff --git a/chrome/test/data/extensions/page_action.crx b/chrome/test/data/extensions/page_action.crx
index 2a397c8..7420c32 100644
--- a/chrome/test/data/extensions/page_action.crx
+++ b/chrome/test/data/extensions/page_action.crx
Binary files differ
diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/background.html b/chrome/test/data/extensions/samples/subscribe_page_action/background.html
index e85e5a6..0eeca7e 100644
--- a/chrome/test/data/extensions/samples/subscribe_page_action/background.html
+++ b/chrome/test/data/extensions/samples/subscribe_page_action/background.html
@@ -1,8 +1,13 @@
<html>
+<head>
<script>
// The Page Action ID.
var pageActionId = "RssPageAction";
+ // The icons to use. These correspond to the icons listed in the manifest.
+ var subscribeId = 0;
+ var alreadySubscribedId = 1;
+
// The window this Page Action is associated with.
var windowId = -1;
@@ -15,6 +20,32 @@
// The feed URL found on the page.
var feedUrl = "";
+ // The URL to use to check if user is subscribed already.
+ var subscribedUrl = "http://www.google.com/reader/api/0/subscribed?s=feed%2F";
+
+ // The XMLHttpRequest object that checks if you are already subscribed.
+ var req;
+
+ // The status of whether you have already subscribed to this feed or not.
+ var alreadySubscribed = false;
+
+ function EnableIcon(subscribed) {
+ alreadySubscribed = subscribed;
+ if (!alreadySubscribed) {
+ chrome.pageActions.enableForTab(
+ pageActionId, {tabId: tabId,
+ url: pageUrl,
+ title: "Click to subscribe...",
+ iconId: subscribeId});
+ } else {
+ chrome.pageActions.enableForTab(
+ pageActionId, {tabId: tabId,
+ url: pageUrl,
+ title: "You are already subscribed to this feed",
+ iconId: alreadySubscribedId});
+ }
+ }
+
chrome.self.onConnect.addListener(function(port) {
windowId = port.tab.windowId;
tabId = port.tab.id;
@@ -28,17 +59,29 @@
// 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});
+ EnableIcon(false); // Not subscribed (as far as we know, might change).
+
+ // But also check the server to see if we have already subscribed so
+ // that we can update the status.
+ feedUrl = encodeURIComponent(feedUrl);
+ req = new XMLHttpRequest();
+ req.onload = handleResponse;
+ req.open("GET", subscribedUrl + feedUrl, false);
+ req.send(null);
}
});
});
+ function handleResponse() {
+ if (req.responseText == "true")
+ EnableIcon(true); // true == Already suscribed.
+ }
+
// 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) {
+ if (!alreadySubscribed && 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.
@@ -46,7 +89,6 @@
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});
}
@@ -55,4 +97,5 @@
});
});
</script>
+</head>
</html>
diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16-subscribed.png b/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16-subscribed.png
new file mode 100644
index 0000000..0369a6b37
--- /dev/null
+++ b/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16-subscribed.png
Binary files differ
diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/manifest.json b/chrome/test/data/extensions/samples/subscribe_page_action/manifest.json
index 9c34a50..6a8f225 100644
--- a/chrome/test/data/extensions/samples/subscribe_page_action/manifest.json
+++ b/chrome/test/data/extensions/samples/subscribe_page_action/manifest.json
@@ -16,7 +16,10 @@
{
"id": "RssPageAction",
"name": "Subscribe to this feed",
- "icon": "feed-icon-16x16.png"
+ "icons": [
+ "feed-icon-16x16.png",
+ "feed-icon-16x16-subscribed.png"
+ ]
}
]
} \ No newline at end of file