• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
DefaultTabHandler(TabHandlerDelegate * delegate)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 
~DefaultTabHandler()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 
GetTabStripModel() const30 TabStripModel* DefaultTabHandler::GetTabStripModel() const {
31   return model_.get();
32 }
33 
34 ////////////////////////////////////////////////////////////////////////////////
35 // DefaultTabHandler, TabStripModelDelegate implementation:
36 
AddBlankTab(bool foreground)37 TabContentsWrapper* DefaultTabHandler::AddBlankTab(bool foreground) {
38   UmaNaclHistogramEnumeration(NEW_TAB_NACL_BASELINE);
39   return delegate_->AsBrowser()->AddBlankTab(foreground);
40 }
41 
AddBlankTabAt(int index,bool foreground)42 TabContentsWrapper* DefaultTabHandler::AddBlankTabAt(int index,
43                                                      bool foreground) {
44   return delegate_->AsBrowser()->AddBlankTabAt(index, foreground);
45 }
46 
CreateNewStripWithContents(TabContentsWrapper * detached_contents,const gfx::Rect & window_bounds,const DockInfo & dock_info,bool maximize)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 
GetDragActions() const58 int DefaultTabHandler::GetDragActions() const {
59   return delegate_->AsBrowser()->GetDragActions();
60 }
61 
CreateTabContentsForURL(const GURL & url,const GURL & referrer,Profile * profile,PageTransition::Type transition,bool defer_load,SiteInstance * instance) const62 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 
CanDuplicateContentsAt(int index)77 bool DefaultTabHandler::CanDuplicateContentsAt(int index) {
78   return delegate_->AsBrowser()->CanDuplicateContentsAt(index);
79 }
80 
DuplicateContentsAt(int index)81 void DefaultTabHandler::DuplicateContentsAt(int index) {
82   delegate_->AsBrowser()->DuplicateContentsAt(index);
83 }
84 
CloseFrameAfterDragSession()85 void DefaultTabHandler::CloseFrameAfterDragSession() {
86   delegate_->AsBrowser()->CloseFrameAfterDragSession();
87 }
88 
CreateHistoricalTab(TabContentsWrapper * contents)89 void DefaultTabHandler::CreateHistoricalTab(TabContentsWrapper* contents) {
90   delegate_->AsBrowser()->CreateHistoricalTab(contents);
91 }
92 
RunUnloadListenerBeforeClosing(TabContentsWrapper * contents)93 bool DefaultTabHandler::RunUnloadListenerBeforeClosing(
94     TabContentsWrapper* contents) {
95   return delegate_->AsBrowser()->RunUnloadListenerBeforeClosing(contents);
96 }
97 
CanCloseContentsAt(int index)98 bool DefaultTabHandler::CanCloseContentsAt(int index) {
99   return delegate_->AsBrowser()->CanCloseContentsAt(index);
100 }
101 
CanBookmarkAllTabs() const102 bool DefaultTabHandler::CanBookmarkAllTabs() const {
103   return delegate_->AsBrowser()->CanBookmarkAllTabs();
104 }
105 
BookmarkAllTabs()106 void DefaultTabHandler::BookmarkAllTabs() {
107   delegate_->AsBrowser()->BookmarkAllTabs();
108 }
109 
CanCloseTab() const110 bool DefaultTabHandler::CanCloseTab() const {
111   return delegate_->AsBrowser()->CanCloseTab();
112 }
113 
ToggleUseVerticalTabs()114 void DefaultTabHandler::ToggleUseVerticalTabs() {
115   delegate_->AsBrowser()->ToggleUseVerticalTabs();
116 }
117 
CanRestoreTab()118 bool DefaultTabHandler::CanRestoreTab() {
119   return delegate_->AsBrowser()->CanRestoreTab();
120 }
121 
RestoreTab()122 void DefaultTabHandler::RestoreTab() {
123   delegate_->AsBrowser()->RestoreTab();
124 }
125 
LargeIconsPermitted() const126 bool DefaultTabHandler::LargeIconsPermitted() const {
127   return delegate_->AsBrowser()->LargeIconsPermitted();
128 }
129 
UseVerticalTabs() const130 bool DefaultTabHandler::UseVerticalTabs() const {
131   return delegate_->AsBrowser()->UseVerticalTabs();
132 }
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 // DefaultTabHandler, TabStripModelObserver implementation:
136 
TabInsertedAt(TabContentsWrapper * contents,int index,bool foreground)137 void DefaultTabHandler::TabInsertedAt(TabContentsWrapper* contents,
138                                       int index,
139                                       bool foreground) {
140   delegate_->AsBrowser()->TabInsertedAt(contents, index, foreground);
141 }
142 
TabClosingAt(TabStripModel * tab_strip_model,TabContentsWrapper * contents,int index)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 
TabDetachedAt(TabContentsWrapper * contents,int index)149 void DefaultTabHandler::TabDetachedAt(TabContentsWrapper* contents, int index) {
150   delegate_->AsBrowser()->TabDetachedAt(contents, index);
151 }
152 
TabDeselected(TabContentsWrapper * contents)153 void DefaultTabHandler::TabDeselected(TabContentsWrapper* contents) {
154   delegate_->AsBrowser()->TabDeselected(contents);
155 }
156 
TabSelectedAt(TabContentsWrapper * old_contents,TabContentsWrapper * new_contents,int index,bool user_gesture)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 
TabMoved(TabContentsWrapper * contents,int from_index,int to_index)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 
TabReplacedAt(TabStripModel * tab_strip_model,TabContentsWrapper * old_contents,TabContentsWrapper * new_contents,int index)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 
TabPinnedStateChanged(TabContentsWrapper * contents,int index)181 void DefaultTabHandler::TabPinnedStateChanged(TabContentsWrapper* contents,
182                                               int index) {
183   delegate_->AsBrowser()->TabPinnedStateChanged(contents, index);
184 }
185 
TabStripEmpty()186 void DefaultTabHandler::TabStripEmpty() {
187   delegate_->AsBrowser()->TabStripEmpty();
188 }
189 
190 ////////////////////////////////////////////////////////////////////////////////
191 // TabHandler, public:
192 
193 // static
CreateTabHandler(TabHandlerDelegate * delegate)194 TabHandler* TabHandler::CreateTabHandler(TabHandlerDelegate* delegate) {
195   return new DefaultTabHandler(delegate);
196 }
197 
198