PassRefPtr<ImmutableArray> WebBackForwardList::backListAsImmutableArrayWithLimit(unsigned limit) { unsigned backListSize = static_cast<unsigned>(backListCount()); unsigned size = std::min(backListSize, limit); if (!size) return ImmutableArray::create(); Vector<RefPtr<APIObject> > vector; vector.reserveInitialCapacity(size); ASSERT(backListSize >= size); for (unsigned i = backListSize - size; i < backListSize; ++i) vector.uncheckedAppend(m_entries[i].get()); return ImmutableArray::adopt(vector); }
WebBackForwardListItem* WebBackForwardList::itemAtIndex(int index) { ASSERT(m_current == NoCurrentItemIndex || m_current < m_entries.size()); if (m_current == NoCurrentItemIndex) return 0; // Do range checks without doing math on index to avoid overflow. if (index < -backListCount()) return 0; if (index > forwardListCount()) return 0; return m_entries[index + m_current].get(); }
WebBackForwardListItem* WebBackForwardList::itemAtIndex(int index) const { ASSERT(!m_hasCurrentIndex || m_currentIndex < m_entries.size()); if (!m_hasCurrentIndex || !m_page) return nullptr; // Do range checks without doing math on index to avoid overflow. if (index < -backListCount()) return nullptr; if (index > forwardListCount()) return nullptr; return m_entries[index + m_currentIndex].get(); }
PassRefPtr<API::Array> WebBackForwardList::backListAsAPIArrayWithLimit(unsigned limit) const { ASSERT(!m_hasCurrentIndex || m_currentIndex < m_entries.size()); if (!m_page || !m_hasCurrentIndex) return API::Array::create(); unsigned backListSize = static_cast<unsigned>(backListCount()); unsigned size = std::min(backListSize, limit); if (!size) return API::Array::create(); Vector<RefPtr<API::Object>> vector; vector.reserveInitialCapacity(size); ASSERT(backListSize >= size); for (unsigned i = backListSize - size; i < backListSize; ++i) { ASSERT(m_entries[i]); vector.uncheckedAppend(m_entries[i].get()); } return API::Array::create(std::move(vector)); }
bool ReadingHistory::canGoBack() const { return backListCount() > 0; }
PassRefPtr<API::Array> WebBackForwardList::backList() const { return backListAsAPIArrayWithLimit(backListCount()); }