Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/frame_host/navigation_controller_android.h" | 5 #include "content/browser/frame_host/navigation_controller_android.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 "content/browser/frame_host/navigation_entry_impl.h" | 10 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 11 #include "content/public/browser/browser_context.h" | 11 #include "content/public/browser/browser_context.h" |
| 12 #include "content/public/browser/navigation_controller.h" | 12 #include "content/public/browser/navigation_controller.h" |
| 13 #include "content/public/browser/ssl_host_state_delegate.h" | 13 #include "content/public/browser/ssl_host_state_delegate.h" |
| 14 #include "jni/NavigationControllerImpl_jni.h" | 14 #include "jni/NavigationControllerImpl_jni.h" |
| 15 #include "ui/gfx/android/java_bitmap.h" | 15 #include "ui/gfx/android/java_bitmap.h" |
| 16 | 16 |
| 17 using base::android::AttachCurrentThread; | 17 using base::android::AttachCurrentThread; |
| 18 using base::android::ConvertJavaStringToUTF16; | 18 using base::android::ConvertJavaStringToUTF16; |
| 19 using base::android::ConvertJavaStringToUTF8; | 19 using base::android::ConvertJavaStringToUTF8; |
| 20 using base::android::ConvertUTF16ToJavaString; | 20 using base::android::ConvertUTF16ToJavaString; |
| 21 using base::android::ConvertUTF8ToJavaString; | 21 using base::android::ConvertUTF8ToJavaString; |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // static | 24 // static |
| 25 static void AddNavigationEntryToHistory(JNIEnv* env, | 25 static base::android::ScopedJavaLocalRef<jobject> CreateJavaNavigationEntry( |
| 26 jobject obj, | 26 JNIEnv* env, |
| 27 jobject history, | 27 jobject obj, |
| 28 content::NavigationEntry* entry, | 28 content::NavigationEntry* entry, |
| 29 int index) { | 29 int index) { |
| 30 if (!entry) | |
|
Ted C
2014/09/18 20:29:06
I don't think we should support NULL entries. Tha
David Trainor- moved to gerrit
2014/09/18 21:06:24
Done.
| |
| 31 return base::android::ScopedJavaLocalRef<jobject>(); | |
| 32 | |
| 30 // Get the details of the current entry | 33 // Get the details of the current entry |
| 31 ScopedJavaLocalRef<jstring> j_url( | 34 ScopedJavaLocalRef<jstring> j_url( |
| 32 ConvertUTF8ToJavaString(env, entry->GetURL().spec())); | 35 ConvertUTF8ToJavaString(env, entry->GetURL().spec())); |
| 33 ScopedJavaLocalRef<jstring> j_virtual_url( | 36 ScopedJavaLocalRef<jstring> j_virtual_url( |
| 34 ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec())); | 37 ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec())); |
| 35 ScopedJavaLocalRef<jstring> j_original_url( | 38 ScopedJavaLocalRef<jstring> j_original_url( |
| 36 ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec())); | 39 ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec())); |
| 37 ScopedJavaLocalRef<jstring> j_title( | 40 ScopedJavaLocalRef<jstring> j_title( |
| 38 ConvertUTF16ToJavaString(env, entry->GetTitle())); | 41 ConvertUTF16ToJavaString(env, entry->GetTitle())); |
| 39 ScopedJavaLocalRef<jobject> j_bitmap; | 42 ScopedJavaLocalRef<jobject> j_bitmap; |
| 40 const content::FaviconStatus& status = entry->GetFavicon(); | 43 const content::FaviconStatus& status = entry->GetFavicon(); |
| 41 if (status.valid && status.image.ToSkBitmap()->getSize() > 0) | 44 if (status.valid && status.image.ToSkBitmap()->getSize() > 0) |
| 42 j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap()); | 45 j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap()); |
| 43 | 46 |
| 44 // Add the item to the list | 47 return content::Java_NavigationControllerImpl_createNavigationEntry( |
| 45 content::Java_NavigationControllerImpl_addToNavigationHistory( | |
| 46 env, | 48 env, |
| 47 obj, | 49 obj, |
|
Ted C
2014/09/18 20:29:06
wha? Why is this method not static? Why was it n
David Trainor- moved to gerrit
2014/09/18 21:06:24
hah good question!
| |
| 48 history, | |
| 49 index, | 50 index, |
| 50 j_url.obj(), | 51 j_url.obj(), |
| 51 j_virtual_url.obj(), | 52 j_virtual_url.obj(), |
| 52 j_original_url.obj(), | 53 j_original_url.obj(), |
| 53 j_title.obj(), | 54 j_title.obj(), |
| 54 j_bitmap.obj()); | 55 j_bitmap.obj()); |
| 55 } | 56 } |
| 56 | 57 |
| 58 static void AddNavigationEntryToHistory(JNIEnv* env, | |
| 59 jobject obj, | |
| 60 jobject history, | |
| 61 content::NavigationEntry* entry, | |
| 62 int index) { | |
| 63 base::android::ScopedJavaLocalRef<jobject> j_entry = | |
| 64 CreateJavaNavigationEntry(env, obj, entry, index); | |
| 65 if (j_entry.is_null()) | |
|
Ted C
2014/09/18 20:29:06
would be able to remove this check here based on a
David Trainor- moved to gerrit
2014/09/18 21:06:24
Done.
| |
| 66 return; | |
| 67 | |
| 68 content::Java_NavigationControllerImpl_addToNavigationHistory( | |
| 69 env, | |
| 70 obj, | |
| 71 history, | |
| 72 j_entry.obj()); | |
| 73 } | |
| 74 | |
| 57 } // namespace | 75 } // namespace |
| 58 | 76 |
| 59 namespace content { | 77 namespace content { |
| 60 | 78 |
| 61 // static | 79 // static |
| 62 bool NavigationControllerAndroid::Register(JNIEnv* env) { | 80 bool NavigationControllerAndroid::Register(JNIEnv* env) { |
| 63 return RegisterNativesImpl(env); | 81 return RegisterNativesImpl(env); |
| 64 } | 82 } |
| 65 | 83 |
| 66 NavigationControllerAndroid::NavigationControllerAndroid( | 84 NavigationControllerAndroid::NavigationControllerAndroid( |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 entry->SetIsOverridingUserAgent(enabled); | 303 entry->SetIsOverridingUserAgent(enabled); |
| 286 | 304 |
| 287 // Send the override to the renderer. | 305 // Send the override to the renderer. |
| 288 if (reload_on_state_change) { | 306 if (reload_on_state_change) { |
| 289 // Reloading the page will send the override down as part of the | 307 // Reloading the page will send the override down as part of the |
| 290 // navigation IPC message. | 308 // navigation IPC message. |
| 291 navigation_controller_->ReloadOriginalRequestURL(false); | 309 navigation_controller_->ReloadOriginalRequestURL(false); |
| 292 } | 310 } |
| 293 } | 311 } |
| 294 | 312 |
| 313 base::android::ScopedJavaLocalRef<jobject> | |
| 314 NavigationControllerAndroid::GetPendingEntry(JNIEnv* env, jobject obj) { | |
| 315 return CreateJavaNavigationEntry( | |
| 316 env, | |
| 317 obj, | |
| 318 navigation_controller_->GetPendingEntry(), | |
| 319 navigation_controller_->GetPendingEntryIndex()); | |
| 320 } | |
| 321 | |
| 295 } // namespace content | 322 } // namespace content |
| OLD | NEW |