| 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" |
| 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/extensions/tab_helper.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/sessions/session_types.h" | 14 #include "chrome/browser/sessions/session_types.h" |
| 16 #include "chrome/browser/sessions/tab_restore_service_delegate.h" | 15 #include "chrome/browser/sessions/tab_restore_service_delegate.h" |
| 17 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 16 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
| 18 #include "chrome/common/extensions/extension_constants.h" | 17 #include "chrome/common/extensions/extension_constants.h" |
| 19 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 20 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
| 21 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
| 22 #include "content/public/browser/session_storage_namespace.h" | 21 #include "content/public/browser/session_storage_namespace.h" |
| 23 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 24 #include "extensions/browser/extension_registry.h" | 23 #include "extensions/browser/extension_registry.h" |
| 25 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
| 26 #include "extensions/common/extension_set.h" | 25 #include "extensions/common/extension_set.h" |
| 27 | 26 |
| 28 #if !defined(OS_ANDROID) | 27 #if !defined(OS_ANDROID) |
| 29 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" | 28 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" |
| 30 #endif | 29 #endif |
| 31 | 30 |
| 31 #if defined(ENABLE_EXTENSIONS) |
| 32 #include "chrome/browser/extensions/tab_helper.h" |
| 33 #endif |
| 34 |
| 32 using content::NavigationController; | 35 using content::NavigationController; |
| 33 using content::NavigationEntry; | 36 using content::NavigationEntry; |
| 34 using content::WebContents; | 37 using content::WebContents; |
| 35 | 38 |
| 36 namespace { | 39 namespace { |
| 37 | 40 |
| 38 void RecordAppLaunch(Profile* profile, const TabRestoreService::Tab& tab) { | 41 void RecordAppLaunch(Profile* profile, const TabRestoreService::Tab& tab) { |
| 39 #if !defined(OS_ANDROID) | 42 #if !defined(OS_ANDROID) |
| 40 GURL url = tab.navigations.at(tab.current_navigation_index).virtual_url(); | 43 GURL url = tab.navigations.at(tab.current_navigation_index).virtual_url(); |
| 41 const extensions::Extension* extension = | 44 const extensions::Extension* extension = |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 controller->GetPendingEntry() : controller->GetEntryAtIndex(i); | 417 controller->GetPendingEntry() : controller->GetEntryAtIndex(i); |
| 415 tab->navigations[i] = | 418 tab->navigations[i] = |
| 416 sessions::SerializedNavigationEntry::FromNavigationEntry(i, *entry); | 419 sessions::SerializedNavigationEntry::FromNavigationEntry(i, *entry); |
| 417 } | 420 } |
| 418 tab->timestamp = TimeNow(); | 421 tab->timestamp = TimeNow(); |
| 419 tab->current_navigation_index = controller->GetCurrentEntryIndex(); | 422 tab->current_navigation_index = controller->GetCurrentEntryIndex(); |
| 420 if (tab->current_navigation_index == -1 && entry_count > 0) | 423 if (tab->current_navigation_index == -1 && entry_count > 0) |
| 421 tab->current_navigation_index = 0; | 424 tab->current_navigation_index = 0; |
| 422 tab->tabstrip_index = index; | 425 tab->tabstrip_index = index; |
| 423 | 426 |
| 427 #if defined(ENABLE_EXTENSIONS) |
| 424 extensions::TabHelper* extensions_tab_helper = | 428 extensions::TabHelper* extensions_tab_helper = |
| 425 extensions::TabHelper::FromWebContents(controller->GetWebContents()); | 429 extensions::TabHelper::FromWebContents(controller->GetWebContents()); |
| 426 // extensions_tab_helper is NULL in some browser tests. | 430 // extensions_tab_helper is NULL in some browser tests. |
| 427 if (extensions_tab_helper) { | 431 if (extensions_tab_helper) { |
| 428 const extensions::Extension* extension = | 432 const extensions::Extension* extension = |
| 429 extensions_tab_helper->extension_app(); | 433 extensions_tab_helper->extension_app(); |
| 430 if (extension) | 434 if (extension) |
| 431 tab->extension_app_id = extension->id(); | 435 tab->extension_app_id = extension->id(); |
| 432 } | 436 } |
| 437 #endif |
| 433 | 438 |
| 434 tab->user_agent_override = | 439 tab->user_agent_override = |
| 435 controller->GetWebContents()->GetUserAgentOverride(); | 440 controller->GetWebContents()->GetUserAgentOverride(); |
| 436 | 441 |
| 437 // TODO(ajwong): This does not correctly handle storage for isolated apps. | 442 // TODO(ajwong): This does not correctly handle storage for isolated apps. |
| 438 tab->session_storage_namespace = | 443 tab->session_storage_namespace = |
| 439 controller->GetDefaultSessionStorageNamespace(); | 444 controller->GetDefaultSessionStorageNamespace(); |
| 440 | 445 |
| 441 // Delegate may be NULL during unit tests. | 446 // Delegate may be NULL during unit tests. |
| 442 if (delegate) { | 447 if (delegate) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 Tab* tab = static_cast<Tab*>(entry); | 592 Tab* tab = static_cast<Tab*>(entry); |
| 588 if (tab->browser_id == old_id) | 593 if (tab->browser_id == old_id) |
| 589 tab->browser_id = new_id; | 594 tab->browser_id = new_id; |
| 590 } | 595 } |
| 591 } | 596 } |
| 592 } | 597 } |
| 593 | 598 |
| 594 base::Time TabRestoreServiceHelper::TimeNow() const { | 599 base::Time TabRestoreServiceHelper::TimeNow() const { |
| 595 return time_factory_ ? time_factory_->TimeNow() : base::Time::Now(); | 600 return time_factory_ ? time_factory_->TimeNow() : base::Time::Now(); |
| 596 } | 601 } |
| OLD | NEW |