Chromium Code Reviews| 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 d00a200a771871f26e12a26c8768eda31acceff9..0487e6490c666a833452e46ca59bbc5f76fe97d5 100644 |
| --- a/ios/chrome/browser/ui/browser_view_controller.mm |
| +++ b/ios/chrome/browser/ui/browser_view_controller.mm |
| @@ -56,6 +56,7 @@ |
| #include "ios/chrome/browser/favicon/ios_chrome_favicon_loader_factory.h" |
| #import "ios/chrome/browser/find_in_page/find_in_page_controller.h" |
| #import "ios/chrome/browser/find_in_page/find_in_page_model.h" |
| +#import "ios/chrome/browser/find_in_page/find_tab_helper.h" |
| #include "ios/chrome/browser/first_run/first_run.h" |
| #import "ios/chrome/browser/geolocation/omnibox_geolocation_controller.h" |
| #include "ios/chrome/browser/infobars/infobar_container_ios.h" |
| @@ -289,6 +290,15 @@ bool IsURLAllowedInIncognito(const GURL& url) { |
| // they are added to the tab model. |
| NSString* const kNativeControllerTemporaryKey = @"NativeControllerTemporaryKey"; |
| +// Helper function to return the FindTabHelper for the given |tab|. If |tab| is |
| +// nullptr, returns nullptr. |
|
marq (ping after 24h)
2017/01/31 16:02:49
Why not just return the helper's FindInPageControl
rohitrao (ping after 24h)
2017/02/08 16:14:59
Done.
|
| +FindTabHelper* GetFindTabHelper(Tab* tab) { |
| + if (!tab) { |
| + return nullptr; |
| + } |
| + return FindTabHelper::FromWebState(tab.webState); |
|
Eugene But (OOO till 7-30)
2017/01/31 19:03:48
Optional nit: do you want to use ternary operator
rohitrao (ping after 24h)
2017/02/08 16:14:59
Acknowledged.
|
| +} |
| + |
| } // anonymous namespace |
| @interface BrowserViewController ()<AppRatingPromptDelegate, |
| @@ -1102,11 +1112,16 @@ class BrowserBookmarkModelBridge : public bookmarks::BookmarkModelObserver { |
| - (BOOL)canShowFindBar { |
| // Make sure web controller can handle find in page. |
| Tab* tab = [_model currentTab]; |
| - if (![tab.findInPageController canFindInPage]) |
| + FindTabHelper* findHelper = GetFindTabHelper(tab); |
| + if (!findHelper) |
| + return NO; |
| + |
| + FindInPageController* controller = findHelper->GetController(); |
| + if (![controller canFindInPage]) |
| return NO; |
| // Don't show twice. |
| - if (tab.findInPageController.findInPageModel.enabled) |
| + if (controller.findInPageModel.enabled) |
| return NO; |
| return YES; |
| @@ -1473,7 +1488,14 @@ class BrowserBookmarkModelBridge : public bookmarks::BookmarkModelObserver { |
| DCHECK(tab && ([_model indexOfTab:tab] != NSNotFound)); |
| // Hide find bar when navigating to a new page. |
| [self hideFindBarWithAnimation:NO]; |
| - tab.findInPageController.findInPageModel.enabled = NO; |
| + |
| + FindTabHelper* findHelper = GetFindTabHelper(tab); |
| + if (findHelper) { |
| + FindInPageController* controller = |
| + findHelper->GetController(); |
| + controller.findInPageModel.enabled = NO; |
| + } |
| + |
| if (tab == [_model currentTab]) { |
| // TODO(pinkerton): Fill in here about hiding the forward button on |
| // navigation. |
| @@ -1936,10 +1958,15 @@ class BrowserBookmarkModelBridge : public bookmarks::BookmarkModelObserver { |
| [[_toolbarController toolsPopupController] |
| setIsTabLoading:_toolbarModelIOS->IsLoading()]; |
| - if (tab.findInPageController.findInPageModel.enabled) |
| - [self showFindBarWithAnimation:NO |
| - selectText:YES |
| - shouldFocus:[_findBarController isFocused]]; |
| + FindTabHelper* findHelper = GetFindTabHelper(tab); |
| + if (findHelper) { |
| + FindInPageController* controller = |
| + findHelper->GetController(); |
| + if (controller.findInPageModel.enabled) |
| + [self showFindBarWithAnimation:NO |
| + selectText:YES |
| + shouldFocus:[_findBarController isFocused]]; |
| + } |
| // Hide the toolbar if displaying phone NTP. |
| if (!IsIPadIdiom()) { |
| @@ -3959,24 +3986,28 @@ class BrowserBookmarkModelBridge : public bookmarks::BookmarkModelObserver { |
| case IDC_FIND: |
| [self initFindBarForTab]; |
| break; |
| - case IDC_FIND_NEXT: |
| + case IDC_FIND_NEXT: { |
| + FindInPageController* findInPageController = |
| + FindTabHelper::FromWebState([_model currentTab].webState) |
|
Eugene But (OOO till 7-30)
2017/01/31 19:03:48
Should you use your helper function here and in ot
rohitrao (ping after 24h)
2017/02/08 16:14:59
Changed for now, but I'm going to revisit. I thin
|
| + ->GetController(); |
| // TODO(crbug.com/603524): Reshow find bar if necessary. |
| - [[_model currentTab].findInPageController |
| - findNextStringInPageWithCompletionHandler:^{ |
| - FindInPageModel* model = |
| - [_model currentTab].findInPageController.findInPageModel; |
| - [_findBarController updateResultsCount:model]; |
| - }]; |
| + [findInPageController findNextStringInPageWithCompletionHandler:^{ |
| + FindInPageModel* model = findInPageController.findInPageModel; |
| + [_findBarController updateResultsCount:model]; |
| + }]; |
| break; |
| - case IDC_FIND_PREVIOUS: |
| + } |
| + case IDC_FIND_PREVIOUS: { |
| + FindInPageController* findInPageController = |
| + FindTabHelper::FromWebState([_model currentTab].webState) |
| + ->GetController(); |
| // TODO(crbug.com/603524): Reshow find bar if necessary. |
| - [[_model currentTab].findInPageController |
| - findPreviousStringInPageWithCompletionHandler:^{ |
| - FindInPageModel* model = |
| - [_model currentTab].findInPageController.findInPageModel; |
| - [_findBarController updateResultsCount:model]; |
| - }]; |
| + [findInPageController findPreviousStringInPageWithCompletionHandler:^{ |
| + FindInPageModel* model = findInPageController.findInPageModel; |
| + [_findBarController updateResultsCount:model]; |
| + }]; |
| break; |
| + } |
| case IDC_FIND_CLOSE: |
| [self closeFindInPage]; |
| break; |
| @@ -4215,15 +4246,22 @@ class BrowserBookmarkModelBridge : public bookmarks::BookmarkModelObserver { |
| [self hidePageInfoPopupForView:nil]; |
| if (_voiceSearchController) |
| _voiceSearchController->DismissMicPermissionsHelp(); |
| - [[_model currentTab] dismissModals]; |
| - [[_model currentTab].findInPageController |
| - disableFindInPageWithCompletionHandler:^{ |
| + |
| + Tab* currentTab = [_model currentTab]; |
| + [currentTab dismissModals]; |
| + |
| + FindTabHelper* findHelper = GetFindTabHelper(currentTab); |
| + if (findHelper) { |
| + FindInPageController* findInPageController = |
| + findHelper |
| + ->GetController(); |
| + [findInPageController disableFindInPageWithCompletionHandler:^{ |
| [self updateFindBar:NO shouldFocus:NO]; |
| }]; |
| - [_contextualSearchController movePanelOffscreen]; |
| + } |
| + [_contextualSearchController movePanelOffscreen]; |
| [_paymentRequestManager cancelRequest]; |
| - |
| [_printController dismissAnimated:YES]; |
| _printController.reset(); |
| if (_noTabsController.get()) |
| @@ -4323,40 +4361,46 @@ class BrowserBookmarkModelBridge : public bookmarks::BookmarkModelObserver { |
| [[FindBarControllerIOS alloc] initWithIncognito:_isOffTheRecord]); |
| Tab* tab = [_model currentTab]; |
| - DCHECK(!tab.findInPageController.findInPageModel.enabled); |
| - tab.findInPageController.findInPageModel.enabled = YES; |
| + FindInPageController* controller = |
| + FindTabHelper::FromWebState(tab.webState)->GetController(); |
| + DCHECK(!controller.findInPageModel.enabled); |
| + controller.findInPageModel.enabled = YES; |
| [self showFindBarWithAnimation:YES selectText:YES shouldFocus:YES]; |
| } |
| - (void)searchFindInPage { |
| FindInPageController* findInPageController = |
| - [[_model currentTab] findInPageController]; |
| + FindTabHelper::FromWebState([_model currentTab].webState) |
| + ->GetController(); |
| base::WeakNSObject<BrowserViewController> weakSelf(self); |
| - [findInPageController |
| - findStringInPage:[_findBarController searchTerm] |
| - completionHandler:^{ |
| - FindInPageModel* model = |
| - [_model currentTab].findInPageController.findInPageModel; |
| - [_findBarController updateResultsCount:model]; |
| - }]; |
| + [findInPageController findStringInPage:[_findBarController searchTerm] |
| + completionHandler:^{ |
| + FindInPageModel* model = |
| + findInPageController.findInPageModel; |
| + [_findBarController updateResultsCount:model]; |
| + }]; |
| if (!_isOffTheRecord) |
| [findInPageController saveSearchTerm]; |
| } |
| - (void)closeFindInPage { |
| base::WeakNSObject<BrowserViewController> weakSelf(self); |
| - [[_model currentTab].findInPageController |
| - disableFindInPageWithCompletionHandler:^{ |
| - [weakSelf updateFindBar:NO shouldFocus:NO]; |
| - }]; |
| + FindInPageController* findInPageController = |
| + FindTabHelper::FromWebState([_model currentTab].webState) |
| + ->GetController(); |
| + [findInPageController disableFindInPageWithCompletionHandler:^{ |
| + [weakSelf updateFindBar:NO shouldFocus:NO]; |
| + }]; |
| } |
| - (void)updateFindBar:(BOOL)initialUpdate shouldFocus:(BOOL)shouldFocus { |
| - FindInPageModel* model = |
| - [_model currentTab].findInPageController.findInPageModel; |
| + FindInPageController* findInPageController = |
| + FindTabHelper::FromWebState([_model currentTab].webState) |
| + ->GetController(); |
| + FindInPageModel* model = findInPageController.findInPageModel; |
| if (model.enabled) { |
| if (initialUpdate && !_isOffTheRecord) { |
| - [[_model currentTab].findInPageController restoreSearchTerm]; |
| + [findInPageController restoreSearchTerm]; |
| } |
| [self setFramesForHeaders:[self headerViews] |