form_group.h revision 3240926e260ce088908e02ac07a6cf7b0c0cbf44
18cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd// Copyright 2013 The Chromium Authors. All rights reserved. 28cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd// Use of this source code is governed by a BSD-style license that can be 38cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd// found in the LICENSE file. 48cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 58cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_GROUP_H_ 68cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd#define COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_GROUP_H_ 78cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 88cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd#include <string> 98cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 108cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd#include "base/strings/string16.h" 118cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd#include "components/autofill/core/browser/field_types.h" 128cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 138cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Doddnamespace autofill { 148cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 158cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Doddclass AutofillType; 168cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 178cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd// This class is an interface for collections of form fields, grouped by type. 188cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Doddclass FormGroup { 198cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd public: 208cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd virtual ~FormGroup() {} 218cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 228cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // Used to determine the type of a field based on the text that a user enters 238cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // into the field, interpreted in the given |app_locale| if appropriate. The 248cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // field types can then be reported back to the server. This method is 258cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // additive on |matching_types|. 268cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd virtual void GetMatchingTypes(const base::string16& text, 278cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd const std::string& app_locale, 288cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd ServerFieldTypeSet* matching_types) const; 298cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 308cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // Returns a set of server field types for which this FormGroup has non-empty 318cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // data. This method is additive on |non_empty_types|. 328cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd virtual void GetNonEmptyTypes(const std::string& app_locale, 338cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd ServerFieldTypeSet* non_empty_types) const; 348cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 358cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // Returns the string associated with |type|, without canonicalizing the 368cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // returned value. For user-visible strings, use GetInfo() instead. 378cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd virtual base::string16 GetRawInfo(ServerFieldType type) const = 0; 388cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 398cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // Sets this FormGroup object's data for |type| to |value|, without 408cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // canonicalizing the |value|. For data that has not already been 418cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // canonicalized, use SetInfo() instead. 428cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd virtual void SetRawInfo(ServerFieldType type, 438cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd const base::string16& value) = 0; 448cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 458cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // Returns the string that should be auto-filled into a text field given the 468cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // type of that field, localized to the given |app_locale| if appropriate. 478cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd virtual base::string16 GetInfo(const AutofillType& type, 488cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd const std::string& app_locale) const; 498cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 508cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // Used to populate this FormGroup object with data. Canonicalizes the data 518cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // according to the specified |app_locale| prior to storing, if appropriate. 528cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd virtual bool SetInfo(const AutofillType& type, 538cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd const base::string16& value, 548cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd const std::string& app_locale); 558cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 568cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd protected: 578cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // AutofillProfile needs to call into GetSupportedTypes() for objects of 588cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // non-AutofillProfile type, for which mere inheritance is insufficient. 598cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd friend class AutofillProfile; 608cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 618cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // Returns a set of server field types for which this FormGroup can store 628cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd // data. This method is additive on |supported_types|. 638cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd virtual void GetSupportedTypes(ServerFieldTypeSet* supported_types) const = 0; 648cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd}; 658cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 668cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd} // namespace autofill 678cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd 688cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_GROUP_H_ 698cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd