OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/autofill/form_input_accessory_view_controller.h" | 5 #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/ios/block_types.h" | 9 #include "base/ios/block_types.h" |
10 #include "base/ios/ios_util.h" | 10 #include "base/ios/ios_util.h" |
11 #include "base/mac/foundation_util.h" | 11 #include "base/mac/foundation_util.h" |
12 #include "base/mac/scoped_block.h" | 12 #include "base/mac/scoped_block.h" |
13 #include "base/mac/scoped_nsobject.h" | |
14 #import "components/autofill/core/browser/keyboard_accessory_metrics_logger.h" | 13 #import "components/autofill/core/browser/keyboard_accessory_metrics_logger.h" |
15 #import "components/autofill/ios/browser/js_suggestion_manager.h" | 14 #import "components/autofill/ios/browser/js_suggestion_manager.h" |
16 #import "ios/chrome/browser/autofill/form_input_accessory_view.h" | 15 #import "ios/chrome/browser/autofill/form_input_accessory_view.h" |
17 #import "ios/chrome/browser/autofill/form_suggestion_view.h" | 16 #import "ios/chrome/browser/autofill/form_suggestion_view.h" |
18 #import "ios/chrome/browser/passwords/password_generation_utils.h" | 17 #import "ios/chrome/browser/passwords/password_generation_utils.h" |
19 #include "ios/chrome/browser/ui/ui_util.h" | 18 #include "ios/chrome/browser/ui/ui_util.h" |
20 #import "ios/web/public/url_scheme_util.h" | 19 #import "ios/web/public/url_scheme_util.h" |
21 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" | 20 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
22 #import "ios/web/public/web_state/ui/crw_web_view_proxy.h" | 21 #import "ios/web/public/web_state/ui/crw_web_view_proxy.h" |
23 #include "ios/web/public/web_state/url_verification_constants.h" | 22 #include "ios/web/public/web_state/url_verification_constants.h" |
24 #include "ios/web/public/web_state/web_state.h" | 23 #include "ios/web/public/web_state/web_state.h" |
25 #include "url/gurl.h" | 24 #include "url/gurl.h" |
26 | 25 |
| 26 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 27 #error "This file requires ARC support." |
| 28 #endif |
| 29 |
27 namespace autofill { | 30 namespace autofill { |
28 NSString* const kFormSuggestionAssistButtonPreviousElement = @"previousTap"; | 31 NSString* const kFormSuggestionAssistButtonPreviousElement = @"previousTap"; |
29 NSString* const kFormSuggestionAssistButtonNextElement = @"nextTap"; | 32 NSString* const kFormSuggestionAssistButtonNextElement = @"nextTap"; |
30 NSString* const kFormSuggestionAssistButtonDone = @"done"; | 33 NSString* const kFormSuggestionAssistButtonDone = @"done"; |
31 CGFloat const kInputAccessoryHeight = 44.0f; | 34 CGFloat const kInputAccessoryHeight = 44.0f; |
32 } // namespace autofill | 35 } // namespace autofill |
33 | 36 |
34 namespace { | 37 namespace { |
35 | 38 |
36 // Finds all views of a particular kind if class |klass| in the subview | 39 // Finds all views of a particular kind if class |klass| in the subview |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 94 } |
92 | 95 |
93 return descendants; | 96 return descendants; |
94 } | 97 } |
95 | 98 |
96 NSArray* FindDescendantToolbarItemsForActionName( | 99 NSArray* FindDescendantToolbarItemsForActionName( |
97 UITextInputAssistantItem* inputAssistantItem, | 100 UITextInputAssistantItem* inputAssistantItem, |
98 NSString* actionName) { | 101 NSString* actionName) { |
99 NSMutableArray* toolbarItems = [NSMutableArray array]; | 102 NSMutableArray* toolbarItems = [NSMutableArray array]; |
100 | 103 |
101 base::scoped_nsobject<NSMutableArray> buttonGroupsGroup( | 104 NSMutableArray* buttonGroupsGroup = [[NSMutableArray alloc] init]; |
102 [[NSMutableArray alloc] init]); | |
103 if (inputAssistantItem.leadingBarButtonGroups) | 105 if (inputAssistantItem.leadingBarButtonGroups) |
104 [buttonGroupsGroup addObject:inputAssistantItem.leadingBarButtonGroups]; | 106 [buttonGroupsGroup addObject:inputAssistantItem.leadingBarButtonGroups]; |
105 if (inputAssistantItem.trailingBarButtonGroups) | 107 if (inputAssistantItem.trailingBarButtonGroups) |
106 [buttonGroupsGroup addObject:inputAssistantItem.trailingBarButtonGroups]; | 108 [buttonGroupsGroup addObject:inputAssistantItem.trailingBarButtonGroups]; |
107 for (NSArray* buttonGroups in buttonGroupsGroup.get()) { | 109 for (NSArray* buttonGroups in buttonGroupsGroup) { |
108 for (UIBarButtonItemGroup* group in buttonGroups) { | 110 for (UIBarButtonItemGroup* group in buttonGroups) { |
109 NSArray* items = group.barButtonItems; | 111 NSArray* items = group.barButtonItems; |
110 for (UIBarButtonItem* item in items) { | 112 for (UIBarButtonItem* item in items) { |
111 if (ItemActionMatchesName(item, actionName)) | 113 if (ItemActionMatchesName(item, actionName)) |
112 [toolbarItems addObject:item]; | 114 [toolbarItems addObject:item]; |
113 } | 115 } |
114 } | 116 } |
115 } | 117 } |
116 | 118 |
117 return toolbarItems; | 119 return toolbarItems; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 @end | 195 @end |
194 | 196 |
195 @implementation FormInputAccessoryViewController { | 197 @implementation FormInputAccessoryViewController { |
196 // Bridge to observe the web state from Objective-C. | 198 // Bridge to observe the web state from Objective-C. |
197 std::unique_ptr<web::WebStateObserverBridge> _webStateObserverBridge; | 199 std::unique_ptr<web::WebStateObserverBridge> _webStateObserverBridge; |
198 | 200 |
199 // Last registered keyboard rectangle. | 201 // Last registered keyboard rectangle. |
200 CGRect _keyboardFrame; | 202 CGRect _keyboardFrame; |
201 | 203 |
202 // The custom view that should be shown in the input accessory view. | 204 // The custom view that should be shown in the input accessory view. |
203 base::scoped_nsobject<UIView> _customAccessoryView; | 205 UIView* _customAccessoryView; |
204 | 206 |
205 // The JS manager for interacting with the underlying form. | 207 // The JS manager for interacting with the underlying form. |
206 base::scoped_nsobject<JsSuggestionManager> _JSSuggestionManager; | 208 JsSuggestionManager* _JSSuggestionManager; |
207 | 209 |
208 // The original subviews in keyboard accessory view that were originally not | 210 // The original subviews in keyboard accessory view that were originally not |
209 // hidden but were hidden when showing Autofill suggestions. | 211 // hidden but were hidden when showing Autofill suggestions. |
210 base::scoped_nsobject<NSMutableArray> _hiddenOriginalSubviews; | 212 NSMutableArray* _hiddenOriginalSubviews; |
211 | 213 |
212 // The objects that can provide a custom input accessory view while filling | 214 // The objects that can provide a custom input accessory view while filling |
213 // forms. | 215 // forms. |
214 base::scoped_nsobject<NSArray> _providers; | 216 NSArray* _providers; |
215 | 217 |
216 // Whether suggestions have previously been shown. | 218 // Whether suggestions have previously been shown. |
217 BOOL _suggestionsHaveBeenShown; | 219 BOOL _suggestionsHaveBeenShown; |
218 | 220 |
219 // The object that manages the currently-shown custom accessory view. | 221 // The object that manages the currently-shown custom accessory view. |
220 base::WeakNSProtocol<id<FormInputAccessoryViewProvider>> _currentProvider; | 222 __weak id<FormInputAccessoryViewProvider> _currentProvider; |
221 | 223 |
222 // Logs UMA metrics for the keyboard accessory. | 224 // Logs UMA metrics for the keyboard accessory. |
223 std::unique_ptr<autofill::KeyboardAccessoryMetricsLogger> | 225 std::unique_ptr<autofill::KeyboardAccessoryMetricsLogger> |
224 _keyboardAccessoryMetricsLogger; | 226 _keyboardAccessoryMetricsLogger; |
225 } | 227 } |
226 | 228 |
227 - (instancetype)initWithWebState:(web::WebState*)webState | 229 - (instancetype)initWithWebState:(web::WebState*)webState |
228 providers:(NSArray*)providers { | 230 providers:(NSArray*)providers { |
229 JsSuggestionManager* suggestionManager = | 231 JsSuggestionManager* suggestionManager = |
230 base::mac::ObjCCastStrict<JsSuggestionManager>( | 232 base::mac::ObjCCastStrict<JsSuggestionManager>( |
231 [webState->GetJSInjectionReceiver() | 233 [webState->GetJSInjectionReceiver() |
232 instanceOfClass:[JsSuggestionManager class]]); | 234 instanceOfClass:[JsSuggestionManager class]]); |
233 return [self initWithWebState:webState | 235 return [self initWithWebState:webState |
234 JSSuggestionManager:suggestionManager | 236 JSSuggestionManager:suggestionManager |
235 providers:providers]; | 237 providers:providers]; |
236 } | 238 } |
237 | 239 |
238 - (instancetype)initWithWebState:(web::WebState*)webState | 240 - (instancetype)initWithWebState:(web::WebState*)webState |
239 JSSuggestionManager:(JsSuggestionManager*)JSSuggestionManager | 241 JSSuggestionManager:(JsSuggestionManager*)JSSuggestionManager |
240 providers:(NSArray*)providers { | 242 providers:(NSArray*)providers { |
241 self = [super init]; | 243 self = [super init]; |
242 if (self) { | 244 if (self) { |
243 _JSSuggestionManager.reset([JSSuggestionManager retain]); | 245 _JSSuggestionManager = JSSuggestionManager; |
244 _hiddenOriginalSubviews.reset([[NSMutableArray alloc] init]); | 246 _hiddenOriginalSubviews = [[NSMutableArray alloc] init]; |
245 _webStateObserverBridge.reset( | 247 _webStateObserverBridge.reset( |
246 new web::WebStateObserverBridge(webState, self)); | 248 new web::WebStateObserverBridge(webState, self)); |
247 _providers.reset([providers copy]); | 249 _providers = [providers copy]; |
248 _suggestionsHaveBeenShown = NO; | 250 _suggestionsHaveBeenShown = NO; |
249 _keyboardAccessoryMetricsLogger.reset( | 251 _keyboardAccessoryMetricsLogger.reset( |
250 new autofill::KeyboardAccessoryMetricsLogger()); | 252 new autofill::KeyboardAccessoryMetricsLogger()); |
251 } | 253 } |
252 return self; | 254 return self; |
253 } | 255 } |
254 | 256 |
255 - (void)wasShown { | 257 - (void)wasShown { |
256 // There is no defined relation on the timing of JavaScript events and | 258 // There is no defined relation on the timing of JavaScript events and |
257 // keyboard showing up. So it is necessary to listen to the keyboard | 259 // keyboard showing up. So it is necessary to listen to the keyboard |
(...skipping 27 matching lines...) Expand all Loading... |
285 object:nil]; | 287 object:nil]; |
286 } | 288 } |
287 | 289 |
288 - (void)wasHidden { | 290 - (void)wasHidden { |
289 [_customAccessoryView removeFromSuperview]; | 291 [_customAccessoryView removeFromSuperview]; |
290 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 292 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
291 } | 293 } |
292 | 294 |
293 - (void)dealloc { | 295 - (void)dealloc { |
294 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 296 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
295 [super dealloc]; | |
296 } | 297 } |
297 | 298 |
298 - (web::WebState*)webState { | 299 - (web::WebState*)webState { |
299 return _webStateObserverBridge ? _webStateObserverBridge->web_state() | 300 return _webStateObserverBridge ? _webStateObserverBridge->web_state() |
300 : nullptr; | 301 : nullptr; |
301 } | 302 } |
302 | 303 |
303 - (id<CRWWebViewProxy>)webViewProxy { | 304 - (id<CRWWebViewProxy>)webViewProxy { |
304 return self.webState ? self.webState->GetWebViewProxy() : nil; | 305 return self.webState ? self.webState->GetWebViewProxy() : nil; |
305 } | 306 } |
(...skipping 11 matching lines...) Expand all Loading... |
317 DCHECK(view); | 318 DCHECK(view); |
318 if (IsIPadIdiom()) { | 319 if (IsIPadIdiom()) { |
319 // On iPads running iOS 9 or later, there's no inputAccessoryView available | 320 // On iPads running iOS 9 or later, there's no inputAccessoryView available |
320 // so we attach the custom view directly to the keyboard view instead. | 321 // so we attach the custom view directly to the keyboard view instead. |
321 [_customAccessoryView removeFromSuperview]; | 322 [_customAccessoryView removeFromSuperview]; |
322 | 323 |
323 // If the keyboard isn't visible don't show the custom view. | 324 // If the keyboard isn't visible don't show the custom view. |
324 if (CGRectIntersection([UIScreen mainScreen].bounds, _keyboardFrame) | 325 if (CGRectIntersection([UIScreen mainScreen].bounds, _keyboardFrame) |
325 .size.height == 0 || | 326 .size.height == 0 || |
326 CGRectEqualToRect(_keyboardFrame, CGRectZero)) { | 327 CGRectEqualToRect(_keyboardFrame, CGRectZero)) { |
327 _customAccessoryView.reset(); | 328 _customAccessoryView = nil; |
328 return; | 329 return; |
329 } | 330 } |
330 | 331 |
331 // If this is a form suggestion view and no suggestions have been triggered | 332 // If this is a form suggestion view and no suggestions have been triggered |
332 // yet, don't show the custom view. | 333 // yet, don't show the custom view. |
333 FormSuggestionView* formSuggestionView = | 334 FormSuggestionView* formSuggestionView = |
334 base::mac::ObjCCast<FormSuggestionView>(view); | 335 base::mac::ObjCCast<FormSuggestionView>(view); |
335 if (formSuggestionView) { | 336 if (formSuggestionView) { |
336 int numSuggestions = [[formSuggestionView suggestions] count]; | 337 int numSuggestions = [[formSuggestionView suggestions] count]; |
337 if (!_suggestionsHaveBeenShown && numSuggestions == 0) { | 338 if (!_suggestionsHaveBeenShown && numSuggestions == 0) { |
338 _customAccessoryView.reset(); | 339 _customAccessoryView = nil; |
339 return; | 340 return; |
340 } | 341 } |
341 } | 342 } |
342 _suggestionsHaveBeenShown = YES; | 343 _suggestionsHaveBeenShown = YES; |
343 | 344 |
344 CGFloat height = autofill::kInputAccessoryHeight; | 345 CGFloat height = autofill::kInputAccessoryHeight; |
345 CGRect contentFrame = self.webViewProxy.frame; | 346 CGRect contentFrame = self.webViewProxy.frame; |
346 CGRect frame = CGRectMake(contentFrame.origin.x, -height, | 347 CGRect frame = CGRectMake(contentFrame.origin.x, -height, |
347 contentFrame.size.width, height); | 348 contentFrame.size.width, height); |
348 _customAccessoryView.reset( | 349 _customAccessoryView = |
349 [[FormInputAccessoryView alloc] initWithFrame:frame customView:view]); | 350 [[FormInputAccessoryView alloc] initWithFrame:frame customView:view]; |
350 UIView* keyboardView = [self getKeyboardView]; | 351 UIView* keyboardView = [self getKeyboardView]; |
351 DCHECK(keyboardView); | 352 DCHECK(keyboardView); |
352 [keyboardView addSubview:_customAccessoryView]; | 353 [keyboardView addSubview:_customAccessoryView]; |
353 } else { | 354 } else { |
354 // On all other versions, the custom view replaces the default UI of the | 355 // On all other versions, the custom view replaces the default UI of the |
355 // inputAccessoryView. | 356 // inputAccessoryView. |
356 [self restoreDefaultInputAccessoryView]; | 357 [self restoreDefaultInputAccessoryView]; |
357 CGRect leftFrame; | 358 CGRect leftFrame; |
358 CGRect rightFrame; | 359 CGRect rightFrame; |
359 UIView* inputAccessoryView = [self.webViewProxy keyboardAccessory]; | 360 UIView* inputAccessoryView = [self.webViewProxy keyboardAccessory]; |
360 if (ComputeFramesOfKeyboardParts(inputAccessoryView, &leftFrame, | 361 if (ComputeFramesOfKeyboardParts(inputAccessoryView, &leftFrame, |
361 &rightFrame)) { | 362 &rightFrame)) { |
362 [self hideSubviewsInOriginalAccessoryView:inputAccessoryView]; | 363 [self hideSubviewsInOriginalAccessoryView:inputAccessoryView]; |
363 _customAccessoryView.reset([[FormInputAccessoryView alloc] | 364 _customAccessoryView = |
364 initWithFrame:inputAccessoryView.frame | 365 [[FormInputAccessoryView alloc] initWithFrame:inputAccessoryView.frame |
365 delegate:self | 366 delegate:self |
366 customView:view | 367 customView:view |
367 leftFrame:leftFrame | 368 leftFrame:leftFrame |
368 rightFrame:rightFrame]); | 369 rightFrame:rightFrame]; |
369 [inputAccessoryView addSubview:_customAccessoryView]; | 370 [inputAccessoryView addSubview:_customAccessoryView]; |
370 } | 371 } |
371 } | 372 } |
372 } | 373 } |
373 | 374 |
374 - (void)restoreDefaultInputAccessoryView { | 375 - (void)restoreDefaultInputAccessoryView { |
375 [_customAccessoryView removeFromSuperview]; | 376 [_customAccessoryView removeFromSuperview]; |
376 _customAccessoryView.reset(); | 377 _customAccessoryView = nil; |
377 for (UIView* subview in _hiddenOriginalSubviews.get()) { | 378 for (UIView* subview in _hiddenOriginalSubviews) { |
378 subview.hidden = NO; | 379 subview.hidden = NO; |
379 } | 380 } |
380 [_hiddenOriginalSubviews removeAllObjects]; | 381 [_hiddenOriginalSubviews removeAllObjects]; |
381 } | 382 } |
382 | 383 |
383 - (void)closeKeyboardWithButtonPress { | 384 - (void)closeKeyboardWithButtonPress { |
384 [self closeKeyboardWithoutButtonPress]; | 385 [self closeKeyboardWithoutButtonPress]; |
385 if (_currentProvider && [_currentProvider getLogKeyboardAccessoryMetrics]) | 386 if (_currentProvider && [_currentProvider getLogKeyboardAccessoryMetrics]) |
386 _keyboardAccessoryMetricsLogger->OnCloseButtonPressed(); | 387 _keyboardAccessoryMetricsLogger->OnCloseButtonPressed(); |
387 } | 388 } |
(...skipping 23 matching lines...) Expand all Loading... |
411 if (!inputAccessoryView) | 412 if (!inputAccessoryView) |
412 return NO; | 413 return NO; |
413 descendants = | 414 descendants = |
414 FindDescendantToolbarItemsForActionName(inputAccessoryView, actionName); | 415 FindDescendantToolbarItemsForActionName(inputAccessoryView, actionName); |
415 } | 416 } |
416 | 417 |
417 if (![descendants count]) | 418 if (![descendants count]) |
418 return NO; | 419 return NO; |
419 | 420 |
420 UIBarButtonItem* item = descendants[0]; | 421 UIBarButtonItem* item = descendants[0]; |
| 422 #pragma clang diagnostic push |
| 423 #pragma clang diagnostic ignored "-Warc-performSelector-leaks" |
421 [[item target] performSelector:[item action] withObject:item]; | 424 [[item target] performSelector:[item action] withObject:item]; |
| 425 #pragma clang diagnostic pop |
422 return YES; | 426 return YES; |
423 } | 427 } |
424 | 428 |
425 #pragma mark - | 429 #pragma mark - |
426 #pragma mark FormInputAccessoryViewDelegate | 430 #pragma mark FormInputAccessoryViewDelegate |
427 | 431 |
428 - (void)selectPreviousElementWithButtonPress { | 432 - (void)selectPreviousElementWithButtonPress { |
429 [self selectPreviousElementWithoutButtonPress]; | 433 [self selectPreviousElementWithoutButtonPress]; |
430 if (_currentProvider && [_currentProvider getLogKeyboardAccessoryMetrics]) | 434 if (_currentProvider && [_currentProvider getLogKeyboardAccessoryMetrics]) |
431 _keyboardAccessoryMetricsLogger->OnPreviousButtonPressed(); | 435 _keyboardAccessoryMetricsLogger->OnPreviousButtonPressed(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 } | 504 } |
501 | 505 |
502 - (void)webStateDestroyed:(web::WebState*)webState { | 506 - (void)webStateDestroyed:(web::WebState*)webState { |
503 [self reset]; | 507 [self reset]; |
504 _webStateObserverBridge.reset(); | 508 _webStateObserverBridge.reset(); |
505 } | 509 } |
506 | 510 |
507 - (void)reset { | 511 - (void)reset { |
508 if (_currentProvider) { | 512 if (_currentProvider) { |
509 [_currentProvider inputAccessoryViewControllerDidReset:self]; | 513 [_currentProvider inputAccessoryViewControllerDidReset:self]; |
510 _currentProvider.reset(); | 514 _currentProvider = nil; |
511 } | 515 } |
512 [self restoreDefaultInputAccessoryView]; | 516 [self restoreDefaultInputAccessoryView]; |
513 | 517 |
514 _keyboardAccessoryMetricsLogger.reset( | 518 _keyboardAccessoryMetricsLogger.reset( |
515 new autofill::KeyboardAccessoryMetricsLogger()); | 519 new autofill::KeyboardAccessoryMetricsLogger()); |
516 } | 520 } |
517 | 521 |
518 - (void)retrieveAccessoryViewForForm:(const std::string&)formName | 522 - (void)retrieveAccessoryViewForForm:(const std::string&)formName |
519 field:(const std::string&)fieldName | 523 field:(const std::string&)fieldName |
520 value:(const std::string&)value | 524 value:(const std::string&)value |
521 type:(const std::string&)type | 525 type:(const std::string&)type |
522 webState:(web::WebState*)webState { | 526 webState:(web::WebState*)webState { |
523 base::WeakNSObject<FormInputAccessoryViewController> weakSelf(self); | 527 __weak FormInputAccessoryViewController* weakSelf = self; |
524 std::string strongFormName = formName; | 528 std::string strongFormName = formName; |
525 std::string strongFieldName = fieldName; | 529 std::string strongFieldName = fieldName; |
526 std::string strongValue = value; | 530 std::string strongValue = value; |
527 std::string strongType = type; | 531 std::string strongType = type; |
528 | 532 |
529 // Build a block for each provider that will invoke its completion with YES | 533 // Build a block for each provider that will invoke its completion with YES |
530 // if the provider can provide an accessory view for the specified form/field | 534 // if the provider can provide an accessory view for the specified form/field |
531 // and NO otherwise. | 535 // and NO otherwise. |
532 base::scoped_nsobject<NSMutableArray> findProviderBlocks( | 536 NSMutableArray* findProviderBlocks = [[NSMutableArray alloc] init]; |
533 [[NSMutableArray alloc] init]); | |
534 for (NSUInteger i = 0; i < [_providers count]; i++) { | 537 for (NSUInteger i = 0; i < [_providers count]; i++) { |
535 base::mac::ScopedBlock<passwords::PipelineBlock> block( | 538 passwords::PipelineBlock block = |
536 ^(void (^completion)(BOOL success)) { | 539 ^(void (^completion)(BOOL success)) { |
537 // Access all the providers through |self| to guarantee that both | 540 // Access all the providers through |self| to guarantee that both |
538 // |self| and all the providers exist when the block is executed. | 541 // |self| and all the providers exist when the block is executed. |
539 // |_providers| is immutable, so the subscripting is always valid. | 542 // |_providers| is immutable, so the subscripting is always valid. |
540 base::scoped_nsobject<FormInputAccessoryViewController> strongSelf( | 543 FormInputAccessoryViewController* strongSelf = weakSelf; |
541 [weakSelf retain]); | |
542 if (!strongSelf) | 544 if (!strongSelf) |
543 return; | 545 return; |
544 id<FormInputAccessoryViewProvider> provider = | 546 id<FormInputAccessoryViewProvider> provider = |
545 strongSelf.get()->_providers[i]; | 547 strongSelf->_providers[i]; |
546 [provider checkIfAccessoryViewIsAvailableForFormNamed:strongFormName | 548 [provider checkIfAccessoryViewIsAvailableForFormNamed:strongFormName |
547 fieldName:strongFieldName | 549 fieldName:strongFieldName |
548 webState:webState | 550 webState:webState |
549 completionHandler:completion]; | 551 completionHandler:completion]; |
550 }, | 552 }; |
551 base::scoped_policy::RETAIN); | |
552 [findProviderBlocks addObject:block]; | 553 [findProviderBlocks addObject:block]; |
553 } | 554 } |
554 | 555 |
555 // Once the view is retrieved, update the UI. | 556 // Once the view is retrieved, update the UI. |
556 AccessoryViewReadyCompletion readyCompletion = | 557 AccessoryViewReadyCompletion readyCompletion = |
557 ^(UIView* accessoryView, id<FormInputAccessoryViewProvider> provider) { | 558 ^(UIView* accessoryView, id<FormInputAccessoryViewProvider> provider) { |
558 base::scoped_nsobject<FormInputAccessoryViewController> strongSelf( | 559 FormInputAccessoryViewController* strongSelf = weakSelf; |
559 [weakSelf retain]); | 560 if (!strongSelf || !strongSelf->_currentProvider) |
560 if (!strongSelf || !strongSelf.get()->_currentProvider) | |
561 return; | 561 return; |
562 DCHECK_EQ(strongSelf.get()->_currentProvider.get(), provider); | 562 DCHECK_EQ(strongSelf->_currentProvider, provider); |
563 [provider setAccessoryViewDelegate:strongSelf]; | 563 [provider setAccessoryViewDelegate:strongSelf]; |
564 [strongSelf showCustomInputAccessoryView:accessoryView]; | 564 [strongSelf showCustomInputAccessoryView:accessoryView]; |
565 }; | 565 }; |
566 | 566 |
567 // Once a provider is found, use it to retrieve the accessory view. | 567 // Once a provider is found, use it to retrieve the accessory view. |
568 passwords::PipelineCompletionBlock onProviderFound = | 568 passwords::PipelineCompletionBlock onProviderFound = |
569 ^(NSUInteger providerIndex) { | 569 ^(NSUInteger providerIndex) { |
570 if (providerIndex == NSNotFound) { | 570 if (providerIndex == NSNotFound) { |
571 [weakSelf reset]; | 571 [weakSelf reset]; |
572 return; | 572 return; |
573 } | 573 } |
574 base::scoped_nsobject<FormInputAccessoryViewController> strongSelf( | 574 FormInputAccessoryViewController* strongSelf = weakSelf; |
575 [weakSelf retain]); | |
576 if (!strongSelf || ![strongSelf webState]) | 575 if (!strongSelf || ![strongSelf webState]) |
577 return; | 576 return; |
578 id<FormInputAccessoryViewProvider> provider = | 577 id<FormInputAccessoryViewProvider> provider = |
579 strongSelf.get()->_providers[providerIndex]; | 578 strongSelf->_providers[providerIndex]; |
580 [strongSelf.get()->_currentProvider | 579 [strongSelf->_currentProvider |
581 inputAccessoryViewControllerDidReset:self]; | 580 inputAccessoryViewControllerDidReset:self]; |
582 strongSelf.get()->_currentProvider.reset(provider); | 581 strongSelf->_currentProvider = provider; |
583 [strongSelf.get()->_currentProvider | 582 [strongSelf->_currentProvider |
584 retrieveAccessoryViewForFormNamed:strongFormName | 583 retrieveAccessoryViewForFormNamed:strongFormName |
585 fieldName:strongFieldName | 584 fieldName:strongFieldName |
586 value:strongValue | 585 value:strongValue |
587 type:strongType | 586 type:strongType |
588 webState:webState | 587 webState:webState |
589 accessoryViewUpdateBlock:readyCompletion]; | 588 accessoryViewUpdateBlock:readyCompletion]; |
590 }; | 589 }; |
591 | 590 |
592 // Run all the blocks in |findProviderBlocks| until one invokes its | 591 // Run all the blocks in |findProviderBlocks| until one invokes its |
593 // completion with YES. The first one to do so will be passed to | 592 // completion with YES. The first one to do so will be passed to |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 // that we don't present our custom view over the keyboard. | 639 // that we don't present our custom view over the keyboard. |
641 - (void)textInputDidBeginEditing:(NSNotification*)notification { | 640 - (void)textInputDidBeginEditing:(NSNotification*)notification { |
642 [self reset]; | 641 [self reset]; |
643 } | 642 } |
644 | 643 |
645 - (void)keyboardDidHide:(NSNotification*)notification { | 644 - (void)keyboardDidHide:(NSNotification*)notification { |
646 _keyboardFrame = CGRectZero; | 645 _keyboardFrame = CGRectZero; |
647 } | 646 } |
648 | 647 |
649 @end | 648 @end |
OLD | NEW |