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

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: Remove frame id 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..c4aed9e9ad0a82a8b0564446741aceb110d88989
--- /dev/null
+++ b/chrome/browser/autofill/password_autofill_manager.cc
@@ -0,0 +1,118 @@
+// 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;
+}
+
+bool PasswordAutofillManager::DidAcceptAutofillSuggestion(
+ const webkit::forms::FormField& field,
+ const string16& value) {
+ webkit::forms::FormField input;
+ PasswordInfo password;
+ if (!FindLoginInfo(field, &input, &password))
+ return false;
+
+ if (WillFillUserNameAndPassword(input, password.fill_data)) {
+ 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;
+ PasswordInfo password;
+ return FindLoginInfo(field, &input, &password);
+}
+
+bool PasswordAutofillManager::DidClearAutofillSelection(
+ const webkit::forms::FormField& field) {
+ webkit::forms::FormField input;
+ PasswordInfo password;
+ return FindLoginInfo(field, &input, &password);
+}
+
+void PasswordAutofillManager::PasswordFormMapping(
+ const webkit::forms::FormField& username_element,
+ const webkit::forms::PasswordFormFillData& fill_data) {
+ PasswordInfo password_info;
+ password_info.fill_data = fill_data;
+
+ login_to_password_info_[username_element] = password_info;
+}
+
+void PasswordAutofillManager::FrameClosing() {
+ // When this function lived in the renderer only login info that was added
+ // with the same frame_id as this closing frame was removed instead of all
+ // the elements.
+ // If weird behaviour occurs with login info disappearing from a page, this
+ // could be the cause.
+
+ login_to_password_info_.clear();
+}
Ilya Sherman 2012/03/09 22:00:26 I don't think this is safe, because the frame that
csharp 2012/03/12 15:11:56 Ah, that makes much more sense, sorry for misreadi
+
+////////////////////////////////////////////////////////////////////////////////
+// PasswordAutofillManager, private:
+
+bool PasswordAutofillManager::WillFillUserNameAndPassword(
+ const webkit::forms::FormField& username_element,
+ const webkit::forms::PasswordFormFillData& fill_data) {
+ string16 current_username = username_element.value;
+
+ // Look for any suitable matches to current field text.
+ if (fill_data.basic_data.fields[0].value == current_username) {
+ 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,
+ PasswordInfo* 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