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

Unified Diff: components/autofill/content/renderer/password_autofill_agent.cc

Issue 2035143002: Basic implementation of showing password fill dialog on page load (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Cleanup and tests Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/content/renderer/password_autofill_agent.cc
diff --git a/components/autofill/content/renderer/password_autofill_agent.cc b/components/autofill/content/renderer/password_autofill_agent.cc
index 0174ba911d7e606b11df4fab3f6bbeb021544618..9a9fd85f757b7c11a28b8bfe966de9cb3b4b3d22 100644
--- a/components/autofill/content/renderer/password_autofill_agent.cc
+++ b/components/autofill/content/renderer/password_autofill_agent.cc
@@ -11,11 +11,9 @@
#include <utility>
#include "base/bind.h"
-#include "base/command_line.h"
#include "base/i18n/case_conversion.h"
#include "base/memory/linked_ptr.h"
#include "base/message_loop/message_loop.h"
-#include "base/metrics/field_trial.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
@@ -24,7 +22,6 @@
#include "components/autofill/content/renderer/password_form_conversion_utils.h"
#include "components/autofill/content/renderer/renderer_save_password_progress_logger.h"
#include "components/autofill/core/common/autofill_constants.h"
-#include "components/autofill/core/common/autofill_switches.h"
#include "components/autofill/core/common/autofill_util.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/autofill/core/common/password_form.h"
@@ -54,12 +51,6 @@ namespace {
// The size above which we stop triggering autocomplete.
static const size_t kMaximumTextSizeForAutocomplete = 1000;
-// Experiment information
-const char kFillOnAccountSelectFieldTrialName[] = "FillOnAccountSelect";
-const char kFillOnAccountSelectFieldTrialEnabledWithHighlightGroup[] =
- "EnableWithHighlight";
-const char kFillOnAccountSelectFieldTrialEnabledWithNoHighlightGroup[] =
- "EnableWithNoHighlight";
const char kDummyUsernameField[] = "anonymous_username";
const char kDummyPasswordField[] = "anonymous_password";
@@ -227,47 +218,6 @@ bool FindFormInputElement(
return true;
}
-bool ShouldFillOnAccountSelect() {
- std::string group_name =
- base::FieldTrialList::FindFullName(kFillOnAccountSelectFieldTrialName);
-
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableFillOnAccountSelect)) {
- return false;
- }
-
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableFillOnAccountSelect) ||
- base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableFillOnAccountSelectNoHighlighting)) {
- return true;
- }
-
- return group_name ==
- kFillOnAccountSelectFieldTrialEnabledWithHighlightGroup ||
- group_name ==
- kFillOnAccountSelectFieldTrialEnabledWithNoHighlightGroup;
-}
-
-bool ShouldHighlightFields() {
- std::string group_name =
- base::FieldTrialList::FindFullName(kFillOnAccountSelectFieldTrialName);
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableFillOnAccountSelect) ||
- base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableFillOnAccountSelect)) {
- return true;
- }
-
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableFillOnAccountSelectNoHighlighting)) {
- return false;
- }
-
- return group_name !=
- kFillOnAccountSelectFieldTrialEnabledWithNoHighlightGroup;
-}
-
// Helper to search through |control_elements| for the specified input elements
// in |data|, and add results to |result|.
bool FindFormInputElements(
@@ -399,28 +349,6 @@ bool CanShowSuggestion(const PasswordFormFillData& fill_data,
return false;
}
-// Returns true if there exists a credential suggestion whose username field is
-// an exact match to the current username (not just a prefix).
-bool HasExactMatchSuggestion(const PasswordFormFillData& fill_data,
- const base::string16& current_username) {
- if (fill_data.username_field.value == current_username)
- return true;
-
- for (const auto& usernames : fill_data.other_possible_usernames) {
- for (const auto& username_string : usernames.second) {
- if (username_string == current_username)
- return true;
- }
- }
-
- for (const auto& login : fill_data.additional_logins) {
- if (login.first == current_username)
- return true;
- }
-
- return false;
-}
-
// This function attempts to fill |username_element| and |password_element|
// with values from |fill_data|. The |password_element| will only have the
// suggestedValue set, and will be registered for copying that to the real
@@ -589,20 +517,6 @@ bool FillFormOnPasswordReceived(
bool form_has_fillable_username = !username_field_name.empty() &&
IsElementAutocompletable(username_element);
- if (ShouldFillOnAccountSelect()) {
- if (!ShouldHighlightFields()) {
- return false;
- }
-
- if (form_has_fillable_username) {
- username_element.setAutofilled(true);
- } else if (username_element.isNull() ||
- HasExactMatchSuggestion(fill_data, username_element.value())) {
- password_element.setAutofilled(true);
- }
- return false;
- }
-
if (form_has_fillable_username && username_element.value().isEmpty()) {
// TODO(tkent): Check maxlength and pattern.
username_element.setValue(fill_data.username_field.value, true);
@@ -1328,6 +1242,14 @@ void PasswordAutofillAgent::DidStartProvisionalLoad() {
void PasswordAutofillAgent::OnFillPasswordForm(
int key,
const PasswordFormFillData& form_data) {
+ GetFillableElementFromFormData(key, form_data, true, nullptr);
+}
+
+void PasswordAutofillAgent::GetFillableElementFromFormData(
+ int key,
+ const PasswordFormFillData& form_data,
+ bool should_fill_forms,
+ std::vector<blink::WebInputElement>* elements) {
std::unique_ptr<RendererSavePasswordProgressLogger> logger;
if (logging_state_active_) {
logger.reset(new RendererSavePasswordProgressLogger(this, routing_id()));
@@ -1399,7 +1321,7 @@ void PasswordAutofillAgent::OnFillPasswordForm(
// If wait_for_username is true, we don't want to initially fill the form
// until the user types in a valid username.
- if (!form_data.wait_for_username) {
+ if (should_fill_forms && !form_data.wait_for_username) {
FillFormOnPasswordReceived(
form_data, username_element, password_element,
&nonscript_modified_values_,
@@ -1415,6 +1337,8 @@ void PasswordAutofillAgent::OnFillPasswordForm(
web_input_to_password_info_[main_element] = password_info;
if (!main_element.isPasswordField())
password_to_username_[password_element] = username_element;
+ if (elements)
+ elements->push_back(main_element);
}
}

Powered by Google App Engine
This is Rietveld 408576698