Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/browser/ui/browser_tab_restore_service_delegate.cc

Issue 1321713005: Abstract WebContents/NavigationController from core TabRestore code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to review Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" 5 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h"
6 6
7 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_commands.h" 8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/browser_finder.h" 9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/browser_tabrestore.h" 10 #include "chrome/browser/ui/browser_tabrestore.h"
11 #include "chrome/browser/ui/browser_window.h" 11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "components/sessions/content/content_live_tab.h"
13 #include "components/sessions/content/content_tab_client_data.h" 14 #include "components/sessions/content/content_tab_client_data.h"
14 #include "content/public/browser/navigation_controller.h" 15 #include "content/public/browser/navigation_controller.h"
15 #include "content/public/browser/session_storage_namespace.h" 16 #include "content/public/browser/session_storage_namespace.h"
16 17
17 using content::NavigationController; 18 using content::NavigationController;
18 using content::SessionStorageNamespace; 19 using content::SessionStorageNamespace;
19 using content::WebContents; 20 using content::WebContents;
20 21
21 void BrowserTabRestoreServiceDelegate::ShowBrowserWindow() { 22 void BrowserTabRestoreServiceDelegate::ShowBrowserWindow() {
22 browser_->window()->Show(); 23 browser_->window()->Show();
23 } 24 }
24 25
25 const SessionID& BrowserTabRestoreServiceDelegate::GetSessionID() const { 26 const SessionID& BrowserTabRestoreServiceDelegate::GetSessionID() const {
26 return browser_->session_id(); 27 return browser_->session_id();
27 } 28 }
28 29
29 int BrowserTabRestoreServiceDelegate::GetTabCount() const { 30 int BrowserTabRestoreServiceDelegate::GetTabCount() const {
30 return browser_->tab_strip_model()->count(); 31 return browser_->tab_strip_model()->count();
31 } 32 }
32 33
33 int BrowserTabRestoreServiceDelegate::GetSelectedIndex() const { 34 int BrowserTabRestoreServiceDelegate::GetSelectedIndex() const {
34 return browser_->tab_strip_model()->active_index(); 35 return browser_->tab_strip_model()->active_index();
35 } 36 }
36 37
37 std::string BrowserTabRestoreServiceDelegate::GetAppName() const { 38 std::string BrowserTabRestoreServiceDelegate::GetAppName() const {
38 return browser_->app_name(); 39 return browser_->app_name();
39 } 40 }
40 41
41 WebContents* BrowserTabRestoreServiceDelegate::GetWebContentsAt( 42 sessions::LiveTab* BrowserTabRestoreServiceDelegate::GetLiveTabAt(
42 int index) const { 43 int index) const {
43 return browser_->tab_strip_model()->GetWebContentsAt(index); 44 return sessions::ContentLiveTab::FromWebContents(
45 browser_->tab_strip_model()->GetWebContentsAt(index));
44 } 46 }
45 47
46 WebContents* BrowserTabRestoreServiceDelegate::GetActiveWebContents() const { 48 sessions::LiveTab* BrowserTabRestoreServiceDelegate::GetActiveLiveTab() const {
47 return browser_->tab_strip_model()->GetActiveWebContents(); 49 return sessions::ContentLiveTab::FromWebContents(
50 browser_->tab_strip_model()->GetActiveWebContents());
48 } 51 }
49 52
50 bool BrowserTabRestoreServiceDelegate::IsTabPinned(int index) const { 53 bool BrowserTabRestoreServiceDelegate::IsTabPinned(int index) const {
51 return browser_->tab_strip_model()->IsTabPinned(index); 54 return browser_->tab_strip_model()->IsTabPinned(index);
52 } 55 }
53 56
54 WebContents* BrowserTabRestoreServiceDelegate::AddRestoredTab( 57 sessions::LiveTab* BrowserTabRestoreServiceDelegate::AddRestoredTab(
55 const std::vector<sessions::SerializedNavigationEntry>& navigations, 58 const std::vector<sessions::SerializedNavigationEntry>& navigations,
56 int tab_index, 59 int tab_index,
57 int selected_navigation, 60 int selected_navigation,
58 const std::string& extension_app_id, 61 const std::string& extension_app_id,
59 bool select, 62 bool select,
60 bool pin, 63 bool pin,
61 bool from_last_session, 64 bool from_last_session,
62 const sessions::TabClientData* tab_client_data, 65 const sessions::TabClientData* tab_client_data,
63 const std::string& user_agent_override) { 66 const std::string& user_agent_override) {
64 SessionStorageNamespace* storage_namespace = 67 SessionStorageNamespace* storage_namespace =
65 tab_client_data 68 tab_client_data
66 ? static_cast<const sessions::ContentTabClientData*>(tab_client_data) 69 ? static_cast<const sessions::ContentTabClientData*>(tab_client_data)
67 ->session_storage_namespace() 70 ->session_storage_namespace()
68 : nullptr; 71 : nullptr;
69 return chrome::AddRestoredTab(browser_, navigations, tab_index, 72
70 selected_navigation, extension_app_id, select, 73 WebContents* web_contents = chrome::AddRestoredTab(
71 pin, from_last_session, storage_namespace, 74 browser_, navigations, tab_index, selected_navigation, extension_app_id,
72 user_agent_override); 75 select, pin, from_last_session, storage_namespace, user_agent_override);
76
77 return sessions::ContentLiveTab::FromWebContents(web_contents);
73 } 78 }
74 79
75 WebContents* BrowserTabRestoreServiceDelegate::ReplaceRestoredTab( 80 sessions::LiveTab* BrowserTabRestoreServiceDelegate::ReplaceRestoredTab(
76 const std::vector<sessions::SerializedNavigationEntry>& navigations, 81 const std::vector<sessions::SerializedNavigationEntry>& navigations,
77 int selected_navigation, 82 int selected_navigation,
78 bool from_last_session, 83 bool from_last_session,
79 const std::string& extension_app_id, 84 const std::string& extension_app_id,
80 const sessions::TabClientData* tab_client_data, 85 const sessions::TabClientData* tab_client_data,
81 const std::string& user_agent_override) { 86 const std::string& user_agent_override) {
82 SessionStorageNamespace* storage_namespace = 87 SessionStorageNamespace* storage_namespace =
83 tab_client_data 88 tab_client_data
84 ? static_cast<const sessions::ContentTabClientData*>(tab_client_data) 89 ? static_cast<const sessions::ContentTabClientData*>(tab_client_data)
85 ->session_storage_namespace() 90 ->session_storage_namespace()
86 : nullptr; 91 : nullptr;
87 return chrome::ReplaceRestoredTab(browser_, navigations, selected_navigation, 92
88 from_last_session, extension_app_id, 93 WebContents* web_contents = chrome::ReplaceRestoredTab(
89 storage_namespace, user_agent_override); 94 browser_, navigations, selected_navigation, from_last_session,
95 extension_app_id, storage_namespace, user_agent_override);
96
97 return sessions::ContentLiveTab::FromWebContents(web_contents);
90 } 98 }
91 99
92 void BrowserTabRestoreServiceDelegate::CloseTab() { 100 void BrowserTabRestoreServiceDelegate::CloseTab() {
93 chrome::CloseTab(browser_); 101 chrome::CloseTab(browser_);
94 } 102 }
95 103
96 // static 104 // static
97 TabRestoreServiceDelegate* BrowserTabRestoreServiceDelegate::Create( 105 TabRestoreServiceDelegate* BrowserTabRestoreServiceDelegate::Create(
98 Profile* profile, 106 Profile* profile,
99 chrome::HostDesktopType host_desktop_type, 107 chrome::HostDesktopType host_desktop_type,
(...skipping 12 matching lines...) Expand all
112 return browser->tab_restore_service_delegate(); 120 return browser->tab_restore_service_delegate();
113 else 121 else
114 return NULL; 122 return NULL;
115 } 123 }
116 124
117 // static 125 // static
118 TabRestoreServiceDelegate* 126 TabRestoreServiceDelegate*
119 BrowserTabRestoreServiceDelegate::FindDelegateForWebContents( 127 BrowserTabRestoreServiceDelegate::FindDelegateForWebContents(
120 const WebContents* contents) { 128 const WebContents* contents) {
121 Browser* browser = chrome::FindBrowserWithWebContents(contents); 129 Browser* browser = chrome::FindBrowserWithWebContents(contents);
122 return browser ? browser->tab_restore_service_delegate() : NULL; 130 return browser ? browser->tab_restore_service_delegate() : nullptr;
123 } 131 }
124 132
125 // static 133 // static
126 TabRestoreServiceDelegate* BrowserTabRestoreServiceDelegate::FindDelegateWithID( 134 TabRestoreServiceDelegate* BrowserTabRestoreServiceDelegate::FindDelegateWithID(
127 SessionID::id_type desired_id, 135 SessionID::id_type desired_id,
128 chrome::HostDesktopType host_desktop_type) { 136 chrome::HostDesktopType host_desktop_type) {
129 Browser* browser = chrome::FindBrowserWithID(desired_id); 137 Browser* browser = chrome::FindBrowserWithID(desired_id);
130 return (browser && browser->host_desktop_type() == host_desktop_type) ? 138 return (browser && browser->host_desktop_type() == host_desktop_type) ?
131 browser->tab_restore_service_delegate() : NULL; 139 browser->tab_restore_service_delegate() : NULL;
132 } 140 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_tab_restore_service_delegate.h ('k') | chrome/browser/ui/browser_tab_strip_model_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698