summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/browser_tab_restore_service_delegate.cc
blob: 75e1c24e0a7077c513299517252e4a24ffce7dfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright (c) 2012 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/ui/browser_tab_restore_service_delegate.h"

#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_tabrestore.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "content/public/browser/navigation_controller.h"

using content::NavigationController;
using content::SessionStorageNamespace;
using content::WebContents;

void BrowserTabRestoreServiceDelegate::ShowBrowserWindow() {
  browser_->window()->Show();
}

const SessionID& BrowserTabRestoreServiceDelegate::GetSessionID() const {
  return browser_->session_id();
}

int BrowserTabRestoreServiceDelegate::GetTabCount() const {
  return browser_->tab_strip_model()->count();
}

int BrowserTabRestoreServiceDelegate::GetSelectedIndex() const {
  return browser_->tab_strip_model()->active_index();
}

std::string BrowserTabRestoreServiceDelegate::GetAppName() const {
  return browser_->app_name();
}

WebContents* BrowserTabRestoreServiceDelegate::GetWebContentsAt(
    int index) const {
  return browser_->tab_strip_model()->GetWebContentsAt(index);
}

WebContents* BrowserTabRestoreServiceDelegate::GetActiveWebContents() const {
  return browser_->tab_strip_model()->GetActiveWebContents();
}

bool BrowserTabRestoreServiceDelegate::IsTabPinned(int index) const {
  return browser_->tab_strip_model()->IsTabPinned(index);
}

WebContents* BrowserTabRestoreServiceDelegate::AddRestoredTab(
      const std::vector<sessions::SerializedNavigationEntry>& navigations,
      int tab_index,
      int selected_navigation,
      const std::string& extension_app_id,
      bool select,
      bool pin,
      bool from_last_session,
      SessionStorageNamespace* storage_namespace,
      const std::string& user_agent_override) {
  return chrome::AddRestoredTab(browser_, navigations, tab_index,
                                selected_navigation, extension_app_id, select,
                                pin, from_last_session, storage_namespace,
                                user_agent_override);
}

WebContents* BrowserTabRestoreServiceDelegate::ReplaceRestoredTab(
      const std::vector<sessions::SerializedNavigationEntry>& navigations,
      int selected_navigation,
      bool from_last_session,
      const std::string& extension_app_id,
      SessionStorageNamespace* session_storage_namespace,
      const std::string& user_agent_override) {
  return chrome::ReplaceRestoredTab(browser_, navigations, selected_navigation,
                             from_last_session, extension_app_id,
                             session_storage_namespace, user_agent_override);
}

void BrowserTabRestoreServiceDelegate::CloseTab() {
  chrome::CloseTab(browser_);
}

// Implementations of TabRestoreServiceDelegate static methods

// static
TabRestoreServiceDelegate* TabRestoreServiceDelegate::Create(
    Profile* profile,
    chrome::HostDesktopType host_desktop_type,
    const std::string& app_name) {
  Browser* browser;
  if (app_name.empty()) {
    browser = new Browser(Browser::CreateParams(profile, host_desktop_type));
  } else {
    // Only trusted app popup windows should ever be restored.
    browser = new Browser(
        Browser::CreateParams::CreateForApp(
            app_name, true /* trusted_source */, gfx::Rect(), profile,
            host_desktop_type));
  }
  if (browser)
    return browser->tab_restore_service_delegate();
  else
    return NULL;
}

// static
TabRestoreServiceDelegate*
    TabRestoreServiceDelegate::FindDelegateForWebContents(
        const WebContents* contents) {
  Browser* browser = chrome::FindBrowserWithWebContents(contents);
  return browser ? browser->tab_restore_service_delegate() : NULL;
}

// static
TabRestoreServiceDelegate* TabRestoreServiceDelegate::FindDelegateWithID(
    SessionID::id_type desired_id,
    chrome::HostDesktopType host_desktop_type) {
  Browser* browser = chrome::FindBrowserWithID(desired_id);
  return (browser && browser->host_desktop_type() == host_desktop_type) ?
             browser->tab_restore_service_delegate() : NULL;
}