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

Side by Side Diff: components/autofill/ios/browser/js_autofill_manager.mm

Issue 1007813002: [iOS] Upstream autofill component code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added dconnelly to OWNERS Created 5 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "components/autofill/ios/browser/js_autofill_manager.h"
6
7 #include "base/format_macros.h"
8 #include "base/json/string_escape.h"
9 #include "base/logging.h"
10 #import "ios/web/public/web_state/js/crw_js_early_script_manager.h"
11
12 @implementation JsAutofillManager
13
14 - (void)fetchFormsWithRequirements:(autofill::RequirementsMask)requirements
15 minimumRequiredFieldsCount:(NSUInteger)requiredFieldsCount
16 completionHandler:(void (^)(NSString*))completionHandler {
17 DCHECK(completionHandler);
18 // Convert from C++ enum to JS enum.
19 NSString* requirementsJS = nil;
20 switch (requirements) {
21 case autofill::REQUIRE_NONE:
22 requirementsJS = @"__gCrWeb.autofill.REQUIREMENTS_MASK_NONE";
23 break;
24 case autofill::REQUIRE_AUTOCOMPLETE:
25 requirementsJS =
26 @"__gCrWeb.autofill.REQUIREMENTS_MASK_REQUIRE_AUTOCOMPLETE";
27 break;
28 }
29 DCHECK(requirementsJS);
30
31 NSString* extractFormsJS = [NSString
32 stringWithFormat:@"__gCrWeb.autofill.extractForms(%" PRIuNS ", %@);",
33 requiredFieldsCount, requirementsJS];
34 [self evaluate:extractFormsJS
35 stringResultHandler:^(NSString* result, NSError*) {
36 completionHandler(result);
37 }];
38 }
39
40 #pragma mark -
41 #pragma mark ProtectedMethods
42
43 - (NSString*)scriptPath {
44 return @"autofill_controller";
45 }
46
47 - (NSString*)presenceBeacon {
48 return @"__gCrWeb.autofill";
49 }
50
51 - (NSArray*)directDependencies {
52 return @[ [CRWJSEarlyScriptManager class] ];
53 }
54
55 - (void)fillActiveFormField:(NSString*)dataString
56 completionHandler:(ProceduralBlock)completionHandler {
57 web::JavaScriptCompletion resultHandler = ^void(NSString*, NSError*) {
58 completionHandler();
59 };
60
61 NSString* js =
62 [NSString stringWithFormat:@"__gCrWeb.autofill.fillActiveFormField(%@);",
63 dataString];
64 [self evaluate:js stringResultHandler:resultHandler];
65 }
66
67 - (void)fillForm:(NSString*)dataString
68 completionHandler:(ProceduralBlock)completionHandler {
69 DCHECK(completionHandler);
70 NSString* fillFormJS = [NSString
71 stringWithFormat:@"__gCrWeb.autofill.fillForm(%@);", dataString];
72 id stringResultHandler = ^(NSString*, NSError*) {
73 completionHandler();
74 };
75 return [self evaluate:fillFormJS stringResultHandler:stringResultHandler];
76 }
77
78 - (void)dispatchAutocompleteEvent:(NSString*)formName {
79 NSString* dispatchAutocompleteEventJS = [NSString
80 stringWithFormat:@"__gCrWeb.autofill.dispatchAutocompleteEvent(%s);",
81 base::GetQuotedJSONString([formName UTF8String])
82 .c_str()];
83 [self evaluate:dispatchAutocompleteEventJS stringResultHandler:nil];
84 }
85
86 - (void)dispatchAutocompleteErrorEvent:(NSString*)formName
87 withReason:(NSString*)reason {
88 NSString* autocompleteErrorJS = [NSString
89 stringWithFormat:
90 @"__gCrWeb.autofill.dispatchAutocompleteErrorEvent(%s, %s);",
91 base::GetQuotedJSONString([formName UTF8String]).c_str(),
92 base::GetQuotedJSONString([reason UTF8String]).c_str()];
93 [self evaluate:autocompleteErrorJS stringResultHandler:nil];
94 }
95
96 - (void)fillPredictionData:(NSString*)dataString {
97 [self deferredEvaluate:
98 [NSString
99 stringWithFormat:@"__gCrWeb.autofill.fillPredictionData(%@);",
100 dataString]];
101 }
102
103 @end
OLDNEW
« no previous file with comments | « components/autofill/ios/browser/js_autofill_manager.h ('k') | components/autofill/ios/browser/js_suggestion_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698