1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/strings/string_util.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/password_manager/password_form_data.h"
9 using autofill::PasswordForm
;
11 PasswordForm
* CreatePasswordFormFromData(
12 const PasswordFormData
& form_data
) {
13 PasswordForm
* form
= new PasswordForm();
14 form
->scheme
= form_data
.scheme
;
15 form
->preferred
= form_data
.preferred
;
16 form
->ssl_valid
= form_data
.ssl_valid
;
17 form
->date_created
= base::Time::FromDoubleT(form_data
.creation_time
);
18 if (form_data
.signon_realm
)
19 form
->signon_realm
= std::string(form_data
.signon_realm
);
21 form
->origin
= GURL(form_data
.origin
);
23 form
->action
= GURL(form_data
.action
);
24 if (form_data
.submit_element
)
25 form
->submit_element
= base::WideToUTF16(form_data
.submit_element
);
26 if (form_data
.username_element
)
27 form
->username_element
= base::WideToUTF16(form_data
.username_element
);
28 if (form_data
.password_element
)
29 form
->password_element
= base::WideToUTF16(form_data
.password_element
);
30 if (form_data
.username_value
) {
31 form
->username_value
= base::WideToUTF16(form_data
.username_value
);
32 if (form_data
.password_value
)
33 form
->password_value
= base::WideToUTF16(form_data
.password_value
);
35 form
->blacklisted_by_user
= true;
40 typedef std::set
<const autofill::PasswordForm
*> SetOfForms
;
42 bool ContainsSamePasswordFormsPtr(
43 const std::vector
<PasswordForm
*>& first
,
44 const std::vector
<PasswordForm
*>& second
) {
45 if (first
.size() != second
.size())
48 // TODO(cramya): As per b/7079906, the STLport of Android causes a crash
49 // if we use expectations(first.begin(), first.end()) to copy a vector
50 // into a set rather than std::copy that is used below.
51 // Need to revert this once STLport is fixed.
52 SetOfForms expectations
;
53 std::copy(first
.begin(), first
.end(), std::inserter(expectations
,
54 expectations
.begin()));
55 for (unsigned int i
= 0; i
< second
.size(); ++i
) {
56 const PasswordForm
* actual
= second
[i
];
57 bool found_match
= false;
58 for (SetOfForms::iterator it
= expectations
.begin();
59 it
!= expectations
.end(); ++it
) {
60 const PasswordForm
* expected
= *it
;
61 if (*expected
== *actual
) {
63 expectations
.erase(it
);
68 LOG(ERROR
) << "No match for:" << std::endl
<< *actual
;
75 bool ContainsSamePasswordForms(
76 std::vector
<autofill::PasswordForm
>& first
,
77 std::vector
<autofill::PasswordForm
>& second
) {
78 std::vector
<PasswordForm
*> first_ptr
;
79 for (unsigned int i
= 0; i
< first
.size(); ++i
) {
80 first_ptr
.push_back(&first
[i
]);
82 std::vector
<PasswordForm
*> second_ptr
;
83 for (unsigned int i
= 0; i
< second
.size(); ++i
) {
84 second_ptr
.push_back(&second
[i
]);
86 return ContainsSamePasswordFormsPtr(first_ptr
, second_ptr
);