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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // Get the badge background color for a tab, or the default if no color 213 // Get the badge background color for a tab, or the default if no color
214 // was set. 214 // was set.
215 SkColor GetBadgeBackgroundColor(int tab_id) const { 215 SkColor GetBadgeBackgroundColor(int tab_id) const {
216 return GetValue(&badge_background_color_, tab_id); 216 return GetValue(&badge_background_color_, tab_id);
217 } 217 }
218 218
219 // Set this action's badge visibility on a specific tab. This takes 219 // Set this action's badge visibility on a specific tab. This takes
220 // care of any appropriate transition animations. Returns true if 220 // care of any appropriate transition animations. Returns true if
221 // the appearance has changed. 221 // the appearance has changed.
222 bool SetAppearance(int tab_id, Appearance value); 222 bool SetAppearance(int tab_id, Appearance value);
223 // The declarative appearance overrides a default appearance but is overridden
224 // by an appearance set directly on the tab.
225 void DeclarativeShow(int tab_id);
226 void UndoDeclarativeShow(int tab_id);
227
223 // Get the badge visibility for a tab, or the default badge visibility 228 // Get the badge visibility for a tab, or the default badge visibility
224 // if none was set. 229 // if none was set.
225 bool GetIsVisible(int tab_id) const { 230 bool GetIsVisible(int tab_id) const {
226 return GetValue(&appearance_, tab_id) != INVISIBLE; 231 return GetDeclarativeValue(&appearance_,
232 &declarative_show_count_, ACTIVE,
233 tab_id)
234 != INVISIBLE;
227 } 235 }
228 236
229 // True if the tab's action wants the user's attention. 237 // True if the tab's action wants the user's attention.
230 bool WantsAttention(int tab_id) const { 238 bool WantsAttention(int tab_id) const {
231 return GetValue(&appearance_, tab_id) == WANTS_ATTENTION; 239 return GetDeclarativeValue(&appearance_,
240 &declarative_show_count_, ACTIVE,
241 tab_id)
242 == WANTS_ATTENTION;
232 } 243 }
233 244
234 // Remove all tab-specific state. 245 // Remove all tab-specific state.
235 void ClearAllValuesForTab(int tab_id); 246 void ClearAllValuesForTab(int tab_id);
236 247
237 // If the specified tab has a badge, paint it into the provided bounds. 248 // If the specified tab has a badge, paint it into the provided bounds.
238 void PaintBadge(gfx::Canvas* canvas, const gfx::Rect& bounds, int tab_id); 249 void PaintBadge(gfx::Canvas* canvas, const gfx::Rect& bounds, int tab_id);
239 250
240 // Returns icon image with badge for specified tab. 251 // Returns icon image with badge for specified tab.
241 gfx::ImageSkia GetIconWithBadge(const gfx::ImageSkia& icon, 252 gfx::ImageSkia GetIconWithBadge(const gfx::ImageSkia& icon,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 T GetValue(const std::map<int, T>* map, int tab_id) const { 287 T GetValue(const std::map<int, T>* map, int tab_id) const {
277 typename std::map<int, T>::const_iterator iter = map->find(tab_id); 288 typename std::map<int, T>::const_iterator iter = map->find(tab_id);
278 if (iter != map->end()) { 289 if (iter != map->end()) {
279 return iter->second; 290 return iter->second;
280 } else { 291 } else {
281 iter = map->find(kDefaultTabId); 292 iter = map->find(kDefaultTabId);
282 return iter != map->end() ? iter->second : ValueTraits<T>::CreateEmpty(); 293 return iter != map->end() ? iter->second : ValueTraits<T>::CreateEmpty();
283 } 294 }
284 } 295 }
285 296
297 // Returns the first of map[tab_id], declarative_map[tab_id] (uses
298 // |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!
299 // that's defined. Don't return this result to an extension's background page
300 // because the declarative state can leak information about hosts the
301 // extension doesn't have permission to access.
302 template<class T>
303 T GetDeclarativeValue(const std::map<int, T>* map,
304 const std::map<int, int>* declarative_map,
305 T declarative_value,
306 int tab_id) const {
307 typename std::map<int, T>::const_iterator iter = map->find(tab_id);
308 if (iter != map->end())
309 return iter->second;
310
311 if (ContainsKey(*declarative_map, tab_id))
312 return declarative_value;
313
314 iter = map->find(kDefaultTabId);
315 if (iter != map->end())
316 return iter->second;
317
318 return ValueTraits<T>::CreateEmpty();
319 }
320
286 // The id for the extension this action belongs to (as defined in the 321 // The id for the extension this action belongs to (as defined in the
287 // extension manifest). 322 // extension manifest).
288 const std::string extension_id_; 323 const std::string extension_id_;
289 324
290 const extensions::ActionInfo::Type action_type_; 325 const extensions::ActionInfo::Type action_type_;
291 326
292 // Each of these data items can have both a global state (stored with the key 327 // Each of these data items can have both a global state (stored with the key
293 // kDefaultTabId), or tab-specific state (stored with the tab_id as the key). 328 // kDefaultTabId), or tab-specific state (stored with the tab_id as the key).
294 std::map<int, GURL> popup_url_; 329 std::map<int, GURL> popup_url_;
295 std::map<int, std::string> title_; 330 std::map<int, std::string> title_;
296 std::map<int, gfx::ImageSkia> icon_; 331 std::map<int, gfx::ImageSkia> icon_;
297 std::map<int, std::string> badge_text_; 332 std::map<int, std::string> badge_text_;
298 std::map<int, SkColor> badge_background_color_; 333 std::map<int, SkColor> badge_background_color_;
299 std::map<int, SkColor> badge_text_color_; 334 std::map<int, SkColor> badge_text_color_;
300 std::map<int, Appearance> appearance_; 335 std::map<int, Appearance> appearance_;
301 336
337 // Declarative state exists for two reasons: First, we need to hide it from
338 // the extension's background/event page to avoid leaking data from hosts the
339 // extension doesn't have permission to access. Second, the action's state
340 // gets both reset and given its declarative values in response to a
341 // WebContentsObserver::DidNavigateMainFrame event, and there's no way to set
342 // those up to be called in the right order.
343
344 // 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.
345 std::map<int, int> declarative_show_count_;
346
302 // IconAnimations are destroyed by a delayed task on the UI message loop so 347 // IconAnimations are destroyed by a delayed task on the UI message loop so
303 // that even if the Extension and ExtensionAction are destroyed on a non-UI 348 // that even if the Extension and ExtensionAction are destroyed on a non-UI
304 // thread, the animation will still only be touched from the UI thread. This 349 // thread, the animation will still only be touched from the UI thread. This
305 // causes the WeakPtr in this map to become NULL. GetIconAnimation() removes 350 // causes the WeakPtr in this map to become NULL. GetIconAnimation() removes
306 // NULLs to prevent the map from growing without bound. 351 // NULLs to prevent the map from growing without bound.
307 mutable std::map<int, base::WeakPtr<IconAnimation> > icon_animation_; 352 mutable std::map<int, base::WeakPtr<IconAnimation> > icon_animation_;
308 353
309 // ExtensionIconSet containing paths to bitmaps from which default icon's 354 // ExtensionIconSet containing paths to bitmaps from which default icon's
310 // image representations will be selected. 355 // image representations will be selected.
311 scoped_ptr<const ExtensionIconSet> default_icon_; 356 scoped_ptr<const ExtensionIconSet> default_icon_;
(...skipping 10 matching lines...) Expand all
322 }; 367 };
323 368
324 template<> 369 template<>
325 struct ExtensionAction::ValueTraits<int> { 370 struct ExtensionAction::ValueTraits<int> {
326 static int CreateEmpty() { 371 static int CreateEmpty() {
327 return -1; 372 return -1;
328 } 373 }
329 }; 374 };
330 375
331 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_ 376 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698