Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Unified Diff: ios/clean/chrome/browser/ui/find_in_page/find_in_page_coordinator.mm

Issue 2737563006: [ios] Adds support for Find in Page to the new architecture. (Closed)
Patch Set: ObjC mediator Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/clean/chrome/browser/ui/find_in_page/find_in_page_coordinator.mm
diff --git a/ios/clean/chrome/browser/ui/find_in_page/find_in_page_coordinator.mm b/ios/clean/chrome/browser/ui/find_in_page/find_in_page_coordinator.mm
new file mode 100644
index 0000000000000000000000000000000000000000..01362b3198e9a1ef0dd8c5e02733d87971420d60
--- /dev/null
+++ b/ios/clean/chrome/browser/ui/find_in_page/find_in_page_coordinator.mm
@@ -0,0 +1,107 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/clean/chrome/browser/ui/find_in_page/find_in_page_coordinator.h"
+
+#include <memory>
+
+#include "base/logging.h"
+#import "ios/chrome/browser/find_in_page/find_tab_helper.h"
+#import "ios/clean/chrome/browser/ui/commands/find_in_page_visibility_commands.h"
+#import "ios/clean/chrome/browser/ui/find_in_page/find_in_page_mediator.h"
+#import "ios/clean/chrome/browser/ui/find_in_page/find_in_page_view_controller.h"
+#include "ios/shared/chrome/browser/tabs/web_state_list.h"
+#import "ios/shared/chrome/browser/ui/browser_list/browser.h"
+#import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h"
+#import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+@interface FindInPageCoordinator ()<FindInPageVisibilityCommands,
+ FindInPageConsumerProvider>
+
+@property(nonatomic, strong) FindInPageMediator* mediator;
+
+@property(nonatomic, strong)
+ FindInPageViewController* viewController;
+
+@end
+
+@implementation FindInPageCoordinator
+
+@synthesize mediator = _mediator;
+@synthesize viewController = _viewController;
+
+#pragma mark - Coordinator lifecycle management
+
+- (void)dealloc {
+ // TODO(rohitrao): The __weak pointers in the CommandDispatcher appear to have
+ // already been zeroed out by this point, so stopDispatchingToTarget:self does
+ // not appear to properly delete the forwarding entries for this target. Work
+ // around this by calling stopDispatchingForSelector: instead.
+
+ CommandDispatcher* dispatcher = self.browser->dispatcher();
+ [dispatcher stopDispatchingForSelector:@selector(showFindInPage)];
+ [dispatcher stopDispatchingForSelector:@selector(hideFindInPage)];
+}
+
+- (void)wasAddedToParentCoordinator:(BrowserCoordinator*)parent {
+ DCHECK(self.browser);
+
+ // Register command handlers with the dispatcher.
+ CommandDispatcher* dispatcher = self.browser->dispatcher();
+ [dispatcher startDispatchingToTarget:self
+ forSelector:@selector(showFindInPage)];
+ [dispatcher startDispatchingToTarget:self
+ forSelector:@selector(hideFindInPage)];
+
+
+ _mediator = [[FindInPageMediator alloc] initWithWebStateList:(&self.browser->web_state_list()) provider:self dispatcher:static_cast<id>(dispatcher)];
+}
+
+- (void)wasRemovedFromParentCoordinator {
+ [self.browser->dispatcher() stopDispatchingToTarget:self];
+}
+
+- (void)start {
+ self.viewController = [[FindInPageViewController alloc] init];
+ self.viewController.dispatcher = static_cast<id>(self.browser->dispatcher());
+ [super start];
+}
+
+- (void)stop {
+ [super stop];
+ self.viewController = nil;
+}
+
+#pragma mark - Consumer provider
+
+- (id<FindInPageConsumer>)consumer {
+ if (!self.started) {
+ [self start];
+ }
+ DCHECK(self.viewController);
+ return self.viewController;
+}
+
+#pragma mark - Command handlers
+
+- (void)showFindInPage {
+ NSLog(@"showFindInPage command handler");
marq (ping after 24h) 2017/04/06 16:13:27 Remove logging.
rohitrao (ping after 24h) 2017/04/11 20:46:16 Done.
+ if (!self.started)
+ [self start];
+}
+
+- (void)hideFindInPage {
+ NSLog(@"hideFindInPage command handler");
+ web::WebState* webState = self.browser->web_state_list().GetActiveWebState();
+ FindTabHelper* helper = FindTabHelper::FromWebState(webState);
marq (ping after 24h) 2017/04/06 16:13:27 Feels like the mediator should be doing this part.
rohitrao (ping after 24h) 2017/04/06 16:27:07 Agreed, but I couldn't figure out how to push this
marq (ping after 24h) 2017/04/07 09:45:55 Would just replacing lines 100-102 with [self.medi
rohitrao (ping after 24h) 2017/04/11 20:46:16 Done, at the cost of a larger public API for the m
+ helper->StopFinding(nil);
+ if (self.started)
+ [self stop];
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698