storage_traits/
webstorage_thread.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use malloc_size_of_derive::MallocSizeOf;
6use profile_traits::mem::ReportsChan;
7use serde::{Deserialize, Serialize};
8use servo_base::generic_channel::GenericSender;
9use servo_base::id::WebViewId;
10use servo_url::ImmutableOrigin;
11
12#[derive(Clone, Copy, Debug, Deserialize, PartialEq, MallocSizeOf, Serialize)]
13pub enum WebStorageType {
14    Session,
15    Local,
16}
17
18#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
19pub struct OriginDescriptor {
20    pub name: String,
21}
22
23impl OriginDescriptor {
24    pub fn new(name: String) -> Self {
25        OriginDescriptor { name }
26    }
27}
28
29/// Request operations on the storage data associated with a particular url
30#[derive(Debug, Deserialize, Serialize)]
31pub enum WebStorageThreadMsg {
32    /// gets the number of key/value pairs present in the associated storage data
33    Length(
34        GenericSender<usize>,
35        WebStorageType,
36        WebViewId,
37        ImmutableOrigin,
38    ),
39
40    /// gets the name of the key at the specified index in the associated storage data
41    Key(
42        GenericSender<Option<String>>,
43        WebStorageType,
44        WebViewId,
45        ImmutableOrigin,
46        u32,
47    ),
48
49    /// Gets the available keys in the associated storage data
50    Keys(
51        GenericSender<Vec<String>>,
52        WebStorageType,
53        WebViewId,
54        ImmutableOrigin,
55    ),
56
57    /// gets the value associated with the given key in the associated storage data
58    GetItem(
59        GenericSender<Option<String>>,
60        WebStorageType,
61        WebViewId,
62        ImmutableOrigin,
63        String,
64    ),
65
66    /// sets the value of the given key in the associated storage data
67    SetItem(
68        GenericSender<Result<(bool, Option<String>), ()>>,
69        WebStorageType,
70        WebViewId,
71        ImmutableOrigin,
72        String,
73        String,
74    ),
75
76    /// removes the key/value pair for the given key in the associated storage data
77    RemoveItem(
78        GenericSender<Option<String>>,
79        WebStorageType,
80        WebViewId,
81        ImmutableOrigin,
82        String,
83    ),
84
85    /// clears the associated storage data by removing all the key/value pairs
86    Clear(
87        GenericSender<bool>,
88        WebStorageType,
89        WebViewId,
90        ImmutableOrigin,
91    ),
92
93    /// clones all storage data of the given top-level browsing context for a new browsing context.
94    /// should only be used for sessionStorage.
95    Clone {
96        sender: GenericSender<()>,
97        src: WebViewId,
98        dest: WebViewId,
99    },
100
101    /// gets the list of origin descriptors for given storage type
102    ///
103    /// TODO: Consider returning `Vec<SiteDescriptor>`
104    ListOrigins(GenericSender<Vec<OriginDescriptor>>, WebStorageType),
105
106    /// clears storage data for given storage type and sites, affecting all matching origins
107    ClearDataForSites(GenericSender<()>, WebStorageType, Vec<String>),
108
109    /// send a reply when done cleaning up thread resources and then shut it down
110    Exit(GenericSender<()>),
111
112    /// Measure memory used by this thread and send the report over the provided channel.
113    CollectMemoryReport(ReportsChan),
114}