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

Side by Side Diff: ios/chrome/browser/ui/browser_view_controller.mm

Issue 2775623002: [ios] WebStateList owns all WebState it manages. (Closed)
Patch Set: Fix gn check Created 3 years, 8 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 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/ui/browser_view_controller.h" 5 #import "ios/chrome/browser/ui/browser_view_controller.h"
6 6
7 #import <AssetsLibrary/AssetsLibrary.h> 7 #import <AssetsLibrary/AssetsLibrary.h>
8 #import <MobileCoreServices/MobileCoreServices.h> 8 #import <MobileCoreServices/MobileCoreServices.h>
9 #import <PassKit/PassKit.h> 9 #import <PassKit/PassKit.h>
10 #import <Photos/Photos.h> 10 #import <Photos/Photos.h>
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 #include "ios/chrome/grit/ios_strings.h" 164 #include "ios/chrome/grit/ios_strings.h"
165 #import "ios/net/request_tracker.h" 165 #import "ios/net/request_tracker.h"
166 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" 166 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
167 #include "ios/public/provider/chrome/browser/ui/app_rating_prompt.h" 167 #include "ios/public/provider/chrome/browser/ui/app_rating_prompt.h"
168 #include "ios/public/provider/chrome/browser/ui/default_ios_web_view_factory.h" 168 #include "ios/public/provider/chrome/browser/ui/default_ios_web_view_factory.h"
169 #import "ios/public/provider/chrome/browser/voice/voice_search_bar.h" 169 #import "ios/public/provider/chrome/browser/voice/voice_search_bar.h"
170 #import "ios/public/provider/chrome/browser/voice/voice_search_bar_owner.h" 170 #import "ios/public/provider/chrome/browser/voice/voice_search_bar_owner.h"
171 #include "ios/public/provider/chrome/browser/voice/voice_search_controller.h" 171 #include "ios/public/provider/chrome/browser/voice/voice_search_controller.h"
172 #include "ios/public/provider/chrome/browser/voice/voice_search_controller_deleg ate.h" 172 #include "ios/public/provider/chrome/browser/voice/voice_search_controller_deleg ate.h"
173 #include "ios/public/provider/chrome/browser/voice/voice_search_provider.h" 173 #include "ios/public/provider/chrome/browser/voice/voice_search_provider.h"
174 #import "ios/shared/chrome/browser/tabs/web_state_list.h"
175 #import "ios/shared/chrome/browser/tabs/web_state_opener.h"
174 #include "ios/web/public/active_state_manager.h" 176 #include "ios/web/public/active_state_manager.h"
175 #include "ios/web/public/navigation_item.h" 177 #include "ios/web/public/navigation_item.h"
176 #import "ios/web/public/navigation_manager.h" 178 #import "ios/web/public/navigation_manager.h"
177 #include "ios/web/public/referrer_util.h" 179 #include "ios/web/public/referrer_util.h"
178 #include "ios/web/public/ssl_status.h" 180 #include "ios/web/public/ssl_status.h"
179 #include "ios/web/public/url_scheme_util.h" 181 #include "ios/web/public/url_scheme_util.h"
180 #include "ios/web/public/user_agent.h" 182 #include "ios/web/public/user_agent.h"
181 #include "ios/web/public/web_client.h" 183 #include "ios/web/public/web_client.h"
182 #import "ios/web/public/web_state/context_menu_params.h" 184 #import "ios/web/public/web_state/context_menu_params.h"
183 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" 185 #import "ios/web/public/web_state/ui/crw_native_content_provider.h"
(...skipping 3471 matching lines...) Expand 10 before | Expand all | Expand 10 after
3655 // ending up in the history causign the app to crash at every subsequent 3657 // ending up in the history causign the app to crash at every subsequent
3656 // restart. 3658 // restart.
3657 if (url.host() == kChromeUIBrowserCrashHost) { 3659 if (url.host() == kChromeUIBrowserCrashHost) {
3658 [self induceBrowserCrash]; 3660 [self induceBrowserCrash];
3659 // In debug the app can continue working even after the CHECK. Adding a 3661 // In debug the app can continue working even after the CHECK. Adding a
3660 // return avoids the crash url to be added to the history. 3662 // return avoids the crash url to be added to the history.
3661 return; 3663 return;
3662 } 3664 }
3663 3665
3664 if (url == [_preloadController prerenderedURL]) { 3666 if (url == [_preloadController prerenderedURL]) {
3667 std::unique_ptr<web::WebState> newWebState =
3668 [_preloadController releasePrerenderContents];
3669 DCHECK(newWebState);
3670
3665 Tab* oldTab = [_model currentTab]; 3671 Tab* oldTab = [_model currentTab];
3666 Tab* newTab = [_preloadController releasePrerenderContents]; 3672 Tab* newTab = LegacyTabHelper::GetTabForWebState(newWebState.get());
3667 DCHECK(oldTab); 3673 DCHECK(oldTab);
3668 DCHECK(newTab); 3674 DCHECK(newTab);
3675
3669 bool canPruneItems = 3676 bool canPruneItems =
3670 [newTab navigationManager]->CanPruneAllButLastCommittedItem(); 3677 [newTab navigationManager]->CanPruneAllButLastCommittedItem();
3678
3671 if (oldTab && newTab && canPruneItems) { 3679 if (oldTab && newTab && canPruneItems) {
3672 [oldTab recordStateInHistory]; 3680 [oldTab recordStateInHistory];
3673 [newTab navigationManager]->CopyStateFromAndPrune( 3681 [newTab navigationManager]->CopyStateFromAndPrune(
3674 [oldTab navigationManager]); 3682 [oldTab navigationManager]);
3675 [[newTab nativeAppNavigationController] 3683 [[newTab nativeAppNavigationController]
3676 copyStateFrom:[oldTab nativeAppNavigationController]]; 3684 copyStateFrom:[oldTab nativeAppNavigationController]];
3677 [_model replaceTab:oldTab withTab:newTab]; 3685
3686 [_model webStateList]->ReplaceWebStateAt([_model indexOfTab:oldTab],
3687 std::move(newWebState));
3678 3688
3679 // Set isPrerenderTab to NO after replacing the tab. This will allow the 3689 // Set isPrerenderTab to NO after replacing the tab. This will allow the
3680 // BrowserViewController to detect that a pre-rendered tab is switched in, 3690 // BrowserViewController to detect that a pre-rendered tab is switched in,
3681 // and show the prerendering animation. 3691 // and show the prerendering animation.
3682 newTab.isPrerenderTab = NO; 3692 newTab.isPrerenderTab = NO;
3683 3693
3684 [self tabLoadComplete:newTab withSuccess:newTab.loadFinished]; 3694 [self tabLoadComplete:newTab withSuccess:newTab.loadFinished];
3685
3686 return; 3695 return;
3687 } 3696 }
3688 } 3697 }
3689 3698
3690 GURL urlToLoad = url; 3699 GURL urlToLoad = url;
3691 if ([_preloadController hasPrefetchedURL:url]) { 3700 if ([_preloadController hasPrefetchedURL:url]) {
3692 // Prefetched URLs have modified URLs, so load the prefetched version of 3701 // Prefetched URLs have modified URLs, so load the prefetched version of
3693 // |url| instead of the original |url|. 3702 // |url| instead of the original |url|.
3694 urlToLoad = [_preloadController prefetchedURL]; 3703 urlToLoad = [_preloadController prefetchedURL];
3695 } 3704 }
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
4658 [self updateToolbarControlsAlpha:1.0]; 4667 [self updateToolbarControlsAlpha:1.0];
4659 [self updateToolbarBackgroundAlpha:1.0]; 4668 [self updateToolbarBackgroundAlpha:1.0];
4660 [_tabStripController view].alpha = 1.0; 4669 [_tabStripController view].alpha = 1.0;
4661 }; 4670 };
4662 4671
4663 // After the transition animation completes, add the tab to the tab model 4672 // After the transition animation completes, add the tab to the tab model
4664 // (on iPad this triggers the tab strip animation too), then fade out the 4673 // (on iPad this triggers the tab strip animation too), then fade out the
4665 // transitioning panel and remove it. 4674 // transitioning panel and remove it.
4666 void (^completion)(BOOL) = ^(BOOL finished) { 4675 void (^completion)(BOOL) = ^(BOOL finished) {
4667 _contextualSearchMask.alpha = 0; 4676 _contextualSearchMask.alpha = 0;
4668 Tab* newTab = [tabProvider releaseTab]; 4677 std::unique_ptr<web::WebState> webState = [tabProvider releaseWebState];
4669 DCHECK(newTab); 4678 DCHECK(webState);
4670 DCHECK([newTab navigationManager]); 4679 DCHECK(webState->GetNavigationManager());
4671 // Add the new tab to the tab model. 4680
4672 [newTab setParentTabModel:_model]; 4681 Tab* newTab = LegacyTabHelper::GetTabForWebState(webState.get());
4673 // Insert the new tab one after the current tab. 4682 WebStateList* webStateList = [_model webStateList];
4674 Tab* currentTab = [_model currentTab]; 4683
4675 NSUInteger index = [_model indexOfTab:currentTab]; 4684 // Insert the new tab after the current tab.
4676 [_model insertTab:newTab atIndex:index + 1]; 4685 DCHECK_NE(webStateList->active_index(), WebStateList::kInvalidIndex);
4686 DCHECK_NE(webStateList->active_index(), INT_MAX);
4687 int insertion_index = webStateList->active_index() + 1;
4688 webStateList->InsertWebState(insertion_index, std::move(webState));
4689 webStateList->SetOpenerOfWebStateAt(insertion_index,
4690 [tabProvider webStateOpener]);
4677 4691
4678 // Set isPrerenderTab to NO after inserting the tab. This will allow the 4692 // Set isPrerenderTab to NO after inserting the tab. This will allow the
4679 // BrowserViewController to detect that a pre-rendered tab is switched in, 4693 // BrowserViewController to detect that a pre-rendered tab is switched in,
4680 // and show the prerendering animation. This needs to happen before the 4694 // and show the prerendering animation. This needs to happen before the
4681 // tab is made the current tab. 4695 // tab is made the current tab.
4682 // This also enables contextual search (if otherwise applicable) on 4696 // This also enables contextual search (if otherwise applicable) on
4683 // |newTab|. 4697 // |newTab|.
4698
4684 newTab.isPrerenderTab = NO; 4699 newTab.isPrerenderTab = NO;
4685 [_model setCurrentTab:newTab]; 4700 [_model setCurrentTab:newTab];
4686 4701
4687 if (newTab.loadFinished) 4702 if (newTab.loadFinished)
4688 [self tabLoadComplete:newTab withSuccess:YES]; 4703 [self tabLoadComplete:newTab withSuccess:YES];
4689 4704
4690 if (focusInput) { 4705 if (focusInput) {
4691 [_toolbarController focusOmnibox]; 4706 [_toolbarController focusOmnibox];
4692 } 4707 }
4693 _infoBarContainer->RestoreInfobars(); 4708 _infoBarContainer->RestoreInfobars();
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
5124 5139
5125 - (UIView*)voiceSearchButton { 5140 - (UIView*)voiceSearchButton {
5126 return _voiceSearchButton; 5141 return _voiceSearchButton;
5127 } 5142 }
5128 5143
5129 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { 5144 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner {
5130 return [self currentLogoAnimationControllerOwner]; 5145 return [self currentLogoAnimationControllerOwner];
5131 } 5146 }
5132 5147
5133 @end 5148 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/BUILD.gn ('k') | ios/chrome/browser/ui/browser_view_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698