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 tab->session_storage_namespace = controller->GetSessionStorageNamespace(); | 553 tab->session_storage_namespace = controller->GetSessionStorageNamespace(); |
550 | 554 |
551 // Delegate may be NULL during unit tests. | 555 // Delegate may be NULL during unit tests. |
552 if (delegate) { | 556 if (delegate) { |
553 tab->browser_id = delegate->GetSessionID().id(); | 557 tab->browser_id = delegate->GetSessionID().id(); |
554 tab->pinned = delegate->IsTabPinned(tab->tabstrip_index); | 558 tab->pinned = delegate->IsTabPinned(tab->tabstrip_index); |
555 } | 559 } |
556 } | 560 } |
557 | 561 |
558 void TabRestoreService::NotifyTabsChanged() { | 562 void TabRestoreService::NotifyTabsChanged() { |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 | 992 |
989 TabRestoreServiceDelegate* TabRestoreService::RestoreTab( | 993 TabRestoreServiceDelegate* TabRestoreService::RestoreTab( |
990 const Tab& tab, | 994 const Tab& tab, |
991 TabRestoreServiceDelegate* delegate, | 995 TabRestoreServiceDelegate* delegate, |
992 WindowOpenDisposition disposition) { | 996 WindowOpenDisposition disposition) { |
993 if (disposition == CURRENT_TAB && delegate) { | 997 if (disposition == CURRENT_TAB && delegate) { |
994 delegate->ReplaceRestoredTab(tab.navigations, | 998 delegate->ReplaceRestoredTab(tab.navigations, |
995 tab.current_navigation_index, | 999 tab.current_navigation_index, |
996 tab.from_last_session, | 1000 tab.from_last_session, |
997 tab.extension_app_id, | 1001 tab.extension_app_id, |
998 tab.session_storage_namespace); | 1002 tab.session_storage_namespace, |
| 1003 tab.user_agent_override); |
999 } else { | 1004 } else { |
1000 // We only respsect the tab's original browser if there's no disposition. | 1005 // We only respsect the tab's original browser if there's no disposition. |
1001 if (disposition == UNKNOWN && tab.has_browser()) | 1006 if (disposition == UNKNOWN && tab.has_browser()) |
1002 delegate = TabRestoreServiceDelegate::FindDelegateWithID(tab.browser_id); | 1007 delegate = TabRestoreServiceDelegate::FindDelegateWithID(tab.browser_id); |
1003 | 1008 |
1004 int tab_index = -1; | 1009 int tab_index = -1; |
1005 | 1010 |
1006 // |delegate| will be NULL in cases where one isn't already available (eg, | 1011 // |delegate| will be NULL in cases where one isn't already available (eg, |
1007 // when invoked on Mac OS X with no windows open). In this case, create a | 1012 // when invoked on Mac OS X with no windows open). In this case, create a |
1008 // new browser into which we restore the tabs. | 1013 // new browser into which we restore the tabs. |
(...skipping 13 matching lines...) Expand all Loading... |
1022 } | 1027 } |
1023 | 1028 |
1024 WebContents* web_contents = delegate->AddRestoredTab( | 1029 WebContents* web_contents = delegate->AddRestoredTab( |
1025 tab.navigations, | 1030 tab.navigations, |
1026 tab_index, | 1031 tab_index, |
1027 tab.current_navigation_index, | 1032 tab.current_navigation_index, |
1028 tab.extension_app_id, | 1033 tab.extension_app_id, |
1029 disposition != NEW_BACKGROUND_TAB, | 1034 disposition != NEW_BACKGROUND_TAB, |
1030 tab.pinned, | 1035 tab.pinned, |
1031 tab.from_last_session, | 1036 tab.from_last_session, |
1032 tab.session_storage_namespace); | 1037 tab.session_storage_namespace, |
| 1038 tab.user_agent_override); |
1033 web_contents->GetController().LoadIfNecessary(); | 1039 web_contents->GetController().LoadIfNecessary(); |
1034 } | 1040 } |
1035 RecordAppLaunch(profile(), tab); | 1041 RecordAppLaunch(profile(), tab); |
1036 return delegate; | 1042 return delegate; |
1037 } | 1043 } |
1038 | 1044 |
1039 | 1045 |
1040 bool TabRestoreService::ValidateTab(Tab* tab) { | 1046 bool TabRestoreService::ValidateTab(Tab* tab) { |
1041 if (tab->navigations.empty()) | 1047 if (tab->navigations.empty()) |
1042 return false; | 1048 return false; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 // the front, not the end and we just added the entries to the end). | 1250 // the front, not the end and we just added the entries to the end). |
1245 entries_to_write_ = staging_entries_.size(); | 1251 entries_to_write_ = staging_entries_.size(); |
1246 | 1252 |
1247 PruneEntries(); | 1253 PruneEntries(); |
1248 NotifyTabsChanged(); | 1254 NotifyTabsChanged(); |
1249 } | 1255 } |
1250 | 1256 |
1251 Time TabRestoreService::TimeNow() const { | 1257 Time TabRestoreService::TimeNow() const { |
1252 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); | 1258 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); |
1253 } | 1259 } |
OLD | NEW |