OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/browser/android/content_view_core_impl.h" | 5 #include "content/browser/android/content_view_core_impl.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 | 1026 |
1027 void ContentViewCoreImpl::GoForward(JNIEnv* env, jobject obj) { | 1027 void ContentViewCoreImpl::GoForward(JNIEnv* env, jobject obj) { |
1028 web_contents_->GetController().GoForward(); | 1028 web_contents_->GetController().GoForward(); |
1029 tab_crashed_ = false; | 1029 tab_crashed_ = false; |
1030 } | 1030 } |
1031 | 1031 |
1032 void ContentViewCoreImpl::GoToOffset(JNIEnv* env, jobject obj, jint offset) { | 1032 void ContentViewCoreImpl::GoToOffset(JNIEnv* env, jobject obj, jint offset) { |
1033 web_contents_->GetController().GoToOffset(offset); | 1033 web_contents_->GetController().GoToOffset(offset); |
1034 } | 1034 } |
1035 | 1035 |
| 1036 void ContentViewCoreImpl::GoToNavigationIndex(JNIEnv* env, |
| 1037 jobject obj, |
| 1038 jint index) { |
| 1039 web_contents_->GetController().GoToIndex(index); |
| 1040 } |
| 1041 |
1036 void ContentViewCoreImpl::StopLoading(JNIEnv* env, jobject obj) { | 1042 void ContentViewCoreImpl::StopLoading(JNIEnv* env, jobject obj) { |
1037 web_contents_->Stop(); | 1043 web_contents_->Stop(); |
1038 } | 1044 } |
1039 | 1045 |
1040 void ContentViewCoreImpl::Reload(JNIEnv* env, jobject obj) { | 1046 void ContentViewCoreImpl::Reload(JNIEnv* env, jobject obj) { |
1041 // Set check_for_repost parameter to false as we have no repost confirmation | 1047 // Set check_for_repost parameter to false as we have no repost confirmation |
1042 // dialog ("confirm form resubmission" screen will still appear, however). | 1048 // dialog ("confirm form resubmission" screen will still appear, however). |
1043 if (web_contents_->GetController().NeedsReload()) | 1049 if (web_contents_->GetController().NeedsReload()) |
1044 web_contents_->GetController().LoadIfNecessary(); | 1050 web_contents_->GetController().LoadIfNecessary(); |
1045 else | 1051 else |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 return view && view->HasValidFrame(); | 1154 return view && view->HasValidFrame(); |
1149 } | 1155 } |
1150 | 1156 |
1151 void ContentViewCoreImpl::ScrollFocusedEditableNodeIntoView(JNIEnv* env, | 1157 void ContentViewCoreImpl::ScrollFocusedEditableNodeIntoView(JNIEnv* env, |
1152 jobject obj) { | 1158 jobject obj) { |
1153 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 1159 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
1154 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoRect(host->GetRoutingID(), | 1160 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoRect(host->GetRoutingID(), |
1155 gfx::Rect())); | 1161 gfx::Rect())); |
1156 } | 1162 } |
1157 | 1163 |
| 1164 namespace { |
| 1165 |
| 1166 static void AddNavigationEntryToHistory(JNIEnv* env, jobject obj, |
| 1167 jobject history, |
| 1168 NavigationEntry* entry, |
| 1169 int index) { |
| 1170 // Get the details of the current entry |
| 1171 ScopedJavaLocalRef<jstring> j_url( |
| 1172 ConvertUTF8ToJavaString(env, entry->GetURL().spec())); |
| 1173 ScopedJavaLocalRef<jstring> j_virtual_url( |
| 1174 ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec())); |
| 1175 ScopedJavaLocalRef<jstring> j_original_url( |
| 1176 ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec())); |
| 1177 ScopedJavaLocalRef<jstring> j_title( |
| 1178 ConvertUTF16ToJavaString(env, entry->GetTitle())); |
| 1179 ScopedJavaLocalRef<jobject> j_bitmap; |
| 1180 const FaviconStatus& status = entry->GetFavicon(); |
| 1181 if (status.valid && status.image.ToSkBitmap()->getSize() > 0) |
| 1182 j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap()); |
| 1183 |
| 1184 // Add the item to the list |
| 1185 Java_ContentViewCore_addToNavigationHistory( |
| 1186 env, obj, history, index, j_url.obj(), j_virtual_url.obj(), |
| 1187 j_original_url.obj(), j_title.obj(), j_bitmap.obj()); |
| 1188 } |
| 1189 |
| 1190 } // namespace |
| 1191 |
1158 int ContentViewCoreImpl::GetNavigationHistory(JNIEnv* env, | 1192 int ContentViewCoreImpl::GetNavigationHistory(JNIEnv* env, |
1159 jobject obj, | 1193 jobject obj, |
1160 jobject context) { | 1194 jobject context) { |
1161 // Iterate through navigation entries to populate the list | 1195 // Iterate through navigation entries to populate the list |
1162 const NavigationController& controller = web_contents_->GetController(); | 1196 const NavigationController& controller = web_contents_->GetController(); |
1163 int count = controller.GetEntryCount(); | 1197 int count = controller.GetEntryCount(); |
1164 for (int i = 0; i < count; ++i) { | 1198 for (int i = 0; i < count; ++i) { |
1165 NavigationEntry* entry = controller.GetEntryAtIndex(i); | 1199 AddNavigationEntryToHistory( |
1166 | 1200 env, obj, context, controller.GetEntryAtIndex(i), i); |
1167 // Get the details of the current entry | |
1168 ScopedJavaLocalRef<jstring> j_url = ConvertUTF8ToJavaString(env, | |
1169 entry->GetURL().spec()); | |
1170 ScopedJavaLocalRef<jstring> j_virtual_url = ConvertUTF8ToJavaString(env, | |
1171 entry->GetVirtualURL().spec()); | |
1172 ScopedJavaLocalRef<jstring> j_original_url = ConvertUTF8ToJavaString(env, | |
1173 entry->GetOriginalRequestURL().spec()); | |
1174 ScopedJavaLocalRef<jstring> j_title = ConvertUTF16ToJavaString(env, | |
1175 entry->GetTitle()); | |
1176 ScopedJavaLocalRef<jobject> j_bitmap; | |
1177 const FaviconStatus& status = entry->GetFavicon(); | |
1178 if (status.valid && status.image.ToSkBitmap()->getSize() > 0) { | |
1179 j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap()); | |
1180 } | |
1181 | |
1182 // Add the item to the list | |
1183 Java_ContentViewCore_addToNavigationHistory(env, obj, context, j_url.obj(), | |
1184 j_virtual_url.obj(), j_original_url.obj(), j_title.obj(), | |
1185 j_bitmap.obj()); | |
1186 } | 1201 } |
1187 | 1202 |
1188 return controller.GetCurrentEntryIndex(); | 1203 return controller.GetCurrentEntryIndex(); |
1189 } | 1204 } |
1190 | 1205 |
| 1206 void ContentViewCoreImpl::GetDirectedNavigationHistory(JNIEnv* env, |
| 1207 jobject obj, |
| 1208 jobject context, |
| 1209 jboolean is_forward, |
| 1210 jint max_entries) { |
| 1211 // Iterate through navigation entries to populate the list |
| 1212 const NavigationController& controller = web_contents_->GetController(); |
| 1213 int count = controller.GetEntryCount(); |
| 1214 int num_added = 0; |
| 1215 int increment_value = is_forward ? 1 : -1; |
| 1216 for (int i = controller.GetCurrentEntryIndex() + increment_value; |
| 1217 i >= 0 && i < count; |
| 1218 i += increment_value) { |
| 1219 if (num_added >= max_entries) |
| 1220 break; |
| 1221 |
| 1222 AddNavigationEntryToHistory( |
| 1223 env, obj, context, controller.GetEntryAtIndex(i), i); |
| 1224 num_added++; |
| 1225 } |
| 1226 } |
| 1227 |
1191 int ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) { | 1228 int ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) { |
1192 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 1229 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
1193 if (!rwhva) | 1230 if (!rwhva) |
1194 return 0; | 1231 return 0; |
1195 return rwhva->GetNativeImeAdapter(); | 1232 return rwhva->GetNativeImeAdapter(); |
1196 } | 1233 } |
1197 | 1234 |
1198 jboolean ContentViewCoreImpl::NeedsReload(JNIEnv* env, jobject obj) { | 1235 jboolean ContentViewCoreImpl::NeedsReload(JNIEnv* env, jobject obj) { |
1199 return web_contents_->GetController().NeedsReload(); | 1236 return web_contents_->GetController().NeedsReload(); |
1200 } | 1237 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { | 1345 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { |
1309 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; | 1346 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; |
1310 return false; | 1347 return false; |
1311 } | 1348 } |
1312 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); | 1349 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); |
1313 | 1350 |
1314 return RegisterNativesImpl(env) >= 0; | 1351 return RegisterNativesImpl(env) >= 0; |
1315 } | 1352 } |
1316 | 1353 |
1317 } // namespace content | 1354 } // namespace content |
OLD | NEW |