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 <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 // Loads are scheduled for each restored tab unless the tab is going to | 514 // Loads are scheduled for each restored tab unless the tab is going to |
515 // be selected as ShowBrowser() will load the selected tab. | 515 // be selected as ShowBrowser() will load the selected tab. |
516 bool is_selected_tab = (i == selected_tab_index); | 516 bool is_selected_tab = (i == selected_tab_index); |
517 WebContents* contents = RestoreTab(tab, i, browser, is_selected_tab); | 517 WebContents* contents = RestoreTab(tab, i, browser, is_selected_tab); |
518 | 518 |
519 // RestoreTab can return nullptr if |tab| doesn't have valid data. | 519 // RestoreTab can return nullptr if |tab| doesn't have valid data. |
520 if (!contents) | 520 if (!contents) |
521 continue; | 521 continue; |
522 | 522 |
523 RestoredTab restored_tab(contents, is_selected_tab, | 523 RestoredTab restored_tab(contents, is_selected_tab, |
524 tab.extension_app_id.empty(), tab.pinned); | 524 tab.extension_app_id.empty(), tab.pinned, |
525 tab.last_activation_time); | |
525 created_contents->push_back(restored_tab); | 526 created_contents->push_back(restored_tab); |
526 | 527 |
527 // If this isn't the selected tab, there's nothing else to do. | 528 // If this isn't the selected tab, there's nothing else to do. |
528 if (!is_selected_tab) | 529 if (!is_selected_tab) |
529 continue; | 530 continue; |
530 | 531 |
531 ShowBrowser(browser, browser->tab_strip_model()->GetIndexOfWebContents( | 532 ShowBrowser(browser, browser->tab_strip_model()->GetIndexOfWebContents( |
532 contents)); | 533 contents)); |
533 // TODO(sky): remove. For debugging 368236. | 534 // TODO(sky): remove. For debugging 368236. |
534 CHECK_EQ(browser->tab_strip_model()->GetActiveWebContents(), contents); | 535 CHECK_EQ(browser->tab_strip_model()->GetActiveWebContents(), contents); |
535 } | 536 } |
536 } else { | 537 } else { |
537 // If the browser already has tabs, we want to restore the new ones after | 538 // If the browser already has tabs, we want to restore the new ones after |
538 // the existing ones. E.g. this happens in Win8 Metro where we merge | 539 // the existing ones. E.g. this happens in Win8 Metro where we merge |
539 // windows or when launching a hosted app from the app launcher. | 540 // windows or when launching a hosted app from the app launcher. |
540 int tab_index_offset = initial_tab_count; | 541 int tab_index_offset = initial_tab_count; |
541 for (int i = 0; i < static_cast<int>(window.tabs.size()); ++i) { | 542 for (int i = 0; i < static_cast<int>(window.tabs.size()); ++i) { |
542 const sessions::SessionTab& tab = *(window.tabs[i]); | 543 const sessions::SessionTab& tab = *(window.tabs[i]); |
543 // Always schedule loads as we will not be calling ShowBrowser(). | 544 // Always schedule loads as we will not be calling ShowBrowser(). |
544 WebContents* contents = | 545 WebContents* contents = |
545 RestoreTab(tab, tab_index_offset + i, browser, false); | 546 RestoreTab(tab, tab_index_offset + i, browser, false); |
546 if (contents) { | 547 if (contents) { |
547 RestoredTab restored_tab(contents, false, | 548 RestoredTab restored_tab(contents, false, |
548 tab.extension_app_id.empty(), tab.pinned); | 549 tab.extension_app_id.empty(), tab.pinned, |
550 tab.last_activation_time); | |
549 created_contents->push_back(restored_tab); | 551 created_contents->push_back(restored_tab); |
550 } | 552 } |
551 } | 553 } |
552 } | 554 } |
553 } | 555 } |
554 | 556 |
555 // |tab_index| is ignored for pinned tabs which will always be pushed behind | 557 // |tab_index| is ignored for pinned tabs which will always be pushed behind |
556 // the last existing pinned tab. | 558 // the last existing pinned tab. |
557 // |tab_loader_| will schedule this tab for loading if |is_selected_tab| is | 559 // |tab_loader_| will schedule this tab for loading if |is_selected_tab| is |
558 // false. | 560 // false. |
(...skipping 25 matching lines...) Expand all Loading... | |
584 WebContents* web_contents = chrome::AddRestoredTab( | 586 WebContents* web_contents = chrome::AddRestoredTab( |
585 browser, tab.navigations, tab_index, selected_index, | 587 browser, tab.navigations, tab_index, selected_index, |
586 tab.extension_app_id, | 588 tab.extension_app_id, |
587 false, // select | 589 false, // select |
588 tab.pinned, true, session_storage_namespace.get(), | 590 tab.pinned, true, session_storage_namespace.get(), |
589 tab.user_agent_override); | 591 tab.user_agent_override); |
590 // Regression check: check that the tab didn't start loading right away. The | 592 // Regression check: check that the tab didn't start loading right away. The |
591 // focused tab will be loaded by Browser, and TabLoader will load the rest. | 593 // focused tab will be loaded by Browser, and TabLoader will load the rest. |
592 DCHECK(web_contents->GetController().NeedsReload()); | 594 DCHECK(web_contents->GetController().NeedsReload()); |
593 | 595 |
596 // Restore the saved activation time. By default, the activation time of a | |
597 // WebContent is initially set to the creation time of the tab, which is not | |
598 // necessarly the same as the loading time. This makes sure that the state | |
599 // is preserved between restores. | |
600 web_contents->SetLastActiveTime(tab.last_activation_time); | |
sky
2015/05/12 21:25:29
It's my understanding there is no guarantee that t
Georges Khalil
2015/05/15 16:55:30
You are right, if the OS reboots, TimeTicks become
sky
2015/05/18 15:53:28
I think time ticks is safer as blocks can go back.
Georges Khalil
2015/05/19 19:32:15
I'm not sure how we could sanitize time ticks, as
sky
2015/05/19 19:55:16
After you've read the data in all we care about is
gab
2015/05/20 17:08:57
I'm not convinced that this is true. For example,
| |
601 | |
594 return web_contents; | 602 return web_contents; |
595 } | 603 } |
596 | 604 |
597 Browser* CreateRestoredBrowser(Browser::Type type, | 605 Browser* CreateRestoredBrowser(Browser::Type type, |
598 gfx::Rect bounds, | 606 gfx::Rect bounds, |
599 ui::WindowShowState show_state, | 607 ui::WindowShowState show_state, |
600 const std::string& app_name) { | 608 const std::string& app_name) { |
601 Browser::CreateParams params(type, profile_, host_desktop_type_); | 609 Browser::CreateParams params(type, profile_, host_desktop_type_); |
602 if (!app_name.empty()) { | 610 if (!app_name.empty()) { |
603 const bool trusted_source = true; // We only store trusted app windows. | 611 const bool trusted_source = true; // We only store trusted app windows. |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
825 if (prioritize_tabs == "mru") | 833 if (prioritize_tabs == "mru") |
826 return SMART_RESTORE_MODE_MRU; | 834 return SMART_RESTORE_MODE_MRU; |
827 if (prioritize_tabs == "simple") | 835 if (prioritize_tabs == "simple") |
828 return SMART_RESTORE_MODE_SIMPLE; | 836 return SMART_RESTORE_MODE_SIMPLE; |
829 return SMART_RESTORE_MODE_OFF; | 837 return SMART_RESTORE_MODE_OFF; |
830 } | 838 } |
831 | 839 |
832 // static | 840 // static |
833 base::CallbackList<void(int)>* | 841 base::CallbackList<void(int)>* |
834 SessionRestore::on_session_restored_callbacks_ = nullptr; | 842 SessionRestore::on_session_restored_callbacks_ = nullptr; |
OLD | NEW |