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

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

Issue 2250433003: Replaces find pasteboard with a static variable in Find in page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 12 matching lines...) Expand all
23 #import "ios/web/public/web_state/web_state_observer_bridge.h" 23 #import "ios/web/public/web_state/web_state_observer_bridge.h"
24 24
25 NSString* const kFindBarTextFieldWillBecomeFirstResponderNotification = 25 NSString* const kFindBarTextFieldWillBecomeFirstResponderNotification =
26 @"kFindBarTextFieldWillBecomeFirstResponderNotification"; 26 @"kFindBarTextFieldWillBecomeFirstResponderNotification";
27 NSString* const kFindBarTextFieldDidResignFirstResponderNotification = 27 NSString* const kFindBarTextFieldDidResignFirstResponderNotification =
28 @"kFindBarTextFieldDidResignFirstResponderNotification"; 28 @"kFindBarTextFieldDidResignFirstResponderNotification";
29 29
30 namespace { 30 namespace {
31 // The delay (in secs) after which the find in page string will be pumped again. 31 // The delay (in secs) after which the find in page string will be pumped again.
32 const NSTimeInterval kRecurringPumpDelay = .01; 32 const NSTimeInterval kRecurringPumpDelay = .01;
33
34 static NSString* staticSearchTerm;
Eugene But (OOO till 7-30) 2016/08/16 16:34:44 This should have comments per Objective-C Style Gu
Eugene But (OOO till 7-30) 2016/08/16 16:34:45 Please prefix globals with |g|, not with |static|:
stkhapugin 2016/08/16 16:45:57 There are no class variables in ObjC. Renaming don
stkhapugin 2016/08/16 16:45:57 Done.
Eugene But (OOO till 7-30) 2016/08/16 16:53:10 This is a class variable, no? @interface FindInPag
33 } 35 }
34 36
35 @interface FindInPageController () <DOMAltering, CRWWebStateObserver> 37 @interface FindInPageController () <DOMAltering, CRWWebStateObserver>
36 // The find in page controller delegate. 38 // The find in page controller delegate.
37 @property(nonatomic, readonly) id<FindInPageControllerDelegate> delegate; 39 @property(nonatomic, readonly) id<FindInPageControllerDelegate> delegate;
38 // The web view's scroll view. 40 // The web view's scroll view.
39 @property(nonatomic, readonly) CRWWebViewScrollViewProxy* webViewScrollView; 41 @property(nonatomic, readonly) CRWWebViewScrollViewProxy* webViewScrollView;
40 42
41 // Convenience method to obtain UIPasteboardNameFind from UIPasteBoard. 43 // Sets the search term to |string|. Stored until the application quit.
Eugene But (OOO till 7-30) 2016/08/16 16:34:45 Maybe move these comments to static variable so th
stkhapugin 2016/08/16 16:45:57 Since there are no class variables, I'll have to k
Eugene But (OOO till 7-30) 2016/08/16 16:53:11 Replied above about class variable. If you have gl
42 - (UIPasteboard*)findPasteboard; 44 + (void)setSearchTerm:(NSString*)string;
45 // The search term, stored until the application quit.
46 + (NSString*)searchTerm;
47
43 // Find in Page text field listeners. 48 // Find in Page text field listeners.
44 - (void)findBarTextFieldWillBecomeFirstResponder:(NSNotification*)note; 49 - (void)findBarTextFieldWillBecomeFirstResponder:(NSNotification*)note;
45 - (void)findBarTextFieldDidResignFirstResponder:(NSNotification*)note; 50 - (void)findBarTextFieldDidResignFirstResponder:(NSNotification*)note;
46 // Keyboard listeners. 51 // Keyboard listeners.
47 - (void)keyboardDidShow:(NSNotification*)note; 52 - (void)keyboardDidShow:(NSNotification*)note;
48 - (void)keyboardWillHide:(NSNotification*)note; 53 - (void)keyboardWillHide:(NSNotification*)note;
49 // Constantly injects the find string in page until 54 // Constantly injects the find string in page until
50 // |disableFindInPageWithCompletionHandler:| is called or the find operation is 55 // |disableFindInPageWithCompletionHandler:| is called or the find operation is
51 // complete. Calls |completionHandler| if the find operation is complete. 56 // complete. Calls |completionHandler| if the find operation is complete.
52 // |completionHandler| can be nil. 57 // |completionHandler| can be nil.
(...skipping 27 matching lines...) Expand all
80 // True when a find is in progress. Used to avoid running JavaScript during 85 // True when a find is in progress. Used to avoid running JavaScript during
81 // disable when there is nothing to clear. 86 // disable when there is nothing to clear.
82 BOOL _findStringStarted; 87 BOOL _findStringStarted;
83 88
84 // Bridge to observe the web state from Objective-C. 89 // Bridge to observe the web state from Objective-C.
85 std::unique_ptr<web::WebStateObserverBridge> _webStateObserverBridge; 90 std::unique_ptr<web::WebStateObserverBridge> _webStateObserverBridge;
86 } 91 }
87 92
88 @synthesize delegate = _delegate; 93 @synthesize delegate = _delegate;
89 94
95 + (void)setSearchTerm:(NSString*)string {
96 staticSearchTerm = [string copy];
97 }
98
99 + (NSString*)searchTerm {
100 return staticSearchTerm;
101 }
102
90 - (id)initWithWebState:(web::WebState*)webState 103 - (id)initWithWebState:(web::WebState*)webState
91 delegate:(id<FindInPageControllerDelegate>)delegate { 104 delegate:(id<FindInPageControllerDelegate>)delegate {
92 self = [super init]; 105 self = [super init];
93 if (self) { 106 if (self) {
94 DCHECK(delegate); 107 DCHECK(delegate);
95 _findInPageJsManager = base::mac::ObjCCastStrict<JsFindinpageManager>( 108 _findInPageJsManager = base::mac::ObjCCastStrict<JsFindinpageManager>(
96 [webState->GetJSInjectionReceiver() 109 [webState->GetJSInjectionReceiver()
97 instanceOfClass:[JsFindinpageManager class]]); 110 instanceOfClass:[JsFindinpageManager class]]);
98 _delegate = delegate; 111 _delegate = delegate;
99 _webStateObserverBridge.reset( 112 _webStateObserverBridge.reset(
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // handler. 294 // handler.
282 if (_findStringStarted) { 295 if (_findStringStarted) {
283 [_findInPageJsManager disableWithCompletionHandler:handler]; 296 [_findInPageJsManager disableWithCompletionHandler:handler];
284 _findStringStarted = NO; 297 _findStringStarted = NO;
285 } else { 298 } else {
286 handler(); 299 handler();
287 } 300 }
288 } 301 }
289 302
290 - (void)saveSearchTerm { 303 - (void)saveSearchTerm {
291 [self findPasteboard].string = [[self findInPageModel] text]; 304 [[FindInPageController class] setSearchTerm:[[self findInPageModel] text]];
Eugene But (OOO till 7-30) 2016/08/16 16:34:45 s/FindInPageController/self
stkhapugin 2016/08/16 16:45:57 Done.
292 } 305 }
293 306
294 - (void)restoreSearchTerm { 307 - (void)restoreSearchTerm {
295 // Pasteboards always return nil in background: 308 // Pasteboards always return nil in background:
296 if ([[UIApplication sharedApplication] applicationState] != 309 if ([[UIApplication sharedApplication] applicationState] !=
297 UIApplicationStateActive) { 310 UIApplicationStateActive) {
298 return; 311 return;
299 } 312 }
300 313
301 NSString* term = [self findPasteboard].string; 314 NSString* term = [[FindInPageController class] searchTerm];
Eugene But (OOO till 7-30) 2016/08/16 16:34:44 ditto
stkhapugin 2016/08/16 16:45:57 Done.
302 [[self findInPageModel] updateQuery:(term ? term : @"") matches:0]; 315 [[self findInPageModel] updateQuery:(term ? term : @"") matches:0];
303 } 316 }
304 317
305 - (UIPasteboard*)findPasteboard { 318 - (UIPasteboard*)findPasteboard {
Eugene But (OOO till 7-30) 2016/08/16 16:34:44 Is this still used?
stkhapugin 2016/08/16 16:45:57 No, good catch! Removed.
306 return [UIPasteboard pasteboardWithName:UIPasteboardNameFind create:NO]; 319 return [UIPasteboard pasteboardWithName:UIPasteboardNameFind create:NO];
307 } 320 }
308 321
309 - (web::WebState*)webState { 322 - (web::WebState*)webState {
310 return _webStateObserverBridge ? _webStateObserverBridge->web_state() 323 return _webStateObserverBridge ? _webStateObserverBridge->web_state()
311 : nullptr; 324 : nullptr;
312 } 325 }
313 326
314 #pragma mark - Notification listeners 327 #pragma mark - Notification listeners
315 328
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 390
378 - (BOOL)canReleaseDOMLock { 391 - (BOOL)canReleaseDOMLock {
379 return NO; 392 return NO;
380 } 393 }
381 394
382 - (void)releaseDOMLockWithCompletionHandler:(ProceduralBlock)completionHandler { 395 - (void)releaseDOMLockWithCompletionHandler:(ProceduralBlock)completionHandler {
383 NOTREACHED(); 396 NOTREACHED();
384 } 397 }
385 398
386 @end 399 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698