Debian Codegraph @

third_party/rust/webext-storage/README.md

raw
1 # WebExtension Storage Component
2
3 The WebExtension Storage component can be used to power an implementation of the
4 [`chrome.storage.sync`](https://developer.chrome.com/extensions/storage) WebExtension API,
5 which gives each WebExtensions its own private key-value store that will sync between a user's
6 devices. This particular implementation sits atop [Firefox Sync](../sync_manager/README.md).
7
8 With a small amount of work, this component would also be capable of powering an implementation
9 of `chrome.storage.local`, but this is not an explicit goal at this stage.
10
11 * [Features](#features)
12 * [Using the component](#using-the-component)
13 * [Working on the component](#working-on-the-component)
14
15 ## Features
16
17 The WebExtension Storage component offers:
18
19 1. Local storage of key-value data indexed by WebExtension ID.
20 1. Basic Create, Read, Update and Delete (CRUD) operations for items in the database.
21 1. Syncing of stored data between applications, via Firefox Sync.
22
23 The component ***does not*** offer, but may offer in the future:
24
25 1. Separate storage for key-value data that does not sync, per the
26 `chrome.storage.local` WebExtension API.
27 1. Import functionality from previous WebExtension storage implementations backed by
28 [Kinto](https://kinto-storage.org).
29
30 The component ***does not*** offer, and we have no concrete plans to offer:
31
32 1. Any facilities for loading or running WebExtensions, or exposing this data to them.
33 1. Any helpers to secure data access between different WebExtensions.
34
35 As a consuming application, you will need to implement code that plumbs this component in to your
36 WebExtensions infrastructure, so that each WebExtension gets access to its own data (and only its
37 own data) stored in this component.
38
39 ## Using the component
40
41 ### Prerequisites
42
43 To use this component for local storage of WebExtension data, you will need to know how to integrate appservices components
44 into an application on your target platform:
45 * **Firefox Desktop**: There's some custom bridging code in mozilla-central.
46 * **Android**: Bindings not yet available; please reach out on slack to discuss!
47 * **iOS**: Bindings not yet available; please reach out on slack to discuss!
48 * **Other Platforms**: We don't know yet; please reach out on slack to discuss!
49
50 ### Core Concepts
51
52 * We assume each WebExtension is uniquely identified by an immutable **extension id**.
53 * A **WebExtension Store** is a database that maps extension ids to key-value JSON maps, one per extension.
54 It exposes methods that mirror those of the [`chrome.storage` spec](https://developer.chrome.com/extensions/storage)
55 (e.g. `get`, `set`, and `delete`) and which take an extension id as their first argument.
56
57 ## Working on the component
58
59 ### Prerequisites
60
61 To effectively work on the WebExtension Storage component, you will need to be familiar with:
62
63 * Our general [guidelines for contributors](../../docs/contributing.md).
64 * The [core concepts](#core-concepts) for users of the component, outlined above.
65 * The way we [generate ffi bindings](../../docs/howtos/building-a-rust-component.md) and expose them to
66 [Kotlin](../../docs/howtos/exposing-rust-components-to-kotlin.md) and
67 [Swift](../../docs/howtos/exposing-rust-components-to-swift.md).
68 * The key ideas behind [how Firefox Sync works](../../docs/synconomicon/) and the [sync15 crate](../sync15/README.md).
69
70 ### Storage Overview
71
72 This component stores WebExtension data in a SQLite database, one row per extension id.
73 The key-value map data for each extension is stored as serialized JSON in a `TEXT` field;
74 this is nice and simple and helps ensure that the stored data has the semantics we want,
75 which are pretty much just the semantics of JSON.
76
77 For syncing, we maintain a "mirror" table which contains one item per record known to
78 exist on the server. These items are identified by a randomly-generated GUID, in order
79 to hide the raw extension ids from the sync server.
80
81 When uploading records to the server, we write one
82 [encrypted BSO](https://mozilla-services.readthedocs.io/en/latest/sync/storageformat5.html#collection-records)
83 per extension. Its server-visible id is the randomly-generated GUID, and its encrypted payload
84 contains the plaintext extension id and corresponding key-value map data.
85
86 The end result is something like this (highly simplified!) diagram:
87
88 [![storage overview diagram](https://docs.google.com/drawings/d/e/2PACX-1vSvCk0uJlXYTtWHmjxhL-mNLGL_q7F50LavltedREH8Ijuqjl875jKYd9PdJ5SrD3mhVOFqANs6A_NB/pub?w=727&h=546)](https://docs.google.com/drawings/d/1MlkFQJ7SUnW4WSEAF9e-2O34EnsAwUFi3Xcf0Lj3Hc8/)
89
90 The details of the encryption are handled by the [sync15 crate](../sync15/README.md), following
91 the formats defied in [sync storage format v5](https://mozilla-services.readthedocs.io/en/latest/sync/storageformat5.html#collection-records).