Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / browser_tab_restore_service_delegate.cc
blob75e1c24e0a7077c513299517252e4a24ffce7dfe
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/browser_tabrestore.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "content/public/browser/navigation_controller.h"
15 using content::NavigationController;
16 using content::SessionStorageNamespace;
17 using content::WebContents;
19 void BrowserTabRestoreServiceDelegate::ShowBrowserWindow() {
20 browser_->window()->Show();
23 const SessionID& BrowserTabRestoreServiceDelegate::GetSessionID() const {
24 return browser_->session_id();
27 int BrowserTabRestoreServiceDelegate::GetTabCount() const {
28 return browser_->tab_strip_model()->count();
31 int BrowserTabRestoreServiceDelegate::GetSelectedIndex() const {
32 return browser_->tab_strip_model()->active_index();
35 std::string BrowserTabRestoreServiceDelegate::GetAppName() const {
36 return browser_->app_name();
39 WebContents* BrowserTabRestoreServiceDelegate::GetWebContentsAt(
40 int index) const {
41 return browser_->tab_strip_model()->GetWebContentsAt(index);
44 WebContents* BrowserTabRestoreServiceDelegate::GetActiveWebContents() const {
45 return browser_->tab_strip_model()->GetActiveWebContents();
48 bool BrowserTabRestoreServiceDelegate::IsTabPinned(int index) const {
49 return browser_->tab_strip_model()->IsTabPinned(index);
52 WebContents* BrowserTabRestoreServiceDelegate::AddRestoredTab(
53 const std::vector<sessions::SerializedNavigationEntry>& navigations,
54 int tab_index,
55 int selected_navigation,
56 const std::string& extension_app_id,
57 bool select,
58 bool pin,
59 bool from_last_session,
60 SessionStorageNamespace* storage_namespace,
61 const std::string& user_agent_override) {
62 return chrome::AddRestoredTab(browser_, navigations, tab_index,
63 selected_navigation, extension_app_id, select,
64 pin, from_last_session, storage_namespace,
65 user_agent_override);
68 WebContents* BrowserTabRestoreServiceDelegate::ReplaceRestoredTab(
69 const std::vector<sessions::SerializedNavigationEntry>& navigations,
70 int selected_navigation,
71 bool from_last_session,
72 const std::string& extension_app_id,
73 SessionStorageNamespace* session_storage_namespace,
74 const std::string& user_agent_override) {
75 return chrome::ReplaceRestoredTab(browser_, navigations, selected_navigation,
76 from_last_session, extension_app_id,
77 session_storage_namespace, user_agent_override);
80 void BrowserTabRestoreServiceDelegate::CloseTab() {
81 chrome::CloseTab(browser_);
84 // Implementations of TabRestoreServiceDelegate static methods
86 // static
87 TabRestoreServiceDelegate* TabRestoreServiceDelegate::Create(
88 Profile* profile,
89 chrome::HostDesktopType host_desktop_type,
90 const std::string& app_name) {
91 Browser* browser;
92 if (app_name.empty()) {
93 browser = new Browser(Browser::CreateParams(profile, host_desktop_type));
94 } else {
95 // Only trusted app popup windows should ever be restored.
96 browser = new Browser(
97 Browser::CreateParams::CreateForApp(
98 app_name, true /* trusted_source */, gfx::Rect(), profile,
99 host_desktop_type));
101 if (browser)
102 return browser->tab_restore_service_delegate();
103 else
104 return NULL;
107 // static
108 TabRestoreServiceDelegate*
109 TabRestoreServiceDelegate::FindDelegateForWebContents(
110 const WebContents* contents) {
111 Browser* browser = chrome::FindBrowserWithWebContents(contents);
112 return browser ? browser->tab_restore_service_delegate() : NULL;
115 // static
116 TabRestoreServiceDelegate* TabRestoreServiceDelegate::FindDelegateWithID(
117 SessionID::id_type desired_id,
118 chrome::HostDesktopType host_desktop_type) {
119 Browser* browser = chrome::FindBrowserWithID(desired_id);
120 return (browser && browser->host_desktop_type() == host_desktop_type) ?
121 browser->tab_restore_service_delegate() : NULL;