| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/android/tab_state.h" | 5 #include "chrome/browser/android/tab_state.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 navigations[0] = entry.get(); | 489 navigations[0] = entry.get(); |
| 490 | 490 |
| 491 return WebContentsState::WriteNavigationsAsByteBuffer(env, | 491 return WebContentsState::WriteNavigationsAsByteBuffer(env, |
| 492 is_off_the_record, | 492 is_off_the_record, |
| 493 navigations, | 493 navigations, |
| 494 0); | 494 0); |
| 495 } | 495 } |
| 496 | 496 |
| 497 // Static JNI methods. | 497 // Static JNI methods. |
| 498 | 498 |
| 499 static void FreeWebContentsStateBuffer(JNIEnv* env, jclass clazz, jobject obj) { | 499 static void FreeWebContentsStateBuffer(JNIEnv* env, |
| 500 const JavaParamRef<jclass>& clazz, |
| 501 const JavaParamRef<jobject>& obj) { |
| 500 void* data = env->GetDirectBufferAddress(obj); | 502 void* data = env->GetDirectBufferAddress(obj); |
| 501 free(data); | 503 free(data); |
| 502 } | 504 } |
| 503 | 505 |
| 504 static ScopedJavaLocalRef<jobject> RestoreContentsFromByteBuffer( | 506 static ScopedJavaLocalRef<jobject> RestoreContentsFromByteBuffer( |
| 505 JNIEnv* env, | 507 JNIEnv* env, |
| 506 jclass clazz, | 508 const JavaParamRef<jclass>& clazz, |
| 507 jobject state, | 509 const JavaParamRef<jobject>& state, |
| 508 jint saved_state_version, | 510 jint saved_state_version, |
| 509 jboolean initially_hidden) { | 511 jboolean initially_hidden) { |
| 510 return WebContentsState::RestoreContentsFromByteBuffer(env, | 512 return WebContentsState::RestoreContentsFromByteBuffer(env, |
| 511 clazz, | 513 clazz, |
| 512 state, | 514 state, |
| 513 saved_state_version, | 515 saved_state_version, |
| 514 initially_hidden); | 516 initially_hidden); |
| 515 } | 517 } |
| 516 | 518 |
| 517 static ScopedJavaLocalRef<jobject> GetContentsStateAsByteBuffer(JNIEnv* env, | 519 static ScopedJavaLocalRef<jobject> GetContentsStateAsByteBuffer( |
| 518 jclass clazz, | 520 JNIEnv* env, |
| 519 jobject jtab) { | 521 const JavaParamRef<jclass>& clazz, |
| 522 const JavaParamRef<jobject>& jtab) { |
| 520 TabAndroid* tab_android = TabAndroid::GetNativeTab(env, jtab); | 523 TabAndroid* tab_android = TabAndroid::GetNativeTab(env, jtab); |
| 521 return WebContentsState::GetContentsStateAsByteBuffer(env, tab_android); | 524 return WebContentsState::GetContentsStateAsByteBuffer(env, tab_android); |
| 522 } | 525 } |
| 523 | 526 |
| 524 static ScopedJavaLocalRef<jobject> CreateSingleNavigationStateAsByteBuffer( | 527 static ScopedJavaLocalRef<jobject> CreateSingleNavigationStateAsByteBuffer( |
| 525 JNIEnv* env, | 528 JNIEnv* env, |
| 526 jclass clazz, | 529 const JavaParamRef<jclass>& clazz, |
| 527 jstring url, | 530 const JavaParamRef<jstring>& url, |
| 528 jstring referrer_url, | 531 const JavaParamRef<jstring>& referrer_url, |
| 529 jint referrer_policy, | 532 jint referrer_policy, |
| 530 jboolean is_off_the_record) { | 533 jboolean is_off_the_record) { |
| 531 return WebContentsState::CreateSingleNavigationStateAsByteBuffer( | 534 return WebContentsState::CreateSingleNavigationStateAsByteBuffer( |
| 532 env, url, referrer_url, referrer_policy, is_off_the_record); | 535 env, url, referrer_url, referrer_policy, is_off_the_record); |
| 533 } | 536 } |
| 534 | 537 |
| 535 static ScopedJavaLocalRef<jstring> GetDisplayTitleFromByteBuffer( | 538 static ScopedJavaLocalRef<jstring> GetDisplayTitleFromByteBuffer( |
| 536 JNIEnv* env, | 539 JNIEnv* env, |
| 537 jclass clazz, | 540 const JavaParamRef<jclass>& clazz, |
| 538 jobject state, | 541 const JavaParamRef<jobject>& state, |
| 539 jint saved_state_version) { | 542 jint saved_state_version) { |
| 540 void* data = env->GetDirectBufferAddress(state); | 543 void* data = env->GetDirectBufferAddress(state); |
| 541 int size = env->GetDirectBufferCapacity(state); | 544 int size = env->GetDirectBufferCapacity(state); |
| 542 | 545 |
| 543 ScopedJavaLocalRef<jstring> result = | 546 ScopedJavaLocalRef<jstring> result = |
| 544 WebContentsState::GetDisplayTitleFromByteBuffer( | 547 WebContentsState::GetDisplayTitleFromByteBuffer( |
| 545 env, data, size, saved_state_version); | 548 env, data, size, saved_state_version); |
| 546 return result; | 549 return result; |
| 547 } | 550 } |
| 548 | 551 |
| 549 static ScopedJavaLocalRef<jstring> GetVirtualUrlFromByteBuffer( | 552 static ScopedJavaLocalRef<jstring> GetVirtualUrlFromByteBuffer( |
| 550 JNIEnv* env, | 553 JNIEnv* env, |
| 551 jclass clazz, | 554 const JavaParamRef<jclass>& clazz, |
| 552 jobject state, | 555 const JavaParamRef<jobject>& state, |
| 553 jint saved_state_version) { | 556 jint saved_state_version) { |
| 554 void* data = env->GetDirectBufferAddress(state); | 557 void* data = env->GetDirectBufferAddress(state); |
| 555 int size = env->GetDirectBufferCapacity(state); | 558 int size = env->GetDirectBufferCapacity(state); |
| 556 ScopedJavaLocalRef<jstring> result = | 559 ScopedJavaLocalRef<jstring> result = |
| 557 WebContentsState::GetVirtualUrlFromByteBuffer( | 560 WebContentsState::GetVirtualUrlFromByteBuffer( |
| 558 env, data, size, saved_state_version); | 561 env, data, size, saved_state_version); |
| 559 return result; | 562 return result; |
| 560 } | 563 } |
| 561 | 564 |
| 562 // Creates a historical tab entry from the serialized tab contents contained | 565 // Creates a historical tab entry from the serialized tab contents contained |
| 563 // within |state|. | 566 // within |state|. |
| 564 static void CreateHistoricalTab(JNIEnv* env, | 567 static void CreateHistoricalTab(JNIEnv* env, |
| 565 jclass clazz, | 568 const JavaParamRef<jclass>& clazz, |
| 566 jobject state, | 569 const JavaParamRef<jobject>& state, |
| 567 jint saved_state_version) { | 570 jint saved_state_version) { |
| 568 scoped_ptr<WebContents> web_contents(WebContents::FromJavaWebContents( | 571 scoped_ptr<WebContents> web_contents(WebContents::FromJavaWebContents( |
| 569 WebContentsState::RestoreContentsFromByteBuffer(env, clazz, state, | 572 WebContentsState::RestoreContentsFromByteBuffer(env, clazz, state, |
| 570 saved_state_version, true) | 573 saved_state_version, true) |
| 571 .obj())); | 574 .obj())); |
| 572 if (web_contents.get()) | 575 if (web_contents.get()) |
| 573 TabAndroid::CreateHistoricalTabFromContents(web_contents.get()); | 576 TabAndroid::CreateHistoricalTabFromContents(web_contents.get()); |
| 574 } | 577 } |
| 575 | 578 |
| 576 bool RegisterTabState(JNIEnv* env) { | 579 bool RegisterTabState(JNIEnv* env) { |
| 577 return RegisterNativesImpl(env); | 580 return RegisterNativesImpl(env); |
| 578 } | 581 } |
| OLD | NEW |