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

Unified Diff: chrome/browser/autofill/password_autofill_manager.cc

Issue 9600038: Add Password Autofill Manager to New Autofill (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 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: chrome/browser/autofill/password_autofill_manager.cc
diff --git a/chrome/browser/autofill/password_autofill_manager.cc b/chrome/browser/autofill/password_autofill_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..471d10bf9adbb10212eeec4babbec64e7b99f942
--- /dev/null
+++ b/chrome/browser/autofill/password_autofill_manager.cc
@@ -0,0 +1,109 @@
+// Copyright (c) 2012 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 "chrome/browser/autofill/password_autofill_manager.h"
+#include "chrome/common/autofill_messages.h"
+#include "content/public/browser/render_view_host.h"
+#include "ui/base/keycodes/keyboard_codes.h"
+
+////////////////////////////////////////////////////////////////////////////////
+// PasswordAutofillManager, public:
+
+PasswordAutofillManager::PasswordAutofillManager(
+ content::RenderViewHost* render_view_host)
+ : render_view_host_(render_view_host) {
+}
+
+PasswordAutofillManager::~PasswordAutofillManager() {
+}
+
+bool PasswordAutofillManager::WouldHandleKeyDown(
+ const webkit::forms::FormField& field) {
+ LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field);
+ if (iter == login_to_password_info_.end())
+ return false;
+
+ return true;
Ilya Sherman 2012/03/15 18:27:41 nit: You can combine lines 24-27 as """return iter
csharp 2012/03/16 20:21:12 Done.
+}
+
+bool PasswordAutofillManager::DidAcceptAutofillSuggestion(
+ const webkit::forms::FormField& field,
+ const string16& value) {
+ webkit::forms::FormField input;
+ webkit::forms::PasswordFormFillData password;
+ if (!FindLoginInfo(field, &input, &password))
+ return false;
+
+ if (WillFillUserNameAndPassword(input, password)) {
+ if (render_view_host_) {
+ render_view_host_->Send(new AutofillMsg_PasswordAcceptAutofillSuggestion(
+ render_view_host_->GetRoutingID(),
+ value));
+ }
+ return true;
+ }
+
+ return false;
+}
+
+bool PasswordAutofillManager::DidSelectAutofillSuggestion(
+ const webkit::forms::FormField& field) {
+ webkit::forms::FormField input;
+ webkit::forms::PasswordFormFillData password;
+ return FindLoginInfo(field, &input, &password);
+}
+
+bool PasswordAutofillManager::DidClearAutofillSelection(
+ const webkit::forms::FormField& field) {
+ webkit::forms::FormField input;
+ webkit::forms::PasswordFormFillData password;
+ return FindLoginInfo(field, &input, &password);
+}
+
+void PasswordAutofillManager::AddPasswordFormMapping(
+ const webkit::forms::FormField& username_element,
+ const webkit::forms::PasswordFormFillData& password) {
+ login_to_password_info_[username_element] = password;
+}
+
+void PasswordAutofillManager::Reset() {
+ login_to_password_info_.clear();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// PasswordAutofillManager, private:
+
+bool PasswordAutofillManager::WillFillUserNameAndPassword(
+ const webkit::forms::FormField& username_element,
+ const webkit::forms::PasswordFormFillData& fill_data) {
+ string16 current_username = username_element.value;
Ilya Sherman 2012/03/15 18:27:41 Hmm, is this always going to be the empty string,
csharp 2012/03/16 20:21:12 It is. I failed to copy over an assignment stateme
+
+ // Look for any suitable matches to current field text.
+ if (fill_data.basic_data.fields[0].value == current_username) {
Ilya Sherman 2012/03/15 18:27:41 Why is this a full string equality check, rather t
csharp 2012/03/16 20:21:12 If you've selected isherman then current_username
Ilya Sherman 2012/03/20 00:58:55 What happens if I type "ish" and click on the sugg
Ilya Sherman 2012/03/22 01:20:06 Bump.
csharp 2012/03/29 16:28:17 current_username will be equal to what you selecte
+ return true;
+ } else {
+ // Scan additional logins for a match.
+ webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter;
+ for (iter = fill_data.additional_logins.begin();
+ iter != fill_data.additional_logins.end(); ++iter) {
+ if (iter->first == current_username)
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool PasswordAutofillManager::FindLoginInfo(
+ const webkit::forms::FormField& field,
+ webkit::forms::FormField* found_input,
+ webkit::forms::PasswordFormFillData* found_password) {
+ LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field);
+ if (iter == login_to_password_info_.end())
+ return false;
+
+ *found_input = field;
+ *found_password = iter->second;
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698