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

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: Sync past refactoring and fix build+tests 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..a80019f4feb3422de9357e6ea45c9efd9de8e57f 100644
--- a/chrome/browser/extensions/extension_action.h
+++ b/chrome/browser/extensions/extension_action.h
@@ -220,15 +220,22 @@ 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 overrided
+ // by an appearance set directly on the tab.
+ void SetDeclarativeAppearance(int tab_id, Appearance value);
+ void ClearDeclarativeAppearance(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_appearance_, 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_appearance_, tab_id)
+ == WANTS_ATTENTION;
}
// Remove all tab-specific state.
@@ -283,6 +290,30 @@ class ExtensionAction {
}
}
+ // Returns the first of map[tab_id], declarative_map[tab_id],
+ // map[kDefaultTabId], or ValueTraits<T>::CreateEmpty() 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, T>* declarative_map,
+ int tab_id) const {
+ typename std::map<int, T>::const_iterator iter = map->find(tab_id);
+ if (iter != map->end())
+ return iter->second;
+
+ iter = declarative_map->find(tab_id);
+ if (iter != declarative_map->end())
+ return iter->second;
+
+ 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_;
@@ -298,6 +329,13 @@ class ExtensionAction {
std::map<int, SkColor> badge_background_color_;
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.
+ std::map<int, Appearance> declarative_appearance_;
// 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

Powered by Google App Engine
This is Rietveld 408576698