tab_strip_model_delegate.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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
12class Browser;
13class DockInfo;
14
15namespace content {
16class WebContents;
17}
18
19namespace gfx {
20class 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///////////////////////////////////////////////////////////////////////////////
35class TabStripModelDelegate {
36 public:
37  enum {
38    TAB_MOVE_ACTION = 1,
39    TAB_TEAROFF_ACTION = 2
40  };
41
42  virtual ~TabStripModelDelegate() {}
43
44  // Adds what the delegate considers to be a blank tab to the model. An |index|
45  // value of -1 means to append the contents to the end of the tab strip.
46  virtual void AddBlankTabAt(int index, bool foreground) = 0;
47
48  // Asks for a new TabStripModel to be created and the given web contentses to
49  // be added to it. Its size and position are reflected in |window_bounds|.
50  // If |dock_info|'s type is other than NONE, the newly created window should
51  // be docked as identified by |dock_info|. Returns the Browser object
52  // representing the newly created window and tab strip. This does not
53  // show the window; it's up to the caller to do so.
54  //
55  // TODO(avi): This is a layering violation; the TabStripModel should not know
56  // about the Browser type. At least fix so that this returns a
57  // TabStripModelDelegate, or perhaps even move this code elsewhere.
58  struct NewStripContents {
59    // The WebContents to add.
60    content::WebContents* web_contents;
61    // A bitmask of TabStripModel::AddTabTypes to apply to the added contents.
62    int add_types;
63  };
64  virtual Browser* CreateNewStripWithContents(
65      const std::vector<NewStripContents>& contentses,
66      const gfx::Rect& window_bounds,
67      const DockInfo& dock_info,
68      bool maximize) = 0;
69
70  // Determines what drag actions are possible for the specified strip.
71  virtual int GetDragActions() const = 0;
72
73  // Returns whether some contents can be duplicated.
74  virtual bool CanDuplicateContentsAt(int index) = 0;
75
76  // Duplicates the contents at the provided index and places it into its own
77  // window.
78  virtual void DuplicateContentsAt(int index) = 0;
79
80  // Called when a drag session has completed and the frame that initiated the
81  // the session should be closed.
82  virtual void CloseFrameAfterDragSession() = 0;
83
84  // Creates an entry in the historical tab database for the specified
85  // WebContents.
86  virtual void CreateHistoricalTab(content::WebContents* contents) = 0;
87
88  // Runs any unload listeners associated with the specified WebContents
89  // before it is closed. If there are unload listeners that need to be run,
90  // this function returns true and the TabStripModel will wait before closing
91  // the WebContents. If it returns false, there are no unload listeners
92  // and the TabStripModel will close the WebContents immediately.
93  virtual bool RunUnloadListenerBeforeClosing(
94      content::WebContents* contents) = 0;
95
96  // Returns true if a tab can be restored.
97  virtual bool CanRestoreTab() = 0;
98
99  // Restores the last closed tab if CanRestoreTab would return true.
100  virtual void RestoreTab() = 0;
101
102  // Returns true if we should allow "bookmark all tabs" in this window; this is
103  // true when there is more than one bookmarkable tab open.
104  virtual bool CanBookmarkAllTabs() const = 0;
105
106  // Creates a bookmark folder containing a bookmark for all open tabs.
107  virtual void BookmarkAllTabs() = 0;
108};
109
110#endif  // CHROME_BROWSER_UI_TABS_TAB_STRIP_MODEL_DELEGATE_H_
111