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 3 // found in the LICENSE file. 4 5 package org.chromium.content.browser.framehost; 6 7 import org.chromium.base.CalledByNative; 8 import org.chromium.base.JNINamespace; 9 import org.chromium.content_public.browser.NavigationController; 10 11 /** 12 * The NavigationControllerImpl Java wrapper to allow communicating with the native 13 * NavigationControllerImpl object. 14 */ 15 @JNINamespace("content") 16 // TODO(tedchoc): Remove the package restriction once this class moves to a non-public content 17 // package whose visibility will be enforced via DEPS. 18 /* package */ class NavigationControllerImpl implements NavigationController { 19 20 private long mNativeNavigationControllerAndroid; 21 NavigationControllerImpl(long nativeNavigationControllerAndroid)22 private NavigationControllerImpl(long nativeNavigationControllerAndroid) { 23 mNativeNavigationControllerAndroid = nativeNavigationControllerAndroid; 24 } 25 26 @CalledByNative create(long nativeNavigationControllerAndroid)27 private static NavigationControllerImpl create(long nativeNavigationControllerAndroid) { 28 return new NavigationControllerImpl(nativeNavigationControllerAndroid); 29 } 30 31 @CalledByNative destroy()32 private void destroy() { 33 mNativeNavigationControllerAndroid = 0; 34 } 35 36 @Override canGoBack()37 public boolean canGoBack() { 38 return mNativeNavigationControllerAndroid != 0 39 && nativeCanGoBack(mNativeNavigationControllerAndroid); 40 } 41 42 @Override canGoForward()43 public boolean canGoForward() { 44 return mNativeNavigationControllerAndroid != 0 45 && nativeCanGoForward(mNativeNavigationControllerAndroid); 46 } 47 48 @Override canGoToOffset(int offset)49 public boolean canGoToOffset(int offset) { 50 return mNativeNavigationControllerAndroid != 0 51 && nativeCanGoToOffset(mNativeNavigationControllerAndroid, offset); 52 } 53 54 @Override goToOffset(int offset)55 public void goToOffset(int offset) { 56 if (mNativeNavigationControllerAndroid != 0) { 57 nativeGoToOffset(mNativeNavigationControllerAndroid, offset); 58 } 59 } 60 61 @Override goToNavigationIndex(int index)62 public void goToNavigationIndex(int index) { 63 if (mNativeNavigationControllerAndroid != 0) { 64 nativeGoToNavigationIndex(mNativeNavigationControllerAndroid, index); 65 } 66 } 67 68 @Override goBack()69 public void goBack() { 70 if (mNativeNavigationControllerAndroid != 0) { 71 nativeGoBack(mNativeNavigationControllerAndroid); 72 } 73 } 74 75 @Override goForward()76 public void goForward() { 77 if (mNativeNavigationControllerAndroid != 0) { 78 nativeGoForward(mNativeNavigationControllerAndroid); 79 } 80 } 81 nativeCanGoBack(long nativeNavigationControllerAndroid)82 private native boolean nativeCanGoBack(long nativeNavigationControllerAndroid); nativeCanGoForward(long nativeNavigationControllerAndroid)83 private native boolean nativeCanGoForward(long nativeNavigationControllerAndroid); nativeCanGoToOffset( long nativeNavigationControllerAndroid, int offset)84 private native boolean nativeCanGoToOffset( 85 long nativeNavigationControllerAndroid, int offset); nativeGoBack(long nativeNavigationControllerAndroid)86 private native void nativeGoBack(long nativeNavigationControllerAndroid); nativeGoForward(long nativeNavigationControllerAndroid)87 private native void nativeGoForward(long nativeNavigationControllerAndroid); nativeGoToOffset(long nativeNavigationControllerAndroid, int offset)88 private native void nativeGoToOffset(long nativeNavigationControllerAndroid, int offset); nativeGoToNavigationIndex( long nativeNavigationControllerAndroid, int index)89 private native void nativeGoToNavigationIndex( 90 long nativeNavigationControllerAndroid, int index); 91 } 92