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

// This file was exported from google3, do not edit manually.
// See README.chromium for details.

edition = "2023";

option optimize_for = LITE_RUNTIME;
option java_package = "org.chromium.components.metrics";

package ukm;

option features.enum_type = CLOSED;
option features.utf8_validation = NONE;

// Types of source ids defined by
// https://cs.chromium.org/chromium/src/services/metrics/public/cpp/ukm_source_id.h
// WARNING: Please update both the internal version and the Chromium version of
// this file when new enum values are added.
enum SourceType {
  DEFAULT = 0;
  NAVIGATION_ID = 1;
  APP_ID = 2;
  HISTORY_ID = 3;
  WEBAPK_ID = 4;
  PAYMENT_APP_ID = 5;
  DESKTOP_WEB_APP_ID = 6;
  WORKER_ID = 7;
  NO_URL_ID = 8;
  REDIRECT_ID = 9;
  WEB_IDENTITY_ID = 10;
  CHROMEOS_WEBSITE_ID = 11;
  EXTENSION_ID = 12;
  NOTIFICATION_ID = 13;
  CDM_ID = 14;
  IWA_BUNDLE_ID = 15;
}

// Android Activity Type defined by
// https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/flags/android/chrome_session_state.h?q=ActivityType
enum AndroidActivityType {
  TABBED = 0;
  CUSTOM_TAB = 1;
  TRUSTED_WEB_ACTIVITY = 2;
  WEB_APP = 3;
  WEB_APK = 4;
  PRE_FIRST_TAB = 5;
  AUTH_TAB = 6;
  DEV_TOOLS = 7;
}

// This signifies if the reported source is a navigation to the same origin as
// the previous document.
// Its value is "unset" for error pages and same document navigations.
// It is "same origin" when the previous document is of the same origin as the
// one we're navigating to.
// Otherwise, it is "cross origin".
enum SameOriginStatus {
  SAME_ORIGIN_STATUS_UNSET = 0;
  SAME_ORIGIN = 1;
  CROSS_ORIGIN = 2;
}

enum UrlScheme {
  URL_SCHEME_UNSUPPORTED = 0;
  HTTP = 1;
  HTTPS = 2;
  FTP = 3;
  ABOUT = 4;
  CHROME = 5;
  CHROME_EXTENSION = 6;
  APP = 7;
}

// If the URL exceeds the length limit, the client will truncate the URL and
// indicate where in the URL the truncation occurred.
// If URLs are truncated at a given component, that component and all longer
// components are considered incomplete. The collector replaces incomplete
// components with kChromiumURLTooLong placeholder.
enum TruncationStatus {
  NOT_TRUNCATED = 0;
  // Yields full_url incomplete.
  TRUNCATED_AT_FULL_PATH = 1;
  // This yields full_url and url_without_query incomplete.
  TRUNCATED_AT_URL_WITHOUT_QUERY = 2;
  // This yields full_url, url_without_query, origin, and
  // registered_domain_with_scheme incomplete.
  TRUNCATED_AT_ORIGIN = 3;
}

// Next tag: 11
message UrlInfo {
  string url = 1;

  // Number of URLs seen for this source before the current URL.
  // If unset, it’s equivalent to the count of the UrlInfo before it + 1,
  // or 0 if it’s the first UrlInfo.
  int32 previous_url_count = 2;

  // The truncation status of the URL, if it exceeded the size limit on client.
  // If status is not NOT_TRUNCATED, some or all of LookupInfo fields will be
  // filled with a placeholder value rather than KUS result for an incomplete
  // URL component. See TruncationStatus enum for details.
  TruncationStatus truncation_status = 10;
}

// Next tag: 4
message NavigationMetadata {
  // Whether this is the same origin as the previous document, cross-origin or
  // unset.
  SameOriginStatus same_origin_status = 1;

  // Whether this navigation is initiated by the renderer.
  // Renderer-initiated navigations include navigations that were triggered
  // from Javascript, by users interacting with the content (e.g. clicking
  // on <a> links or submitting forms, or by client-side redirects.
  // On the other hand, we have browser-initiated navigations, e.g. ones
  // triggered by the user interacting with the browser's UI.
  bool is_renderer_initiated = 2;

  // Whether the navigation committed an error page, as a result of a network
  // error.
  bool is_error_page = 3;
}

// Next tag: 19
message Source {
  // An identifier for the source. This should be unique within a session.
  int64 id = 1;

  // The type, which is based on how the Source is created.
  SourceType type = 16;

  // Unique identifier (for a given client_id/session_id) for the tab this
  // source is associated with. Should only be set for navigation sources.
  int64 tab_id = 10;

  // The source id of the last committed non-same-document navigation for the
  // tab this source is in. Should only be set for navigation sources. For
  // backward compatibility, this field will never be set to the source id of a
  // same-document source. In cases where the last committed navigation was a
  // same-document navigation, previous_same_document_source_id will contain
  // the source id of that previous same document navigation, while
  // previous_source_id will contain the source id of the last committed
  // non-same-document navigation. For example, if a user starts on page A (a
  // non same document page load), then performs a same document navigation to
  // B, then navigates to C (which could be either a same document or a non same
  // document navigation), previous_source_id will reference A, and
  // previous_same_document_source_id will reference B.
  int64 previous_source_id = 11;

  // The source id for the previous same document navigation, if the
  // previously committed source was a same document navigation. If
  // the previously committed source was not a same document
  // navigation, this field will be unset.
  int64 previous_same_document_source_id = 14;

  // For sources representing the first navigation in a new tab, this id marks
  // the source which opened the tab. Should only be set for the first
  // navigation source in a tab.
  int64 opener_source_id = 12;

  // URL information linked to the Source within the record. Only URLs from main
  // frames are recorded.
  // - For non-navigation sources, e.g. a Blink Document, this will contain
  //   exactly one element.
  // - For navigation sources, this contains one element if there's no
  //   redirects.
  //   If there's a redirect, at version 149.0.7817.0 or later, this field
  //   represents the whole redirect chain (up to
  //   net::URLRequest::kMaxRedirects) in order. The last element  of the vector
  //   is the URL of the final landing page. Before version 149.0.7817.0, this
  //   field contains only the initial URL and the final landing URL.
  repeated UrlInfo urls = 8;

  // Data about the URL of the Document, copied from the Source message whose
  // id matched the navigation source id of the DocumentCreated event.
  repeated UrlInfo resolved_urls = 15;

  // Whether this source is for a same document navigation. Examples of same
  // document navigations are fragment navigations, pushState/replaceState,
  // and same page history navigation.
  bool is_same_document_navigation = 13;

  // Metadata about the navigation that is set when the URL is recorded.
  NavigationMetadata navigation_metadata = 17;

  // The URL of the source, as recorded in history. If this URL has not been
  // discovered by Google's crawler, it should not be recorded.
  // Replaced by |urls| field.
  string deprecated_url = 2 [deprecated = true];

  reserved 5;
  reserved deprecated_url_origin;
  reserved 9;
  reserved deprecated_url_scheme;

  // The initial URL of the source. Set in cases where the source URL changed
  // (e.g. it was redirected), otherwise unset. If this URL has not been
  // discovered by Google's crawler, it should not be recorded.
  string deprecated_initial_url = 6 [deprecated = true];

  // Denotes the Chrome Android activity type when created. See
  // https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/flags/android/chrome_session_state.h;l=20;drc=c14f6f4b9c44fe479a8d004576b42723b2a5feb6
  AndroidActivityType android_activity_type = 18;

  // Relative time of navigation for this Source, as seen by the client, and is
  // set for sources of type ukm::SourceIdType::NAVIGATION_ID. Time of events
  // related to this Source will generally be relative to this timestamp. The
  // recorded navigation time is in TimeTicks, which is the relative time since
  // the origin. The origin is platform-specific but is guaranteed to be
  // monotonically increase within each session.
  int64 navigation_time_msec = 3;

  reserved 4;
  reserved 7;
}
