summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorbondd <bondd@chromium.org>2015-07-06 13:55:42 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-06 20:56:45 +0000
commit3f22bbead528105071ceaaa5ecd7c0ca0698c583 (patch)
tree986d2a3edcd57d3a70540b26fd26784e5e198824 /components
parent35df0c989e6939a4c8fa3eeb26b67c64df4c0465 (diff)
downloadchromium_src-3f22bbead528105071ceaaa5ecd7c0ca0698c583.zip
chromium_src-3f22bbead528105071ceaaa5ecd7c0ca0698c583.tar.gz
chromium_src-3f22bbead528105071ceaaa5ecd7c0ca0698c583.tar.bz2
Autofill: Add initial iOS full-form Autofill behind a switch.
Add a switch to control whether iOS uses old single-field Autofill or new full-form Autofill. Switch is off by default so Autofill will work exactly the same as before. Downstream iOS part is here: https://chromereviews.googleplex.com/217317013 BUG=504644 Review URL: https://codereview.chromium.org/1211253002 Cr-Commit-Position: refs/heads/master@{#337468}
Diffstat (limited to 'components')
-rw-r--r--components/autofill.gypi2
-rw-r--r--components/autofill/core/common/autofill_switches.cc6
-rw-r--r--components/autofill/core/common/autofill_switches.h2
-rw-r--r--components/autofill/ios/browser/autofill_field_trial_ios.cc24
-rw-r--r--components/autofill/ios/browser/autofill_field_trial_ios.h28
-rw-r--r--components/autofill/ios/browser/js_autofill_manager.h3
-rw-r--r--components/autofill/ios/browser/js_autofill_manager.mm6
-rw-r--r--components/autofill/ios/browser/resources/autofill_controller.js24
8 files changed, 92 insertions, 3 deletions
diff --git a/components/autofill.gypi b/components/autofill.gypi
index 06ea5f5..99cc85d 100644
--- a/components/autofill.gypi
+++ b/components/autofill.gypi
@@ -460,6 +460,8 @@
'autofill/ios/browser/autofill_driver_ios_bridge.h',
'autofill/ios/browser/credit_card_util.h',
'autofill/ios/browser/credit_card_util.mm',
+ 'autofill/ios/browser/autofill_field_trial_ios.cc',
+ 'autofill/ios/browser/autofill_field_trial_ios.h',
'autofill/ios/browser/form_suggestion.h',
'autofill/ios/browser/form_suggestion.mm',
'autofill/ios/browser/js_autofill_manager.h',
diff --git a/components/autofill/core/common/autofill_switches.cc b/components/autofill/core/common/autofill_switches.cc
index 754bb80..675475a 100644
--- a/components/autofill/core/common/autofill_switches.cc
+++ b/components/autofill/core/common/autofill_switches.cc
@@ -15,6 +15,9 @@ const char kDisableCreditCardScan[] = "disable-credit-card-scan";
// selection, rather than autofilling on page load.
const char kDisableFillOnAccountSelect[] = "disable-fill-on-account-select";
+// Disables the experimental Full Form Autofill on iOS feature.
+const char kDisableFullFormAutofillIOS[] = "disable-full-form-autofill-ios";
+
// Force hiding the local save checkbox in the autofill dialog box for getting
// the full credit card number for a wallet card. The card will never be stored
// locally.
@@ -45,6 +48,9 @@ const char kEnableFillOnAccountSelect[] = "enable-fill-on-account-select";
const char kEnableFillOnAccountSelectNoHighlighting[] =
"enable-fill-on-account-select-no-highlighting";
+// Enables the experimental Full Form Autofill on iOS feature.
+const char kEnableFullFormAutofillIOS[] = "enable-full-form-autofill-ios";
+
// Force showing the local save checkbox in the autofill dialog box for getting
// the full credit card number for a wallet card.
const char kEnableOfferStoreUnmaskedWalletCards[] =
diff --git a/components/autofill/core/common/autofill_switches.h b/components/autofill/core/common/autofill_switches.h
index 7bb9803..2c6ee91 100644
--- a/components/autofill/core/common/autofill_switches.h
+++ b/components/autofill/core/common/autofill_switches.h
@@ -12,6 +12,7 @@ namespace switches {
// alongside the definition of their values in the .cc file.
extern const char kDisableCreditCardScan[];
extern const char kDisableFillOnAccountSelect[];
+extern const char kDisableFullFormAutofillIOS[];
extern const char kDisableOfferStoreUnmaskedWalletCards[];
extern const char kDisablePasswordGeneration[];
extern const char kDisableSingleClickAutofill[];
@@ -19,6 +20,7 @@ extern const char kEnableAccessorySuggestionView[];
extern const char kEnableCreditCardScan[];
extern const char kEnableFillOnAccountSelect[];
extern const char kEnableFillOnAccountSelectNoHighlighting[];
+extern const char kEnableFullFormAutofillIOS[];
extern const char kEnableOfferStoreUnmaskedWalletCards[];
extern const char kEnablePasswordGeneration[];
extern const char kEnableSingleClickAutofill[];
diff --git a/components/autofill/ios/browser/autofill_field_trial_ios.cc b/components/autofill/ios/browser/autofill_field_trial_ios.cc
new file mode 100644
index 0000000..75e8758
--- /dev/null
+++ b/components/autofill/ios/browser/autofill_field_trial_ios.cc
@@ -0,0 +1,24 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/autofill/ios/browser/autofill_field_trial_ios.h"
+
+#include "base/command_line.h"
+#include "components/autofill/core/common/autofill_switches.h"
+
+namespace autofill {
+
+bool AutofillFieldTrialIOS::IsFullFormAutofillEnabled() {
+ const base::CommandLine* command_line =
+ base::CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(autofill::switches::kDisableFullFormAutofillIOS))
+ return false;
+ if (command_line->HasSwitch(autofill::switches::kEnableFullFormAutofillIOS))
+ return true;
+
+ // TODO(bondd): Control via a FieldTrial.
+ return false;
+}
+
+} // namespace autofill
diff --git a/components/autofill/ios/browser/autofill_field_trial_ios.h b/components/autofill/ios/browser/autofill_field_trial_ios.h
new file mode 100644
index 0000000..cb5d3cb
--- /dev/null
+++ b/components/autofill/ios/browser/autofill_field_trial_ios.h
@@ -0,0 +1,28 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_AUTOFILL_IOS_BROWSER_AUTOFILL_FIELD_TRIAL_IOS_H_
+#define COMPONENTS_AUTOFILL_IOS_BROWSER_AUTOFILL_FIELD_TRIAL_IOS_H_
+
+#include "base/macros.h"
+
+namespace autofill {
+
+// This class manages the iOS Autofill field trials.
+class AutofillFieldTrialIOS {
+ public:
+ // Returns whether the user is in a full-form Autofill field trial. Full-form
+ // Autofill fills all fields of the form at once, similar to the desktop and
+ // Clank Autofill implementations. Previous iOS implementation requires user
+ // to select an Autofill value for each field individually, automatically
+ // advancing focus to the next field after each selection.
+ static bool IsFullFormAutofillEnabled();
+
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillFieldTrialIOS);
+};
+
+} // namespace autofill
+
+#endif // COMPONENTS_AUTOFILL_IOS_BROWSER_AUTOFILL_FIELD_TRIAL_IOS_H_
diff --git a/components/autofill/ios/browser/js_autofill_manager.h b/components/autofill/ios/browser/js_autofill_manager.h
index c6769b6..b6635f4 100644
--- a/components/autofill/ios/browser/js_autofill_manager.h
+++ b/components/autofill/ios/browser/js_autofill_manager.h
@@ -38,9 +38,12 @@
completionHandler:(ProceduralBlock)completionHandler;
// Fills a number of fields in the same named form.
+// Applies Autofill CSS (i.e. yellow background) to filled elements if
+// |styleElements| is true.
// |completionHandler| is called after the forms are filled. |completionHandler|
// cannot be nil.
- (void)fillForm:(NSString*)dataString
+ styleElements:(BOOL)styleElements
completionHandler:(ProceduralBlock)completionHandler;
// Dispatches the autocomplete event to the form element with the given
diff --git a/components/autofill/ios/browser/js_autofill_manager.mm b/components/autofill/ios/browser/js_autofill_manager.mm
index 2066a82..71df9fd 100644
--- a/components/autofill/ios/browser/js_autofill_manager.mm
+++ b/components/autofill/ios/browser/js_autofill_manager.mm
@@ -70,10 +70,12 @@
}
- (void)fillForm:(NSString*)dataString
+ styleElements:(BOOL)styleElements
completionHandler:(ProceduralBlock)completionHandler {
DCHECK(completionHandler);
- NSString* fillFormJS = [NSString
- stringWithFormat:@"__gCrWeb.autofill.fillForm(%@);", dataString];
+ NSString* fillFormJS =
+ [NSString stringWithFormat:@"__gCrWeb.autofill.fillForm(%@, %s);",
+ dataString, styleElements ? "true" : "false"];
id stringResultHandler = ^(NSString*, NSError*) {
completionHandler();
};
diff --git a/components/autofill/ios/browser/resources/autofill_controller.js b/components/autofill/ios/browser/resources/autofill_controller.js
index a950b58..b283da3 100644
--- a/components/autofill/ios/browser/resources/autofill_controller.js
+++ b/components/autofill/ios/browser/resources/autofill_controller.js
@@ -153,6 +153,13 @@ __gCrWeb.autofill.lastAutoFilledElement = null;
__gCrWeb.autofill.lastActiveElement = null;
/**
+ * Whether CSS for autofilled elements has been injected into the page.
+ *
+ * @type {boolean}
+ */
+__gCrWeb.autofill.styleInjected = false;
+
+/**
* Extracts fields from |controlElements| with |requirements| and |extractMask|
* to |formFields|. The extracted fields are also placed in |elementArray|.
*
@@ -494,8 +501,21 @@ __gCrWeb.autofill['fillActiveFormField'] = function(data) {
* Fills a number of fields in the same named form.
*
* @param {Object<AutofillFormData>} data The data to fill in.
+ * @param {boolean} styleElements Apply Autofill CSS style to filled elements.
*/
-__gCrWeb.autofill['fillForm'] = function(data) {
+__gCrWeb.autofill['fillForm'] = function(data, styleElements) {
+ // Inject CSS to style the autofilled elements with a yellow background.
+ if (styleElements && !__gCrWeb.autofill.styleInjected) {
+ var style = document.createElement('style');
+ style.textContent = '[chrome-autofilled] {' +
+ 'background-color:#FAFFBD !important;' +
+ 'background-image:none !important;' +
+ 'color:#000000 !important;' +
+ '}';
+ document.head.appendChild(style);
+ __gCrWeb.autofill.styleInjected = true;
+ }
+
var form = __gCrWeb.common.getFormElementFromIdentifier(data.formName);
var controlElements = __gCrWeb.common.getFormControlElements(form);
for (var i = 0; i < controlElements.length; ++i) {
@@ -506,6 +526,8 @@ __gCrWeb.autofill['fillForm'] = function(data) {
var value = data.fields[__gCrWeb['common'].nameForAutofill(element)];
if (value) {
element.value = value;
+ if (styleElements)
+ element.setAttribute('chrome-autofilled');
}
}
};