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