summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tabs
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-28 22:45:40 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-28 22:45:40 +0000
commitecc523f661dd66ab6dafa276971c84f491f2521e (patch)
treebf6bbe6619420fb19210ed99f31ac385614137b9 /chrome/browser/tabs
parent19e300520d7474d430e2bb904a564253fe66a547 (diff)
downloadchromium_src-ecc523f661dd66ab6dafa276971c84f491f2521e.zip
chromium_src-ecc523f661dd66ab6dafa276971c84f491f2521e.tar.gz
chromium_src-ecc523f661dd66ab6dafa276971c84f491f2521e.tar.bz2
Create a TabHandler object to decouple Browser from TabStripModel API.
Currently it's just a pass-through so everything still works while I begin to move stuff out of Browser down into it. BUG=none TEST=existing unittests. Review URL: http://codereview.chromium.org/3412041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60860 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tabs')
-rw-r--r--chrome/browser/tabs/default_tab_handler.cc198
-rw-r--r--chrome/browser/tabs/default_tab_handler.h88
-rw-r--r--chrome/browser/tabs/tab_handler.h36
3 files changed, 322 insertions, 0 deletions
diff --git a/chrome/browser/tabs/default_tab_handler.cc b/chrome/browser/tabs/default_tab_handler.cc
new file mode 100644
index 0000000..5149173
--- /dev/null
+++ b/chrome/browser/tabs/default_tab_handler.cc
@@ -0,0 +1,198 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/tabs/default_tab_handler.h"
+
+#include "chrome/browser/browser.h"
+#include "chrome/browser/tabs/tab_strip_model.h"
+
+////////////////////////////////////////////////////////////////////////////////
+// DefaultTabHandler, public:
+
+DefaultTabHandler::DefaultTabHandler(TabHandlerDelegate* delegate)
+ : delegate_(delegate),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ model_(new TabStripModel(this, delegate->GetProfile()))) {
+ model_->AddObserver(this);
+}
+
+DefaultTabHandler::~DefaultTabHandler() {
+ // The tab strip should not have any significant tabs at this point.
+ DCHECK(!model_->HasNonPhantomTabs());
+ model_->RemoveObserver(this);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DefaultTabHandler, TabHandler implementation:
+
+TabStripModel* DefaultTabHandler::GetTabStripModel() const {
+ return model_.get();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DefaultTabHandler, TabStripModelDelegate implementation:
+
+TabContents* DefaultTabHandler::AddBlankTab(bool foreground) {
+ return delegate_->AsBrowser()->AddBlankTab(foreground);
+}
+
+TabContents* DefaultTabHandler::AddBlankTabAt(int index, bool foreground) {
+ return delegate_->AsBrowser()->AddBlankTabAt(index, foreground);
+}
+
+Browser* DefaultTabHandler::CreateNewStripWithContents(
+ TabContents* detached_contents,
+ const gfx::Rect& window_bounds,
+ const DockInfo& dock_info,
+ bool maximize) {
+ return delegate_->AsBrowser()->CreateNewStripWithContents(detached_contents,
+ window_bounds,
+ dock_info,
+ maximize);
+}
+
+void DefaultTabHandler::ContinueDraggingDetachedTab(
+ TabContents* contents,
+ const gfx::Rect& window_bounds,
+ const gfx::Rect& tab_bounds) {
+ delegate_->AsBrowser()->ContinueDraggingDetachedTab(contents,
+ window_bounds,
+ tab_bounds);
+}
+
+int DefaultTabHandler::GetDragActions() const {
+ return delegate_->AsBrowser()->GetDragActions();
+}
+
+TabContents* DefaultTabHandler::CreateTabContentsForURL(
+ const GURL& url,
+ const GURL& referrer,
+ Profile* profile,
+ PageTransition::Type transition,
+ bool defer_load,
+ SiteInstance* instance) const {
+ return delegate_->AsBrowser()->CreateTabContentsForURL(url,
+ referrer,
+ profile,
+ transition,
+ defer_load,
+ instance);
+}
+
+bool DefaultTabHandler::CanDuplicateContentsAt(int index) {
+ return delegate_->AsBrowser()->CanDuplicateContentsAt(index);
+}
+
+void DefaultTabHandler::DuplicateContentsAt(int index) {
+ delegate_->AsBrowser()->DuplicateContentsAt(index);
+}
+
+void DefaultTabHandler::CloseFrameAfterDragSession() {
+ delegate_->AsBrowser()->CloseFrameAfterDragSession();
+}
+
+void DefaultTabHandler::CreateHistoricalTab(TabContents* contents) {
+ delegate_->AsBrowser()->CreateHistoricalTab(contents);
+}
+
+bool DefaultTabHandler::RunUnloadListenerBeforeClosing(TabContents* contents) {
+ return delegate_->AsBrowser()->RunUnloadListenerBeforeClosing(contents);
+}
+
+bool DefaultTabHandler::CanCloseContentsAt(int index) {
+ return delegate_->AsBrowser()->CanCloseContentsAt(index);
+}
+
+bool DefaultTabHandler::CanBookmarkAllTabs() const {
+ return delegate_->AsBrowser()->CanBookmarkAllTabs();
+}
+
+void DefaultTabHandler::BookmarkAllTabs() {
+ delegate_->AsBrowser()->BookmarkAllTabs();
+}
+
+bool DefaultTabHandler::CanCloseTab() const {
+ return delegate_->AsBrowser()->CanCloseTab();
+}
+
+void DefaultTabHandler::ToggleUseVerticalTabs() {
+ delegate_->AsBrowser()->ToggleUseVerticalTabs();
+}
+
+bool DefaultTabHandler::CanRestoreTab() {
+ return delegate_->AsBrowser()->CanRestoreTab();
+}
+
+void DefaultTabHandler::RestoreTab() {
+ delegate_->AsBrowser()->RestoreTab();
+}
+
+bool DefaultTabHandler::LargeIconsPermitted() const {
+ return delegate_->AsBrowser()->LargeIconsPermitted();
+}
+
+bool DefaultTabHandler::UseVerticalTabs() const {
+ return delegate_->AsBrowser()->UseVerticalTabs();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DefaultTabHandler, TabStripModelObserver implementation:
+
+void DefaultTabHandler::TabInsertedAt(TabContents* contents,
+ int index,
+ bool foreground) {
+ delegate_->AsBrowser()->TabInsertedAt(contents, index, foreground);
+}
+
+void DefaultTabHandler::TabClosingAt(TabContents* contents, int index) {
+ delegate_->AsBrowser()->TabClosingAt(contents, index);
+}
+
+void DefaultTabHandler::TabDetachedAt(TabContents* contents, int index) {
+ delegate_->AsBrowser()->TabDetachedAt(contents, index);
+}
+
+void DefaultTabHandler::TabDeselectedAt(TabContents* contents, int index) {
+ delegate_->AsBrowser()->TabDeselectedAt(contents, index);
+}
+
+void DefaultTabHandler::TabSelectedAt(TabContents* old_contents,
+ TabContents* new_contents,
+ int index,
+ bool user_gesture) {
+ delegate_->AsBrowser()->TabSelectedAt(old_contents,
+ new_contents,
+ index,
+ user_gesture);
+}
+
+void DefaultTabHandler::TabMoved(TabContents* contents,
+ int from_index,
+ int to_index) {
+ delegate_->AsBrowser()->TabMoved(contents, from_index, to_index);
+}
+
+void DefaultTabHandler::TabReplacedAt(TabContents* old_contents,
+ TabContents* new_contents,
+ int index) {
+ delegate_->AsBrowser()->TabReplacedAt(old_contents, new_contents, index);
+}
+
+void DefaultTabHandler::TabPinnedStateChanged(TabContents* contents,
+ int index) {
+ delegate_->AsBrowser()->TabPinnedStateChanged(contents, index);
+}
+
+void DefaultTabHandler::TabStripEmpty() {
+ delegate_->AsBrowser()->TabStripEmpty();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// TabHandler, public:
+
+// static
+TabHandler* TabHandler::CreateTabHandler(TabHandlerDelegate* delegate) {
+ return new DefaultTabHandler(delegate);
+}
+
diff --git a/chrome/browser/tabs/default_tab_handler.h b/chrome/browser/tabs/default_tab_handler.h
new file mode 100644
index 0000000..8a2af16
--- /dev/null
+++ b/chrome/browser/tabs/default_tab_handler.h
@@ -0,0 +1,88 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_TABS_DEFAULT_TAB_HANDLER_H_
+#define CHROME_BROWSER_TABS_DEFAULT_TAB_HANDLER_H_
+#pragma once
+
+#include "base/scoped_ptr.h"
+#include "chrome/browser/tabs/tab_handler.h"
+#include "chrome/browser/tabs/tab_strip_model_delegate.h"
+#include "chrome/browser/tabs/tab_strip_model_observer.h"
+
+// A TabHandler implementation that interacts with the default TabStripModel.
+// The intent is that the TabStripModel API is contained at this level, and
+// never propagates beyond to the Browser.
+class DefaultTabHandler : public TabHandler,
+ public TabStripModelDelegate,
+ public TabStripModelObserver {
+ public:
+ explicit DefaultTabHandler(TabHandlerDelegate* delegate);
+ virtual ~DefaultTabHandler();
+
+ // Overridden from TabHandler:
+ virtual TabStripModel* GetTabStripModel() const;
+
+ // Overridden from TabStripModelDelegate:
+ virtual TabContents* AddBlankTab(bool foreground);
+ virtual TabContents* AddBlankTabAt(int index, bool foreground);
+ virtual Browser* CreateNewStripWithContents(TabContents* detached_contents,
+ const gfx::Rect& window_bounds,
+ const DockInfo& dock_info,
+ bool maximize);
+ virtual void ContinueDraggingDetachedTab(TabContents* contents,
+ const gfx::Rect& window_bounds,
+ const gfx::Rect& tab_bounds);
+ virtual int GetDragActions() const;
+ virtual TabContents* CreateTabContentsForURL(const GURL& url,
+ const GURL& referrer,
+ Profile* profile,
+ PageTransition::Type transition,
+ bool defer_load,
+ SiteInstance* instance) const;
+ virtual bool CanDuplicateContentsAt(int index);
+ virtual void DuplicateContentsAt(int index);
+ virtual void CloseFrameAfterDragSession();
+ virtual void CreateHistoricalTab(TabContents* contents);
+ virtual bool RunUnloadListenerBeforeClosing(TabContents* contents);
+ virtual bool CanCloseContentsAt(int index);
+ virtual bool CanBookmarkAllTabs() const;
+ virtual void BookmarkAllTabs();
+ virtual bool CanCloseTab() const;
+ virtual void ToggleUseVerticalTabs();
+ virtual bool CanRestoreTab();
+ virtual void RestoreTab();
+ virtual bool LargeIconsPermitted() const;
+ virtual bool UseVerticalTabs() const;
+
+ // Overridden from TabStripModelObserver:
+ virtual void TabInsertedAt(TabContents* contents,
+ int index,
+ bool foreground);
+ virtual void TabClosingAt(TabContents* contents, int index);
+ virtual void TabDetachedAt(TabContents* contents, int index);
+ virtual void TabDeselectedAt(TabContents* contents, int index);
+ virtual void TabSelectedAt(TabContents* old_contents,
+ TabContents* new_contents,
+ int index,
+ bool user_gesture);
+ virtual void TabMoved(TabContents* contents,
+ int from_index,
+ int to_index);
+ virtual void TabReplacedAt(TabContents* old_contents,
+ TabContents* new_contents,
+ int index);
+ virtual void TabPinnedStateChanged(TabContents* contents, int index);
+ virtual void TabStripEmpty();
+
+ private:
+ TabHandlerDelegate* delegate_;
+
+ scoped_ptr<TabStripModel> model_;
+
+ DISALLOW_COPY_AND_ASSIGN(DefaultTabHandler);
+};
+
+#endif // CHROME_BROWSER_TABS_DEFAULT_TAB_HANDLER_H_
+
diff --git a/chrome/browser/tabs/tab_handler.h b/chrome/browser/tabs/tab_handler.h
new file mode 100644
index 0000000..e67aece
--- /dev/null
+++ b/chrome/browser/tabs/tab_handler.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_TABS_TAB_HANDLER_H_
+#define CHROME_BROWSER_TABS_TAB_HANDLER_H_
+#pragma once
+
+class Browser;
+class Profile;
+class TabStripModel;
+
+class TabHandlerDelegate {
+ public:
+ virtual Profile* GetProfile() const = 0;
+
+ // TODO(beng): remove once decoupling with Browser is complete.
+ virtual Browser* AsBrowser() = 0;
+};
+
+// An interface implemented by an object that can perform tab related
+// functionality for a Browser. This functionality includes mapping individual
+// TabContentses into indices for an index-based tab organization scheme for
+// example.
+class TabHandler {
+ public:
+ // Creates a TabHandler implementation and returns it, transferring ownership
+ // to the caller.
+ static TabHandler* CreateTabHandler(TabHandlerDelegate* delegate);
+
+ // TODO(beng): remove once decoupling with Browser is complete.
+ virtual TabStripModel* GetTabStripModel() const = 0;
+};
+
+#endif // CHROME_BROWSER_TABS_TAB_HANDLER_H_
+