| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/content/renderer/password_autofill_agent.h" | 5 #include "components/autofill/content/renderer/password_autofill_agent.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "components/autofill/content/common/autofill_messages.h" | 12 #include "components/autofill/content/common/autofill_messages.h" |
| 13 #include "components/autofill/content/renderer/form_autofill_util.h" | 13 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 14 #include "components/autofill/content/renderer/password_form_conversion_utils.h" | 14 #include "components/autofill/content/renderer/password_form_conversion_utils.h" |
| 15 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" |
| 15 #include "components/autofill/core/common/form_field_data.h" | 16 #include "components/autofill/core/common/form_field_data.h" |
| 16 #include "components/autofill/core/common/password_autofill_util.h" | 17 #include "components/autofill/core/common/password_autofill_util.h" |
| 17 #include "components/autofill/core/common/password_form.h" | 18 #include "components/autofill/core/common/password_form.h" |
| 18 #include "components/autofill/core/common/password_form_fill_data.h" | 19 #include "components/autofill/core/common/password_form_fill_data.h" |
| 19 #include "content/public/renderer/render_view.h" | 20 #include "content/public/renderer/render_view.h" |
| 20 #include "third_party/WebKit/public/platform/WebVector.h" | 21 #include "third_party/WebKit/public/platform/WebVector.h" |
| 21 #include "third_party/WebKit/public/web/WebAutofillClient.h" | 22 #include "third_party/WebKit/public/web/WebAutofillClient.h" |
| 22 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
| 23 #include "third_party/WebKit/public/web/WebElement.h" | 24 #include "third_party/WebKit/public/web/WebElement.h" |
| 24 #include "third_party/WebKit/public/web/WebFormElement.h" | 25 #include "third_party/WebKit/public/web/WebFormElement.h" |
| 25 #include "third_party/WebKit/public/web/WebInputEvent.h" | 26 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 27 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 27 #include "third_party/WebKit/public/web/WebNode.h" | 28 #include "third_party/WebKit/public/web/WebNode.h" |
| 28 #include "third_party/WebKit/public/web/WebNodeList.h" | 29 #include "third_party/WebKit/public/web/WebNodeList.h" |
| 29 #include "third_party/WebKit/public/web/WebPasswordFormData.h" | 30 #include "third_party/WebKit/public/web/WebPasswordFormData.h" |
| 30 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 31 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 31 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 32 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 32 #include "third_party/WebKit/public/web/WebView.h" | 33 #include "third_party/WebKit/public/web/WebView.h" |
| 33 #include "ui/events/keycodes/keyboard_codes.h" | 34 #include "ui/events/keycodes/keyboard_codes.h" |
| 35 #include "url/gurl.h" |
| 34 | 36 |
| 35 namespace autofill { | 37 namespace autofill { |
| 36 namespace { | 38 namespace { |
| 37 | 39 |
| 38 // The size above which we stop triggering autocomplete. | 40 // The size above which we stop triggering autocomplete. |
| 39 static const size_t kMaximumTextSizeForAutocomplete = 1000; | 41 static const size_t kMaximumTextSizeForAutocomplete = 1000; |
| 40 | 42 |
| 41 // Maps element names to the actual elements to simplify form filling. | 43 // Maps element names to the actual elements to simplify form filling. |
| 42 typedef std::map<base::string16, blink::WebInputElement> FormInputElementMap; | 44 typedef std::map<base::string16, blink::WebInputElement> FormInputElementMap; |
| 43 | 45 |
| 46 // Use the shorter name when referencing SavePasswordProgressLogger::StringID |
| 47 // values to spare line breaks. The code provides enough context for that |
| 48 // already. |
| 49 typedef SavePasswordProgressLogger Logger; |
| 50 |
| 44 // Utility struct for form lookup and autofill. When we parse the DOM to look up | 51 // Utility struct for form lookup and autofill. When we parse the DOM to look up |
| 45 // a form, in addition to action and origin URL's we have to compare all | 52 // a form, in addition to action and origin URL's we have to compare all |
| 46 // necessary form elements. To avoid having to look these up again when we want | 53 // necessary form elements. To avoid having to look these up again when we want |
| 47 // to fill the form, the FindFormElements function stores the pointers | 54 // to fill the form, the FindFormElements function stores the pointers |
| 48 // in a FormElements* result, referenced to ensure they are safe to use. | 55 // in a FormElements* result, referenced to ensure they are safe to use. |
| 49 struct FormElements { | 56 struct FormElements { |
| 50 blink::WebFormElement form_element; | 57 blink::WebFormElement form_element; |
| 51 FormInputElementMap input_elements; | 58 FormInputElementMap input_elements; |
| 52 }; | 59 }; |
| 53 | 60 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // appropriately named elements match the element to be saved. Currently | 200 // appropriately named elements match the element to be saved. Currently |
| 194 // we ignore filling passwords where naming is ambigious anyway. | 201 // we ignore filling passwords where naming is ambigious anyway. |
| 195 for (size_t i = 0; i < temp_elements.size(); ++i) { | 202 for (size_t i = 0; i < temp_elements.size(); ++i) { |
| 196 if (temp_elements[i].to<blink::WebElement>().getAttribute("value") == | 203 if (temp_elements[i].to<blink::WebElement>().getAttribute("value") == |
| 197 form.password_value) | 204 form.password_value) |
| 198 return true; | 205 return true; |
| 199 } | 206 } |
| 200 return false; | 207 return false; |
| 201 } | 208 } |
| 202 | 209 |
| 210 // Log a message including the name, method and action of |form|. |
| 211 void LogHTMLForm(SavePasswordProgressLogger* logger, |
| 212 SavePasswordProgressLogger::StringID message_id, |
| 213 const blink::WebFormElement& form) { |
| 214 logger->LogHTMLForm(message_id, |
| 215 form.name().utf8(), |
| 216 form.method().utf8(), |
| 217 GURL(form.action().utf8())); |
| 218 } |
| 219 |
| 203 } // namespace | 220 } // namespace |
| 204 | 221 |
| 205 //////////////////////////////////////////////////////////////////////////////// | 222 //////////////////////////////////////////////////////////////////////////////// |
| 206 // PasswordAutofillAgent, public: | 223 // PasswordAutofillAgent, public: |
| 207 | 224 |
| 208 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderView* render_view) | 225 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderView* render_view) |
| 209 : content::RenderViewObserver(render_view), | 226 : content::RenderViewObserver(render_view), |
| 210 usernames_usage_(NOTHING_TO_AUTOFILL), | 227 usernames_usage_(NOTHING_TO_AUTOFILL), |
| 211 web_view_(render_view->GetWebView()), | 228 web_view_(render_view->GetWebView()), |
| 229 logging_state_active_(false), |
| 212 weak_ptr_factory_(this) { | 230 weak_ptr_factory_(this) { |
| 213 } | 231 } |
| 214 | 232 |
| 215 PasswordAutofillAgent::~PasswordAutofillAgent() { | 233 PasswordAutofillAgent::~PasswordAutofillAgent() { |
| 216 } | 234 } |
| 217 | 235 |
| 218 PasswordAutofillAgent::PasswordValueGatekeeper::PasswordValueGatekeeper() | 236 PasswordAutofillAgent::PasswordValueGatekeeper::PasswordValueGatekeeper() |
| 219 : was_user_gesture_seen_(false) { | 237 : was_user_gesture_seen_(false) { |
| 220 } | 238 } |
| 221 | 239 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 void PasswordAutofillAgent::OnDynamicFormsSeen(blink::WebFrame* frame) { | 423 void PasswordAutofillAgent::OnDynamicFormsSeen(blink::WebFrame* frame) { |
| 406 SendPasswordForms(frame, false /* only_visible */); | 424 SendPasswordForms(frame, false /* only_visible */); |
| 407 } | 425 } |
| 408 | 426 |
| 409 void PasswordAutofillAgent::FirstUserGestureObserved() { | 427 void PasswordAutofillAgent::FirstUserGestureObserved() { |
| 410 gatekeeper_.OnUserGesture(); | 428 gatekeeper_.OnUserGesture(); |
| 411 } | 429 } |
| 412 | 430 |
| 413 void PasswordAutofillAgent::SendPasswordForms(blink::WebFrame* frame, | 431 void PasswordAutofillAgent::SendPasswordForms(blink::WebFrame* frame, |
| 414 bool only_visible) { | 432 bool only_visible) { |
| 433 scoped_ptr<RendererSavePasswordProgressLogger> logger; |
| 434 // From the perspective of saving passwords, only calls with |only_visible| |
| 435 // being true are important -- the decision whether to save the password is |
| 436 // only made after visible forms are known, for failed login detection. Calls |
| 437 // with |only_visible| false are important for password form autofill, which |
| 438 // is currently not part of the logging. |
| 439 if (only_visible && logging_state_active_) { |
| 440 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); |
| 441 logger->LogMessage(Logger::STRING_SEND_PASSWORD_FORMS_METHOD); |
| 442 } |
| 443 |
| 415 // Make sure that this security origin is allowed to use password manager. | 444 // Make sure that this security origin is allowed to use password manager. |
| 416 blink::WebSecurityOrigin origin = frame->document().securityOrigin(); | 445 blink::WebSecurityOrigin origin = frame->document().securityOrigin(); |
| 417 if (!OriginCanAccessPasswordManager(origin)) | 446 if (logger) { |
| 447 logger->LogURL(Logger::STRING_SECURITY_ORIGIN, |
| 448 GURL(origin.toString().utf8())); |
| 449 } |
| 450 if (!OriginCanAccessPasswordManager(origin)) { |
| 451 if (logger) { |
| 452 logger->LogMessage(Logger::STRING_SECURITY_ORIGIN_FAILURE); |
| 453 logger->LogMessage(Logger::STRING_DECISION_DROP); |
| 454 } |
| 418 return; | 455 return; |
| 456 } |
| 419 | 457 |
| 420 // Checks whether the webpage is a redirect page or an empty page. | 458 // Checks whether the webpage is a redirect page or an empty page. |
| 421 if (IsWebpageEmpty(frame)) | 459 if (IsWebpageEmpty(frame)) { |
| 460 if (logger) { |
| 461 logger->LogMessage(Logger::STRING_WEBPAGE_EMPTY); |
| 462 logger->LogMessage(Logger::STRING_DECISION_DROP); |
| 463 } |
| 422 return; | 464 return; |
| 465 } |
| 423 | 466 |
| 424 blink::WebVector<blink::WebFormElement> forms; | 467 blink::WebVector<blink::WebFormElement> forms; |
| 425 frame->document().forms(forms); | 468 frame->document().forms(forms); |
| 469 if (logger) |
| 470 logger->LogNumber(Logger::STRING_NUMBER_OF_ALL_FORMS, forms.size()); |
| 426 | 471 |
| 427 std::vector<PasswordForm> password_forms; | 472 std::vector<PasswordForm> password_forms; |
| 428 for (size_t i = 0; i < forms.size(); ++i) { | 473 for (size_t i = 0; i < forms.size(); ++i) { |
| 429 const blink::WebFormElement& form = forms[i]; | 474 const blink::WebFormElement& form = forms[i]; |
| 475 bool is_form_visible = IsWebNodeVisible(form); |
| 476 if (logger) { |
| 477 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, form); |
| 478 logger->LogBoolean(Logger::STRING_FORM_IS_VISIBLE, is_form_visible); |
| 479 } |
| 430 | 480 |
| 431 // If requested, ignore non-rendered forms, e.g. those styled with | 481 // If requested, ignore non-rendered forms, e.g. those styled with |
| 432 // display:none. | 482 // display:none. |
| 433 if (only_visible && !IsWebNodeVisible(form)) | 483 if (only_visible && !is_form_visible) |
| 434 continue; | 484 continue; |
| 435 | 485 |
| 436 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form)); | 486 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form)); |
| 437 if (password_form.get()) | 487 if (password_form.get()) { |
| 488 if (logger) { |
| 489 logger->LogPasswordForm(Logger::STRING_FORM_IS_PASSWORD, |
| 490 *password_form); |
| 491 } |
| 438 password_forms.push_back(*password_form); | 492 password_forms.push_back(*password_form); |
| 493 } |
| 439 } | 494 } |
| 440 | 495 |
| 441 if (password_forms.empty() && !only_visible) { | 496 if (password_forms.empty() && !only_visible) { |
| 442 // We need to send the PasswordFormsRendered message regardless of whether | 497 // We need to send the PasswordFormsRendered message regardless of whether |
| 443 // there are any forms visible, as this is also the code path that triggers | 498 // there are any forms visible, as this is also the code path that triggers |
| 444 // showing the infobar. | 499 // showing the infobar. |
| 445 return; | 500 return; |
| 446 } | 501 } |
| 447 | 502 |
| 448 if (only_visible) { | 503 if (only_visible) { |
| 449 Send(new AutofillHostMsg_PasswordFormsRendered(routing_id(), | 504 Send(new AutofillHostMsg_PasswordFormsRendered(routing_id(), |
| 450 password_forms)); | 505 password_forms)); |
| 451 } else { | 506 } else { |
| 452 Send(new AutofillHostMsg_PasswordFormsParsed(routing_id(), password_forms)); | 507 Send(new AutofillHostMsg_PasswordFormsParsed(routing_id(), password_forms)); |
| 453 } | 508 } |
| 454 } | 509 } |
| 455 | 510 |
| 456 bool PasswordAutofillAgent::OnMessageReceived(const IPC::Message& message) { | 511 bool PasswordAutofillAgent::OnMessageReceived(const IPC::Message& message) { |
| 457 bool handled = true; | 512 bool handled = true; |
| 458 IPC_BEGIN_MESSAGE_MAP(PasswordAutofillAgent, message) | 513 IPC_BEGIN_MESSAGE_MAP(PasswordAutofillAgent, message) |
| 459 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordForm, OnFillPasswordForm) | 514 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordForm, OnFillPasswordForm) |
| 515 IPC_MESSAGE_HANDLER(AutofillMsg_ChangeLoggingState, OnChangeLoggingState) |
| 460 IPC_MESSAGE_UNHANDLED(handled = false) | 516 IPC_MESSAGE_UNHANDLED(handled = false) |
| 461 IPC_END_MESSAGE_MAP() | 517 IPC_END_MESSAGE_MAP() |
| 462 return handled; | 518 return handled; |
| 463 } | 519 } |
| 464 | 520 |
| 465 void PasswordAutofillAgent::DidStartLoading() { | 521 void PasswordAutofillAgent::DidStartLoading() { |
| 466 if (usernames_usage_ != NOTHING_TO_AUTOFILL) { | 522 if (usernames_usage_ != NOTHING_TO_AUTOFILL) { |
| 467 UMA_HISTOGRAM_ENUMERATION("PasswordManager.OtherPossibleUsernamesUsage", | 523 UMA_HISTOGRAM_ENUMERATION("PasswordManager.OtherPossibleUsernamesUsage", |
| 468 usernames_usage_, | 524 usernames_usage_, |
| 469 OTHER_POSSIBLE_USERNAMES_MAX); | 525 OTHER_POSSIBLE_USERNAMES_MAX); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 // into a hidden field and then clear the password (http://crbug.com/28910). | 557 // into a hidden field and then clear the password (http://crbug.com/28910). |
| 502 // This method gets called before any of those handlers run, so save away | 558 // This method gets called before any of those handlers run, so save away |
| 503 // a copy of the password in case it gets lost. | 559 // a copy of the password in case it gets lost. |
| 504 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form)); | 560 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form)); |
| 505 if (password_form) | 561 if (password_form) |
| 506 provisionally_saved_forms_[frame].reset(password_form.release()); | 562 provisionally_saved_forms_[frame].reset(password_form.release()); |
| 507 } | 563 } |
| 508 | 564 |
| 509 void PasswordAutofillAgent::WillSubmitForm(blink::WebLocalFrame* frame, | 565 void PasswordAutofillAgent::WillSubmitForm(blink::WebLocalFrame* frame, |
| 510 const blink::WebFormElement& form) { | 566 const blink::WebFormElement& form) { |
| 567 scoped_ptr<RendererSavePasswordProgressLogger> logger; |
| 568 if (logging_state_active_) { |
| 569 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); |
| 570 logger->LogMessage(Logger::STRING_WILL_SUBMIT_FORM_METHOD); |
| 571 LogHTMLForm(logger.get(), Logger::STRING_HTML_FORM_FOR_SUBMIT, form); |
| 572 } |
| 573 |
| 511 scoped_ptr<PasswordForm> submitted_form = CreatePasswordForm(form); | 574 scoped_ptr<PasswordForm> submitted_form = CreatePasswordForm(form); |
| 512 | 575 |
| 513 // If there is a provisionally saved password, copy over the previous | 576 // If there is a provisionally saved password, copy over the previous |
| 514 // password value so we get the user's typed password, not the value that | 577 // password value so we get the user's typed password, not the value that |
| 515 // may have been transformed for submit. | 578 // may have been transformed for submit. |
| 516 // TODO(gcasto): Do we need to have this action equality check? Is it trying | 579 // TODO(gcasto): Do we need to have this action equality check? Is it trying |
| 517 // to prevent accidentally copying over passwords from a different form? | 580 // to prevent accidentally copying over passwords from a different form? |
| 518 if (submitted_form) { | 581 if (submitted_form) { |
| 582 if (logger) { |
| 583 logger->LogPasswordForm(Logger::STRING_CREATED_PASSWORD_FORM, |
| 584 *submitted_form); |
| 585 } |
| 519 if (provisionally_saved_forms_[frame].get() && | 586 if (provisionally_saved_forms_[frame].get() && |
| 520 submitted_form->action == provisionally_saved_forms_[frame]->action) { | 587 submitted_form->action == provisionally_saved_forms_[frame]->action) { |
| 588 if (logger) |
| 589 logger->LogMessage(Logger::STRING_SUBMITTED_PASSWORD_REPLACED); |
| 521 submitted_form->password_value = | 590 submitted_form->password_value = |
| 522 provisionally_saved_forms_[frame]->password_value; | 591 provisionally_saved_forms_[frame]->password_value; |
| 523 } | 592 } |
| 524 | 593 |
| 525 // Some observers depend on sending this information now instead of when | 594 // Some observers depend on sending this information now instead of when |
| 526 // the frame starts loading. If there are redirects that cause a new | 595 // the frame starts loading. If there are redirects that cause a new |
| 527 // RenderView to be instantiated (such as redirects to the WebStore) | 596 // RenderView to be instantiated (such as redirects to the WebStore) |
| 528 // we will never get to finish the load. | 597 // we will never get to finish the load. |
| 529 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(), | 598 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(), |
| 530 *submitted_form)); | 599 *submitted_form)); |
| 531 // Remove reference since we have already submitted this form. | 600 // Remove reference since we have already submitted this form. |
| 532 provisionally_saved_forms_.erase(frame); | 601 provisionally_saved_forms_.erase(frame); |
| 602 } else if (logger) { |
| 603 logger->LogMessage(Logger::STRING_DECISION_DROP); |
| 533 } | 604 } |
| 534 } | 605 } |
| 535 | 606 |
| 536 blink::WebFrame* PasswordAutofillAgent::CurrentOrChildFrameWithSavedForms( | 607 blink::WebFrame* PasswordAutofillAgent::CurrentOrChildFrameWithSavedForms( |
| 537 const blink::WebFrame* current_frame) { | 608 const blink::WebFrame* current_frame) { |
| 538 for (FrameToPasswordFormMap::const_iterator it = | 609 for (FrameToPasswordFormMap::const_iterator it = |
| 539 provisionally_saved_forms_.begin(); | 610 provisionally_saved_forms_.begin(); |
| 540 it != provisionally_saved_forms_.end(); | 611 it != provisionally_saved_forms_.end(); |
| 541 ++it) { | 612 ++it) { |
| 542 blink::WebFrame* form_frame = it->first; | 613 blink::WebFrame* form_frame = it->first; |
| 543 // The check that the returned frame is related to |current_frame| is mainly | 614 // The check that the returned frame is related to |current_frame| is mainly |
| 544 // for double-checking. There should not be any unrelated frames in | 615 // for double-checking. There should not be any unrelated frames in |
| 545 // |provisionally_saved_forms_|, because the map is cleared after | 616 // |provisionally_saved_forms_|, because the map is cleared after |
| 546 // navigation. If there are reasons to remove this check in the future and | 617 // navigation. If there are reasons to remove this check in the future and |
| 547 // keep just the first frame found, it might be a good idea to add a UMA | 618 // keep just the first frame found, it might be a good idea to add a UMA |
| 548 // statistic or a similar check on how many frames are here to choose from. | 619 // statistic or a similar check on how many frames are here to choose from. |
| 549 if (current_frame == form_frame || | 620 if (current_frame == form_frame || |
| 550 current_frame->findChildByName(form_frame->assignedName())) { | 621 current_frame->findChildByName(form_frame->assignedName())) { |
| 551 return form_frame; | 622 return form_frame; |
| 552 } | 623 } |
| 553 } | 624 } |
| 554 return NULL; | 625 return NULL; |
| 555 } | 626 } |
| 556 | 627 |
| 557 void PasswordAutofillAgent::DidStartProvisionalLoad( | 628 void PasswordAutofillAgent::DidStartProvisionalLoad( |
| 558 blink::WebLocalFrame* frame) { | 629 blink::WebLocalFrame* frame) { |
| 630 scoped_ptr<RendererSavePasswordProgressLogger> logger; |
| 631 if (logging_state_active_) { |
| 632 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); |
| 633 logger->LogMessage(Logger::STRING_DID_START_PROVISIONAL_LOAD_METHOD); |
| 634 } |
| 635 |
| 559 if (!frame->parent()) { | 636 if (!frame->parent()) { |
| 560 // If the navigation is not triggered by a user gesture, e.g. by some ajax | 637 // If the navigation is not triggered by a user gesture, e.g. by some ajax |
| 561 // callback, then inherit the submitted password form from the previous | 638 // callback, then inherit the submitted password form from the previous |
| 562 // state. This fixes the no password save issue for ajax login, tracked in | 639 // state. This fixes the no password save issue for ajax login, tracked in |
| 563 // [http://crbug/43219]. Note that this still fails for sites that use | 640 // [http://crbug/43219]. Note that this still fails for sites that use |
| 564 // synchonous XHR as isProcessingUserGesture() will return true. | 641 // synchonous XHR as isProcessingUserGesture() will return true. |
| 565 blink::WebFrame* form_frame = CurrentOrChildFrameWithSavedForms(frame); | 642 blink::WebFrame* form_frame = CurrentOrChildFrameWithSavedForms(frame); |
| 643 if (logger) { |
| 644 logger->LogBoolean(Logger::STRING_FORM_FRAME_EQ_FRAME, |
| 645 form_frame == frame); |
| 646 } |
| 566 if (!blink::WebUserGestureIndicator::isProcessingUserGesture()) { | 647 if (!blink::WebUserGestureIndicator::isProcessingUserGesture()) { |
| 567 // If onsubmit has been called, try and save that form. | 648 // If onsubmit has been called, try and save that form. |
| 568 if (provisionally_saved_forms_[form_frame].get()) { | 649 if (provisionally_saved_forms_[form_frame].get()) { |
| 650 if (logger) { |
| 651 logger->LogPasswordForm( |
| 652 Logger::STRING_PROVISIONALLY_SAVED_FORM_FOR_FRAME, |
| 653 *provisionally_saved_forms_[form_frame]); |
| 654 } |
| 569 Send(new AutofillHostMsg_PasswordFormSubmitted( | 655 Send(new AutofillHostMsg_PasswordFormSubmitted( |
| 570 routing_id(), *provisionally_saved_forms_[form_frame])); | 656 routing_id(), *provisionally_saved_forms_[form_frame])); |
| 571 provisionally_saved_forms_.erase(form_frame); | 657 provisionally_saved_forms_.erase(form_frame); |
| 572 } else { | 658 } else { |
| 573 // Loop through the forms on the page looking for one that has been | 659 // Loop through the forms on the page looking for one that has been |
| 574 // filled out. If one exists, try and save the credentials. | 660 // filled out. If one exists, try and save the credentials. |
| 575 blink::WebVector<blink::WebFormElement> forms; | 661 blink::WebVector<blink::WebFormElement> forms; |
| 576 frame->document().forms(forms); | 662 frame->document().forms(forms); |
| 577 | 663 |
| 664 bool password_forms_found = false; |
| 578 for (size_t i = 0; i < forms.size(); ++i) { | 665 for (size_t i = 0; i < forms.size(); ++i) { |
| 579 blink::WebFormElement form_element = forms[i]; | 666 blink::WebFormElement form_element = forms[i]; |
| 667 if (logger) { |
| 668 LogHTMLForm( |
| 669 logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, form_element); |
| 670 } |
| 580 scoped_ptr<PasswordForm> password_form( | 671 scoped_ptr<PasswordForm> password_form( |
| 581 CreatePasswordForm(form_element)); | 672 CreatePasswordForm(form_element)); |
| 582 if (password_form.get() && !password_form->username_value.empty() && | 673 if (password_form.get() && !password_form->username_value.empty() && |
| 583 !password_form->password_value.empty() && | 674 !password_form->password_value.empty() && |
| 584 !PasswordValueIsDefault(*password_form, form_element)) { | 675 !PasswordValueIsDefault(*password_form, form_element)) { |
| 676 password_forms_found = true; |
| 677 if (logger) { |
| 678 logger->LogPasswordForm( |
| 679 Logger::STRING_PASSWORD_FORM_FOUND_ON_PAGE, *password_form); |
| 680 } |
| 585 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(), | 681 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(), |
| 586 *password_form)); | 682 *password_form)); |
| 587 } | 683 } |
| 588 } | 684 } |
| 685 if (!password_forms_found && logger) { |
| 686 logger->LogMessage(Logger::STRING_DECISION_DROP); |
| 687 } |
| 589 } | 688 } |
| 590 } | 689 } |
| 591 // Clear the whole map during main frame navigation. | 690 // Clear the whole map during main frame navigation. |
| 592 provisionally_saved_forms_.clear(); | 691 provisionally_saved_forms_.clear(); |
| 593 | 692 |
| 594 // This is a new navigation, so require a new user gesture before filling in | 693 // This is a new navigation, so require a new user gesture before filling in |
| 595 // passwords. | 694 // passwords. |
| 596 gatekeeper_.Reset(); | 695 gatekeeper_.Reset(); |
| 696 } else { |
| 697 if (logger) |
| 698 logger->LogMessage(Logger::STRING_DECISION_DROP); |
| 597 } | 699 } |
| 598 } | 700 } |
| 599 | 701 |
| 600 void PasswordAutofillAgent::OnFillPasswordForm( | 702 void PasswordAutofillAgent::OnFillPasswordForm( |
| 601 const PasswordFormFillData& form_data) { | 703 const PasswordFormFillData& form_data) { |
| 602 if (usernames_usage_ == NOTHING_TO_AUTOFILL) { | 704 if (usernames_usage_ == NOTHING_TO_AUTOFILL) { |
| 603 if (form_data.other_possible_usernames.size()) | 705 if (form_data.other_possible_usernames.size()) |
| 604 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_PRESENT; | 706 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_PRESENT; |
| 605 else if (usernames_usage_ == NOTHING_TO_AUTOFILL) | 707 else if (usernames_usage_ == NOTHING_TO_AUTOFILL) |
| 606 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_ABSENT; | 708 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_ABSENT; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 | 743 |
| 642 FormData form; | 744 FormData form; |
| 643 FormFieldData field; | 745 FormFieldData field; |
| 644 FindFormAndFieldForFormControlElement( | 746 FindFormAndFieldForFormControlElement( |
| 645 username_element, &form, &field, REQUIRE_NONE); | 747 username_element, &form, &field, REQUIRE_NONE); |
| 646 Send(new AutofillHostMsg_AddPasswordFormMapping( | 748 Send(new AutofillHostMsg_AddPasswordFormMapping( |
| 647 routing_id(), field, form_data)); | 749 routing_id(), field, form_data)); |
| 648 } | 750 } |
| 649 } | 751 } |
| 650 | 752 |
| 753 void PasswordAutofillAgent::OnChangeLoggingState(bool active) { |
| 754 logging_state_active_ = active; |
| 755 } |
| 756 |
| 651 //////////////////////////////////////////////////////////////////////////////// | 757 //////////////////////////////////////////////////////////////////////////////// |
| 652 // PasswordAutofillAgent, private: | 758 // PasswordAutofillAgent, private: |
| 653 | 759 |
| 654 void PasswordAutofillAgent::GetSuggestions( | 760 void PasswordAutofillAgent::GetSuggestions( |
| 655 const PasswordFormFillData& fill_data, | 761 const PasswordFormFillData& fill_data, |
| 656 const base::string16& input, | 762 const base::string16& input, |
| 657 std::vector<base::string16>* suggestions, | 763 std::vector<base::string16>* suggestions, |
| 658 std::vector<base::string16>* realms) { | 764 std::vector<base::string16>* realms) { |
| 659 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) { | 765 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) { |
| 660 suggestions->push_back(fill_data.basic_data.fields[0].value); | 766 suggestions->push_back(fill_data.basic_data.fields[0].value); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); | 1009 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); |
| 904 if (iter == login_to_password_info_.end()) | 1010 if (iter == login_to_password_info_.end()) |
| 905 return false; | 1011 return false; |
| 906 | 1012 |
| 907 *found_input = input; | 1013 *found_input = input; |
| 908 *found_password = iter->second; | 1014 *found_password = iter->second; |
| 909 return true; | 1015 return true; |
| 910 } | 1016 } |
| 911 | 1017 |
| 912 } // namespace autofill | 1018 } // namespace autofill |
| OLD | NEW |