Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Unified Diff: chrome/browser/extensions/extension_action.h

Issue 11547033: Implement declarativeContent API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Dominic's comments Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_action.h
diff --git a/chrome/browser/extensions/extension_action.h b/chrome/browser/extensions/extension_action.h
index dacd961ee03bb531df0289fc9037730a03071ccf..6b8f37bb1fd1bef6c1be2787ad86d5a8ba475345 100644
--- a/chrome/browser/extensions/extension_action.h
+++ b/chrome/browser/extensions/extension_action.h
@@ -220,15 +220,26 @@ class ExtensionAction {
// care of any appropriate transition animations. Returns true if
// the appearance has changed.
bool SetAppearance(int tab_id, Appearance value);
+ // The declarative appearance overrides a default appearance but is overridden
+ // by an appearance set directly on the tab.
+ void DeclarativeShow(int tab_id);
+ void UndoDeclarativeShow(int tab_id);
+
// Get the badge visibility for a tab, or the default badge visibility
// if none was set.
bool GetIsVisible(int tab_id) const {
- return GetValue(&appearance_, tab_id) != INVISIBLE;
+ return GetDeclarativeValue(&appearance_,
+ &declarative_show_count_, ACTIVE,
+ tab_id)
+ != INVISIBLE;
}
// True if the tab's action wants the user's attention.
bool WantsAttention(int tab_id) const {
- return GetValue(&appearance_, tab_id) == WANTS_ATTENTION;
+ return GetDeclarativeValue(&appearance_,
+ &declarative_show_count_, ACTIVE,
+ tab_id)
+ == WANTS_ATTENTION;
}
// Remove all tab-specific state.
@@ -283,6 +294,30 @@ class ExtensionAction {
}
}
+ // Returns the first of map[tab_id], declarative_map[tab_id] (uses
+ // |declarative_value|), map[kDefaultTabId], or ValueTraits<T>::CreateEmpty()
battre 2013/01/18 16:13:40 I think the "declarative_map[tab_id] (uses |declar
Jeffrey Yasskin 2013/01/22 08:01:22 This function was too general anyway; I've rewritt
battre 2013/01/22 12:54:52 Beautiful!
+ // that's defined. Don't return this result to an extension's background page
+ // because the declarative state can leak information about hosts the
+ // extension doesn't have permission to access.
+ template<class T>
+ T GetDeclarativeValue(const std::map<int, T>* map,
+ const std::map<int, int>* declarative_map,
+ T declarative_value,
+ int tab_id) const {
+ typename std::map<int, T>::const_iterator iter = map->find(tab_id);
+ if (iter != map->end())
+ return iter->second;
+
+ if (ContainsKey(*declarative_map, tab_id))
+ return declarative_value;
+
+ iter = map->find(kDefaultTabId);
+ if (iter != map->end())
+ return iter->second;
+
+ return ValueTraits<T>::CreateEmpty();
+ }
+
// The id for the extension this action belongs to (as defined in the
// extension manifest).
const std::string extension_id_;
@@ -299,6 +334,16 @@ class ExtensionAction {
std::map<int, SkColor> badge_text_color_;
std::map<int, Appearance> appearance_;
+ // Declarative state exists for two reasons: First, we need to hide it from
+ // the extension's background/event page to avoid leaking data from hosts the
+ // extension doesn't have permission to access. Second, the action's state
+ // gets both reset and given its declarative values in response to a
+ // WebContentsObserver::DidNavigateMainFrame event, and there's no way to set
+ // those up to be called in the right order.
+
+ // Maps tab_id to the number of times
battre 2013/01/18 16:13:40 nit: this sentence seems incomplete and lacks a ".
Jeffrey Yasskin 2013/01/22 08:01:22 That's not a nit. ;) Thanks; fixed.
+ std::map<int, int> declarative_show_count_;
+
// IconAnimations are destroyed by a delayed task on the UI message loop so
// that even if the Extension and ExtensionAction are destroyed on a non-UI
// thread, the animation will still only be touched from the UI thread. This

Powered by Google App Engine
This is Rietveld 408576698