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