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(); |
297 const int entry_count = controller.GetEntryCount(); | |
298 const int current_index = controller.GetLastCommittedEntryIndex(); | |
296 const int pending_index = controller.GetPendingEntryIndex(); | 299 const int pending_index = controller.GetPendingEntryIndex(); |
297 int entry_count = controller.GetEntryCount(); | 300 DCHECK(current_index < entry_count); |
298 if (entry_count == 0 && pending_index == 0) | 301 DCHECK(pending_index < entry_count); |
299 entry_count++; | |
300 | 302 |
301 if (entry_count == 0) | 303 if (entry_count == 0) |
302 return ScopedJavaLocalRef<jobject>(); | 304 return ScopedJavaLocalRef<jobject>(); |
303 | 305 |
304 int current_entry = controller.GetLastCommittedEntryIndex(); | |
305 if (current_entry == -1 && entry_count > 0) | |
306 current_entry = 0; | |
307 | |
308 std::vector<content::NavigationEntry*> navigations(entry_count); | 306 std::vector<content::NavigationEntry*> navigations(entry_count); |
309 for (int i = 0; i < entry_count; ++i) { | 307 for (int i = 0; i < entry_count; ++i) { |
310 content::NavigationEntry* entry = (i == pending_index) ? | 308 navigations[i] = (i == pending_index) ? controller.GetPendingEntry() |
Eugene But (OOO till 7-30)
2017/04/07 15:21:07
I was under impression that if |i == pending_index
arthursonzogni
2017/04/10 08:16:35
It would have been nice if the code could be simpl
| |
311 controller.GetPendingEntry() : controller.GetEntryAtIndex(i); | 309 : controller.GetEntryAtIndex(i); |
312 navigations[i] = entry; | |
313 } | 310 } |
314 | 311 |
315 return WebContentsState::WriteNavigationsAsByteBuffer( | 312 return WebContentsState::WriteNavigationsAsByteBuffer( |
316 env, | 313 env, profile->IsOffTheRecord(), navigations, current_index); |
317 profile->IsOffTheRecord(), | |
318 navigations, | |
319 current_entry); | |
320 } | 314 } |
321 | 315 |
322 // Common implementation for GetContentsStateAsByteBuffer() and | 316 // Common implementation for GetContentsStateAsByteBuffer() and |
323 // CreateContentsStateAsByteBuffer(). Does not assume ownership of the | 317 // CreateContentsStateAsByteBuffer(). Does not assume ownership of the |
324 // navigations. | 318 // navigations. |
325 ScopedJavaLocalRef<jobject> WebContentsState::WriteNavigationsAsByteBuffer( | 319 ScopedJavaLocalRef<jobject> WebContentsState::WriteNavigationsAsByteBuffer( |
326 JNIEnv* env, | 320 JNIEnv* env, |
327 bool is_off_the_record, | 321 bool is_off_the_record, |
328 const std::vector<content::NavigationEntry*>& navigations, | 322 const std::vector<content::NavigationEntry*>& navigations, |
329 int current_entry) { | 323 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( | 566 std::unique_ptr<WebContents> web_contents(WebContents::FromJavaWebContents( |
573 WebContentsState::RestoreContentsFromByteBuffer( | 567 WebContentsState::RestoreContentsFromByteBuffer( |
574 env, clazz, state, saved_state_version, true))); | 568 env, clazz, state, saved_state_version, true))); |
575 if (web_contents.get()) | 569 if (web_contents.get()) |
576 TabAndroid::CreateHistoricalTabFromContents(web_contents.get()); | 570 TabAndroid::CreateHistoricalTabFromContents(web_contents.get()); |
577 } | 571 } |
578 | 572 |
579 bool RegisterTabState(JNIEnv* env) { | 573 bool RegisterTabState(JNIEnv* env) { |
580 return RegisterNativesImpl(env); | 574 return RegisterNativesImpl(env); |
581 } | 575 } |
OLD | NEW |