| 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 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 // false. | 581 // false. |
| 582 WebContents* RestoreTab(const sessions::SessionTab& tab, | 582 WebContents* RestoreTab(const sessions::SessionTab& tab, |
| 583 const int tab_index, | 583 const int tab_index, |
| 584 Browser* browser, | 584 Browser* browser, |
| 585 bool is_selected_tab) { | 585 bool is_selected_tab) { |
| 586 // It's possible (particularly for foreign sessions) to receive a tab | 586 // It's possible (particularly for foreign sessions) to receive a tab |
| 587 // without valid navigations. In that case, just skip it. | 587 // without valid navigations. In that case, just skip it. |
| 588 // See crbug.com/154129. | 588 // See crbug.com/154129. |
| 589 if (tab.navigations.empty()) | 589 if (tab.navigations.empty()) |
| 590 return nullptr; | 590 return nullptr; |
| 591 int selected_index = tab.current_navigation_index; | 591 int selected_index = GetSelectedIndexFromTab(tab); |
| 592 selected_index = std::max( | |
| 593 0, | |
| 594 std::min(selected_index, static_cast<int>(tab.navigations.size() - 1))); | |
| 595 | 592 |
| 596 RecordAppLaunchForTab(browser, tab, selected_index); | 593 RecordAppLaunchForTab(browser, tab, selected_index); |
| 597 | 594 |
| 598 // Associate sessionStorage (if any) to the restored tab. | 595 // Associate sessionStorage (if any) to the restored tab. |
| 599 scoped_refptr<content::SessionStorageNamespace> session_storage_namespace; | 596 scoped_refptr<content::SessionStorageNamespace> session_storage_namespace; |
| 600 if (!tab.session_storage_persistent_id.empty()) { | 597 if (!tab.session_storage_persistent_id.empty()) { |
| 601 session_storage_namespace = | 598 session_storage_namespace = |
| 602 content::BrowserContext::GetDefaultStoragePartition(profile_) | 599 content::BrowserContext::GetDefaultStoragePartition(profile_) |
| 603 ->GetDOMStorageContext() | 600 ->GetDOMStorageContext() |
| 604 ->RecreateSessionStorage(tab.session_storage_persistent_id); | 601 ->RecreateSessionStorage(tab.session_storage_persistent_id); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 // static | 833 // static |
| 837 SessionRestore::CallbackSubscription | 834 SessionRestore::CallbackSubscription |
| 838 SessionRestore::RegisterOnSessionRestoredCallback( | 835 SessionRestore::RegisterOnSessionRestoredCallback( |
| 839 const base::Callback<void(int)>& callback) { | 836 const base::Callback<void(int)>& callback) { |
| 840 return on_session_restored_callbacks()->Add(callback); | 837 return on_session_restored_callbacks()->Add(callback); |
| 841 } | 838 } |
| 842 | 839 |
| 843 // static | 840 // static |
| 844 base::CallbackList<void(int)>* | 841 base::CallbackList<void(int)>* |
| 845 SessionRestore::on_session_restored_callbacks_ = nullptr; | 842 SessionRestore::on_session_restored_callbacks_ = nullptr; |
| OLD | NEW |