1 // Copyright (c) 2011 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 "chrome/browser/ui/browser_tab_restore_service_delegate.h"
6
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_list.h"
9 #include "chrome/browser/ui/browser_window.h"
10
ShowBrowserWindow()11 void BrowserTabRestoreServiceDelegate::ShowBrowserWindow() {
12 browser_->window()->Show();
13 }
14
GetSessionID() const15 const SessionID& BrowserTabRestoreServiceDelegate::GetSessionID() const {
16 return browser_->session_id();
17 }
18
GetTabCount() const19 int BrowserTabRestoreServiceDelegate::GetTabCount() const {
20 return browser_->tab_count();
21 }
22
GetSelectedIndex() const23 int BrowserTabRestoreServiceDelegate::GetSelectedIndex() const {
24 return browser_->active_index();
25 }
26
GetTabContentsAt(int index) const27 TabContents* BrowserTabRestoreServiceDelegate::GetTabContentsAt(
28 int index) const {
29 return browser_->GetTabContentsAt(index);
30 }
31
GetSelectedTabContents() const32 TabContents* BrowserTabRestoreServiceDelegate::GetSelectedTabContents() const {
33 return browser_->GetSelectedTabContents();
34 }
35
IsTabPinned(int index) const36 bool BrowserTabRestoreServiceDelegate::IsTabPinned(int index) const {
37 return browser_->IsTabPinned(index);
38 }
39
AddRestoredTab(const std::vector<TabNavigation> & navigations,int tab_index,int selected_navigation,const std::string & extension_app_id,bool select,bool pin,bool from_last_session,SessionStorageNamespace * storage_namespace)40 TabContents* BrowserTabRestoreServiceDelegate::AddRestoredTab(
41 const std::vector<TabNavigation>& navigations,
42 int tab_index,
43 int selected_navigation,
44 const std::string& extension_app_id,
45 bool select,
46 bool pin,
47 bool from_last_session,
48 SessionStorageNamespace* storage_namespace) {
49 return browser_->AddRestoredTab(navigations, tab_index, selected_navigation,
50 extension_app_id, select, pin,
51 from_last_session, storage_namespace);
52 }
53
ReplaceRestoredTab(const std::vector<TabNavigation> & navigations,int selected_navigation,bool from_last_session,const std::string & extension_app_id,SessionStorageNamespace * session_storage_namespace)54 void BrowserTabRestoreServiceDelegate::ReplaceRestoredTab(
55 const std::vector<TabNavigation>& navigations,
56 int selected_navigation,
57 bool from_last_session,
58 const std::string& extension_app_id,
59 SessionStorageNamespace* session_storage_namespace) {
60 browser_->ReplaceRestoredTab(navigations, selected_navigation,
61 from_last_session, extension_app_id,
62 session_storage_namespace);
63 }
64
CloseTab()65 void BrowserTabRestoreServiceDelegate::CloseTab() {
66 browser_->CloseTab();
67 }
68
69 // Implementations of TabRestoreServiceDelegate static methods
70
71 // static
Create(Profile * profile)72 TabRestoreServiceDelegate* TabRestoreServiceDelegate::Create(Profile* profile) {
73 Browser* browser = Browser::Create(profile);
74 if (browser)
75 return browser->tab_restore_service_delegate();
76 else
77 return NULL;
78 }
79
80 // static
FindDelegateForController(const NavigationController * controller,int * index)81 TabRestoreServiceDelegate* TabRestoreServiceDelegate::FindDelegateForController(
82 const NavigationController* controller,
83 int* index) {
84 Browser* browser = Browser::GetBrowserForController(controller, index);
85 if (browser)
86 return browser->tab_restore_service_delegate();
87 else
88 return NULL;
89 }
90
91 // static
FindDelegateWithID(SessionID::id_type desired_id)92 TabRestoreServiceDelegate* TabRestoreServiceDelegate::FindDelegateWithID(
93 SessionID::id_type desired_id) {
94 Browser* browser = BrowserList::FindBrowserWithID(desired_id);
95 if (browser)
96 return browser->tab_restore_service_delegate();
97 else
98 return NULL;
99 }
100