OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 delegate = TabRestoreServiceDelegate::Create(profile(), window->app_name); | 372 delegate = TabRestoreServiceDelegate::Create(profile(), window->app_name); |
373 for (size_t tab_i = 0; tab_i < window->tabs.size(); ++tab_i) { | 373 for (size_t tab_i = 0; tab_i < window->tabs.size(); ++tab_i) { |
374 const Tab& tab = window->tabs[tab_i]; | 374 const Tab& tab = window->tabs[tab_i]; |
375 WebContents* restored_tab = | 375 WebContents* restored_tab = |
376 delegate->AddRestoredTab(tab.navigations, delegate->GetTabCount(), | 376 delegate->AddRestoredTab(tab.navigations, delegate->GetTabCount(), |
377 tab.current_navigation_index, | 377 tab.current_navigation_index, |
378 tab.extension_app_id, | 378 tab.extension_app_id, |
379 static_cast<int>(tab_i) == | 379 static_cast<int>(tab_i) == |
380 window->selected_tab_index, | 380 window->selected_tab_index, |
381 tab.pinned, tab.from_last_session, | 381 tab.pinned, tab.from_last_session, |
382 tab.session_storage_namespace); | 382 tab.session_storage_namespace_map); |
383 if (restored_tab) { | 383 if (restored_tab) { |
384 restored_tab->GetController().LoadIfNecessary(); | 384 restored_tab->GetController().LoadIfNecessary(); |
385 RecordAppLaunch(profile(), tab); | 385 RecordAppLaunch(profile(), tab); |
386 } | 386 } |
387 } | 387 } |
388 // All the window's tabs had the same former browser_id. | 388 // All the window's tabs had the same former browser_id. |
389 if (window->tabs[0].has_browser()) { | 389 if (window->tabs[0].has_browser()) { |
390 UpdateTabBrowserIDs(window->tabs[0].browser_id, | 390 UpdateTabBrowserIDs(window->tabs[0].browser_id, |
391 delegate->GetSessionID().id()); | 391 delegate->GetSessionID().id()); |
392 } | 392 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 TabContents* tab_contents = | 539 TabContents* tab_contents = |
540 TabContents::FromWebContents(controller->GetWebContents()); | 540 TabContents::FromWebContents(controller->GetWebContents()); |
541 // tab_contents is NULL in some browser tests. | 541 // tab_contents is NULL in some browser tests. |
542 if (tab_contents) { | 542 if (tab_contents) { |
543 const extensions::Extension* extension = | 543 const extensions::Extension* extension = |
544 tab_contents->extension_tab_helper()->extension_app(); | 544 tab_contents->extension_tab_helper()->extension_app(); |
545 if (extension) | 545 if (extension) |
546 tab->extension_app_id = extension->id(); | 546 tab->extension_app_id = extension->id(); |
547 } | 547 } |
548 | 548 |
549 // TODO(ajwong): This does not correctly handle storage for isolated apps. | 549 tab->session_storage_namespace_map = |
550 tab->session_storage_namespace = | 550 controller->GetSessionStorageNamespaceMap(); |
551 controller->GetSessionStorageNamespaceMap().find("")->second; | |
552 | 551 |
553 // Delegate may be NULL during unit tests. | 552 // Delegate may be NULL during unit tests. |
554 if (delegate) { | 553 if (delegate) { |
555 tab->browser_id = delegate->GetSessionID().id(); | 554 tab->browser_id = delegate->GetSessionID().id(); |
556 tab->pinned = delegate->IsTabPinned(tab->tabstrip_index); | 555 tab->pinned = delegate->IsTabPinned(tab->tabstrip_index); |
557 } | 556 } |
558 } | 557 } |
559 | 558 |
560 void TabRestoreService::NotifyTabsChanged() { | 559 void TabRestoreService::NotifyTabsChanged() { |
561 FOR_EACH_OBSERVER(TabRestoreServiceObserver, observer_list_, | 560 FOR_EACH_OBSERVER(TabRestoreServiceObserver, observer_list_, |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 | 989 |
991 TabRestoreServiceDelegate* TabRestoreService::RestoreTab( | 990 TabRestoreServiceDelegate* TabRestoreService::RestoreTab( |
992 const Tab& tab, | 991 const Tab& tab, |
993 TabRestoreServiceDelegate* delegate, | 992 TabRestoreServiceDelegate* delegate, |
994 WindowOpenDisposition disposition) { | 993 WindowOpenDisposition disposition) { |
995 if (disposition == CURRENT_TAB && delegate) { | 994 if (disposition == CURRENT_TAB && delegate) { |
996 delegate->ReplaceRestoredTab(tab.navigations, | 995 delegate->ReplaceRestoredTab(tab.navigations, |
997 tab.current_navigation_index, | 996 tab.current_navigation_index, |
998 tab.from_last_session, | 997 tab.from_last_session, |
999 tab.extension_app_id, | 998 tab.extension_app_id, |
1000 tab.session_storage_namespace); | 999 tab.session_storage_namespace_map); |
1001 } else { | 1000 } else { |
1002 // We only respsect the tab's original browser if there's no disposition. | 1001 // We only respsect the tab's original browser if there's no disposition. |
1003 if (disposition == UNKNOWN && tab.has_browser()) | 1002 if (disposition == UNKNOWN && tab.has_browser()) |
1004 delegate = TabRestoreServiceDelegate::FindDelegateWithID(tab.browser_id); | 1003 delegate = TabRestoreServiceDelegate::FindDelegateWithID(tab.browser_id); |
1005 | 1004 |
1006 int tab_index = -1; | 1005 int tab_index = -1; |
1007 | 1006 |
1008 // |delegate| will be NULL in cases where one isn't already available (eg, | 1007 // |delegate| will be NULL in cases where one isn't already available (eg, |
1009 // when invoked on Mac OS X with no windows open). In this case, create a | 1008 // when invoked on Mac OS X with no windows open). In this case, create a |
1010 // new browser into which we restore the tabs. | 1009 // new browser into which we restore the tabs. |
(...skipping 13 matching lines...) Expand all Loading... |
1024 } | 1023 } |
1025 | 1024 |
1026 WebContents* web_contents = delegate->AddRestoredTab( | 1025 WebContents* web_contents = delegate->AddRestoredTab( |
1027 tab.navigations, | 1026 tab.navigations, |
1028 tab_index, | 1027 tab_index, |
1029 tab.current_navigation_index, | 1028 tab.current_navigation_index, |
1030 tab.extension_app_id, | 1029 tab.extension_app_id, |
1031 disposition != NEW_BACKGROUND_TAB, | 1030 disposition != NEW_BACKGROUND_TAB, |
1032 tab.pinned, | 1031 tab.pinned, |
1033 tab.from_last_session, | 1032 tab.from_last_session, |
1034 tab.session_storage_namespace); | 1033 tab.session_storage_namespace_map); |
1035 web_contents->GetController().LoadIfNecessary(); | 1034 web_contents->GetController().LoadIfNecessary(); |
1036 } | 1035 } |
1037 RecordAppLaunch(profile(), tab); | 1036 RecordAppLaunch(profile(), tab); |
1038 return delegate; | 1037 return delegate; |
1039 } | 1038 } |
1040 | 1039 |
1041 | 1040 |
1042 bool TabRestoreService::ValidateTab(Tab* tab) { | 1041 bool TabRestoreService::ValidateTab(Tab* tab) { |
1043 if (tab->navigations.empty()) | 1042 if (tab->navigations.empty()) |
1044 return false; | 1043 return false; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 // the front, not the end and we just added the entries to the end). | 1245 // the front, not the end and we just added the entries to the end). |
1247 entries_to_write_ = staging_entries_.size(); | 1246 entries_to_write_ = staging_entries_.size(); |
1248 | 1247 |
1249 PruneEntries(); | 1248 PruneEntries(); |
1250 NotifyTabsChanged(); | 1249 NotifyTabsChanged(); |
1251 } | 1250 } |
1252 | 1251 |
1253 Time TabRestoreService::TimeNow() const { | 1252 Time TabRestoreService::TimeNow() const { |
1254 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); | 1253 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); |
1255 } | 1254 } |
OLD | NEW |