Home | History | Annotate | Download | only in tabs
      1 // Copyright (c) 2010 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_TABS_TAB_STRIP_MODEL_DELEGATE_H_
      6 #define CHROME_BROWSER_TABS_TAB_STRIP_MODEL_DELEGATE_H_
      7 #pragma once
      8 
      9 #include "content/common/page_transition_types.h"
     10 
     11 class Browser;
     12 class DockInfo;
     13 class GURL;
     14 class Profile;
     15 class SiteInstance;
     16 class TabContents;
     17 class TabContentsWrapper;
     18 namespace gfx {
     19 class Rect;
     20 }
     21 
     22 ///////////////////////////////////////////////////////////////////////////////
     23 //
     24 // TabStripModelDelegate
     25 //
     26 //  A delegate interface that the TabStripModel uses to perform work that it
     27 //  can't do itself, such as obtain a container HWND for creating new
     28 //  TabContents, creating new TabStripModels for detached tabs, etc.
     29 //
     30 //  This interface is typically implemented by the controller that instantiates
     31 //  the TabStripModel (in our case the Browser object).
     32 //
     33 ///////////////////////////////////////////////////////////////////////////////
     34 class TabStripModelDelegate {
     35  public:
     36   enum {
     37     TAB_MOVE_ACTION = 1,
     38     TAB_TEAROFF_ACTION = 2
     39   };
     40 
     41   // Adds what the delegate considers to be a blank tab to the model.
     42   virtual TabContentsWrapper* AddBlankTab(bool foreground) = 0;
     43   virtual TabContentsWrapper* AddBlankTabAt(int index, bool foreground) = 0;
     44 
     45   // Asks for a new TabStripModel to be created and the given tab contents to
     46   // be added to it. Its size and position are reflected in |window_bounds|.
     47   // If |dock_info|'s type is other than NONE, the newly created window should
     48   // be docked as identified by |dock_info|. Returns the Browser object
     49   // representing the newly created window and tab strip. This does not
     50   // show the window, it's up to the caller to do so.
     51   virtual Browser* CreateNewStripWithContents(TabContentsWrapper* contents,
     52                                               const gfx::Rect& window_bounds,
     53                                               const DockInfo& dock_info,
     54                                               bool maximize) = 0;
     55 
     56   // Determines what drag actions are possible for the specified strip.
     57   virtual int GetDragActions() const = 0;
     58 
     59   // Creates an appropriate TabContents for the given URL. This is handled by
     60   // the delegate since the TabContents may require special circumstances to
     61   // exist for it to be constructed (e.g. a parent HWND).
     62   // If |defer_load| is true, the navigation controller doesn't load the url.
     63   // If |instance| is not null, its process is used to render the tab.
     64   virtual TabContentsWrapper* CreateTabContentsForURL(
     65       const GURL& url,
     66       const GURL& referrer,
     67       Profile* profile,
     68       PageTransition::Type transition,
     69       bool defer_load,
     70       SiteInstance* instance) const = 0;
     71 
     72   // Returns whether some contents can be duplicated.
     73   virtual bool CanDuplicateContentsAt(int index) = 0;
     74 
     75   // Duplicates the contents at the provided index and places it into its own
     76   // window.
     77   virtual void DuplicateContentsAt(int index) = 0;
     78 
     79   // Called when a drag session has completed and the frame that initiated the
     80   // the session should be closed.
     81   virtual void CloseFrameAfterDragSession() = 0;
     82 
     83   // Creates an entry in the historical tab database for the specified
     84   // TabContents.
     85   virtual void CreateHistoricalTab(TabContentsWrapper* contents) = 0;
     86 
     87   // Runs any unload listeners associated with the specified TabContents before
     88   // it is closed. If there are unload listeners that need to be run, this
     89   // function returns true and the TabStripModel will wait before closing the
     90   // TabContents. If it returns false, there are no unload listeners and the
     91   // TabStripModel can close the TabContents immediately.
     92   virtual bool RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) = 0;
     93 
     94   // Returns true if a tab can be restored.
     95   virtual bool CanRestoreTab() = 0;
     96 
     97   // Restores the last closed tab if CanRestoreTab would return true.
     98   virtual void RestoreTab() = 0;
     99 
    100   // Returns whether some contents can be closed.
    101   virtual bool CanCloseContentsAt(int index) = 0;
    102 
    103   // Returns true if we should allow "bookmark all tabs" in this window; this is
    104   // true when there is more than one bookmarkable tab open.
    105   virtual bool CanBookmarkAllTabs() const = 0;
    106 
    107   // Creates a bookmark folder containing a bookmark for all open tabs.
    108   virtual void BookmarkAllTabs() = 0;
    109 
    110   // Returns true if any of the tabs can be closed.
    111   virtual bool CanCloseTab() const = 0;
    112 
    113   // Returns true if the vertical tabstrip presentation should be used.
    114   virtual bool UseVerticalTabs() const = 0;
    115 
    116   // Toggles the use of the vertical tabstrip.
    117   virtual void ToggleUseVerticalTabs() = 0;
    118 
    119   // Returns true if the tab strip can use large icons.
    120   virtual bool LargeIconsPermitted() const = 0;
    121 
    122  protected:
    123   virtual ~TabStripModelDelegate() {}
    124 };
    125 
    126 #endif  // CHROME_BROWSER_TABS_TAB_STRIP_MODEL_DELEGATE_H_
    127