wayland_bridge/
secure_output.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use crate::client::Client;
use crate::compositor::Surface;
use crate::object::{NewObjectExt, ObjectRef, RequestReceiver};
use anyhow::Error;
use fuchsia_wayland_core as wl;
use zcr_secure_output_v1_server_protocol::{
    ZcrSecureOutputV1, ZcrSecureOutputV1Request, ZcrSecurityV1, ZcrSecurityV1Request,
};

/// An implementation of the zcr_secure_output_v1 global.
pub struct SecureOutput;

impl SecureOutput {
    /// Creates a new `SecureOutput`.
    pub fn new() -> Self {
        SecureOutput
    }
}

impl RequestReceiver<ZcrSecureOutputV1> for SecureOutput {
    fn receive(
        this: ObjectRef<Self>,
        request: ZcrSecureOutputV1Request,
        client: &mut Client,
    ) -> Result<(), Error> {
        match request {
            ZcrSecureOutputV1Request::Destroy => {
                client.delete_id(this.id())?;
            }
            ZcrSecureOutputV1Request::GetSecurity { id, surface } => {
                id.implement(client, Security::new(surface))?;
            }
        }
        Ok(())
    }
}

struct Security {
    _surface_ref: ObjectRef<Surface>,
}

impl Security {
    pub fn new(surface: wl::ObjectId) -> Self {
        Security { _surface_ref: surface.into() }
    }
}

impl RequestReceiver<ZcrSecurityV1> for Security {
    fn receive(
        this: ObjectRef<Self>,
        request: ZcrSecurityV1Request,
        client: &mut Client,
    ) -> Result<(), Error> {
        match request {
            ZcrSecurityV1Request::Destroy => {
                client.delete_id(this.id())?;
            }
            ZcrSecurityV1Request::OnlyVisibleOnSecureOutput => {}
        }
        Ok(())
    }
}