15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/observer_list.h"
10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/prefs/pref_change_registrar.h"
115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "base/scoped_observer.h"
1203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chrome/browser/extensions/extension_action.h"
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/keyed_service/core/keyed_service.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_registrar.h"
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/browser/extension_prefs.h"
185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "extensions/browser/extension_registry_observer.h"
19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "extensions/common/extension.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Browser;
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PrefService;
23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class Profile;
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
25effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochnamespace extensions {
265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuclass ExtensionRegistry;
27010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)class ExtensionSet;
28effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Model for the browser actions toolbar.
30f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class ExtensionToolbarModel : public content::NotificationObserver,
3103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                              public ExtensionActionAPI::Observer,
325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                              public ExtensionRegistryObserver,
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                              public KeyedService {
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
35effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ExtensionToolbarModel(Profile* profile, ExtensionPrefs* extension_prefs);
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~ExtensionToolbarModel();
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A class which is informed of changes to the model; represents the view of
398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // MVC. Also used for signaling view changes such as showing extension popups.
401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // TODO(devlin): Should this really be an observer? It acts more like a
411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // delegate.
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class Observer {
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   public:
4403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    // An extension has been added to the toolbar and should go at |index|.
4503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    virtual void ToolbarExtensionAdded(const Extension* extension,
4603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                                       int index) = 0;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    // The given |extension| should be removed from the toolbar.
4903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    virtual void ToolbarExtensionRemoved(const Extension* extension) = 0;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    // The given |extension| has been moved to |index|. |index| is the desired
5203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    // *final* index of the extension (that is, in the adjusted order, extension
5303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    // should be at |index|).
5403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    virtual void ToolbarExtensionMoved(const Extension* extension,
5503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                                       int index) = 0;
5603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
5703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    // Signals that the browser action for the given |extension| has been
5803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    // updated.
5903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    virtual void ToolbarExtensionUpdated(const Extension* extension) = 0;
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    // Signal the |extension| to show the popup now in the active window.
621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    // If |grant_active_tab| is true, then active tab permissions should be
631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    // given to the extension (only do this if this is through a user action).
648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    // Returns true if a popup was slated to be shown.
651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    virtual bool ShowExtensionActionPopup(const Extension* extension,
661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                          bool grant_active_tab) = 0;
678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Signal when the container needs to be redrawn because of a size change,
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // and when the model has finished loading.
7003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    virtual void ToolbarVisibleCountChanged() = 0;
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
72effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    // Signal that the model has entered or exited highlighting mode, or that
73effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    // the extensions being highlighted have (probably*) changed. Highlighting
74effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    // mode indicates that only a subset of the extensions are actively
75effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    // displayed, and those extensions should be highlighted for extra emphasis.
76effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    // * probably, because if we are in highlight mode and receive a call to
77effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    //   highlight a new set of extensions, we do not compare the current set
78effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    //   with the new set (and just assume the new set is different).
7903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    virtual void ToolbarHighlightModeChanged(bool is_highlighting) = 0;
80effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    // Returns the browser associated with the Observer.
821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    virtual Browser* GetBrowser() = 0;
831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   protected:
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual ~Observer() {}
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
88f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Convenience function to get the ExtensionToolbarModel for a Profile.
89f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  static ExtensionToolbarModel* Get(Profile* profile);
90f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
9103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Add or remove an observer.
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddObserver(Observer* observer);
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RemoveObserver(Observer* observer);
9403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
9503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Moves the given |extension|'s icon to the given |index|.
9603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  void MoveExtensionIcon(const Extension* extension, int index);
9703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
9803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Sets the number of extension icons that should be visible.
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If count == size(), this will set the visible icon count to -1, meaning
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // "show all actions".
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetVisibleIconCount(int count);
10203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // As above, a return value of -1 represents "show all actions".
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int GetVisibleIconCount() const { return visible_icon_count_; }
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool extensions_initialized() const { return extensions_initialized_; }
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
108effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  const ExtensionList& toolbar_items() const {
109effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    return is_highlighting_ ? highlighted_items_ : toolbar_items_;
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
112effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  bool is_highlighting() const { return is_highlighting_; }
113effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Utility functions for converting between an index into the list of
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // incognito-enabled browser actions, and the list of all browser actions.
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int IncognitoIndexToOriginal(int incognito_index);
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int OriginalIndexToIncognito(int original_index);
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void OnExtensionToolbarPrefChange();
120c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Finds the Observer associated with |browser| and tells it to display a
1221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // popup for the given |extension|. If |grant_active_tab| is true, this
1231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // grants active tab permissions to the |extension|; only do this because of
1241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // a direct user action.
1251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  bool ShowExtensionActionPopup(const Extension* extension,
1261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                Browser* browser,
1271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                bool grant_active_tab);
1288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Ensures that the extensions in the |extension_ids| list are visible on the
1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // toolbar. This might mean they need to be moved to the front (if they are in
1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // the overflow bucket).
132effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  void EnsureVisibility(const ExtensionIdList& extension_ids);
133effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
134effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Highlight the extensions specified by |extension_ids|. This will cause
135effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // the ToolbarModel to only display those extensions.
136effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Highlighting mode is only entered if there is at least one extension to
137effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // be shown.
138effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Returns true if highlighting mode is entered, false otherwise.
139effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  bool HighlightExtensions(const ExtensionIdList& extension_ids);
140effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
141effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Stop highlighting extensions. All extensions can be shown again, and the
142effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // number of visible icons will be reset to what it was before highlighting.
143effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  void StopHighlighting();
1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
14503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Sets the number of visible icons and notifies all observers of the change.
14603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  void SetVisibleIconCountForTest(size_t visible_icons);
14703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
14903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // content::NotificationObserver:
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Observe(int type,
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       const content::NotificationSource& source,
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       const content::NotificationDetails& details) OVERRIDE;
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
154010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Callback when extensions are ready.
155010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void OnReady();
156010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
15703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // ExtensionRegistryObserver:
1585c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
1595c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                                 const Extension* extension) OVERRIDE;
1605c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  virtual void OnExtensionUnloaded(
1615c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      content::BrowserContext* browser_context,
1625c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      const Extension* extension,
1635c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      UnloadedExtensionInfo::Reason reason) OVERRIDE;
1645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void OnExtensionUninstalled(
1655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      content::BrowserContext* browser_context,
1665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      const Extension* extension,
1675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      extensions::UninstallReason reason) OVERRIDE;
1685c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
16903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // ExtensionActionAPI::Observer:
17003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  virtual void OnExtensionActionUpdated(
17103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      ExtensionAction* extension_action,
17203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      content::WebContents* web_contents,
17303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      content::BrowserContext* browser_context) OVERRIDE;
17403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // To be called after the extension service is ready; gets loaded extensions
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // from the extension service and their saved order from the pref service
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // and constructs |toolbar_items_| from these data.
178010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void InitializeExtensionList(const ExtensionSet& extensions);
179010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void Populate(const ExtensionIdList& positions,
180010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                const ExtensionSet& extensions);
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Save the model to prefs.
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void UpdatePrefs();
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
18503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Updates |extension|'s browser action visibility pref if the browser action
18603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // is in the overflow menu and should be considered hidden.
18703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  void MaybeUpdateVisibilityPref(const Extension* extension, int index);
18803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
18903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Calls MaybeUpdateVisibilityPref() for each extension in |toolbar_items|.
19003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  void MaybeUpdateVisibilityPrefs();
19103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Finds the last known visible position of the icon for an |extension|. The
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // value returned is a zero-based index into the vector of visible items.
194effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  size_t FindNewPositionFromLastKnownGood(const Extension* extension);
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
19603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Returns true if the given |extension| should be added to the toolbar.
19703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  bool ShouldAddExtension(const Extension* extension);
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
19903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Adds or removes the given |extension| from the toolbar model.
200effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  void AddExtension(const Extension* extension);
201effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  void RemoveExtension(const Extension* extension);
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
20303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Our observers.
20403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  ObserverList<Observer> observers_;
20503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
206f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // The Profile this toolbar model is for.
207f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Profile* profile_;
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
209effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ExtensionPrefs* extension_prefs_;
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PrefService* prefs_;
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // True if we've handled the initial EXTENSIONS_READY notification.
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool extensions_initialized_;
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
21503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // If true, we include all extensions in the toolbar model. If false, we only
21603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // include browser actions.
21703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  bool include_all_extensions_;
21803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Ordered list of browser action buttons.
220effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ExtensionList toolbar_items_;
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
222effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // List of browser action buttons which should be highlighted.
223effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ExtensionList highlighted_items_;
224effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
225effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Indication whether or not we are currently in highlight mode; typically,
226effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // this is equivalent to !highlighted_items_.empty(), but can be different
227effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // if we are exiting highlight mode due to no longer having highlighted items.
228effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  bool is_highlighting_;
229effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
230effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // The number of icons which were visible before highlighting a subset, in
231effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // order to restore the count when finished.
232effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  int old_visible_icon_count_;
233effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
234effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ExtensionIdList last_known_positions_;
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The number of icons visible (the rest should be hidden in the overflow
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // chevron).
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int visible_icon_count_;
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationRegistrar registrar_;
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
24203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  ScopedObserver<ExtensionActionAPI, ExtensionActionAPI::Observer>
24303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      extension_action_observer_;
24403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
2455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Listen to extension load, unloaded notifications.
2465c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
2475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      extension_registry_observer_;
2485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
249c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // For observing change of toolbar order preference by external entity (sync).
250c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  PrefChangeRegistrar pref_change_registrar_;
251c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  base::Closure pref_change_callback_;
252c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
253c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  base::WeakPtrFactory<ExtensionToolbarModel> weak_ptr_factory_;
254c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel);
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
258effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch}  // namespace extensions
259effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_
261