summaryrefslogtreecommitdiffstats
path: root/content/browser/web_contents
diff options
context:
space:
mode:
authortedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-22 23:50:03 +0000
committertedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-22 23:50:03 +0000
commit9ba14056e51e361ba14f529151fb7c24cf3a4267 (patch)
tree4c95908199c12e1b0b0b520deb49f47312cf701f /content/browser/web_contents
parent1b4763145250bf02d592c6c7ffc3d3e36484f4c3 (diff)
downloadchromium_src-9ba14056e51e361ba14f529151fb7c24cf3a4267.zip
chromium_src-9ba14056e51e361ba14f529151fb7c24cf3a4267.tar.gz
chromium_src-9ba14056e51e361ba14f529151fb7c24cf3a4267.tar.bz2
Add support for basic web_contents methods in ContentView (android).
This adds the basic navigation functionality and some other basic calls that were simply calling into WebContents. Again, this is for ContentShell upstreaming in android. BUG= TEST= Review URL: https://chromiumcodereview.appspot.com/10581051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143741 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/web_contents')
-rw-r--r--content/browser/web_contents/navigation_controller_impl.cc22
-rw-r--r--content/browser/web_contents/navigation_controller_impl.h5
2 files changed, 19 insertions, 8 deletions
diff --git a/content/browser/web_contents/navigation_controller_impl.cc b/content/browser/web_contents/navigation_controller_impl.cc
index 5dad661..d985605 100644
--- a/content/browser/web_contents/navigation_controller_impl.cc
+++ b/content/browser/web_contents/navigation_controller_impl.cc
@@ -428,15 +428,19 @@ NavigationEntry* NavigationControllerImpl::GetEntryAtIndex(
NavigationEntry* NavigationControllerImpl::GetEntryAtOffset(
int offset) const {
- int index = (transient_entry_index_ != -1) ?
- transient_entry_index_ + offset :
- last_committed_entry_index_ + offset;
+ int index = GetIndexForOffset(offset);
if (index < 0 || index >= GetEntryCount())
return NULL;
return entries_[index].get();
}
+int NavigationControllerImpl::GetIndexForOffset(int offset) const {
+ return (transient_entry_index_ != -1) ?
+ transient_entry_index_ + offset :
+ last_committed_entry_index_ + offset;
+}
+
bool NavigationControllerImpl::CanGoBack() const {
return entries_.size() > 1 && GetCurrentEntryIndex() > 0;
}
@@ -446,6 +450,11 @@ bool NavigationControllerImpl::CanGoForward() const {
return index >= 0 && index < (static_cast<int>(entries_.size()) - 1);
}
+bool NavigationControllerImpl::CanGoToOffset(int offset) const {
+ int index = GetIndexForOffset(offset);
+ return index >= 0 && index < GetEntryCount();
+}
+
void NavigationControllerImpl::GoBack() {
if (!CanGoBack()) {
NOTREACHED();
@@ -519,13 +528,10 @@ void NavigationControllerImpl::GoToIndex(int index) {
}
void NavigationControllerImpl::GoToOffset(int offset) {
- int index = (transient_entry_index_ != -1) ?
- transient_entry_index_ + offset :
- last_committed_entry_index_ + offset;
- if (index < 0 || index >= GetEntryCount())
+ if (!CanGoToOffset(offset))
return;
- GoToIndex(index);
+ GoToIndex(GetIndexForOffset(offset));
}
void NavigationControllerImpl::RemoveEntryAtIndex(int index) {
diff --git a/content/browser/web_contents/navigation_controller_impl.h b/content/browser/web_contents/navigation_controller_impl.h
index 5053475..aa9ac23 100644
--- a/content/browser/web_contents/navigation_controller_impl.h
+++ b/content/browser/web_contents/navigation_controller_impl.h
@@ -80,6 +80,7 @@ class CONTENT_EXPORT NavigationControllerImpl
virtual void LoadIfNecessary() OVERRIDE;
virtual bool CanGoBack() const OVERRIDE;
virtual bool CanGoForward() const OVERRIDE;
+ virtual bool CanGoToOffset(int offset) const OVERRIDE;
virtual void GoBack() OVERRIDE;
virtual void GoForward() OVERRIDE;
virtual void GoToIndex(int index) OVERRIDE;
@@ -270,6 +271,10 @@ class CONTENT_EXPORT NavigationControllerImpl
// transient_entry_index_).
void InsertEntriesFrom(const NavigationControllerImpl& source, int max_index);
+ // Returns the navigation index that differs from the current entry by the
+ // specified |offset|. The index returned is not guaranteed to be valid.
+ int GetIndexForOffset(int offset) const;
+
// ---------------------------------------------------------------------------
// The user browser context associated with this controller.