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

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

Issue 2724683002: [ios] Moves the Find in Page APIs into FindTabHelper. (Closed)
Patch Set: Test cleanup. 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 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 return true; 288 return true;
289 std::string url_host = url.host(); 289 std::string url_host = url.host();
290 return url_host != kChromeUIHistoryHost && 290 return url_host != kChromeUIHistoryHost &&
291 url_host != kChromeUIHistoryFrameHost; 291 url_host != kChromeUIHistoryFrameHost;
292 } 292 }
293 293
294 // Temporary key to use when storing native controllers vended to tabs before 294 // Temporary key to use when storing native controllers vended to tabs before
295 // they are added to the tab model. 295 // they are added to the tab model.
296 NSString* const kNativeControllerTemporaryKey = @"NativeControllerTemporaryKey"; 296 NSString* const kNativeControllerTemporaryKey = @"NativeControllerTemporaryKey";
297 297
298 // Helper function to return the FindInPageController for the given |tab|. If 298 } // namespace
299 // |tab| is nullptr or has no FindTabHelper, returns nil.
300 FindInPageController* GetFindInPageController(Tab* tab) {
301 if (!tab) {
302 return nil;
303 }
304 FindTabHelper* helper = FindTabHelper::FromWebState(tab.webState);
305 if (!helper) {
306 return nil;
307 }
308 return helper->GetController();
309 }
310
311 } // anonymous namespace
312 299
313 @interface BrowserViewController ()<AppRatingPromptDelegate, 300 @interface BrowserViewController ()<AppRatingPromptDelegate,
314 ContextualSearchControllerDelegate, 301 ContextualSearchControllerDelegate,
315 ContextualSearchPanelMotionObserver, 302 ContextualSearchPanelMotionObserver,
316 CRWNativeContentProvider, 303 CRWNativeContentProvider,
317 CRWWebStateDelegate, 304 CRWWebStateDelegate,
318 DialogPresenterDelegate, 305 DialogPresenterDelegate,
319 FullScreenControllerDelegate, 306 FullScreenControllerDelegate,
320 KeyCommandsPlumbing, 307 KeyCommandsPlumbing,
321 MFMailComposeViewControllerDelegate, 308 MFMailComposeViewControllerDelegate,
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 Tab* tab = [_model currentTab]; 1075 Tab* tab = [_model currentTab];
1089 // TODO(shreyasv): Make it so the URL returned by the tab is always valid and 1076 // TODO(shreyasv): Make it so the URL returned by the tab is always valid and
1090 // remove check on net::NSURLWithGURL(tab.url) ( http://crbug.com/400999 ). 1077 // remove check on net::NSURLWithGURL(tab.url) ( http://crbug.com/400999 ).
1091 return tab && !tab.url.SchemeIs(kChromeUIScheme) && 1078 return tab && !tab.url.SchemeIs(kChromeUIScheme) &&
1092 net::NSURLWithGURL(tab.url); 1079 net::NSURLWithGURL(tab.url);
1093 } 1080 }
1094 1081
1095 - (BOOL)canShowFindBar { 1082 - (BOOL)canShowFindBar {
1096 // Make sure web controller can handle find in page. 1083 // Make sure web controller can handle find in page.
1097 Tab* tab = [_model currentTab]; 1084 Tab* tab = [_model currentTab];
1098 FindInPageController* controller = GetFindInPageController(tab); 1085 if (!tab) {
1099 if (![controller canFindInPage])
1100 return NO; 1086 return NO;
1087 }
1101 1088
1102 // Don't show twice. 1089 auto* helper = FindTabHelper::FromWebState(tab.webState);
1103 if (controller.findInPageModel.enabled) 1090 return (helper && helper->CurrentPageSupportsFindInPage() &&
1104 return NO; 1091 !helper->IsFindUIActive());
1105
1106 return YES;
1107 } 1092 }
1108 1093
1109 - (web::UserAgentType)userAgentType { 1094 - (web::UserAgentType)userAgentType {
1110 web::WebState* webState = [_model currentTab].webState; 1095 web::WebState* webState = [_model currentTab].webState;
1111 if (!webState) 1096 if (!webState)
1112 return web::UserAgentType::NONE; 1097 return web::UserAgentType::NONE;
1113 web::NavigationItem* visibleItem = 1098 web::NavigationItem* visibleItem =
1114 webState->GetNavigationManager()->GetVisibleItem(); 1099 webState->GetNavigationManager()->GetVisibleItem();
1115 if (!visibleItem) 1100 if (!visibleItem)
1116 return web::UserAgentType::NONE; 1101 return web::UserAgentType::NONE;
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 name:kTabModelNewTabWillOpenNotification 1453 name:kTabModelNewTabWillOpenNotification
1469 object:_model]; 1454 object:_model];
1470 } 1455 }
1471 1456
1472 - (void)pageLoadStarting:(NSNotification*)notify { 1457 - (void)pageLoadStarting:(NSNotification*)notify {
1473 Tab* tab = notify.userInfo[kTabModelTabKey]; 1458 Tab* tab = notify.userInfo[kTabModelTabKey];
1474 DCHECK(tab && ([_model indexOfTab:tab] != NSNotFound)); 1459 DCHECK(tab && ([_model indexOfTab:tab] != NSNotFound));
1475 // Hide find bar when navigating to a new page. 1460 // Hide find bar when navigating to a new page.
1476 [self hideFindBarWithAnimation:NO]; 1461 [self hideFindBarWithAnimation:NO];
1477 1462
1478 FindInPageController* controller = GetFindInPageController(tab);
1479 controller.findInPageModel.enabled = NO;
1480
1481 if (tab == [_model currentTab]) { 1463 if (tab == [_model currentTab]) {
1482 // TODO(pinkerton): Fill in here about hiding the forward button on 1464 // TODO(pinkerton): Fill in here about hiding the forward button on
1483 // navigation. 1465 // navigation.
1484 } 1466 }
1485 } 1467 }
1486 1468
1487 - (void)pageLoadStarted:(NSNotification*)notify { 1469 - (void)pageLoadStarted:(NSNotification*)notify {
1488 Tab* tab = notify.userInfo[kTabModelTabKey]; 1470 Tab* tab = notify.userInfo[kTabModelTabKey];
1489 DCHECK(tab); 1471 DCHECK(tab);
1490 if (tab == [_model currentTab]) { 1472 if (tab == [_model currentTab]) {
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 1905
1924 if (tab.isPrerenderTab && !_toolbarModelIOS->IsLoading()) 1906 if (tab.isPrerenderTab && !_toolbarModelIOS->IsLoading())
1925 [_toolbarController showPrerenderingAnimation]; 1907 [_toolbarController showPrerenderingAnimation];
1926 1908
1927 // Also update the loading state for the tools menu (that is really an 1909 // Also update the loading state for the tools menu (that is really an
1928 // extension of the toolbar on the iPhone). 1910 // extension of the toolbar on the iPhone).
1929 if (!IsIPadIdiom()) 1911 if (!IsIPadIdiom())
1930 [[_toolbarController toolsPopupController] 1912 [[_toolbarController toolsPopupController]
1931 setIsTabLoading:_toolbarModelIOS->IsLoading()]; 1913 setIsTabLoading:_toolbarModelIOS->IsLoading()];
1932 1914
1933 FindInPageController* controller = GetFindInPageController(tab); 1915 auto* findHelper = FindTabHelper::FromWebState(tab.webState);
1934 if (controller.findInPageModel.enabled) { 1916 if (findHelper && findHelper->IsFindUIActive()) {
1935 [self showFindBarWithAnimation:NO 1917 [self showFindBarWithAnimation:NO
1936 selectText:YES 1918 selectText:YES
1937 shouldFocus:[_findBarController isFocused]]; 1919 shouldFocus:[_findBarController isFocused]];
1938 } 1920 }
1939 1921
1940 // Hide the toolbar if displaying phone NTP. 1922 // Hide the toolbar if displaying phone NTP.
1941 if (!IsIPadIdiom()) { 1923 if (!IsIPadIdiom()) {
1942 web::NavigationItem* item = [tab navigationManager]->GetVisibleItem(); 1924 web::NavigationItem* item = [tab navigationManager]->GetVisibleItem();
1943 BOOL hideToolbar = NO; 1925 BOOL hideToolbar = NO;
1944 if (item) { 1926 if (item) {
(...skipping 1945 matching lines...) Expand 10 before | Expand all | Expand 10 after
3890 return card; 3872 return card;
3891 } 3873 }
3892 3874
3893 #pragma mark - Command Handling 3875 #pragma mark - Command Handling
3894 3876
3895 - (IBAction)chromeExecuteCommand:(id)sender { 3877 - (IBAction)chromeExecuteCommand:(id)sender {
3896 NSInteger command = [sender tag]; 3878 NSInteger command = [sender tag];
3897 3879
3898 if (!_model || !_browserState) 3880 if (!_model || !_browserState)
3899 return; 3881 return;
3882 Tab* currentTab = [_model currentTab];
3900 3883
3901 switch (command) { 3884 switch (command) {
3902 case IDC_BACK: 3885 case IDC_BACK:
3903 [[_model currentTab] goBack]; 3886 [[_model currentTab] goBack];
3904 break; 3887 break;
3905 case IDC_BOOKMARK_PAGE: 3888 case IDC_BOOKMARK_PAGE:
3906 [self initializeBookmarkInteractionController]; 3889 [self initializeBookmarkInteractionController];
3907 [_bookmarkInteractionController 3890 [_bookmarkInteractionController
3908 presentBookmarkForTab:[_model currentTab] 3891 presentBookmarkForTab:[_model currentTab]
3909 currentlyBookmarked:_toolbarModelIOS->IsCurrentTabBookmarkedByUser() 3892 currentlyBookmarked:_toolbarModelIOS->IsCurrentTabBookmarkedByUser()
3910 inView:[_toolbarController bookmarkButtonView] 3893 inView:[_toolbarController bookmarkButtonView]
3911 originRect:[_toolbarController bookmarkButtonAnchorRect]]; 3894 originRect:[_toolbarController bookmarkButtonAnchorRect]];
3912 break; 3895 break;
3913 case IDC_CLOSE_TAB: 3896 case IDC_CLOSE_TAB:
3914 [self closeCurrentTab]; 3897 [self closeCurrentTab];
3915 break; 3898 break;
3916 case IDC_FIND: 3899 case IDC_FIND:
3917 [self initFindBarForTab]; 3900 [self initFindBarForTab];
3918 break; 3901 break;
3919 case IDC_FIND_NEXT: { 3902 case IDC_FIND_NEXT: {
3920 FindInPageController* findInPageController = 3903 DCHECK(currentTab);
3921 GetFindInPageController([_model currentTab]);
3922 // TODO(crbug.com/603524): Reshow find bar if necessary. 3904 // TODO(crbug.com/603524): Reshow find bar if necessary.
3923 [findInPageController findNextStringInPageWithCompletionHandler:^{ 3905 FindTabHelper::FromWebState(currentTab.webState)
3924 FindInPageModel* model = findInPageController.findInPageModel; 3906 ->ContinueFinding(FindTabHelper::FORWARD, ^(FindInPageModel* model) {
3925 [_findBarController updateResultsCount:model]; 3907 [_findBarController updateResultsCount:model];
3926 }]; 3908 });
3927 break; 3909 break;
3928 } 3910 }
3929 case IDC_FIND_PREVIOUS: { 3911 case IDC_FIND_PREVIOUS: {
3930 FindInPageController* findInPageController = 3912 DCHECK(currentTab);
3931 GetFindInPageController([_model currentTab]);
3932 // TODO(crbug.com/603524): Reshow find bar if necessary. 3913 // TODO(crbug.com/603524): Reshow find bar if necessary.
3933 [findInPageController findPreviousStringInPageWithCompletionHandler:^{ 3914 FindTabHelper::FromWebState(currentTab.webState)
3934 FindInPageModel* model = findInPageController.findInPageModel; 3915 ->ContinueFinding(FindTabHelper::REVERSE, ^(FindInPageModel* model) {
3935 [_findBarController updateResultsCount:model]; 3916 [_findBarController updateResultsCount:model];
3936 }]; 3917 });
3937 break; 3918 break;
3938 } 3919 }
3939 case IDC_FIND_CLOSE: 3920 case IDC_FIND_CLOSE:
3940 [self closeFindInPage]; 3921 [self closeFindInPage];
3941 break; 3922 break;
3942 case IDC_FIND_UPDATE: 3923 case IDC_FIND_UPDATE:
3943 [self searchFindInPage]; 3924 [self searchFindInPage];
3944 break; 3925 break;
3945 case IDC_FORWARD: 3926 case IDC_FORWARD:
3946 [[_model currentTab] goForward]; 3927 [[_model currentTab] goForward];
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
4138 [_bookmarkInteractionController dismissSnackbar]; 4119 [_bookmarkInteractionController dismissSnackbar];
4139 [_toolbarController cancelOmniboxEdit]; 4120 [_toolbarController cancelOmniboxEdit];
4140 [_dialogPresenter cancelAllDialogs]; 4121 [_dialogPresenter cancelAllDialogs];
4141 [self hidePageInfoPopupForView:nil]; 4122 [self hidePageInfoPopupForView:nil];
4142 if (_voiceSearchController) 4123 if (_voiceSearchController)
4143 _voiceSearchController->DismissMicPermissionsHelp(); 4124 _voiceSearchController->DismissMicPermissionsHelp();
4144 4125
4145 Tab* currentTab = [_model currentTab]; 4126 Tab* currentTab = [_model currentTab];
4146 [currentTab dismissModals]; 4127 [currentTab dismissModals];
4147 4128
4148 FindInPageController* findInPageController = 4129 if (currentTab) {
4149 GetFindInPageController(currentTab); 4130 auto* findHelper = FindTabHelper::FromWebState(currentTab.webState);
4150 [findInPageController disableFindInPageWithCompletionHandler:^{ 4131 if (findHelper) {
4151 [self updateFindBar:NO shouldFocus:NO]; 4132 findHelper->StopFinding(^{
4152 }]; 4133 [self updateFindBar:NO shouldFocus:NO];
4134 });
4135 }
4136 }
4153 4137
4154 [_contextualSearchController movePanelOffscreen]; 4138 [_contextualSearchController movePanelOffscreen];
4155 [_paymentRequestManager cancelRequest]; 4139 [_paymentRequestManager cancelRequest];
4156 [_printController dismissAnimated:YES]; 4140 [_printController dismissAnimated:YES];
4157 _printController.reset(); 4141 _printController.reset();
4158 [_toolbarController dismissToolsMenuPopup]; 4142 [_toolbarController dismissToolsMenuPopup];
4159 [_contextMenuCoordinator stop]; 4143 [_contextMenuCoordinator stop];
4160 [self dismissRateThisAppDialog]; 4144 [self dismissRateThisAppDialog];
4161 4145
4162 [_contentSuggestionsCoordinator stop]; 4146 [_contentSuggestionsCoordinator stop];
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
4247 // Create find bar controller and pass it to the web controller. 4231 // Create find bar controller and pass it to the web controller.
4248 - (void)initFindBarForTab { 4232 - (void)initFindBarForTab {
4249 if (!self.canShowFindBar) 4233 if (!self.canShowFindBar)
4250 return; 4234 return;
4251 4235
4252 if (!_findBarController) 4236 if (!_findBarController)
4253 _findBarController.reset( 4237 _findBarController.reset(
4254 [[FindBarControllerIOS alloc] initWithIncognito:_isOffTheRecord]); 4238 [[FindBarControllerIOS alloc] initWithIncognito:_isOffTheRecord]);
4255 4239
4256 Tab* tab = [_model currentTab]; 4240 Tab* tab = [_model currentTab];
4257 FindInPageController* controller = GetFindInPageController(tab); 4241 DCHECK(tab);
4258 DCHECK(!controller.findInPageModel.enabled); 4242 auto* helper = FindTabHelper::FromWebState(tab.webState);
4259 controller.findInPageModel.enabled = YES; 4243 DCHECK(!helper->IsFindUIActive());
4244 helper->SetFindUIActive(true);
4260 [self showFindBarWithAnimation:YES selectText:YES shouldFocus:YES]; 4245 [self showFindBarWithAnimation:YES selectText:YES shouldFocus:YES];
4261 } 4246 }
4262 4247
4263 - (void)searchFindInPage { 4248 - (void)searchFindInPage {
4264 FindInPageController* findInPageController = 4249 DCHECK([_model currentTab]);
4265 GetFindInPageController([_model currentTab]); 4250 auto* helper = FindTabHelper::FromWebState([_model currentTab].webState);
4266 base::WeakNSObject<BrowserViewController> weakSelf(self); 4251 base::WeakNSObject<BrowserViewController> weakSelf(self);
4267 [findInPageController findStringInPage:[_findBarController searchTerm] 4252 helper->StartFinding([_findBarController searchTerm],
4268 completionHandler:^{ 4253 ^(FindInPageModel* model) {
4269 FindInPageModel* model =
4270 findInPageController.findInPageModel;
4271 [_findBarController updateResultsCount:model]; 4254 [_findBarController updateResultsCount:model];
4272 }]; 4255 });
4256
4273 if (!_isOffTheRecord) 4257 if (!_isOffTheRecord)
4274 [findInPageController saveSearchTerm]; 4258 helper->PersistSearchTerm();
4275 } 4259 }
4276 4260
4277 - (void)closeFindInPage { 4261 - (void)closeFindInPage {
4278 base::WeakNSObject<BrowserViewController> weakSelf(self); 4262 base::WeakNSObject<BrowserViewController> weakSelf(self);
4279 FindInPageController* findInPageController = 4263 Tab* currentTab = [_model currentTab];
4280 GetFindInPageController([_model currentTab]); 4264 if (currentTab) {
4281 [findInPageController disableFindInPageWithCompletionHandler:^{ 4265 FindTabHelper::FromWebState(currentTab.webState)->StopFinding(^{
4282 [weakSelf updateFindBar:NO shouldFocus:NO]; 4266 [weakSelf updateFindBar:NO shouldFocus:NO];
4283 }]; 4267 });
4268 }
4284 } 4269 }
4285 4270
4286 - (void)updateFindBar:(BOOL)initialUpdate shouldFocus:(BOOL)shouldFocus { 4271 - (void)updateFindBar:(BOOL)initialUpdate shouldFocus:(BOOL)shouldFocus {
4287 FindInPageController* findInPageController = 4272 DCHECK([_model currentTab]);
4288 GetFindInPageController([_model currentTab]); 4273 auto* helper = FindTabHelper::FromWebState([_model currentTab].webState);
4289 FindInPageModel* model = findInPageController.findInPageModel; 4274 if (helper && helper->IsFindUIActive()) {
4290 if (model.enabled) {
4291 if (initialUpdate && !_isOffTheRecord) { 4275 if (initialUpdate && !_isOffTheRecord) {
4292 [findInPageController restoreSearchTerm]; 4276 helper->RestoreSearchTerm();
4293 } 4277 }
4294 4278
4295 [self setFramesForHeaders:[self headerViews] 4279 [self setFramesForHeaders:[self headerViews]
4296 atOffset:[self currentHeaderOffset]]; 4280 atOffset:[self currentHeaderOffset]];
4297 [_findBarController updateView:model 4281 [_findBarController updateView:helper->GetFindResult()
4298 initialUpdate:initialUpdate 4282 initialUpdate:initialUpdate
4299 focusTextfield:shouldFocus]; 4283 focusTextfield:shouldFocus];
4300 } else { 4284 } else {
4301 [self hideFindBarWithAnimation:YES]; 4285 [self hideFindBarWithAnimation:YES];
4302 } 4286 }
4303 } 4287 }
4304 4288
4305 - (void)showAllBookmarks { 4289 - (void)showAllBookmarks {
4306 DCHECK(self.visible || self.dismissingModal); 4290 DCHECK(self.visible || self.dismissingModal);
4307 GURL URL(kChromeUIBookmarksURL); 4291 GURL URL(kChromeUIBookmarksURL);
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
5088 5072
5089 - (UIView*)voiceSearchButton { 5073 - (UIView*)voiceSearchButton {
5090 return _voiceSearchButton; 5074 return _voiceSearchButton;
5091 } 5075 }
5092 5076
5093 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { 5077 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner {
5094 return [self currentLogoAnimationControllerOwner]; 5078 return [self currentLogoAnimationControllerOwner];
5095 } 5079 }
5096 5080
5097 @end 5081 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698