| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" |
| 10 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/strings/string16.h" |
| 12 #include "content/browser/frame_host/navigation_controller_impl.h" | 14 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 13 #include "content/browser/frame_host/navigation_entry_impl.h" | 15 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 14 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/browser/ssl_host_state_delegate.h" | 17 #include "content/public/browser/ssl_host_state_delegate.h" |
| 16 #include "content/public/common/resource_request_body.h" | 18 #include "content/public/common/resource_request_body.h" |
| 17 #include "jni/NavigationControllerImpl_jni.h" | 19 #include "jni/NavigationControllerImpl_jni.h" |
| 18 #include "net/base/data_url.h" | 20 #include "net/base/data_url.h" |
| 19 #include "ui/gfx/android/java_bitmap.h" | 21 #include "ui/gfx/android/java_bitmap.h" |
| 20 | 22 |
| 21 using base::android::AttachCurrentThread; | 23 using base::android::AttachCurrentThread; |
| 22 using base::android::ConvertJavaStringToUTF16; | 24 using base::android::ConvertJavaStringToUTF16; |
| 23 using base::android::ConvertJavaStringToUTF8; | 25 using base::android::ConvertJavaStringToUTF8; |
| 24 using base::android::ConvertUTF16ToJavaString; | 26 using base::android::ConvertUTF16ToJavaString; |
| 25 using base::android::ConvertUTF8ToJavaString; | 27 using base::android::ConvertUTF8ToJavaString; |
| 26 using base::android::JavaParamRef; | 28 using base::android::JavaParamRef; |
| 27 using base::android::JavaRef; | 29 using base::android::JavaRef; |
| 28 using base::android::ScopedJavaLocalRef; | 30 using base::android::ScopedJavaLocalRef; |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 // static | 34 // static |
| 33 static base::android::ScopedJavaLocalRef<jobject> CreateJavaNavigationEntry( | 35 static base::android::ScopedJavaLocalRef<jobject> CreateJavaNavigationEntry( |
| 34 JNIEnv* env, | 36 JNIEnv* env, |
| 35 content::NavigationEntry* entry, | 37 content::NavigationEntryImpl* entry, |
| 36 int index) { | 38 int index) { |
| 37 DCHECK(entry); | 39 DCHECK(entry); |
| 38 | 40 |
| 39 // Get the details of the current entry | 41 // Get the details of the current entry |
| 40 ScopedJavaLocalRef<jstring> j_url( | 42 ScopedJavaLocalRef<jstring> j_url( |
| 41 ConvertUTF8ToJavaString(env, entry->GetURL().spec())); | 43 ConvertUTF8ToJavaString(env, entry->GetURL().spec())); |
| 42 ScopedJavaLocalRef<jstring> j_virtual_url( | 44 ScopedJavaLocalRef<jstring> j_virtual_url( |
| 43 ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec())); | 45 ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec())); |
| 44 ScopedJavaLocalRef<jstring> j_original_url( | 46 ScopedJavaLocalRef<jstring> j_original_url( |
| 45 ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec())); | 47 ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec())); |
| 46 ScopedJavaLocalRef<jstring> j_title( | 48 ScopedJavaLocalRef<jstring> j_title( |
| 47 ConvertUTF16ToJavaString(env, entry->GetTitle())); | 49 ConvertUTF16ToJavaString(env, entry->GetTitle())); |
| 48 ScopedJavaLocalRef<jobject> j_bitmap; | 50 ScopedJavaLocalRef<jobject> j_bitmap; |
| 49 const content::FaviconStatus& status = entry->GetFavicon(); | 51 const content::FaviconStatus& status = entry->GetFavicon(); |
| 50 if (status.valid && status.image.ToSkBitmap()->getSize() > 0) | 52 if (status.valid && status.image.ToSkBitmap()->getSize() > 0) |
| 51 j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap()); | 53 j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap()); |
| 52 | 54 |
| 55 std::vector<std::string> extra_data_keys; |
| 56 std::vector<base::string16> extra_data_values; |
| 57 for (const auto& pair : entry->get_extra_data()) { |
| 58 extra_data_keys.push_back(pair.first); |
| 59 extra_data_values.push_back(pair.second); |
| 60 } |
| 61 ScopedJavaLocalRef<jobjectArray> j_extra_data_keys( |
| 62 base::android::ToJavaArrayOfStrings(env, extra_data_keys)); |
| 63 ScopedJavaLocalRef<jobjectArray> j_extra_data_values( |
| 64 base::android::ToJavaArrayOfStrings(env, extra_data_values)); |
| 65 |
| 53 return content::Java_NavigationControllerImpl_createNavigationEntry( | 66 return content::Java_NavigationControllerImpl_createNavigationEntry( |
| 54 env, index, j_url, j_virtual_url, j_original_url, j_title, j_bitmap, | 67 env, index, j_url, j_virtual_url, j_original_url, j_title, j_bitmap, |
| 55 entry->GetTransitionType()); | 68 entry->GetTransitionType(), j_extra_data_keys, j_extra_data_values); |
| 56 } | 69 } |
| 57 | 70 |
| 58 static void AddNavigationEntryToHistory(JNIEnv* env, | 71 static void AddNavigationEntryToHistory(JNIEnv* env, |
| 59 const JavaRef<jobject>& history, | 72 const JavaRef<jobject>& history, |
| 60 content::NavigationEntry* entry, | 73 content::NavigationEntryImpl* entry, |
| 61 int index) { | 74 int index) { |
| 62 content::Java_NavigationControllerImpl_addToNavigationHistory( | 75 content::Java_NavigationControllerImpl_addToNavigationHistory( |
| 63 env, history, CreateJavaNavigationEntry(env, entry, index)); | 76 env, history, CreateJavaNavigationEntry(env, entry, index)); |
| 64 } | 77 } |
| 65 | 78 |
| 66 } // namespace | 79 } // namespace |
| 67 | 80 |
| 68 namespace content { | 81 namespace content { |
| 69 | 82 |
| 70 // static | 83 // static |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 } | 363 } |
| 351 } | 364 } |
| 352 | 365 |
| 353 base::android::ScopedJavaLocalRef<jobject> | 366 base::android::ScopedJavaLocalRef<jobject> |
| 354 NavigationControllerAndroid::GetEntryAtIndex(JNIEnv* env, | 367 NavigationControllerAndroid::GetEntryAtIndex(JNIEnv* env, |
| 355 const JavaParamRef<jobject>& obj, | 368 const JavaParamRef<jobject>& obj, |
| 356 int index) { | 369 int index) { |
| 357 if (index < 0 || index >= navigation_controller_->GetEntryCount()) | 370 if (index < 0 || index >= navigation_controller_->GetEntryCount()) |
| 358 return base::android::ScopedJavaLocalRef<jobject>(); | 371 return base::android::ScopedJavaLocalRef<jobject>(); |
| 359 | 372 |
| 360 content::NavigationEntry* entry = | 373 return CreateJavaNavigationEntry( |
| 361 navigation_controller_->GetEntryAtIndex(index); | 374 env, navigation_controller_->GetEntryAtIndex(index), index); |
| 362 return CreateJavaNavigationEntry(env, entry, index); | |
| 363 } | 375 } |
| 364 | 376 |
| 365 base::android::ScopedJavaLocalRef<jobject> | 377 base::android::ScopedJavaLocalRef<jobject> |
| 366 NavigationControllerAndroid::GetPendingEntry(JNIEnv* env, | 378 NavigationControllerAndroid::GetPendingEntry(JNIEnv* env, |
| 367 const JavaParamRef<jobject>& obj) { | 379 const JavaParamRef<jobject>& obj) { |
| 368 content::NavigationEntry* entry = navigation_controller_->GetPendingEntry(); | 380 content::NavigationEntryImpl* entry = |
| 381 navigation_controller_->GetPendingEntry(); |
| 369 | 382 |
| 370 if (!entry) | 383 if (!entry) |
| 371 return base::android::ScopedJavaLocalRef<jobject>(); | 384 return base::android::ScopedJavaLocalRef<jobject>(); |
| 372 | 385 |
| 373 return CreateJavaNavigationEntry( | 386 return CreateJavaNavigationEntry( |
| 374 env, entry, navigation_controller_->GetPendingEntryIndex()); | 387 env, entry, navigation_controller_->GetPendingEntryIndex()); |
| 375 } | 388 } |
| 376 | 389 |
| 377 jint NavigationControllerAndroid::GetLastCommittedEntryIndex( | 390 jint NavigationControllerAndroid::GetLastCommittedEntryIndex( |
| 378 JNIEnv* env, | 391 JNIEnv* env, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 JNIEnv* env, | 426 JNIEnv* env, |
| 414 const JavaParamRef<jobject>& obj, | 427 const JavaParamRef<jobject>& obj, |
| 415 jlong source_navigation_controller_android, | 428 jlong source_navigation_controller_android, |
| 416 jboolean replace_entry) { | 429 jboolean replace_entry) { |
| 417 navigation_controller_->CopyStateFromAndPrune( | 430 navigation_controller_->CopyStateFromAndPrune( |
| 418 reinterpret_cast<NavigationControllerAndroid*>( | 431 reinterpret_cast<NavigationControllerAndroid*>( |
| 419 source_navigation_controller_android)->navigation_controller_, | 432 source_navigation_controller_android)->navigation_controller_, |
| 420 replace_entry); | 433 replace_entry); |
| 421 } | 434 } |
| 422 | 435 |
| 436 void NavigationControllerAndroid::SetEntryExtraData( |
| 437 JNIEnv* env, |
| 438 const JavaParamRef<jobject>& obj, |
| 439 jint index, |
| 440 const JavaParamRef<jstring>& jkey, |
| 441 const JavaParamRef<jstring>& jvalue) { |
| 442 if (index < 0 || index >= navigation_controller_->GetEntryCount()) |
| 443 return; |
| 444 |
| 445 std::string key = base::android::ConvertJavaStringToUTF8(env, jkey); |
| 446 base::string16 value = base::android::ConvertJavaStringToUTF16(env, jvalue); |
| 447 navigation_controller_->GetEntryAtIndex(index)->SetExtraData(key, value); |
| 448 } |
| 449 |
| 423 } // namespace content | 450 } // namespace content |
| OLD | NEW |