17d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifndef COMPONENTS_AUTOFILL_CORE_COMMON_FORM_DATA_H_
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define COMPONENTS_AUTOFILL_CORE_COMMON_FORM_DATA_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h"
117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "components/autofill/core/common/form_field_data.h"
127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace autofill {
15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Holds information about a form to be filled and/or submitted.
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct FormData {
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  FormData();
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  FormData(const FormData& data);
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ~FormData();
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Used in testing, and in recording metrics and setting preferences, where
231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // false positives/negatives aren't super important.
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool operator==(const FormData& form) const;
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool operator!=(const FormData& form) const;
26cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
27cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Allow FormData to be a key in STL containers.
28cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  bool operator<(const FormData& form) const;
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The name of the form.
31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  base::string16 name;
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The URL (minus query parameters) containing the form.
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL origin;
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The action target of the form.
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL action;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // true if this form was submitted by a user gesture and not javascript.
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool user_submitted;
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A vector of all the input fields in the form.
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<FormFieldData> fields;
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
42d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// For testing.
43d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)std::ostream& operator<<(std::ostream& os, const FormData& form);
44d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
45424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Serialize FormData. Used by the PasswordManager to persist FormData
46424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// pertaining to password forms. Serialized data is appended to |pickle|
47424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void SerializeFormData(const FormData& form_data, Pickle* pickle);
48424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Deserialize FormData. This assumes that |iter| is currently pointing to
49424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// the part of a pickle created by SerializeFormData. Returns true on success.
50424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)bool DeserializeFormData(PickleIterator* iter, FormData* form_data);
51424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
52c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}  // namespace autofill
53c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif  // COMPONENTS_AUTOFILL_CORE_COMMON_FORM_DATA_H_
55