| OLD | NEW |
| 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 Loading... |
| 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 // Keeps find in page search term to be shared between different tabs. Never |
| 35 // reset, not stored on disk. |
| 36 static NSString* gSearchTerm; |
| 33 } | 37 } |
| 34 | 38 |
| 35 @interface FindInPageController () <DOMAltering, CRWWebStateObserver> | 39 @interface FindInPageController () <DOMAltering, CRWWebStateObserver> |
| 36 // The find in page controller delegate. | 40 // The find in page controller delegate. |
| 37 @property(nonatomic, readonly) id<FindInPageControllerDelegate> delegate; | 41 @property(nonatomic, readonly) id<FindInPageControllerDelegate> delegate; |
| 38 // The web view's scroll view. | 42 // The web view's scroll view. |
| 39 @property(nonatomic, readonly) CRWWebViewScrollViewProxy* webViewScrollView; | 43 @property(nonatomic, readonly) CRWWebViewScrollViewProxy* webViewScrollView; |
| 40 | 44 |
| 41 // Convenience method to obtain UIPasteboardNameFind from UIPasteBoard. | 45 // Sets the search term to |string|. Stored until the application quit. |
| 42 - (UIPasteboard*)findPasteboard; | 46 + (void)setSearchTerm:(NSString*)string; |
| 47 // The search term, stored until the application quit. |
| 48 + (NSString*)searchTerm; |
| 49 |
| 43 // Find in Page text field listeners. | 50 // Find in Page text field listeners. |
| 44 - (void)findBarTextFieldWillBecomeFirstResponder:(NSNotification*)note; | 51 - (void)findBarTextFieldWillBecomeFirstResponder:(NSNotification*)note; |
| 45 - (void)findBarTextFieldDidResignFirstResponder:(NSNotification*)note; | 52 - (void)findBarTextFieldDidResignFirstResponder:(NSNotification*)note; |
| 46 // Keyboard listeners. | 53 // Keyboard listeners. |
| 47 - (void)keyboardDidShow:(NSNotification*)note; | 54 - (void)keyboardDidShow:(NSNotification*)note; |
| 48 - (void)keyboardWillHide:(NSNotification*)note; | 55 - (void)keyboardWillHide:(NSNotification*)note; |
| 49 // Constantly injects the find string in page until | 56 // Constantly injects the find string in page until |
| 50 // |disableFindInPageWithCompletionHandler:| is called or the find operation is | 57 // |disableFindInPageWithCompletionHandler:| is called or the find operation is |
| 51 // complete. Calls |completionHandler| if the find operation is complete. | 58 // complete. Calls |completionHandler| if the find operation is complete. |
| 52 // |completionHandler| can be nil. | 59 // |completionHandler| can be nil. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 80 // True when a find is in progress. Used to avoid running JavaScript during | 87 // True when a find is in progress. Used to avoid running JavaScript during |
| 81 // disable when there is nothing to clear. | 88 // disable when there is nothing to clear. |
| 82 BOOL _findStringStarted; | 89 BOOL _findStringStarted; |
| 83 | 90 |
| 84 // Bridge to observe the web state from Objective-C. | 91 // Bridge to observe the web state from Objective-C. |
| 85 std::unique_ptr<web::WebStateObserverBridge> _webStateObserverBridge; | 92 std::unique_ptr<web::WebStateObserverBridge> _webStateObserverBridge; |
| 86 } | 93 } |
| 87 | 94 |
| 88 @synthesize delegate = _delegate; | 95 @synthesize delegate = _delegate; |
| 89 | 96 |
| 97 + (void)setSearchTerm:(NSString*)string { |
| 98 [gSearchTerm release]; |
| 99 gSearchTerm = [string copy]; |
| 100 } |
| 101 |
| 102 + (NSString*)searchTerm { |
| 103 return gSearchTerm; |
| 104 } |
| 105 |
| 90 - (id)initWithWebState:(web::WebState*)webState | 106 - (id)initWithWebState:(web::WebState*)webState |
| 91 delegate:(id<FindInPageControllerDelegate>)delegate { | 107 delegate:(id<FindInPageControllerDelegate>)delegate { |
| 92 self = [super init]; | 108 self = [super init]; |
| 93 if (self) { | 109 if (self) { |
| 94 DCHECK(delegate); | 110 DCHECK(delegate); |
| 95 _findInPageJsManager = base::mac::ObjCCastStrict<JsFindinpageManager>( | 111 _findInPageJsManager = base::mac::ObjCCastStrict<JsFindinpageManager>( |
| 96 [webState->GetJSInjectionReceiver() | 112 [webState->GetJSInjectionReceiver() |
| 97 instanceOfClass:[JsFindinpageManager class]]); | 113 instanceOfClass:[JsFindinpageManager class]]); |
| 98 _delegate = delegate; | 114 _delegate = delegate; |
| 99 _webStateObserverBridge.reset( | 115 _webStateObserverBridge.reset( |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 // handler. | 297 // handler. |
| 282 if (_findStringStarted) { | 298 if (_findStringStarted) { |
| 283 [_findInPageJsManager disableWithCompletionHandler:handler]; | 299 [_findInPageJsManager disableWithCompletionHandler:handler]; |
| 284 _findStringStarted = NO; | 300 _findStringStarted = NO; |
| 285 } else { | 301 } else { |
| 286 handler(); | 302 handler(); |
| 287 } | 303 } |
| 288 } | 304 } |
| 289 | 305 |
| 290 - (void)saveSearchTerm { | 306 - (void)saveSearchTerm { |
| 291 [self findPasteboard].string = [[self findInPageModel] text]; | 307 [[self class] setSearchTerm:[[self findInPageModel] text]]; |
| 292 } | 308 } |
| 293 | 309 |
| 294 - (void)restoreSearchTerm { | 310 - (void)restoreSearchTerm { |
| 295 // Pasteboards always return nil in background: | 311 // Pasteboards always return nil in background: |
| 296 if ([[UIApplication sharedApplication] applicationState] != | 312 if ([[UIApplication sharedApplication] applicationState] != |
| 297 UIApplicationStateActive) { | 313 UIApplicationStateActive) { |
| 298 return; | 314 return; |
| 299 } | 315 } |
| 300 | 316 |
| 301 NSString* term = [self findPasteboard].string; | 317 NSString* term = [[self class] searchTerm]; |
| 302 [[self findInPageModel] updateQuery:(term ? term : @"") matches:0]; | 318 [[self findInPageModel] updateQuery:(term ? term : @"") matches:0]; |
| 303 } | 319 } |
| 304 | 320 |
| 305 - (UIPasteboard*)findPasteboard { | |
| 306 return [UIPasteboard pasteboardWithName:UIPasteboardNameFind create:NO]; | |
| 307 } | |
| 308 | |
| 309 - (web::WebState*)webState { | 321 - (web::WebState*)webState { |
| 310 return _webStateObserverBridge ? _webStateObserverBridge->web_state() | 322 return _webStateObserverBridge ? _webStateObserverBridge->web_state() |
| 311 : nullptr; | 323 : nullptr; |
| 312 } | 324 } |
| 313 | 325 |
| 314 #pragma mark - Notification listeners | 326 #pragma mark - Notification listeners |
| 315 | 327 |
| 316 - (void)findBarTextFieldWillBecomeFirstResponder:(NSNotification*)note { | 328 - (void)findBarTextFieldWillBecomeFirstResponder:(NSNotification*)note { |
| 317 // Listen to the keyboard appearance notifications. | 329 // Listen to the keyboard appearance notifications. |
| 318 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; | 330 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 | 389 |
| 378 - (BOOL)canReleaseDOMLock { | 390 - (BOOL)canReleaseDOMLock { |
| 379 return NO; | 391 return NO; |
| 380 } | 392 } |
| 381 | 393 |
| 382 - (void)releaseDOMLockWithCompletionHandler:(ProceduralBlock)completionHandler { | 394 - (void)releaseDOMLockWithCompletionHandler:(ProceduralBlock)completionHandler { |
| 383 NOTREACHED(); | 395 NOTREACHED(); |
| 384 } | 396 } |
| 385 | 397 |
| 386 @end | 398 @end |
| OLD | NEW |