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

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

Issue 2327083002: Ntp: restore scroll position. (Closed)
Patch Set: Adrress review comments from clamy. Created 4 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 <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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 370 }
358 } 371 }
359 372
360 base::android::ScopedJavaLocalRef<jobject> 373 base::android::ScopedJavaLocalRef<jobject>
361 NavigationControllerAndroid::GetEntryAtIndex(JNIEnv* env, 374 NavigationControllerAndroid::GetEntryAtIndex(JNIEnv* env,
362 const JavaParamRef<jobject>& obj, 375 const JavaParamRef<jobject>& obj,
363 int index) { 376 int index) {
364 if (index < 0 || index >= navigation_controller_->GetEntryCount()) 377 if (index < 0 || index >= navigation_controller_->GetEntryCount())
365 return base::android::ScopedJavaLocalRef<jobject>(); 378 return base::android::ScopedJavaLocalRef<jobject>();
366 379
367 content::NavigationEntry* entry = 380 return CreateJavaNavigationEntry(
368 navigation_controller_->GetEntryAtIndex(index); 381 env, navigation_controller_->GetEntryAtIndex(index), index);
369 return CreateJavaNavigationEntry(env, entry, index);
370 } 382 }
371 383
372 base::android::ScopedJavaLocalRef<jobject> 384 base::android::ScopedJavaLocalRef<jobject>
373 NavigationControllerAndroid::GetPendingEntry(JNIEnv* env, 385 NavigationControllerAndroid::GetPendingEntry(JNIEnv* env,
374 const JavaParamRef<jobject>& obj) { 386 const JavaParamRef<jobject>& obj) {
375 content::NavigationEntry* entry = navigation_controller_->GetPendingEntry(); 387 content::NavigationEntryImpl* entry =
388 navigation_controller_->GetPendingEntry();
376 389
377 if (!entry) 390 if (!entry)
378 return base::android::ScopedJavaLocalRef<jobject>(); 391 return base::android::ScopedJavaLocalRef<jobject>();
379 392
380 return CreateJavaNavigationEntry( 393 return CreateJavaNavigationEntry(
381 env, entry, navigation_controller_->GetPendingEntryIndex()); 394 env, entry, navigation_controller_->GetPendingEntryIndex());
382 } 395 }
383 396
384 jint NavigationControllerAndroid::GetLastCommittedEntryIndex( 397 jint NavigationControllerAndroid::GetLastCommittedEntryIndex(
385 JNIEnv* env, 398 JNIEnv* env,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 JNIEnv* env, 433 JNIEnv* env,
421 const JavaParamRef<jobject>& obj, 434 const JavaParamRef<jobject>& obj,
422 jlong source_navigation_controller_android, 435 jlong source_navigation_controller_android,
423 jboolean replace_entry) { 436 jboolean replace_entry) {
424 navigation_controller_->CopyStateFromAndPrune( 437 navigation_controller_->CopyStateFromAndPrune(
425 reinterpret_cast<NavigationControllerAndroid*>( 438 reinterpret_cast<NavigationControllerAndroid*>(
426 source_navigation_controller_android)->navigation_controller_, 439 source_navigation_controller_android)->navigation_controller_,
427 replace_entry); 440 replace_entry);
428 } 441 }
429 442
443 void NavigationControllerAndroid::SetEntryExtraData(
444 JNIEnv* env,
445 const JavaParamRef<jobject>& obj,
446 jint index,
447 const JavaParamRef<jstring>& jkey,
448 const JavaParamRef<jstring>& jvalue) {
449 if (index < 0 || index >= navigation_controller_->GetEntryCount())
450 return;
451
452 std::string key = base::android::ConvertJavaStringToUTF8(env, jkey);
453 base::string16 value = base::android::ConvertJavaStringToUTF16(env, jvalue);
454 navigation_controller_->GetEntryAtIndex(index)->SetExtraData(key, value);
455 }
456
430 } // namespace content 457 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698