Commit f5f14121 authored by Dominik Laskowski's avatar Dominik Laskowski Committed by Commit Bot

display: Validate content protection requests

DisplayConfigurator clients are responsible for renewing their content
protection requests when the display configuration changes, as pending
tasks will be killed on reconfiguration in a future CL.

This CL invokes the failure callback for requests whose display is
invalid.

Bug: 929449
Test: display_unittests
Change-Id: I74d247b8532a7072d7852903d1ce4c4e5006f1c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1554004
Commit-Queue: Dominik Laskowski <domlaskowski@chromium.org>
Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649276}
parent a19b0cb8
......@@ -4,7 +4,8 @@
#include "ui/display/manager/display_configurator.h"
#include <stddef.h>
#include <algorithm>
#include <cstddef>
#include <utility>
#include "base/bind.h"
......@@ -791,22 +792,15 @@ void DisplayConfigurator::QueryContentProtection(
ContentProtectionClientId client_id,
int64_t display_id,
QueryContentProtectionCallback callback) {
if (!client_id || configurator_disabled()) {
std::move(callback).Run(/*success=*/false, DISPLAY_CONNECTION_TYPE_NONE,
CONTENT_PROTECTION_METHOD_NONE);
return;
}
// Exclude virtual displays so that protected content will not be recaptured
// through the cast stream.
for (const DisplaySnapshot* display : cached_displays_) {
if (display->display_id() == display_id &&
const DisplaySnapshot* display = GetDisplay(display_id);
if (configurator_disabled() || !display ||
!IsPhysicalDisplayType(display->type())) {
std::move(callback).Run(/*success=*/false, DISPLAY_CONNECTION_TYPE_NONE,
CONTENT_PROTECTION_METHOD_NONE);
return;
}
}
QueueContentProtectionTask(new QueryContentProtectionTask(
layout_manager_.get(), native_display_delegate_.get(), display_id,
......@@ -848,7 +842,7 @@ void DisplayConfigurator::ApplyContentProtection(
int64_t display_id,
uint32_t protection_mask,
ApplyContentProtectionCallback callback) {
if (!client_id || configurator_disabled()) {
if (configurator_disabled() || !client_id || !GetDisplay(display_id)) {
std::move(callback).Run(/*success=*/false);
return;
}
......@@ -949,6 +943,15 @@ void DisplayConfigurator::PrepareForExit() {
configure_display_ = false;
}
const DisplaySnapshot* DisplayConfigurator::GetDisplay(
int64_t display_id) const {
auto it = std::find_if(cached_displays_.begin(), cached_displays_.end(),
[display_id](const DisplaySnapshot* display) {
return display->display_id() == display_id;
});
return it == cached_displays_.end() ? nullptr : *it;
}
void DisplayConfigurator::SetDisplayPowerInternal(
chromeos::DisplayPowerState power_state,
int flags,
......
......@@ -317,6 +317,8 @@ class DISPLAY_MANAGER_EXPORT DisplayConfigurator
return !configure_display_ || display_externally_controlled_;
}
const DisplaySnapshot* GetDisplay(int64_t display_id) const;
// Updates |pending_*| members and applies the passed-in state. |callback| is
// invoked (perhaps synchronously) on completion.
void SetDisplayPowerInternal(chromeos::DisplayPowerState power_state,
......
......@@ -987,6 +987,27 @@ TEST_F(DisplayConfiguratorTest, ContentProtection) {
query_content_protection_protection_mask_);
EXPECT_EQ(kNoActions, log_->GetActionsAndClear());
// Requests on invalid display should fail.
constexpr int64_t kInvalidDisplayId = -999;
configurator_.QueryContentProtection(
id, kInvalidDisplayId,
base::BindOnce(&DisplayConfiguratorTest::QueryContentProtectionCallback,
base::Unretained(this)));
configurator_.ApplyContentProtection(
id, kInvalidDisplayId, CONTENT_PROTECTION_METHOD_HDCP,
base::BindOnce(&DisplayConfiguratorTest::ApplyContentProtectionCallback,
base::Unretained(this)));
EXPECT_EQ(4, query_content_protection_call_count_);
EXPECT_FALSE(query_content_protection_success_);
EXPECT_EQ(static_cast<uint32_t>(DISPLAY_CONNECTION_TYPE_NONE),
query_content_protection_connection_mask_);
EXPECT_EQ(static_cast<uint32_t>(CONTENT_PROTECTION_METHOD_NONE),
query_content_protection_protection_mask_);
EXPECT_EQ(2, apply_content_protection_call_count_);
EXPECT_FALSE(apply_content_protection_success_);
// Protections should be disabled after unregister.
configurator_.UnregisterContentProtectionClient(id);
EXPECT_EQ(GetSetHDCPStateAction(*outputs_[1], HDCP_STATE_UNDESIRED),
......
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