summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc40
-rw-r--r--chrome/browser/tab_contents/tab_contents.h23
2 files changed, 40 insertions, 23 deletions
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index a526207..43c7c27 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -609,26 +609,33 @@ void TabContents::SetPageActionEnabled(const ExtensionAction* page_action,
const std::string& title,
int icon_id) {
DCHECK(page_action);
-
- if (!enable &&
- enabled_page_actions_.end() == enabled_page_actions_.find(page_action)) {
- return; // Don't need to disable twice.
- }
-
- if (enable) {
- enabled_page_actions_[page_action].reset(
- new ExtensionActionState(title, icon_id));
- } else {
- enabled_page_actions_.erase(page_action);
- }
+ ExtensionActionState* state = GetOrCreatePageActionState(page_action);
+ state->set_hidden(!enable);
+ state->set_title(title);
+ state->set_icon_index(icon_id);
+ state->set_icon(NULL);
}
const ExtensionActionState* TabContents::GetPageActionState(
const ExtensionAction* page_action) {
- if (enabled_page_actions_.end() == enabled_page_actions_.find(page_action))
+ if (page_actions_.end() == page_actions_.find(page_action))
return NULL;
- return enabled_page_actions_[page_action].get();
+ return page_actions_[page_action].get();
+}
+
+ExtensionActionState* TabContents::GetOrCreatePageActionState(
+ const ExtensionAction* page_action) {
+ if (page_actions_.end() == page_actions_.find(page_action)) {
+ page_actions_[page_action].reset(
+ new ExtensionActionState(page_action->title(), 0));
+ }
+
+ return page_actions_[page_action].get();
+}
+
+void TabContents::PageActionStateChanged() {
+ NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
}
void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
@@ -1400,12 +1407,12 @@ void TabContents::DidNavigateMainFramePostCommit(
fav_icon_helper_.FetchFavIcon(details.entry->url());
// Disable all page actions, unless this is an in-page navigation.
- if (!enabled_page_actions_.empty()) {
+ if (!page_actions_.empty()) {
url_canon::Replacements<char> replacements;
replacements.ClearRef();
if (params.url.ReplaceComponents(replacements) !=
params.referrer.ReplaceComponents(replacements)) {
- enabled_page_actions_.clear();
+ page_actions_.clear();
}
}
@@ -2625,4 +2632,3 @@ void TabContents::Observe(NotificationType type,
void TabContents::set_encoding(const std::string& encoding) {
encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
}
-
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index 99db09c..47b4243 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -269,6 +269,16 @@ class TabContents : public PageNavigator,
const ExtensionActionState* GetPageActionState(
const ExtensionAction* page_action);
+ // Same as above, but creates an enable state if it doesn't exist. The return
+ // value can be updated. The caller should call PageActionStateChanged when
+ // done modifying the state.
+ ExtensionActionState* GetOrCreatePageActionState(
+ const ExtensionAction* page_action);
+
+ // Call this after updating a ExtensionActionState object returned by
+ // GetOrCreatePageActionState to notify clients about the changes.
+ void PageActionStateChanged();
+
// Whether the tab is in the process of being destroyed.
// Added as a tentative work-around for focus related bug #4633. This allows
// us not to store focus when a tab is being closed.
@@ -1111,12 +1121,13 @@ class TabContents : public PageNavigator,
// Data for 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 ExtensionAction*, linked_ptr<ExtensionActionState> >
- enabled_page_actions_;
+ // A map of page actions that this tab knows about (and a state object that
+ // can be used to update the title, icon, visibilty, etc used for the page
+ // action). This map is cleared every time the mainframe navigates and
+ // populated by the PageAction extension API.
+ typedef std::map< const ExtensionAction*, linked_ptr<ExtensionActionState> >
+ PageActionStateMap;
+ PageActionStateMap page_actions_;
// Data for misc internal state ----------------------------------------------