Chromium Code Reviews| 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 81a822ad84d6f5525602acdad47cb59c784ed9a1..834e1de47a9e95846ac1db223ae9863e5f80b689 100644 |
| --- a/components/autofill/content/renderer/password_autofill_agent.cc |
| +++ b/components/autofill/content/renderer/password_autofill_agent.cc |
| @@ -201,15 +201,45 @@ PasswordAutofillAgent::PasswordAutofillAgent(content::RenderView* render_view) |
| : content::RenderViewObserver(render_view), |
| usernames_usage_(NOTHING_TO_AUTOFILL), |
| web_view_(render_view->GetWebView()), |
| - gesture_handler_(new AutofillWebUserGestureHandler(this)), |
| - user_gesture_occurred_(false), |
| weak_ptr_factory_(this) { |
| - blink::WebUserGestureIndicator::setHandler(gesture_handler_.get()); |
| } |
| -PasswordAutofillAgent::~PasswordAutofillAgent() { |
| - DCHECK(gesture_handler_.get()); |
| - blink::WebUserGestureIndicator::setHandler(NULL); |
| +PasswordAutofillAgent::~PasswordAutofillAgent() {} |
| + |
| +PasswordAutofillAgent::PasswordValueGatekeeper::PasswordValueGatekeeper() |
| + : was_gesture_seen_(false) {} |
| + |
| +PasswordAutofillAgent::PasswordValueGatekeeper::~PasswordValueGatekeeper() {} |
| + |
| +void PasswordAutofillAgent::PasswordValueGatekeeper::RegisterElement( |
| + blink::WebInputElement& element) { |
| + if (was_gesture_seen_) |
| + ShowValue(element); |
| + else |
| + elements_.push_back(element); |
| +} |
| + |
| +void PasswordAutofillAgent::PasswordValueGatekeeper::ShowValue( |
| + blink::WebInputElement& element) { |
| + if (!element.isNull() && !element.suggestedValue().isNull()) |
| + element.setValue(element.suggestedValue(), true); |
| +} |
| + |
| +void PasswordAutofillAgent::PasswordValueGatekeeper::OnGesture() { |
| + was_gesture_seen_ = true; |
| + |
| + for (std::vector<blink::WebInputElement>::iterator iter = elements_.begin(); |
| + iter != elements_.end(); |
| + ++iter) { |
| + ShowValue(*iter); |
| + } |
| + |
| + elements_.clear(); |
| +} |
| + |
| +void PasswordAutofillAgent::PasswordValueGatekeeper::Reset() { |
| + was_gesture_seen_ = false; |
| + elements_.clear(); |
| } |
| bool PasswordAutofillAgent::TextFieldDidEndEditing( |
| @@ -477,6 +507,21 @@ void PasswordAutofillAgent::WillSubmitForm(blink::WebFrame* frame, |
| } |
| } |
| +void PasswordAutofillAgent::DidHandleKeyEvent() { |
|
jww
2014/02/13 21:34:00
To ask what I think is a silly question, these fun
vabr (Chromium)
2014/02/14 08:13:12
Thanks for bringing this up!
I double-checked, and
|
| + gatekeeper_.OnGesture(); |
| +} |
| + |
| +void PasswordAutofillAgent::DidHandleMouseEvent( |
| + const blink::WebMouseEvent& event) { |
| + if (event.button != blink::WebMouseEvent::ButtonNone) |
| + gatekeeper_.OnGesture(); |
| +} |
| + |
| +void PasswordAutofillAgent::DidHandleTouchEvent( |
| + const blink::WebTouchEvent& /*event*/) { |
| + gatekeeper_.OnGesture(); |
| +} |
| + |
| blink::WebFrame* PasswordAutofillAgent::CurrentOrChildFrameWithSavedForms( |
| const blink::WebFrame* current_frame) { |
| for (FrameToPasswordFormMap::const_iterator it = |
| @@ -534,10 +579,9 @@ void PasswordAutofillAgent::DidStartProvisionalLoad(blink::WebFrame* frame) { |
| // Clear the whole map during main frame navigation. |
| provisionally_saved_forms_.clear(); |
| - // We are navigating, se we need to wait for a new user gesture before |
| + // New navigation means the need to wait for a new user gesture before |
| // filling in passwords. |
| - user_gesture_occurred_ = false; |
| - gesture_handler_->clearElements(); |
| + gatekeeper_.Reset(); |
| } |
| } |
| @@ -772,16 +816,12 @@ bool PasswordAutofillAgent::FillUserNameAndPassword( |
| return false; |
| } |
| - // If a user gesture has not occurred, we setup a handler to listen for the |
| - // next user gesture, at which point we then fill in the password. This is to |
| - // make sure that we do not fill in the DOM with a password until we believe |
| - // the user is intentionally interacting with the page. |
| - if (!user_gesture_occurred_) { |
| - gesture_handler_->addElement(*password_element); |
| - password_element->setSuggestedValue(password); |
| - } else { |
| - password_element->setValue(password, true); |
| - } |
| + // We wait with filling in the password until a user gesture occurred. This is |
| + // to make sure that we do not fill in the DOM with a password until we |
| + // believe the user is intentionally interacting with the page. |
| + password_element->setSuggestedValue(password); |
| + gatekeeper_.RegisterElement(*password_element); |
| + |
| // Note: Don't call SetElementAutofilled() here, as that dispatches an |
| // onChange event in JavaScript, which is not appropriate for the password |
| // element if a user gesture has not yet occured. |
| @@ -857,23 +897,4 @@ bool PasswordAutofillAgent::FindLoginInfo(const blink::WebNode& node, |
| return true; |
| } |
| -void PasswordAutofillAgent::AutofillWebUserGestureHandler::onGesture() { |
| - agent_->set_user_gesture_occurred(true); |
| - |
| - std::vector<blink::WebInputElement>::iterator iter; |
| - for (iter = elements_.begin(); iter != elements_.end(); ++iter) { |
| - if (!iter->isNull() && !iter->suggestedValue().isNull()) |
| - iter->setValue(iter->suggestedValue(), true); |
| - } |
| - |
| - elements_.clear(); |
| -} |
| - |
| -PasswordAutofillAgent::AutofillWebUserGestureHandler:: |
| - AutofillWebUserGestureHandler(PasswordAutofillAgent* agent) |
| - : agent_(agent) {} |
| - |
| -PasswordAutofillAgent::AutofillWebUserGestureHandler:: |
| - ~AutofillWebUserGestureHandler() {} |
| - |
| } // namespace autofill |