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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 // Even if all windows are ui::SHOW_STATE_MINIMIZED, if one of them is the | 392 // Even if all windows are ui::SHOW_STATE_MINIMIZED, if one of them is the |
393 // active window it will be made visible by the call to | 393 // active window it will be made visible by the call to |
394 // browser_to_activate->window()->Activate() later on in this method. | 394 // browser_to_activate->window()->Activate() later on in this method. |
395 bool has_visible_browser = false; | 395 bool has_visible_browser = false; |
396 for (const auto& window : *windows) { | 396 for (const auto& window : *windows) { |
397 if (window->show_state != ui::SHOW_STATE_MINIMIZED || | 397 if (window->show_state != ui::SHOW_STATE_MINIMIZED || |
398 window->window_id.id() == active_window_id) | 398 window->window_id.id() == active_window_id) |
399 has_visible_browser = true; | 399 has_visible_browser = true; |
400 } | 400 } |
401 | 401 |
402 // Always move the session window with |active_window_id| to the front, so | |
sky
2017/03/07 17:34:19
Now that I think about it you shouldn't reorder wi
Qiang(Joe) Xu
2017/03/07 21:17:04
ok, thanks for the info. Another solution I upload
| |
403 // that if the first session window is restored to the existing tabbed | |
404 // browser, the existing browser is the |browser_to_activate|. | |
405 for (auto i = windows->begin(); i != windows->end(); ++i) { | |
406 if ((*i)->window_id.id() == active_window_id) { | |
407 std::iter_swap(windows->begin(), i); | |
408 break; | |
409 } | |
410 } | |
411 | |
402 for (auto i = windows->begin(); i != windows->end(); ++i) { | 412 for (auto i = windows->begin(); i != windows->end(); ++i) { |
403 Browser* browser = nullptr; | 413 Browser* browser = nullptr; |
404 if (!has_tabbed_browser && | 414 if (!has_tabbed_browser && |
405 (*i)->type == sessions::SessionWindow::TYPE_TABBED) | 415 (*i)->type == sessions::SessionWindow::TYPE_TABBED) |
406 has_tabbed_browser = true; | 416 has_tabbed_browser = true; |
407 if (i == windows->begin() && | 417 if (i == windows->begin() && |
408 (*i)->type == sessions::SessionWindow::TYPE_TABBED && browser_ && | 418 (*i)->type == sessions::SessionWindow::TYPE_TABBED && browser_ && |
409 browser_->is_type_tabbed() && | 419 browser_->is_type_tabbed() && |
410 !browser_->profile()->IsOffTheRecord()) { | 420 !browser_->profile()->IsOffTheRecord()) { |
411 // The first set of tabs is added to the existing browser. | 421 // The first set of tabs is added to the existing browser. |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 browser->tab_strip_model()->ActivateTabAt(selected_tab_index, true); | 659 browser->tab_strip_model()->ActivateTabAt(selected_tab_index, true); |
650 | 660 |
651 if (browser_ == browser) | 661 if (browser_ == browser) |
652 return; | 662 return; |
653 | 663 |
654 browser->window()->Show(); | 664 browser->window()->Show(); |
655 browser->set_is_session_restore(false); | 665 browser->set_is_session_restore(false); |
656 | 666 |
657 // TODO(jcampan): http://crbug.com/8123 we should not need to set the | 667 // TODO(jcampan): http://crbug.com/8123 we should not need to set the |
658 // initial focus explicitly. | 668 // initial focus explicitly. |
659 browser->tab_strip_model()->GetActiveWebContents()->SetInitialFocus(); | 669 if (browser->window()->IsActive()) |
670 browser->tab_strip_model()->GetActiveWebContents()->SetInitialFocus(); | |
660 } | 671 } |
661 | 672 |
662 // Appends the urls in |urls| to |browser|. | 673 // Appends the urls in |urls| to |browser|. |
663 void AppendURLsToBrowser(Browser* browser, const std::vector<GURL>& urls) { | 674 void AppendURLsToBrowser(Browser* browser, const std::vector<GURL>& urls) { |
664 for (size_t i = 0; i < urls.size(); ++i) { | 675 for (size_t i = 0; i < urls.size(); ++i) { |
665 int add_types = TabStripModel::ADD_FORCE_INDEX; | 676 int add_types = TabStripModel::ADD_FORCE_INDEX; |
666 if (i == 0) | 677 if (i == 0) |
667 add_types |= TabStripModel::ADD_ACTIVE; | 678 add_types |= TabStripModel::ADD_ACTIVE; |
668 chrome::NavigateParams params(browser, urls[i], | 679 chrome::NavigateParams params(browser, urls[i], |
669 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); | 680 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
844 // static | 855 // static |
845 SessionRestore::CallbackSubscription | 856 SessionRestore::CallbackSubscription |
846 SessionRestore::RegisterOnSessionRestoredCallback( | 857 SessionRestore::RegisterOnSessionRestoredCallback( |
847 const base::Callback<void(int)>& callback) { | 858 const base::Callback<void(int)>& callback) { |
848 return on_session_restored_callbacks()->Add(callback); | 859 return on_session_restored_callbacks()->Add(callback); |
849 } | 860 } |
850 | 861 |
851 // static | 862 // static |
852 base::CallbackList<void(int)>* | 863 base::CallbackList<void(int)>* |
853 SessionRestore::on_session_restored_callbacks_ = nullptr; | 864 SessionRestore::on_session_restored_callbacks_ = nullptr; |
OLD | NEW |