| 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, |
| 383 tab.user_agent_override); |
| 383 if (restored_tab) { | 384 if (restored_tab) { |
| 384 restored_tab->GetController().LoadIfNecessary(); | 385 restored_tab->GetController().LoadIfNecessary(); |
| 385 RecordAppLaunch(profile(), tab); | 386 RecordAppLaunch(profile(), tab); |
| 386 } | 387 } |
| 387 } | 388 } |
| 388 // All the window's tabs had the same former browser_id. | 389 // All the window's tabs had the same former browser_id. |
| 389 if (window->tabs[0].has_browser()) { | 390 if (window->tabs[0].has_browser()) { |
| 390 UpdateTabBrowserIDs(window->tabs[0].browser_id, | 391 UpdateTabBrowserIDs(window->tabs[0].browser_id, |
| 391 delegate->GetSessionID().id()); | 392 delegate->GetSessionID().id()); |
| 392 } | 393 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 TabContents* tab_contents = | 540 TabContents* tab_contents = |
| 540 TabContents::FromWebContents(controller->GetWebContents()); | 541 TabContents::FromWebContents(controller->GetWebContents()); |
| 541 // tab_contents is NULL in some browser tests. | 542 // tab_contents is NULL in some browser tests. |
| 542 if (tab_contents) { | 543 if (tab_contents) { |
| 543 const extensions::Extension* extension = | 544 const extensions::Extension* extension = |
| 544 tab_contents->extension_tab_helper()->extension_app(); | 545 tab_contents->extension_tab_helper()->extension_app(); |
| 545 if (extension) | 546 if (extension) |
| 546 tab->extension_app_id = extension->id(); | 547 tab->extension_app_id = extension->id(); |
| 547 } | 548 } |
| 548 | 549 |
| 550 tab->user_agent_override = |
| 551 controller->GetWebContents()->GetUserAgentOverride(); |
| 552 |
| 549 // TODO(ajwong): This does not correctly handle storage for isolated apps. | 553 // TODO(ajwong): This does not correctly handle storage for isolated apps. |
| 550 tab->session_storage_namespace = | 554 tab->session_storage_namespace = |
| 551 controller->GetDefaultSessionStorageNamespace(); | 555 controller->GetDefaultSessionStorageNamespace(); |
| 552 | 556 |
| 553 // Delegate may be NULL during unit tests. | 557 // Delegate may be NULL during unit tests. |
| 554 if (delegate) { | 558 if (delegate) { |
| 555 tab->browser_id = delegate->GetSessionID().id(); | 559 tab->browser_id = delegate->GetSessionID().id(); |
| 556 tab->pinned = delegate->IsTabPinned(tab->tabstrip_index); | 560 tab->pinned = delegate->IsTabPinned(tab->tabstrip_index); |
| 557 } | 561 } |
| 558 } | 562 } |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 | 994 |
| 991 TabRestoreServiceDelegate* TabRestoreService::RestoreTab( | 995 TabRestoreServiceDelegate* TabRestoreService::RestoreTab( |
| 992 const Tab& tab, | 996 const Tab& tab, |
| 993 TabRestoreServiceDelegate* delegate, | 997 TabRestoreServiceDelegate* delegate, |
| 994 WindowOpenDisposition disposition) { | 998 WindowOpenDisposition disposition) { |
| 995 if (disposition == CURRENT_TAB && delegate) { | 999 if (disposition == CURRENT_TAB && delegate) { |
| 996 delegate->ReplaceRestoredTab(tab.navigations, | 1000 delegate->ReplaceRestoredTab(tab.navigations, |
| 997 tab.current_navigation_index, | 1001 tab.current_navigation_index, |
| 998 tab.from_last_session, | 1002 tab.from_last_session, |
| 999 tab.extension_app_id, | 1003 tab.extension_app_id, |
| 1000 tab.session_storage_namespace); | 1004 tab.session_storage_namespace, |
| 1005 tab.user_agent_override); |
| 1001 } else { | 1006 } else { |
| 1002 // We only respsect the tab's original browser if there's no disposition. | 1007 // We only respsect the tab's original browser if there's no disposition. |
| 1003 if (disposition == UNKNOWN && tab.has_browser()) | 1008 if (disposition == UNKNOWN && tab.has_browser()) |
| 1004 delegate = TabRestoreServiceDelegate::FindDelegateWithID(tab.browser_id); | 1009 delegate = TabRestoreServiceDelegate::FindDelegateWithID(tab.browser_id); |
| 1005 | 1010 |
| 1006 int tab_index = -1; | 1011 int tab_index = -1; |
| 1007 | 1012 |
| 1008 // |delegate| will be NULL in cases where one isn't already available (eg, | 1013 // |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 | 1014 // when invoked on Mac OS X with no windows open). In this case, create a |
| 1010 // new browser into which we restore the tabs. | 1015 // new browser into which we restore the tabs. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1024 } | 1029 } |
| 1025 | 1030 |
| 1026 WebContents* web_contents = delegate->AddRestoredTab( | 1031 WebContents* web_contents = delegate->AddRestoredTab( |
| 1027 tab.navigations, | 1032 tab.navigations, |
| 1028 tab_index, | 1033 tab_index, |
| 1029 tab.current_navigation_index, | 1034 tab.current_navigation_index, |
| 1030 tab.extension_app_id, | 1035 tab.extension_app_id, |
| 1031 disposition != NEW_BACKGROUND_TAB, | 1036 disposition != NEW_BACKGROUND_TAB, |
| 1032 tab.pinned, | 1037 tab.pinned, |
| 1033 tab.from_last_session, | 1038 tab.from_last_session, |
| 1034 tab.session_storage_namespace); | 1039 tab.session_storage_namespace, |
| 1040 tab.user_agent_override); |
| 1035 web_contents->GetController().LoadIfNecessary(); | 1041 web_contents->GetController().LoadIfNecessary(); |
| 1036 } | 1042 } |
| 1037 RecordAppLaunch(profile(), tab); | 1043 RecordAppLaunch(profile(), tab); |
| 1038 return delegate; | 1044 return delegate; |
| 1039 } | 1045 } |
| 1040 | 1046 |
| 1041 | 1047 |
| 1042 bool TabRestoreService::ValidateTab(Tab* tab) { | 1048 bool TabRestoreService::ValidateTab(Tab* tab) { |
| 1043 if (tab->navigations.empty()) | 1049 if (tab->navigations.empty()) |
| 1044 return false; | 1050 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). | 1252 // the front, not the end and we just added the entries to the end). |
| 1247 entries_to_write_ = staging_entries_.size(); | 1253 entries_to_write_ = staging_entries_.size(); |
| 1248 | 1254 |
| 1249 PruneEntries(); | 1255 PruneEntries(); |
| 1250 NotifyTabsChanged(); | 1256 NotifyTabsChanged(); |
| 1251 } | 1257 } |
| 1252 | 1258 |
| 1253 Time TabRestoreService::TimeNow() const { | 1259 Time TabRestoreService::TimeNow() const { |
| 1254 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); | 1260 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); |
| 1255 } | 1261 } |
| OLD | NEW |