diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-15 20:21:58 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-15 20:21:58 +0000 |
commit | 4577622518be7c7ddd4f3b45016d4fa68d253802 (patch) | |
tree | e09db89fdb34063d7dcb6ffc013821792ab3f38e /chrome/test | |
parent | 631d1ab9de83c531ca43b8134226eb247a4ee3aa (diff) | |
download | chromium_src-4577622518be7c7ddd4f3b45016d4fa68d253802.zip chromium_src-4577622518be7c7ddd4f3b45016d4fa68d253802.tar.gz chromium_src-4577622518be7c7ddd4f3b45016d4fa68d253802.tar.bz2 |
Retrying this patch. This was already reviewed by mpcomplete and the
only change is a fix for the UI test that broke and a small change to
event_bindings.cc (reviewed in-person).
ExtensionFunctionDispatcher now notifies ExtensionProcessManager 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.
TBR=mpcomplete
BUG=13936
TEST=The RSS sample extension should work as before.
Review URL: http://codereview.chromium.org/149683
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20782 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
3 files changed, 29 insertions, 83 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/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" ] } ] diff --git a/chrome/test/data/extensions/uitest/event_sink/test.html b/chrome/test/data/extensions/uitest/event_sink/test.html index 2520d48..5462243 100644 --- a/chrome/test/data/extensions/uitest/event_sink/test.html +++ b/chrome/test/data/extensions/uitest/event_sink/test.html @@ -1,4 +1,5 @@ -HOLA!!! +HOLA!!! If you dont see the message DONE, then there is an error in the script. +<br> <script type="text/javascript"> // This extension registers for all tab and window events, and whenever one @@ -47,11 +48,6 @@ HOLA!!! portToAutomation.postMessage(chrome.tabs.onRemoved.eventName_); }); - // Page action events. - chrome.pageActions.onExecute.addListener(function(info) { - portToAutomation.postMessage(chrome.pageActions.onExecute.eventName_); - }); - // Bookmark events. chrome.bookmarks.onAdded.addListener(function(info) { portToAutomation.postMessage(chrome.bookmarks.onAdded.eventName_); |