pub struct OriginKey { /* private fields */ }Expand description
The security principal a piece of stored state belongs to.
Storage is keyed by this and never by a URL. Two pages on one origin share storage; two pages on different origins must not see each other’s, and that is a security property rather than a nicety.
Derived through Url::origin, which is Servo’s implementation of the
WHATWG origin concept, so the awkward cases are already decided: blob:
unwraps to its inner origin, and file: and data: are opaque.
§Opaque origins
Url::origin mints a fresh opaque origin on every call for a file:
URL, so a document must derive its key once, at construction, and hold it.
Deriving twice would give one document two identities and lose its own
writes.
That is exactly the intended behaviour and not a wrinkle to route around.
Collapsing every file: page into one shared bucket would mean any local
HTML file could read any other’s saved state, which is the same class of
mistake as blitz-net’s file: handler reading any path it is handed.
One such hole is enough.
is_persistable is the flag a disk-backed
provider must check: an opaque origin is unique to one instance of one
document, so writing it to disk stores a row that can never be read again.
Implementations§
Source§impl OriginKey
impl OriginKey
Sourcepub fn for_document(url: &Url) -> OriginKey
pub fn for_document(url: &Url) -> OriginKey
The origin of a document loaded from url.
Call once per document and keep the result. See the type’s docs for why
calling twice is a bug for file: and data: URLs.
Sourcepub fn opaque() -> OriginKey
pub fn opaque() -> OriginKey
A fresh opaque origin, shared with nothing.
The serialisation of every opaque origin is the string null, so it
cannot be used to tell two of them apart. This appends a
process-unique counter so that a provider keying an in-memory map on
as_str isolates them from each other, which
null alone would not.
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
A stable string for this origin, suitable as a map or table key.
Unique per origin, including across opaque ones. Not a URL, and not to be parsed back into one.
Sourcepub fn is_persistable(&self) -> bool
pub fn is_persistable(&self) -> bool
Whether state under this origin may be written to disk.
False for opaque origins. A provider that persists must check this and keep the rest in memory; see the type’s docs.
Trait Implementations§
impl Eq for OriginKey
impl StructuralPartialEq for OriginKey
Auto Trait Implementations§
impl Freeze for OriginKey
impl RefUnwindSafe for OriginKey
impl Send for OriginKey
impl Sync for OriginKey
impl Unpin for OriginKey
impl UnsafeUnpin for OriginKey
impl UnwindSafe for OriginKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more