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

Unified Diff: ios/chrome/browser/ui/browser_view_controller.mm

Issue 2724683002: [ios] Moves the Find in Page APIs into FindTabHelper. (Closed)
Patch Set: Review 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/find_in_page/find_tab_helper_unittest.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/browser_view_controller.mm
diff --git a/ios/chrome/browser/ui/browser_view_controller.mm b/ios/chrome/browser/ui/browser_view_controller.mm
index 32bc6f7e3a4089fbbfc9fabdf277b6dfc4630e54..3ef6c50604247cf3f4edf2e0d299e8e6d2eb6c91 100644
--- a/ios/chrome/browser/ui/browser_view_controller.mm
+++ b/ios/chrome/browser/ui/browser_view_controller.mm
@@ -295,20 +295,7 @@ bool IsURLAllowedInIncognito(const GURL& url) {
// they are added to the tab model.
NSString* const kNativeControllerTemporaryKey = @"NativeControllerTemporaryKey";
-// Helper function to return the FindInPageController for the given |tab|. If
-// |tab| is nullptr or has no FindTabHelper, returns nil.
-FindInPageController* GetFindInPageController(Tab* tab) {
- if (!tab) {
- return nil;
- }
- FindTabHelper* helper = FindTabHelper::FromWebState(tab.webState);
- if (!helper) {
- return nil;
- }
- return helper->GetController();
-}
-
-} // anonymous namespace
+} // namespace
@interface BrowserViewController ()<AppRatingPromptDelegate,
ContextualSearchControllerDelegate,
@@ -1095,15 +1082,13 @@ class BrowserBookmarkModelBridge : public bookmarks::BookmarkModelObserver {
- (BOOL)canShowFindBar {
// Make sure web controller can handle find in page.
Tab* tab = [_model currentTab];
- FindInPageController* controller = GetFindInPageController(tab);
- if (![controller canFindInPage])
- return NO;
-
- // Don't show twice.
- if (controller.findInPageModel.enabled)
+ if (!tab) {
return NO;
+ }
- return YES;
+ auto* helper = FindTabHelper::FromWebState(tab.webState);
+ return (helper && helper->CurrentPageSupportsFindInPage() &&
+ !helper->IsFindUIActive());
}
- (web::UserAgentType)userAgentType {
@@ -1475,9 +1460,6 @@ class BrowserBookmarkModelBridge : public bookmarks::BookmarkModelObserver {
// Hide find bar when navigating to a new page.
[self hideFindBarWithAnimation:NO];
- FindInPageController* controller = GetFindInPageController(tab);
- controller.findInPageModel.enabled = NO;
-
if (tab == [_model currentTab]) {
// TODO(pinkerton): Fill in here about hiding the forward button on
// navigation.
@@ -1930,8 +1912,8 @@ class BrowserBookmarkModelBridge : public bookmarks::BookmarkModelObserver {
[[_toolbarController toolsPopupController]
setIsTabLoading:_toolbarModelIOS->IsLoading()];
- FindInPageController* controller = GetFindInPageController(tab);
- if (controller.findInPageModel.enabled) {
+ auto* findHelper = FindTabHelper::FromWebState(tab.webState);
+ if (findHelper && findHelper->IsFindUIActive()) {
[self showFindBarWithAnimation:NO
selectText:YES
shouldFocus:[_findBarController isFocused]];
@@ -3910,6 +3892,7 @@ class BrowserBookmarkModelBridge : public bookmarks::BookmarkModelObserver {
if (!_model || !_browserState)
return;
+ Tab* currentTab = [_model currentTab];
switch (command) {
case IDC_BACK:
@@ -3930,23 +3913,21 @@ class BrowserBookmarkModelBridge : public bookmarks::BookmarkModelObserver {
[self initFindBarForTab];
break;
case IDC_FIND_NEXT: {
- FindInPageController* findInPageController =
- GetFindInPageController([_model currentTab]);
+ DCHECK(currentTab);
// TODO(crbug.com/603524): Reshow find bar if necessary.
- [findInPageController findNextStringInPageWithCompletionHandler:^{
- FindInPageModel* model = findInPageController.findInPageModel;
- [_findBarController updateResultsCount:model];
- }];
+ FindTabHelper::FromWebState(currentTab.webState)
+ ->ContinueFinding(FindTabHelper::FORWARD, ^(FindInPageModel* model) {
+ [_findBarController updateResultsCount:model];
+ });
break;
}
case IDC_FIND_PREVIOUS: {
- FindInPageController* findInPageController =
- GetFindInPageController([_model currentTab]);
+ DCHECK(currentTab);
// TODO(crbug.com/603524): Reshow find bar if necessary.
- [findInPageController findPreviousStringInPageWithCompletionHandler:^{
- FindInPageModel* model = findInPageController.findInPageModel;
- [_findBarController updateResultsCount:model];
- }];
+ FindTabHelper::FromWebState(currentTab.webState)
+ ->ContinueFinding(FindTabHelper::REVERSE, ^(FindInPageModel* model) {
+ [_findBarController updateResultsCount:model];
+ });
break;
}
case IDC_FIND_CLOSE:
@@ -4158,11 +4139,14 @@ class BrowserBookmarkModelBridge : public bookmarks::BookmarkModelObserver {
Tab* currentTab = [_model currentTab];
[currentTab dismissModals];
- FindInPageController* findInPageController =
- GetFindInPageController(currentTab);
- [findInPageController disableFindInPageWithCompletionHandler:^{
- [self updateFindBar:NO shouldFocus:NO];
- }];
+ if (currentTab) {
+ auto* findHelper = FindTabHelper::FromWebState(currentTab.webState);
+ if (findHelper) {
+ findHelper->StopFinding(^{
+ [self updateFindBar:NO shouldFocus:NO];
+ });
+ }
+ }
[_contextualSearchController movePanelOffscreen];
[_paymentRequestManager cancelRequest];
@@ -4267,47 +4251,47 @@ class BrowserBookmarkModelBridge : public bookmarks::BookmarkModelObserver {
[[FindBarControllerIOS alloc] initWithIncognito:_isOffTheRecord]);
Tab* tab = [_model currentTab];
- FindInPageController* controller = GetFindInPageController(tab);
- DCHECK(!controller.findInPageModel.enabled);
- controller.findInPageModel.enabled = YES;
+ DCHECK(tab);
+ auto* helper = FindTabHelper::FromWebState(tab.webState);
+ DCHECK(!helper->IsFindUIActive());
+ helper->SetFindUIActive(true);
[self showFindBarWithAnimation:YES selectText:YES shouldFocus:YES];
}
- (void)searchFindInPage {
- FindInPageController* findInPageController =
- GetFindInPageController([_model currentTab]);
+ DCHECK([_model currentTab]);
+ auto* helper = FindTabHelper::FromWebState([_model currentTab].webState);
base::WeakNSObject<BrowserViewController> weakSelf(self);
- [findInPageController findStringInPage:[_findBarController searchTerm]
- completionHandler:^{
- FindInPageModel* model =
- findInPageController.findInPageModel;
+ helper->StartFinding([_findBarController searchTerm],
+ ^(FindInPageModel* model) {
[_findBarController updateResultsCount:model];
- }];
+ });
+
if (!_isOffTheRecord)
- [findInPageController saveSearchTerm];
+ helper->PersistSearchTerm();
}
- (void)closeFindInPage {
base::WeakNSObject<BrowserViewController> weakSelf(self);
- FindInPageController* findInPageController =
- GetFindInPageController([_model currentTab]);
- [findInPageController disableFindInPageWithCompletionHandler:^{
- [weakSelf updateFindBar:NO shouldFocus:NO];
- }];
+ Tab* currentTab = [_model currentTab];
+ if (currentTab) {
+ FindTabHelper::FromWebState(currentTab.webState)->StopFinding(^{
+ [weakSelf updateFindBar:NO shouldFocus:NO];
+ });
+ }
}
- (void)updateFindBar:(BOOL)initialUpdate shouldFocus:(BOOL)shouldFocus {
- FindInPageController* findInPageController =
- GetFindInPageController([_model currentTab]);
- FindInPageModel* model = findInPageController.findInPageModel;
- if (model.enabled) {
+ DCHECK([_model currentTab]);
+ auto* helper = FindTabHelper::FromWebState([_model currentTab].webState);
+ if (helper && helper->IsFindUIActive()) {
if (initialUpdate && !_isOffTheRecord) {
- [findInPageController restoreSearchTerm];
+ helper->RestoreSearchTerm();
}
[self setFramesForHeaders:[self headerViews]
atOffset:[self currentHeaderOffset]];
- [_findBarController updateView:model
+ [_findBarController updateView:helper->GetFindResult()
initialUpdate:initialUpdate
focusTextfield:shouldFocus];
} else {
« no previous file with comments | « ios/chrome/browser/find_in_page/find_tab_helper_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698