Skip to main content

Capabilities

Struct Capabilities 

Source
#[non_exhaustive]
pub struct Capabilities {
Show 19 fields pub process: ProcessGrants, pub fs: FileGrants, pub network: NetworkGrants, pub webview: Option<Vec<HostPattern>>, pub webview_input: bool, pub webview_runtime_origin: bool, pub webview_media: Vec<WebMedia>, pub status_bar: bool, pub clipboard: bool, pub picker: bool, pub share: bool, pub speech: bool, pub notifications: bool, pub audio: bool, pub application: bool, pub home_dir: bool, pub host: Vec<String>, pub open_url: Option<OpenUrlGrant>, pub windows: Option<WindowsGrant>,
}
Expand description

What an app may do (one declaration, or one grant). Start with Self::default and set the fields to grant; new capabilities default to denied.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§process: ProcessGrants

Explicit native subprocess grants.

§fs: FileGrants

Explicit native filesystem grants.

§network: NetworkGrants

fetch, remote images and video.

§webview: Option<Vec<HostPattern>>

The hosts web views may show; None: no web views.

§webview_input: bool

Web views may take trusted input (sendInput, webview.input): never without a declaration (Capabilities::all leaves it off).

§webview_runtime_origin: bool

A web view’s allowOrigin adds one origin to the hosts it may show (webview.runtimeOrigin): never without a declaration (Capabilities::all leaves it off).

§webview_media: Vec<WebMedia>

What web views’ pages may capture (webview.media): never without a declaration (Capabilities::all leaves it empty).

§status_bar: bool

The app may set the status bar.

§clipboard: bool

The app may read and write the system clipboard (nsh/clipboard).

§picker: bool

The app may show the system’s picker (nsh/picker): the files the user picks in it reach the app.

§share: bool

The app may show the system’s share sheet (Share of nsh): the text, links and files it shares leave the app where the user sends them.

§speech: bool

The app may recognize the user’s speech (Speech of nsh-extra): the microphone listens while a session runs, and the transcript reaches the app.

§notifications: bool

The app may show notifications and set its badge (Notifications of nsh). The user’s permission is the system’s, on top of this.

§audio: bool

The app may play sound (Sound and AudioPlayer of nsh).

§application: bool

The app may act on the application as a whole: the main window, the application menu, the tray, global shortcuts, quitting, restarting and launching at login (nsh/desktop), and the app’s page in the system’s settings (nsh/mobile’s AppSettings).

§home_dir: bool

os.homedir() may tell the user’s home directory.

§host: Vec<String>

The functions of the embedding app nsh/host may call: names, or prefixes ending in * ("*": all); empty: none, also for apps without a declaration (Capabilities::all).

§open_url: Option<OpenUrlGrant>

The URLs the app may open outside it (openUrl of nsh/device); None: none.

§windows: Option<WindowsGrant>

The windows the app may open and what they may do (nsh/desktop’s Window); None: no window of the app’s own. The first window needs the grant too: no window is privileged.

Implementations§

Source§

impl Capabilities

Source

pub fn all() -> Capabilities

Legacy unrestricted APIs for apps without a declaration. Socket, process, filesystem and host function grants stay empty and always require explicit opt-in.

Source

pub fn from_json(value: &Value) -> Result<Capabilities, String>

Parses capabilities strictly: unknown keys are errors. What NSH itself reads (nsh.json, bundles, packages, grants) goes through Capabilities::from_json_lenient, which a newer NSH’s keys do not break.

Source

pub fn from_json_lenient( value: &Value, ) -> Result<(Capabilities, Vec<String>), String>

Parses capabilities a newer NSH may have written (nsh.json, bundles, signed packages, grants): what it cannot read never grants anything. An unknown capability is not granted; an unknown key inside one (a restriction this runtime cannot apply) drops what it is in, the whole capability or the http grant; a value of a form it does not know drops its capability (or its http grant), and the others stay. Declared capabilities allow only what they list, so what is dropped is denied. Only a declaration that is no object is denied whole. Returns what was dropped (capabilities.bluetooth, …) with the capabilities.

Source

pub fn to_json(&self) -> Value

The JSON form Capabilities::from_json reads.

Trait Implementations§

Source§

impl Clone for Capabilities

Source§

fn clone(&self) -> Capabilities

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Capabilities

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Capabilities

Source§

fn default() -> Capabilities

Returns the “default value” for a type. Read more
Source§

impl Eq for Capabilities

Source§

impl PartialEq for Capabilities

Source§

fn eq(&self, other: &Capabilities) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Capabilities

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ParallelSend for T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more