navigation_controller_android.cc revision 116680a4aac90f2aa7413d9095a592090648e557
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#include "content/browser/frame_host/navigation_controller_android.h"
6
7#include "base/android/jni_android.h"
8#include "content/public/browser/navigation_controller.h"
9#include "jni/NavigationControllerImpl_jni.h"
10
11using base::android::AttachCurrentThread;
12
13namespace content {
14
15// static
16bool NavigationControllerAndroid::Register(JNIEnv* env) {
17  return RegisterNativesImpl(env);
18}
19
20NavigationControllerAndroid::NavigationControllerAndroid(
21    NavigationController* navigation_controller)
22    : navigation_controller_(navigation_controller) {
23  JNIEnv* env = AttachCurrentThread();
24  obj_.Reset(env,
25             Java_NavigationControllerImpl_create(
26                 env, reinterpret_cast<intptr_t>(this)).obj());
27}
28
29NavigationControllerAndroid::~NavigationControllerAndroid() {
30  Java_NavigationControllerImpl_destroy(AttachCurrentThread(), obj_.obj());
31}
32
33base::android::ScopedJavaLocalRef<jobject>
34NavigationControllerAndroid::GetJavaObject() {
35  return base::android::ScopedJavaLocalRef<jobject>(obj_);
36}
37
38jboolean NavigationControllerAndroid::CanGoBack(JNIEnv* env, jobject obj) {
39  return navigation_controller_->CanGoBack();
40}
41
42jboolean NavigationControllerAndroid::CanGoForward(JNIEnv* env,
43                                                   jobject obj) {
44  return navigation_controller_->CanGoForward();
45}
46
47jboolean NavigationControllerAndroid::CanGoToOffset(JNIEnv* env,
48                                                    jobject obj,
49                                                    jint offset) {
50  return navigation_controller_->CanGoToOffset(offset);
51}
52
53void NavigationControllerAndroid::GoBack(JNIEnv* env, jobject obj) {
54  navigation_controller_->GoBack();
55}
56
57void NavigationControllerAndroid::GoForward(JNIEnv* env, jobject obj) {
58  navigation_controller_->GoForward();
59}
60
61void NavigationControllerAndroid::GoToOffset(JNIEnv* env,
62                                             jobject obj,
63                                             jint offset) {
64  navigation_controller_->GoToOffset(offset);
65}
66
67void NavigationControllerAndroid::LoadIfNecessary(JNIEnv* env, jobject obj) {
68  navigation_controller_->LoadIfNecessary();
69}
70
71void NavigationControllerAndroid::ContinuePendingReload(JNIEnv* env,
72                                                        jobject obj) {
73  navigation_controller_->ContinuePendingReload();
74}
75
76void NavigationControllerAndroid::Reload(JNIEnv* env,
77                                         jobject obj,
78                                         jboolean check_for_repost) {
79  navigation_controller_->Reload(check_for_repost);
80}
81
82void NavigationControllerAndroid::ReloadIgnoringCache(
83    JNIEnv* env,
84    jobject obj,
85    jboolean check_for_repost) {
86  navigation_controller_->ReloadIgnoringCache(check_for_repost);
87}
88
89void NavigationControllerAndroid::RequestRestoreLoad(JNIEnv* env, jobject obj) {
90  navigation_controller_->SetNeedsReload();
91}
92
93void NavigationControllerAndroid::CancelPendingReload(JNIEnv* env,
94                                                      jobject obj) {
95  navigation_controller_->CancelPendingReload();
96}
97
98void NavigationControllerAndroid::GoToNavigationIndex(JNIEnv* env,
99                                                      jobject obj,
100                                                      jint index) {
101  navigation_controller_->GoToIndex(index);
102}
103
104}  // namespace content
105