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

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

Issue 1002653002: [Password Manager] Use XHR completion as a possible signal for form submission (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 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 c55ec4512c49917820f6572457617bb86bad69d7..0cfd948c47147bd49044ef99995960a0a2097a1e 100644
--- a/components/autofill/content/renderer/password_autofill_agent.cc
+++ b/components/autofill/content/renderer/password_autofill_agent.cc
@@ -848,9 +848,59 @@ bool PasswordAutofillAgent::OriginCanAccessPasswordManager(
}
void PasswordAutofillAgent::OnDynamicFormsSeen() {
+ //LOG(INFO) << this << "DynamicFormsSeen";
SendPasswordForms(false /* only_visible */);
}
+void PasswordAutofillAgent::OnFormElementsRemoved(
+ const blink::WebVector<blink::WebNode>& nodes) {
+ //LOG(INFO) << nodes.size();
+ std::set<blink::WebFormElement> form_elements;
+ for (size_t i = 0; i < nodes.size(); ++i) {
+ if (!nodes[i].isElementNode()) {
+ //LOG(INFO) << "early exit";
+ continue;
+ }
+
+ blink::WebElement element = nodes[i].toConst<blink::WebElement>();
+ if (!element.hasHTMLTagName("input")) {
+ //LOG(INFO) << "later exit";
+ continue;
+ }
+
+ blink::WebInputElement input_element = element.to<blink::WebInputElement>();
+ //LOG(INFO) << input_element.getAttribute("id").utf8();
+ if (!input_element.form().isNull()) {
+ //LOG(INFO) << input_element.form().name().utf8();
+ form_elements.insert(input_element.form());
+ } else {
+ //LOG(INFO) << "no form";
+ }
+ }
+ //LOG(INFO) << form_elements.size();
+
+ if (!provisionally_saved_form_ ||
+ provisionally_saved_form_->username_value.empty() ||
+ (provisionally_saved_form_->password_value.empty() &&
+ provisionally_saved_form_->new_password_value.empty())) {
+ //LOG(INFO) << "no provisionally saved form";
+ return;
+ }
+
+ //LOG(INFO) << provisionally_saved_form_->action;
+ for (std::set<blink::WebFormElement>::iterator it = form_elements.begin();
+ it != form_elements.end(); ++it) {
+ GURL action(GetCanonicalActionURL(*it));
+ //LOG(INFO) << action.spec();
+ if (action == provisionally_saved_form_->action) {
+ Send(new AutofillHostMsg_PasswordFormSubmitted(
+ routing_id(), *provisionally_saved_form_));
+ provisionally_saved_form_.reset();
+ return;
+ }
+ }
+}
+
void PasswordAutofillAgent::FirstUserGestureObserved() {
gatekeeper_.OnUserGesture();
}
@@ -992,11 +1042,24 @@ void PasswordAutofillAgent::DidStopLoading() {
}
void PasswordAutofillAgent::FrameDetached() {
+ /* LOG(INFO) << this << "closing";
+ if (!render_frame()->GetWebFrame()->parent())
+ LOG(INFO) << "MainFrame";
+ if (ProvisionallySavedPasswordIsValid())
+ LOG(INFO) << "Password Valid";*/
+ if (render_frame()->GetWebFrame()->parent() &&
+ ProvisionallySavedPasswordIsValid()) {
+ //LOG(INFO) << "SENDING";
+ Send(new AutofillHostMsg_PasswordFormSubmitted(
+ routing_id(), *provisionally_saved_form_));
+ provisionally_saved_form_.reset();
+ }
FrameClosing();
}
void PasswordAutofillAgent::WillSendSubmitEvent(
const blink::WebFormElement& form) {
+ LOG(INFO) << "Will send submit event";
// 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,
@@ -1355,6 +1418,52 @@ void PasswordAutofillAgent::ProvisionallySavePassword(
provisionally_saved_form_ = password_form.Pass();
}
+bool PasswordAutofillAgent::ProvisionallySavedPasswordIsValid() {
+ return provisionally_saved_form_ &&
+ !provisionally_saved_form_->username_value.empty() &&
+ (!provisionally_saved_form_->password_value.empty() ||
+ provisionally_saved_form_->new_password_value.empty());
+}
+
+void PasswordAutofillAgent::XHRSucceeded() {
+ blink::WebFrame* frame = render_frame()->GetWebFrame();
+ blink::WebVector<blink::WebFormElement> forms;
+ frame->document().forms(forms);
+
+ if (!provisionally_saved_form_ ||
+ provisionally_saved_form_->username_value.empty() ||
+ (provisionally_saved_form_->password_value.empty() &&
+ provisionally_saved_form_->new_password_value.empty()))
+ return;
+
+ bool matched = false;
+ std::vector<PasswordForm> password_forms;
+ for (size_t i = 0; i < forms.size(); ++i) {
+ const blink::WebFormElement& form = forms[i];
+ bool is_form_visible = IsWebNodeVisible(form);
+
+ // If requested, ignore non-rendered forms, e.g., those styled with
+ // display:none.
+ if (!is_form_visible) {
+ LOG(INFO) << "Form: " << form.action().utf8() << "is invisible";
+ continue;
+ }
+
+ scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form, nullptr));
+ if (password_form.get()) {
+ password_forms.push_back(*password_form);
+ if (provisionally_saved_form_->username_element == password_form->username_element &&
+ (provisionally_saved_form_->password_element == password_form->password_element ||
+ provisionally_saved_form_->new_password_element == password_form->new_password_element)) {
+ matched = true;
+ }
+ }
+ }
+ LOG(INFO) << password_forms.size();
+ if (!matched)
+ LOG(INFO) << "Should Save";
+}
+
// LegacyPasswordAutofillAgent -------------------------------------------------
PasswordAutofillAgent::LegacyPasswordAutofillAgent::LegacyPasswordAutofillAgent(

Powered by Google App Engine
This is Rietveld 408576698