summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-15 03:24:36 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-15 03:24:36 +0000
commitcf9a246cf386c7af0fb6524ac5d025c0d4e8563a (patch)
tree914b55375eee47f6d21f2fc3f106c4ba506637ec /chrome/test
parent0c48c17f7ebcc0c8f79eba1aeae56d32b3c2f03f (diff)
downloadchromium_src-cf9a246cf386c7af0fb6524ac5d025c0d4e8563a.zip
chromium_src-cf9a246cf386c7af0fb6524ac5d025c0d4e8563a.tar.gz
chromium_src-cf9a246cf386c7af0fb6524ac5d025c0d4e8563a.tar.bz2
EFD now notifies EPM of renderviews created, which in turn notifies the renderer of page actions that it knows about.
Remove generic event "page-action-executed" in favor of page action specific event (sent as extension_id/page_action_id). In the bindings, we now setup events for each page action we know about so we can register for specific events, and not receive broadcast events from all page actions. To setup these events I added a GetCurrentPageActions() to extension_process_bindings.cc and a helper function GetCurrentExtensionId(). And, finally, I simplified the page action background page by removing the check to see if we are already subscribed to the feed (since we now support multiple feed readers, it doesn't make sense anymore to always check Google Reader). This check might make a comeback later in a different form. BUG=13936 TEST=The RSS sample extension should work as before. Review URL: http://codereview.chromium.org/155514 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20714 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/data/extensions/samples/subscribe_page_action/background.html101
-rw-r--r--chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16-subscribed.pngbin450 -> 0 bytes
-rw-r--r--chrome/test/data/extensions/samples/subscribe_page_action/manifest.json3
3 files changed, 27 insertions, 77 deletions
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 94761ff..4d14440 100644
--- a/chrome/test/data/extensions/samples/subscribe_page_action/background.html
+++ b/chrome/test/data/extensions/samples/subscribe_page_action/background.html
@@ -4,53 +4,14 @@
// The Page Action ID.
var pageActionId = "RssPageAction";
- // The icons to use. These correspond to the icons listed in the manifest.
+ // The icon to use. This corresponds to the icon listed in the manifest.
var subscribeId = 0;
- var alreadySubscribedId = 1;
- // 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 = "";
-
- // 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});
- }
- }
+ // A dictionary keyed off of tabId that keeps track of data per tab (for
+ // example what feedUrl was detected in the tab).
+ var feedData = {};
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.
@@ -59,49 +20,39 @@
// Let Chrome know that the PageAction needs to be enabled for this tabId
// and for the url of this page.
if (feedUrl) {
- 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);
+ feedData[port.tab.id] = {pageUrl: port.tab.url,
+ feedUrl: feedUrl};
+
+ chrome.pageActions.enableForTab(
+ pageActionId, {tabId: port.tab.id,
+ url: port.tab.url,
+ title: "Click to subscribe...",
+ iconId: subscribeId});
}
});
});
- 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.pageActions["RssPageAction"].addListener(function(reply) {
chrome.windows.getCurrent(function(window) {
chrome.tabs.get(reply.data.tabId, function(tab) {
- 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.
- if (reply.pageActionId == pageActionId &&
- reply.data.tabUrl == pageUrl) {
- // Create a new tab showing the subscription page with the right
- // feed URL.
- chrome.tabs.create({url: "subscribe.html?" + feedUrl,
- windowId: windowId});
- } else {
- console.log("Ignoring execute event.");
- console.log("PageActionId: " + reply.pageActionId + " == " +
- pageActionId);
- console.log("TabUrl : " + reply.data.tabUrl + " == " +
- pageUrl);
- }
+ // 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.
+ chrome.tabs.create({url: "subscribe.html?" +
+ feedData[reply.data.tabId].feedUrl,
+ windowId: window.windowId});
}
});
});
});
+
+ chrome.tabs.onRemoved.addListener(function(reply) {
+ feedData[reply.tabId] = null;
+ });
</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
deleted file mode 100644
index 0369a6b37..0000000
--- a/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16-subscribed.png
+++ /dev/null
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 5807816..7adaf8f 100644
--- a/chrome/test/data/extensions/samples/subscribe_page_action/manifest.json
+++ b/chrome/test/data/extensions/samples/subscribe_page_action/manifest.json
@@ -17,8 +17,7 @@
"id": "RssPageAction",
"name": "Subscribe to this feed",
"icons": [
- "feed-icon-16x16.png",
- "feed-icon-16x16-subscribed.png"
+ "feed-icon-16x16.png"
]
}
]