chromium/components/services/storage/service_worker/service_worker_database.proto

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

syntax = "proto2";

option optimize_for = LITE_RUNTIME;

package storage;

message ServiceWorkerOriginTrialFeature {
  required string name = 1;
  repeated string tokens = 2;
}

message ServiceWorkerOriginTrialInfo {
  repeated ServiceWorkerOriginTrialFeature features = 1;
}

message ServiceWorkerNavigationPreloadState {
  required bool enabled = 1;
  optional string header = 2;
}

// NEXT ID TO USE: 27
message ServiceWorkerRegistrationData {
  enum ServiceWorkerScriptType {
    CLASSIC = 0;
    MODULE = 1;
  }
  enum ServiceWorkerUpdateViaCacheType {
    IMPORTS = 0;
    ALL = 1;
    NONE = 2;
  }
  enum CrossOriginEmbedderPolicyValue {
    NONE_OR_NOT_EXIST = 0;
    REQUIRE_CORP = 1;
    CREDENTIALLESS = 2;
  }
  enum AncestorFrameType {
    NORMAL_FRAME = 0;
    FENCED_FRAME = 1;
  }
  enum FetchHandlerSkippableType {
    reserved 0;  // Deprecated UNKNOWN_FETCH_HANDLER.
    NOT_SKIPPABLE = 1;
    SKIPPABLE_EMPTY_FETCH_HANDLER = 2;
  }
  enum ReferrerPolicyValue {
    ALWAYS = 0;
    DEFAULT = 1;
    NO_REFERRER_WHEN_DOWNGRADE = 2;
    NEVER = 3;
    ORIGIN = 4;
    ORIGIN_WHEN_CROSS_ORIGIN = 5;
    STRICT_ORIGIN_WHEN_CROSS_ORIGIN = 6;
    SAME_ORIGIN = 7;
    STRICT_ORIGIN = 8;
  }

  // https://wicg.github.io/private-network-access/#framework
  enum IPAddressSpace {
    UNKNOWN = 0;
    LOCAL = 1;
    PRIVATE = 2;
    PUBLIC = 3;
  }

  message PolicyContainerPolicies {
    optional ReferrerPolicyValue referrer_policy = 1 [default = DEFAULT];
    optional int32 sandbox_flags = 2 [default = 0];
    optional IPAddressSpace ip_address_space = 3 [default = UNKNOWN];
    // TODO(crbug.com/40168691): add content security policies
  }

  message RouterRules {
    message RuleV1 {
      message Condition {
        // Structure representing a URLPattern as described in:
        // https://wicg.github.io/urlpattern/.
        message URLPattern {
          message Part {
            enum Modifier {
              kNone = 0;
              kOptional = 1;
              kZeroOrMore = 2;
              kOneOrMore = 3;
            }
            // Represents a fixed string part of a URLPattern as described in:
            // https://wicg.github.io/urlpattern/#part-type-fixed-text
            message FixedPattern {
              optional string value = 1;
            }
            // Represents either a segment wildcard part or a full wildcard
            // part of a URLPattern as described in:
            // https://wicg.github.io/urlpattern/#parts
            message WildcardPattern {
              optional string name = 1;
              optional string prefix = 2;
              optional string value = 3;
              optional string suffix = 4;
            }
            optional Modifier modifier = 1;
            oneof pattern {
              FixedPattern fixed = 2;
              // Note that kRegex PartType is not implemented because we do not
              // execute regexp in the browser process for security concerns.
              // (but reserve 3 for regexp just in case).
              WildcardPattern segment_wildcard = 4;
              WildcardPattern full_wildcard = 5;
            }
          }
          message Options {
            optional bool ignore_case = 1 [default = false];
          }

          repeated Part legacy_pathname = 1;

          repeated Part protocol = 3;
          repeated Part username = 4;
          repeated Part password = 5;
          repeated Part hostname = 2;
          repeated Part port = 6;
          repeated Part pathname = 7;
          repeated Part search = 8;
          repeated Part hash = 9;

          optional Options options = 10;
        }
        message Request {
          optional string method = 1;
          // RequestMode in services/network/public/mojom/fetch_api.mojom
          enum Mode {
            kSameOriginMode = 0;
            kNoCorsMode = 1;
            kCorsMode = 2;
            kCorsWithForcedPreflightMode = 3;
            kNavigateMode = 4;
          }
          optional Mode mode = 2;
          // RequestDestination in services/network/public/mojom/fetch_api.mojom
          enum Destination {
            kEmptyDestination = 0;
            kAudioDestination = 1;
            kAudioWorkletDestination = 2;
            kDocumentDestination = 3;
            kEmbedDestination = 4;
            kFontDestination = 5;
            kFrameDestination = 6;
            kIframeDestination = 7;
            kImageDestination = 8;
            kManifestDestination = 9;
            kObjectDestination = 10;
            kPaintWorkletDestination = 11;
            kReportDestination = 12;
            kScriptDestination = 13;
            kServiceWorkerDestination = 14;
            kSharedWorkerDestination = 15;
            kStyleDestination = 16;
            kTrackDestination = 17;
            kVideoDestination = 18;
            kWebBundleDestination = 19;
            kWorkerDestination = 20;
            kXsltDestination = 21;
            kFencedframeDestination = 22;
            kWebIdentityDestination = 23;
            kDictionaryDestination = 24;
            kSpeculationRulesDestination = 25;
            kJsonDestination = 26;
            kSharedStorageWorkletDestination = 27;
          }
          optional Destination destination = 3;
        }
        message RunningStatus {
          enum Status {
            kRunning = 0;
            kNotRunning = 1;
          }
          optional Status status = 1;
        }
        // TODO(crbug.com/40285651): Remove and replace this to `condition`
        message ConditionObject {
          repeated Condition conditions = 1;
        }
        message OrCondition {
          repeated ConditionObject objects = 1;
        }
        message NotCondition {
          required ConditionObject object = 1;
        }
        // TODO(crbug.com/40285651): Make this a `message` to fit WebIDL
        oneof condition {
          // Used for representing URLPattern.
          URLPattern url_pattern = 1;
          // Used for representing Request.
          Request request = 2;
          // Used for representing running status.
          RunningStatus running_status = 3;
          // Used for representing 'or' condition.
          // The `_condition` suffix is to avoid conflicts with keywords in C++
          OrCondition or_condition = 4;
          // Used for representing 'not' condition.
          // The `_condition` suffix is to avoid conflicts with keywords in C++
          NotCondition not_condition = 5;
        }
      }
      message Source {
        message NetworkSource {}
        message RaceSource {}
        message FetchEventSource {}
        message CacheSource {
          optional string cache_name = 1;
        }
        oneof source {
          NetworkSource network_source = 1;
          RaceSource race_source = 2;
          FetchEventSource fetch_event_source = 3;
          CacheSource cache_source = 4;
        }
      }
      repeated Condition condition = 1;
      repeated Source source = 2;
    }

    required int32 version = 1;
    repeated RuleV1 v1 = 2;
  }

  required int64 registration_id = 1;
  required string scope_url = 2;
  required string script_url = 3;

  // Versions are first stored once they successfully install and become the
  // waiting version. Then they are updated when they transition to the active
  // version.
  required int64 version_id = 4;

  required bool is_active = 5;
  required bool has_fetch_handler = 6;
  optional FetchHandlerSkippableType fetch_handler_skippable_type = 22;

  // Serialized by Time::FromDeltaSinceWindowsEpoch().
  required int64 last_update_check_time = 7;

  optional uint64 resources_total_size_bytes = 8;

  // repeated string foreign_fetch_scope = 9;  // obsolete
  // repeated string foreign_fetch_origin = 10; // obsolete

  // If the registration data was created by old Chrome (< M56),
  // |origin_trial_tokens| is not set. In this case, we have to start the
  // Service Worker and load the main script resource in ServiceWorkerStorage
  // to check the HTTP header.
  optional ServiceWorkerOriginTrialInfo origin_trial_tokens = 11;

  optional ServiceWorkerNavigationPreloadState navigation_preload_state = 12;

  // The set of features that the worker used up until the time installation
  // completed. The values must be from blink::UseCounter::Feature enum.
  repeated uint32 used_features = 13;

  optional ServiceWorkerUpdateViaCacheType update_via_cache = 14
      [default = IMPORTS];
  optional ServiceWorkerScriptType script_type = 15 [default = CLASSIC];

  // The time when the browser received the service worker main script,
  // serialized by Time::ToDeltaSinceWindowsEpoch().
  optional int64 script_response_time = 16;

  optional CrossOriginEmbedderPolicyValue cross_origin_embedder_policy_value =
      17 [default = NONE_OR_NOT_EXIST];
  optional string cross_origin_embedder_policy_reporting_endpoint = 18;
  optional CrossOriginEmbedderPolicyValue
      cross_origin_embedder_policy_report_only_value = 19
      [default = NONE_OR_NOT_EXIST];
  optional string cross_origin_embedder_policy_report_only_reporting_endpoint =
      20;
  optional AncestorFrameType ancestor_frame_type = 21 [default = NORMAL_FRAME];

  optional PolicyContainerPolicies policy_container_policies = 23;

  optional RouterRules router_rules = 24;

  optional bool has_hid_event_handlers = 25;

  optional bool has_usb_event_handlers = 26;
}

message ServiceWorkerResourceRecord {
  required int64 resource_id = 1;
  required string url = 2;
  optional uint64 size_bytes = 3;
  optional string sha256_checksum = 4;
}