Commit 62f08a54 authored by Nazerke's avatar Nazerke Committed by Commit Bot

[iOS][coordinator] Modernize Location Bar Coordinator.

This CL modernizes the LocationBarCoordinator
 - to use |browser| in the initializer
 - to use self.browser to get browserstate, webstatelist and
dispatcher values.

Bug: 1029346, 1048686
Change-Id: I87e10f13748c477b841dadb42249bfd89860d9c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2078453Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Nazerke Kalidolda <nazerke@google.com>
Cr-Commit-Position: refs/heads/master@{#746465}
parent 9be8bffa
......@@ -51,6 +51,7 @@ source_set("location_bar") {
"//ios/chrome/browser/ui/badges",
"//ios/chrome/browser/ui/badges:public",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/elements",
"//ios/chrome/browser/ui/fullscreen",
"//ios/chrome/browser/ui/fullscreen:ui",
......
......@@ -5,16 +5,12 @@
#ifndef IOS_CHROME_BROWSER_UI_LOCATION_BAR_LOCATION_BAR_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_LOCATION_BAR_LOCATION_BAR_COORDINATOR_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
#import "ios/chrome/browser/ui/location_bar/location_bar_url_loader.h"
#import "ios/chrome/browser/ui/omnibox/location_bar_delegate.h"
#import "ios/chrome/browser/ui/toolbar/public/omnibox_focuser.h"
@class CommandDispatcher;
@protocol ApplicationCommands;
class Browser;
@protocol BrowserCommands;
@protocol EditViewAnimatee;
@protocol LocationBarAnimatee;
@protocol OmniboxPopupPresenterDelegate;
......@@ -22,17 +18,20 @@ class Browser;
// Location bar coordinator.
@interface LocationBarCoordinator
: NSObject<LocationBarURLLoader, OmniboxFocuser>
: ChromeCoordinator <LocationBarURLLoader, OmniboxFocuser>
// Unavailable, use -initWithBaseViewController:browser:.
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
NS_UNAVAILABLE;
// Unavailable, use -initWithBaseViewController:browser:.
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browserState:(ChromeBrowserState*)browserState
NS_UNAVAILABLE;
// Command dispatcher.
@property(nonatomic, strong) CommandDispatcher* commandDispatcher;
// View controller containing the omnibox.
@property(nonatomic, strong, readonly)
UIViewController* locationBarViewController;
// The location bar's Browser.
@property(nonatomic, assign) Browser* browser;
// The dispatcher for this view controller.
@property(nonatomic, weak) CommandDispatcher* dispatcher;
// Delegate for this coordinator.
// TODO(crbug.com/799446): Change this.
@property(nonatomic, weak) id<ToolbarCoordinatorDelegate> delegate;
......@@ -40,11 +39,6 @@ class Browser;
@property(nonatomic, weak) id<OmniboxPopupPresenterDelegate>
popupPresenterDelegate;
// Start this coordinator.
- (void)start;
// Stop this coordinator.
- (void)stop;
// Indicates whether the popup has results to show or not.
- (BOOL)omniboxPopupHasAutocompleteResults;
......
......@@ -123,15 +123,15 @@ const int kLocationAuthorizationStatusCount = 5;
}
- (void)start {
DCHECK(self.commandDispatcher);
DCHECK(self.browser);
if (self.started)
return;
[self.commandDispatcher startDispatchingToTarget:self
forProtocol:@protocol(OmniboxFocuser)];
[self.commandDispatcher
[self.browser->GetCommandDispatcher()
startDispatchingToTarget:self
forProtocol:@protocol(OmniboxFocuser)];
[self.browser->GetCommandDispatcher()
startDispatchingToTarget:self
forProtocol:@protocol(LoadQueryCommands)];
......@@ -140,9 +140,12 @@ const int kLocationAuthorizationStatusCount = 5;
self.viewController = [[LocationBarViewController alloc] init];
self.viewController.incognito = isIncognito;
self.viewController.delegate = self;
// TODO(crbug.com/1045047): Use HandlerForProtocol after commands protocol
// clean up.
self.viewController.dispatcher =
static_cast<id<ActivityServiceCommands, BrowserCommands,
ApplicationCommands, LoadQueryCommands>>(self.dispatcher);
ApplicationCommands, LoadQueryCommands>>(
self.browser->GetCommandDispatcher());
self.viewController.voiceSearchEnabled = ios::GetChromeBrowserProvider()
->GetVoiceSearchProvider()
->IsVoiceSearchEnabled();
......@@ -182,9 +185,11 @@ const int kLocationAuthorizationStatusCount = 5;
// Create BadgeMediator and set the viewController as its consumer.
self.badgeMediator = [[BadgeMediator alloc] initWithBrowser:self.browser];
self.badgeMediator.consumer = self.badgeViewController;
// TODO(crbug.com/1045047): Use HandlerForProtocol after commands protocol
// clean up.
self.badgeMediator.dispatcher =
static_cast<id<InfobarCommands, BrowserCoordinatorCommands>>(
self.dispatcher);
self.browser->GetCommandDispatcher());
buttonFactory.delegate = self.badgeMediator;
FullscreenController* fullscreenController =
FullscreenController::FromBrowserState(self.browserState);
......@@ -209,7 +214,7 @@ const int kLocationAuthorizationStatusCount = 5;
- (void)stop {
if (!self.started)
return;
[self.commandDispatcher stopDispatchingToTarget:self];
[self.browser->GetCommandDispatcher() stopDispatchingToTarget:self];
// The popup has to be destroyed before the location bar.
[self.omniboxPopupCoordinator stop];
[self.omniboxCoordinator stop];
......
......@@ -18,7 +18,6 @@
#include "ios/chrome/browser/favicon/ios_chrome_large_icon_service_factory.h"
#import "ios/chrome/browser/main/test_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/toolbar/toolbar_coordinator_delegate.h"
#include "ios/chrome/browser/url_loading/test_url_loading_service.h"
#include "ios/chrome/browser/url_loading/url_loading_params.h"
......@@ -109,10 +108,10 @@ class LocationBarCoordinatorTest : public PlatformTest {
delegate_ = [[TestToolbarCoordinatorDelegate alloc] init];
coordinator_ = [[LocationBarCoordinator alloc] init];
coordinator_.browser = browser_.get();
coordinator_ = [[LocationBarCoordinator alloc]
initWithBaseViewController:nil
browser:browser_.get()];
coordinator_.delegate = delegate_;
coordinator_.commandDispatcher = [[CommandDispatcher alloc] init];
}
void TearDown() override {
......
......@@ -208,12 +208,9 @@
// Sets the location bar up.
- (void)setUpLocationBar {
self.locationBarCoordinator = [[LocationBarCoordinator alloc] init];
self.locationBarCoordinator.browser = self.browser;
self.locationBarCoordinator.dispatcher = self.browser->GetCommandDispatcher();
self.locationBarCoordinator.commandDispatcher =
self.browser->GetCommandDispatcher();
self.locationBarCoordinator =
[[LocationBarCoordinator alloc] initWithBaseViewController:nil
browser:self.browser];
self.locationBarCoordinator.delegate = self.delegate;
self.locationBarCoordinator.popupPresenterDelegate =
self.popupPresenterDelegate;
......
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