Home | History | Annotate | Download | only in tabs
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_UI_TABS_TAB_STRIP_MODEL_DELEGATE_H_
      6 #define CHROME_BROWSER_UI_TABS_TAB_STRIP_MODEL_DELEGATE_H_
      7 
      8 #include <vector>
      9 
     10 #include "content/public/common/page_transition_types.h"
     11 
     12 class Browser;
     13 class DockInfo;
     14 
     15 namespace content {
     16 class WebContents;
     17 }
     18 
     19 namespace gfx {
     20 class Rect;
     21 }
     22 
     23 ///////////////////////////////////////////////////////////////////////////////
     24 //
     25 // TabStripModelDelegate
     26 //
     27 //  A delegate interface that the TabStripModel uses to perform work that it
     28 //  can't do itself, such as obtain a container HWND for creating new
     29 //  WebContentses, creating new TabStripModels for detached tabs, etc.
     30 //
     31 //  This interface is typically implemented by the controller that instantiates
     32 //  the TabStripModel (in our case the Browser object).
     33 //
     34 ///////////////////////////////////////////////////////////////////////////////
     35 class TabStripModelDelegate {
     36  public:
     37   enum {
     38     TAB_MOVE_ACTION = 1,
     39     TAB_TEAROFF_ACTION = 2
     40   };
     41 
     42   enum RestoreTabType {
     43     RESTORE_NONE,
     44     RESTORE_TAB,
     45     RESTORE_WINDOW
     46   };
     47 
     48   virtual ~TabStripModelDelegate() {}
     49 
     50   // Adds what the delegate considers to be a blank tab to the model. An |index|
     51   // value of -1 means to append the contents to the end of the tab strip.
     52   virtual void AddBlankTabAt(int index, bool foreground) = 0;
     53 
     54   // Asks for a new TabStripModel to be created and the given web contentses to
     55   // be added to it. Its size and position are reflected in |window_bounds|.
     56   // If |dock_info|'s type is other than NONE, the newly created window should
     57   // be docked as identified by |dock_info|. Returns the Browser object
     58   // representing the newly created window and tab strip. This does not
     59   // show the window; it's up to the caller to do so.
     60   //
     61   // TODO(avi): This is a layering violation; the TabStripModel should not know
     62   // about the Browser type. At least fix so that this returns a
     63   // TabStripModelDelegate, or perhaps even move this code elsewhere.
     64   struct NewStripContents {
     65     // The WebContents to add.
     66     content::WebContents* web_contents;
     67     // A bitmask of TabStripModel::AddTabTypes to apply to the added contents.
     68     int add_types;
     69   };
     70   virtual Browser* CreateNewStripWithContents(
     71       const std::vector<NewStripContents>& contentses,
     72       const gfx::Rect& window_bounds,
     73       const DockInfo& dock_info,
     74       bool maximize) = 0;
     75 
     76   // Notifies the delegate that the specified WebContents will be added to the
     77   // tab strip (via insertion/appending/replacing existing) and allows it to do
     78   // any preparation that it deems necessary.
     79   virtual void WillAddWebContents(content::WebContents* contents) = 0;
     80 
     81   // Determines what drag actions are possible for the specified strip.
     82   virtual int GetDragActions() const = 0;
     83 
     84   // Returns whether some contents can be duplicated.
     85   virtual bool CanDuplicateContentsAt(int index) = 0;
     86 
     87   // Duplicates the contents at the provided index and places it into its own
     88   // window.
     89   virtual void DuplicateContentsAt(int index) = 0;
     90 
     91   // Called when a drag session has completed and the frame that initiated the
     92   // the session should be closed.
     93   virtual void CloseFrameAfterDragSession() = 0;
     94 
     95   // Creates an entry in the historical tab database for the specified
     96   // WebContents.
     97   virtual void CreateHistoricalTab(content::WebContents* contents) = 0;
     98 
     99   // Runs any unload listeners associated with the specified WebContents
    100   // before it is closed. If there are unload listeners that need to be run,
    101   // this function returns true and the TabStripModel will wait before closing
    102   // the WebContents. If it returns false, there are no unload listeners
    103   // and the TabStripModel will close the WebContents immediately.
    104   virtual bool RunUnloadListenerBeforeClosing(
    105       content::WebContents* contents) = 0;
    106 
    107   // Returns the current tab restore type.
    108   virtual RestoreTabType GetRestoreTabType() = 0;
    109 
    110   // Restores the last closed tab unless tab restore type is none.
    111   virtual void RestoreTab() = 0;
    112 
    113   // Returns true if we should allow "bookmark all tabs" in this window; this is
    114   // true when there is more than one bookmarkable tab open.
    115   virtual bool CanBookmarkAllTabs() const = 0;
    116 
    117   // Creates a bookmark folder containing a bookmark for all open tabs.
    118   virtual void BookmarkAllTabs() = 0;
    119 };
    120 
    121 #endif  // CHROME_BROWSER_UI_TABS_TAB_STRIP_MODEL_DELEGATE_H_
    122