Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / autofill / content / renderer / password_form_conversion_utils.h
blob0c091f33d2c9989c2313578c2fbcdb6da884de85
1 // Copyright 2013 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 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_FORM_CONVERSION_UTILS_H_
6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_FORM_CONVERSION_UTILS_H_
8 #include <map>
10 #include "base/memory/scoped_ptr.h"
11 #include "components/autofill/core/common/password_form_field_prediction_map.h"
12 #include "third_party/WebKit/public/platform/WebString.h"
13 #include "third_party/WebKit/public/platform/WebVector.h"
14 #include "url/gurl.h"
16 namespace blink {
17 class WebDocument;
18 class WebFormElement;
19 class WebFormControlElement;
20 class WebFrame;
21 class WebInputElement;
24 namespace autofill {
26 struct FormData;
27 struct FormFieldData;
28 struct PasswordForm;
30 // Helper functions to assist in getting the canonical form of the action and
31 // origin. The action will proplerly take into account <BASE>, and both will
32 // strip unnecessary data (e.g. query params and HTTP credentials).
33 GURL GetCanonicalActionForForm(const blink::WebFormElement& form);
34 GURL GetCanonicalOriginForDocument(const blink::WebDocument& document);
36 // Tests whether the given form is a GAIA reauthentication form. The form is
37 // not passed directly as WebFormElement, but by specifying its |url| and
38 // |control_elements|. This is for better performance and easier testing.
39 // TODO(msramek): Move this logic to the browser.
40 bool IsGaiaReauthenticationForm(
41 const GURL& origin,
42 const blink::WebVector<blink::WebFormControlElement>& control_elements);
44 typedef std::map<const blink::WebInputElement,
45 blink::WebString> ModifiedValues;
47 // Create a PasswordForm from DOM form. Webkit doesn't allow storing
48 // custom metadata to DOM nodes, so we have to do this every time an event
49 // happens with a given form and compare against previously Create'd forms
50 // to identify..which sucks.
51 // If an element of |form| has an entry in |nonscript_modified_values|, the
52 // associated string is used instead of the element's value to create
53 // the PasswordForm.
54 // |form_predictions| is Autofill server response, if present it's used for
55 // overwriting default username element selection.
56 scoped_ptr<PasswordForm> CreatePasswordFormFromWebForm(
57 const blink::WebFormElement& form,
58 const ModifiedValues* nonscript_modified_values,
59 const FormsPredictionsMap* form_predictions);
61 // Same as CreatePasswordFormFromWebForm() but for input elements that are not
62 // enclosed in <form> element.
63 scoped_ptr<PasswordForm> CreatePasswordFormFromUnownedInputElements(
64 const blink::WebFrame& frame,
65 const ModifiedValues* nonscript_modified_values,
66 const FormsPredictionsMap* form_predictions);
68 } // namespace autofill
70 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_FORM_CONVERSION_UTILS_H__