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 "content/public/browser/navigation_controller.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" | |
| 10 #include "content/browser/frame_host/navigation_entry_impl.h" | |
| 11 #include "content/browser/ssl/ssl_host_state.h" | |
| 9 #include "jni/NavigationControllerImpl_jni.h" | 12 #include "jni/NavigationControllerImpl_jni.h" |
| 13 #include "ui/gfx/android/java_bitmap.h" | |
| 10 | 14 |
| 11 using base::android::AttachCurrentThread; | 15 using base::android::AttachCurrentThread; |
| 16 using base::android::ConvertJavaStringToUTF16; | |
| 17 using base::android::ConvertJavaStringToUTF8; | |
| 18 using base::android::ConvertUTF16ToJavaString; | |
| 19 using base::android::ConvertUTF8ToJavaString; | |
| 12 | 20 |
| 13 namespace content { | 21 namespace content { |
| 14 | 22 |
| 15 // static | 23 // static |
| 24 static void AddNavigationEntryToHistory( | |
|
Yaron
2014/07/23 18:58:38
this should still be in an anonymous namespace, ju
AKVT
2014/07/24 07:47:24
Done.
| |
| 25 JNIEnv* env, | |
| 26 jobject obj, | |
| 27 jobject history, | |
| 28 NavigationEntry* entry, | |
| 29 int index) { | |
| 30 // Get the details of the current entry | |
| 31 ScopedJavaLocalRef<jstring> j_url( | |
| 32 ConvertUTF8ToJavaString(env, entry->GetURL().spec())); | |
| 33 ScopedJavaLocalRef<jstring> j_virtual_url( | |
| 34 ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec())); | |
| 35 ScopedJavaLocalRef<jstring> j_original_url( | |
| 36 ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec())); | |
| 37 ScopedJavaLocalRef<jstring> j_title( | |
| 38 ConvertUTF16ToJavaString(env, entry->GetTitle())); | |
| 39 ScopedJavaLocalRef<jobject> j_bitmap; | |
| 40 const FaviconStatus& status = entry->GetFavicon(); | |
| 41 if (status.valid && status.image.ToSkBitmap()->getSize() > 0) | |
| 42 j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap()); | |
| 43 | |
| 44 // Add the item to the list | |
| 45 Java_NavigationControllerImpl_addToNavigationHistory( | |
| 46 env, obj, history, index, j_url.obj(), j_virtual_url.obj(), | |
| 47 j_original_url.obj(), j_title.obj(), j_bitmap.obj()); | |
| 48 } | |
| 49 | |
| 50 // static | |
| 16 bool NavigationControllerAndroid::Register(JNIEnv* env) { | 51 bool NavigationControllerAndroid::Register(JNIEnv* env) { |
| 17 return RegisterNativesImpl(env); | 52 return RegisterNativesImpl(env); |
| 18 } | 53 } |
| 19 | 54 |
| 20 NavigationControllerAndroid::NavigationControllerAndroid( | 55 NavigationControllerAndroid::NavigationControllerAndroid( |
| 21 NavigationController* navigation_controller) | 56 NavigationController* navigation_controller) |
| 22 : navigation_controller_(navigation_controller) { | 57 : navigation_controller_(navigation_controller) { |
| 23 JNIEnv* env = AttachCurrentThread(); | 58 JNIEnv* env = AttachCurrentThread(); |
| 24 obj_.Reset(env, | 59 obj_.Reset(env, |
| 25 Java_NavigationControllerImpl_create( | 60 Java_NavigationControllerImpl_create( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 jobject obj) { | 129 jobject obj) { |
| 95 navigation_controller_->CancelPendingReload(); | 130 navigation_controller_->CancelPendingReload(); |
| 96 } | 131 } |
| 97 | 132 |
| 98 void NavigationControllerAndroid::GoToNavigationIndex(JNIEnv* env, | 133 void NavigationControllerAndroid::GoToNavigationIndex(JNIEnv* env, |
| 99 jobject obj, | 134 jobject obj, |
| 100 jint index) { | 135 jint index) { |
| 101 navigation_controller_->GoToIndex(index); | 136 navigation_controller_->GoToIndex(index); |
| 102 } | 137 } |
| 103 | 138 |
| 139 void NavigationControllerAndroid::LoadUrl( | |
| 140 JNIEnv* env, jobject obj, | |
| 141 jstring url, | |
| 142 jint load_url_type, | |
| 143 jint transition_type, | |
| 144 jstring j_referrer_url, | |
| 145 jint referrer_policy, | |
| 146 jint ua_override_option, | |
| 147 jstring extra_headers, | |
| 148 jbyteArray post_data, | |
| 149 jstring base_url_for_data_url, | |
| 150 jstring virtual_url_for_data_url, | |
| 151 jboolean can_load_local_resources, | |
| 152 jboolean is_renderer_initiated) { | |
| 153 DCHECK(url); | |
| 154 NavigationController::LoadURLParams params( | |
| 155 GURL(ConvertJavaStringToUTF8(env, url))); | |
| 156 | |
| 157 params.load_type = static_cast<NavigationController::LoadURLType>( | |
| 158 load_url_type); | |
| 159 params.transition_type = PageTransitionFromInt(transition_type); | |
| 160 params.override_user_agent = | |
| 161 static_cast<NavigationController::UserAgentOverrideOption>( | |
| 162 ua_override_option); | |
| 163 | |
| 164 if (extra_headers) | |
| 165 params.extra_headers = ConvertJavaStringToUTF8(env, extra_headers); | |
| 166 | |
| 167 if (post_data) { | |
| 168 std::vector<uint8> http_body_vector; | |
| 169 base::android::JavaByteArrayToByteVector(env, post_data, &http_body_vector); | |
| 170 params.browser_initiated_post_data = | |
| 171 base::RefCountedBytes::TakeVector(&http_body_vector); | |
| 172 } | |
| 173 | |
| 174 if (base_url_for_data_url) { | |
| 175 params.base_url_for_data_url = | |
| 176 GURL(ConvertJavaStringToUTF8(env, base_url_for_data_url)); | |
| 177 } | |
| 178 | |
| 179 if (virtual_url_for_data_url) { | |
| 180 params.virtual_url_for_data_url = | |
| 181 GURL(ConvertJavaStringToUTF8(env, virtual_url_for_data_url)); | |
| 182 } | |
| 183 | |
| 184 params.can_load_local_resources = can_load_local_resources; | |
| 185 if (j_referrer_url) { | |
| 186 params.referrer = content::Referrer( | |
| 187 GURL(ConvertJavaStringToUTF8(env, j_referrer_url)), | |
| 188 static_cast<blink::WebReferrerPolicy>(referrer_policy)); | |
| 189 } | |
| 190 | |
| 191 params.is_renderer_initiated = is_renderer_initiated; | |
| 192 | |
| 193 navigation_controller_->LoadURLWithParams(params); | |
| 194 } | |
| 195 | |
| 196 void NavigationControllerAndroid::ClearHistory(JNIEnv* env, jobject obj) { | |
| 197 // TODO(creis): Do callers of this need to know if it fails? | |
| 198 if (navigation_controller_->CanPruneAllButLastCommitted()) | |
| 199 navigation_controller_->PruneAllButLastCommitted(); | |
| 200 } | |
| 201 | |
| 202 jint NavigationControllerAndroid::GetNavigationHistory( | |
| 203 JNIEnv* env, | |
| 204 jobject obj, | |
| 205 jobject history) { | |
| 206 // Iterate through navigation entries to populate the list | |
| 207 int count = navigation_controller_->GetEntryCount(); | |
| 208 for (int i = 0; i < count; ++i) { | |
| 209 AddNavigationEntryToHistory( | |
| 210 env, obj, history, navigation_controller_->GetEntryAtIndex(i), i); | |
| 211 } | |
| 212 | |
| 213 return navigation_controller_->GetCurrentEntryIndex(); | |
| 214 } | |
| 215 | |
| 216 void NavigationControllerAndroid::GetDirectedNavigationHistory( | |
| 217 JNIEnv* env, | |
| 218 jobject obj, | |
| 219 jobject history, | |
| 220 jboolean is_forward, | |
| 221 jint max_entries) { | |
| 222 // Iterate through navigation entries to populate the list | |
| 223 int count = navigation_controller_->GetEntryCount(); | |
| 224 int num_added = 0; | |
| 225 int increment_value = is_forward ? 1 : -1; | |
| 226 for (int i = navigation_controller_->GetCurrentEntryIndex() + increment_value; | |
| 227 i >= 0 && i < count; | |
| 228 i += increment_value) { | |
| 229 if (num_added >= max_entries) | |
| 230 break; | |
| 231 | |
| 232 AddNavigationEntryToHistory( | |
| 233 env, obj, history, navigation_controller_->GetEntryAtIndex(i), i); | |
| 234 num_added++; | |
| 235 } | |
| 236 } | |
| 237 | |
| 238 ScopedJavaLocalRef<jstring> | |
| 239 NavigationControllerAndroid::GetOriginalUrlForActiveNavigationEntry( | |
| 240 JNIEnv* env, | |
| 241 jobject obj) { | |
| 242 NavigationEntry* entry = navigation_controller_->GetVisibleEntry(); | |
| 243 if (entry == NULL) | |
| 244 return ScopedJavaLocalRef<jstring>(env, NULL); | |
| 245 return ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec()); | |
| 246 } | |
| 247 | |
| 248 void NavigationControllerAndroid::ClearSslPreferences( | |
| 249 JNIEnv* env, | |
| 250 jobject obj) { | |
| 251 SSLHostState* state = SSLHostState::GetFor( | |
| 252 navigation_controller_->GetBrowserContext()); | |
| 253 state->Clear(); | |
| 254 } | |
| 255 | |
| 256 bool NavigationControllerAndroid::GetUseDesktopUserAgent( | |
| 257 JNIEnv* env, | |
| 258 jobject obj) { | |
| 259 NavigationEntry* entry = navigation_controller_->GetVisibleEntry(); | |
| 260 return entry && entry->GetIsOverridingUserAgent(); | |
| 261 } | |
| 262 | |
| 263 void NavigationControllerAndroid::SetUseDesktopUserAgent( | |
| 264 JNIEnv* env, | |
| 265 jobject obj, | |
| 266 jboolean enabled, | |
| 267 jboolean reload_on_state_change) { | |
| 268 if (GetUseDesktopUserAgent(env, obj) == enabled) | |
| 269 return; | |
| 270 | |
| 271 // Make sure the navigation entry actually exists. | |
| 272 NavigationEntry* entry = navigation_controller_->GetVisibleEntry(); | |
| 273 if (!entry) | |
| 274 return; | |
| 275 | |
| 276 // Set the flag in the NavigationEntry. | |
| 277 entry->SetIsOverridingUserAgent(enabled); | |
| 278 | |
| 279 // Send the override to the renderer. | |
| 280 if (reload_on_state_change) { | |
| 281 // Reloading the page will send the override down as part of the | |
| 282 // navigation IPC message. | |
| 283 navigation_controller_->ReloadOriginalRequestURL(false); | |
| 284 } | |
| 285 } | |
| 286 | |
| 104 } // namespace content | 287 } // namespace content |
| OLD | NEW |