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 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 contents->SetLastActiveTime(now - delta); | 551 contents->SetLastActiveTime(now - delta); |
552 | 552 |
553 RestoredTab restored_tab(contents, is_selected_tab, | 553 RestoredTab restored_tab(contents, is_selected_tab, |
554 tab.extension_app_id.empty(), tab.pinned); | 554 tab.extension_app_id.empty(), tab.pinned); |
555 created_contents->push_back(restored_tab); | 555 created_contents->push_back(restored_tab); |
556 | 556 |
557 // If this isn't the selected tab, there's nothing else to do. | 557 // If this isn't the selected tab, there's nothing else to do. |
558 if (!is_selected_tab) | 558 if (!is_selected_tab) |
559 continue; | 559 continue; |
560 | 560 |
561 ShowBrowser(browser, browser->tab_strip_model()->GetIndexOfWebContents( | 561 ShowBrowser(browser, |
562 contents)); | 562 browser->tab_strip_model()->GetIndexOfWebContents(contents), |
563 window.show_state); | |
563 // TODO(sky): remove. For debugging 368236. | 564 // TODO(sky): remove. For debugging 368236. |
564 CHECK_EQ(browser->tab_strip_model()->GetActiveWebContents(), contents); | 565 CHECK_EQ(browser->tab_strip_model()->GetActiveWebContents(), contents); |
565 } | 566 } |
566 } else { | 567 } else { |
567 // If the browser already has tabs, we want to restore the new ones after | 568 // If the browser already has tabs, we want to restore the new ones after |
568 // the existing ones. E.g. this happens in Win8 Metro where we merge | 569 // the existing ones. E.g. this happens in Win8 Metro where we merge |
569 // windows or when launching a hosted app from the app launcher. | 570 // windows or when launching a hosted app from the app launcher. |
570 int tab_index_offset = initial_tab_count; | 571 int tab_index_offset = initial_tab_count; |
571 for (int i = 0; i < static_cast<int>(window.tabs.size()); ++i) { | 572 for (int i = 0; i < static_cast<int>(window.tabs.size()); ++i) { |
572 const sessions::SessionTab& tab = *(window.tabs[i]); | 573 const sessions::SessionTab& tab = *(window.tabs[i]); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 ui::WindowShowState show_state, | 631 ui::WindowShowState show_state, |
631 const std::string& app_name) { | 632 const std::string& app_name) { |
632 Browser::CreateParams params(type, profile_, false); | 633 Browser::CreateParams params(type, profile_, false); |
633 if (!app_name.empty()) { | 634 if (!app_name.empty()) { |
634 const bool trusted_source = true; // We only store trusted app windows. | 635 const bool trusted_source = true; // We only store trusted app windows. |
635 params = Browser::CreateParams::CreateForApp(app_name, trusted_source, | 636 params = Browser::CreateParams::CreateForApp(app_name, trusted_source, |
636 bounds, profile_, false); | 637 bounds, profile_, false); |
637 } else { | 638 } else { |
638 params.initial_bounds = bounds; | 639 params.initial_bounds = bounds; |
639 } | 640 } |
640 params.initial_show_state = show_state; | 641 params.initial_show_state = show_state; |
sky
2017/02/23 03:37:37
The show state is plumbed through here. Is the Sho
Qiang(Joe) Xu
2017/02/23 20:53:14
show states are all right. The ps1's remedy seems
| |
641 params.initial_workspace = workspace; | 642 params.initial_workspace = workspace; |
642 params.is_session_restore = true; | 643 params.is_session_restore = true; |
643 return new Browser(params); | 644 return new Browser(params); |
644 } | 645 } |
645 | 646 |
646 void ShowBrowser(Browser* browser, int selected_tab_index) { | 647 void ShowBrowser(Browser* browser, |
648 int selected_tab_index, | |
649 ui::WindowShowState show_state) { | |
647 DCHECK(browser); | 650 DCHECK(browser); |
648 DCHECK(browser->tab_strip_model()->count()); | 651 DCHECK(browser->tab_strip_model()->count()); |
649 browser->tab_strip_model()->ActivateTabAt(selected_tab_index, true); | 652 browser->tab_strip_model()->ActivateTabAt(selected_tab_index, true); |
650 | 653 |
651 if (browser_ == browser) | 654 show_state == ui::SHOW_STATE_MINIMIZED ? browser->window()->Minimize() |
652 return; | 655 : browser->window()->Show(); |
653 | |
654 browser->window()->Show(); | |
655 browser->set_is_session_restore(false); | 656 browser->set_is_session_restore(false); |
656 | 657 |
657 // TODO(jcampan): http://crbug.com/8123 we should not need to set the | 658 // TODO(jcampan): http://crbug.com/8123 we should not need to set the |
658 // initial focus explicitly. | 659 // initial focus explicitly. |
659 browser->tab_strip_model()->GetActiveWebContents()->SetInitialFocus(); | 660 browser->tab_strip_model()->GetActiveWebContents()->SetInitialFocus(); |
660 } | 661 } |
661 | 662 |
662 // Appends the urls in |urls| to |browser|. | 663 // Appends the urls in |urls| to |browser|. |
663 void AppendURLsToBrowser(Browser* browser, const std::vector<GURL>& urls) { | 664 void AppendURLsToBrowser(Browser* browser, const std::vector<GURL>& urls) { |
664 for (size_t i = 0; i < urls.size(); ++i) { | 665 for (size_t i = 0; i < urls.size(); ++i) { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
844 // static | 845 // static |
845 SessionRestore::CallbackSubscription | 846 SessionRestore::CallbackSubscription |
846 SessionRestore::RegisterOnSessionRestoredCallback( | 847 SessionRestore::RegisterOnSessionRestoredCallback( |
847 const base::Callback<void(int)>& callback) { | 848 const base::Callback<void(int)>& callback) { |
848 return on_session_restored_callbacks()->Add(callback); | 849 return on_session_restored_callbacks()->Add(callback); |
849 } | 850 } |
850 | 851 |
851 // static | 852 // static |
852 base::CallbackList<void(int)>* | 853 base::CallbackList<void(int)>* |
853 SessionRestore::on_session_restored_callbacks_ = nullptr; | 854 SessionRestore::on_session_restored_callbacks_ = nullptr; |
OLD | NEW |