| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 /* | 5 /* |
| 6 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 6 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
| 9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
| 10 * | 10 * |
| (...skipping 2110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2121 if (pending_entry_) | 2121 if (pending_entry_) |
| 2122 pending_entry_->set_ssl_error(error); | 2122 pending_entry_->set_ssl_error(error); |
| 2123 } | 2123 } |
| 2124 | 2124 |
| 2125 void NavigationControllerImpl::DiscardTransientEntry() { | 2125 void NavigationControllerImpl::DiscardTransientEntry() { |
| 2126 if (transient_entry_index_ == -1) | 2126 if (transient_entry_index_ == -1) |
| 2127 return; | 2127 return; |
| 2128 entries_.erase(entries_.begin() + transient_entry_index_); | 2128 entries_.erase(entries_.begin() + transient_entry_index_); |
| 2129 if (last_committed_entry_index_ > transient_entry_index_) | 2129 if (last_committed_entry_index_ > transient_entry_index_) |
| 2130 last_committed_entry_index_--; | 2130 last_committed_entry_index_--; |
| 2131 if (pending_entry_index_ > transient_entry_index_) | |
| 2132 pending_entry_index_--; | |
| 2133 transient_entry_index_ = -1; | 2131 transient_entry_index_ = -1; |
| 2134 } | 2132 } |
| 2135 | 2133 |
| 2136 int NavigationControllerImpl::GetEntryIndexWithUniqueID( | 2134 int NavigationControllerImpl::GetEntryIndexWithUniqueID( |
| 2137 int nav_entry_id) const { | 2135 int nav_entry_id) const { |
| 2138 for (int i = static_cast<int>(entries_.size()) - 1; i >= 0; --i) { | 2136 for (int i = static_cast<int>(entries_.size()) - 1; i >= 0; --i) { |
| 2139 if (entries_[i]->GetUniqueID() == nav_entry_id) | 2137 if (entries_[i]->GetUniqueID() == nav_entry_id) |
| 2140 return i; | 2138 return i; |
| 2141 } | 2139 } |
| 2142 return -1; | 2140 return -1; |
| 2143 } | 2141 } |
| 2144 | 2142 |
| 2145 NavigationEntryImpl* NavigationControllerImpl::GetTransientEntry() const { | 2143 NavigationEntryImpl* NavigationControllerImpl::GetTransientEntry() const { |
| 2146 if (transient_entry_index_ == -1) | 2144 if (transient_entry_index_ == -1) |
| 2147 return NULL; | 2145 return NULL; |
| 2148 return entries_[transient_entry_index_].get(); | 2146 return entries_[transient_entry_index_].get(); |
| 2149 } | 2147 } |
| 2150 | 2148 |
| 2151 void NavigationControllerImpl::SetTransientEntry( | 2149 void NavigationControllerImpl::SetTransientEntry( |
| 2152 std::unique_ptr<NavigationEntry> entry) { | 2150 std::unique_ptr<NavigationEntry> entry) { |
| 2153 // Discard any current transient entry, we can only have one at a time. | 2151 // Discard any current transient entry, we can only have one at a time. |
| 2154 int index = 0; | 2152 int index = 0; |
| 2155 if (last_committed_entry_index_ != -1) | 2153 if (last_committed_entry_index_ != -1) |
| 2156 index = last_committed_entry_index_ + 1; | 2154 index = last_committed_entry_index_ + 1; |
| 2157 DiscardTransientEntry(); | 2155 DiscardTransientEntry(); |
| 2158 entries_.insert(entries_.begin() + index, | 2156 entries_.insert(entries_.begin() + index, |
| 2159 NavigationEntryImpl::FromNavigationEntry(std::move(entry))); | 2157 NavigationEntryImpl::FromNavigationEntry(std::move(entry))); |
| 2160 if (pending_entry_index_ >= index) | |
| 2161 pending_entry_index_++; | |
| 2162 transient_entry_index_ = index; | 2158 transient_entry_index_ = index; |
| 2163 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_ALL); | 2159 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_ALL); |
| 2164 } | 2160 } |
| 2165 | 2161 |
| 2166 void NavigationControllerImpl::InsertEntriesFrom( | 2162 void NavigationControllerImpl::InsertEntriesFrom( |
| 2167 const NavigationControllerImpl& source, | 2163 const NavigationControllerImpl& source, |
| 2168 int max_index) { | 2164 int max_index) { |
| 2169 DCHECK_LE(max_index, source.GetEntryCount()); | 2165 DCHECK_LE(max_index, source.GetEntryCount()); |
| 2170 size_t insert_index = 0; | 2166 size_t insert_index = 0; |
| 2171 for (int i = 0; i < max_index; i++) { | 2167 for (int i = 0; i < max_index; i++) { |
| 2172 // When cloning a tab, copy all entries except interstitial pages. | 2168 // When cloning a tab, copy all entries except interstitial pages. |
| 2173 if (source.entries_[i]->GetPageType() != PAGE_TYPE_INTERSTITIAL) { | 2169 if (source.entries_[i]->GetPageType() != PAGE_TYPE_INTERSTITIAL) { |
| 2174 // TODO(creis): Once we start sharing FrameNavigationEntries between | 2170 // TODO(creis): Once we start sharing FrameNavigationEntries between |
| 2175 // NavigationEntries, it will not be safe to share them with another tab. | 2171 // NavigationEntries, it will not be safe to share them with another tab. |
| 2176 // Must have a version of Clone that recreates them. | 2172 // Must have a version of Clone that recreates them. |
| 2177 entries_.insert(entries_.begin() + insert_index++, | 2173 entries_.insert(entries_.begin() + insert_index++, |
| 2178 source.entries_[i]->Clone()); | 2174 source.entries_[i]->Clone()); |
| 2179 } | 2175 } |
| 2180 } | 2176 } |
| 2181 DCHECK(pending_entry_index_ == -1 || | 2177 DCHECK(pending_entry_index_ == -1 || |
| 2182 pending_entry_ == GetEntryAtIndex(pending_entry_index_)); | 2178 pending_entry_ == GetEntryAtIndex(pending_entry_index_)); |
| 2183 } | 2179 } |
| 2184 | 2180 |
| 2185 void NavigationControllerImpl::SetGetTimestampCallbackForTest( | 2181 void NavigationControllerImpl::SetGetTimestampCallbackForTest( |
| 2186 const base::Callback<base::Time()>& get_timestamp_callback) { | 2182 const base::Callback<base::Time()>& get_timestamp_callback) { |
| 2187 get_timestamp_callback_ = get_timestamp_callback; | 2183 get_timestamp_callback_ = get_timestamp_callback; |
| 2188 } | 2184 } |
| 2189 | 2185 |
| 2190 } // namespace content | 2186 } // namespace content |
| OLD | NEW |