| OLD | NEW |
| 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 Loading... |
| 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" | |
| 54 #include "ui/base/l10n/l10n_util.h" | 53 #include "ui/base/l10n/l10n_util.h" |
| 55 #include "ui/base/l10n/l10n_util_mac.h" | 54 #include "ui/base/l10n/l10n_util_mac.h" |
| 56 | 55 |
| 57 namespace { | 56 namespace { |
| 58 | 57 |
| 59 // Offsets for computing the panels' indexes in the TabSwitcherView. | 58 // Offsets for computing the panels' indexes in the TabSwitcherView. |
| 60 const int kSignInPromoPanelIndex = 2; | 59 const int kSignInPromoPanelIndex = 2; |
| 61 const int kHeaderDistantSessionIndexOffset = 2; | 60 const int kHeaderDistantSessionIndexOffset = 2; |
| 62 const int kLocalTabsOffTheRecordPanelIndex = 0; | 61 const int kLocalTabsOffTheRecordPanelIndex = 0; |
| 63 const int kLocalTabsOnTheRecordPanelIndex = 1; | 62 const int kLocalTabsOnTheRecordPanelIndex = 1; |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 - (void)tabSwitcherDismissWithCurrentSelectedModel { | 835 - (void)tabSwitcherDismissWithCurrentSelectedModel { |
| 837 TabModel* model = [self currentSelectedModel]; | 836 TabModel* model = [self currentSelectedModel]; |
| 838 base::RecordAction(base::UserMetricsAction("MobileTabSwitcherClose")); | 837 base::RecordAction(base::UserMetricsAction("MobileTabSwitcherClose")); |
| 839 [self tabSwitcherDismissWithModel:model]; | 838 [self tabSwitcherDismissWithModel:model]; |
| 840 } | 839 } |
| 841 | 840 |
| 842 - (Tab*)dismissWithNewTabAnimation:(const GURL&)URL | 841 - (Tab*)dismissWithNewTabAnimation:(const GURL&)URL |
| 843 atIndex:(NSUInteger)position | 842 atIndex:(NSUInteger)position |
| 844 transition:(ui::PageTransition)transition | 843 transition:(ui::PageTransition)transition |
| 845 tabModel:(TabModel*)tabModel { | 844 tabModel:(TabModel*)tabModel { |
| 846 web::NavigationManager::WebLoadParams params(URL); | 845 NSUInteger tabIndex = position; |
| 847 params.referrer = web::Referrer(); | 846 if (position > tabModel.count) |
| 848 params.transition_type = transition; | 847 tabIndex = tabModel.count; |
| 849 | 848 |
| 850 DCHECK(tabModel.browserState); | 849 web::NavigationManager::WebLoadParams loadParams(URL); |
| 850 loadParams.transition_type = transition; |
| 851 | 851 |
| 852 base::scoped_nsobject<Tab> tab([[Tab alloc] | 852 Tab* tab = [tabModel insertTabWithLoadParams:loadParams |
| 853 initWithBrowserState:tabModel.browserState | 853 opener:nil |
| 854 opener:nil | 854 openedByDOM:NO |
| 855 openedByDOM:NO | 855 atIndex:tabIndex |
| 856 model:tabModel]); | 856 inBackground:NO]; |
| 857 [tab webController].webUsageEnabled = tabModel.webUsageEnabled; | |
| 858 | 857 |
| 859 ProceduralBlock dismissWithNewTab = ^{ | 858 [self tabSwitcherDismissWithModel:tabModel |
| 860 NSUInteger tabIndex = position; | |
| 861 if (position > tabModel.count) | |
| 862 tabIndex = tabModel.count; | |
| 863 [tabModel insertTab:tab atIndex:tabIndex]; | |
| 864 | |
| 865 if (tabModel.tabUsageRecorder) | |
| 866 tabModel.tabUsageRecorder->TabCreatedForSelection(tab); | |
| 867 | |
| 868 [[tab webController] loadWithParams:params]; | |
| 869 | |
| 870 if (tabModel.webUsageEnabled) { | |
| 871 [tab setWebUsageEnabled:tabModel.webUsageEnabled]; | |
| 872 [[tab webController] triggerPendingLoad]; | |
| 873 } | |
| 874 | |
| 875 NSDictionary* userInfo = @{ | |
| 876 kTabModelTabKey : tab, | |
| 877 kTabModelOpenInBackgroundKey : @(NO), | |
| 878 }; | |
| 879 | |
| 880 [[NSNotificationCenter defaultCenter] | |
| 881 postNotificationName:kTabModelNewTabWillOpenNotification | |
| 882 object:self | |
| 883 userInfo:userInfo]; | |
| 884 | |
| 885 [tabModel setCurrentTab:tab]; | |
| 886 | |
| 887 [self | |
| 888 tabSwitcherDismissWithModel:tabModel | |
| 889 animated:YES | 859 animated:YES |
| 890 withCompletion:^{ | 860 withCompletion:^{ |
| 891 [self.delegate tabSwitcherDismissTransitionDidEnd:self]; | 861 [self.delegate tabSwitcherDismissTransitionDidEnd:self]; |
| 892 }]; | 862 }]; |
| 893 }; | |
| 894 | 863 |
| 895 dismissWithNewTab(); | |
| 896 return tab; | 864 return tab; |
| 897 } | 865 } |
| 898 | 866 |
| 899 - (BOOL)isPanelIndexForLocalSession:(NSUInteger)panelIndex { | 867 - (BOOL)isPanelIndexForLocalSession:(NSUInteger)panelIndex { |
| 900 return panelIndex == kLocalTabsOnTheRecordPanelIndex || | 868 return panelIndex == kLocalTabsOnTheRecordPanelIndex || |
| 901 panelIndex == kLocalTabsOffTheRecordPanelIndex; | 869 panelIndex == kLocalTabsOffTheRecordPanelIndex; |
| 902 } | 870 } |
| 903 | 871 |
| 904 - (void)openTabWithContentOfDistantTab: | 872 - (void)openTabWithContentOfDistantTab: |
| 905 (synced_sessions::DistantTab const*)distantTab { | 873 (synced_sessions::DistantTab const*)distantTab { |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 base::UserMetricsAction("MobileTabSwitcherOpenNonIncognitoTab")); | 1203 base::UserMetricsAction("MobileTabSwitcherOpenNonIncognitoTab")); |
| 1236 } | 1204 } |
| 1237 } | 1205 } |
| 1238 | 1206 |
| 1239 - (void)tabSwitcherPanelController: | 1207 - (void)tabSwitcherPanelController: |
| 1240 (TabSwitcherPanelController*)tabSwitcherPanelController | 1208 (TabSwitcherPanelController*)tabSwitcherPanelController |
| 1241 didCloseLocalTab:(Tab*)tab { | 1209 didCloseLocalTab:(Tab*)tab { |
| 1242 DCHECK(tab); | 1210 DCHECK(tab); |
| 1243 const TabSwitcherSessionType panelSessionType = | 1211 const TabSwitcherSessionType panelSessionType = |
| 1244 tabSwitcherPanelController.sessionType; | 1212 tabSwitcherPanelController.sessionType; |
| 1245 [tab close]; | 1213 TabModel* tabModel = |
| 1214 panelSessionType == TabSwitcherSessionType::OFF_THE_RECORD_SESSION |
| 1215 ? [_tabSwitcherModel otrTabModel] |
| 1216 : [_tabSwitcherModel mainTabModel]; |
| 1217 DCHECK_NE(NSNotFound, static_cast<NSInteger>([tabModel indexOfTab:tab])); |
| 1218 [tabModel closeTab:tab]; |
| 1219 |
| 1246 if (panelSessionType == TabSwitcherSessionType::OFF_THE_RECORD_SESSION) { | 1220 if (panelSessionType == TabSwitcherSessionType::OFF_THE_RECORD_SESSION) { |
| 1247 base::RecordAction( | 1221 base::RecordAction( |
| 1248 base::UserMetricsAction("MobileTabSwitcherCloseIncognitoTab")); | 1222 base::UserMetricsAction("MobileTabSwitcherCloseIncognitoTab")); |
| 1249 } else { | 1223 } else { |
| 1250 base::RecordAction( | 1224 base::RecordAction( |
| 1251 base::UserMetricsAction("MobileTabSwitcherCloseNonIncognitoTab")); | 1225 base::UserMetricsAction("MobileTabSwitcherCloseNonIncognitoTab")); |
| 1252 } | 1226 } |
| 1253 } | 1227 } |
| 1254 | 1228 |
| 1255 - (void)tabSwitcherPanelControllerDidUpdateOverlayViewVisibility: | 1229 - (void)tabSwitcherPanelControllerDidUpdateOverlayViewVisibility: |
| 1256 (TabSwitcherPanelController*)tabSwitcherPanelController { | 1230 (TabSwitcherPanelController*)tabSwitcherPanelController { |
| 1257 [_tabSwitcherView updateOverlayButtonState]; | 1231 [_tabSwitcherView updateOverlayButtonState]; |
| 1258 } | 1232 } |
| 1259 | 1233 |
| 1260 @end | 1234 @end |
| OLD | NEW |