Home | History | Annotate | Download | only in ui
      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 
     11 void BrowserTabRestoreServiceDelegate::ShowBrowserWindow() {
     12   browser_->window()->Show();
     13 }
     14 
     15 const SessionID& BrowserTabRestoreServiceDelegate::GetSessionID() const {
     16   return browser_->session_id();
     17 }
     18 
     19 int BrowserTabRestoreServiceDelegate::GetTabCount() const {
     20   return browser_->tab_count();
     21 }
     22 
     23 int BrowserTabRestoreServiceDelegate::GetSelectedIndex() const {
     24   return browser_->active_index();
     25 }
     26 
     27 TabContents* BrowserTabRestoreServiceDelegate::GetTabContentsAt(
     28     int index) const {
     29   return browser_->GetTabContentsAt(index);
     30 }
     31 
     32 TabContents* BrowserTabRestoreServiceDelegate::GetSelectedTabContents() const {
     33   return browser_->GetSelectedTabContents();
     34 }
     35 
     36 bool BrowserTabRestoreServiceDelegate::IsTabPinned(int index) const {
     37   return browser_->IsTabPinned(index);
     38 }
     39 
     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 
     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 
     65 void BrowserTabRestoreServiceDelegate::CloseTab() {
     66   browser_->CloseTab();
     67 }
     68 
     69 // Implementations of TabRestoreServiceDelegate static methods
     70 
     71 // static
     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
     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
     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