Commit dd489d36 authored by Nazerke's avatar Nazerke Committed by Commit Bot

[iOS][coordinator] Modernize Omnibox Popup Coordinator.

This CL modernizes the OmniboxPopupCoordinator
 - to use |browser| in the initializer,
 - to remove the public property for  dispatcher, webstatelist and
browserstate,
 - to use self.browser to get browserstate, webstatelist and dispatcher
values.

This CL includes migration to ChromeCoordinator as a superclass.

Bug: 1029346, 1048423
Change-Id: Id99b8197d23cbb9d0b16e9a35b096a9b91213562
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2068598Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Nazerke Kalidolda <nazerke@google.com>
Cr-Commit-Position: refs/heads/master@{#743899}
parent 2a0239a8
...@@ -168,8 +168,6 @@ const int kLocationAuthorizationStatusCount = 5; ...@@ -168,8 +168,6 @@ const int kLocationAuthorizationStatusCount = 5;
self.omniboxPopupCoordinator = [self.omniboxCoordinator self.omniboxPopupCoordinator = [self.omniboxCoordinator
createPopupCoordinator:self.popupPresenterDelegate]; createPopupCoordinator:self.popupPresenterDelegate];
self.omniboxPopupCoordinator.dispatcher = self.dispatcher;
self.omniboxPopupCoordinator.webStateList = self.webStateList;
[self.omniboxPopupCoordinator start]; [self.omniboxPopupCoordinator start];
// Create button factory that wil be used by the ViewController to get // Create button factory that wil be used by the ViewController to get
......
...@@ -161,9 +161,10 @@ ...@@ -161,9 +161,10 @@
_editView->model()->set_popup_model(popupView->model()); _editView->model()->set_popup_model(popupView->model());
_editView->SetPopupProvider(popupView.get()); _editView->SetPopupProvider(popupView.get());
OmniboxPopupCoordinator* coordinator = OmniboxPopupCoordinator* coordinator = [[OmniboxPopupCoordinator alloc]
[[OmniboxPopupCoordinator alloc] initWithPopupView:std::move(popupView)]; initWithBaseViewController:nil
coordinator.browserState = self.browser->GetBrowserState(); browser:self.browser
popupView:std::move(popupView)];
coordinator.presenterDelegate = presenterDelegate; coordinator.presenterDelegate = presenterDelegate;
return coordinator; return coordinator;
......
...@@ -27,9 +27,11 @@ source_set("popup") { ...@@ -27,9 +27,11 @@ source_set("popup") {
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/favicon", "//ios/chrome/browser/favicon",
"//ios/chrome/browser/main:public",
"//ios/chrome/browser/search_engines", "//ios/chrome/browser/search_engines",
"//ios/chrome/browser/ui:feature_flags", "//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/ntp:util", "//ios/chrome/browser/ui/ntp:util",
"//ios/chrome/browser/ui/omnibox:omnibox_util", "//ios/chrome/browser/ui/omnibox:omnibox_util",
"//ios/chrome/browser/ui/toolbar/buttons", "//ios/chrome/browser/ui/toolbar/buttons",
......
...@@ -5,39 +5,39 @@ ...@@ -5,39 +5,39 @@
#ifndef IOS_CHROME_BROWSER_UI_OMNIBOX_POPUP_OMNIBOX_POPUP_COORDINATOR_H_ #ifndef IOS_CHROME_BROWSER_UI_OMNIBOX_POPUP_OMNIBOX_POPUP_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_OMNIBOX_POPUP_OMNIBOX_POPUP_COORDINATOR_H_ #define IOS_CHROME_BROWSER_UI_OMNIBOX_POPUP_OMNIBOX_POPUP_COORDINATOR_H_
#import <UIKit/UIKit.h> #import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
#include <memory> #include <memory>
class ChromeBrowserState;
@class CommandDispatcher;
@protocol OmniboxPopupPresenterDelegate; @protocol OmniboxPopupPresenterDelegate;
@protocol OmniboxFocuser; @protocol OmniboxFocuser;
class OmniboxPopupViewIOS; class OmniboxPopupViewIOS;
class WebStateList;
// Coordinator for the Omnibox Popup. // Coordinator for the Omnibox Popup.
@interface OmniboxPopupCoordinator : NSObject @interface OmniboxPopupCoordinator : ChromeCoordinator
- (instancetype)initWithPopupView: - (instancetype)
(std::unique_ptr<OmniboxPopupViewIOS>)popupView NS_DESIGNATED_INITIALIZER; initWithBaseViewController:(UIViewController*)viewController
- (instancetype)init NS_UNAVAILABLE; browser:(Browser*)browser
popupView:(std::unique_ptr<OmniboxPopupViewIOS>)popupView
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
NS_UNAVAILABLE;
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browser:(Browser*)browser NS_UNAVAILABLE;
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browserState:(ChromeBrowserState*)browserState
NS_UNAVAILABLE;
// BrowserState.
@property(nonatomic, assign) ChromeBrowserState* browserState;
// Positioner for the popup. // Positioner for the popup.
@property(nonatomic, weak) id<OmniboxPopupPresenterDelegate> presenterDelegate; @property(nonatomic, weak) id<OmniboxPopupPresenterDelegate> presenterDelegate;
// Whether this coordinator has results to show. // Whether this coordinator has results to show.
@property(nonatomic, assign, readonly) BOOL hasResults; @property(nonatomic, assign, readonly) BOOL hasResults;
// Whether the popup is open. // Whether the popup is open.
@property(nonatomic, assign, readonly) BOOL isOpen; @property(nonatomic, assign, readonly) BOOL isOpen;
// The dispatcher for this view controller.
@property(nonatomic, readwrite, weak) CommandDispatcher* dispatcher;
// The web state list this coordinator is handling.
@property(nonatomic, assign) WebStateList* webStateList;
- (void)start;
- (void)stop;
@end @end
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#import "components/search_engines/template_url_service.h" #import "components/search_engines/template_url_service.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/favicon/ios_chrome_favicon_loader_factory.h" #include "ios/chrome/browser/favicon/ios_chrome_favicon_loader_factory.h"
#import "ios/chrome/browser/main/browser.h"
#include "ios/chrome/browser/search_engines/template_url_service_factory.h" #include "ios/chrome/browser/search_engines/template_url_service_factory.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h" #import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/ntp/ntp_util.h" #import "ios/chrome/browser/ui/ntp/ntp_util.h"
...@@ -38,16 +39,16 @@ ...@@ -38,16 +39,16 @@
@implementation OmniboxPopupCoordinator @implementation OmniboxPopupCoordinator
@synthesize browserState = _browserState;
@synthesize mediator = _mediator; @synthesize mediator = _mediator;
@synthesize popupViewController = _popupViewController; @synthesize popupViewController = _popupViewController;
@synthesize dispatcher = _dispatcher;
#pragma mark - Public #pragma mark - Public
- (instancetype)initWithPopupView: - (instancetype)
(std::unique_ptr<OmniboxPopupViewIOS>)popupView { initWithBaseViewController:(UIViewController*)viewController
self = [super init]; browser:(Browser*)browser
popupView:(std::unique_ptr<OmniboxPopupViewIOS>)popupView {
self = [super initWithBaseViewController:nil browser:browser];
if (self) { if (self) {
_popupView = std::move(popupView); _popupView = std::move(popupView);
} }
...@@ -57,26 +58,31 @@ ...@@ -57,26 +58,31 @@
- (void)start { - (void)start {
std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> imageFetcher = std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> imageFetcher =
std::make_unique<image_fetcher::IOSImageDataFetcherWrapper>( std::make_unique<image_fetcher::IOSImageDataFetcherWrapper>(
self.browserState->GetSharedURLLoaderFactory()); self.browser->GetBrowserState()->GetSharedURLLoaderFactory());
self.mediator = [[OmniboxPopupMediator alloc] self.mediator = [[OmniboxPopupMediator alloc]
initWithFetcher:std::move(imageFetcher) initWithFetcher:std::move(imageFetcher)
faviconLoader:IOSChromeFaviconLoaderFactory::GetForBrowserState( faviconLoader:IOSChromeFaviconLoaderFactory::GetForBrowserState(
self.browserState) self.browser->GetBrowserState())
delegate:_popupView.get()]; delegate:_popupView.get()];
self.mediator.dispatcher = (id<BrowserCommands>)self.dispatcher; // TODO(crbug.com/1045047): Use HandlerForProtocol after commands protocol
self.mediator.webStateList = self.webStateList; // clean up.
self.mediator.dispatcher =
static_cast<id<BrowserCommands>>(self.browser->GetCommandDispatcher());
self.mediator.webStateList = self.browser->GetWebStateList();
TemplateURLService* templateURLService = TemplateURLService* templateURLService =
ios::TemplateURLServiceFactory::GetForBrowserState(self.browserState); ios::TemplateURLServiceFactory::GetForBrowserState(
self.browser->GetBrowserState());
self.mediator.defaultSearchEngineIsGoogle = self.mediator.defaultSearchEngineIsGoogle =
templateURLService && templateURLService->GetDefaultSearchProvider() && templateURLService && templateURLService->GetDefaultSearchProvider() &&
templateURLService->GetDefaultSearchProvider()->GetEngineType( templateURLService->GetDefaultSearchProvider()->GetEngineType(
templateURLService->search_terms_data()) == SEARCH_ENGINE_GOOGLE; templateURLService->search_terms_data()) == SEARCH_ENGINE_GOOGLE;
self.popupViewController = [[OmniboxPopupViewController alloc] init]; self.popupViewController = [[OmniboxPopupViewController alloc] init];
self.popupViewController.incognito = self.browserState->IsOffTheRecord(); self.popupViewController.incognito =
self.browser->GetBrowserState()->IsOffTheRecord();
BOOL isIncognito = self.browserState->IsOffTheRecord(); BOOL isIncognito = self.browser->GetBrowserState()->IsOffTheRecord();
self.mediator.incognito = isIncognito; self.mediator.incognito = isIncognito;
self.mediator.consumer = self.popupViewController; self.mediator.consumer = self.popupViewController;
self.mediator.presenter = [[OmniboxPopupPresenter alloc] self.mediator.presenter = [[OmniboxPopupPresenter alloc]
...@@ -86,7 +92,7 @@ ...@@ -86,7 +92,7 @@
self.popupViewController.imageRetriever = self.mediator; self.popupViewController.imageRetriever = self.mediator;
self.popupViewController.faviconRetriever = self.mediator; self.popupViewController.faviconRetriever = self.mediator;
self.popupViewController.delegate = self.mediator; self.popupViewController.delegate = self.mediator;
[self.dispatcher [self.browser->GetCommandDispatcher()
startDispatchingToTarget:self.popupViewController startDispatchingToTarget:self.popupViewController
forProtocol:@protocol(OmniboxSuggestionCommands)]; forProtocol:@protocol(OmniboxSuggestionCommands)];
...@@ -95,7 +101,7 @@ ...@@ -95,7 +101,7 @@
- (void)stop { - (void)stop {
_popupView.reset(); _popupView.reset();
[self.dispatcher [self.browser->GetCommandDispatcher()
stopDispatchingForProtocol:@protocol(OmniboxSuggestionCommands)]; stopDispatchingForProtocol:@protocol(OmniboxSuggestionCommands)];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment