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

Side by Side Diff: ios/chrome/browser/find_in_page/find_in_page_controller.mm

Issue 2685393004: [ios] Hoists the FindInPageModel up into the controller. (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/find_in_page/find_in_page_controller.h" 5 #import "ios/chrome/browser/find_in_page/find_in_page_controller.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #import <cmath> 9 #import <cmath>
10 #include <memory> 10 #include <memory>
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 // True when a find is in progress. Used to avoid running JavaScript during 84 // True when a find is in progress. Used to avoid running JavaScript during
85 // disable when there is nothing to clear. 85 // disable when there is nothing to clear.
86 BOOL _findStringStarted; 86 BOOL _findStringStarted;
87 87
88 // Bridge to observe the web state from Objective-C. 88 // Bridge to observe the web state from Objective-C.
89 std::unique_ptr<web::WebStateObserverBridge> _webStateObserverBridge; 89 std::unique_ptr<web::WebStateObserverBridge> _webStateObserverBridge;
90 } 90 }
91 91
92 @synthesize delegate = _delegate; 92 @synthesize delegate = _delegate;
93 @synthesize findInPageModel = _findInPageModel;
93 94
94 + (void)setSearchTerm:(NSString*)string { 95 + (void)setSearchTerm:(NSString*)string {
95 gSearchTerm = [string copy]; 96 gSearchTerm = [string copy];
96 } 97 }
97 98
98 + (NSString*)searchTerm { 99 + (NSString*)searchTerm {
99 return gSearchTerm; 100 return gSearchTerm;
100 } 101 }
101 102
102 - (id)initWithWebState:(web::WebState*)webState 103 - (id)initWithWebState:(web::WebState*)webState
103 delegate:(id<FindInPageControllerDelegate>)delegate { 104 delegate:(id<FindInPageControllerDelegate>)delegate {
104 self = [super init]; 105 self = [super init];
105 if (self) { 106 if (self) {
107 _findInPageModel = [[FindInPageModel alloc] init];
106 _findInPageJsManager = base::mac::ObjCCastStrict<JsFindinpageManager>( 108 _findInPageJsManager = base::mac::ObjCCastStrict<JsFindinpageManager>(
107 [webState->GetJSInjectionReceiver() 109 [webState->GetJSInjectionReceiver()
108 instanceOfClass:[JsFindinpageManager class]]); 110 instanceOfClass:[JsFindinpageManager class]]);
111 _findInPageJsManager.findInPageModel = _findInPageModel;
justincohen 2017/02/13 18:09:36 Does this need to be nilled out on dealloc of fipc
rohitrao (ping after 24h) 2017/02/14 14:52:49 I made it a strong reference, so the JS manager wi
109 _delegate = delegate; 112 _delegate = delegate;
110 _webStateObserverBridge.reset( 113 _webStateObserverBridge.reset(
111 new web::WebStateObserverBridge(webState, self)); 114 new web::WebStateObserverBridge(webState, self));
112 _webViewProxy = webState->GetWebViewProxy(); 115 _webViewProxy = webState->GetWebViewProxy();
113 [[NSNotificationCenter defaultCenter] 116 [[NSNotificationCenter defaultCenter]
114 addObserver:self 117 addObserver:self
115 selector:@selector(findBarTextFieldWillBecomeFirstResponder:) 118 selector:@selector(findBarTextFieldWillBecomeFirstResponder:)
116 name:kFindBarTextFieldWillBecomeFirstResponderNotification 119 name:kFindBarTextFieldWillBecomeFirstResponderNotification
117 object:nil]; 120 object:nil];
118 [[NSNotificationCenter defaultCenter] 121 [[NSNotificationCenter defaultCenter]
119 addObserver:self 122 addObserver:self
120 selector:@selector(findBarTextFieldDidResignFirstResponder:) 123 selector:@selector(findBarTextFieldDidResignFirstResponder:)
121 name:kFindBarTextFieldDidResignFirstResponderNotification 124 name:kFindBarTextFieldDidResignFirstResponderNotification
122 object:nil]; 125 object:nil];
123 DOMAlteringLock::CreateForWebState(webState); 126 DOMAlteringLock::CreateForWebState(webState);
124 } 127 }
125 return self; 128 return self;
126 } 129 }
127 130
128 - (void)dealloc { 131 - (void)dealloc {
129 [[NSNotificationCenter defaultCenter] removeObserver:self]; 132 [[NSNotificationCenter defaultCenter] removeObserver:self];
130 } 133 }
131 134
132 - (FindInPageModel*)findInPageModel {
133 return [_findInPageJsManager findInPageModel];
134 }
135
136 - (BOOL)canFindInPage { 135 - (BOOL)canFindInPage {
137 return [_webViewProxy hasSearchableTextContent]; 136 return [_webViewProxy hasSearchableTextContent];
138 } 137 }
139 138
140 - (void)initFindInPage { 139 - (void)initFindInPage {
141 [_findInPageJsManager inject]; 140 [_findInPageJsManager inject];
142 141
143 // Initialize the module with our frame size. 142 // Initialize the module with our frame size.
144 CGRect frame = [_webViewProxy bounds]; 143 CGRect frame = [_webViewProxy bounds];
145 [_findInPageJsManager setWidth:frame.size.width height:frame.size.height]; 144 [_findInPageJsManager setWidth:frame.size.width height:frame.size.height];
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 373
375 - (BOOL)canReleaseDOMLock { 374 - (BOOL)canReleaseDOMLock {
376 return NO; 375 return NO;
377 } 376 }
378 377
379 - (void)releaseDOMLockWithCompletionHandler:(ProceduralBlock)completionHandler { 378 - (void)releaseDOMLockWithCompletionHandler:(ProceduralBlock)completionHandler {
380 NOTREACHED(); 379 NOTREACHED();
381 } 380 }
382 381
383 @end 382 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698