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