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

Side by Side Diff: ios/chrome/browser/ui/tab_switcher/tab_switcher_controller.mm

Issue 2775623002: [ios] WebStateList owns all WebState it manages. (Closed)
Patch Set: Fix ios_chrome_unittests. 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/tab_switcher/tab_switcher_controller.h" 5 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_controller.h"
6 6
7 #include "base/ios/block_types.h" 7 #include "base/ios/block_types.h"
8 #include "base/ios/weak_nsobject.h" 8 #include "base/ios/weak_nsobject.h"
9 #include "base/mac/scoped_nsobject.h" 9 #include "base/mac/scoped_nsobject.h"
10 #include "base/metrics/user_metrics.h" 10 #include "base/metrics/user_metrics.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_view.h" 43 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_view.h"
44 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h" 44 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h"
45 #import "ios/chrome/browser/ui/toolbar/toolbar_owner.h" 45 #import "ios/chrome/browser/ui/toolbar/toolbar_owner.h"
46 #include "ios/chrome/browser/ui/ui_util.h" 46 #include "ios/chrome/browser/ui/ui_util.h"
47 #import "ios/chrome/browser/ui/uikit_ui_util.h" 47 #import "ios/chrome/browser/ui/uikit_ui_util.h"
48 #include "ios/chrome/grit/ios_strings.h" 48 #include "ios/chrome/grit/ios_strings.h"
49 #include "ios/chrome/grit/ios_theme_resources.h" 49 #include "ios/chrome/grit/ios_theme_resources.h"
50 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" 50 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
51 #import "ios/web/public/navigation_manager.h" 51 #import "ios/web/public/navigation_manager.h"
52 #include "ios/web/public/referrer.h" 52 #include "ios/web/public/referrer.h"
53 #import "ios/web/web_state/ui/crw_web_controller.h" 53 #import "ios/web/web_state/ui/crw_web_controller.h"
Eugene But (OOO till 7-30) 2017/03/28 15:27:18 Could you please remove this import and cleanup io
54 #include "ui/base/l10n/l10n_util.h" 54 #include "ui/base/l10n/l10n_util.h"
55 #include "ui/base/l10n/l10n_util_mac.h" 55 #include "ui/base/l10n/l10n_util_mac.h"
56 56
57 namespace { 57 namespace {
58 58
59 // Offsets for computing the panels' indexes in the TabSwitcherView. 59 // Offsets for computing the panels' indexes in the TabSwitcherView.
60 const int kSignInPromoPanelIndex = 2; 60 const int kSignInPromoPanelIndex = 2;
61 const int kHeaderDistantSessionIndexOffset = 2; 61 const int kHeaderDistantSessionIndexOffset = 2;
62 const int kLocalTabsOffTheRecordPanelIndex = 0; 62 const int kLocalTabsOffTheRecordPanelIndex = 0;
63 const int kLocalTabsOnTheRecordPanelIndex = 1; 63 const int kLocalTabsOnTheRecordPanelIndex = 1;
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 - (void)tabSwitcherDismissWithCurrentSelectedModel { 821 - (void)tabSwitcherDismissWithCurrentSelectedModel {
822 TabModel* model = [self currentSelectedModel]; 822 TabModel* model = [self currentSelectedModel];
823 base::RecordAction(base::UserMetricsAction("MobileTabSwitcherClose")); 823 base::RecordAction(base::UserMetricsAction("MobileTabSwitcherClose"));
824 [self tabSwitcherDismissWithModel:model]; 824 [self tabSwitcherDismissWithModel:model];
825 } 825 }
826 826
827 - (Tab*)dismissWithNewTabAnimation:(const GURL&)URL 827 - (Tab*)dismissWithNewTabAnimation:(const GURL&)URL
828 atIndex:(NSUInteger)position 828 atIndex:(NSUInteger)position
829 transition:(ui::PageTransition)transition 829 transition:(ui::PageTransition)transition
830 tabModel:(TabModel*)tabModel { 830 tabModel:(TabModel*)tabModel {
831 web::NavigationManager::WebLoadParams params(URL); 831 NSUInteger tabIndex = position;
832 params.referrer = web::Referrer(); 832 if (position > tabModel.count)
833 params.transition_type = transition; 833 tabIndex = tabModel.count;
834 834
835 DCHECK(tabModel.browserState); 835 Tab* tab = [tabModel insertTabWithURL:URL
836 referrer:web::Referrer()
837 transition:transition
838 opener:nil
839 openedByDOM:NO
840 atIndex:tabIndex
841 inBackground:NO];
836 842
837 base::scoped_nsobject<Tab> tab([[Tab alloc] 843 [self tabSwitcherDismissWithModel:tabModel
838 initWithBrowserState:tabModel.browserState
839 opener:nil
840 openedByDOM:NO
841 model:tabModel]);
842 [tab webController].webUsageEnabled = tabModel.webUsageEnabled;
843
844 ProceduralBlock dismissWithNewTab = ^{
845 NSUInteger tabIndex = position;
846 if (position > tabModel.count)
847 tabIndex = tabModel.count;
848 [tabModel insertTab:tab atIndex:tabIndex];
849
850 if (tabModel.tabUsageRecorder)
851 tabModel.tabUsageRecorder->TabCreatedForSelection(tab);
852
853 [[tab webController] loadWithParams:params];
854
855 if (tabModel.webUsageEnabled) {
856 [tab setWebUsageEnabled:tabModel.webUsageEnabled];
857 [[tab webController] triggerPendingLoad];
858 }
859
860 NSDictionary* userInfo = @{
861 kTabModelTabKey : tab,
862 kTabModelOpenInBackgroundKey : @(NO),
863 };
864
865 [[NSNotificationCenter defaultCenter]
866 postNotificationName:kTabModelNewTabWillOpenNotification
867 object:self
868 userInfo:userInfo];
869
870 [tabModel setCurrentTab:tab];
871
872 [self
873 tabSwitcherDismissWithModel:tabModel
874 animated:YES 844 animated:YES
875 withCompletion:^{ 845 withCompletion:^{
876 [self.delegate tabSwitcherDismissTransitionDidEnd:self]; 846 [self.delegate tabSwitcherDismissTransitionDidEnd:self];
877 }]; 847 }];
878 };
879 848
880 dismissWithNewTab();
881 return tab; 849 return tab;
882 } 850 }
883 851
884 - (BOOL)isPanelIndexForLocalSession:(NSUInteger)panelIndex { 852 - (BOOL)isPanelIndexForLocalSession:(NSUInteger)panelIndex {
885 return panelIndex == kLocalTabsOnTheRecordPanelIndex || 853 return panelIndex == kLocalTabsOnTheRecordPanelIndex ||
886 panelIndex == kLocalTabsOffTheRecordPanelIndex; 854 panelIndex == kLocalTabsOffTheRecordPanelIndex;
887 } 855 }
888 856
889 - (void)openTabWithContentOfDistantTab: 857 - (void)openTabWithContentOfDistantTab:
890 (synced_sessions::DistantTab const*)distantTab { 858 (synced_sessions::DistantTab const*)distantTab {
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 base::UserMetricsAction("MobileTabSwitcherOpenNonIncognitoTab")); 1188 base::UserMetricsAction("MobileTabSwitcherOpenNonIncognitoTab"));
1221 } 1189 }
1222 } 1190 }
1223 1191
1224 - (void)tabSwitcherPanelController: 1192 - (void)tabSwitcherPanelController:
1225 (TabSwitcherPanelController*)tabSwitcherPanelController 1193 (TabSwitcherPanelController*)tabSwitcherPanelController
1226 didCloseLocalTab:(Tab*)tab { 1194 didCloseLocalTab:(Tab*)tab {
1227 DCHECK(tab); 1195 DCHECK(tab);
1228 const TabSwitcherSessionType panelSessionType = 1196 const TabSwitcherSessionType panelSessionType =
1229 tabSwitcherPanelController.sessionType; 1197 tabSwitcherPanelController.sessionType;
1230 [tab close]; 1198 TabModel* tabModel =
1199 panelSessionType == TabSwitcherSessionType::OFF_THE_RECORD_SESSION
1200 ? [_tabSwitcherModel otrTabModel]
1201 : [_tabSwitcherModel mainTabModel];
1202 [tabModel closeTab:tab];
1203
1231 if (panelSessionType == TabSwitcherSessionType::OFF_THE_RECORD_SESSION) { 1204 if (panelSessionType == TabSwitcherSessionType::OFF_THE_RECORD_SESSION) {
1232 base::RecordAction( 1205 base::RecordAction(
1233 base::UserMetricsAction("MobileTabSwitcherCloseIncognitoTab")); 1206 base::UserMetricsAction("MobileTabSwitcherCloseIncognitoTab"));
1234 } else { 1207 } else {
1235 base::RecordAction( 1208 base::RecordAction(
1236 base::UserMetricsAction("MobileTabSwitcherCloseNonIncognitoTab")); 1209 base::UserMetricsAction("MobileTabSwitcherCloseNonIncognitoTab"));
1237 } 1210 }
1238 } 1211 }
1239 1212
1240 - (void)tabSwitcherPanelControllerDidUpdateOverlayViewVisibility: 1213 - (void)tabSwitcherPanelControllerDidUpdateOverlayViewVisibility:
1241 (TabSwitcherPanelController*)tabSwitcherPanelController { 1214 (TabSwitcherPanelController*)tabSwitcherPanelController {
1242 [_tabSwitcherView updateOverlayButtonState]; 1215 [_tabSwitcherView updateOverlayButtonState];
1243 } 1216 }
1244 1217
1245 @end 1218 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698