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

edition = "2023";

package optimization_guide.proto;

option optimize_for = LITE_RUNTIME;
option java_package = "org.chromium.components.optimization_guide.features.proto";

option java_outer_classname = "ActorLoginProto";

// DO NOT EDIT THIS FILE DIRECTLY!
//
// This file is generated in g3 and then synced to Chrome. Instead, please refer to
// http://go/chrome-mqls-onboarding (Google-internal link), and then changes will
// be synced with Chrome automatically.

message ActorLoginLoggingData {
  ActorLoginQuality quality = 1 [features = { field_presence: EXPLICIT }];
}

message ActorLoginQuality {
  // Domain of the page.
  string domain = 1 [features = { field_presence: EXPLICIT }];

  // Location of user. Country of the user as "US"
  string location = 2 [features = { field_presence: EXPLICIT }];

  // Language of the page.
  string language = 3 [features = { field_presence: EXPLICIT }];

  GetCredentialsDetails get_credentials_details = 4 [features = { field_presence: EXPLICIT }];

  repeated AttemptLoginDetails attempt_login_details = 5;

  PermissionOption permission_picked = 6 [features = { field_presence: EXPLICIT }];

  // True if a successful login was detected for a submitted form.
  bool successful_login_detected = 7 [features = { field_presence: EXPLICIT }];

  // The time from the first attempt login call to the successful login
  // detection. Only set if successful_login_detected is true.
  int64 time_until_successful_login_ms = 8 [features = { field_presence: EXPLICIT }];

  // The type of flow that the actor login operation belongs to.
  // This is currently used to distinguish between regular actor login flows and
  // actor login flows part of an automated password change task.
  FlowType flow_type = 9 [features = { field_presence: EXPLICIT }];

  message FormData {
    // The signature of the form. This is the hash identifier used to denote
    // this field for query and voting purposes. See
    // components/autofill/core/common/signatures.cc for more details.
    int64 form_signature = 1 [features = { field_presence: EXPLICIT }];

    // Information about the fields in the form.
    repeated FieldData field_data = 2;

    // The type of frame that the form is on.
    FrameType frame_type = 3 [features = { field_presence: EXPLICIT }];

    message FieldData {
      // The signature of the field. This is the hash identifier used to denote
      // this field for query and voting purposes. See
      // components/autofill/core/common/signatures.cc for more details.
      int64 signature = 1 [features = { field_presence: EXPLICIT }];

      // Deprecated: This is not logged anymore.
      string id = 2 [
        deprecated = true,
        features = { field_presence: EXPLICIT }
      ];

      // Deprecated: This is not logged anymore.
      string name = 3 [
        deprecated = true,
        features = { field_presence: EXPLICIT }
      ];

      // The type of the field.
      FieldType field_type = 4 [features = { field_presence: EXPLICIT }];

      enum FieldType {
        // Assigned if the field is none of the types below.
        UNKNOWN = 0;

        // The field is a username field.
        USERNAME = 1;

        // The field is a password field.
        PASSWORD = 2;

        // The field is a new password field.
        NEW_PASSWORD = 3;

        // The field is a confirmation password field.
        CONFIRMATION_PASSWORD = 4;
      }
    }

    enum FrameType {
      // Assigned if the frame is none of the types below.
      UNKNOWN = 0;

      // If it is a primary main frame.
      MAIN_FRAME = 1;

      // If it is a direct child of a primary main frame.
      DIRECT_CHILD_OF_MAIN_FRAME = 2;

      // If it is a fenced frame or nested in a fenced frame
      FENCED_FRAME = 3;

      // If it is a nested frame.
      NESTED_FRAME = 4;
    }
  }

  message ParsedFormDetails {
    // The form data of the parsed form.
    FormData form_data = 1 [features = { field_presence: EXPLICIT }];

    // Time it took for the async check to validate if
    // the form is a login form or not.
    int64 async_check_time_ms = 2 [features = { field_presence: EXPLICIT }];

    // Indicates if it the form was in a valid frame which also means that the
    // origin is supported.
    bool is_valid_frame_and_origin = 3 [features = { field_presence: EXPLICIT }];

    // True if username field is visible to the user.
    bool is_username_field_visible = 4 [features = { field_presence: EXPLICIT }];

    // True if password field is visible to the user.
    bool is_password_field_visible = 5 [features = { field_presence: EXPLICIT }];

    // True if new password field is visible to the user.
    bool is_new_password_visible = 6 [features = { field_presence: EXPLICIT }];
  }

  message FederatedGetCredentialsDetails {
    // Outcome of the GetCredentials step.
    FederatedGetCredentialsOutcome outcome = 1 [features = { field_presence: EXPLICIT }];

    // Time it took for the list permissions API call to complete.
    int64 list_permissions_call_time_ms = 2 [features = { field_presence: EXPLICIT }];

    enum FederatedGetCredentialsOutcome {
      UNSPECIFIED = 0;

      // No federated credentials found for this site.
      NO_CREDENTIALS = 1;

      // At least one federated credential found for this site.
      CREDENTIALS_FOUND = 2;
    }
  }

  message GetCredentialsDetails {
    // Logs the finder logic outcome for every possible form on the page.
    repeated ParsedFormDetails parsed_form_details = 1;

    // Outcome of the GetCredentials step.
    GetCredentialsOutcome outcome = 2 [features = { field_presence: EXPLICIT }];

    PermissionDetails permission_details = 3 [features = { field_presence: EXPLICIT }];

    // Time it took for getting credentials of the site.
    int64 getting_credentials_time_ms = 4 [features = { field_presence: EXPLICIT }];

    // Federated credentials logs
    FederatedGetCredentialsDetails federated_get_credentials_details = 5 [features = { field_presence: EXPLICIT }];

    enum GetCredentialsOutcome {
      UNSPECIFIED = 0;

      // No credentials exist for this site.
      NO_CREDENTIALS = 1;

      // At least one sign in form exists
      // that matches.
      SIGN_IN_FORM_EXISTS = 2;

      // No sign in form was found.
      NO_SIGN_IN_FORM = 3;

      // Filling is not allowed in the site.
      FILLING_NOT_ALLOWED = 4;
    }

    enum PermissionDetails {
      UNKNOWN = 0;

      // The user gave permanent permission for this
      // credential to be used.
      HAS_PERMANENT_PERMISSION = 1;

      // The user did not give a permanent
      // permission for this credential to be used.
      NO_PERMANENT_PERMISSION = 2;
    }
  }

  message AttemptLoginDetails {
    // Logs the result of all the parsed forms found in the page.
    // Not all are eligible to be filled.
    repeated ParsedFormDetails parsed_form_details = 1;

    // Outcome of the AttemptLogin step.
    AttemptLoginOutcome outcome = 2 [features = { field_presence: EXPLICIT }];

    // The result of a login form that was filled.
    repeated FillingFormResult filling_form_result = 3;

    // Time it took for the whole step to complete.
    int64 attempt_login_time_ms = 4 [features = { field_presence: EXPLICIT }];

    // Indicates if a button click is required to start the login. Can be false
    // for active FedCM API calls.
    bool button_click_required = 5 [features = { field_presence: EXPLICIT }];

    // Indicates if the button click was successful.
    bool button_click_succeeded = 6 [features = { field_presence: EXPLICIT }];

    // The result of filling eligible login forms.
    message FillingFormResult {
      // The form data of the filled form.
      FormData form_data = 1 [features = { field_presence: EXPLICIT }];

      // Indicates if the username was successfully filled.
      bool was_username_filled = 2 [features = { field_presence: EXPLICIT }];

      // Indicates if the password was successfully filled.
      bool was_password_filled = 3 [features = { field_presence: EXPLICIT }];
    }

    enum AttemptLoginOutcome {
      UNSPECIFIED = 0;

      // Password specific statuses :
      // Username field, password field or both at the same
      // time were able to be filled.
      SUCCESS = 1;

      // No sign in form available to be filled.
      NO_SIGN_IN_FORM = 2;

      // The provided credential is not a saved match for the site on which
      // login was triggered.
      INVALID_CREDENTIAL = 3;

      // No fillable fields.
      NO_FILLABLE_FIELDS = 4;

      // The main frame origin does not match the
      // origin for which filling was requested.
      DISALLOWED_ORIGIN = 5;

      // Device reauth required.
      REAUTH_REQUIRED = 6;

      // Device reauth failed
      REAUTH_FAILED = 7;

      // Federated login statuses:
      FEDERATED_SUCCESS = 8;

      // Flow requires user interaction. Often this is because the website
      // requuested non-standard permission to access user informaition.
      FEDERATED_CONTINUATION = 9;

      // The chosen account is no longer available. Should be rare because it
      // means the account state changed inbetween the credential picker and the
      // login attempt.
      FEDERATED_ACCOUNT_NOT_LOGGED_IN = 10;

      // The chosen account turned out to be a sign-up account. This means we
      // had a false-positive from the GetCredentials step.
      FEDERATED_ACCOUNT_IS_SIGN_UP = 11;

      // The account chosen in the credential picker is not eligible to log in
      // for various reasons, like not being supported by the RP. This can also
      // be a false-positive from the GetCredentials step.
      FEDERATED_ACCOUNT_IS_NOT_AVAILABLE = 12;

      // Generic error from the IdP.
      FEDERATED_IDP_RETURNED_ERROR = 13;

      // Network error from the IdP.
      FEDERATED_IDP_NETWORK_ERROR = 14;

      // Request to the IdP to fetch the token was aborted.
      FEDERATED_TOKEN_REQUEST_ABORTED = 15;

      // FedCM UI cannot be displayed.
      FEDERATED_FRAME_NOT_ACTIVE = 16;

      // Similar to FEDERATED_ACCOUNT_IS_NOT_AVAILABLE.
      FEDERATED_EXPECTED_ACCOUNT_NOT_PRESENT = 17;

      // Timeout for the federated login.
      FEDERATED_TIMEOUT = 18;

      // Password filling is not allowed in the site, potentially due to an
      // enterprise policy.
      FILLING_NOT_ALLOWED = 19;

      // The primary page changed while the password filling attempt
      // was in progress, so the attempt was cancelled.
      FILLING_INTERRUPTED_BY_PAGE_CHANGE = 20;
    }
  }

  // Details on Permissions picked
  enum PermissionOption {
    UNKNOWN = 0;

    // The user clicked "Allow once"
    ALLOW_ONCE = 1;

    // The user clicked "Always allow"
    ALWAYS_ALLOW = 2;

    // Task was stopped, user did not pick any
    // permission for this credential and stopped
    // the task.
    TASK_STOPPED = 3;
  }

  enum FlowType {
    // Default value. Regular actor login flows.
    UNSPECIFIED = 0;

    // Actor login flows part of an automated password change actor task.
    AUTOMATED_PASSWORD_CHANGE = 1;
  }
}
