1 // Copyright (c) 2010 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 #include "base/metrics/nacl_histogram.h" 6 #include "chrome/browser/tabs/default_tab_handler.h" 7 #include "chrome/browser/tabs/tab_strip_model.h" 8 #include "chrome/browser/ui/browser.h" 9 10 //////////////////////////////////////////////////////////////////////////////// 11 // DefaultTabHandler, public: 12 13 DefaultTabHandler::DefaultTabHandler(TabHandlerDelegate* delegate) 14 : delegate_(delegate), 15 ALLOW_THIS_IN_INITIALIZER_LIST( 16 model_(new TabStripModel(this, delegate->GetProfile()))) { 17 UmaNaclHistogramEnumeration(FIRST_TAB_NACL_BASELINE); 18 model_->AddObserver(this); 19 } 20 21 DefaultTabHandler::~DefaultTabHandler() { 22 // The tab strip should not have any tabs at this point. 23 DCHECK(model_->empty()); 24 model_->RemoveObserver(this); 25 } 26 27 //////////////////////////////////////////////////////////////////////////////// 28 // DefaultTabHandler, TabHandler implementation: 29 30 TabStripModel* DefaultTabHandler::GetTabStripModel() const { 31 return model_.get(); 32 } 33 34 //////////////////////////////////////////////////////////////////////////////// 35 // DefaultTabHandler, TabStripModelDelegate implementation: 36 37 TabContentsWrapper* DefaultTabHandler::AddBlankTab(bool foreground) { 38 UmaNaclHistogramEnumeration(NEW_TAB_NACL_BASELINE); 39 return delegate_->AsBrowser()->AddBlankTab(foreground); 40 } 41 42 TabContentsWrapper* DefaultTabHandler::AddBlankTabAt(int index, 43 bool foreground) { 44 return delegate_->AsBrowser()->AddBlankTabAt(index, foreground); 45 } 46 47 Browser* DefaultTabHandler::CreateNewStripWithContents( 48 TabContentsWrapper* detached_contents, 49 const gfx::Rect& window_bounds, 50 const DockInfo& dock_info, 51 bool maximize) { 52 return delegate_->AsBrowser()->CreateNewStripWithContents(detached_contents, 53 window_bounds, 54 dock_info, 55 maximize); 56 } 57 58 int DefaultTabHandler::GetDragActions() const { 59 return delegate_->AsBrowser()->GetDragActions(); 60 } 61 62 TabContentsWrapper* DefaultTabHandler::CreateTabContentsForURL( 63 const GURL& url, 64 const GURL& referrer, 65 Profile* profile, 66 PageTransition::Type transition, 67 bool defer_load, 68 SiteInstance* instance) const { 69 return delegate_->AsBrowser()->CreateTabContentsForURL(url, 70 referrer, 71 profile, 72 transition, 73 defer_load, 74 instance); 75 } 76 77 bool DefaultTabHandler::CanDuplicateContentsAt(int index) { 78 return delegate_->AsBrowser()->CanDuplicateContentsAt(index); 79 } 80 81 void DefaultTabHandler::DuplicateContentsAt(int index) { 82 delegate_->AsBrowser()->DuplicateContentsAt(index); 83 } 84 85 void DefaultTabHandler::CloseFrameAfterDragSession() { 86 delegate_->AsBrowser()->CloseFrameAfterDragSession(); 87 } 88 89 void DefaultTabHandler::CreateHistoricalTab(TabContentsWrapper* contents) { 90 delegate_->AsBrowser()->CreateHistoricalTab(contents); 91 } 92 93 bool DefaultTabHandler::RunUnloadListenerBeforeClosing( 94 TabContentsWrapper* contents) { 95 return delegate_->AsBrowser()->RunUnloadListenerBeforeClosing(contents); 96 } 97 98 bool DefaultTabHandler::CanCloseContentsAt(int index) { 99 return delegate_->AsBrowser()->CanCloseContentsAt(index); 100 } 101 102 bool DefaultTabHandler::CanBookmarkAllTabs() const { 103 return delegate_->AsBrowser()->CanBookmarkAllTabs(); 104 } 105 106 void DefaultTabHandler::BookmarkAllTabs() { 107 delegate_->AsBrowser()->BookmarkAllTabs(); 108 } 109 110 bool DefaultTabHandler::CanCloseTab() const { 111 return delegate_->AsBrowser()->CanCloseTab(); 112 } 113 114 void DefaultTabHandler::ToggleUseVerticalTabs() { 115 delegate_->AsBrowser()->ToggleUseVerticalTabs(); 116 } 117 118 bool DefaultTabHandler::CanRestoreTab() { 119 return delegate_->AsBrowser()->CanRestoreTab(); 120 } 121 122 void DefaultTabHandler::RestoreTab() { 123 delegate_->AsBrowser()->RestoreTab(); 124 } 125 126 bool DefaultTabHandler::LargeIconsPermitted() const { 127 return delegate_->AsBrowser()->LargeIconsPermitted(); 128 } 129 130 bool DefaultTabHandler::UseVerticalTabs() const { 131 return delegate_->AsBrowser()->UseVerticalTabs(); 132 } 133 134 //////////////////////////////////////////////////////////////////////////////// 135 // DefaultTabHandler, TabStripModelObserver implementation: 136 137 void DefaultTabHandler::TabInsertedAt(TabContentsWrapper* contents, 138 int index, 139 bool foreground) { 140 delegate_->AsBrowser()->TabInsertedAt(contents, index, foreground); 141 } 142 143 void DefaultTabHandler::TabClosingAt(TabStripModel* tab_strip_model, 144 TabContentsWrapper* contents, 145 int index) { 146 delegate_->AsBrowser()->TabClosingAt(tab_strip_model, contents, index); 147 } 148 149 void DefaultTabHandler::TabDetachedAt(TabContentsWrapper* contents, int index) { 150 delegate_->AsBrowser()->TabDetachedAt(contents, index); 151 } 152 153 void DefaultTabHandler::TabDeselected(TabContentsWrapper* contents) { 154 delegate_->AsBrowser()->TabDeselected(contents); 155 } 156 157 void DefaultTabHandler::TabSelectedAt(TabContentsWrapper* old_contents, 158 TabContentsWrapper* new_contents, 159 int index, 160 bool user_gesture) { 161 delegate_->AsBrowser()->TabSelectedAt(old_contents, 162 new_contents, 163 index, 164 user_gesture); 165 } 166 167 void DefaultTabHandler::TabMoved(TabContentsWrapper* contents, 168 int from_index, 169 int to_index) { 170 delegate_->AsBrowser()->TabMoved(contents, from_index, to_index); 171 } 172 173 void DefaultTabHandler::TabReplacedAt(TabStripModel* tab_strip_model, 174 TabContentsWrapper* old_contents, 175 TabContentsWrapper* new_contents, 176 int index) { 177 delegate_->AsBrowser()->TabReplacedAt(tab_strip_model, old_contents, 178 new_contents, index); 179 } 180 181 void DefaultTabHandler::TabPinnedStateChanged(TabContentsWrapper* contents, 182 int index) { 183 delegate_->AsBrowser()->TabPinnedStateChanged(contents, index); 184 } 185 186 void DefaultTabHandler::TabStripEmpty() { 187 delegate_->AsBrowser()->TabStripEmpty(); 188 } 189 190 //////////////////////////////////////////////////////////////////////////////// 191 // TabHandler, public: 192 193 // static 194 TabHandler* TabHandler::CreateTabHandler(TabHandlerDelegate* delegate) { 195 return new DefaultTabHandler(delegate); 196 } 197 198