Commit 31ea5da3 authored by Daniel Nicoara's avatar Daniel Nicoara Committed by Commit Bot

EXO: Refactor zcr_secure_output interface

Move the zcr_secure_output interface into its own files. This
change only moves code around, no functional changes.

Bug: 896710
Test: Build and run exo_unittests
Change-Id: If0860eb11d72aedcc3b6c98ad70313584e42bc94
Reviewed-on: https://chromium-review.googlesource.com/c/1481064
Commit-Queue: Daniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635371}
parent 3cbcee4c
......@@ -61,6 +61,8 @@ source_set("wayland") {
"wp_presentation.h",
"wp_viewporter.cc",
"wp_viewporter.h",
"zcr_secure_output.cc",
"zcr_secure_output.h",
"zcr_vsync_feedback.cc",
"zcr_vsync_feedback.h",
]
......
......@@ -77,6 +77,7 @@
#include "components/exo/wayland/wl_subcompositor.h"
#include "components/exo/wayland/wp_presentation.h"
#include "components/exo/wayland/wp_viewporter.h"
#include "components/exo/wayland/zcr_secure_output.h"
#include "components/exo/wayland/zcr_vsync_feedback.h"
#include "components/exo/wm_helper.h"
#include "services/viz/public/interfaces/compositing/compositor_frame_sink.mojom.h"
......@@ -157,103 +158,10 @@ const base::FilePath::CharType kSocketName[] = FILE_PATH_LITERAL("wayland-0");
// Group used for wayland socket.
const char kWaylandSocketGroup[] = "wayland";
// A property key containing a boolean set to true if a security object is
// associated with surface object.
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSurfaceHasSecurityKey, false)
// A property key containing a boolean set to true if a blending object is
// associated with surface object.
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSurfaceHasBlendingKey, false)
////////////////////////////////////////////////////////////////////////////////
// security_interface:
// Implements the security interface to a Surface. The "only visible on secure
// output"-state is set to false upon destruction. A window property will be set
// during the lifetime of this class to prevent multiple instances from being
// created for the same Surface.
class Security : public SurfaceObserver {
public:
explicit Security(Surface* surface) : surface_(surface) {
surface_->AddSurfaceObserver(this);
surface_->SetProperty(kSurfaceHasSecurityKey, true);
}
~Security() override {
if (surface_) {
surface_->RemoveSurfaceObserver(this);
surface_->SetOnlyVisibleOnSecureOutput(false);
surface_->SetProperty(kSurfaceHasSecurityKey, false);
}
}
void OnlyVisibleOnSecureOutput() {
if (surface_)
surface_->SetOnlyVisibleOnSecureOutput(true);
}
// Overridden from SurfaceObserver:
void OnSurfaceDestroying(Surface* surface) override {
surface->RemoveSurfaceObserver(this);
surface_ = nullptr;
}
private:
Surface* surface_;
DISALLOW_COPY_AND_ASSIGN(Security);
};
void security_destroy(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
void security_only_visible_on_secure_output(wl_client* client,
wl_resource* resource) {
GetUserDataAs<Security>(resource)->OnlyVisibleOnSecureOutput();
}
const struct zcr_security_v1_interface security_implementation = {
security_destroy, security_only_visible_on_secure_output};
////////////////////////////////////////////////////////////////////////////////
// secure_output_interface:
void secure_output_destroy(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
void secure_output_get_security(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* surface_resource) {
Surface* surface = GetUserDataAs<Surface>(surface_resource);
if (surface->GetProperty(kSurfaceHasSecurityKey)) {
wl_resource_post_error(resource, ZCR_SECURE_OUTPUT_V1_ERROR_SECURITY_EXISTS,
"a security object for that surface already exists");
return;
}
wl_resource* security_resource =
wl_resource_create(client, &zcr_security_v1_interface, 1, id);
SetImplementation(security_resource, &security_implementation,
std::make_unique<Security>(surface));
}
const struct zcr_secure_output_v1_interface secure_output_implementation = {
secure_output_destroy, secure_output_get_security};
void bind_secure_output(wl_client* client,
void* data,
uint32_t version,
uint32_t id) {
wl_resource* resource =
wl_resource_create(client, &zcr_secure_output_v1_interface, 1, id);
wl_resource_set_implementation(resource, &secure_output_implementation, data,
nullptr);
}
////////////////////////////////////////////////////////////////////////////////
// blending_interface:
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/exo/wayland/zcr_secure_output.h"
#include <secure-output-unstable-v1-server-protocol.h>
#include "components/exo/surface.h"
#include "components/exo/surface_observer.h"
#include "components/exo/wayland/server_util.h"
namespace exo {
namespace wayland {
namespace {
// A property key containing a boolean set to true if a security object is
// associated with surface object.
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSurfaceHasSecurityKey, false)
////////////////////////////////////////////////////////////////////////////////
// security_interface:
// Implements the security interface to a Surface. The "only visible on secure
// output"-state is set to false upon destruction. A window property will be set
// during the lifetime of this class to prevent multiple instances from being
// created for the same Surface.
class Security : public SurfaceObserver {
public:
explicit Security(Surface* surface) : surface_(surface) {
surface_->AddSurfaceObserver(this);
surface_->SetProperty(kSurfaceHasSecurityKey, true);
}
~Security() override {
if (surface_) {
surface_->RemoveSurfaceObserver(this);
surface_->SetOnlyVisibleOnSecureOutput(false);
surface_->SetProperty(kSurfaceHasSecurityKey, false);
}
}
void OnlyVisibleOnSecureOutput() {
if (surface_)
surface_->SetOnlyVisibleOnSecureOutput(true);
}
// Overridden from SurfaceObserver:
void OnSurfaceDestroying(Surface* surface) override {
surface->RemoveSurfaceObserver(this);
surface_ = nullptr;
}
private:
Surface* surface_;
DISALLOW_COPY_AND_ASSIGN(Security);
};
void security_destroy(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
void security_only_visible_on_secure_output(wl_client* client,
wl_resource* resource) {
GetUserDataAs<Security>(resource)->OnlyVisibleOnSecureOutput();
}
const struct zcr_security_v1_interface security_implementation = {
security_destroy, security_only_visible_on_secure_output};
////////////////////////////////////////////////////////////////////////////////
// secure_output_interface:
void secure_output_destroy(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
void secure_output_get_security(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* surface_resource) {
Surface* surface = GetUserDataAs<Surface>(surface_resource);
if (surface->GetProperty(kSurfaceHasSecurityKey)) {
wl_resource_post_error(resource, ZCR_SECURE_OUTPUT_V1_ERROR_SECURITY_EXISTS,
"a security object for that surface already exists");
return;
}
wl_resource* security_resource =
wl_resource_create(client, &zcr_security_v1_interface, 1, id);
SetImplementation(security_resource, &security_implementation,
std::make_unique<Security>(surface));
}
const struct zcr_secure_output_v1_interface secure_output_implementation = {
secure_output_destroy, secure_output_get_security};
} // namespace
void bind_secure_output(wl_client* client,
void* data,
uint32_t version,
uint32_t id) {
wl_resource* resource =
wl_resource_create(client, &zcr_secure_output_v1_interface, 1, id);
wl_resource_set_implementation(resource, &secure_output_implementation, data,
nullptr);
}
} // namespace wayland
} // namespace exo
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_EXO_WAYLAND_ZCR_SECURE_OUTPUT_H_
#define COMPONENTS_EXO_WAYLAND_ZCR_SECURE_OUTPUT_H_
#include <stdint.h>
struct wl_client;
namespace exo {
namespace wayland {
void bind_secure_output(wl_client* client,
void* data,
uint32_t version,
uint32_t id);
} // namespace wayland
} // namespace exo
#endif // COMPONENTS_EXO_WAYLAND_ZCR_SECURE_OUTPUT_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment