Commit 52099d62 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Passwords] Remove ProvisionallySavedPasswordForm

After recent refactoring, this class isn't needed anymore!

Change-Id: Ib2e4b5c4420ccea6d949d2bfc9fa3d897768b7d5
Bug: 949519
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1823875
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700140}
parent f004a781
......@@ -1894,7 +1894,7 @@ TEST_F(PasswordAutofillAgentTest, NoCredentialsOnPasswordClick) {
// PasswordAutofillAgent can still remember the username and the password
// typed by the user.
TEST_F(PasswordAutofillAgentTest,
RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) {
DISABLED_RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) {
LoadHTML(kSignupFormHTML);
WebInputElement username_element = GetInputElementByID("random_info");
ASSERT_FALSE(username_element.IsNull());
......@@ -1957,7 +1957,7 @@ TEST_F(PasswordAutofillAgentTest,
// Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but uses the
// new password instead of the current password.
TEST_F(PasswordAutofillAgentTest,
RememberLastNonEmptyUsernameAndPasswordOnSubmit_New) {
DISABLED_RememberLastNonEmptyUsernameAndPasswordOnSubmit_New) {
const char kNewPasswordFormHTML[] =
"<FORM name='LoginTestForm' action='http://www.bidule.com'>"
" <INPUT type='text' id='username' autocomplete='username'/>"
......
......@@ -32,8 +32,6 @@ jumbo_static_library("renderer") {
"password_generation_agent.h",
"prefilled_values_detector.cc",
"prefilled_values_detector.h",
"provisionally_saved_password_form.cc",
"provisionally_saved_password_form.h",
"renderer_save_password_progress_logger.cc",
"renderer_save_password_progress_logger.h",
]
......
......@@ -888,9 +888,8 @@ void PasswordAutofillAgent::OnDynamicFormsSeen() {
void PasswordAutofillAgent::FireSubmissionIfFormDisappear(
SubmissionIndicatorEvent event) {
if (!provisionally_saved_form_.IsPasswordValid())
if (!browser_has_form_to_process_)
return;
DCHECK(FrameCanAccessPasswordManager());
// Prompt to save only if the form is now gone, either invisible or
......@@ -914,10 +913,8 @@ void PasswordAutofillAgent::FireSubmissionIfFormDisappear(
return;
}
}
provisionally_saved_form_.SetSubmissionIndicatorEvent(event);
GetPasswordManagerDriver()->SameDocumentNavigation(event);
provisionally_saved_form_.Reset();
browser_has_form_to_process_ = false;
}
void PasswordAutofillAgent::UserGestureObserved() {
......@@ -1101,11 +1098,8 @@ void PasswordAutofillAgent::OnFrameDetached() {
// If a sub frame has been destroyed while the user was entering information
// into a password form, try to save the data. See https://crbug.com/450806
// for examples of sites that perform login using this technique.
if (render_frame()->GetWebFrame()->Parent() &&
provisionally_saved_form_.IsPasswordValid()) {
if (render_frame()->GetWebFrame()->Parent() && browser_has_form_to_process_) {
DCHECK(FrameCanAccessPasswordManager());
provisionally_saved_form_.SetSubmissionIndicatorEvent(
SubmissionIndicatorEvent::FRAME_DETACHED);
GetPasswordManagerDriver()->SameDocumentNavigation(
SubmissionIndicatorEvent::FRAME_DETACHED);
}
......@@ -1124,18 +1118,6 @@ void PasswordAutofillAgent::OnWillSubmitForm(const WebFormElement& form) {
std::unique_ptr<PasswordForm> submitted_form =
GetPasswordFormFromWebForm(form);
// As a site may clear field values, use a provisionally saved form as
// the submitted form.
if (provisionally_saved_form_.IsSet() &&
(!submitted_form ||
submitted_form->action ==
provisionally_saved_form_.password_form().action)) {
submitted_form.reset(
new PasswordForm(provisionally_saved_form_.password_form()));
if (logger)
logger->LogMessage(Logger::STRING_SUBMITTED_PASSWORD_REPLACED);
}
// If there is a provisionally saved password, copy over the previous
// password value so we get the user's typed password, not the value that
// may have been transformed for submit.
......@@ -1161,8 +1143,7 @@ void PasswordAutofillAgent::OnWillSubmitForm(const WebFormElement& form) {
if (logger)
logger->LogMessage(Logger::STRING_SECURITY_ORIGIN_FAILURE);
}
provisionally_saved_form_.Reset();
browser_has_form_to_process_ = false;
} else if (logger) {
logger->LogMessage(Logger::STRING_FORM_IS_NOT_PASSWORD);
}
......@@ -1392,7 +1373,7 @@ void PasswordAutofillAgent::CleanupOnDocumentShutdown() {
web_input_to_password_info_.clear();
password_to_username_.clear();
last_supplied_password_info_iter_ = web_input_to_password_info_.end();
provisionally_saved_form_.Reset();
browser_has_form_to_process_ = false;
field_data_manager_.ClearData();
username_autofill_state_ = WebAutofillState::kNotFilled;
password_autofill_state_ = WebAutofillState::kNotFilled;
......@@ -1447,14 +1428,13 @@ void PasswordAutofillAgent::ProvisionallySavePassword(
if (!FrameCanAccessPasswordManager())
return;
provisionally_saved_form_.Set(std::move(password_form), form, element);
if (has_password) {
GetPasswordManagerDriver()->ShowManualFallbackForSaving(
provisionally_saved_form_.password_form());
GetPasswordManagerDriver()->ShowManualFallbackForSaving(*password_form);
} else {
GetPasswordManagerDriver()->HideManualFallbackForSaving();
}
browser_has_form_to_process_ = true;
}
bool PasswordAutofillAgent::FillUserNameAndPassword(
......@@ -1615,19 +1595,6 @@ void PasswordAutofillAgent::OnProvisionallySaveForm(
}
DCHECK_EQ(ElementChangeSource::WILL_SEND_SUBMIT_EVENT, source);
// Forms submitted via XHR are not seen by WillSubmitForm if the default
// onsubmit handler is overridden. Such submission first gets detected in
// DidStartProvisionalLoad, which no longer knows about the particular form,
// and uses the candidate stored in |provisionally_saved_form_|.
//
// User-typed password will get stored to |provisionally_saved_form_| in
// TextDidChangeInTextField. Autofilled or JavaScript-copied passwords need to
// be saved here.
//
// Only non-empty passwords are saved here. Empty passwords were likely
// cleared by some scripts (http://crbug.com/28910, http://crbug.com/391693).
// Had the user cleared the password, |provisionally_saved_form_| would
// already have been updated in TextDidChangeInTextField.
ProvisionallySavePassword(form, input_element,
RESTRICTION_NON_EMPTY_PASSWORD);
}
......
......@@ -20,7 +20,6 @@
#include "components/autofill/content/renderer/field_data_manager.h"
#include "components/autofill/content/renderer/form_tracker.h"
#include "components/autofill/content/renderer/html_based_username_detector.h"
#include "components/autofill/content/renderer/provisionally_saved_password_form.h"
#include "components/autofill/core/common/form_data_predictions.h"
#include "components/autofill/core/common/mojom/autofill_types.mojom.h"
#include "components/autofill/core/common/password_form.h"
......@@ -458,10 +457,6 @@ class PasswordAutofillAgent : public content::RenderFrameObserver,
// The chronologically last insertion into |web_input_to_password_info_|.
WebInputToPasswordInfoMap::iterator last_supplied_password_info_iter_;
// Set if the user might be submitting a password form on the current page,
// but the submit may still fail (i.e. doesn't pass JavaScript validation).
ProvisionallySavedPasswordForm provisionally_saved_form_;
// Map WebFormControlElement to the pair of:
// 1) The most recent text that user typed or PasswordManager autofilled in
// input elements. Used for storing username/password before JavaScript
......@@ -489,6 +484,12 @@ class PasswordAutofillAgent : public content::RenderFrameObserver,
// True indicates that a request for credentials has been sent to the store.
bool sent_request_to_store_;
// True indicates that a form data has been sent to the browser process. Gets
// cleared when the form is submitted to indicate that the browser has already
// processed the form.
// TODO(crbug.com/949519): double check if we need this variable.
bool browser_has_form_to_process_ = false;
// True indicates that a safe browsing reputation check has been triggered.
bool checked_safe_browsing_reputation_;
......
// Copyright 2017 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/content/renderer/provisionally_saved_password_form.h"
#include <utility>
namespace autofill {
ProvisionallySavedPasswordForm::ProvisionallySavedPasswordForm() = default;
ProvisionallySavedPasswordForm::~ProvisionallySavedPasswordForm() = default;
void ProvisionallySavedPasswordForm::Set(
std::unique_ptr<PasswordForm> password_form,
const blink::WebFormElement& form_element,
const blink::WebInputElement& input_element) {
password_form_ = std::move(password_form);
form_element_ = form_element;
input_element_ = input_element;
}
void ProvisionallySavedPasswordForm::Reset() {
password_form_.reset();
form_element_.Reset();
input_element_.Reset();
}
bool ProvisionallySavedPasswordForm::IsSet() const {
return static_cast<bool>(password_form_);
}
bool ProvisionallySavedPasswordForm::IsPasswordValid() const {
return IsSet() && !(password_form_->password_value.empty() &&
password_form_->new_password_value.empty());
}
void ProvisionallySavedPasswordForm::SetSubmissionIndicatorEvent(
mojom::SubmissionIndicatorEvent event) {
if (password_form_) {
password_form_->submission_event = event;
password_form_->form_data.submission_event = event;
}
}
} // namespace autofill
// Copyright 2017 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_CONTENT_RENDERER_PROVISIONALLY_SAVED_PASSWORD_FORM_H_
#define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PROVISIONALLY_SAVED_PASSWORD_FORM_H_
#include <memory>
#include "base/macros.h"
#include "components/autofill/core/common/mojom/autofill_types.mojom.h"
#include "components/autofill/core/common/password_form.h"
#include "third_party/blink/public/web/web_input_element.h"
namespace autofill {
struct PasswordForm;
// Represents a possibly submitted password form.
class ProvisionallySavedPasswordForm {
public:
ProvisionallySavedPasswordForm();
~ProvisionallySavedPasswordForm();
// Sets the PasswordForm and web elements that were used in the PasswordForm
// update.
void Set(std::unique_ptr<PasswordForm> password_form,
const blink::WebFormElement& form_element,
const blink::WebInputElement& input_element);
void Reset();
// Returns true if the instance has |password_form_| set, but the actual
// password data may be invalid (e.g. empty username or password).
bool IsSet() const;
// Returns true if |password_form_| has enough information that it is likely
// filled out.
bool IsPasswordValid() const;
const PasswordForm& password_form() const {
DCHECK(IsSet());
return *password_form_;
}
blink::WebFormElement& form_element() { return form_element_; }
blink::WebInputElement& input_element() { return input_element_; }
void SetSubmissionIndicatorEvent(mojom::SubmissionIndicatorEvent event);
private:
std::unique_ptr<PasswordForm> password_form_;
// Last used WebFormElement for the PasswordForm submission. Can be null if
// the form is unowned.
blink::WebFormElement form_element_;
// Last used WebInputElement which led to the PasswordForm update. Can be null
// if the user has performed a form submission (via a button, for example).
blink::WebInputElement input_element_;
DISALLOW_COPY_AND_ASSIGN(ProvisionallySavedPasswordForm);
};
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PROVISIONALLY_SAVED_PASSWORD_FORM_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment