// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Sync protocol datatype extension for the send tab to self items.

// If you change or add any fields in this file, update proto_visitors.h and
// potentially proto_enum_conversions.{h, cc}.

syntax = "proto2";

package sync_pb;

import "components/sync/protocol/encryption.proto";
import "components/sync/protocol/tab_navigation.proto";

option java_multiple_files = true;
option java_package = "org.chromium.components.sync.protocol";
option optimize_for = LITE_RUNTIME;

// Send Tab To Self list entry. This proto contains the fields synced to send
// a url across devices.
message SendTabToSelfSpecifics {
  // A random unique identifier for each shared tab.
  // Required.
  optional string guid = 5;
  // The name of the tab being shared.
  optional string title = 1;
  // The URL of the tab being shared.
  // Required.
  optional string url = 2;
  // The time the tab was shared as measured by the client in microseconds since
  // the windows epoch.
  optional int64 shared_time_usec = 3;
  // A non-unique but human readable name to describe this client, used in UI.
  optional string device_name = 4;
  // The stable Device_id of the device that this tab was shared with.
  // Required.
  optional string target_device_sync_cache_guid = 7;
  // A boolean to designate if the shared tab been opened on the target device.
  optional bool opened = 8;
  // Whether the notification for this proto been dismissed.
  optional bool notification_dismissed = 9;

  reserved "navigation_time_usec";
  reserved 6;

  // Additional information about the sent tab, e.g. scroll position and form
  // field data. Unless custom passphrase encryption is enabled, this is used
  // only locally while on the wire, `encrypted_page_context` is used instead.
  // New in M147.
  optional PageContext page_context = 10;

  // Encrypted version of the `page_context` field. Used only when custom
  // passphrase encryption is NOT enabled.
  // New in M149.
  optional EncryptedData encrypted_page_context = 15;

  // Navigation history for the shared tab. If not empty, the `url` and `title`
  // fields above should match the navigation at `current_navigation_index`.
  // These top-level fields are kept for backward compatibility and are
  // currently duplicated.
  // TODO(crbug.com/495336862): Deduplicate these fields once older clients are
  // no longer supported.
  repeated TabNavigation navigation = 11;

  // Index of the current navigation in `navigation`.
  optional int32 current_navigation_index = 12;

  // Time (in microseconds since the Windows epoch) when the entry was first
  // received by the target device's bridge. Set by the receiving device and
  // synced back to the sender.
  // New in M148.
  optional int64 received_time_windows_epoch_micros = 13;

  // Time (in microseconds since the Windows epoch) when the entry was opened
  // on the target device. Set by the receiving device and synced back to the
  // sender.
  // New in M148.
  optional int64 opened_time_windows_epoch_micros = 14;

  // Time (in microseconds since the Windows epoch) when the entry was activated
  // on the target device. Set by the receiving device and synced to the server.
  // New in M151.
  optional int64 activated_time_windows_epoch_micros = 16;
}

message PageContext {
  optional FormFieldInfo form_field_info = 1;

  // Information about the scroll position on the page.
  optional ScrollPosition scroll_position = 2;
}

message FormFieldInfo {
  repeated FormField fields = 1;
}

message FormField {
  enum AutofillFieldType {
    NO_SERVER_DATA = 0;
    UNKNOWN_TYPE = 1;
    EMPTY_TYPE = 2;
    NAME_FIRST = 3;
    NAME_MIDDLE = 4;
    NAME_LAST = 5;
    NAME_MIDDLE_INITIAL = 6;
    NAME_FULL = 7;
    NAME_SUFFIX = 8;
    EMAIL_ADDRESS = 9;
    PHONE_HOME_NUMBER = 10;
    PHONE_HOME_CITY_CODE = 11;
    PHONE_HOME_COUNTRY_CODE = 12;
    PHONE_HOME_CITY_AND_NUMBER = 13;
    PHONE_HOME_WHOLE_NUMBER = 14;
    ADDRESS_HOME_LINE1 = 15;
    ADDRESS_HOME_LINE2 = 16;
    ADDRESS_HOME_APT_NUM = 17;
    ADDRESS_HOME_CITY = 18;
    ADDRESS_HOME_STATE = 19;
    ADDRESS_HOME_ZIP = 20;
    ADDRESS_HOME_COUNTRY = 21;
    CREDIT_CARD_NAME_FULL = 22;
    CREDIT_CARD_NUMBER = 23;
    CREDIT_CARD_EXP_MONTH = 24;
    CREDIT_CARD_EXP_2_DIGIT_YEAR = 25;
    CREDIT_CARD_EXP_4_DIGIT_YEAR = 26;
    CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR = 27;
    CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR = 28;
    CREDIT_CARD_TYPE = 29;
    CREDIT_CARD_VERIFICATION_CODE = 30;
    COMPANY_NAME = 31;
    MERCHANT_EMAIL_SIGNUP = 32;
    MERCHANT_PROMO_CODE = 33;
    PASSWORD = 34;
    ACCOUNT_CREATION_PASSWORD = 35;
    ADDRESS_HOME_STREET_ADDRESS = 36;
    ADDRESS_HOME_SORTING_CODE = 37;
    ADDRESS_HOME_DEPENDENT_LOCALITY = 38;
    ADDRESS_HOME_LINE3 = 39;
    NOT_ACCOUNT_CREATION_PASSWORD = 40;
    USERNAME = 41;
    USERNAME_AND_EMAIL_ADDRESS = 42;
    NEW_PASSWORD = 43;
    PROBABLY_NEW_PASSWORD = 44;
    NOT_NEW_PASSWORD = 45;
    CREDIT_CARD_NAME_FIRST = 46;
    CREDIT_CARD_NAME_LAST = 47;
    PHONE_HOME_EXTENSION = 48;
    CONFIRMATION_PASSWORD = 49;
    AMBIGUOUS_TYPE = 50;
    SEARCH_TERM = 51;
    PRICE = 52;
    NOT_PASSWORD = 53;
    SINGLE_USERNAME = 54;
    NOT_USERNAME = 55;
    ADDRESS_HOME_STREET_NAME = 56;
    ADDRESS_HOME_HOUSE_NUMBER = 57;
    ADDRESS_HOME_SUBPREMISE = 58;
    ADDRESS_HOME_OTHER_SUBUNIT = 59;
    NAME_LAST_FIRST = 60;
    NAME_LAST_CONJUNCTION = 61;
    NAME_LAST_SECOND = 62;
    NAME_HONORIFIC_PREFIX = 63;
    ADDRESS_HOME_ADDRESS = 64;
    ADDRESS_HOME_ADDRESS_WITH_NAME = 65;
    ADDRESS_HOME_FLOOR = 66;
    PHONE_HOME_CITY_CODE_WITH_TRUNK_PREFIX = 67;
    PHONE_HOME_CITY_AND_NUMBER_WITHOUT_TRUNK_PREFIX = 68;
    PHONE_HOME_NUMBER_PREFIX = 69;
    PHONE_HOME_NUMBER_SUFFIX = 70;
    IBAN_VALUE = 71;
    CREDIT_CARD_STANDALONE_VERIFICATION_CODE = 72;
    NUMERIC_QUANTITY = 73;
    ONE_TIME_CODE = 74;
    DELIVERY_INSTRUCTIONS = 75;
    ADDRESS_HOME_OVERFLOW = 76;
    ADDRESS_HOME_LANDMARK = 77;
    ADDRESS_HOME_OVERFLOW_AND_LANDMARK = 78;
    ADDRESS_HOME_ADMIN_LEVEL2 = 79;
    ADDRESS_HOME_STREET_LOCATION = 80;
    ADDRESS_HOME_BETWEEN_STREETS = 81;
    ADDRESS_HOME_BETWEEN_STREETS_OR_LANDMARK = 82;
    ADDRESS_HOME_STREET_LOCATION_AND_LOCALITY = 83;
    ADDRESS_HOME_STREET_LOCATION_AND_LANDMARK = 84;
    ADDRESS_HOME_DEPENDENT_LOCALITY_AND_LANDMARK = 85;
    ADDRESS_HOME_BETWEEN_STREETS_1 = 86;
    ADDRESS_HOME_BETWEEN_STREETS_2 = 87;
    ADDRESS_HOME_HOUSE_NUMBER_AND_APT = 88;
    SINGLE_USERNAME_FORGOT_PASSWORD = 89;
    ADDRESS_HOME_APT = 90;
    ADDRESS_HOME_APT_TYPE = 91;
    LOYALTY_MEMBERSHIP_ID = 92;
    SINGLE_USERNAME_WITH_INTERMEDIATE_VALUES = 93;
    ALTERNATIVE_FULL_NAME = 94;
    ALTERNATIVE_GIVEN_NAME = 95;
    ALTERNATIVE_FAMILY_NAME = 96;
    DEPRECATED_NAME_LAST_PREFIX = 97;
    DEPRECATED_NAME_LAST_CORE = 98;
    PASSPORT_NUMBER = 99;
    PASSPORT_ISSUING_COUNTRY = 100;
    PASSPORT_EXPIRATION_DATE = 101;
    PASSPORT_ISSUE_DATE = 102;
    LOYALTY_MEMBERSHIP_PROGRAM = 103;
    LOYALTY_MEMBERSHIP_PROVIDER = 104;
    VEHICLE_LICENSE_PLATE = 105;
    VEHICLE_VIN = 106;
    VEHICLE_MAKE = 107;
    VEHICLE_MODEL = 108;
    DRIVERS_LICENSE_REGION = 109;
    DRIVERS_LICENSE_NUMBER = 110;
    DRIVERS_LICENSE_EXPIRATION_DATE = 111;
    DRIVERS_LICENSE_ISSUE_DATE = 112;
    VEHICLE_YEAR = 113;
    VEHICLE_PLATE_STATE = 114;
    EMAIL_OR_LOYALTY_MEMBERSHIP_ID = 115;
    NATIONAL_ID_CARD_NUMBER = 116;
    NATIONAL_ID_CARD_EXPIRATION_DATE = 117;
    NATIONAL_ID_CARD_ISSUE_DATE = 118;
    NATIONAL_ID_CARD_ISSUING_COUNTRY = 119;
    KNOWN_TRAVELER_NUMBER = 120;
    KNOWN_TRAVELER_NUMBER_EXPIRATION_DATE = 121;
    REDRESS_NUMBER = 122;
    ADDRESS_HOME_ZIP_PREFIX = 123;
    ADDRESS_HOME_ZIP_SUFFIX = 124;
    FLIGHT_RESERVATION_FLIGHT_NUMBER = 125;
    FLIGHT_RESERVATION_CONFIRMATION_CODE = 126;
    FLIGHT_RESERVATION_TICKET_NUMBER = 127;
    FLIGHT_RESERVATION_DEPARTURE_DATE = 128;
    ADDRESS_HOME_ZIP_AND_CITY = 129;
    ORDER_ID = 130;
    ORDER_DATE = 131;
    ORDER_MERCHANT_NAME = 132;
    SHIPMENT_TRACKING_NUMBER = 133;
    FLIGHT_RESERVATION_DEPARTURE_AIRPORT = 134;
    FLIGHT_RESERVATION_ARRIVAL_AIRPORT = 135;
  }

  optional string id_attribute = 1;
  optional string name_attribute = 2;
  reserved 3;
  optional string form_control_type = 4;
  optional string value = 5;
  // FormSignature is computed as the big-endian representation of the first 8
  // bytes of the SHA-1 digest of the concatenated string:
  // scheme://host&form_name&field_name_1&field_name_2...
  // Sequences of 5+ consecutive digits are stripped from names to support
  // dynamic IDs. Forms without action URLs fallback to the source page URL.
  optional uint64 form_signature = 6;
  // FieldSignature is computed as the big-endian representation of the first 4
  // bytes of the SHA-1 digest of the concatenated string:
  // field_name&field_control_type
  optional uint32 field_signature = 7;
  repeated AutofillFieldType autofill_types = 8;
}

message ScrollPosition {
  // Text fragment data used for scroll position restoration on the target
  // device.
  optional TextFragmentData text_fragment = 1;
}

// Text fragment data used for scroll position restoration.
// https://wicg.github.io/scroll-to-text-fragment/
message TextFragmentData {
  // The exact text to match.
  // Corresponds to the 'textStart' parameter in the Text Fragment
  // specification.
  optional string text_start = 1;

  // Optional: The end text for a range selection.
  // Corresponds to 'textEnd'.
  optional string text_end = 2;

  // Optional: Prefix to ensure uniqueness of the match.
  // Corresponds to 'prefix'.
  optional string prefix = 3;

  // Optional: Suffix to ensure uniqueness of the match.
  // Corresponds to 'suffix'.
  optional string suffix = 4;
}
