Commit be3986df authored by edchin's avatar edchin Committed by Commit Bot

[ios] Migrate RepostForm from BVC

Change-Id: I4bec2b03fbc58dfa91e89fff059b9a0a5dbd8e5b
Reviewed-on: https://chromium-review.googlesource.com/c/1341448
Commit-Queue: edchin <edchin@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609778}
parent 42999ec4
...@@ -51,7 +51,6 @@ ...@@ -51,7 +51,6 @@
#import "ios/chrome/browser/web/load_timing_tab_helper.h" #import "ios/chrome/browser/web/load_timing_tab_helper.h"
#import "ios/chrome/browser/web/network_activity_indicator_tab_helper.h" #import "ios/chrome/browser/web/network_activity_indicator_tab_helper.h"
#import "ios/chrome/browser/web/page_placeholder_tab_helper.h" #import "ios/chrome/browser/web/page_placeholder_tab_helper.h"
#import "ios/chrome/browser/web/repost_form_tab_helper.h"
#import "ios/chrome/browser/web/tab_id_tab_helper.h" #import "ios/chrome/browser/web/tab_id_tab_helper.h"
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h" #import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/web/public/web_state/web_state.h" #import "ios/web/public/web_state/web_state.h"
......
...@@ -111,7 +111,6 @@ ...@@ -111,7 +111,6 @@
#import "ios/chrome/browser/ui/activity_services/activity_service_legacy_coordinator.h" #import "ios/chrome/browser/ui/activity_services/activity_service_legacy_coordinator.h"
#import "ios/chrome/browser/ui/activity_services/requirements/activity_service_presentation.h" #import "ios/chrome/browser/ui/activity_services/requirements/activity_service_presentation.h"
#import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h" #import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h"
#import "ios/chrome/browser/ui/alert_coordinator/repost_form_coordinator.h"
#import "ios/chrome/browser/ui/app_launcher/app_launcher_coordinator.h" #import "ios/chrome/browser/ui/app_launcher/app_launcher_coordinator.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/password_coordinator.h" #import "ios/chrome/browser/ui/autofill/manual_fill/password_coordinator.h"
#import "ios/chrome/browser/ui/background_generator.h" #import "ios/chrome/browser/ui/background_generator.h"
...@@ -220,7 +219,6 @@ ...@@ -220,7 +219,6 @@
#import "ios/chrome/browser/web/page_placeholder_tab_helper.h" #import "ios/chrome/browser/web/page_placeholder_tab_helper.h"
#include "ios/chrome/browser/web/print_tab_helper.h" #include "ios/chrome/browser/web/print_tab_helper.h"
#import "ios/chrome/browser/web/repost_form_tab_helper.h" #import "ios/chrome/browser/web/repost_form_tab_helper.h"
#import "ios/chrome/browser/web/repost_form_tab_helper_delegate.h"
#import "ios/chrome/browser/web/sad_tab_tab_helper.h" #import "ios/chrome/browser/web/sad_tab_tab_helper.h"
#include "ios/chrome/browser/web/web_state_printer.h" #include "ios/chrome/browser/web/web_state_printer.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h" #import "ios/chrome/browser/web_state_list/web_state_list.h"
...@@ -426,7 +424,6 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -426,7 +424,6 @@ NSString* const kBrowserViewControllerSnackbarCategory =
PageInfoPresentation, PageInfoPresentation,
PasswordControllerDelegate, PasswordControllerDelegate,
PreloadControllerDelegate, PreloadControllerDelegate,
RepostFormTabHelperDelegate,
SadTabCoordinatorDelegate, SadTabCoordinatorDelegate,
SideSwipeControllerDelegate, SideSwipeControllerDelegate,
SnapshotGeneratorDelegate, SnapshotGeneratorDelegate,
...@@ -534,9 +531,6 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -534,9 +531,6 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// Coordinator for Page Info UI. // Coordinator for Page Info UI.
PageInfoLegacyCoordinator* _pageInfoCoordinator; PageInfoLegacyCoordinator* _pageInfoCoordinator;
// Coordinator for displaying Repost Form dialog.
RepostFormCoordinator* _repostFormCoordinator;
ToolbarCoordinatorAdaptor* _toolbarCoordinatorAdaptor; ToolbarCoordinatorAdaptor* _toolbarCoordinatorAdaptor;
// The toolbar UI updater for the toolbar managed by |_toolbarCoordinator|. // The toolbar UI updater for the toolbar managed by |_toolbarCoordinator|.
...@@ -2857,7 +2851,6 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint ...@@ -2857,7 +2851,6 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint
SadTabTabHelper::CreateForWebState(tab.webState, _sadTabCoordinator); SadTabTabHelper::CreateForWebState(tab.webState, _sadTabCoordinator);
} }
PrintTabHelper::CreateForWebState(tab.webState, self); PrintTabHelper::CreateForWebState(tab.webState, self);
RepostFormTabHelper::CreateForWebState(tab.webState, self);
NetExportTabHelper::CreateForWebState(tab.webState, self); NetExportTabHelper::CreateForWebState(tab.webState, self);
CaptivePortalDetectorTabHelper::CreateForWebState(tab.webState, self); CaptivePortalDetectorTabHelper::CreateForWebState(tab.webState, self);
PassKitTabHelper::CreateForWebState(tab.webState, _passKitCoordinator); PassKitTabHelper::CreateForWebState(tab.webState, _passKitCoordinator);
...@@ -5266,25 +5259,6 @@ nativeContentHeaderHeightForPreloadController:(PreloadController*)controller ...@@ -5266,25 +5259,6 @@ nativeContentHeaderHeightForPreloadController:(PreloadController*)controller
[self.dispatcher printTab]; [self.dispatcher printTab];
} }
#pragma mark - RepostFormTabHelperDelegate
- (void)repostFormTabHelper:(RepostFormTabHelper*)helper
presentRepostFormDialogForWebState:(web::WebState*)webState
dialogAtPoint:(CGPoint)location
completionHandler:(void (^)(BOOL))completion {
_repostFormCoordinator =
[[RepostFormCoordinator alloc] initWithBaseViewController:self
dialogLocation:location
webState:webState
completionHandler:completion];
[_repostFormCoordinator start];
}
- (void)repostFormTabHelperDismissRepostFormDialog:
(RepostFormTabHelper*)helper {
_repostFormCoordinator = nil;
}
#pragma mark - TabStripPresentation #pragma mark - TabStripPresentation
- (BOOL)isTabStripFullyVisible { - (BOOL)isTabStripFullyVisible {
......
...@@ -27,6 +27,7 @@ source_set("main") { ...@@ -27,6 +27,7 @@ source_set("main") {
"//ios/chrome/browser/sessions:serialisation", "//ios/chrome/browser/sessions:serialisation",
"//ios/chrome/browser/tabs", "//ios/chrome/browser/tabs",
"//ios/chrome/browser/tabs:tabs_internal", "//ios/chrome/browser/tabs:tabs_internal",
"//ios/chrome/browser/ui/alert_coordinator",
"//ios/chrome/browser/ui/authentication/consent_bump", "//ios/chrome/browser/ui/authentication/consent_bump",
"//ios/chrome/browser/ui/autofill", "//ios/chrome/browser/ui/autofill",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
...@@ -35,6 +36,9 @@ source_set("main") { ...@@ -35,6 +36,9 @@ source_set("main") {
"//ios/chrome/browser/ui/reading_list", "//ios/chrome/browser/ui/reading_list",
"//ios/chrome/browser/ui/recent_tabs", "//ios/chrome/browser/ui/recent_tabs",
"//ios/chrome/browser/ui/snackbar", "//ios/chrome/browser/ui/snackbar",
"//ios/chrome/browser/web",
"//ios/chrome/browser/web:tab_helper_delegates",
"//ios/chrome/browser/web_state_list",
"//ios/public/provider/chrome/browser", "//ios/public/provider/chrome/browser",
] ]
public_deps = [ public_deps = [
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
#import "ios/chrome/browser/ui/main/browser_coordinator.h" #import "ios/chrome/browser/ui/main/browser_coordinator.h"
#include <memory>
#include "base/scoped_observer.h"
#import "ios/chrome/browser/ui/alert_coordinator/repost_form_coordinator.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_coordinator.h" #import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_coordinator.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_coordinator_delegate.h" #import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_coordinator_delegate.h"
#import "ios/chrome/browser/ui/autofill/form_input_accessory_coordinator.h" #import "ios/chrome/browser/ui/autofill/form_input_accessory_coordinator.h"
...@@ -16,13 +20,19 @@ ...@@ -16,13 +20,19 @@
#import "ios/chrome/browser/ui/reading_list/reading_list_coordinator.h" #import "ios/chrome/browser/ui/reading_list/reading_list_coordinator.h"
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_coordinator.h" #import "ios/chrome/browser/ui/recent_tabs/recent_tabs_coordinator.h"
#import "ios/chrome/browser/ui/snackbar/snackbar_coordinator.h" #import "ios/chrome/browser/ui/snackbar/snackbar_coordinator.h"
#import "ios/chrome/browser/web/repost_form_tab_helper.h"
#import "ios/chrome/browser/web/repost_form_tab_helper_delegate.h"
#include "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
@interface BrowserCoordinator ()<ConsentBumpCoordinatorDelegate, @interface BrowserCoordinator ()<ConsentBumpCoordinatorDelegate,
FormInputAccessoryCoordinatorDelegate> FormInputAccessoryCoordinatorDelegate,
RepostFormTabHelperDelegate,
WebStateListObserving>
// Handles command dispatching. // Handles command dispatching.
@property(nonatomic, strong) CommandDispatcher* dispatcher; @property(nonatomic, strong) CommandDispatcher* dispatcher;
...@@ -48,12 +58,21 @@ ...@@ -48,12 +58,21 @@
// Coordinator for Recent Tabs. // Coordinator for Recent Tabs.
@property(nonatomic, strong) RecentTabsCoordinator* recentTabsCoordinator; @property(nonatomic, strong) RecentTabsCoordinator* recentTabsCoordinator;
// Coordinator for displaying Repost Form dialog.
@property(nonatomic, strong) RepostFormCoordinator* repostFormCoordinator;
// Coordinator for displaying snackbars. // Coordinator for displaying snackbars.
@property(nonatomic, strong) SnackbarCoordinator* snackbarCoordinator; @property(nonatomic, strong) SnackbarCoordinator* snackbarCoordinator;
@end @end
@implementation BrowserCoordinator @implementation BrowserCoordinator {
// Observers for WebStateList.
std::unique_ptr<WebStateListObserverBridge> _webStateListObserverBridge;
std::unique_ptr<ScopedObserver<WebStateList, WebStateListObserver>>
_scopedWebStateListObserver;
}
@synthesize dispatcher = _dispatcher; @synthesize dispatcher = _dispatcher;
// Child coordinators // Child coordinators
@synthesize consentBumpCoordinator = _consentBumpCoordinator; @synthesize consentBumpCoordinator = _consentBumpCoordinator;
...@@ -61,6 +80,7 @@ ...@@ -61,6 +80,7 @@
@synthesize qrScannerCoordinator = _qrScannerCoordinator; @synthesize qrScannerCoordinator = _qrScannerCoordinator;
@synthesize readingListCoordinator = _readingListCoordinator; @synthesize readingListCoordinator = _readingListCoordinator;
@synthesize recentTabsCoordinator = _recentTabsCoordinator; @synthesize recentTabsCoordinator = _recentTabsCoordinator;
@synthesize repostFormCoordinator = _repostFormCoordinator;
@synthesize snackbarCoordinator = _snackbarCoordinator; @synthesize snackbarCoordinator = _snackbarCoordinator;
#pragma mark - ChromeCoordinator #pragma mark - ChromeCoordinator
...@@ -74,11 +94,15 @@ ...@@ -74,11 +94,15 @@
[self.dispatcher [self.dispatcher
startDispatchingToTarget:self startDispatchingToTarget:self
forProtocol:@protocol(BrowserCoordinatorCommands)]; forProtocol:@protocol(BrowserCoordinatorCommands)];
[self installDelegatesForAllWebStates];
[self addWebStateListObserver];
[super start]; [super start];
} }
- (void)stop { - (void)stop {
[super stop]; [super stop];
[self removeWebStateListObserver];
[self uninstallDelegatesForAllWebStates];
[self.dispatcher stopDispatchingToTarget:self]; [self.dispatcher stopDispatchingToTarget:self];
[self stopChildCoordinators]; [self stopChildCoordinators];
[self destroyViewController]; [self destroyViewController];
...@@ -92,7 +116,7 @@ ...@@ -92,7 +116,7 @@
BrowserViewControllerDependencyFactory* factory = BrowserViewControllerDependencyFactory* factory =
[[BrowserViewControllerDependencyFactory alloc] [[BrowserViewControllerDependencyFactory alloc]
initWithBrowserState:self.browserState initWithBrowserState:self.browserState
webStateList:[self.tabModel webStateList]]; webStateList:self.tabModel.webStateList];
_viewController = [[BrowserViewController alloc] _viewController = [[BrowserViewController alloc]
initWithTabModel:self.tabModel initWithTabModel:self.tabModel
browserState:self.browserState browserState:self.browserState
...@@ -131,6 +155,8 @@ ...@@ -131,6 +155,8 @@
/* RecentTabsCoordinator is created and started by a BrowserCommand */ /* RecentTabsCoordinator is created and started by a BrowserCommand */
/* RepostFormCoordinator is created and started by a delegate method */
self.snackbarCoordinator = [[SnackbarCoordinator alloc] init]; self.snackbarCoordinator = [[SnackbarCoordinator alloc] init];
self.snackbarCoordinator.dispatcher = self.dispatcher; self.snackbarCoordinator.dispatcher = self.dispatcher;
[self.snackbarCoordinator start]; [self.snackbarCoordinator start];
...@@ -153,6 +179,9 @@ ...@@ -153,6 +179,9 @@
[self.recentTabsCoordinator stop]; [self.recentTabsCoordinator stop];
self.recentTabsCoordinator = nil; self.recentTabsCoordinator = nil;
[self.repostFormCoordinator stop];
self.repostFormCoordinator = nil;
[self.snackbarCoordinator stop]; [self.snackbarCoordinator stop];
self.snackbarCoordinator = nil; self.snackbarCoordinator = nil;
} }
...@@ -245,4 +274,94 @@ ...@@ -245,4 +274,94 @@
showCreditCardSettingsFromViewController:self.viewController]; showCreditCardSettingsFromViewController:self.viewController];
} }
#pragma mark - RepostFormTabHelperDelegate
- (void)repostFormTabHelper:(RepostFormTabHelper*)helper
presentRepostFormDialogForWebState:(web::WebState*)webState
dialogAtPoint:(CGPoint)location
completionHandler:(void (^)(BOOL))completion {
self.repostFormCoordinator = [[RepostFormCoordinator alloc]
initWithBaseViewController:self.viewController
dialogLocation:location
webState:webState
completionHandler:completion];
[self.repostFormCoordinator start];
}
- (void)repostFormTabHelperDismissRepostFormDialog:
(RepostFormTabHelper*)helper {
[self.repostFormCoordinator stop];
self.repostFormCoordinator = nil;
}
// TODO(crbug.com/906525) : Move WebStateListObserving out of
// BrowserCoordinator.
#pragma mark - WebStateListObserving
- (void)webStateList:(WebStateList*)webStateList
didInsertWebState:(web::WebState*)webState
atIndex:(int)index
activating:(BOOL)activating {
[self installDelegatesForWebState:webState];
}
- (void)webStateList:(WebStateList*)webStateList
didReplaceWebState:(web::WebState*)oldWebState
withWebState:(web::WebState*)newWebState
atIndex:(int)index {
[self uninstallDelegatesForWebState:oldWebState];
[self installDelegatesForWebState:newWebState];
}
- (void)webStateList:(WebStateList*)webStateList
didDetachWebState:(web::WebState*)webState
atIndex:(int)index {
[self uninstallDelegatesForWebState:webState];
}
// TODO(crbug.com/906525) : Move out of BrowserCoordinator along with
// WebStateListObserving.
#pragma mark - Private WebState management methods
// Adds observer for WebStateList.
- (void)addWebStateListObserver {
_webStateListObserverBridge =
std::make_unique<WebStateListObserverBridge>(self);
_scopedWebStateListObserver =
std::make_unique<ScopedObserver<WebStateList, WebStateListObserver>>(
_webStateListObserverBridge.get());
_scopedWebStateListObserver->Add(self.tabModel.webStateList);
}
// Removes observer for WebStateList.
- (void)removeWebStateListObserver {
_scopedWebStateListObserver.reset();
_webStateListObserverBridge.reset();
}
// Installs delegates for each WebState in WebStateList.
- (void)installDelegatesForAllWebStates {
for (int i = 0; i < self.tabModel.webStateList->count(); i++) {
web::WebState* webState = self.tabModel.webStateList->GetWebStateAt(i);
[self installDelegatesForWebState:webState];
}
}
// Uninstalls delegates for each WebState in WebStateList.
- (void)uninstallDelegatesForAllWebStates {
for (int i = 0; i < self.tabModel.webStateList->count(); i++) {
web::WebState* webState = self.tabModel.webStateList->GetWebStateAt(i);
[self uninstallDelegatesForWebState:webState];
}
}
// Install delegates for |webState|.
- (void)installDelegatesForWebState:(web::WebState*)webState {
RepostFormTabHelper::CreateForWebState(webState, self);
}
// Uninstalls delegates for |webState|.
- (void)uninstallDelegatesForWebState:(web::WebState*)webState {
}
@end @end
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