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/session_restore.h" | 5 #include "chrome/browser/sessions/session_restore.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/platform_file.h" | 18 #include "base/platform_file.h" |
19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
20 #include "base/stringprintf.h" | 20 #include "base/stringprintf.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
| 23 #include "chrome/browser/extensions/extension_system.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/sessions/session_service.h" | 25 #include "chrome/browser/sessions/session_service.h" |
25 #include "chrome/browser/sessions/session_service_factory.h" | 26 #include "chrome/browser/sessions/session_service_factory.h" |
26 #include "chrome/browser/sessions/session_types.h" | 27 #include "chrome/browser/sessions/session_types.h" |
27 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
28 #include "chrome/browser/ui/browser_finder.h" | 29 #include "chrome/browser/ui/browser_finder.h" |
29 #include "chrome/browser/ui/browser_navigator.h" | 30 #include "chrome/browser/ui/browser_navigator.h" |
30 #include "chrome/browser/ui/browser_tabrestore.h" | 31 #include "chrome/browser/ui/browser_tabrestore.h" |
31 #include "chrome/browser/ui/browser_tabstrip.h" | 32 #include "chrome/browser/ui/browser_tabstrip.h" |
32 #include "chrome/browser/ui/browser_window.h" | 33 #include "chrome/browser/ui/browser_window.h" |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 | 584 |
584 RecordAppLaunchForTab(browser, tab, selected_index); | 585 RecordAppLaunchForTab(browser, tab, selected_index); |
585 | 586 |
586 if (disposition == CURRENT_TAB) { | 587 if (disposition == CURRENT_TAB) { |
587 DCHECK(!use_new_window); | 588 DCHECK(!use_new_window); |
588 chrome::ReplaceRestoredTab(browser, | 589 chrome::ReplaceRestoredTab(browser, |
589 tab.navigations, | 590 tab.navigations, |
590 selected_index, | 591 selected_index, |
591 true, | 592 true, |
592 tab.extension_app_id, | 593 tab.extension_app_id, |
593 NULL); | 594 content::SessionStorageNamespaceMap()); |
594 } else { | 595 } else { |
595 int tab_index = use_new_window ? 0 : browser->active_index() + 1; | 596 int tab_index = use_new_window ? 0 : browser->active_index() + 1; |
596 WebContents* web_contents = chrome::AddRestoredTab( | 597 WebContents* web_contents = chrome::AddRestoredTab( |
597 browser, | 598 browser, |
598 tab.navigations, | 599 tab.navigations, |
599 tab_index, | 600 tab_index, |
600 selected_index, | 601 selected_index, |
601 tab.extension_app_id, | 602 tab.extension_app_id, |
602 false, // selected | 603 false, // selected |
603 tab.pinned, | 604 tab.pinned, |
604 true, | 605 true, |
605 NULL); | 606 content::SessionStorageNamespaceMap()); |
606 // Start loading the tab immediately. | 607 // Start loading the tab immediately. |
607 web_contents->GetController().LoadIfNecessary(); | 608 web_contents->GetController().LoadIfNecessary(); |
608 } | 609 } |
609 | 610 |
610 if (use_new_window) { | 611 if (use_new_window) { |
611 chrome::ActivateTabAt(browser, 0, true); | 612 chrome::ActivateTabAt(browser, 0, true); |
612 browser->window()->Show(); | 613 browser->window()->Show(); |
613 } | 614 } |
614 NotifySessionServiceOfRestoredTabs(browser, browser->tab_count()); | 615 NotifySessionServiceOfRestoredTabs(browser, browser->tab_count()); |
615 | 616 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 DCHECK(!tab.navigations.empty()); | 870 DCHECK(!tab.navigations.empty()); |
870 int selected_index = tab.current_navigation_index; | 871 int selected_index = tab.current_navigation_index; |
871 selected_index = std::max( | 872 selected_index = std::max( |
872 0, | 873 0, |
873 std::min(selected_index, | 874 std::min(selected_index, |
874 static_cast<int>(tab.navigations.size() - 1))); | 875 static_cast<int>(tab.navigations.size() - 1))); |
875 | 876 |
876 RecordAppLaunchForTab(browser, tab, selected_index); | 877 RecordAppLaunchForTab(browser, tab, selected_index); |
877 | 878 |
878 // Associate sessionStorage (if any) to the restored tab. | 879 // Associate sessionStorage (if any) to the restored tab. |
879 scoped_refptr<content::SessionStorageNamespace> session_storage_namespace; | 880 content::SessionStorageNamespaceMap restored_session_storage_namespaces; |
880 if (!tab.session_storage_persistent_id.empty()) { | 881 for (std::map<std::string, std::string>::const_iterator it = |
881 session_storage_namespace = | 882 tab.session_storage_persistent_id_map.begin(); |
882 content::BrowserContext::GetDefaultDOMStorageContext(profile_)-> | 883 it != tab.session_storage_persistent_id_map.end(); |
883 RecreateSessionStorage(tab.session_storage_persistent_id); | 884 ++it) { |
| 885 using content::BrowserContext; |
| 886 if (BrowserContext::IsValidStoragePartitionId(profile_, it->first)) { |
| 887 restored_session_storage_namespaces[it->first] = |
| 888 BrowserContext::GetDOMStorageContextByPartitionId(profile_, |
| 889 it->first)-> |
| 890 RecreateSessionStorage(it->second); |
| 891 } |
884 } | 892 } |
885 | 893 |
886 WebContents* web_contents = | 894 WebContents* web_contents = |
887 chrome::AddRestoredTab(browser, | 895 chrome::AddRestoredTab(browser, |
888 tab.navigations, | 896 tab.navigations, |
889 tab_index, | 897 tab_index, |
890 selected_index, | 898 selected_index, |
891 tab.extension_app_id, | 899 tab.extension_app_id, |
892 false, // select | 900 false, // select |
893 tab.pinned, | 901 tab.pinned, |
894 true, | 902 true, |
895 session_storage_namespace.get()); | 903 restored_session_storage_namespaces); |
896 // Regression check: check that the tab didn't start loading right away. The | 904 // Regression check: check that the tab didn't start loading right away. The |
897 // focused tab will be loaded by Browser, and TabLoader will load the rest. | 905 // focused tab will be loaded by Browser, and TabLoader will load the rest. |
898 DCHECK(web_contents->GetController().NeedsReload()); | 906 DCHECK(web_contents->GetController().NeedsReload()); |
899 | 907 |
900 // Set up the file access rights for the selected navigation entry. | 908 // Set up the file access rights for the selected navigation entry. |
901 const int id = web_contents->GetRenderProcessHost()->GetID(); | 909 const int id = web_contents->GetRenderProcessHost()->GetID(); |
902 const int read_file_permissions = | 910 const int read_file_permissions = |
903 base::PLATFORM_FILE_OPEN | | 911 base::PLATFORM_FILE_OPEN | |
904 base::PLATFORM_FILE_READ | | 912 base::PLATFORM_FILE_READ | |
905 base::PLATFORM_FILE_EXCLUSIVE_READ | | 913 base::PLATFORM_FILE_EXCLUSIVE_READ | |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 if (active_session_restorers == NULL) | 1098 if (active_session_restorers == NULL) |
1091 return false; | 1099 return false; |
1092 for (std::set<SessionRestoreImpl*>::const_iterator it = | 1100 for (std::set<SessionRestoreImpl*>::const_iterator it = |
1093 active_session_restorers->begin(); | 1101 active_session_restorers->begin(); |
1094 it != active_session_restorers->end(); ++it) { | 1102 it != active_session_restorers->end(); ++it) { |
1095 if ((*it)->profile() == profile) | 1103 if ((*it)->profile() == profile) |
1096 return true; | 1104 return true; |
1097 } | 1105 } |
1098 return false; | 1106 return false; |
1099 } | 1107 } |
OLD | NEW |