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

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..883b2390d8fede99c1a641774115923956cad5f9
--- /dev/null
+++ b/chrome/browser/autofill/password_autofill_manager.cc
@@ -0,0 +1,139 @@
+// 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/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/common/autofill_messages.h"
+#include "content/browser/renderer_host/render_view_host.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/renderer/render_view.h"
+#include "ui/base/keycodes/keyboard_codes.h"
+
+////////////////////////////////////////////////////////////////////////////////
+// PasswordAutofillManager, public:
+
+PasswordAutofillManager::PasswordAutofillManager(
+ TabContentsWrapper* tab_contents_wrapper)
+ : tab_contents_wrapper_(tab_contents_wrapper) {
+}
+
+PasswordAutofillManager::~PasswordAutofillManager() {
+}
+
+bool PasswordAutofillManager::TextFieldHandlingKeyDown(
+ const webkit::forms::FormField& field,
+ int key_code) {
+ LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field);
+ if (iter == login_to_password_info_.end())
+ return false;
+
+ if (tab_contents_wrapper_ && tab_contents_wrapper_->web_contents() &&
+ tab_contents_wrapper_->web_contents()->GetRenderViewHost()) {
Ilya Sherman 2012/03/06 20:32:44 Hmm, can any of these actually ever be NULL?
csharp 2012/03/07 15:49:16 I don't think so, but I since I only use this to s
Ilya Sherman 2012/03/07 22:33:18 If the RenderViewHost remains constant for a TabCo
csharp 2012/03/08 16:48:37 Done.
+ RenderViewHost* host =
+ tab_contents_wrapper_->web_contents()->GetRenderViewHost();
+ host->Send(new AutofillMsg_PasswordHandleKeyDown(host->GetRoutingID(),
+ key_code));
+ }
+
+ iter->second.backspace_pressed_last =
+ (key_code == ui::VKEY_BACK || key_code == ui::VKEY_DELETE);
Ilya Sherman 2012/03/06 20:32:44 It looks like you're also doing this work on the r
csharp 2012/03/07 15:49:16 I had thought I still had code here that looked at
+
+ 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 (tab_contents_wrapper_ && tab_contents_wrapper_->web_contents() &&
+ tab_contents_wrapper_->web_contents()->GetRenderViewHost()) {
+ RenderViewHost* host =
+ tab_contents_wrapper_->web_contents()->GetRenderViewHost();
+ host->Send(new AutofillMsg_PasswordAcceptAutofillSuggestion(
+ host->GetRoutingID(),
+ value));
Ilya Sherman 2012/03/06 20:32:44 Why not send the full fill data here, rather than
csharp 2012/03/07 15:49:16 We kinda get the full fill data for free in the re
Ilya Sherman 2012/03/07 22:33:18 Hmm, it seems a little wrong to have both the brow
csharp 2012/03/08 16:48:37 Ok, so I think we can removed the duplicated data.
Ilya Sherman 2012/03/08 23:22:14 Ok, I think I better understand now why it's hard
+ }
+ 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::FillPasswordForm(
+ const webkit::forms::FormField& username_element,
+ const webkit::forms::PasswordFormFillData& fill_data,
+ int frame_id) {
+ PasswordInfo password_info;
+ password_info.frame_id = frame_id;
+ password_info.fill_data = fill_data;
+
+ login_to_password_info_[username_element] = password_info;
+}
+
+void PasswordAutofillManager::FrameClosing(long long frame_id) {
+ for (LoginToPasswordInfoMap::iterator iter = login_to_password_info_.begin();
+ iter != login_to_password_info_.end();) {
+ if (iter->second.frame_id == frame_id)
+ login_to_password_info_.erase(iter++);
+ else
+ ++iter;
+ }
Ilya Sherman 2012/03/06 20:32:44 Does anything go wrong if we just empty the map wh
csharp 2012/03/07 15:49:16 From my understanding of this code, I don't think
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// 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;
+ }
Ilya Sherman 2012/03/06 20:32:44 nit: The if-stmt body is 1 line, so no need for cu
csharp 2012/03/07 15:49:16 Done.
+ }
+ }
+
+ 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