| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "chrome/browser/sessions/tab_restore_service_delegate.h" | 13 #include "chrome/browser/sessions/tab_restore_service_delegate.h" |
| 14 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 14 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
| 15 #include "components/sessions/content/content_serialized_navigation_builder.h" | 15 #include "components/sessions/content/content_serialized_navigation_builder.h" |
| 16 #include "components/sessions/core/tab_restore_service_client.h" | 16 #include "components/sessions/core/tab_restore_service_client.h" |
| 17 #include "components/sessions/session_types.h" | 17 #include "components/sessions/session_types.h" |
| 18 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
| 19 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
| 20 #include "content/public/browser/session_storage_namespace.h" | 20 #include "content/public/browser/session_storage_namespace.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 | 22 |
| 23 #if defined(ENABLE_EXTENSIONS) | |
| 24 #include "chrome/browser/extensions/tab_helper.h" | |
| 25 #endif | |
| 26 | |
| 27 using content::NavigationController; | 23 using content::NavigationController; |
| 28 using content::NavigationEntry; | 24 using content::NavigationEntry; |
| 29 using content::WebContents; | 25 using content::WebContents; |
| 30 | 26 |
| 31 // TabRestoreServiceHelper::Observer ------------------------------------------- | 27 // TabRestoreServiceHelper::Observer ------------------------------------------- |
| 32 | 28 |
| 33 TabRestoreServiceHelper::Observer::~Observer() {} | 29 TabRestoreServiceHelper::Observer::~Observer() {} |
| 34 | 30 |
| 35 void TabRestoreServiceHelper::Observer::OnClearEntries() {} | 31 void TabRestoreServiceHelper::Observer::OnClearEntries() {} |
| 36 | 32 |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 tab->navigations[i] = | 388 tab->navigations[i] = |
| 393 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( | 389 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( |
| 394 i, *entry); | 390 i, *entry); |
| 395 } | 391 } |
| 396 tab->timestamp = TimeNow(); | 392 tab->timestamp = TimeNow(); |
| 397 tab->current_navigation_index = controller->GetCurrentEntryIndex(); | 393 tab->current_navigation_index = controller->GetCurrentEntryIndex(); |
| 398 if (tab->current_navigation_index == -1 && entry_count > 0) | 394 if (tab->current_navigation_index == -1 && entry_count > 0) |
| 399 tab->current_navigation_index = 0; | 395 tab->current_navigation_index = 0; |
| 400 tab->tabstrip_index = index; | 396 tab->tabstrip_index = index; |
| 401 | 397 |
| 402 #if defined(ENABLE_EXTENSIONS) | 398 tab->extension_app_id = |
| 403 extensions::TabHelper* extensions_tab_helper = | 399 client_->GetExtensionAppIDForWebContents(controller->GetWebContents()); |
| 404 extensions::TabHelper::FromWebContents(controller->GetWebContents()); | |
| 405 // extensions_tab_helper is NULL in some browser tests. | |
| 406 if (extensions_tab_helper) { | |
| 407 const extensions::Extension* extension = | |
| 408 extensions_tab_helper->extension_app(); | |
| 409 if (extension) | |
| 410 tab->extension_app_id = extension->id(); | |
| 411 } | |
| 412 #endif | |
| 413 | 400 |
| 414 tab->user_agent_override = | 401 tab->user_agent_override = |
| 415 controller->GetWebContents()->GetUserAgentOverride(); | 402 controller->GetWebContents()->GetUserAgentOverride(); |
| 416 | 403 |
| 417 // TODO(ajwong): This does not correctly handle storage for isolated apps. | 404 // TODO(ajwong): This does not correctly handle storage for isolated apps. |
| 418 tab->session_storage_namespace = | 405 tab->session_storage_namespace = |
| 419 controller->GetDefaultSessionStorageNamespace(); | 406 controller->GetDefaultSessionStorageNamespace(); |
| 420 | 407 |
| 421 // Delegate may be NULL during unit tests. | 408 // Delegate may be NULL during unit tests. |
| 422 if (delegate) { | 409 if (delegate) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 Tab* tab = static_cast<Tab*>(entry); | 554 Tab* tab = static_cast<Tab*>(entry); |
| 568 if (tab->browser_id == old_id) | 555 if (tab->browser_id == old_id) |
| 569 tab->browser_id = new_id; | 556 tab->browser_id = new_id; |
| 570 } | 557 } |
| 571 } | 558 } |
| 572 } | 559 } |
| 573 | 560 |
| 574 base::Time TabRestoreServiceHelper::TimeNow() const { | 561 base::Time TabRestoreServiceHelper::TimeNow() const { |
| 575 return time_factory_ ? time_factory_->TimeNow() : base::Time::Now(); | 562 return time_factory_ ? time_factory_->TimeNow() : base::Time::Now(); |
| 576 } | 563 } |
| OLD | NEW |