Chromium Code Reviews| 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 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 821 - (void)tabSwitcherDismissWithCurrentSelectedModel { | 820 - (void)tabSwitcherDismissWithCurrentSelectedModel { |
| 822 TabModel* model = [self currentSelectedModel]; | 821 TabModel* model = [self currentSelectedModel]; |
| 823 base::RecordAction(base::UserMetricsAction("MobileTabSwitcherClose")); | 822 base::RecordAction(base::UserMetricsAction("MobileTabSwitcherClose")); |
| 824 [self tabSwitcherDismissWithModel:model]; | 823 [self tabSwitcherDismissWithModel:model]; |
| 825 } | 824 } |
| 826 | 825 |
| 827 - (Tab*)dismissWithNewTabAnimation:(const GURL&)URL | 826 - (Tab*)dismissWithNewTabAnimation:(const GURL&)URL |
| 828 atIndex:(NSUInteger)position | 827 atIndex:(NSUInteger)position |
| 829 transition:(ui::PageTransition)transition | 828 transition:(ui::PageTransition)transition |
| 830 tabModel:(TabModel*)tabModel { | 829 tabModel:(TabModel*)tabModel { |
| 831 web::NavigationManager::WebLoadParams params(URL); | 830 NSUInteger tabIndex = position; |
| 832 params.referrer = web::Referrer(); | 831 if (position > tabModel.count) |
| 833 params.transition_type = transition; | 832 tabIndex = tabModel.count; |
| 834 | 833 |
| 835 DCHECK(tabModel.browserState); | 834 Tab* tab = [tabModel insertTabWithURL:URL |
|
rohitrao (ping after 24h)
2017/04/03 17:49:35
Could you use insertTabWithLoadParams here instead
sdefresne
2017/04/04 13:47:57
Done.
| |
| 835 referrer:web::Referrer() | |
| 836 transition:transition | |
| 837 opener:nil | |
| 838 openedByDOM:NO | |
| 839 atIndex:tabIndex | |
| 840 inBackground:NO]; | |
| 836 | 841 |
| 837 base::scoped_nsobject<Tab> tab([[Tab alloc] | 842 [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 | 843 animated:YES |
| 875 withCompletion:^{ | 844 withCompletion:^{ |
| 876 [self.delegate tabSwitcherDismissTransitionDidEnd:self]; | 845 [self.delegate tabSwitcherDismissTransitionDidEnd:self]; |
| 877 }]; | 846 }]; |
| 878 }; | |
| 879 | 847 |
| 880 dismissWithNewTab(); | |
| 881 return tab; | 848 return tab; |
| 882 } | 849 } |
| 883 | 850 |
| 884 - (BOOL)isPanelIndexForLocalSession:(NSUInteger)panelIndex { | 851 - (BOOL)isPanelIndexForLocalSession:(NSUInteger)panelIndex { |
| 885 return panelIndex == kLocalTabsOnTheRecordPanelIndex || | 852 return panelIndex == kLocalTabsOnTheRecordPanelIndex || |
| 886 panelIndex == kLocalTabsOffTheRecordPanelIndex; | 853 panelIndex == kLocalTabsOffTheRecordPanelIndex; |
| 887 } | 854 } |
| 888 | 855 |
| 889 - (void)openTabWithContentOfDistantTab: | 856 - (void)openTabWithContentOfDistantTab: |
| 890 (synced_sessions::DistantTab const*)distantTab { | 857 (synced_sessions::DistantTab const*)distantTab { |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1220 base::UserMetricsAction("MobileTabSwitcherOpenNonIncognitoTab")); | 1187 base::UserMetricsAction("MobileTabSwitcherOpenNonIncognitoTab")); |
| 1221 } | 1188 } |
| 1222 } | 1189 } |
| 1223 | 1190 |
| 1224 - (void)tabSwitcherPanelController: | 1191 - (void)tabSwitcherPanelController: |
| 1225 (TabSwitcherPanelController*)tabSwitcherPanelController | 1192 (TabSwitcherPanelController*)tabSwitcherPanelController |
| 1226 didCloseLocalTab:(Tab*)tab { | 1193 didCloseLocalTab:(Tab*)tab { |
| 1227 DCHECK(tab); | 1194 DCHECK(tab); |
| 1228 const TabSwitcherSessionType panelSessionType = | 1195 const TabSwitcherSessionType panelSessionType = |
| 1229 tabSwitcherPanelController.sessionType; | 1196 tabSwitcherPanelController.sessionType; |
| 1230 [tab close]; | 1197 TabModel* tabModel = |
| 1198 panelSessionType == TabSwitcherSessionType::OFF_THE_RECORD_SESSION | |
| 1199 ? [_tabSwitcherModel otrTabModel] | |
| 1200 : [_tabSwitcherModel mainTabModel]; | |
| 1201 [tabModel closeTab:tab]; | |
|
rohitrao (ping after 24h)
2017/04/03 17:49:35
DCHECK_NE(NSNotFound, [tabModel indexOfTab:tab]),
sdefresne
2017/04/04 13:47:56
Done.
| |
| 1202 | |
| 1231 if (panelSessionType == TabSwitcherSessionType::OFF_THE_RECORD_SESSION) { | 1203 if (panelSessionType == TabSwitcherSessionType::OFF_THE_RECORD_SESSION) { |
| 1232 base::RecordAction( | 1204 base::RecordAction( |
| 1233 base::UserMetricsAction("MobileTabSwitcherCloseIncognitoTab")); | 1205 base::UserMetricsAction("MobileTabSwitcherCloseIncognitoTab")); |
| 1234 } else { | 1206 } else { |
| 1235 base::RecordAction( | 1207 base::RecordAction( |
| 1236 base::UserMetricsAction("MobileTabSwitcherCloseNonIncognitoTab")); | 1208 base::UserMetricsAction("MobileTabSwitcherCloseNonIncognitoTab")); |
| 1237 } | 1209 } |
| 1238 } | 1210 } |
| 1239 | 1211 |
| 1240 - (void)tabSwitcherPanelControllerDidUpdateOverlayViewVisibility: | 1212 - (void)tabSwitcherPanelControllerDidUpdateOverlayViewVisibility: |
| 1241 (TabSwitcherPanelController*)tabSwitcherPanelController { | 1213 (TabSwitcherPanelController*)tabSwitcherPanelController { |
| 1242 [_tabSwitcherView updateOverlayButtonState]; | 1214 [_tabSwitcherView updateOverlayButtonState]; |
| 1243 } | 1215 } |
| 1244 | 1216 |
| 1245 @end | 1217 @end |
| OLD | NEW |