summaryrefslogtreecommitdiffstats
path: root/webkit/glue/password_form_dom_manager.cc
blob: 5c56d63f10064fbae21a479178a8a9be5f736f63 (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
// Copyright (c) 2006-2008 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 "base/logging.h"
#include "third_party/WebKit/WebKit/chromium/public/WebPasswordFormData.h"
#include "webkit/glue/glue_util.h"
#include "webkit/glue/password_form_dom_manager.h"

using WebKit::WebFormElement;
using WebKit::WebPasswordFormData;

namespace webkit_glue {

PasswordForm* PasswordFormDomManager::CreatePasswordForm(
    const WebFormElement& webform)
{
  WebPasswordFormData web_password_form(webform);
  if (web_password_form.isValid())
    return new PasswordForm(web_password_form);
  return NULL;
}

// static
void PasswordFormDomManager::InitFillData(
    const PasswordForm& form_on_page,
    const PasswordFormMap& matches,
    const PasswordForm* const preferred_match,
    bool wait_for_username_before_autofill,
    PasswordFormDomManager::FillData* result) {
  DCHECK(preferred_match);
  // Fill basic form data.
  result->basic_data.origin = form_on_page.origin;
  result->basic_data.action = form_on_page.action;
  result->basic_data.elements.push_back(form_on_page.username_element);
  result->basic_data.values.push_back(preferred_match->username_value);
  result->basic_data.elements.push_back(form_on_page.password_element);
  result->basic_data.values.push_back(preferred_match->password_value);
  result->basic_data.submit = form_on_page.submit_element;
  result->wait_for_username = wait_for_username_before_autofill;

  // Copy additional username/value pairs.
  PasswordFormMap::const_iterator iter;
  for (iter = matches.begin(); iter != matches.end(); iter++) {
    if (iter->second != preferred_match)
      result->additional_logins[iter->first] = iter->second->password_value;
  }
}

}  // namespace webkit_glue