Chromium Code Reviews| Index: content/browser/frame_host/navigation_controller_android.cc |
| diff --git a/content/browser/frame_host/navigation_controller_android.cc b/content/browser/frame_host/navigation_controller_android.cc |
| index 69f7bb1a177263bc4a98c2c18e26b825a5b7f7fa..90821c503618940e3bcd77741669a9d5223996a8 100644 |
| --- a/content/browser/frame_host/navigation_controller_android.cc |
| +++ b/content/browser/frame_host/navigation_controller_android.cc |
| @@ -5,10 +5,18 @@ |
| #include "content/browser/frame_host/navigation_controller_android.h" |
| #include "base/android/jni_android.h" |
| -#include "content/public/browser/navigation_controller.h" |
| +#include "base/android/jni_array.h" |
| +#include "base/android/jni_string.h" |
| +#include "content/browser/frame_host/navigation_entry_impl.h" |
|
Yaron
2014/07/22 20:49:05
can this just use content/public/browser/frame_hos
AKVT
2014/07/23 11:49:23
"favicon_status.h" header is missing in navigation
Yaron
2014/07/23 18:58:37
I think you should include it too then. You aren't
|
| +#include "content/browser/ssl/ssl_host_state.h" |
| #include "jni/NavigationControllerImpl_jni.h" |
| +#include "ui/gfx/android/java_bitmap.h" |
| using base::android::AttachCurrentThread; |
| +using base::android::ConvertJavaStringToUTF16; |
| +using base::android::ConvertJavaStringToUTF8; |
| +using base::android::ConvertUTF16ToJavaString; |
| +using base::android::ConvertUTF8ToJavaString; |
| namespace content { |
| @@ -101,4 +109,187 @@ void NavigationControllerAndroid::GoToNavigationIndex(JNIEnv* env, |
| navigation_controller_->GoToIndex(index); |
| } |
| +void NavigationControllerAndroid::LoadUrl( |
| + NavigationController::LoadURLParams& params) { |
| + navigation_controller_->LoadURLWithParams(params); |
| +} |
| + |
| +void NavigationControllerAndroid::LoadUrl( |
| + JNIEnv* env, jobject obj, |
| + jstring url, |
| + jint load_url_type, |
| + jint transition_type, |
| + jstring j_referrer_url, |
| + jint referrer_policy, |
| + jint ua_override_option, |
| + jstring extra_headers, |
| + jbyteArray post_data, |
| + jstring base_url_for_data_url, |
| + jstring virtual_url_for_data_url, |
| + jboolean can_load_local_resources, |
| + jboolean is_renderer_initiated) { |
| + DCHECK(url); |
| + NavigationController::LoadURLParams params( |
| + GURL(ConvertJavaStringToUTF8(env, url))); |
| + |
| + params.load_type = static_cast<NavigationController::LoadURLType>( |
| + load_url_type); |
| + params.transition_type = PageTransitionFromInt(transition_type); |
| + params.override_user_agent = |
| + static_cast<NavigationController::UserAgentOverrideOption>( |
| + ua_override_option); |
| + |
| + if (extra_headers) |
| + params.extra_headers = ConvertJavaStringToUTF8(env, extra_headers); |
| + |
| + if (post_data) { |
| + std::vector<uint8> http_body_vector; |
| + base::android::JavaByteArrayToByteVector(env, post_data, &http_body_vector); |
| + params.browser_initiated_post_data = |
| + base::RefCountedBytes::TakeVector(&http_body_vector); |
| + } |
| + |
| + if (base_url_for_data_url) { |
| + params.base_url_for_data_url = |
| + GURL(ConvertJavaStringToUTF8(env, base_url_for_data_url)); |
| + } |
| + |
| + if (virtual_url_for_data_url) { |
| + params.virtual_url_for_data_url = |
| + GURL(ConvertJavaStringToUTF8(env, virtual_url_for_data_url)); |
| + } |
| + |
| + params.can_load_local_resources = can_load_local_resources; |
| + if (j_referrer_url) { |
| + params.referrer = content::Referrer( |
| + GURL(ConvertJavaStringToUTF8(env, j_referrer_url)), |
| + static_cast<blink::WebReferrerPolicy>(referrer_policy)); |
| + } |
| + |
| + params.is_renderer_initiated = is_renderer_initiated; |
| + |
| + LoadUrl(params); |
|
Yaron
2014/07/22 20:49:05
just call LoadUrlWithParams directly and get rid o
AKVT
2014/07/23 11:49:23
Done.
|
| +} |
| + |
| +void NavigationControllerAndroid::ClearHistory(JNIEnv* env, jobject obj) { |
| + // TODO(creis): Do callers of this need to know if it fails? |
| + if (navigation_controller_->CanPruneAllButLastCommitted()) |
| + navigation_controller_->PruneAllButLastCommitted(); |
| +} |
| + |
| +namespace { |
|
Yaron
2014/07/22 20:49:05
please move this namespace up above all the member
AKVT
2014/07/23 11:49:23
Done.
|
| + |
| +static void AddNavigationEntryToHistory( |
| + JNIEnv* env, |
| + jobject obj, |
| + jobject history, |
| + NavigationEntry* entry, |
| + int index) { |
| + // Get the details of the current entry |
| + ScopedJavaLocalRef<jstring> j_url( |
| + ConvertUTF8ToJavaString(env, entry->GetURL().spec())); |
| + ScopedJavaLocalRef<jstring> j_virtual_url( |
| + ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec())); |
| + ScopedJavaLocalRef<jstring> j_original_url( |
| + ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec())); |
| + ScopedJavaLocalRef<jstring> j_title( |
| + ConvertUTF16ToJavaString(env, entry->GetTitle())); |
| + ScopedJavaLocalRef<jobject> j_bitmap; |
| + const FaviconStatus& status = entry->GetFavicon(); |
| + if (status.valid && status.image.ToSkBitmap()->getSize() > 0) |
| + j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap()); |
| + |
| + // Add the item to the list |
| + Java_NavigationControllerImpl_addToNavigationHistory( |
| + env, obj, history, index, j_url.obj(), j_virtual_url.obj(), |
| + j_original_url.obj(), j_title.obj(), j_bitmap.obj()); |
| +} |
| + |
| +} // namespace |
| + |
| +jint NavigationControllerAndroid::GetNavigationHistory( |
| + JNIEnv* env, |
| + jobject obj, |
| + jobject history) { |
| + // Iterate through navigation entries to populate the list |
| + int count = navigation_controller_->GetEntryCount(); |
| + for (int i = 0; i < count; ++i) { |
| + AddNavigationEntryToHistory( |
| + env, obj, history, navigation_controller_->GetEntryAtIndex(i), i); |
| + } |
| + |
| + return navigation_controller_->GetCurrentEntryIndex(); |
| +} |
| + |
| +void NavigationControllerAndroid::GetDirectedNavigationHistory( |
| + JNIEnv* env, |
| + jobject obj, |
| + jobject history, |
| + jboolean is_forward, |
| + jint max_entries) { |
| + // Iterate through navigation entries to populate the list |
| + int count = navigation_controller_->GetEntryCount(); |
| + int num_added = 0; |
| + int increment_value = is_forward ? 1 : -1; |
| + for (int i = navigation_controller_->GetCurrentEntryIndex() + increment_value; |
| + i >= 0 && i < count; |
| + i += increment_value) { |
| + if (num_added >= max_entries) |
| + break; |
| + |
| + AddNavigationEntryToHistory( |
| + env, obj, history, navigation_controller_->GetEntryAtIndex(i), i); |
| + num_added++; |
| + } |
| +} |
| + |
| +ScopedJavaLocalRef<jstring> |
| +NavigationControllerAndroid::GetOriginalUrlForActiveNavigationEntry( |
| + JNIEnv* env, |
| + jobject obj) { |
| + NavigationEntry* entry = navigation_controller_->GetVisibleEntry(); |
| + if (entry == NULL) |
| + return ScopedJavaLocalRef<jstring>(env, NULL); |
| + return ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec()); |
| +} |
| + |
| +void NavigationControllerAndroid::ClearSslPreferences( |
| + JNIEnv* env, |
| + jobject obj) { |
| + SSLHostState* state = SSLHostState::GetFor( |
| + navigation_controller_->GetBrowserContext()); |
| + state->Clear(); |
| +} |
| + |
| +bool NavigationControllerAndroid::GetUseDesktopUserAgent( |
| + JNIEnv* env, |
| + jobject obj) { |
| + NavigationEntry* entry = navigation_controller_->GetVisibleEntry(); |
| + return entry && entry->GetIsOverridingUserAgent(); |
| +} |
| + |
| +void NavigationControllerAndroid::SetUseDesktopUserAgent( |
| + JNIEnv* env, |
| + jobject obj, |
| + jboolean enabled, |
| + jboolean reload_on_state_change) { |
| + if (GetUseDesktopUserAgent(env, obj) == enabled) |
| + return; |
| + |
| + // Make sure the navigation entry actually exists. |
| + NavigationEntry* entry = navigation_controller_->GetVisibleEntry(); |
| + if (!entry) |
| + return; |
| + |
| + // Set the flag in the NavigationEntry. |
| + entry->SetIsOverridingUserAgent(enabled); |
| + |
| + // Send the override to the renderer. |
| + if (reload_on_state_change) { |
| + // Reloading the page will send the override down as part of the |
| + // navigation IPC message. |
| + navigation_controller_->ReloadOriginalRequestURL(false); |
| + } |
| +} |
| + |
| } // namespace content |