Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Side by Side Diff: components/exo/wayland/server.cc

Issue 1802993003: exo: Add support for secure_output interface to wayland bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wayland-protocols-secure-contents
Patch Set: rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/exo/wayland/server.h" 5 #include "components/exo/wayland/server.h"
6 6
7 #include <grp.h> 7 #include <grp.h>
8 #include <linux/input.h> 8 #include <linux/input.h>
9 #include <scaler-server-protocol.h> 9 #include <scaler-server-protocol.h>
10 #include <secure-output-unstable-v1-server-protocol.h>
10 #include <stddef.h> 11 #include <stddef.h>
11 #include <stdint.h> 12 #include <stdint.h>
12 #include <wayland-server-core.h> 13 #include <wayland-server-core.h>
13 #include <wayland-server-protocol-core.h> 14 #include <wayland-server-protocol-core.h>
14 #include <xdg-shell-unstable-v5-server-protocol.h> 15 #include <xdg-shell-unstable-v5-server-protocol.h>
15 16
16 #include <algorithm> 17 #include <algorithm>
17 #include <iterator> 18 #include <iterator>
18 #include <string> 19 #include <string>
19 #include <utility> 20 #include <utility>
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 97 }
97 98
98 // A property key containing the surface resource that is associated with 99 // A property key containing the surface resource that is associated with
99 // window. If unset, no surface resource is associated with window. 100 // window. If unset, no surface resource is associated with window.
100 DEFINE_WINDOW_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); 101 DEFINE_WINDOW_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr);
101 102
102 // A property key containing a boolean set to true if a viewport is associated 103 // A property key containing a boolean set to true if a viewport is associated
103 // with window. 104 // with window.
104 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); 105 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false);
105 106
107 // A property key containing a boolean set to true if a security object is
108 // associated with window.
109 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasSecurityKey, false);
110
106 //////////////////////////////////////////////////////////////////////////////// 111 ////////////////////////////////////////////////////////////////////////////////
107 // wl_buffer_interface: 112 // wl_buffer_interface:
108 113
109 void buffer_destroy(wl_client* client, wl_resource* resource) { 114 void buffer_destroy(wl_client* client, wl_resource* resource) {
110 wl_resource_destroy(resource); 115 wl_resource_destroy(resource);
111 } 116 }
112 117
113 const struct wl_buffer_interface buffer_implementation = {buffer_destroy}; 118 const struct wl_buffer_interface buffer_implementation = {buffer_destroy};
114 119
115 void HandleBufferReleaseCallback(wl_resource* resource) { 120 void HandleBufferReleaseCallback(wl_resource* resource) {
(...skipping 1751 matching lines...) Expand 10 before | Expand all | Expand 10 after
1867 uint32_t id, 1872 uint32_t id,
1868 wl_resource* surface_resource) { 1873 wl_resource* surface_resource) {
1869 Surface* surface = GetUserDataAs<Surface>(surface_resource); 1874 Surface* surface = GetUserDataAs<Surface>(surface_resource);
1870 if (surface->GetProperty(kSurfaceHasViewportKey)) { 1875 if (surface->GetProperty(kSurfaceHasViewportKey)) {
1871 wl_resource_post_error(resource, WL_SCALER_ERROR_VIEWPORT_EXISTS, 1876 wl_resource_post_error(resource, WL_SCALER_ERROR_VIEWPORT_EXISTS,
1872 "a viewport for that surface already exists"); 1877 "a viewport for that surface already exists");
1873 return; 1878 return;
1874 } 1879 }
1875 1880
1876 wl_resource* viewport_resource = wl_resource_create( 1881 wl_resource* viewport_resource = wl_resource_create(
1877 client, &wl_viewport_interface, wl_resource_get_version(resource), id); 1882 client, &wl_viewport_interface, wl_resource_get_version(resource), id);
Daniele Castagna 2016/03/16 22:28:07 Maybe mention this minor change in the description
reveman 2016/03/17 16:36:32 Done.
1878 if (!viewport_resource) {
1879 wl_resource_post_no_memory(resource);
1880 return;
1881 }
1882 1883
1883 SetImplementation(viewport_resource, &viewport_implementation, 1884 SetImplementation(viewport_resource, &viewport_implementation,
1884 make_scoped_ptr(new Viewport(surface))); 1885 make_scoped_ptr(new Viewport(surface)));
1885 } 1886 }
1886 1887
1887 const struct wl_scaler_interface scaler_implementation = {scaler_destroy, 1888 const struct wl_scaler_interface scaler_implementation = {scaler_destroy,
1888 scaler_get_viewport}; 1889 scaler_get_viewport};
1889 1890
1890 const uint32_t scaler_version = 2; 1891 const uint32_t scaler_version = 2;
1891 1892
1892 void bind_scaler(wl_client* client, void* data, uint32_t version, uint32_t id) { 1893 void bind_scaler(wl_client* client, void* data, uint32_t version, uint32_t id) {
1893 wl_resource* resource = wl_resource_create( 1894 wl_resource* resource = wl_resource_create(
1894 client, &wl_scaler_interface, std::min(version, scaler_version), id); 1895 client, &wl_scaler_interface, std::min(version, scaler_version), id);
1895 if (!resource) { 1896
1896 wl_client_post_no_memory(client);
1897 return;
1898 }
1899 wl_resource_set_implementation(resource, &scaler_implementation, data, 1897 wl_resource_set_implementation(resource, &scaler_implementation, data,
1900 nullptr); 1898 nullptr);
1901 } 1899 }
1902 1900
1901 ////////////////////////////////////////////////////////////////////////////////
1902 // security_interface:
1903
1904 class Security : public SurfaceObserver {
1905 public:
1906 explicit Security(Surface* surface) : surface_(surface) {
1907 surface_->AddSurfaceObserver(this);
1908 surface_->SetProperty(kSurfaceHasSecurityKey, true);
1909 }
1910 ~Security() override {
1911 if (surface_) {
1912 surface_->RemoveSurfaceObserver(this);
1913 surface_->SetOnlyVisibleOnSecureOutput(false);
1914 surface_->SetProperty(kSurfaceHasSecurityKey, false);
1915 }
1916 }
1917
1918 void OnlyVisibleOnSecureOutput() {
1919 if (surface_)
1920 surface_->SetOnlyVisibleOnSecureOutput(true);
1921 }
1922
1923 // Overridden from SurfaceObserver:
1924 void OnSurfaceDestroying(Surface* surface) override {
1925 surface->RemoveSurfaceObserver(this);
1926 surface_ = nullptr;
1927 }
1928
1929 private:
1930 Surface* surface_;
1931
1932 DISALLOW_COPY_AND_ASSIGN(Security);
1933 };
1934
1935 void security_destroy(wl_client* client, wl_resource* resource) {
1936 wl_resource_destroy(resource);
1937 }
1938
1939 void security_only_visible_on_secure_output(wl_client* client,
1940 wl_resource* resource) {
1941 GetUserDataAs<Security>(resource)->OnlyVisibleOnSecureOutput();
1942 }
1943
1944 const struct zwp_security_v1_interface security_implementation = {
1945 security_destroy, security_only_visible_on_secure_output};
1946
1947 ////////////////////////////////////////////////////////////////////////////////
1948 // secure_output_interface:
1949
1950 void secure_output_destroy(wl_client* client, wl_resource* resource) {
1951 wl_resource_destroy(resource);
1952 }
1953
1954 void secure_output_get_security(wl_client* client,
1955 wl_resource* resource,
1956 uint32_t id,
1957 wl_resource* surface_resource) {
1958 Surface* surface = GetUserDataAs<Surface>(surface_resource);
1959 if (surface->GetProperty(kSurfaceHasSecurityKey)) {
1960 wl_resource_post_error(resource, ZWP_SECURE_OUTPUT_V1_ERROR_SECURITY_EXISTS,
1961 "a security object for that surface already exists");
1962 return;
1963 }
1964
1965 wl_resource* security_resource =
1966 wl_resource_create(client, &zwp_security_v1_interface, 1, id);
1967
1968 SetImplementation(security_resource, &security_implementation,
1969 make_scoped_ptr(new Security(surface)));
1970 }
1971
1972 const struct zwp_secure_output_v1_interface secure_output_implementation = {
1973 secure_output_destroy, secure_output_get_security};
1974
1975 void bind_secure_output(wl_client* client,
1976 void* data,
1977 uint32_t version,
1978 uint32_t id) {
1979 wl_resource* resource =
1980 wl_resource_create(client, &zwp_secure_output_v1_interface, 1, id);
1981
1982 wl_resource_set_implementation(resource, &secure_output_implementation, data,
1983 nullptr);
1984 }
1985
1903 } // namespace 1986 } // namespace
1904 1987
1905 //////////////////////////////////////////////////////////////////////////////// 1988 ////////////////////////////////////////////////////////////////////////////////
1906 // Server, public: 1989 // Server, public:
1907 1990
1908 Server::Server(Display* display) 1991 Server::Server(Display* display)
1909 : display_(display), wl_display_(wl_display_create()) { 1992 : display_(display), wl_display_(wl_display_create()) {
1910 wl_global_create(wl_display_.get(), &wl_compositor_interface, 1993 wl_global_create(wl_display_.get(), &wl_compositor_interface,
1911 compositor_version, display_, bind_compositor); 1994 compositor_version, display_, bind_compositor);
1912 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); 1995 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm);
(...skipping 10 matching lines...) Expand all
1923 wl_global_create(wl_display_.get(), &wl_output_interface, output_version, 2006 wl_global_create(wl_display_.get(), &wl_output_interface, output_version,
1924 display_, bind_output); 2007 display_, bind_output);
1925 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_, 2008 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_,
1926 bind_xdg_shell); 2009 bind_xdg_shell);
1927 wl_global_create(wl_display_.get(), &wl_data_device_manager_interface, 1, 2010 wl_global_create(wl_display_.get(), &wl_data_device_manager_interface, 1,
1928 display_, bind_data_device_manager); 2011 display_, bind_data_device_manager);
1929 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, 2012 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version,
1930 display_, bind_seat); 2013 display_, bind_seat);
1931 wl_global_create(wl_display_.get(), &wl_scaler_interface, scaler_version, 2014 wl_global_create(wl_display_.get(), &wl_scaler_interface, scaler_version,
1932 display_, bind_scaler); 2015 display_, bind_scaler);
2016 wl_global_create(wl_display_.get(), &zwp_secure_output_v1_interface, 1,
2017 display_, bind_secure_output);
1933 } 2018 }
1934 2019
1935 Server::~Server() {} 2020 Server::~Server() {}
1936 2021
1937 // static 2022 // static
1938 scoped_ptr<Server> Server::Create(Display* display) { 2023 scoped_ptr<Server> Server::Create(Display* display) {
1939 scoped_ptr<Server> server(new Server(display)); 2024 scoped_ptr<Server> server(new Server(display));
1940 2025
1941 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); 2026 char* runtime_dir = getenv("XDG_RUNTIME_DIR");
1942 if (!runtime_dir) { 2027 if (!runtime_dir) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1994 DCHECK(event_loop); 2079 DCHECK(event_loop);
1995 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 2080 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
1996 } 2081 }
1997 2082
1998 void Server::Flush() { 2083 void Server::Flush() {
1999 wl_display_flush_clients(wl_display_.get()); 2084 wl_display_flush_clients(wl_display_.get());
2000 } 2085 }
2001 2086
2002 } // namespace wayland 2087 } // namespace wayland
2003 } // namespace exo 2088 } // namespace exo
OLDNEW
« components/exo/surface_unittest.cc ('K') | « components/exo/wayland/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698