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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 if (*current_entry_index < 0 || | 279 if (*current_entry_index < 0 || |
280 *current_entry_index >= static_cast<int>(navigations->size())) | 280 *current_entry_index >= static_cast<int>(navigations->size())) |
281 return false; | 281 return false; |
282 | 282 |
283 return true; | 283 return true; |
284 } | 284 } |
285 | 285 |
286 }; // anonymous namespace | 286 }; // anonymous namespace |
287 | 287 |
288 ScopedJavaLocalRef<jobject> WebContentsState::GetContentsStateAsByteBuffer( | 288 ScopedJavaLocalRef<jobject> WebContentsState::GetContentsStateAsByteBuffer( |
289 JNIEnv* env, TabAndroid* tab) { | 289 JNIEnv* env, |
290 TabAndroid* tab) { | |
290 Profile* profile = tab->GetProfile(); | 291 Profile* profile = tab->GetProfile(); |
291 if (!profile) | 292 if (!profile) |
292 return ScopedJavaLocalRef<jobject>(); | 293 return ScopedJavaLocalRef<jobject>(); |
293 | 294 |
294 content::NavigationController& controller = | 295 content::NavigationController& controller = |
295 tab->web_contents()->GetController(); | 296 tab->web_contents()->GetController(); |
296 const int pending_index = controller.GetPendingEntryIndex(); | 297 const int entry_count = controller.GetEntryCount(); |
297 int entry_count = controller.GetEntryCount(); | |
298 if (entry_count == 0 && pending_index == 0) | |
Charlie Reis
2017/04/11 23:31:08
Right. pending_index should be -1 if entry_count
| |
299 entry_count++; | |
300 | |
301 if (entry_count == 0) | 298 if (entry_count == 0) |
302 return ScopedJavaLocalRef<jobject>(); | 299 return ScopedJavaLocalRef<jobject>(); |
303 | 300 |
304 int current_entry = controller.GetLastCommittedEntryIndex(); | |
305 if (current_entry == -1 && entry_count > 0) | |
306 current_entry = 0; | |
Charlie Reis
2017/04/11 23:31:08
Yeah, I think this was in response to the entry_co
| |
307 | |
308 std::vector<content::NavigationEntry*> navigations(entry_count); | 301 std::vector<content::NavigationEntry*> navigations(entry_count); |
309 for (int i = 0; i < entry_count; ++i) { | 302 for (int i = 0; i < entry_count; ++i) { |
310 content::NavigationEntry* entry = (i == pending_index) ? | 303 navigations[i] = controller.GetEntryAtIndex(i); |
311 controller.GetPendingEntry() : controller.GetEntryAtIndex(i); | |
312 navigations[i] = entry; | |
313 } | 304 } |
314 | 305 |
315 return WebContentsState::WriteNavigationsAsByteBuffer( | 306 return WebContentsState::WriteNavigationsAsByteBuffer( |
316 env, | 307 env, profile->IsOffTheRecord(), navigations, |
317 profile->IsOffTheRecord(), | 308 controller.GetLastCommittedEntryIndex()); |
318 navigations, | |
319 current_entry); | |
320 } | 309 } |
321 | 310 |
322 // Common implementation for GetContentsStateAsByteBuffer() and | 311 // Common implementation for GetContentsStateAsByteBuffer() and |
323 // CreateContentsStateAsByteBuffer(). Does not assume ownership of the | 312 // CreateContentsStateAsByteBuffer(). Does not assume ownership of the |
324 // navigations. | 313 // navigations. |
325 ScopedJavaLocalRef<jobject> WebContentsState::WriteNavigationsAsByteBuffer( | 314 ScopedJavaLocalRef<jobject> WebContentsState::WriteNavigationsAsByteBuffer( |
326 JNIEnv* env, | 315 JNIEnv* env, |
327 bool is_off_the_record, | 316 bool is_off_the_record, |
328 const std::vector<content::NavigationEntry*>& navigations, | 317 const std::vector<content::NavigationEntry*>& navigations, |
329 int current_entry) { | 318 int current_entry) { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 std::unique_ptr<WebContents> web_contents(WebContents::FromJavaWebContents( | 561 std::unique_ptr<WebContents> web_contents(WebContents::FromJavaWebContents( |
573 WebContentsState::RestoreContentsFromByteBuffer( | 562 WebContentsState::RestoreContentsFromByteBuffer( |
574 env, clazz, state, saved_state_version, true))); | 563 env, clazz, state, saved_state_version, true))); |
575 if (web_contents.get()) | 564 if (web_contents.get()) |
576 TabAndroid::CreateHistoricalTabFromContents(web_contents.get()); | 565 TabAndroid::CreateHistoricalTabFromContents(web_contents.get()); |
577 } | 566 } |
578 | 567 |
579 bool RegisterTabState(JNIEnv* env) { | 568 bool RegisterTabState(JNIEnv* env) { |
580 return RegisterNativesImpl(env); | 569 return RegisterNativesImpl(env); |
581 } | 570 } |
OLD | NEW |