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_helper.h" | 5 #include "chrome/browser/sessions/tab_restore_service_helper.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 Window* window = static_cast<Window*>(entry); | 227 Window* window = static_cast<Window*>(entry); |
228 | 228 |
229 // When restoring a window, either the entire window can be restored, or a | 229 // When restoring a window, either the entire window can be restored, or a |
230 // single tab within it. If the entry's ID matches the one to restore, then | 230 // single tab within it. If the entry's ID matches the one to restore, then |
231 // the entire window will be restored. | 231 // the entire window will be restored. |
232 if (!restoring_tab_in_window) { | 232 if (!restoring_tab_in_window) { |
233 delegate = TabRestoreServiceDelegate::Create(profile_, host_desktop_type, | 233 delegate = TabRestoreServiceDelegate::Create(profile_, host_desktop_type, |
234 window->app_name); | 234 window->app_name); |
235 for (size_t tab_i = 0; tab_i < window->tabs.size(); ++tab_i) { | 235 for (size_t tab_i = 0; tab_i < window->tabs.size(); ++tab_i) { |
236 const Tab& tab = window->tabs[tab_i]; | 236 const Tab& tab = window->tabs[tab_i]; |
237 WebContents* restored_tab = | 237 WebContents* restored_tab = delegate->AddRestoredTab( |
238 delegate->AddRestoredTab(tab.navigations, delegate->GetTabCount(), | 238 tab.navigations, |
239 tab.current_navigation_index, | 239 delegate->GetTabCount(), |
240 tab.extension_app_id, | 240 tab.current_navigation_index, |
241 static_cast<int>(tab_i) == | 241 tab.extension_app_id, |
242 window->selected_tab_index, | 242 static_cast<int>(tab_i) == window->selected_tab_index, |
243 tab.pinned, tab.from_last_session, | 243 tab.pinned, |
244 tab.session_storage_namespace, | 244 tab.from_last_session, |
245 tab.user_agent_override); | 245 tab.session_storage_namespace, |
| 246 tab.user_agent_override, |
| 247 tab.sync_session_id); |
246 if (restored_tab) { | 248 if (restored_tab) { |
247 restored_tab->GetController().LoadIfNecessary(); | 249 restored_tab->GetController().LoadIfNecessary(); |
248 RecordAppLaunch(profile_, tab); | 250 RecordAppLaunch(profile_, tab); |
249 } | 251 } |
250 } | 252 } |
251 // All the window's tabs had the same former browser_id. | 253 // All the window's tabs had the same former browser_id. |
252 if (window->tabs[0].has_browser()) { | 254 if (window->tabs[0].has_browser()) { |
253 UpdateTabBrowserIDs(window->tabs[0].browser_id, | 255 UpdateTabBrowserIDs(window->tabs[0].browser_id, |
254 delegate->GetSessionID().id()); | 256 delegate->GetSessionID().id()); |
255 } | 257 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 NavigationEntry* entry = (i == pending_index) ? | 394 NavigationEntry* entry = (i == pending_index) ? |
393 controller->GetPendingEntry() : controller->GetEntryAtIndex(i); | 395 controller->GetPendingEntry() : controller->GetEntryAtIndex(i); |
394 tab->navigations[i] = | 396 tab->navigations[i] = |
395 sessions::SerializedNavigationEntry::FromNavigationEntry(i, *entry); | 397 sessions::SerializedNavigationEntry::FromNavigationEntry(i, *entry); |
396 } | 398 } |
397 tab->timestamp = TimeNow(); | 399 tab->timestamp = TimeNow(); |
398 tab->current_navigation_index = controller->GetCurrentEntryIndex(); | 400 tab->current_navigation_index = controller->GetCurrentEntryIndex(); |
399 if (tab->current_navigation_index == -1 && entry_count > 0) | 401 if (tab->current_navigation_index == -1 && entry_count > 0) |
400 tab->current_navigation_index = 0; | 402 tab->current_navigation_index = 0; |
401 tab->tabstrip_index = index; | 403 tab->tabstrip_index = index; |
| 404 tab->sync_session_id = tab->sync_session_id; |
402 | 405 |
403 extensions::TabHelper* extensions_tab_helper = | 406 extensions::TabHelper* extensions_tab_helper = |
404 extensions::TabHelper::FromWebContents(controller->GetWebContents()); | 407 extensions::TabHelper::FromWebContents(controller->GetWebContents()); |
405 // extensions_tab_helper is NULL in some browser tests. | 408 // extensions_tab_helper is NULL in some browser tests. |
406 if (extensions_tab_helper) { | 409 if (extensions_tab_helper) { |
407 const extensions::Extension* extension = | 410 const extensions::Extension* extension = |
408 extensions_tab_helper->extension_app(); | 411 extensions_tab_helper->extension_app(); |
409 if (extension) | 412 if (extension) |
410 tab->extension_app_id = extension->id(); | 413 tab->extension_app_id = extension->id(); |
411 } | 414 } |
(...skipping 16 matching lines...) Expand all Loading... |
428 const Tab& tab, | 431 const Tab& tab, |
429 TabRestoreServiceDelegate* delegate, | 432 TabRestoreServiceDelegate* delegate, |
430 chrome::HostDesktopType host_desktop_type, | 433 chrome::HostDesktopType host_desktop_type, |
431 WindowOpenDisposition disposition) { | 434 WindowOpenDisposition disposition) { |
432 if (disposition == CURRENT_TAB && delegate) { | 435 if (disposition == CURRENT_TAB && delegate) { |
433 delegate->ReplaceRestoredTab(tab.navigations, | 436 delegate->ReplaceRestoredTab(tab.navigations, |
434 tab.current_navigation_index, | 437 tab.current_navigation_index, |
435 tab.from_last_session, | 438 tab.from_last_session, |
436 tab.extension_app_id, | 439 tab.extension_app_id, |
437 tab.session_storage_namespace, | 440 tab.session_storage_namespace, |
438 tab.user_agent_override); | 441 tab.user_agent_override, |
| 442 tab.sync_session_id); |
439 } else { | 443 } else { |
440 // We only respsect the tab's original browser if there's no disposition. | 444 // We only respsect the tab's original browser if there's no disposition. |
441 if (disposition == UNKNOWN && tab.has_browser()) { | 445 if (disposition == UNKNOWN && tab.has_browser()) { |
442 delegate = TabRestoreServiceDelegate::FindDelegateWithID( | 446 delegate = TabRestoreServiceDelegate::FindDelegateWithID( |
443 tab.browser_id, host_desktop_type); | 447 tab.browser_id, host_desktop_type); |
444 } | 448 } |
445 | 449 |
446 int tab_index = -1; | 450 int tab_index = -1; |
447 | 451 |
448 // |delegate| will be NULL in cases where one isn't already available (eg, | 452 // |delegate| will be NULL in cases where one isn't already available (eg, |
449 // when invoked on Mac OS X with no windows open). In this case, create a | 453 // when invoked on Mac OS X with no windows open). In this case, create a |
450 // new browser into which we restore the tabs. | 454 // new browser into which we restore the tabs. |
451 if (delegate && disposition != NEW_WINDOW) { | 455 if (delegate && disposition != NEW_WINDOW) { |
452 tab_index = tab.tabstrip_index; | 456 tab_index = tab.tabstrip_index; |
453 } else { | 457 } else { |
454 delegate = TabRestoreServiceDelegate::Create(profile_, host_desktop_type, | 458 delegate = TabRestoreServiceDelegate::Create(profile_, host_desktop_type, |
455 std::string()); | 459 std::string()); |
456 if (tab.has_browser()) | 460 if (tab.has_browser()) |
457 UpdateTabBrowserIDs(tab.browser_id, delegate->GetSessionID().id()); | 461 UpdateTabBrowserIDs(tab.browser_id, delegate->GetSessionID().id()); |
458 } | 462 } |
459 | 463 |
460 // Place the tab at the end if the tab index is no longer valid or | 464 // Place the tab at the end if the tab index is no longer valid or |
461 // we were passed a specific disposition. | 465 // we were passed a specific disposition. |
462 if (tab_index < 0 || tab_index > delegate->GetTabCount() || | 466 if (tab_index < 0 || tab_index > delegate->GetTabCount() || |
463 disposition != UNKNOWN) { | 467 disposition != UNKNOWN) { |
464 tab_index = delegate->GetTabCount(); | 468 tab_index = delegate->GetTabCount(); |
465 } | 469 } |
466 | 470 |
467 WebContents* web_contents = delegate->AddRestoredTab( | 471 WebContents* web_contents = |
468 tab.navigations, | 472 delegate->AddRestoredTab(tab.navigations, |
469 tab_index, | 473 tab_index, |
470 tab.current_navigation_index, | 474 tab.current_navigation_index, |
471 tab.extension_app_id, | 475 tab.extension_app_id, |
472 disposition != NEW_BACKGROUND_TAB, | 476 disposition != NEW_BACKGROUND_TAB, |
473 tab.pinned, | 477 tab.pinned, |
474 tab.from_last_session, | 478 tab.from_last_session, |
475 tab.session_storage_namespace, | 479 tab.session_storage_namespace, |
476 tab.user_agent_override); | 480 tab.user_agent_override, |
| 481 tab.sync_session_id); |
477 web_contents->GetController().LoadIfNecessary(); | 482 web_contents->GetController().LoadIfNecessary(); |
478 } | 483 } |
479 RecordAppLaunch(profile_, tab); | 484 RecordAppLaunch(profile_, tab); |
480 return delegate; | 485 return delegate; |
481 } | 486 } |
482 | 487 |
483 | 488 |
484 bool TabRestoreServiceHelper::ValidateTab(Tab* tab) { | 489 bool TabRestoreServiceHelper::ValidateTab(Tab* tab) { |
485 if (tab->navigations.empty()) | 490 if (tab->navigations.empty()) |
486 return false; | 491 return false; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 Tab* tab = static_cast<Tab*>(entry); | 566 Tab* tab = static_cast<Tab*>(entry); |
562 if (tab->browser_id == old_id) | 567 if (tab->browser_id == old_id) |
563 tab->browser_id = new_id; | 568 tab->browser_id = new_id; |
564 } | 569 } |
565 } | 570 } |
566 } | 571 } |
567 | 572 |
568 base::Time TabRestoreServiceHelper::TimeNow() const { | 573 base::Time TabRestoreServiceHelper::TimeNow() const { |
569 return time_factory_ ? time_factory_->TimeNow() : base::Time::Now(); | 574 return time_factory_ ? time_factory_->TimeNow() : base::Time::Now(); |
570 } | 575 } |
OLD | NEW |