// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module storage.mojom;
import "mojo/public/mojom/base/time.mojom";
import "services/network/public/mojom/cross_origin_embedder_policy.mojom";
import "third_party/blink/public/mojom/script/script_type.mojom";
import "third_party/blink/public/mojom/frame/policy_container.mojom";
import "third_party/blink/public/mojom/service_worker/navigation_preload_state.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_ancestor_frame_type.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_database.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_fetch_handler_type.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_registration_options.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_router_rule.mojom";
import "third_party/blink/public/mojom/storage_key/storage_key.mojom";
import "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom";
import "url/mojom/url.mojom";
// Status code of service worker database operations.
// This is used in UMA. A new value must be appended only.
enum ServiceWorkerDatabaseStatus {
kOk = 0,
kErrorNotFound = 1,
kErrorIOError = 2,
kErrorCorrupted = 3,
kErrorFailed = 4,
kErrorNotSupported = 5,
kErrorDisabled = 6,
// Mojo connection to the Storage Service is disconnected, typically due to a
// crash.
kErrorStorageDisconnected = 7,
};
// Represents a service worker registration data which is stored persistently
// in database. The Storage Service (//components/services/storage) supplies
// this data. //content/browser consumes data to create in-memory representation
// of a service worker registration.
struct ServiceWorkerRegistrationData {
// These values are immutable for the life of a registration.
int64 registration_id = blink.mojom.kInvalidServiceWorkerRegistrationId;
url.mojom.Url scope;
// The `key` field isn't part of the registration data as per the spec but
// it's convenient to have here as some internal operations on the
// registration data require the storage key (such as
// ServiceWorkerDatabase::WriteRegistration).
blink.mojom.StorageKey key;
// Versions are first stored once they successfully install and become
// the waiting version. Then transition to the active version. The stored
// version may be in the ACTIVATED state or in the INSTALLED state.
url.mojom.Url script;
blink.mojom.ScriptType script_type = blink.mojom.ScriptType.kClassic;
blink.mojom.ServiceWorkerUpdateViaCache update_via_cache =
blink.mojom.ServiceWorkerUpdateViaCache.kImports;
int64 version_id = blink.mojom.kInvalidServiceWorkerVersionId;
bool is_active = false;
blink.mojom.ServiceWorkerFetchHandlerType fetch_handler_type =
blink.mojom.ServiceWorkerFetchHandlerType.kNoHandler;
mojo_base.mojom.Time last_update_check;
mojo_base.mojom.Time script_response_time;
map<string, array<string>>? origin_trial_tokens;
blink.mojom.NavigationPreloadState navigation_preload_state;
array<blink.mojom.WebFeature> used_features;
// Not populated until the registration is stored into database.
int64 resources_total_size_bytes = 0;
blink.mojom.PolicyContainerPolicies? policy_container_policies;
// The type of the frame that registered this service worker, which is used
// to restrict the use of some powerful APIs in FencedFrames
// (crbug.com/1276419).
blink.mojom.AncestorFrameType ancestor_frame_type;
blink.mojom.ServiceWorkerRouterRules? router_rules;
// Set to true if the service worker had hid event handlers on initial script
// execution.
bool has_hid_event_handlers;
// Set to true if the service worker had usb event handlers on initial script
// execution.
bool has_usb_event_handlers;
};
// Represents a service worker script data which is stored in database.
// The Storage Service (//components/services/storage) supplies this record.
// The //content consumes this record to create in-memory representation of a
// service worker script.
struct ServiceWorkerResourceRecord {
int64 resource_id = blink.mojom.kInvalidServiceWorkerResourceId;
url.mojom.Url url;
// |size_bytes| could be -1 when there was an error while loading the worker
// script data, but when stored to the database this value is always >= 0.
int64 size_bytes = 0;
// |sha256_checksum| is a hash string calculated from each service worker
// script resource data with the SHA256 algorithm. This could be empty when
// the stored record is old.
string? sha256_checksum;
};