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