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.
5 #ifndef CHROME_BROWSER_UI_TABS_TAB_STRIP_MODEL_DELEGATE_H_
6 #define CHROME_BROWSER_UI_TABS_TAB_STRIP_MODEL_DELEGATE_H_
10 #include "content/public/common/page_transition_types.h"
24 ///////////////////////////////////////////////////////////////////////////////
26 // TabStripModelDelegate
28 // A delegate interface that the TabStripModel uses to perform work that it
29 // can't do itself, such as obtain a container HWND for creating new
30 // WebContentses, creating new TabStripModels for detached tabs, etc.
32 // This interface is typically implemented by the controller that instantiates
33 // the TabStripModel (in our case the Browser object).
35 ///////////////////////////////////////////////////////////////////////////////
36 class TabStripModelDelegate
{
40 TAB_TEAROFF_ACTION
= 2
49 virtual ~TabStripModelDelegate() {}
51 // Adds a tab to the model and loads |url| in the tab. If |url| is an empty
52 // URL, then the new tab-page is loaded instead. An |index| value of -1
53 // means to append the contents to the end of the tab strip.
54 virtual void AddTabAt(const GURL
& url
, int index
, bool foreground
) = 0;
56 // Asks for a new TabStripModel to be created and the given web contentses to
57 // be added to it. Its size and position are reflected in |window_bounds|.
58 // If |dock_info|'s type is other than NONE, the newly created window should
59 // be docked as identified by |dock_info|. Returns the Browser object
60 // representing the newly created window and tab strip. This does not
61 // show the window; it's up to the caller to do so.
63 // TODO(avi): This is a layering violation; the TabStripModel should not know
64 // about the Browser type. At least fix so that this returns a
65 // TabStripModelDelegate, or perhaps even move this code elsewhere.
66 struct NewStripContents
{
67 // The WebContents to add.
68 content::WebContents
* web_contents
;
69 // A bitmask of TabStripModel::AddTabTypes to apply to the added contents.
72 virtual Browser
* CreateNewStripWithContents(
73 const std::vector
<NewStripContents
>& contentses
,
74 const gfx::Rect
& window_bounds
,
75 const DockInfo
& dock_info
,
78 // Notifies the delegate that the specified WebContents will be added to the
79 // tab strip (via insertion/appending/replacing existing) and allows it to do
80 // any preparation that it deems necessary.
81 virtual void WillAddWebContents(content::WebContents
* contents
) = 0;
83 // Determines what drag actions are possible for the specified strip.
84 virtual int GetDragActions() const = 0;
86 // Returns whether some contents can be duplicated.
87 virtual bool CanDuplicateContentsAt(int index
) = 0;
89 // Duplicates the contents at the provided index and places it into its own
91 virtual void DuplicateContentsAt(int index
) = 0;
93 // Called when a drag session has completed and the frame that initiated the
94 // the session should be closed.
95 virtual void CloseFrameAfterDragSession() = 0;
97 // Creates an entry in the historical tab database for the specified
99 virtual void CreateHistoricalTab(content::WebContents
* contents
) = 0;
101 // Runs any unload listeners associated with the specified WebContents
102 // before it is closed. If there are unload listeners that need to be run,
103 // this function returns true and the TabStripModel will wait before closing
104 // the WebContents. If it returns false, there are no unload listeners
105 // and the TabStripModel will close the WebContents immediately.
106 virtual bool RunUnloadListenerBeforeClosing(
107 content::WebContents
* contents
) = 0;
109 // Returns true if we should run unload listeners before attempts
110 // to close |contents|.
111 virtual bool ShouldRunUnloadListenerBeforeClosing(
112 content::WebContents
* contents
) = 0;
114 // Returns the current tab restore type.
115 virtual RestoreTabType
GetRestoreTabType() = 0;
117 // Restores the last closed tab unless tab restore type is none.
118 virtual void RestoreTab() = 0;
120 // Returns true if we should allow "bookmark all tabs" in this window; this is
121 // true when there is more than one bookmarkable tab open.
122 virtual bool CanBookmarkAllTabs() const = 0;
124 // Creates a bookmark folder containing a bookmark for all open tabs.
125 virtual void BookmarkAllTabs() = 0;
128 #endif // CHROME_BROWSER_UI_TABS_TAB_STRIP_MODEL_DELEGATE_H_