OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/tab_contents/navigation_controller.h" | 5 #include "chrome/browser/tab_contents/navigation_controller.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/browser_about_handler.h" | 12 #include "chrome/browser/browser_about_handler.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/browser_url_handler.h" | 14 #include "chrome/browser/browser_url_handler.h" |
15 #include "chrome/browser/in_process_webkit/dom_storage_context.h" | 15 #include "chrome/browser/in_process_webkit/session_storage_namespace.h" |
16 #include "chrome/browser/in_process_webkit/webkit_context.h" | |
17 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
18 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
19 #include "chrome/browser/renderer_host/site_instance.h" | 18 #include "chrome/browser/renderer_host/site_instance.h" |
20 #include "chrome/browser/sessions/session_types.h" | 19 #include "chrome/browser/sessions/session_types.h" |
21 #include "chrome/browser/tab_contents/interstitial_page.h" | 20 #include "chrome/browser/tab_contents/interstitial_page.h" |
22 #include "chrome/browser/tab_contents/navigation_entry.h" | 21 #include "chrome/browser/tab_contents/navigation_entry.h" |
23 #include "chrome/browser/tab_contents/tab_contents.h" | 22 #include "chrome/browser/tab_contents/tab_contents.h" |
24 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 23 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
25 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
26 #include "chrome/common/navigation_types.h" | 25 #include "chrome/common/navigation_types.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 106 |
108 // NavigationController --------------------------------------------------- | 107 // NavigationController --------------------------------------------------- |
109 | 108 |
110 // static | 109 // static |
111 size_t NavigationController::max_entry_count_ = | 110 size_t NavigationController::max_entry_count_ = |
112 chrome::kMaxSessionHistoryEntries; | 111 chrome::kMaxSessionHistoryEntries; |
113 | 112 |
114 // static | 113 // static |
115 bool NavigationController::check_for_repost_ = true; | 114 bool NavigationController::check_for_repost_ = true; |
116 | 115 |
117 NavigationController::NavigationController(TabContents* contents, | 116 NavigationController::NavigationController( |
118 Profile* profile) | 117 TabContents* contents, |
| 118 Profile* profile, |
| 119 SessionStorageNamespace* session_storage_namespace) |
119 : profile_(profile), | 120 : profile_(profile), |
120 pending_entry_(NULL), | 121 pending_entry_(NULL), |
121 last_committed_entry_index_(-1), | 122 last_committed_entry_index_(-1), |
122 pending_entry_index_(-1), | 123 pending_entry_index_(-1), |
123 transient_entry_index_(-1), | 124 transient_entry_index_(-1), |
124 tab_contents_(contents), | 125 tab_contents_(contents), |
125 max_restored_page_id_(-1), | 126 max_restored_page_id_(-1), |
126 ALLOW_THIS_IN_INITIALIZER_LIST(ssl_manager_(this)), | 127 ALLOW_THIS_IN_INITIALIZER_LIST(ssl_manager_(this)), |
127 needs_reload_(false), | 128 needs_reload_(false), |
128 session_storage_namespace_id_(profile->GetWebKitContext()-> | 129 session_storage_namespace_(session_storage_namespace), |
129 dom_storage_context()->AllocateSessionStorageNamespaceId()), | |
130 pending_reload_(NO_RELOAD) { | 130 pending_reload_(NO_RELOAD) { |
131 DCHECK(profile_); | 131 DCHECK(profile_); |
| 132 if (!session_storage_namespace_) |
| 133 session_storage_namespace_ = new SessionStorageNamespace(profile_); |
132 } | 134 } |
133 | 135 |
134 NavigationController::~NavigationController() { | 136 NavigationController::~NavigationController() { |
135 DiscardNonCommittedEntriesInternal(); | 137 DiscardNonCommittedEntriesInternal(); |
136 | 138 |
137 NotificationService::current()->Notify( | 139 NotificationService::current()->Notify( |
138 NotificationType::TAB_CLOSED, | 140 NotificationType::TAB_CLOSED, |
139 Source<NavigationController>(this), | 141 Source<NavigationController>(this), |
140 NotificationService::NoDetails()); | 142 NotificationService::NoDetails()); |
141 | |
142 // When we go away, the session storage namespace will no longer be reachable. | |
143 profile_->GetWebKitContext()->DeleteSessionStorageNamespace( | |
144 session_storage_namespace_id_); | |
145 } | 143 } |
146 | 144 |
147 void NavigationController::RestoreFromState( | 145 void NavigationController::RestoreFromState( |
148 const std::vector<TabNavigation>& navigations, | 146 const std::vector<TabNavigation>& navigations, |
149 int selected_navigation, | 147 int selected_navigation, |
150 bool from_last_session) { | 148 bool from_last_session) { |
151 // Verify that this controller is unused and that the input is valid. | 149 // Verify that this controller is unused and that the input is valid. |
152 DCHECK(entry_count() == 0 && !pending_entry()); | 150 DCHECK(entry_count() == 0 && !pending_entry()); |
153 DCHECK(selected_navigation >= 0 && | 151 DCHECK(selected_navigation >= 0 && |
154 selected_navigation < static_cast<int>(navigations.size())); | 152 selected_navigation < static_cast<int>(navigations.size())); |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 void NavigationController::CopyStateFrom(const NavigationController& source) { | 938 void NavigationController::CopyStateFrom(const NavigationController& source) { |
941 // Verify that we look new. | 939 // Verify that we look new. |
942 DCHECK(entry_count() == 0 && !pending_entry()); | 940 DCHECK(entry_count() == 0 && !pending_entry()); |
943 | 941 |
944 if (source.entry_count() == 0) | 942 if (source.entry_count() == 0) |
945 return; // Nothing new to do. | 943 return; // Nothing new to do. |
946 | 944 |
947 needs_reload_ = true; | 945 needs_reload_ = true; |
948 InsertEntriesFrom(source, source.entry_count()); | 946 InsertEntriesFrom(source, source.entry_count()); |
949 | 947 |
950 session_storage_namespace_id_ = | 948 session_storage_namespace_ = source.session_storage_namespace_->Clone(); |
951 profile_->GetWebKitContext()->dom_storage_context()->CloneSessionStorage( | |
952 source.session_storage_namespace_id_); | |
953 | 949 |
954 FinishRestore(source.last_committed_entry_index_, false); | 950 FinishRestore(source.last_committed_entry_index_, false); |
955 } | 951 } |
956 | 952 |
957 void NavigationController::CopyStateFromAndPrune( | 953 void NavigationController::CopyStateFromAndPrune( |
958 const NavigationController& source) { | 954 const NavigationController& source) { |
959 // This code is intended for use when the last entry is the active entry. | 955 // This code is intended for use when the last entry is the active entry. |
960 DCHECK((transient_entry_index_ != -1 && | 956 DCHECK((transient_entry_index_ != -1 && |
961 transient_entry_index_ == entry_count() - 1) || | 957 transient_entry_index_ == entry_count() - 1) || |
962 (pending_entry_ && (pending_entry_index_ == -1 || | 958 (pending_entry_ && (pending_entry_index_ == -1 || |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1209 for (int i = 0; i < max_index; i++) { | 1205 for (int i = 0; i < max_index; i++) { |
1210 // When cloning a tab, copy all entries except interstitial pages | 1206 // When cloning a tab, copy all entries except interstitial pages |
1211 if (source.entries_[i].get()->page_type() != | 1207 if (source.entries_[i].get()->page_type() != |
1212 NavigationEntry::INTERSTITIAL_PAGE) { | 1208 NavigationEntry::INTERSTITIAL_PAGE) { |
1213 entries_.insert(entries_.begin() + insert_index++, | 1209 entries_.insert(entries_.begin() + insert_index++, |
1214 linked_ptr<NavigationEntry>( | 1210 linked_ptr<NavigationEntry>( |
1215 new NavigationEntry(*source.entries_[i]))); | 1211 new NavigationEntry(*source.entries_[i]))); |
1216 } | 1212 } |
1217 } | 1213 } |
1218 } | 1214 } |
OLD | NEW |