OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/sessions/session_restore.h" | 5 #include "chrome/browser/sessions/session_restore.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <list> | 10 #include <list> |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 // NEW_WINDOW, in which case the tab will be opened in a new browser. Returns | 194 // NEW_WINDOW, in which case the tab will be opened in a new browser. Returns |
195 // the WebContents of the restored tab. | 195 // the WebContents of the restored tab. |
196 WebContents* RestoreForeignTab(const sessions::SessionTab& tab, | 196 WebContents* RestoreForeignTab(const sessions::SessionTab& tab, |
197 WindowOpenDisposition disposition) { | 197 WindowOpenDisposition disposition) { |
198 DCHECK(!tab.navigations.empty()); | 198 DCHECK(!tab.navigations.empty()); |
199 int selected_index = tab.current_navigation_index; | 199 int selected_index = tab.current_navigation_index; |
200 selected_index = std::max( | 200 selected_index = std::max( |
201 0, | 201 0, |
202 std::min(selected_index, static_cast<int>(tab.navigations.size() - 1))); | 202 std::min(selected_index, static_cast<int>(tab.navigations.size() - 1))); |
203 | 203 |
204 bool use_new_window = disposition == NEW_WINDOW; | 204 bool use_new_window = disposition == WindowOpenDisposition::NEW_WINDOW; |
205 | 205 |
206 Browser* browser = | 206 Browser* browser = |
207 use_new_window | 207 use_new_window |
208 ? new Browser(Browser::CreateParams(profile_)) | 208 ? new Browser(Browser::CreateParams(profile_)) |
209 : browser_; | 209 : browser_; |
210 | 210 |
211 RecordAppLaunchForTab(browser, tab, selected_index); | 211 RecordAppLaunchForTab(browser, tab, selected_index); |
212 | 212 |
213 WebContents* web_contents; | 213 WebContents* web_contents; |
214 if (disposition == CURRENT_TAB) { | 214 if (disposition == WindowOpenDisposition::CURRENT_TAB) { |
215 DCHECK(!use_new_window); | 215 DCHECK(!use_new_window); |
216 web_contents = chrome::ReplaceRestoredTab( | 216 web_contents = chrome::ReplaceRestoredTab( |
217 browser, tab.navigations, selected_index, true, tab.extension_app_id, | 217 browser, tab.navigations, selected_index, true, tab.extension_app_id, |
218 nullptr, tab.user_agent_override); | 218 nullptr, tab.user_agent_override); |
219 } else { | 219 } else { |
220 int tab_index = | 220 int tab_index = |
221 use_new_window ? 0 : browser->tab_strip_model()->active_index() + 1; | 221 use_new_window ? 0 : browser->tab_strip_model()->active_index() + 1; |
222 web_contents = chrome::AddRestoredTab( | 222 web_contents = chrome::AddRestoredTab( |
223 browser, tab.navigations, tab_index, selected_index, | 223 browser, tab.navigations, tab_index, selected_index, |
224 tab.extension_app_id, | 224 tab.extension_app_id, |
225 disposition == NEW_FOREGROUND_TAB, // selected | 225 disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB, // selected |
226 tab.pinned, true, nullptr, tab.user_agent_override); | 226 tab.pinned, true, nullptr, tab.user_agent_override); |
227 // Start loading the tab immediately. | 227 // Start loading the tab immediately. |
228 web_contents->GetController().LoadIfNecessary(); | 228 web_contents->GetController().LoadIfNecessary(); |
229 } | 229 } |
230 | 230 |
231 if (use_new_window) { | 231 if (use_new_window) { |
232 browser->tab_strip_model()->ActivateTabAt(0, true); | 232 browser->tab_strip_model()->ActivateTabAt(0, true); |
233 browser->window()->Show(); | 233 browser->window()->Show(); |
234 } | 234 } |
235 NotifySessionServiceOfRestoredTabs(browser, | 235 NotifySessionServiceOfRestoredTabs(browser, |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 } | 656 } |
657 | 657 |
658 // Appends the urls in |urls| to |browser|. | 658 // Appends the urls in |urls| to |browser|. |
659 void AppendURLsToBrowser(Browser* browser, const std::vector<GURL>& urls) { | 659 void AppendURLsToBrowser(Browser* browser, const std::vector<GURL>& urls) { |
660 for (size_t i = 0; i < urls.size(); ++i) { | 660 for (size_t i = 0; i < urls.size(); ++i) { |
661 int add_types = TabStripModel::ADD_FORCE_INDEX; | 661 int add_types = TabStripModel::ADD_FORCE_INDEX; |
662 if (i == 0) | 662 if (i == 0) |
663 add_types |= TabStripModel::ADD_ACTIVE; | 663 add_types |= TabStripModel::ADD_ACTIVE; |
664 chrome::NavigateParams params(browser, urls[i], | 664 chrome::NavigateParams params(browser, urls[i], |
665 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); | 665 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); |
666 params.disposition = i == 0 ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; | 666 params.disposition = i == 0 ? WindowOpenDisposition::NEW_FOREGROUND_TAB |
| 667 : WindowOpenDisposition::NEW_BACKGROUND_TAB; |
667 params.tabstrip_add_types = add_types; | 668 params.tabstrip_add_types = add_types; |
668 chrome::Navigate(¶ms); | 669 chrome::Navigate(¶ms); |
669 } | 670 } |
670 } | 671 } |
671 | 672 |
672 // Invokes TabRestored on the SessionService for all tabs in browser after | 673 // Invokes TabRestored on the SessionService for all tabs in browser after |
673 // initial_count. | 674 // initial_count. |
674 void NotifySessionServiceOfRestoredTabs(Browser* browser, int initial_count) { | 675 void NotifySessionServiceOfRestoredTabs(Browser* browser, int initial_count) { |
675 SessionService* session_service = | 676 SessionService* session_service = |
676 SessionServiceFactory::GetForProfile(profile_); | 677 SessionServiceFactory::GetForProfile(profile_); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 // static | 839 // static |
839 SessionRestore::CallbackSubscription | 840 SessionRestore::CallbackSubscription |
840 SessionRestore::RegisterOnSessionRestoredCallback( | 841 SessionRestore::RegisterOnSessionRestoredCallback( |
841 const base::Callback<void(int)>& callback) { | 842 const base::Callback<void(int)>& callback) { |
842 return on_session_restored_callbacks()->Add(callback); | 843 return on_session_restored_callbacks()->Add(callback); |
843 } | 844 } |
844 | 845 |
845 // static | 846 // static |
846 base::CallbackList<void(int)>* | 847 base::CallbackList<void(int)>* |
847 SessionRestore::on_session_restored_callbacks_ = nullptr; | 848 SessionRestore::on_session_restored_callbacks_ = nullptr; |
OLD | NEW |