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