diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-01 21:57:00 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-01 21:57:00 +0000 |
commit | d7eaf5753249cbb6e95441b07e00a6349c7afe89 (patch) | |
tree | 7d03c6ce6a182a52465ad4d8f410117c2430a6bf /chrome/browser/tab_contents | |
parent | 92ac30171a8334bc1691096abccf004ed02d0d42 (diff) | |
download | chromium_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/browser/tab_contents')
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 28 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.h | 24 |
2 files changed, 35 insertions, 17 deletions
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index c4906ce..0884317 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -565,23 +565,31 @@ void TabContents::SetIsCrashed(bool state) { } void TabContents::SetPageActionEnabled(const PageAction* page_action, - bool enable) { + bool enable, + const std::string& title, + int icon_id) { DCHECK(page_action); - if (enable == IsPageActionEnabled(page_action)) - return; // Don't need to do anything more. + if (!enable && + enabled_page_actions_.end() == enabled_page_actions_.find(page_action)) { + return; // Don't need to disable twice. + } - if (enable) - enabled_page_actions_.insert(page_action); - else + if (enable) { + enabled_page_actions_[page_action].reset( + new PageActionState(title, icon_id)); + } else { enabled_page_actions_.erase(page_action); + } } -bool TabContents::IsPageActionEnabled(const PageAction* page_action) { - DCHECK(page_action); - return enabled_page_actions_.end() != enabled_page_actions_.find(page_action); -} +const PageActionState* TabContents::GetPageActionState( + const PageAction* page_action) { + if (enabled_page_actions_.end() == enabled_page_actions_.find(page_action)) + return NULL; + return enabled_page_actions_[page_action].get(); +} void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) { if (delegate_) diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 5b4fa7b..f81c725 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -32,6 +32,7 @@ #include "chrome/common/gears_api.h" #include "chrome/common/navigation_types.h" #include "chrome/common/notification_registrar.h" +#include "chrome/common/page_action.h" #include "chrome/common/property_bag.h" #include "chrome/common/renderer_preferences.h" #include "net/base/load_states.h" @@ -254,10 +255,17 @@ class TabContents : public PageNavigator, void SetIsCrashed(bool state); // Adds/removes a page action to the list of page actions that are active in + // this tab. The parameter |title| (if not empty) can be used to override the + // page action title for this tab and |icon_id| specifies an icon index + // (defined in the manifest) to use instead of the first icon (for this tab). + void SetPageActionEnabled(const PageAction* page_action, bool enable, + const std::string& title, int icon_id); + + // Returns the page action state for this tab. The pair returns contains + // the title (string) for the page action and the icon index to use (int). + // If this function returns NULL it means the page action is not enabled for // this tab. - void SetPageActionEnabled(const PageAction* page_action, bool enable); - // Checks to see if the PageAction should be visible in this tab. - bool IsPageActionEnabled(const PageAction* page_action); + const PageActionState* GetPageActionState(const PageAction* page_action); // Whether the tab is in the process of being destroyed. // Added as a tentative work-around for focus related bug #4633. This allows @@ -1036,10 +1044,12 @@ class TabContents : public PageNavigator, // Data for Page Actions ----------------------------------------------------- - // A set of page actions that are enabled in this tab. This list is cleared - // every time the mainframe navigates and populated by the PageAction - // extension API. - std::set<const PageAction*> enabled_page_actions_; + // A map of page actions that are enabled in this tab (and a state object + // that can be used to override the title and icon used for the page action). + // This map is cleared every time the mainframe navigates and populated by the + // PageAction extension API. + std::map< const PageAction*, linked_ptr<PageActionState> > + enabled_page_actions_; // Data for misc internal state ---------------------------------------------- |