Commit 08df566d authored by Tim Zheng's avatar Tim Zheng Committed by Commit Bot

Add a method to set startup ID in Aura shell.

A new method is added to the Aura shell interface. When client call this
method, the startup ID is set as a property on the Aura window.
This is going to be used to identify a specific virtual machine
applications that a window is for.

TEST: still compile.
Bug: 828147
Change-Id: If86547f4a58ca7793887acfdbb7f6eb0036bf761
Reviewed-on: https://chromium-review.googlesource.com/990791Reviewed-by: default avatarDavid Reveman <reveman@chromium.org>
Commit-Queue: David Reveman <reveman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547985}
parent 2ad6d1a8
......@@ -56,6 +56,9 @@ DEFINE_LOCAL_UI_CLASS_PROPERTY_KEY(Surface*, kMainSurfaceKey, nullptr)
// Application Id set by the client.
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(std::string, kApplicationIdKey, nullptr);
// Application Id set by the client.
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(std::string, kStartupIdKey, nullptr);
// The accelerator keys used to close ShellSurfaces.
const struct {
ui::KeyboardCode keycode;
......@@ -524,6 +527,25 @@ void ShellSurfaceBase::SetApplicationId(const std::string& application_id) {
SetApplicationId(widget_->GetNativeWindow(), application_id);
}
// static
void ShellSurfaceBase::SetStartupId(aura::Window* window,
const std::string& id) {
TRACE_EVENT1("exo", "ShellSurfaceBase::SetStartupId", "startup_id", id);
window->SetProperty(kStartupIdKey, new std::string(id));
}
// static
const std::string* ShellSurfaceBase::GetStartupId(aura::Window* window) {
return window->GetProperty(kStartupIdKey);
}
void ShellSurfaceBase::SetStartupId(const char* startup_id) {
// Store the value in |startup_id_| in case the window does not exist yet.
startup_id_ = std::string(startup_id);
if (widget_ && widget_->GetNativeWindow())
SetStartupId(widget_->GetNativeWindow(), startup_id);
}
void ShellSurfaceBase::Close() {
if (!close_callback_.is_null())
close_callback_.Run();
......@@ -610,6 +632,12 @@ ShellSurfaceBase::AsTracedValue() const {
if (application_id)
value->SetString("application_id", *application_id);
const std::string* startup_id =
GetStartupId(GetWidget()->GetNativeWindow());
if (startup_id)
value->SetString("startup_id", *startup_id);
}
return value;
}
......@@ -766,6 +794,10 @@ void ShellSurfaceBase::OnSetParent(Surface* parent,
}
}
void ShellSurfaceBase::OnSetStartupId(const char* startup_id) {
SetStartupId(startup_id);
}
////////////////////////////////////////////////////////////////////////////////
// SurfaceObserver overrides:
......@@ -1120,6 +1152,7 @@ void ShellSurfaceBase::CreateShellSurfaceWidget(
window->SetEventTargeter(base::WrapUnique(
new CustomWindowTargeter(widget_, client_controlled_move_resize_)));
SetApplicationId(window, application_id_);
SetStartupId(window, startup_id_);
SetMainSurface(window, root_surface());
// Start tracking changes to window bounds and window state.
......
......@@ -121,6 +121,14 @@ class ShellSurfaceBase : public SurfaceTreeHost,
// Set the application ID for the surface.
void SetApplicationId(const std::string& application_id);
// Sets the startup ID for the window. The startup ID identifies the
// application using startup notification protocol.
static void SetStartupId(aura::Window* window, const std::string& id);
static const std::string* GetStartupId(aura::Window* window);
// Set the startup ID for the surface.
void SetStartupId(const char* startup_id);
// Signal a request to close the window. It is up to the implementation to
// actually decide to do so though.
void Close();
......@@ -165,6 +173,7 @@ class ShellSurfaceBase : public SurfaceTreeHost,
void OnSetFrame(SurfaceFrameType type) override;
void OnSetFrameColors(SkColor active_color, SkColor inactive_color) override;
void OnSetParent(Surface* parent, const gfx::Point& position) override;
void OnSetStartupId(const char* startup_id) override;
// Overridden from SurfaceObserver:
void OnSurfaceDestroying(Surface* surface) override;
......@@ -338,6 +347,7 @@ class ShellSurfaceBase : public SurfaceTreeHost,
SkColor inactive_frame_color_ = SK_ColorBLACK;
bool pending_show_widget_ = false;
std::string application_id_;
std::string startup_id_;
gfx::Rect geometry_;
gfx::Rect pending_geometry_;
base::RepeatingClosure close_callback_;
......
......@@ -252,6 +252,24 @@ TEST_F(ShellSurfaceTest, SetApplicationId) {
EXPECT_EQ("test", *ShellSurface::GetApplicationId(window));
}
TEST_F(ShellSurfaceTest, SetStartupId) {
gfx::Size buffer_size(64, 64);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
EXPECT_FALSE(shell_surface->GetWidget());
shell_surface->SetStartupId("pre-widget-id");
surface->Attach(buffer.get());
surface->Commit();
aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
EXPECT_EQ("pre-widget-id", *ShellSurface::GetStartupId(window));
shell_surface->SetStartupId("test");
EXPECT_EQ("test", *ShellSurface::GetStartupId(window));
}
TEST_F(ShellSurfaceTest, Move) {
std::unique_ptr<Surface> surface(new Surface);
std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
......
......@@ -56,6 +56,7 @@ class SubSurface : public SurfaceDelegate, public SurfaceObserver {
void OnSetFrameColors(SkColor active_color, SkColor inactive_color) override {
}
void OnSetParent(Surface* parent, const gfx::Point& position) override {}
void OnSetStartupId(const char* startup_id) override {}
// Overridden from SurfaceObserver:
void OnSurfaceDestroying(Surface* surface) override;
......
......@@ -447,6 +447,13 @@ void Surface::SetFrameColors(SkColor active_color, SkColor inactive_color) {
delegate_->OnSetFrameColors(active_color, inactive_color);
}
void Surface::SetStartupId(const char* startup_id) {
TRACE_EVENT1("exo", "Surface::SetStartupId", "startup_id", startup_id);
if (delegate_)
delegate_->OnSetStartupId(startup_id);
}
void Surface::SetParent(Surface* parent, const gfx::Point& position) {
TRACE_EVENT2("exo", "Surface::SetParent", "parent", !!parent, "position",
position.ToString());
......
......@@ -145,6 +145,9 @@ class Surface final : public ui::PropertyHandler {
// Request that surface should use a specific set of frame colors.
void SetFrameColors(SkColor active_color, SkColor inactive_color);
// Request that surface should have a specific startup_id string.
void SetStartupId(const char* startup_id);
// Request "parent" for surface.
void SetParent(Surface* parent, const gfx::Point& position);
......
......@@ -38,6 +38,9 @@ class SurfaceDelegate {
// is the initial position of surface relative to origin of parent.
virtual void OnSetParent(Surface* parent, const gfx::Point& position) = 0;
// Called when surface was requested to set a specific startup ID label.
virtual void OnSetStartupId(const char* startup_id) = 0;
protected:
virtual ~SurfaceDelegate() {}
};
......
......@@ -91,6 +91,7 @@ class SurfaceTreeHost : public SurfaceDelegate,
void OnSetFrameColors(SkColor active_color, SkColor inactive_color) override {
}
void OnSetParent(Surface* parent, const gfx::Point& position) override {}
void OnSetStartupId(const char* startup_id) override {}
// Overridden from cc::BeginFrameObserverBase:
bool OnBeginFrameDerivedImpl(const viz::BeginFrameArgs& args) override;
......
......@@ -218,7 +218,7 @@ enum zaura_surface_frame_type {
#define ZAURA_SURFACE_SET_FRAME 0
#define ZAURA_SURFACE_SET_PARENT 1
#define ZAURA_SURFACE_SET_FRAME_COLORS 2
#define ZAURA_SURFACE_SET_STARTUP_ID 3
/**
* @ingroup iface_zaura_surface
......@@ -232,6 +232,10 @@ enum zaura_surface_frame_type {
* @ingroup iface_zaura_surface
*/
#define ZAURA_SURFACE_SET_FRAME_COLORS_SINCE_VERSION 3
/**
* @ingroup iface_zaura_surface
*/
#define ZAURA_SURFACE_SET_STARTUP_ID_SINCE_VERSION 4
/** @ingroup iface_zaura_surface */
static inline void
......@@ -297,6 +301,18 @@ zaura_surface_set_frame_colors(struct zaura_surface *zaura_surface, uint32_t act
ZAURA_SURFACE_SET_FRAME_COLORS, active_color, inactive_color);
}
/**
* @ingroup iface_zaura_surface
*
* Set the startup ID.
*/
static inline void zaura_surface_set_startup_id(
struct zaura_surface* zaura_surface,
const char* startup_id) {
wl_proxy_marshal((struct wl_proxy*)zaura_surface,
ZAURA_SURFACE_SET_STARTUP_ID, startup_id);
}
#ifndef ZAURA_OUTPUT_SCALE_PROPERTY_ENUM
#define ZAURA_OUTPUT_SCALE_PROPERTY_ENUM
/**
......
......@@ -50,7 +50,7 @@ static const struct wl_message zaura_shell_requests[] = {
};
WL_EXPORT const struct wl_interface zaura_shell_interface = {
"zaura_shell", 3,
"zaura_shell", 4,
2, zaura_shell_requests,
0, NULL,
};
......@@ -59,11 +59,12 @@ static const struct wl_message zaura_surface_requests[] = {
{ "set_frame", "u", types + 0 },
{ "set_parent", "2?oii", types + 6 },
{ "set_frame_colors", "3uu", types + 0 },
{ "set_startup_id", "4?s", types + 0 },
};
WL_EXPORT const struct wl_interface zaura_surface_interface = {
"zaura_surface", 3,
3, zaura_surface_requests,
"zaura_surface", 4,
4, zaura_surface_requests,
0, NULL,
};
......
......@@ -224,6 +224,15 @@ struct zaura_surface_interface {
struct wl_resource *resource,
uint32_t active_color,
uint32_t inactive_color);
/**
* set the startup ID of this surface
*
* Set the startup ID.
* @since 4
*/
void (*set_startup_id)(struct wl_client* client,
struct wl_resource* resource,
const char* startup_id);
};
......@@ -239,6 +248,10 @@ struct zaura_surface_interface {
* @ingroup iface_zaura_surface
*/
#define ZAURA_SURFACE_SET_FRAME_COLORS_SINCE_VERSION 3
/**
* @ingroup iface_zaura_surface
*/
#define ZAURA_SURFACE_SET_STARTUP_ID_SINCE_VERSION 4
#ifndef ZAURA_OUTPUT_SCALE_PROPERTY_ENUM
#define ZAURA_OUTPUT_SCALE_PROPERTY_ENUM
......
......@@ -24,7 +24,7 @@
DEALINGS IN THE SOFTWARE.
</copyright>
<interface name="zaura_shell" version="3">
<interface name="zaura_shell" version="4">
<description summary="aura_shell">
The global interface exposing aura shell capabilities is used to
instantiate an interface extension for a wl_surface object.
......@@ -68,7 +68,7 @@
</request>
</interface>
<interface name="zaura_surface" version="3">
<interface name="zaura_surface" version="4">
<description summary="aura shell interface to a wl_surface">
An additional interface to a wl_surface object, which allows the
client to access aura shell specific functionality for surface.
......@@ -111,6 +111,15 @@
<arg name="active_color" type="uint" summary="32 bit ARGB color value, not premultiplied"/>
<arg name="inactive_color" type="uint" summary="32 bit ARGB color value, not premultiplied"/>
</request>
<!-- Version 4 additions -->
<request name="set_startup_id" since="4">
<description summary="set the startup ID of this surface">
Set the startup ID.
</description>
<arg name="startup_id" type="string" allow-null="true"/>
</request>
</interface>
<interface name="zaura_output" version="2">
......
......@@ -2708,6 +2708,11 @@ class AuraSurface : public SurfaceObserver {
surface_->SetParent(parent ? parent->surface_ : nullptr, position);
}
void SetStartupId(const char* startup_id) {
if (surface_)
surface_->SetStartupId(startup_id);
}
// Overridden from SurfaceObserver:
void OnSurfaceDestroying(Surface* surface) override {
surface->RemoveSurfaceObserver(this);
......@@ -2757,9 +2762,15 @@ void aura_surface_set_frame_colors(wl_client* client,
inactive_color);
}
void aura_surface_set_startup_id(wl_client* client,
wl_resource* resource,
const char* startup_id) {
GetUserDataAs<AuraSurface>(resource)->SetStartupId(startup_id);
}
const struct zaura_surface_interface aura_surface_implementation = {
aura_surface_set_frame, aura_surface_set_parent,
aura_surface_set_frame_colors};
aura_surface_set_frame_colors, aura_surface_set_startup_id};
////////////////////////////////////////////////////////////////////////////////
// aura_output_interface:
......@@ -2850,7 +2861,7 @@ void aura_shell_get_aura_output(wl_client* client,
const struct zaura_shell_interface aura_shell_implementation = {
aura_shell_get_aura_surface, aura_shell_get_aura_output};
const uint32_t aura_shell_version = 3;
const uint32_t aura_shell_version = 4;
void bind_aura_shell(wl_client* client,
void* data,
......
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