summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/password_autofill_manager.h
blob: a67078c9716dad7ff7bf1d6d0b7e71b3ac0ad85f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 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.

#ifndef CHROME_BROWSER_AUTOFILL_PASSWORD_AUTOFILL_MANAGER_H_
#define CHROME_BROWSER_AUTOFILL_PASSWORD_AUTOFILL_MANAGER_H_
#pragma once

// This file was contains some repeated code from
// chrome/renderer/autofill/password_autofill_manager because as we move to the
// new Autofill UI we needs these functions in both the browser and renderer.
// Once the move is completed the repeated code in the renderer half should be
// removed.
// http://crbug.com/51644

#include <map>

#include "webkit/forms/password_form_dom_manager.h"

namespace content {
class WebContents;
}  // namespace content

// This class is responsible for filling password forms.
class PasswordAutofillManager {
 public:
  explicit PasswordAutofillManager(content::WebContents* web_contents);
  virtual ~PasswordAutofillManager();

  // Fills the password associated with user name |value|. Returns true if the
  // username and password fields were filled, false otherwise.
  bool DidAcceptAutofillSuggestion(const webkit::forms::FormField& field,
                                   const string16& value);

  // Invoked when a password mapping is added.
  void AddPasswordFormMapping(
      const webkit::forms::FormField& username_element,
      const webkit::forms::PasswordFormFillData& password);

  // Invoked to clear any page specific cached values.
  void Reset();

 private:
  // TODO(csharp): Modify the AutofillExternalDeletegate code so that it can
  // figure out if a entry is a password one without using this mapping.
  // crbug.com/118601
  typedef std::map<webkit::forms::FormField,
                   webkit::forms::PasswordFormFillData>
      LoginToPasswordInfoMap;

  // Returns true if |current_username| matches a username for one of the
  // login mappings in |password|.
  bool WillFillUserNameAndPassword(
      const string16& current_username,
      const webkit::forms::PasswordFormFillData& password);

  // Finds login information for a |node| that was previously filled.
  bool FindLoginInfo(const webkit::forms::FormField& field,
                     webkit::forms::PasswordFormFillData* found_password);

  // The logins we have filled so far with their associated info.
  LoginToPasswordInfoMap login_to_password_info_;

  // We only need the RenderViewHost pointer in WebContents, but if we attempt
  // to just store RenderViewHost on creation, it becomes invalid once we start
  // using it. By having the WebContents we can always get a valid pointer.
  content::WebContents* web_contents_;  // Weak reference.

  DISALLOW_COPY_AND_ASSIGN(PasswordAutofillManager);
};

#endif  // CHROME_BROWSER_AUTOFILL_PASSWORD_AUTOFILL_MANAGER_H_