| Index: chrome/browser/chromeos/display/output_protection_delegate.cc
|
| diff --git a/chrome/browser/chromeos/display/output_protection_delegate.cc b/chrome/browser/chromeos/display/output_protection_delegate.cc
|
| index 1797d5ff37d3e3cf5d1986f2c0334bae724a2ebc..e5a9041745f78969026d1829028cd6e82b41bbab 100644
|
| --- a/chrome/browser/chromeos/display/output_protection_delegate.cc
|
| +++ b/chrome/browser/chromeos/display/output_protection_delegate.cc
|
| @@ -4,18 +4,23 @@
|
|
|
| #include "chrome/browser/chromeos/display/output_protection_delegate.h"
|
|
|
| -#include "ash/shell.h"
|
| -#include "build/build_config.h"
|
| +#include "chrome/browser/chromeos/display/output_protection_controller_ash.h"
|
| +#include "chrome/browser/chromeos/display/output_protection_controller_mus.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/render_frame_host.h"
|
| -#include "content/public/browser/web_contents.h"
|
| +#include "services/service_manager/runner/common/client_util.h"
|
| #include "ui/display/display.h"
|
| #include "ui/display/screen.h"
|
| +#include "ui/display/types/display_constants.h"
|
|
|
| namespace chromeos {
|
|
|
| namespace {
|
|
|
| +bool IsRunningInMash() {
|
| + return service_manager::ServiceManagerIsRemote();
|
| +}
|
| +
|
| bool GetCurrentDisplayId(content::RenderFrameHost* rfh, int64_t* display_id) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| DCHECK(rfh);
|
| @@ -35,111 +40,81 @@ void DoNothing(bool status) {
|
|
|
| } // namespace
|
|
|
| +OutputProtectionDelegate::Controller::Controller() {}
|
| +
|
| +OutputProtectionDelegate::Controller::~Controller() {}
|
| +
|
| OutputProtectionDelegate::OutputProtectionDelegate(int render_process_id,
|
| int render_frame_id)
|
| : render_process_id_(render_process_id),
|
| render_frame_id_(render_frame_id),
|
| window_(nullptr),
|
| - client_id_(display::DisplayConfigurator::kInvalidClientId),
|
| - display_id_(0),
|
| + display_id_(display::kInvalidDisplayId),
|
| weak_ptr_factory_(this) {
|
| // This can be constructed on IO or UI thread.
|
| }
|
|
|
| OutputProtectionDelegate::~OutputProtectionDelegate() {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| -
|
| - display::DisplayConfigurator* configurator =
|
| - ash::Shell::GetInstance()->display_configurator();
|
| - configurator->UnregisterContentProtectionClient(client_id_);
|
| -
|
| if (window_)
|
| window_->RemoveObserver(this);
|
| }
|
|
|
| -display::DisplayConfigurator::ContentProtectionClientId
|
| -OutputProtectionDelegate::GetClientId() {
|
| - DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| - if (client_id_ == display::DisplayConfigurator::kInvalidClientId) {
|
| - content::RenderFrameHost* rfh =
|
| - content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
|
| - if (!rfh || !GetCurrentDisplayId(rfh, &display_id_))
|
| - return display::DisplayConfigurator::kInvalidClientId;
|
| -
|
| - aura::Window* window = rfh->GetNativeView();
|
| - if (!window)
|
| - return display::DisplayConfigurator::kInvalidClientId;
|
| -
|
| - display::DisplayConfigurator* configurator =
|
| - ash::Shell::GetInstance()->display_configurator();
|
| - client_id_ = configurator->RegisterContentProtectionClient();
|
| -
|
| - if (client_id_ != display::DisplayConfigurator::kInvalidClientId) {
|
| - window->AddObserver(this);
|
| - window_ = window;
|
| - }
|
| - }
|
| - return client_id_;
|
| -}
|
| -
|
| void OutputProtectionDelegate::QueryStatus(
|
| const QueryStatusCallback& callback) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
| - content::RenderFrameHost* rfh =
|
| - content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
|
| - if (!rfh) {
|
| - LOG(WARNING) << "RenderFrameHost is not alive.";
|
| + if (!InitializeControllerIfNecessary()) {
|
| callback.Run(false, 0, 0);
|
| return;
|
| }
|
|
|
| - display::DisplayConfigurator* configurator =
|
| - ash::Shell::GetInstance()->display_configurator();
|
| - configurator->QueryContentProtectionStatus(
|
| - GetClientId(), display_id_,
|
| - base::Bind(&OutputProtectionDelegate::QueryStatusComplete,
|
| - weak_ptr_factory_.GetWeakPtr(), callback));
|
| + controller_->QueryStatus(display_id_, callback);
|
| }
|
|
|
| -void OutputProtectionDelegate::EnableProtection(
|
| +void OutputProtectionDelegate::SetProtection(
|
| uint32_t desired_method_mask,
|
| - const EnableProtectionCallback& callback) {
|
| + const SetProtectionCallback& callback) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
| - display::DisplayConfigurator* configurator =
|
| - ash::Shell::GetInstance()->display_configurator();
|
| - configurator->EnableContentProtection(
|
| - GetClientId(), display_id_, desired_method_mask,
|
| - base::Bind(&OutputProtectionDelegate::EnableProtectionComplete,
|
| - weak_ptr_factory_.GetWeakPtr(), callback));
|
| + if (!InitializeControllerIfNecessary()) {
|
| + callback.Run(false);
|
| + return;
|
| + }
|
| + controller_->SetProtection(display_id_, desired_method_mask, callback);
|
| desired_method_mask_ = desired_method_mask;
|
| }
|
|
|
| -void OutputProtectionDelegate::QueryStatusComplete(
|
| - const QueryStatusCallback& callback,
|
| - const display::DisplayConfigurator::QueryProtectionResponse& response) {
|
| +bool OutputProtectionDelegate::InitializeControllerIfNecessary() {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
| + if (controller_)
|
| + return true;
|
| +
|
| content::RenderFrameHost* rfh =
|
| content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
|
| - // TODO(xjz): Investigate whether this check (and the other one above) should
|
| - // be removed.
|
| if (!rfh) {
|
| - LOG(WARNING) << "RenderFrameHost is not alive.";
|
| - callback.Run(false, 0, 0);
|
| - return;
|
| + DLOG(WARNING) << "RenderFrameHost is not alive.";
|
| + return false;
|
| }
|
|
|
| - callback.Run(response.success, response.link_mask, response.protection_mask);
|
| -}
|
| + int64_t display_id = display::kInvalidDisplayId;
|
| + if (!GetCurrentDisplayId(rfh, &display_id))
|
| + return false;
|
|
|
| -void OutputProtectionDelegate::EnableProtectionComplete(
|
| - const EnableProtectionCallback& callback,
|
| - bool success) {
|
| - DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + aura::Window* window = rfh->GetNativeView();
|
| + if (!window)
|
| + return false;
|
|
|
| - callback.Run(success);
|
| + if (IsRunningInMash())
|
| + controller_ = base::MakeUnique<OutputProtectionControllerMus>();
|
| + else
|
| + controller_ = base::MakeUnique<OutputProtectionControllerAsh>();
|
| +
|
| + display_id_ = display_id;
|
| + window_ = window;
|
| + window_->AddObserver(this);
|
| + return true;
|
| }
|
|
|
| void OutputProtectionDelegate::OnWindowHierarchyChanged(
|
| @@ -147,26 +122,24 @@ void OutputProtectionDelegate::OnWindowHierarchyChanged(
|
| content::RenderFrameHost* rfh =
|
| content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
|
| if (!rfh) {
|
| - LOG(WARNING) << "RenderFrameHost is not alive.";
|
| + DLOG(WARNING) << "RenderFrameHost is not alive.";
|
| return;
|
| }
|
|
|
| - int64_t new_display_id = 0;
|
| + int64_t new_display_id = display::kInvalidDisplayId;
|
| if (!GetCurrentDisplayId(rfh, &new_display_id))
|
| return;
|
| +
|
| if (display_id_ == new_display_id)
|
| return;
|
|
|
| if (desired_method_mask_ != display::CONTENT_PROTECTION_METHOD_NONE) {
|
| - // Display changed and should enable output protections on new display.
|
| - display::DisplayConfigurator* configurator =
|
| - ash::Shell::GetInstance()->display_configurator();
|
| - configurator->EnableContentProtection(GetClientId(), new_display_id,
|
| - desired_method_mask_,
|
| - base::Bind(&DoNothing));
|
| - configurator->EnableContentProtection(
|
| - GetClientId(), display_id_, display::CONTENT_PROTECTION_METHOD_NONE,
|
| - base::Bind(&DoNothing));
|
| + DCHECK(controller_);
|
| + controller_->SetProtection(new_display_id, desired_method_mask_,
|
| + base::Bind(&DoNothing));
|
| + controller_->SetProtection(display_id_,
|
| + display::CONTENT_PROTECTION_METHOD_NONE,
|
| + base::Bind(&DoNothing));
|
| }
|
| display_id_ = new_display_id;
|
| }
|
|
|