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 base::generic_channel::GenericSender;
6use base::id::WebViewId;
7use malloc_size_of_derive::MallocSizeOf;
8use profile_traits::mem::ReportsChan;
9use serde::{Deserialize, Serialize};
10use servo_url::ServoUrl;
11
12#[derive(Clone, Copy, Debug, Deserialize, PartialEq, MallocSizeOf, Serialize)]
13pub enum WebStorageType {
14    Session,
15    Local,
16}
17
18#[derive(Clone, Debug, Deserialize, 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(GenericSender<usize>, WebStorageType, WebViewId, ServoUrl),
34
35    /// gets the name of the key at the specified index in the associated storage data
36    Key(
37        GenericSender<Option<String>>,
38        WebStorageType,
39        WebViewId,
40        ServoUrl,
41        u32,
42    ),
43
44    /// Gets the available keys in the associated storage data
45    Keys(
46        GenericSender<Vec<String>>,
47        WebStorageType,
48        WebViewId,
49        ServoUrl,
50    ),
51
52    /// gets the value associated with the given key in the associated storage data
53    GetItem(
54        GenericSender<Option<String>>,
55        WebStorageType,
56        WebViewId,
57        ServoUrl,
58        String,
59    ),
60
61    /// sets the value of the given key in the associated storage data
62    SetItem(
63        GenericSender<Result<(bool, Option<String>), ()>>,
64        WebStorageType,
65        WebViewId,
66        ServoUrl,
67        String,
68        String,
69    ),
70
71    /// removes the key/value pair for the given key in the associated storage data
72    RemoveItem(
73        GenericSender<Option<String>>,
74        WebStorageType,
75        WebViewId,
76        ServoUrl,
77        String,
78    ),
79
80    /// clears the associated storage data by removing all the key/value pairs
81    Clear(GenericSender<bool>, WebStorageType, WebViewId, ServoUrl),
82
83    /// clones all storage data of the given top-level browsing context for a new browsing context.
84    /// should only be used for sessionStorage.
85    Clone {
86        sender: GenericSender<()>,
87        src: WebViewId,
88        dest: WebViewId,
89    },
90
91    /// gets the list of origin descriptors for given storage type
92    ///
93    /// TODO: Consider returning `Vec<SiteDescriptor>`
94    ListOrigins(GenericSender<Vec<OriginDescriptor>>, WebStorageType),
95
96    /// clears storage data for given storage type and sites, affecting all matching origins
97    ClearDataForSites(GenericSender<()>, WebStorageType, Vec<String>),
98
99    /// send a reply when done cleaning up thread resources and then shut it down
100    Exit(GenericSender<()>),
101
102    /// Measure memory used by this thread and send the report over the provided channel.
103    CollectMemoryReport(ReportsChan),
104}