chromium/chrome/common/extensions/api/autofill_private.idl

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Use the <code>chrome.autofillPrivate</code> API to add, remove, or update
// autofill data from the settings UI.
namespace autofillPrivate {
  // Subset of properties from the user account (signin component, AccountInfo).
  dictionary AccountInfo {
    DOMString email;
    boolean isSyncEnabledForAutofillProfiles;
    boolean isEligibleForAddressAccountStorage;

    // Controls whether the Autofill Sync toggle should be available (duplicated
    // from the Sync Settings page) on the Autofill Settings page.
    // TODO(crbug.com/40943238): Remove when toggle becomes available on the Sync
    // page for non-syncing users.
    boolean isAutofillSyncToggleAvailable;

    // Represents the UserSelectableType::kAutofill state (enabled or not).
    // TODO(crbug.com/40943238): Remove when toggle becomes available on the Sync
    // page for non-syncing users.
    boolean isAutofillSyncToggleEnabled;
  };

  // A copy of FieldType from
  // chrome/common/extensions/api/autofill_private.idl
  enum FieldType {
    NO_SERVER_DATA,
    UNKNOWN_TYPE,
    EMPTY_TYPE,
    NAME_FIRST,
    NAME_MIDDLE,
    NAME_LAST,
    NAME_MIDDLE_INITIAL,
    NAME_FULL,
    NAME_SUFFIX,
    EMAIL_ADDRESS,
    PHONE_HOME_NUMBER,
    PHONE_HOME_CITY_CODE,
    PHONE_HOME_COUNTRY_CODE,
    PHONE_HOME_CITY_AND_NUMBER,
    PHONE_HOME_WHOLE_NUMBER,
    ADDRESS_HOME_LINE1,
    ADDRESS_HOME_LINE2,
    ADDRESS_HOME_APT_NUM,
    ADDRESS_HOME_CITY,
    ADDRESS_HOME_STATE,
    ADDRESS_HOME_ZIP,
    ADDRESS_HOME_COUNTRY,
    CREDIT_CARD_NAME_FULL,
    CREDIT_CARD_NUMBER,
    CREDIT_CARD_EXP_MONTH,
    CREDIT_CARD_EXP_2_DIGIT_YEAR,
    CREDIT_CARD_EXP_4_DIGIT_YEAR,
    CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR,
    CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR,
    CREDIT_CARD_TYPE,
    CREDIT_CARD_VERIFICATION_CODE,
    COMPANY_NAME,
    FIELD_WITH_DEFAULT_VALUE,
    MERCHANT_EMAIL_SIGNUP,
    MERCHANT_PROMO_CODE,
    PASSWORD,
    ACCOUNT_CREATION_PASSWORD,
    ADDRESS_HOME_STREET_ADDRESS,
    ADDRESS_HOME_SORTING_CODE,
    ADDRESS_HOME_DEPENDENT_LOCALITY,
    ADDRESS_HOME_LINE3,
    NOT_ACCOUNT_CREATION_PASSWORD,
    USERNAME,
    USERNAME_AND_EMAIL_ADDRESS,
    NEW_PASSWORD,
    PROBABLY_NEW_PASSWORD,
    NOT_NEW_PASSWORD,
    CREDIT_CARD_NAME_FIRST,
    CREDIT_CARD_NAME_LAST,
    PHONE_HOME_EXTENSION,
    CONFIRMATION_PASSWORD,
    AMBIGUOUS_TYPE,
    SEARCH_TERM,
    PRICE,
    NOT_PASSWORD,
    SINGLE_USERNAME,
    NOT_USERNAME,
    UPI_VPA,
    ADDRESS_HOME_STREET_NAME,
    ADDRESS_HOME_HOUSE_NUMBER,
    ADDRESS_HOME_SUBPREMISE,
    ADDRESS_HOME_OTHER_SUBUNIT,
    NAME_LAST_FIRST,
    NAME_LAST_CONJUNCTION,
    NAME_LAST_SECOND,
    NAME_HONORIFIC_PREFIX,
    ADDRESS_HOME_ADDRESS,
    ADDRESS_HOME_ADDRESS_WITH_NAME,
    ADDRESS_HOME_FLOOR,
    PHONE_HOME_CITY_CODE_WITH_TRUNK_PREFIX,
    PHONE_HOME_CITY_AND_NUMBER_WITHOUT_TRUNK_PREFIX,
    PHONE_HOME_NUMBER_PREFIX,
    PHONE_HOME_NUMBER_SUFFIX,
    IBAN_VALUE,
    CREDIT_CARD_STANDALONE_VERIFICATION_CODE,
    NUMERIC_QUANTITY,
    ONE_TIME_CODE,
    DELIVERY_INSTRUCTIONS,
    ADDRESS_HOME_OVERFLOW,
    ADDRESS_HOME_LANDMARK,
    ADDRESS_HOME_OVERFLOW_AND_LANDMARK,
    ADDRESS_HOME_ADMIN_LEVEL2,
    ADDRESS_HOME_STREET_LOCATION,
    ADDRESS_HOME_BETWEEN_STREETS,
    ADDRESS_HOME_BETWEEN_STREETS_OR_LANDMARK,
    ADDRESS_HOME_STREET_LOCATION_AND_LOCALITY,
    ADDRESS_HOME_STREET_LOCATION_AND_LANDMARK,
    ADDRESS_HOME_DEPENDENT_LOCALITY_AND_LANDMARK,
    ADDRESS_HOME_BETWEEN_STREETS_1,
    ADDRESS_HOME_BETWEEN_STREETS_2,
    SINGLE_USERNAME_FORGOT_PASSWORD,
    ADDRESS_HOME_APT,
    ADDRESS_HOME_APT_TYPE,
    ADDRESS_HOME_HOUSE_NUMBER_AND_APT,
    SINGLE_USERNAME_WITH_INTERMEDIATE_VALUES,
    MAX_VALID_FIELD_TYPE
  };

  // The address record type. Describes where the address is stored.
  enum AddressRecordType {
    // The address is stored in the Chrome infrastructure (locally and
    // possibly synced between devices).
    LOCAL_OR_SYNCABLE,
    // The address is stored in a third party service that is tied
    // to user's account.
    ACCOUNT
  };

  // Metadata about an autofill entry (address or credit card) which is used to
  // render a summary list of all entries.
  dictionary AutofillMetadata {
    // Short summary of the address/credit card which is displayed in the UI; an
    // undefined value means that this entry has just been created on the client
    // and has not yet been given a summary.
    DOMString summaryLabel;

    // Short, secondary summary of the address/credit card which is displayed
    // in the UI; an undefined value means that this entry has just been created
    // on the client and has not yet been given a summary.
    DOMString? summarySublabel;

    // For addresses. Describes where the address is stored.
    AddressRecordType? recordType;

    // For credit cards, whether the entry is locally owned by Chrome (as opposed to
    // being synced down from the server). Non-local entries may not be editable.
    boolean? isLocal;

    // For credit cards, whether this is migratable (both the card number and
    // expiration date valid and does not have the duplicated server card).
    boolean? isMigratable;

    // For credit cards. Indicates whether a card is eligible for virtual cards
    // enrollment.
    boolean? isVirtualCardEnrollmentEligible;

    // For credit cards. Indicates whether a card has been enrolled in virtual
    // cards if it is eligible.
    boolean? isVirtualCardEnrolled;
  };

  // Represents single entry of the autofill profile, containing field type and
  // the corresponding field value.
  dictionary AddressField {
    FieldType type;
    DOMString value;
  };

  // An address entry which can be saved in the autofill section of the
  // settings UI.
  dictionary AddressEntry {
    // Globally unique identifier for this entry.
    DOMString? guid;

    // Fields have to be stored in the array with every field style stored only
    // once.
    AddressField[] fields;

    DOMString? languageCode;

    AutofillMetadata? metadata;
  };

  // An entry representing a country and its code.
  dictionary CountryEntry {
    // The internationalized name of the country.
    DOMString? name;

    // A two-character string representing the country.
    DOMString? countryCode;
  };

  // A component to be shown in an address editor. Different countries have
  // different components to their addresses.
  dictionary AddressComponent {
    // The field type.
    FieldType field;

    // The name of the field.
    DOMString fieldName;

    // A hint for the UI regarding whether the input is likely to be long.
    boolean isLongField;

    // Whether this component is required or not.
    boolean isRequired;

    // A placeholder for the text field to be used when the user has not yet
    // input a value for the field.
    DOMString? placeholder;
  };

  // A row of address components. Each component in a row should be shown in the
  // same row in the UI. For example, city, state, and zip code are all included
  // on the same line for US addresses.
  dictionary AddressComponentRow {
    AddressComponent[] row;
  };

  // The address components for a given country code. Each entry in |components|
  // constitutes a row in the UI, while each inner array contains the list of
  // components to use in that row. For example, city, state, and zip code are
  // all included on the same line for US addresses. This dictionary also
  // includes the associated language code.
  dictionary AddressComponents {
    // The components.
    AddressComponentRow[] components;

    // The language code.
    DOMString languageCode;
  };

  // A credit card entry which can be saved in the autofill section of the
  // settings UI.
  dictionary CreditCardEntry {
    // Globally unique identifier for this entry.
    DOMString? guid;

    // The card's instrument ID from the GPay server, if applicable.
    DOMString? instrumentId;

    // Name of the person who owns the credit card.
    DOMString? name;

    // Credit card number.
    DOMString? cardNumber;

    // Month as 2-character string ("01" = January, "12" = December).
    DOMString? expirationMonth;

    // Year as a 4-character string (as in "2015").
    DOMString? expirationYear;

    // Credit card's nickname.
    DOMString? nickname;

    // Credit card's network.
    DOMString? network;

    // Credit card's image source.
    DOMString? imageSrc;

    // Credit card's masked cvc.
    DOMString? cvc;

    // Credit card's product terms URL.
    DOMString? productTermsUrl;

    AutofillMetadata? metadata;
  };

  // An IBAN entry which can be saved in the autofill section of the
  // settings UI.
  dictionary IbanEntry {
    // Globally unique identifier for this entry.
    DOMString? guid;

    // IBAN value.
    DOMString? value;

    // IBAN's nickname.
    DOMString? nickname;

    AutofillMetadata? metadata;
  };

  callback GetAccountInfoCallback = void(optional AccountInfo accountInfo);
  callback GetCountryListCallback = void(CountryEntry[] countries);
  callback GetAddressComponentsCallback = void(AddressComponents components);
  callback GetAddressListCallback = void(AddressEntry[] entries);
  callback GetCreditCardListCallback = void(CreditCardEntry[] entries);
  callback GetIbanListCallback = void(IbanEntry[] entries);
  callback IsValidIbanCallback = void(boolean isValid);
  callback GetCreditCardCallback = void(optional CreditCardEntry card);
  callback CheckForDeviceAuthCallback = void(boolean isDeviceAuthAvailable);

  interface Functions {
    // Gets currently signed-in user profile info, no value is returned if
    // the user is not signed-in.
    // |callback|: Callback which will be called with the info.
    static void getAccountInfo(
        GetAccountInfoCallback callback);

    // Saves the given address. If |address| has an empty string as its ID, it
    // will be assigned a new one and added as a new entry.
    // |address|: The address entry to save.
    static void saveAddress(AddressEntry address);

    // Gets the list of all countries.
    // |forAccountAddressProfile|: whether the address profile opened in the
    // editor originates in the user's profile.
    // |callback|: Callback which will be called with the countries.
    static void getCountryList(
        boolean forAccountAddressProfile,
        GetCountryListCallback callback);

    // Gets the address components for a given country code.
    // |countryCode|: A two-character string representing the address' country
    //     whose components should be returned. See autofill_country.cc for a
    //     list of valid codes.
    // |callback|: Callback which will be called with components.
    static void getAddressComponents(
        DOMString countryCode,
        GetAddressComponentsCallback callback);

    // Gets the list of addresses.
    // |callback|: Callback which will be called with the list of addresses.
    static void getAddressList(
        GetAddressListCallback callback);

    // Saves the given credit card. If |card| has an empty string as its
    // ID, it will be assigned a new one and added as a new entry.
    // |card|: The card entry to save.
    static void saveCreditCard(CreditCardEntry card);

    // Saves the given IBAN. If `iban` has an empty string as its ID, it will be
    // assigned a new one and added as a new entry.
    // |iban|: The IBAN entry to save.
    static void saveIban(IbanEntry iban);

    // Removes the entry (address or credit card) with the given ID.
    // |guid|: ID of the entry to remove.
    static void removeEntry(DOMString guid);

    // Gets the list of credit cards.
    // |callback|: Callback which will be called with the list of credit cards.
    static void getCreditCardList(
        GetCreditCardListCallback callback);

    // Gets the list of IBANs.
    // `callback`: Callback which will be called with the list of IBANs.
    static void getIbanList(
        GetIbanListCallback callback);

    // Returns true if the given `ibanValue` is a valid IBAN.
    // `callback`: Callback which will be called with the result of IBAN
    // validation.
    static void isValidIban(
        DOMString ibanValue, IsValidIbanCallback callback);

    // Triggers local credit cards migration.
    static void migrateCreditCards();

    // Logs that the server cards edit link was clicked.
    static void logServerCardLinkClicked();

    // Enrolls a credit card into virtual cards.
    // |cardId|: The server side id of the credit card to be enrolled. Note it
    // refers to the legacy server id of credit cards, not the instrument ids.
    static void addVirtualCard(DOMString cardId);

    // Unenrolls a credit card from virtual cards.
    // |cardId|: The server side id of the credit card to be unenrolled. Note
    // it refers to the legacy server id of credit cards, not the instrument
    // ids.
    static void removeVirtualCard(DOMString cardId);

    // Authenticates the user via device authentication and if successful, it
    // will then flip the mandatory auth toggle.
    static void authenticateUserAndFlipMandatoryAuthToggle();

    // Returns the local card based on the `guid` provided. The user could
    // also be challenged with a reauth if that is enabled. For a successful
    // auth, the local card is returned otherwise return a null object.
    static void getLocalCard(
        DOMString guid, GetCreditCardCallback callback);

    // Returns true if there is authentication available on this device
    // (biometric or screen lock), false otherwise.
    static void checkIfDeviceAuthAvailable(
        CheckForDeviceAuthCallback callback);

    // Bulk delete all the CVCs (server and local) from the local webdata
    // database. For server CVCs, this will also clear them from the Chrome
    // sync server and thus other devices.
    static void bulkDeleteAllCvcs();

    // Sets the Sync Autofill toggle value, which corresponds to
    // `syncer::UserSelectableType::kAutofill` in `SyncUserSettings`.
    static void setAutofillSyncToggleEnabled(boolean enabled);
  };

  interface Events {
    // Fired when the personal data has changed, meaning that an entry has
    // been added, removed, or changed.
    // `addressEntries`: the updated list of addresses.
    // `creditCardEntries`: the updated list of credit cards.
    // `ibans`: the updated list of IBANs.
    // `accountInfo`: account info if the user is signed-in or no value if not.
    static void onPersonalDataChanged(AddressEntry[] addressEntries,
        CreditCardEntry[] creditCardEntries,
        IbanEntry[] ibans,
        optional AccountInfo accountInfo);
  };
};