diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-06 16:46:11 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-06 16:46:11 +0000 |
commit | ce5c4504531cfd32972dfd123f98183c3706951a (patch) | |
tree | 679f14d1ea5738a6bedb752a4c61b7f3c50efde1 /chrome/browser/extensions/extension_page_actions_module.cc | |
parent | aec92f83d096ca57ab6ce515ae7063b8081b630e (diff) | |
download | chromium_src-ce5c4504531cfd32972dfd123f98183c3706951a.zip chromium_src-ce5c4504531cfd32972dfd123f98183c3706951a.tar.gz chromium_src-ce5c4504531cfd32972dfd123f98183c3706951a.tar.bz2 |
PageActions now work across tabs and windows.
The extension system now provides TabId to extensions so it is now possible to activate PageActions in other tabs besides the first in the tab strip. :)
BUG=None
TEST=None (requires a PageAction extension to test against).
Review URL: http://codereview.chromium.org/109046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15415 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_page_actions_module.cc')
-rw-r--r-- | chrome/browser/extensions/extension_page_actions_module.cc | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/chrome/browser/extensions/extension_page_actions_module.cc b/chrome/browser/extensions/extension_page_actions_module.cc index edf08dd..bf23f65 100644 --- a/chrome/browser/extensions/extension_page_actions_module.cc +++ b/chrome/browser/extensions/extension_page_actions_module.cc @@ -10,6 +10,7 @@ #include "chrome/browser/extensions/extension.h" #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/tab_contents/navigation_entry.h" bool EnablePageActionFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); @@ -25,39 +26,33 @@ bool EnablePageActionFunction::RunImpl() { std::string url; EXTENSION_FUNCTION_VALIDATE(action->GetString(L"url", &url)); - Browser* browser = BrowserList::GetLastActive(); - if (!browser) + // Find the TabContents that contains this tab id. + TabContents* contents = NULL; + ExtensionTabUtil::GetTabById(tab_id, profile(), NULL, NULL, &contents, NULL); + if (!contents) return false; - // HACK: We need to figure out the tab index from the tab_id (pending). - // For now we only support page actions in the first tab in the strip (tab 0). - int tab_index = 0; - - TabStripModel* tab_strip = browser->tabstrip_model(); - TabContents* contents = tab_strip->GetTabContentsAt(tab_index); - - // Not needed when we stop hard-coding the tab index. - tab_id = ExtensionTabUtil::GetTabId(contents); + // Make sure the URL hasn't changed. + // TODO(finnur): Add an error message here when there is a way to. + if (url != contents->controller().GetActiveEntry()->url().spec()) + return false; // Find our extension. Extension* extension = NULL; - if (profile()->GetExtensionsService()) { - const ExtensionList* extensions = - profile()->GetExtensionsService()->extensions(); - for (ExtensionList::const_iterator iter = extensions->begin(); - iter != extensions->end(); ++iter) { - if ((*iter)->id() == extension_id()) { - extension = (*iter); - break; // Found our extension. - } - } - } + ExtensionsService* service = profile()->GetExtensionsService(); + if (service) + extension = service->GetExtensionByID(extension_id()); + else + NOTREACHED(); + if (!extension) + return false; - if (!extension || - !extension->UpdatePageAction(page_action_id, tab_id, GURL(url))) + const PageAction* page_action = extension->GetPageAction(page_action_id); + if (!page_action) return false; - // Broadcast notifications when the UI should be updated. + // Set visible and broadcast notifications that the UI should be updated. + contents->EnablePageAction(page_action); contents->NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS); return true; |