OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/tab_restore_service.h" | 5 #include "chrome/browser/sessions/tab_restore_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 if (!restoring_tab_in_window) { | 331 if (!restoring_tab_in_window) { |
332 browser = Browser::Create(profile()); | 332 browser = Browser::Create(profile()); |
333 for (size_t tab_i = 0; tab_i < window->tabs.size(); ++tab_i) { | 333 for (size_t tab_i = 0; tab_i < window->tabs.size(); ++tab_i) { |
334 const Tab& tab = window->tabs[tab_i]; | 334 const Tab& tab = window->tabs[tab_i]; |
335 TabContents* restored_tab = | 335 TabContents* restored_tab = |
336 browser->AddRestoredTab(tab.navigations, browser->tab_count(), | 336 browser->AddRestoredTab(tab.navigations, browser->tab_count(), |
337 tab.current_navigation_index, | 337 tab.current_navigation_index, |
338 tab.extension_app_id, | 338 tab.extension_app_id, |
339 (static_cast<int>(tab_i) == | 339 (static_cast<int>(tab_i) == |
340 window->selected_tab_index), | 340 window->selected_tab_index), |
341 tab.pinned, tab.from_last_session); | 341 tab.pinned, tab.from_last_session, |
| 342 tab.session_storage_namespace); |
342 if (restored_tab) | 343 if (restored_tab) |
343 restored_tab->controller().LoadIfNecessary(); | 344 restored_tab->controller().LoadIfNecessary(); |
344 } | 345 } |
345 // All the window's tabs had the same former browser_id. | 346 // All the window's tabs had the same former browser_id. |
346 if (window->tabs[0].has_browser()) { | 347 if (window->tabs[0].has_browser()) { |
347 UpdateTabBrowserIDs(window->tabs[0].browser_id, | 348 UpdateTabBrowserIDs(window->tabs[0].browser_id, |
348 browser->session_id().id()); | 349 browser->session_id().id()); |
349 } | 350 } |
350 } else { | 351 } else { |
351 // Restore a single tab from the window. Find the tab that matches the ID | 352 // Restore a single tab from the window. Find the tab that matches the ID |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 } | 470 } |
470 tab->timestamp = TimeNow(); | 471 tab->timestamp = TimeNow(); |
471 tab->current_navigation_index = controller->GetCurrentEntryIndex(); | 472 tab->current_navigation_index = controller->GetCurrentEntryIndex(); |
472 if (tab->current_navigation_index == -1 && entry_count > 0) | 473 if (tab->current_navigation_index == -1 && entry_count > 0) |
473 tab->current_navigation_index = 0; | 474 tab->current_navigation_index = 0; |
474 | 475 |
475 Extension* extension = controller->tab_contents()->extension_app(); | 476 Extension* extension = controller->tab_contents()->extension_app(); |
476 if (extension) | 477 if (extension) |
477 tab->extension_app_id = extension->id(); | 478 tab->extension_app_id = extension->id(); |
478 | 479 |
| 480 tab->session_storage_namespace = controller->session_storage_namespace(); |
| 481 |
479 // Browser may be NULL during unit tests. | 482 // Browser may be NULL during unit tests. |
480 if (browser) { | 483 if (browser) { |
481 tab->browser_id = browser->session_id().id(); | 484 tab->browser_id = browser->session_id().id(); |
482 tab->tabstrip_index = | 485 tab->tabstrip_index = |
483 browser->tabstrip_model()->GetIndexOfController(controller); | 486 browser->tabstrip_model()->GetIndexOfController(controller); |
484 tab->pinned = browser->tabstrip_model()->IsTabPinned(tab->tabstrip_index); | 487 tab->pinned = browser->tabstrip_model()->IsTabPinned(tab->tabstrip_index); |
485 } | 488 } |
486 } | 489 } |
487 | 490 |
488 void TabRestoreService::NotifyTabsChanged() { | 491 void TabRestoreService::NotifyTabsChanged() { |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 Browser* TabRestoreService::RestoreTab(const Tab& tab, | 862 Browser* TabRestoreService::RestoreTab(const Tab& tab, |
860 Browser* browser, | 863 Browser* browser, |
861 bool replace_existing_tab) { | 864 bool replace_existing_tab) { |
862 // |browser| will be NULL in cases where one isn't already available (eg, | 865 // |browser| will be NULL in cases where one isn't already available (eg, |
863 // when invoked on Mac OS X with no windows open). In this case, create a | 866 // when invoked on Mac OS X with no windows open). In this case, create a |
864 // new browser into which we restore the tabs. | 867 // new browser into which we restore the tabs. |
865 if (replace_existing_tab && browser) { | 868 if (replace_existing_tab && browser) { |
866 browser->ReplaceRestoredTab(tab.navigations, | 869 browser->ReplaceRestoredTab(tab.navigations, |
867 tab.current_navigation_index, | 870 tab.current_navigation_index, |
868 tab.from_last_session, | 871 tab.from_last_session, |
869 tab.extension_app_id); | 872 tab.extension_app_id, |
| 873 tab.session_storage_namespace); |
870 } else { | 874 } else { |
871 if (tab.has_browser()) | 875 if (tab.has_browser()) |
872 browser = BrowserList::FindBrowserWithID(tab.browser_id); | 876 browser = BrowserList::FindBrowserWithID(tab.browser_id); |
873 | 877 |
874 int tab_index = -1; | 878 int tab_index = -1; |
875 if (browser) { | 879 if (browser) { |
876 tab_index = tab.tabstrip_index; | 880 tab_index = tab.tabstrip_index; |
877 } else { | 881 } else { |
878 browser = Browser::Create(profile()); | 882 browser = Browser::Create(profile()); |
879 if (tab.has_browser()) { | 883 if (tab.has_browser()) { |
880 UpdateTabBrowserIDs(tab.browser_id, browser->session_id().id()); | 884 UpdateTabBrowserIDs(tab.browser_id, browser->session_id().id()); |
881 } | 885 } |
882 } | 886 } |
883 | 887 |
884 if (tab_index < 0 || tab_index > browser->tab_count()) { | 888 if (tab_index < 0 || tab_index > browser->tab_count()) { |
885 tab_index = browser->tab_count(); | 889 tab_index = browser->tab_count(); |
886 } | 890 } |
887 | 891 |
888 browser->AddRestoredTab(tab.navigations, | 892 browser->AddRestoredTab(tab.navigations, |
889 tab_index, | 893 tab_index, |
890 tab.current_navigation_index, | 894 tab.current_navigation_index, |
891 tab.extension_app_id, | 895 tab.extension_app_id, |
892 true, tab.pinned, tab.from_last_session); | 896 true, tab.pinned, tab.from_last_session, |
| 897 tab.session_storage_namespace); |
893 } | 898 } |
894 return browser; | 899 return browser; |
895 } | 900 } |
896 | 901 |
897 | 902 |
898 bool TabRestoreService::ValidateTab(Tab* tab) { | 903 bool TabRestoreService::ValidateTab(Tab* tab) { |
899 if (tab->navigations.empty()) | 904 if (tab->navigations.empty()) |
900 return false; | 905 return false; |
901 | 906 |
902 tab->current_navigation_index = | 907 tab->current_navigation_index = |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 // correctly write out the entries when Save is invoked (Save starts from | 1055 // correctly write out the entries when Save is invoked (Save starts from |
1051 // the front, not the end and we just added the entries to the end). | 1056 // the front, not the end and we just added the entries to the end). |
1052 entries_to_write_ = staging_entries_.size(); | 1057 entries_to_write_ = staging_entries_.size(); |
1053 | 1058 |
1054 PruneAndNotify(); | 1059 PruneAndNotify(); |
1055 } | 1060 } |
1056 | 1061 |
1057 Time TabRestoreService::TimeNow() const { | 1062 Time TabRestoreService::TimeNow() const { |
1058 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); | 1063 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); |
1059 } | 1064 } |
OLD | NEW |