mirror of
https://github.com/servo/servo
synced 2026-05-11 01:22:19 +02:00
sessionStorage entries are identified via their associated origins and removed across all browsing contexts. This brings sessionStorage in line with cookies, which were already handled by the API. Both public and private browsing contexts are included in the clearing operation. The necessary support has been added to the storage crate to clear WebStorage data. Testing: A new integration test has been added. Signed-off-by: Jan Varga <jvarga@igalia.com>
92 lines
3.0 KiB
Rust
92 lines
3.0 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
use base::generic_channel::{self, GenericSend, GenericSender, SendResult};
|
|
use malloc_size_of::malloc_size_of_is_0;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::client_storage::ClientStorageThreadMessage;
|
|
use crate::indexeddb::IndexedDBThreadMsg;
|
|
use crate::webstorage_thread::{OriginDescriptor, WebStorageThreadMsg, WebStorageType};
|
|
|
|
pub mod client_storage;
|
|
pub mod indexeddb;
|
|
pub mod webstorage_thread;
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct StorageThreads {
|
|
client_storage_thread: GenericSender<ClientStorageThreadMessage>,
|
|
idb_thread: GenericSender<IndexedDBThreadMsg>,
|
|
web_storage_thread: GenericSender<WebStorageThreadMsg>,
|
|
}
|
|
|
|
impl StorageThreads {
|
|
pub fn new(
|
|
client_storage_thread: GenericSender<ClientStorageThreadMessage>,
|
|
idb_thread: GenericSender<IndexedDBThreadMsg>,
|
|
web_storage_thread: GenericSender<WebStorageThreadMsg>,
|
|
) -> StorageThreads {
|
|
StorageThreads {
|
|
client_storage_thread,
|
|
idb_thread,
|
|
web_storage_thread,
|
|
}
|
|
}
|
|
|
|
// TODO: Consider changing to `webstorage_sites`
|
|
pub fn webstorage_origins(&self, storage_type: WebStorageType) -> Vec<OriginDescriptor> {
|
|
let (sender, receiver) = generic_channel::channel().unwrap();
|
|
let _ = self
|
|
.web_storage_thread
|
|
.send(WebStorageThreadMsg::ListOrigins(sender, storage_type));
|
|
receiver.recv().unwrap()
|
|
}
|
|
|
|
pub fn clear_webstorage_for_sites(&self, storage_type: WebStorageType, sites: &[&str]) {
|
|
let sites = sites.iter().map(|site| site.to_string()).collect();
|
|
let (sender, receiver) = generic_channel::channel().unwrap();
|
|
let _ = self
|
|
.web_storage_thread
|
|
.send(WebStorageThreadMsg::ClearDataForSites(
|
|
sender,
|
|
storage_type,
|
|
sites,
|
|
));
|
|
let _ = receiver.recv();
|
|
}
|
|
}
|
|
|
|
impl GenericSend<ClientStorageThreadMessage> for StorageThreads {
|
|
fn send(&self, msg: ClientStorageThreadMessage) -> SendResult {
|
|
self.client_storage_thread.send(msg)
|
|
}
|
|
|
|
fn sender(&self) -> GenericSender<ClientStorageThreadMessage> {
|
|
self.client_storage_thread.clone()
|
|
}
|
|
}
|
|
|
|
impl GenericSend<IndexedDBThreadMsg> for StorageThreads {
|
|
fn send(&self, msg: IndexedDBThreadMsg) -> SendResult {
|
|
self.idb_thread.send(msg)
|
|
}
|
|
|
|
fn sender(&self) -> GenericSender<IndexedDBThreadMsg> {
|
|
self.idb_thread.clone()
|
|
}
|
|
}
|
|
|
|
impl GenericSend<WebStorageThreadMsg> for StorageThreads {
|
|
fn send(&self, msg: WebStorageThreadMsg) -> SendResult {
|
|
self.web_storage_thread.send(msg)
|
|
}
|
|
|
|
fn sender(&self) -> GenericSender<WebStorageThreadMsg> {
|
|
self.web_storage_thread.clone()
|
|
}
|
|
}
|
|
|
|
// Ignore the sub-fields
|
|
malloc_size_of_is_0!(StorageThreads);
|