mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Initial IndexedDB Support (#33044)
Adds indexeddb support to servo. At the moment heed is being used as the backend, although this can be swapped out by implementing `KvsEngine`. This PR adds a thread + a thread pool for Indexeddb related operations. Also `database_access_task_source` is added for Indexeddb related operations. This is a partial rewrite of #25214. (Reopened due to branching issue) Fixes #6963 --------- Signed-off-by: Ashwin Naren <arihant2math@gmail.com> Signed-off-by: Josh Matthews <josh@joshmatthews.net> Co-authored-by: Rasmus Viitanen <rasviitanen@gmail.com> Co-authored-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
d33cf8fbd1
commit
ed9a79f3f4
259 changed files with 11141 additions and 8 deletions
73
components/net/indexeddb/engines/mod.rs
Normal file
73
components/net/indexeddb/engines/mod.rs
Normal file
|
@ -0,0 +1,73 @@
|
|||
/* 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 std::collections::VecDeque;
|
||||
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use net_traits::indexeddb_thread::{AsyncOperation, IndexedDBTxnMode};
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
pub use self::heed::HeedEngine;
|
||||
|
||||
mod heed;
|
||||
|
||||
#[derive(Eq, Hash, PartialEq)]
|
||||
pub struct SanitizedName {
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl SanitizedName {
|
||||
pub fn new(name: String) -> SanitizedName {
|
||||
let name = name.replace("https://", "");
|
||||
let name = name.replace("http://", "");
|
||||
// FIXME:(arihant2math) Disallowing special characters might be a big problem,
|
||||
// but better safe than sorry. E.g. the db name '../other_origin/db',
|
||||
// would let us access databases from another origin.
|
||||
let name = name
|
||||
.chars()
|
||||
.map(|c| match c {
|
||||
'A'..='Z' => c,
|
||||
'a'..='z' => c,
|
||||
'0'..='9' => c,
|
||||
'-' => c,
|
||||
'_' => c,
|
||||
_ => '-',
|
||||
})
|
||||
.collect();
|
||||
SanitizedName { name }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for SanitizedName {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.name)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct KvsOperation {
|
||||
pub sender: IpcSender<Option<Vec<u8>>>,
|
||||
pub store_name: SanitizedName,
|
||||
pub operation: AsyncOperation,
|
||||
}
|
||||
|
||||
pub struct KvsTransaction {
|
||||
pub mode: IndexedDBTxnMode,
|
||||
pub requests: VecDeque<KvsOperation>,
|
||||
}
|
||||
|
||||
pub trait KvsEngine {
|
||||
fn create_store(&self, store_name: SanitizedName, auto_increment: bool);
|
||||
|
||||
fn delete_store(&self, store_name: SanitizedName);
|
||||
|
||||
#[expect(dead_code)]
|
||||
fn close_store(&self, store_name: SanitizedName);
|
||||
|
||||
fn process_transaction(
|
||||
&self,
|
||||
transaction: KvsTransaction,
|
||||
) -> oneshot::Receiver<Option<Vec<u8>>>;
|
||||
|
||||
fn has_key_generator(&self, store_name: SanitizedName) -> bool;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue