Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / extension_toolbar_model.h
index 29e83b3..d70a658 100644 (file)
@@ -33,7 +33,7 @@ class ExtensionToolbarModel : public content::NotificationObserver,
                               public KeyedService {
  public:
   ExtensionToolbarModel(Profile* profile, ExtensionPrefs* extension_prefs);
-  virtual ~ExtensionToolbarModel();
+  ~ExtensionToolbarModel() override;
 
   // A class which is informed of changes to the model; represents the view of
   // MVC. Also used for signaling view changes such as showing extension popups.
@@ -41,16 +41,17 @@ class ExtensionToolbarModel : public content::NotificationObserver,
   // delegate.
   class Observer {
    public:
-    // An extension has been added to the toolbar and should go at |index|.
+    // TODO(devlin): Rename these methods to be OnFoo.
+    // Signals that an |extension| has been added to the toolbar at |index|.
     virtual void ToolbarExtensionAdded(const Extension* extension,
                                        int index) = 0;
 
-    // The given |extension| should be removed from the toolbar.
+    // Signals that the given |extension| has been removed from the toolbar.
     virtual void ToolbarExtensionRemoved(const Extension* extension) = 0;
 
-    // The given |extension| has been moved to |index|. |index| is the desired
-    // *final* index of the extension (that is, in the adjusted order, extension
-    // should be at |index|).
+    // Signals that the given |extension| has been moved to |index|. |index| is
+    // the desired *final* index of the extension (that is, in the adjusted
+    // order, extension should be at |index|).
     virtual void ToolbarExtensionMoved(const Extension* extension,
                                        int index) = 0;
 
@@ -58,18 +59,18 @@ class ExtensionToolbarModel : public content::NotificationObserver,
     // updated.
     virtual void ToolbarExtensionUpdated(const Extension* extension) = 0;
 
-    // Signal the |extension| to show the popup now in the active window.
+    // Signals the |extension| to show the popup now in the active window.
     // If |grant_active_tab| is true, then active tab permissions should be
     // given to the extension (only do this if this is through a user action).
     // Returns true if a popup was slated to be shown.
     virtual bool ShowExtensionActionPopup(const Extension* extension,
                                           bool grant_active_tab) = 0;
 
-    // Signal when the container needs to be redrawn because of a size change,
+    // Signals when the container needs to be redrawn because of a size change,
     // and when the model has finished loading.
     virtual void ToolbarVisibleCountChanged() = 0;
 
-    // Signal that the model has entered or exited highlighting mode, or that
+    // Signals that the model has entered or exited highlighting mode, or that
     // the extensions being highlighted have (probably*) changed. Highlighting
     // mode indicates that only a subset of the extensions are actively
     // displayed, and those extensions should be highlighted for extra emphasis.
@@ -78,6 +79,12 @@ class ExtensionToolbarModel : public content::NotificationObserver,
     //   with the new set (and just assume the new set is different).
     virtual void ToolbarHighlightModeChanged(bool is_highlighting) = 0;
 
+    // Signals that the toolbar needs to be reordered for the given
+    // |web_contents|. This is caused by an overflowed action wanting to run,
+    // and needing to "pop itself out".
+    virtual void OnToolbarReorderNecessary(
+        content::WebContents* web_contents) = 0;
+
     // Returns the browser associated with the Observer.
     virtual Browser* GetBrowser() = 0;
 
@@ -88,20 +95,24 @@ class ExtensionToolbarModel : public content::NotificationObserver,
   // Convenience function to get the ExtensionToolbarModel for a Profile.
   static ExtensionToolbarModel* Get(Profile* profile);
 
-  // Add or remove an observer.
+  // Adds or removes an observer.
   void AddObserver(Observer* observer);
   void RemoveObserver(Observer* observer);
 
   // Moves the given |extension|'s icon to the given |index|.
-  void MoveExtensionIcon(const Extension* extension, int index);
+  void MoveExtensionIcon(const std::string& id, size_t index);
 
   // Sets the number of extension icons that should be visible.
   // If count == size(), this will set the visible icon count to -1, meaning
   // "show all actions".
-  void SetVisibleIconCount(int count);
+  void SetVisibleIconCount(size_t count);
+
+  size_t visible_icon_count() const {
+    return visible_icon_count_ == -1 ?
+        toolbar_items().size() : static_cast<size_t>(visible_icon_count_);
+  }
 
-  // As above, a return value of -1 represents "show all actions".
-  int GetVisibleIconCount() const { return visible_icon_count_; }
+  bool all_icons_visible() const { return visible_icon_count_ == -1; }
 
   bool extensions_initialized() const { return extensions_initialized_; }
 
@@ -111,13 +122,18 @@ class ExtensionToolbarModel : public content::NotificationObserver,
 
   bool is_highlighting() const { return is_highlighting_; }
 
-  // Utility functions for converting between an index into the list of
-  // incognito-enabled browser actions, and the list of all browser actions.
-  int IncognitoIndexToOriginal(int incognito_index);
-  int OriginalIndexToIncognito(int original_index);
-
   void OnExtensionToolbarPrefChange();
 
+  // Returns the item order for a given tab. This can be different from the
+  // base item order if the action wants to run on the given page, and needs to
+  // be popped out of overflow.
+  ExtensionList GetItemOrderForTab(content::WebContents* web_contents) const;
+
+  // Returns the visible icon count for a given tab. This can be different from
+  // the base item order if the action wants to run on the given page and needs
+  // to be popped out of overflow.
+  size_t GetVisibleIconCountForTab(content::WebContents* web_contents) const;
+
   // Finds the Observer associated with |browser| and tells it to display a
   // popup for the given |extension|. If |grant_active_tab| is true, this
   // grants active tab permissions to the |extension|; only do this because of
@@ -131,7 +147,7 @@ class ExtensionToolbarModel : public content::NotificationObserver,
   // the overflow bucket).
   void EnsureVisibility(const ExtensionIdList& extension_ids);
 
-  // Highlight the extensions specified by |extension_ids|. This will cause
+  // Highlights the extensions specified by |extension_ids|. This will cause
   // the ToolbarModel to only display those extensions.
   // Highlighting mode is only entered if there is at least one extension to
   // be shown.
@@ -142,42 +158,39 @@ class ExtensionToolbarModel : public content::NotificationObserver,
   // number of visible icons will be reset to what it was before highlighting.
   void StopHighlighting();
 
-  // Sets the number of visible icons and notifies all observers of the change.
-  void SetVisibleIconCountForTest(size_t visible_icons);
-
  private:
   // content::NotificationObserver:
-  virtual void Observe(int type,
-                       const content::NotificationSource& source,
-                       const content::NotificationDetails& details) OVERRIDE;
+  void Observe(int type,
+               const content::NotificationSource& source,
+               const content::NotificationDetails& details) override;
 
   // Callback when extensions are ready.
   void OnReady();
 
   // ExtensionRegistryObserver:
-  virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
-                                 const Extension* extension) OVERRIDE;
-  virtual void OnExtensionUnloaded(
-      content::BrowserContext* browser_context,
-      const Extension* extension,
-      UnloadedExtensionInfo::Reason reason) OVERRIDE;
-  virtual void OnExtensionUninstalled(
-      content::BrowserContext* browser_context,
-      const Extension* extension,
-      extensions::UninstallReason reason) OVERRIDE;
+  void OnExtensionLoaded(content::BrowserContext* browser_context,
+                         const Extension* extension) override;
+  void OnExtensionUnloaded(content::BrowserContext* browser_context,
+                           const Extension* extension,
+                           UnloadedExtensionInfo::Reason reason) override;
+  void OnExtensionUninstalled(content::BrowserContext* browser_context,
+                              const Extension* extension,
+                              extensions::UninstallReason reason) override;
 
   // ExtensionActionAPI::Observer:
-  virtual void OnExtensionActionUpdated(
+  void OnExtensionActionUpdated(
       ExtensionAction* extension_action,
       content::WebContents* web_contents,
-      content::BrowserContext* browser_context) OVERRIDE;
+      content::BrowserContext* browser_context) override;
 
   // To be called after the extension service is ready; gets loaded extensions
-  // from the extension service and their saved order from the pref service
-  // and constructs |toolbar_items_| from these data.
-  void InitializeExtensionList(const ExtensionSet& extensions);
-  void Populate(const ExtensionIdList& positions,
-                const ExtensionSet& extensions);
+  // from the ExtensionRegistry and their saved order from the pref service
+  // and constructs |toolbar_items_| from these data. IncognitoPopulate()
+  // takes the shortcut - looking at the regular model's content and modifying
+  // it.
+  void InitializeExtensionList();
+  void Populate(const ExtensionIdList& positions);
+  void IncognitoPopulate();
 
   // Save the model to prefs.
   void UpdatePrefs();
@@ -200,6 +213,9 @@ class ExtensionToolbarModel : public content::NotificationObserver,
   void AddExtension(const Extension* extension);
   void RemoveExtension(const Extension* extension);
 
+  // Removes all current items (because we're going to [re]Populate()).
+  void ClearItems();
+
   // Our observers.
   ObserverList<Observer> observers_;
 
@@ -234,7 +250,9 @@ class ExtensionToolbarModel : public content::NotificationObserver,
   ExtensionIdList last_known_positions_;
 
   // The number of icons visible (the rest should be hidden in the overflow
-  // chevron).
+  // chevron). A value of -1 indicates that all icons should be visible.
+  // TODO(devlin): Make a new variable to indicate that all icons should be
+  // visible, instead of overloading this one.
   int visible_icon_count_;
 
   content::NotificationRegistrar registrar_;