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

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

Issue 2654433007: [ios] Moves find-in-page code out of Tab and into FindTabHelper. (Closed)
Patch Set: Review. Created 3 years, 10 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" 51 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
52 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 52 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
53 #include "ios/chrome/browser/chrome_url_constants.h" 53 #include "ios/chrome/browser/chrome_url_constants.h"
54 #include "ios/chrome/browser/chrome_url_util.h" 54 #include "ios/chrome/browser/chrome_url_util.h"
55 #import "ios/chrome/browser/content_suggestions/content_suggestions_coordinator. h" 55 #import "ios/chrome/browser/content_suggestions/content_suggestions_coordinator. h"
56 #include "ios/chrome/browser/experimental_flags.h" 56 #include "ios/chrome/browser/experimental_flags.h"
57 #import "ios/chrome/browser/favicon/favicon_loader.h" 57 #import "ios/chrome/browser/favicon/favicon_loader.h"
58 #include "ios/chrome/browser/favicon/ios_chrome_favicon_loader_factory.h" 58 #include "ios/chrome/browser/favicon/ios_chrome_favicon_loader_factory.h"
59 #import "ios/chrome/browser/find_in_page/find_in_page_controller.h" 59 #import "ios/chrome/browser/find_in_page/find_in_page_controller.h"
60 #import "ios/chrome/browser/find_in_page/find_in_page_model.h" 60 #import "ios/chrome/browser/find_in_page/find_in_page_model.h"
61 #import "ios/chrome/browser/find_in_page/find_tab_helper.h"
61 #include "ios/chrome/browser/first_run/first_run.h" 62 #include "ios/chrome/browser/first_run/first_run.h"
62 #import "ios/chrome/browser/geolocation/omnibox_geolocation_controller.h" 63 #import "ios/chrome/browser/geolocation/omnibox_geolocation_controller.h"
63 #include "ios/chrome/browser/infobars/infobar_container_ios.h" 64 #include "ios/chrome/browser/infobars/infobar_container_ios.h"
64 #include "ios/chrome/browser/infobars/infobar_container_view.h" 65 #include "ios/chrome/browser/infobars/infobar_container_view.h"
65 #import "ios/chrome/browser/metrics/new_tab_page_uma.h" 66 #import "ios/chrome/browser/metrics/new_tab_page_uma.h"
66 #include "ios/chrome/browser/metrics/tab_usage_recorder.h" 67 #include "ios/chrome/browser/metrics/tab_usage_recorder.h"
67 #import "ios/chrome/browser/native_app_launcher/native_app_navigation_controller .h" 68 #import "ios/chrome/browser/native_app_launcher/native_app_navigation_controller .h"
68 #import "ios/chrome/browser/open_url_util.h" 69 #import "ios/chrome/browser/open_url_util.h"
69 #import "ios/chrome/browser/passwords/password_controller.h" 70 #import "ios/chrome/browser/passwords/password_controller.h"
70 #import "ios/chrome/browser/payments/payment_request_manager.h" 71 #import "ios/chrome/browser/payments/payment_request_manager.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 return true; 285 return true;
285 std::string url_host = url.host(); 286 std::string url_host = url.host();
286 return url_host != kChromeUIHistoryHost && 287 return url_host != kChromeUIHistoryHost &&
287 url_host != kChromeUIHistoryFrameHost; 288 url_host != kChromeUIHistoryFrameHost;
288 } 289 }
289 290
290 // Temporary key to use when storing native controllers vended to tabs before 291 // Temporary key to use when storing native controllers vended to tabs before
291 // they are added to the tab model. 292 // they are added to the tab model.
292 NSString* const kNativeControllerTemporaryKey = @"NativeControllerTemporaryKey"; 293 NSString* const kNativeControllerTemporaryKey = @"NativeControllerTemporaryKey";
293 294
295 // Helper function to return the FindInPageController for the given |tab|. If
296 // |tab| is nullptr or has no FindTabHelper, returns nil.
297 FindInPageController* GetFindInPageController(Tab* tab) {
298 if (!tab) {
299 return nil;
300 }
301 FindTabHelper* helper = FindTabHelper::FromWebState(tab.webState);
302 if (!helper) {
303 return nil;
304 }
305 return helper->GetController();
306 }
307
294 } // anonymous namespace 308 } // anonymous namespace
295 309
296 @interface BrowserViewController ()<AppRatingPromptDelegate, 310 @interface BrowserViewController ()<AppRatingPromptDelegate,
297 ContextualSearchControllerDelegate, 311 ContextualSearchControllerDelegate,
298 ContextualSearchPanelMotionObserver, 312 ContextualSearchPanelMotionObserver,
299 CRWNativeContentProvider, 313 CRWNativeContentProvider,
300 CRWWebStateDelegate, 314 CRWWebStateDelegate,
301 DialogPresenterDelegate, 315 DialogPresenterDelegate,
302 FullScreenControllerDelegate, 316 FullScreenControllerDelegate,
303 KeyCommandsPlumbing, 317 KeyCommandsPlumbing,
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 Tab* tab = [_model currentTab]; 1073 Tab* tab = [_model currentTab];
1060 // TODO(shreyasv): Make it so the URL returned by the tab is always valid and 1074 // TODO(shreyasv): Make it so the URL returned by the tab is always valid and
1061 // remove check on net::NSURLWithGURL(tab.url) ( http://crbug.com/400999 ). 1075 // remove check on net::NSURLWithGURL(tab.url) ( http://crbug.com/400999 ).
1062 return tab && !tab.url.SchemeIs(kChromeUIScheme) && 1076 return tab && !tab.url.SchemeIs(kChromeUIScheme) &&
1063 net::NSURLWithGURL(tab.url); 1077 net::NSURLWithGURL(tab.url);
1064 } 1078 }
1065 1079
1066 - (BOOL)canShowFindBar { 1080 - (BOOL)canShowFindBar {
1067 // Make sure web controller can handle find in page. 1081 // Make sure web controller can handle find in page.
1068 Tab* tab = [_model currentTab]; 1082 Tab* tab = [_model currentTab];
1069 if (![tab.findInPageController canFindInPage]) 1083 FindInPageController* controller = GetFindInPageController(tab);
1084 if (![controller canFindInPage])
1070 return NO; 1085 return NO;
1071 1086
1072 // Don't show twice. 1087 // Don't show twice.
1073 if (tab.findInPageController.findInPageModel.enabled) 1088 if (controller.findInPageModel.enabled)
1074 return NO; 1089 return NO;
1075 1090
1076 return YES; 1091 return YES;
1077 } 1092 }
1078 1093
1079 - (void)setVisible:(BOOL)visible { 1094 - (void)setVisible:(BOOL)visible {
1080 if (_visible == visible) 1095 if (_visible == visible)
1081 return; 1096 return;
1082 _visible = visible; 1097 _visible = visible;
1083 } 1098 }
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 selector:@selector(tabWasAdded:) 1438 selector:@selector(tabWasAdded:)
1424 name:kTabModelNewTabWillOpenNotification 1439 name:kTabModelNewTabWillOpenNotification
1425 object:_model]; 1440 object:_model];
1426 } 1441 }
1427 1442
1428 - (void)pageLoadStarting:(NSNotification*)notify { 1443 - (void)pageLoadStarting:(NSNotification*)notify {
1429 Tab* tab = notify.userInfo[kTabModelTabKey]; 1444 Tab* tab = notify.userInfo[kTabModelTabKey];
1430 DCHECK(tab && ([_model indexOfTab:tab] != NSNotFound)); 1445 DCHECK(tab && ([_model indexOfTab:tab] != NSNotFound));
1431 // Hide find bar when navigating to a new page. 1446 // Hide find bar when navigating to a new page.
1432 [self hideFindBarWithAnimation:NO]; 1447 [self hideFindBarWithAnimation:NO];
1433 tab.findInPageController.findInPageModel.enabled = NO; 1448
1449 FindInPageController* controller = GetFindInPageController(tab);
1450 controller.findInPageModel.enabled = NO;
1451
1434 if (tab == [_model currentTab]) { 1452 if (tab == [_model currentTab]) {
1435 // TODO(pinkerton): Fill in here about hiding the forward button on 1453 // TODO(pinkerton): Fill in here about hiding the forward button on
1436 // navigation. 1454 // navigation.
1437 } 1455 }
1438 } 1456 }
1439 1457
1440 - (void)pageLoadStarted:(NSNotification*)notify { 1458 - (void)pageLoadStarted:(NSNotification*)notify {
1441 Tab* tab = notify.userInfo[kTabModelTabKey]; 1459 Tab* tab = notify.userInfo[kTabModelTabKey];
1442 DCHECK(tab); 1460 DCHECK(tab);
1443 if (tab == [_model currentTab]) { 1461 if (tab == [_model currentTab]) {
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 1895
1878 if (tab.isPrerenderTab && !_toolbarModelIOS->IsLoading()) 1896 if (tab.isPrerenderTab && !_toolbarModelIOS->IsLoading())
1879 [_toolbarController showPrerenderingAnimation]; 1897 [_toolbarController showPrerenderingAnimation];
1880 1898
1881 // Also update the loading state for the tools menu (that is really an 1899 // Also update the loading state for the tools menu (that is really an
1882 // extension of the toolbar on the iPhone). 1900 // extension of the toolbar on the iPhone).
1883 if (!IsIPadIdiom()) 1901 if (!IsIPadIdiom())
1884 [[_toolbarController toolsPopupController] 1902 [[_toolbarController toolsPopupController]
1885 setIsTabLoading:_toolbarModelIOS->IsLoading()]; 1903 setIsTabLoading:_toolbarModelIOS->IsLoading()];
1886 1904
1887 if (tab.findInPageController.findInPageModel.enabled) 1905 FindInPageController* controller = GetFindInPageController(tab);
1906 if (controller.findInPageModel.enabled) {
1888 [self showFindBarWithAnimation:NO 1907 [self showFindBarWithAnimation:NO
1889 selectText:YES 1908 selectText:YES
1890 shouldFocus:[_findBarController isFocused]]; 1909 shouldFocus:[_findBarController isFocused]];
1910 }
1891 1911
1892 // Hide the toolbar if displaying phone NTP. 1912 // Hide the toolbar if displaying phone NTP.
1893 if (!IsIPadIdiom()) { 1913 if (!IsIPadIdiom()) {
1894 CRWSessionEntry* entry = 1914 CRWSessionEntry* entry =
1895 [[tab navigationManager]->GetSessionController() currentEntry]; 1915 [[tab navigationManager]->GetSessionController() currentEntry];
1896 BOOL hideToolbar = NO; 1916 BOOL hideToolbar = NO;
1897 if (entry) { 1917 if (entry) {
1898 GURL url = [entry navigationItem]->GetURL(); 1918 GURL url = [entry navigationItem]->GetURL();
1899 BOOL isNTP = url.GetOrigin() == GURL(kChromeUINewTabURL); 1919 BOOL isNTP = url.GetOrigin() == GURL(kChromeUINewTabURL);
1900 hideToolbar = isNTP && !_isOffTheRecord && 1920 hideToolbar = isNTP && !_isOffTheRecord &&
(...skipping 1910 matching lines...) Expand 10 before | Expand all | Expand 10 after
3811 currentlyBookmarked:_toolbarModelIOS->IsCurrentTabBookmarkedByUser() 3831 currentlyBookmarked:_toolbarModelIOS->IsCurrentTabBookmarkedByUser()
3812 inView:[_toolbarController bookmarkButtonView] 3832 inView:[_toolbarController bookmarkButtonView]
3813 originRect:[_toolbarController bookmarkButtonAnchorRect]]; 3833 originRect:[_toolbarController bookmarkButtonAnchorRect]];
3814 break; 3834 break;
3815 case IDC_CLOSE_TAB: 3835 case IDC_CLOSE_TAB:
3816 [self closeCurrentTab]; 3836 [self closeCurrentTab];
3817 break; 3837 break;
3818 case IDC_FIND: 3838 case IDC_FIND:
3819 [self initFindBarForTab]; 3839 [self initFindBarForTab];
3820 break; 3840 break;
3821 case IDC_FIND_NEXT: 3841 case IDC_FIND_NEXT: {
3842 FindInPageController* findInPageController =
3843 GetFindInPageController([_model currentTab]);
3822 // TODO(crbug.com/603524): Reshow find bar if necessary. 3844 // TODO(crbug.com/603524): Reshow find bar if necessary.
3823 [[_model currentTab].findInPageController 3845 [findInPageController findNextStringInPageWithCompletionHandler:^{
3824 findNextStringInPageWithCompletionHandler:^{ 3846 FindInPageModel* model = findInPageController.findInPageModel;
3825 FindInPageModel* model = 3847 [_findBarController updateResultsCount:model];
3826 [_model currentTab].findInPageController.findInPageModel; 3848 }];
3827 [_findBarController updateResultsCount:model];
3828 }];
3829 break; 3849 break;
3830 case IDC_FIND_PREVIOUS: 3850 }
3851 case IDC_FIND_PREVIOUS: {
3852 FindInPageController* findInPageController =
3853 GetFindInPageController([_model currentTab]);
3831 // TODO(crbug.com/603524): Reshow find bar if necessary. 3854 // TODO(crbug.com/603524): Reshow find bar if necessary.
3832 [[_model currentTab].findInPageController 3855 [findInPageController findPreviousStringInPageWithCompletionHandler:^{
3833 findPreviousStringInPageWithCompletionHandler:^{ 3856 FindInPageModel* model = findInPageController.findInPageModel;
3834 FindInPageModel* model = 3857 [_findBarController updateResultsCount:model];
3835 [_model currentTab].findInPageController.findInPageModel; 3858 }];
3836 [_findBarController updateResultsCount:model];
3837 }];
3838 break; 3859 break;
3860 }
3839 case IDC_FIND_CLOSE: 3861 case IDC_FIND_CLOSE:
3840 [self closeFindInPage]; 3862 [self closeFindInPage];
3841 break; 3863 break;
3842 case IDC_FIND_UPDATE: 3864 case IDC_FIND_UPDATE:
3843 [self searchFindInPage]; 3865 [self searchFindInPage];
3844 break; 3866 break;
3845 case IDC_FORWARD: 3867 case IDC_FORWARD:
3846 [[_model currentTab] goForward]; 3868 [[_model currentTab] goForward];
3847 break; 3869 break;
3848 case IDC_FULLSCREEN: 3870 case IDC_FULLSCREEN:
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
4031 4053
4032 - (void)clearPresentedStateWithCompletion:(ProceduralBlock)completion { 4054 - (void)clearPresentedStateWithCompletion:(ProceduralBlock)completion {
4033 [[_dependencyFactory shareControllerInstance] cancelShareAnimated:NO]; 4055 [[_dependencyFactory shareControllerInstance] cancelShareAnimated:NO];
4034 [_bookmarkInteractionController dismissBookmarkModalControllerAnimated:NO]; 4056 [_bookmarkInteractionController dismissBookmarkModalControllerAnimated:NO];
4035 [_bookmarkInteractionController dismissSnackbar]; 4057 [_bookmarkInteractionController dismissSnackbar];
4036 [_toolbarController cancelOmniboxEdit]; 4058 [_toolbarController cancelOmniboxEdit];
4037 [_dialogPresenter cancelAllDialogs]; 4059 [_dialogPresenter cancelAllDialogs];
4038 [self hidePageInfoPopupForView:nil]; 4060 [self hidePageInfoPopupForView:nil];
4039 if (_voiceSearchController) 4061 if (_voiceSearchController)
4040 _voiceSearchController->DismissMicPermissionsHelp(); 4062 _voiceSearchController->DismissMicPermissionsHelp();
4041 [[_model currentTab] dismissModals]; 4063
4042 [[_model currentTab].findInPageController 4064 Tab* currentTab = [_model currentTab];
4043 disableFindInPageWithCompletionHandler:^{ 4065 [currentTab dismissModals];
4044 [self updateFindBar:NO shouldFocus:NO]; 4066
4045 }]; 4067 FindInPageController* findInPageController =
4068 GetFindInPageController(currentTab);
4069 [findInPageController disableFindInPageWithCompletionHandler:^{
4070 [self updateFindBar:NO shouldFocus:NO];
4071 }];
4072
4046 [_contextualSearchController movePanelOffscreen]; 4073 [_contextualSearchController movePanelOffscreen];
4047
4048 [_paymentRequestManager cancelRequest]; 4074 [_paymentRequestManager cancelRequest];
4049
4050 [_printController dismissAnimated:YES]; 4075 [_printController dismissAnimated:YES];
4051 _printController.reset(); 4076 _printController.reset();
4052 [_toolbarController dismissToolsMenuPopup]; 4077 [_toolbarController dismissToolsMenuPopup];
4053 [_contextMenuCoordinator stop]; 4078 [_contextMenuCoordinator stop];
4054 [self dismissRateThisAppDialog]; 4079 [self dismissRateThisAppDialog];
4055 4080
4056 [_contentSuggestionsCoordinator stop]; 4081 [_contentSuggestionsCoordinator stop];
4057 4082
4058 if (self.presentedViewController) { 4083 if (self.presentedViewController) {
4059 // Dismisses any other modal controllers that may be present, e.g. Recent 4084 // Dismisses any other modal controllers that may be present, e.g. Recent
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
4136 // Create find bar controller and pass it to the web controller. 4161 // Create find bar controller and pass it to the web controller.
4137 - (void)initFindBarForTab { 4162 - (void)initFindBarForTab {
4138 if (!self.canShowFindBar) 4163 if (!self.canShowFindBar)
4139 return; 4164 return;
4140 4165
4141 if (!_findBarController) 4166 if (!_findBarController)
4142 _findBarController.reset( 4167 _findBarController.reset(
4143 [[FindBarControllerIOS alloc] initWithIncognito:_isOffTheRecord]); 4168 [[FindBarControllerIOS alloc] initWithIncognito:_isOffTheRecord]);
4144 4169
4145 Tab* tab = [_model currentTab]; 4170 Tab* tab = [_model currentTab];
4146 DCHECK(!tab.findInPageController.findInPageModel.enabled); 4171 FindInPageController* controller = GetFindInPageController(tab);
4147 tab.findInPageController.findInPageModel.enabled = YES; 4172 DCHECK(!controller.findInPageModel.enabled);
4173 controller.findInPageModel.enabled = YES;
4148 [self showFindBarWithAnimation:YES selectText:YES shouldFocus:YES]; 4174 [self showFindBarWithAnimation:YES selectText:YES shouldFocus:YES];
4149 } 4175 }
4150 4176
4151 - (void)searchFindInPage { 4177 - (void)searchFindInPage {
4152 FindInPageController* findInPageController = 4178 FindInPageController* findInPageController =
4153 [[_model currentTab] findInPageController]; 4179 GetFindInPageController([_model currentTab]);
4154 base::WeakNSObject<BrowserViewController> weakSelf(self); 4180 base::WeakNSObject<BrowserViewController> weakSelf(self);
4155 [findInPageController 4181 [findInPageController findStringInPage:[_findBarController searchTerm]
4156 findStringInPage:[_findBarController searchTerm] 4182 completionHandler:^{
4157 completionHandler:^{ 4183 FindInPageModel* model =
4158 FindInPageModel* model = 4184 findInPageController.findInPageModel;
4159 [_model currentTab].findInPageController.findInPageModel; 4185 [_findBarController updateResultsCount:model];
4160 [_findBarController updateResultsCount:model]; 4186 }];
4161 }];
4162 if (!_isOffTheRecord) 4187 if (!_isOffTheRecord)
4163 [findInPageController saveSearchTerm]; 4188 [findInPageController saveSearchTerm];
4164 } 4189 }
4165 4190
4166 - (void)closeFindInPage { 4191 - (void)closeFindInPage {
4167 base::WeakNSObject<BrowserViewController> weakSelf(self); 4192 base::WeakNSObject<BrowserViewController> weakSelf(self);
4168 [[_model currentTab].findInPageController 4193 FindInPageController* findInPageController =
4169 disableFindInPageWithCompletionHandler:^{ 4194 GetFindInPageController([_model currentTab]);
4170 [weakSelf updateFindBar:NO shouldFocus:NO]; 4195 [findInPageController disableFindInPageWithCompletionHandler:^{
4171 }]; 4196 [weakSelf updateFindBar:NO shouldFocus:NO];
4197 }];
4172 } 4198 }
4173 4199
4174 - (void)updateFindBar:(BOOL)initialUpdate shouldFocus:(BOOL)shouldFocus { 4200 - (void)updateFindBar:(BOOL)initialUpdate shouldFocus:(BOOL)shouldFocus {
4175 FindInPageModel* model = 4201 FindInPageController* findInPageController =
4176 [_model currentTab].findInPageController.findInPageModel; 4202 GetFindInPageController([_model currentTab]);
4203 FindInPageModel* model = findInPageController.findInPageModel;
4177 if (model.enabled) { 4204 if (model.enabled) {
4178 if (initialUpdate && !_isOffTheRecord) { 4205 if (initialUpdate && !_isOffTheRecord) {
4179 [[_model currentTab].findInPageController restoreSearchTerm]; 4206 [findInPageController restoreSearchTerm];
4180 } 4207 }
4181 4208
4182 [self setFramesForHeaders:[self headerViews] 4209 [self setFramesForHeaders:[self headerViews]
4183 atOffset:[self currentHeaderOffset]]; 4210 atOffset:[self currentHeaderOffset]];
4184 [_findBarController updateView:model 4211 [_findBarController updateView:model
4185 initialUpdate:initialUpdate 4212 initialUpdate:initialUpdate
4186 focusTextfield:shouldFocus]; 4213 focusTextfield:shouldFocus];
4187 } else { 4214 } else {
4188 [self hideFindBarWithAnimation:YES]; 4215 [self hideFindBarWithAnimation:YES];
4189 } 4216 }
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
4970 4997
4971 - (UIView*)voiceSearchButton { 4998 - (UIView*)voiceSearchButton {
4972 return _voiceSearchButton; 4999 return _voiceSearchButton;
4973 } 5000 }
4974 5001
4975 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { 5002 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner {
4976 return [self currentLogoAnimationControllerOwner]; 5003 return [self currentLogoAnimationControllerOwner];
4977 } 5004 }
4978 5005
4979 @end 5006 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/tabs/tab.mm ('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