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 class GURL; 15 16 namespace content { 17 class WebContents; 18 } 19 20 namespace gfx { 21 class Rect; 22 } 23 24 /////////////////////////////////////////////////////////////////////////////// 25 // 26 // TabStripModelDelegate 27 // 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. 31 // 32 // This interface is typically implemented by the controller that instantiates 33 // the TabStripModel (in our case the Browser object). 34 // 35 /////////////////////////////////////////////////////////////////////////////// 36 class TabStripModelDelegate { 37 public: 38 enum { 39 TAB_MOVE_ACTION = 1, 40 TAB_TEAROFF_ACTION = 2 41 }; 42 43 enum RestoreTabType { 44 RESTORE_NONE, 45 RESTORE_TAB, 46 RESTORE_WINDOW 47 }; 48 49 virtual ~TabStripModelDelegate() {} 50 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; 55 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. 62 // 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. 70 int add_types; 71 }; 72 virtual Browser* CreateNewStripWithContents( 73 const std::vector<NewStripContents>& contentses, 74 const gfx::Rect& window_bounds, 75 const DockInfo& dock_info, 76 bool maximize) = 0; 77 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; 82 83 // Determines what drag actions are possible for the specified strip. 84 virtual int GetDragActions() const = 0; 85 86 // Returns whether some contents can be duplicated. 87 virtual bool CanDuplicateContentsAt(int index) = 0; 88 89 // Duplicates the contents at the provided index and places it into its own 90 // window. 91 virtual void DuplicateContentsAt(int index) = 0; 92 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; 96 97 // Creates an entry in the historical tab database for the specified 98 // WebContents. 99 virtual void CreateHistoricalTab(content::WebContents* contents) = 0; 100 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; 108 109 // Returns true if we should run unload listeners before attempts 110 // to close |contents|. 111 virtual bool ShouldRunUnloadListenerBeforeClosing( 112 content::WebContents* contents) = 0; 113 114 // Returns the current tab restore type. 115 virtual RestoreTabType GetRestoreTabType() = 0; 116 117 // Restores the last closed tab unless tab restore type is none. 118 virtual void RestoreTab() = 0; 119 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; 123 124 // Creates a bookmark folder containing a bookmark for all open tabs. 125 virtual void BookmarkAllTabs() = 0; 126 }; 127 128 #endif // CHROME_BROWSER_UI_TABS_TAB_STRIP_MODEL_DELEGATE_H_ 129