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

Side by Side Diff: ios/chrome/browser/tabs/tab_model.mm

Issue 2766413004: [ios] Change API to inform WebStateList of opener-opened relationship. (Closed)
Patch Set: Address comments. Created 3 years, 9 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
« no previous file with comments | « no previous file | ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 #import "ios/chrome/browser/tabs/tab_model.h" 5 #import "ios/chrome/browser/tabs/tab_model.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 27 matching lines...) Expand all
38 #import "ios/chrome/browser/tabs/tab_model_observers_bridge.h" 38 #import "ios/chrome/browser/tabs/tab_model_observers_bridge.h"
39 #import "ios/chrome/browser/tabs/tab_model_selected_tab_observer.h" 39 #import "ios/chrome/browser/tabs/tab_model_selected_tab_observer.h"
40 #import "ios/chrome/browser/tabs/tab_model_synced_window_delegate.h" 40 #import "ios/chrome/browser/tabs/tab_model_synced_window_delegate.h"
41 #import "ios/chrome/browser/tabs/tab_model_web_state_list_delegate.h" 41 #import "ios/chrome/browser/tabs/tab_model_web_state_list_delegate.h"
42 #import "ios/chrome/browser/tabs/tab_parenting_observer.h" 42 #import "ios/chrome/browser/tabs/tab_parenting_observer.h"
43 #import "ios/chrome/browser/xcallback_parameters.h" 43 #import "ios/chrome/browser/xcallback_parameters.h"
44 #import "ios/shared/chrome/browser/tabs/web_state_list.h" 44 #import "ios/shared/chrome/browser/tabs/web_state_list.h"
45 #import "ios/shared/chrome/browser/tabs/web_state_list_fast_enumeration_helper.h " 45 #import "ios/shared/chrome/browser/tabs/web_state_list_fast_enumeration_helper.h "
46 #import "ios/shared/chrome/browser/tabs/web_state_list_metrics_observer.h" 46 #import "ios/shared/chrome/browser/tabs/web_state_list_metrics_observer.h"
47 #import "ios/shared/chrome/browser/tabs/web_state_list_observer.h" 47 #import "ios/shared/chrome/browser/tabs/web_state_list_observer.h"
48 #import "ios/shared/chrome/browser/tabs/web_state_opener.h"
48 #import "ios/web/navigation/crw_session_certificate_policy_manager.h" 49 #import "ios/web/navigation/crw_session_certificate_policy_manager.h"
49 #import "ios/web/navigation/crw_session_controller.h" 50 #import "ios/web/navigation/crw_session_controller.h"
50 #include "ios/web/public/browser_state.h" 51 #include "ios/web/public/browser_state.h"
51 #include "ios/web/public/certificate_policy_cache.h" 52 #include "ios/web/public/certificate_policy_cache.h"
52 #include "ios/web/public/navigation_item.h" 53 #include "ios/web/public/navigation_item.h"
53 #import "ios/web/public/navigation_manager.h" 54 #import "ios/web/public/navigation_manager.h"
54 #include "ios/web/public/web_thread.h" 55 #include "ios/web/public/web_thread.h"
55 #import "ios/web/web_state/ui/crw_web_controller.h" 56 #import "ios/web/web_state/ui/crw_web_controller.h"
56 #import "ios/web/web_state/web_state_impl.h" 57 #import "ios/web/web_state/web_state_impl.h"
57 #include "url/gurl.h" 58 #include "url/gurl.h"
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 439
439 DCHECK_GE(index, 0); 440 DCHECK_GE(index, 0);
440 return [self tabAtIndex:static_cast<NSUInteger>(index)]; 441 return [self tabAtIndex:static_cast<NSUInteger>(index)];
441 } 442 }
442 443
443 - (Tab*)openerOfTab:(Tab*)tab { 444 - (Tab*)openerOfTab:(Tab*)tab {
444 int index = _webStateList->GetIndexOfWebState(tab.webState); 445 int index = _webStateList->GetIndexOfWebState(tab.webState);
445 if (index == WebStateList::kInvalidIndex) 446 if (index == WebStateList::kInvalidIndex)
446 return nil; 447 return nil;
447 448
448 web::WebState* opener = _webStateList->GetOpenerOfWebStateAt(index); 449 WebStateOpener opener = _webStateList->GetOpenerOfWebStateAt(index);
449 return opener ? LegacyTabHelper::GetTabForWebState(opener) : nil; 450 return opener.opener ? LegacyTabHelper::GetTabForWebState(opener.opener)
451 : nil;
450 } 452 }
451 453
452 - (Tab*)insertTabWithURL:(const GURL&)URL 454 - (Tab*)insertTabWithURL:(const GURL&)URL
453 referrer:(const web::Referrer&)referrer 455 referrer:(const web::Referrer&)referrer
454 transition:(ui::PageTransition)transition 456 transition:(ui::PageTransition)transition
455 opener:(Tab*)parentTab 457 opener:(Tab*)parentTab
456 openedByDOM:(BOOL)openedByDOM 458 openedByDOM:(BOOL)openedByDOM
457 atIndex:(NSUInteger)index 459 atIndex:(NSUInteger)index
458 inBackground:(BOOL)inBackground { 460 inBackground:(BOOL)inBackground {
459 web::NavigationManager::WebLoadParams params(URL); 461 web::NavigationManager::WebLoadParams params(URL);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 521
520 - (void)insertTab:(Tab*)tab 522 - (void)insertTab:(Tab*)tab
521 atIndex:(NSUInteger)index 523 atIndex:(NSUInteger)index
522 opener:(Tab*)parentTab 524 opener:(Tab*)parentTab
523 transition:(ui::PageTransition)transition { 525 transition:(ui::PageTransition)transition {
524 DCHECK(tab); 526 DCHECK(tab);
525 DCHECK(![_tabRetainer containsObject:tab]); 527 DCHECK(![_tabRetainer containsObject:tab]);
526 528
527 [_tabRetainer addObject:tab]; 529 [_tabRetainer addObject:tab];
528 if (index == TabModelConstants::kTabPositionAutomatically) { 530 if (index == TabModelConstants::kTabPositionAutomatically) {
529 _webStateList->AppendWebState(transition, tab.webState, parentTab.webState); 531 _webStateList->AppendWebState(
532 transition, tab.webState,
533 WebStateOpener(parentTab.webState, tab.openerNavigationIndex));
530 } else { 534 } else {
531 DCHECK_LE(index, static_cast<NSUInteger>(INT_MAX)); 535 DCHECK_LE(index, static_cast<NSUInteger>(INT_MAX));
532 const int insertion_index = static_cast<int>(index); 536 const int insertion_index = static_cast<int>(index);
533 _webStateList->InsertWebState(insertion_index, tab.webState, 537 _webStateList->InsertWebState(insertion_index, tab.webState);
534 parentTab.webState); 538 if (parentTab.webState) {
539 _webStateList->SetOpenerOfWebStateAt(
540 insertion_index,
541 WebStateOpener(parentTab.webState, tab.openerNavigationIndex));
542 }
535 } 543 }
536 544
537 // Persist the session due to a new tab being inserted. If this is a 545 // Persist the session due to a new tab being inserted. If this is a
538 // background tab (will not become active), saving now will capture the 546 // background tab (will not become active), saving now will capture the
539 // state properly. If it does eventually become active, another save will 547 // state properly. If it does eventually become active, another save will
540 // be triggered to properly capture the end result. 548 // be triggered to properly capture the end result.
541 [self saveSessionImmediately:NO]; 549 [self saveSessionImmediately:NO];
542 } 550 }
543 551
544 - (void)insertTab:(Tab*)tab atIndex:(NSUInteger)index opener:(Tab*)parentTab { 552 - (void)insertTab:(Tab*)tab atIndex:(NSUInteger)index opener:(Tab*)parentTab {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 [_tabRetainer removeObject:oldTab]; 587 [_tabRetainer removeObject:oldTab];
580 [_tabRetainer addObject:newTab]; 588 [_tabRetainer addObject:newTab];
581 [newTab setParentTabModel:self]; 589 [newTab setParentTabModel:self];
582 590
583 // The WebState is owned by the associated Tab, so it is safe to ignore 591 // The WebState is owned by the associated Tab, so it is safe to ignore
584 // the result and won't cause a memory leak. Once the ownership is moved 592 // the result and won't cause a memory leak. Once the ownership is moved
585 // to WebStateList, this function will return a std::unique_ptr<> and the 593 // to WebStateList, this function will return a std::unique_ptr<> and the
586 // object destroyed as expected, so it will fine to ignore the result then 594 // object destroyed as expected, so it will fine to ignore the result then
587 // too. See http://crbug.com/546222 for progress of changing the ownership 595 // too. See http://crbug.com/546222 for progress of changing the ownership
588 // of the WebStates. 596 // of the WebStates.
589 ignore_result(_webStateList->ReplaceWebStateAt( 597 ignore_result(_webStateList->ReplaceWebStateAt(index, newTab.webState));
590 index, newTab.webState, GetOpenerForTab(self, newTab).webState)); 598
599 Tab* parentTab = GetOpenerForTab(self, newTab);
600 if (parentTab) {
601 _webStateList->SetOpenerOfWebStateAt(
602 index,
603 WebStateOpener(parentTab.webState, newTab.openerNavigationIndex));
604 }
591 605
592 [oldTab setParentTabModel:nil]; 606 [oldTab setParentTabModel:nil];
593 [oldTab close]; 607 [oldTab close];
594 } 608 }
595 609
596 - (void)closeTabAtIndex:(NSUInteger)index { 610 - (void)closeTabAtIndex:(NSUInteger)index {
597 DCHECK(index < self.count); 611 DCHECK(index < self.count);
598 [self closeTab:[self tabAtIndex:index]]; 612 [self closeTab:[self tabAtIndex:index]];
599 } 613 }
600 614
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 891
878 // Fix openers now that all Tabs have been restored. Only look for an opener 892 // Fix openers now that all Tabs have been restored. Only look for an opener
879 // Tab in the newly restored Tabs and not in the already open Tabs. 893 // Tab in the newly restored Tabs and not in the already open Tabs.
880 for (int index = oldCount; index < _webStateList->count(); ++index) { 894 for (int index = oldCount; index < _webStateList->count(); ++index) {
881 DCHECK_GE(index, oldCount); 895 DCHECK_GE(index, oldCount);
882 NSUInteger tabIndex = static_cast<NSUInteger>(index - oldCount); 896 NSUInteger tabIndex = static_cast<NSUInteger>(index - oldCount);
883 Tab* tab = [restoredTabs objectAtIndex:tabIndex]; 897 Tab* tab = [restoredTabs objectAtIndex:tabIndex];
884 Tab* opener = GetOpenerForTab(restoredTabs.get(), tab); 898 Tab* opener = GetOpenerForTab(restoredTabs.get(), tab);
885 if (opener) { 899 if (opener) {
886 DCHECK(opener.webState); 900 DCHECK(opener.webState);
887 _webStateList->SetOpenerOfWebStateAt(index, opener.webState); 901 _webStateList->SetOpenerOfWebStateAt(
902 index, WebStateOpener(opener.webState, tab.openerNavigationIndex));
888 } 903 }
889 } 904 }
890 905
891 // Update the selected tab if there was a selected Tab in the saved session. 906 // Update the selected tab if there was a selected Tab in the saved session.
892 if (window.selectedIndex != NSNotFound) { 907 if (window.selectedIndex != NSNotFound) {
893 NSUInteger selectedIndex = window.selectedIndex + oldCount; 908 NSUInteger selectedIndex = window.selectedIndex + oldCount;
894 DCHECK_LT(selectedIndex, self.count); 909 DCHECK_LT(selectedIndex, self.count);
895 DCHECK([self tabAtIndex:selectedIndex]); 910 DCHECK([self tabAtIndex:selectedIndex]);
896 911
897 if (persistState && self.currentTab) 912 if (persistState && self.currentTab)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 } 974 }
960 975
961 // Called when UIApplicationWillEnterForegroundNotification is received. 976 // Called when UIApplicationWillEnterForegroundNotification is received.
962 - (void)applicationWillEnterForeground:(NSNotification*)notify { 977 - (void)applicationWillEnterForeground:(NSNotification*)notify {
963 if (_tabUsageRecorder) { 978 if (_tabUsageRecorder) {
964 _tabUsageRecorder->AppWillEnterForeground(); 979 _tabUsageRecorder->AppWillEnterForeground();
965 } 980 }
966 } 981 }
967 982
968 @end 983 @end
OLDNEW
« no previous file with comments | « no previous file | ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698