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;
self.omniboxPopupCoordinator = [self.omniboxCoordinator
createPopupCoordinator:self.popupPresenterDelegate];
self.omniboxPopupCoordinator.dispatcher = self.dispatcher;
self.omniboxPopupCoordinator.webStateList = self.webStateList;
[self.omniboxPopupCoordinator start];
// Create button factory that wil be used by the ViewController to get
......
......@@ -161,9 +161,10 @@
_editView->model()->set_popup_model(popupView->model());
_editView->SetPopupProvider(popupView.get());
OmniboxPopupCoordinator* coordinator =
[[OmniboxPopupCoordinator alloc] initWithPopupView:std::move(popupView)];
coordinator.browserState = self.browser->GetBrowserState();
OmniboxPopupCoordinator* coordinator = [[OmniboxPopupCoordinator alloc]
initWithBaseViewController:nil
browser:self.browser
popupView:std::move(popupView)];
coordinator.presenterDelegate = presenterDelegate;
return coordinator;
......
......@@ -27,9 +27,11 @@ source_set("popup") {
"//ios/chrome/browser",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/favicon",
"//ios/chrome/browser/main:public",
"//ios/chrome/browser/search_engines",
"//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/ntp:util",
"//ios/chrome/browser/ui/omnibox:omnibox_util",
"//ios/chrome/browser/ui/toolbar/buttons",
......
......@@ -5,39 +5,39 @@
#ifndef 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>
class ChromeBrowserState;
@class CommandDispatcher;
@protocol OmniboxPopupPresenterDelegate;
@protocol OmniboxFocuser;
class OmniboxPopupViewIOS;
class WebStateList;
// Coordinator for the Omnibox Popup.
@interface OmniboxPopupCoordinator : NSObject
@interface OmniboxPopupCoordinator : ChromeCoordinator
- (instancetype)initWithPopupView:
(std::unique_ptr<OmniboxPopupViewIOS>)popupView NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)
initWithBaseViewController:(UIViewController*)viewController
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.
@property(nonatomic, weak) id<OmniboxPopupPresenterDelegate> presenterDelegate;
// Whether this coordinator has results to show.
@property(nonatomic, assign, readonly) BOOL hasResults;
// Whether the popup is open.
@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
......
......@@ -11,6 +11,7 @@
#import "components/search_engines/template_url_service.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.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"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/ntp/ntp_util.h"
......@@ -38,16 +39,16 @@
@implementation OmniboxPopupCoordinator
@synthesize browserState = _browserState;
@synthesize mediator = _mediator;
@synthesize popupViewController = _popupViewController;
@synthesize dispatcher = _dispatcher;
#pragma mark - Public
- (instancetype)initWithPopupView:
(std::unique_ptr<OmniboxPopupViewIOS>)popupView {
self = [super init];
- (instancetype)
initWithBaseViewController:(UIViewController*)viewController
browser:(Browser*)browser
popupView:(std::unique_ptr<OmniboxPopupViewIOS>)popupView {
self = [super initWithBaseViewController:nil browser:browser];
if (self) {
_popupView = std::move(popupView);
}
......@@ -57,26 +58,31 @@
- (void)start {
std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> imageFetcher =
std::make_unique<image_fetcher::IOSImageDataFetcherWrapper>(
self.browserState->GetSharedURLLoaderFactory());
self.browser->GetBrowserState()->GetSharedURLLoaderFactory());
self.mediator = [[OmniboxPopupMediator alloc]
initWithFetcher:std::move(imageFetcher)
faviconLoader:IOSChromeFaviconLoaderFactory::GetForBrowserState(
self.browserState)
self.browser->GetBrowserState())
delegate:_popupView.get()];
self.mediator.dispatcher = (id<BrowserCommands>)self.dispatcher;
self.mediator.webStateList = self.webStateList;
// TODO(crbug.com/1045047): Use HandlerForProtocol after commands protocol
// clean up.
self.mediator.dispatcher =
static_cast<id<BrowserCommands>>(self.browser->GetCommandDispatcher());
self.mediator.webStateList = self.browser->GetWebStateList();
TemplateURLService* templateURLService =
ios::TemplateURLServiceFactory::GetForBrowserState(self.browserState);
ios::TemplateURLServiceFactory::GetForBrowserState(
self.browser->GetBrowserState());
self.mediator.defaultSearchEngineIsGoogle =
templateURLService && templateURLService->GetDefaultSearchProvider() &&
templateURLService->GetDefaultSearchProvider()->GetEngineType(
templateURLService->search_terms_data()) == SEARCH_ENGINE_GOOGLE;
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.consumer = self.popupViewController;
self.mediator.presenter = [[OmniboxPopupPresenter alloc]
......@@ -86,7 +92,7 @@
self.popupViewController.imageRetriever = self.mediator;
self.popupViewController.faviconRetriever = self.mediator;
self.popupViewController.delegate = self.mediator;
[self.dispatcher
[self.browser->GetCommandDispatcher()
startDispatchingToTarget:self.popupViewController
forProtocol:@protocol(OmniboxSuggestionCommands)];
......@@ -95,7 +101,7 @@
- (void)stop {
_popupView.reset();
[self.dispatcher
[self.browser->GetCommandDispatcher()
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