| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/ios/browser/js_autofill_manager.h" | 5 #import "components/autofill/ios/browser/js_autofill_manager.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/json/string_escape.h" | 8 #include "base/json/string_escape.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| 11 @implementation JsAutofillManager | 11 @implementation JsAutofillManager |
| 12 | 12 |
| 13 - (void)fetchFormsWithMinimumRequiredFieldsCount:(NSUInteger)requiredFieldsCount | 13 - (void)fetchFormsWithMinimumRequiredFieldsCount:(NSUInteger)requiredFieldsCount |
| 14 completionHandler: | 14 completionHandler: |
| 15 (void (^)(NSString*))completionHandler { | 15 (void (^)(NSString*))completionHandler { |
| 16 [self fetchFormsWithRequirements:autofill::REQUIRE_NONE | |
| 17 minimumRequiredFieldsCount:requiredFieldsCount | |
| 18 completionHandler:completionHandler]; | |
| 19 } | |
| 20 | |
| 21 - (void)fetchFormsWithRequirements:(autofill::RequirementsMask)requirements | |
| 22 minimumRequiredFieldsCount:(NSUInteger)requiredFieldsCount | |
| 23 completionHandler:(void (^)(NSString*))completionHandler { | |
| 24 DCHECK(completionHandler); | 16 DCHECK(completionHandler); |
| 25 // Convert from C++ enum to JS enum. | |
| 26 NSString* requirementsJS = nil; | |
| 27 switch (requirements) { | |
| 28 case autofill::REQUIRE_NONE: | |
| 29 requirementsJS = @"__gCrWeb.autofill.REQUIREMENTS_MASK_NONE"; | |
| 30 break; | |
| 31 case autofill::REQUIRE_AUTOCOMPLETE: | |
| 32 requirementsJS = | |
| 33 @"__gCrWeb.autofill.REQUIREMENTS_MASK_REQUIRE_AUTOCOMPLETE"; | |
| 34 break; | |
| 35 } | |
| 36 DCHECK(requirementsJS); | |
| 37 | |
| 38 NSString* extractFormsJS = [NSString | 17 NSString* extractFormsJS = [NSString |
| 39 stringWithFormat:@"__gCrWeb.autofill.extractForms(%" PRIuNS ", %@);", | 18 stringWithFormat:@"__gCrWeb.autofill.extractForms(%" PRIuNS ");", |
| 40 requiredFieldsCount, requirementsJS]; | 19 requiredFieldsCount]; |
| 41 [self evaluate:extractFormsJS | 20 [self evaluate:extractFormsJS |
| 42 stringResultHandler:^(NSString* result, NSError*) { | 21 stringResultHandler:^(NSString* result, NSError*) { |
| 43 completionHandler(result); | 22 completionHandler(result); |
| 44 }]; | 23 }]; |
| 45 } | 24 } |
| 46 | 25 |
| 47 #pragma mark - | 26 #pragma mark - |
| 48 #pragma mark ProtectedMethods | 27 #pragma mark ProtectedMethods |
| 49 | 28 |
| 50 - (NSString*)scriptPath { | 29 - (NSString*)scriptPath { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 88 } |
| 110 | 89 |
| 111 - (void)fillPredictionData:(NSString*)dataString { | 90 - (void)fillPredictionData:(NSString*)dataString { |
| 112 [self deferredEvaluate: | 91 [self deferredEvaluate: |
| 113 [NSString | 92 [NSString |
| 114 stringWithFormat:@"__gCrWeb.autofill.fillPredictionData(%@);", | 93 stringWithFormat:@"__gCrWeb.autofill.fillPredictionData(%@);", |
| 115 dataString]]; | 94 dataString]]; |
| 116 } | 95 } |
| 117 | 96 |
| 118 @end | 97 @end |
| OLD | NEW |