Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: content/browser/frame_host/navigation_controller_android.cc

Issue 577353002: [Android] Expose GetPendingEntry from NavigationController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Comments Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 content::NavigationEntry* entry,
28 content::NavigationEntry* entry, 28 int index) {
29 int index) { 29 DCHECK(entry);
30
30 // Get the details of the current entry 31 // Get the details of the current entry
31 ScopedJavaLocalRef<jstring> j_url( 32 ScopedJavaLocalRef<jstring> j_url(
32 ConvertUTF8ToJavaString(env, entry->GetURL().spec())); 33 ConvertUTF8ToJavaString(env, entry->GetURL().spec()));
33 ScopedJavaLocalRef<jstring> j_virtual_url( 34 ScopedJavaLocalRef<jstring> j_virtual_url(
34 ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec())); 35 ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec()));
35 ScopedJavaLocalRef<jstring> j_original_url( 36 ScopedJavaLocalRef<jstring> j_original_url(
36 ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec())); 37 ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec()));
37 ScopedJavaLocalRef<jstring> j_title( 38 ScopedJavaLocalRef<jstring> j_title(
38 ConvertUTF16ToJavaString(env, entry->GetTitle())); 39 ConvertUTF16ToJavaString(env, entry->GetTitle()));
39 ScopedJavaLocalRef<jobject> j_bitmap; 40 ScopedJavaLocalRef<jobject> j_bitmap;
40 const content::FaviconStatus& status = entry->GetFavicon(); 41 const content::FaviconStatus& status = entry->GetFavicon();
41 if (status.valid && status.image.ToSkBitmap()->getSize() > 0) 42 if (status.valid && status.image.ToSkBitmap()->getSize() > 0)
42 j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap()); 43 j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap());
43 44
44 // Add the item to the list 45 return content::Java_NavigationControllerImpl_createNavigationEntry(
45 content::Java_NavigationControllerImpl_addToNavigationHistory(
46 env, 46 env,
47 obj,
48 history,
49 index, 47 index,
50 j_url.obj(), 48 j_url.obj(),
51 j_virtual_url.obj(), 49 j_virtual_url.obj(),
52 j_original_url.obj(), 50 j_original_url.obj(),
53 j_title.obj(), 51 j_title.obj(),
54 j_bitmap.obj()); 52 j_bitmap.obj());
55 } 53 }
56 54
55 static void AddNavigationEntryToHistory(JNIEnv* env,
56 jobject history,
57 content::NavigationEntry* entry,
58 int index) {
59 content::Java_NavigationControllerImpl_addToNavigationHistory(
60 env,
61 history,
62 CreateJavaNavigationEntry(env, entry, index).obj());
63 }
64
57 } // namespace 65 } // namespace
58 66
59 namespace content { 67 namespace content {
60 68
61 // static 69 // static
62 bool NavigationControllerAndroid::Register(JNIEnv* env) { 70 bool NavigationControllerAndroid::Register(JNIEnv* env) {
63 return RegisterNativesImpl(env); 71 return RegisterNativesImpl(env);
64 } 72 }
65 73
66 NavigationControllerAndroid::NavigationControllerAndroid( 74 NavigationControllerAndroid::NavigationControllerAndroid(
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 navigation_controller_->PruneAllButLastCommitted(); 217 navigation_controller_->PruneAllButLastCommitted();
210 } 218 }
211 219
212 jint NavigationControllerAndroid::GetNavigationHistory(JNIEnv* env, 220 jint NavigationControllerAndroid::GetNavigationHistory(JNIEnv* env,
213 jobject obj, 221 jobject obj,
214 jobject history) { 222 jobject history) {
215 // Iterate through navigation entries to populate the list 223 // Iterate through navigation entries to populate the list
216 int count = navigation_controller_->GetEntryCount(); 224 int count = navigation_controller_->GetEntryCount();
217 for (int i = 0; i < count; ++i) { 225 for (int i = 0; i < count; ++i) {
218 AddNavigationEntryToHistory( 226 AddNavigationEntryToHistory(
219 env, obj, history, navigation_controller_->GetEntryAtIndex(i), i); 227 env, history, navigation_controller_->GetEntryAtIndex(i), i);
220 } 228 }
221 229
222 return navigation_controller_->GetCurrentEntryIndex(); 230 return navigation_controller_->GetCurrentEntryIndex();
223 } 231 }
224 232
225 void NavigationControllerAndroid::GetDirectedNavigationHistory( 233 void NavigationControllerAndroid::GetDirectedNavigationHistory(
226 JNIEnv* env, 234 JNIEnv* env,
227 jobject obj, 235 jobject obj,
228 jobject history, 236 jobject history,
229 jboolean is_forward, 237 jboolean is_forward,
230 jint max_entries) { 238 jint max_entries) {
231 // Iterate through navigation entries to populate the list 239 // Iterate through navigation entries to populate the list
232 int count = navigation_controller_->GetEntryCount(); 240 int count = navigation_controller_->GetEntryCount();
233 int num_added = 0; 241 int num_added = 0;
234 int increment_value = is_forward ? 1 : -1; 242 int increment_value = is_forward ? 1 : -1;
235 for (int i = navigation_controller_->GetCurrentEntryIndex() + increment_value; 243 for (int i = navigation_controller_->GetCurrentEntryIndex() + increment_value;
236 i >= 0 && i < count; 244 i >= 0 && i < count;
237 i += increment_value) { 245 i += increment_value) {
238 if (num_added >= max_entries) 246 if (num_added >= max_entries)
239 break; 247 break;
240 248
241 AddNavigationEntryToHistory( 249 AddNavigationEntryToHistory(
242 env, obj, history, navigation_controller_->GetEntryAtIndex(i), i); 250 env, history, navigation_controller_->GetEntryAtIndex(i), i);
243 num_added++; 251 num_added++;
244 } 252 }
245 } 253 }
246 254
247 ScopedJavaLocalRef<jstring> 255 ScopedJavaLocalRef<jstring>
248 NavigationControllerAndroid::GetOriginalUrlForVisibleNavigationEntry( 256 NavigationControllerAndroid::GetOriginalUrlForVisibleNavigationEntry(
249 JNIEnv* env, 257 JNIEnv* env,
250 jobject obj) { 258 jobject obj) {
251 NavigationEntry* entry = navigation_controller_->GetVisibleEntry(); 259 NavigationEntry* entry = navigation_controller_->GetVisibleEntry();
252 if (entry == NULL) 260 if (entry == NULL)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 entry->SetIsOverridingUserAgent(enabled); 293 entry->SetIsOverridingUserAgent(enabled);
286 294
287 // Send the override to the renderer. 295 // Send the override to the renderer.
288 if (reload_on_state_change) { 296 if (reload_on_state_change) {
289 // Reloading the page will send the override down as part of the 297 // Reloading the page will send the override down as part of the
290 // navigation IPC message. 298 // navigation IPC message.
291 navigation_controller_->ReloadOriginalRequestURL(false); 299 navigation_controller_->ReloadOriginalRequestURL(false);
292 } 300 }
293 } 301 }
294 302
303 base::android::ScopedJavaLocalRef<jobject>
304 NavigationControllerAndroid::GetPendingEntry(JNIEnv* env, jobject obj) {
305 content::NavigationEntry* entry = navigation_controller_->GetPendingEntry();
306
307 if (!entry)
308 return base::android::ScopedJavaLocalRef<jobject>();
309
310 return CreateJavaNavigationEntry(
311 env, entry, navigation_controller_->GetPendingEntryIndex());
312 }
313
295 } // namespace content 314 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698