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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 // Restore window(s) from a foreign session. Returns newly created Browsers. | 156 // Restore window(s) from a foreign session. Returns newly created Browsers. |
157 std::vector<Browser*> RestoreForeignSession( | 157 std::vector<Browser*> RestoreForeignSession( |
158 std::vector<const sessions::SessionWindow*>::const_iterator begin, | 158 std::vector<const sessions::SessionWindow*>::const_iterator begin, |
159 std::vector<const sessions::SessionWindow*>::const_iterator end) { | 159 std::vector<const sessions::SessionWindow*>::const_iterator end) { |
160 std::vector<Browser*> browsers; | 160 std::vector<Browser*> browsers; |
161 std::vector<RestoredTab> created_contents; | 161 std::vector<RestoredTab> created_contents; |
162 // Create a browser instance to put the restored tabs in. | 162 // Create a browser instance to put the restored tabs in. |
163 for (std::vector<const sessions::SessionWindow*>::const_iterator i = begin; | 163 for (std::vector<const sessions::SessionWindow*>::const_iterator i = begin; |
164 i != end; ++i) { | 164 i != end; ++i) { |
165 Browser* browser = | 165 Browser* browser = CreateRestoredBrowser( |
166 CreateRestoredBrowser(BrowserTypeForWindowType((*i)->type), | 166 BrowserTypeForWindowType((*i)->type), (*i)->bounds, (*i)->workspace, |
167 (*i)->bounds, (*i)->show_state, (*i)->app_name); | 167 (*i)->show_state, (*i)->app_name); |
168 browsers.push_back(browser); | 168 browsers.push_back(browser); |
169 | 169 |
170 // Restore and show the browser. | 170 // Restore and show the browser. |
171 const int initial_tab_count = 0; | 171 const int initial_tab_count = 0; |
172 int selected_tab_index = | 172 int selected_tab_index = |
173 std::max(0, std::min((*i)->selected_tab_index, | 173 std::max(0, std::min((*i)->selected_tab_index, |
174 static_cast<int>((*i)->tabs.size()) - 1)); | 174 static_cast<int>((*i)->tabs.size()) - 1)); |
175 RestoreTabsToBrowser(*(*i), browser, initial_tab_count, | 175 RestoreTabsToBrowser(*(*i), browser, initial_tab_count, |
176 selected_tab_index, &created_contents); | 176 selected_tab_index, &created_contents); |
177 NotifySessionServiceOfRestoredTabs(browser, initial_tab_count); | 177 NotifySessionServiceOfRestoredTabs(browser, initial_tab_count); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 #if defined(OS_CHROMEOS) | 404 #if defined(OS_CHROMEOS) |
405 chromeos::BootTimesRecorder::Get()->AddLoginTimeMarker( | 405 chromeos::BootTimesRecorder::Get()->AddLoginTimeMarker( |
406 "SessionRestore-CreateRestoredBrowser-Start", false); | 406 "SessionRestore-CreateRestoredBrowser-Start", false); |
407 #endif | 407 #endif |
408 // Show the first window if none are visible. | 408 // Show the first window if none are visible. |
409 ui::WindowShowState show_state = (*i)->show_state; | 409 ui::WindowShowState show_state = (*i)->show_state; |
410 if (!has_visible_browser) { | 410 if (!has_visible_browser) { |
411 show_state = ui::SHOW_STATE_NORMAL; | 411 show_state = ui::SHOW_STATE_NORMAL; |
412 has_visible_browser = true; | 412 has_visible_browser = true; |
413 } | 413 } |
414 browser = | 414 browser = CreateRestoredBrowser(BrowserTypeForWindowType((*i)->type), |
415 CreateRestoredBrowser(BrowserTypeForWindowType((*i)->type), | 415 (*i)->bounds, (*i)->workspace, |
416 (*i)->bounds, show_state, (*i)->app_name); | 416 show_state, (*i)->app_name); |
417 #if defined(OS_CHROMEOS) | 417 #if defined(OS_CHROMEOS) |
418 chromeos::BootTimesRecorder::Get()->AddLoginTimeMarker( | 418 chromeos::BootTimesRecorder::Get()->AddLoginTimeMarker( |
419 "SessionRestore-CreateRestoredBrowser-End", false); | 419 "SessionRestore-CreateRestoredBrowser-End", false); |
420 #endif | 420 #endif |
421 } | 421 } |
422 if ((*i)->type == sessions::SessionWindow::TYPE_TABBED) | 422 if ((*i)->type == sessions::SessionWindow::TYPE_TABBED) |
423 last_browser = browser; | 423 last_browser = browser; |
424 WebContents* active_tab = | 424 WebContents* active_tab = |
425 browser->tab_strip_model()->GetActiveWebContents(); | 425 browser->tab_strip_model()->GetActiveWebContents(); |
426 int initial_tab_count = browser->tab_strip_model()->count(); | 426 int initial_tab_count = browser->tab_strip_model()->count(); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 tab.user_agent_override); | 612 tab.user_agent_override); |
613 // Regression check: check that the tab didn't start loading right away. The | 613 // Regression check: check that the tab didn't start loading right away. The |
614 // focused tab will be loaded by Browser, and TabLoader will load the rest. | 614 // focused tab will be loaded by Browser, and TabLoader will load the rest. |
615 DCHECK(web_contents->GetController().NeedsReload()); | 615 DCHECK(web_contents->GetController().NeedsReload()); |
616 | 616 |
617 return web_contents; | 617 return web_contents; |
618 } | 618 } |
619 | 619 |
620 Browser* CreateRestoredBrowser(Browser::Type type, | 620 Browser* CreateRestoredBrowser(Browser::Type type, |
621 gfx::Rect bounds, | 621 gfx::Rect bounds, |
| 622 const std::string& workspace, |
622 ui::WindowShowState show_state, | 623 ui::WindowShowState show_state, |
623 const std::string& app_name) { | 624 const std::string& app_name) { |
624 Browser::CreateParams params(type, profile_); | 625 Browser::CreateParams params(type, profile_); |
625 if (!app_name.empty()) { | 626 if (!app_name.empty()) { |
626 const bool trusted_source = true; // We only store trusted app windows. | 627 const bool trusted_source = true; // We only store trusted app windows. |
627 params = Browser::CreateParams::CreateForApp(app_name, trusted_source, | 628 params = Browser::CreateParams::CreateForApp(app_name, trusted_source, |
628 bounds, profile_); | 629 bounds, profile_); |
629 } else { | 630 } else { |
630 params.initial_bounds = bounds; | 631 params.initial_bounds = bounds; |
631 } | 632 } |
632 params.initial_show_state = show_state; | 633 params.initial_show_state = show_state; |
| 634 params.initial_workspace = workspace; |
633 params.is_session_restore = true; | 635 params.is_session_restore = true; |
634 return new Browser(params); | 636 return new Browser(params); |
635 } | 637 } |
636 | 638 |
637 void ShowBrowser(Browser* browser, int selected_tab_index) { | 639 void ShowBrowser(Browser* browser, int selected_tab_index) { |
638 DCHECK(browser); | 640 DCHECK(browser); |
639 DCHECK(browser->tab_strip_model()->count()); | 641 DCHECK(browser->tab_strip_model()->count()); |
640 browser->tab_strip_model()->ActivateTabAt(selected_tab_index, true); | 642 browser->tab_strip_model()->ActivateTabAt(selected_tab_index, true); |
641 | 643 |
642 if (browser_ == browser) | 644 if (browser_ == browser) |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 // static | 835 // static |
834 SessionRestore::CallbackSubscription | 836 SessionRestore::CallbackSubscription |
835 SessionRestore::RegisterOnSessionRestoredCallback( | 837 SessionRestore::RegisterOnSessionRestoredCallback( |
836 const base::Callback<void(int)>& callback) { | 838 const base::Callback<void(int)>& callback) { |
837 return on_session_restored_callbacks()->Add(callback); | 839 return on_session_restored_callbacks()->Add(callback); |
838 } | 840 } |
839 | 841 |
840 // static | 842 // static |
841 base::CallbackList<void(int)>* | 843 base::CallbackList<void(int)>* |
842 SessionRestore::on_session_restored_callbacks_ = nullptr; | 844 SessionRestore::on_session_restored_callbacks_ = nullptr; |
OLD | NEW |