Commit 70e99e87 authored by xhwang's avatar xhwang Committed by Commit bot

Move PepperOutputProtectionMessageFilter::Delegate to OutputProtectionDelegate.

BUG=479843

Review URL: https://codereview.chromium.org/1139923006

Cr-Commit-Position: refs/heads/master@{#330485}
parent d2cfa088
// Copyright 2013 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 "chrome/browser/chromeos/display/output_protection_delegate.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "build/build_config.h"
#include "chrome/browser/media/media_capture_devices_dispatcher.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "ui/gfx/screen.h"
namespace chromeos {
namespace {
bool GetCurrentDisplayId(content::RenderFrameHost* rfh, int64* display_id) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
gfx::NativeView native_view = rfh->GetNativeView();
gfx::Screen* screen = gfx::Screen::GetScreenFor(native_view);
if (!screen)
return false;
gfx::Display display = screen->GetDisplayNearestWindow(native_view);
*display_id = display.id();
return true;
}
void DoNothing(bool status) {
}
} // namespace
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_(ui::DisplayConfigurator::kInvalidClientId),
display_id_(0),
weak_ptr_factory_(this) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
}
OutputProtectionDelegate::~OutputProtectionDelegate() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
ui::DisplayConfigurator* configurator =
ash::Shell::GetInstance()->display_configurator();
configurator->UnregisterContentProtectionClient(client_id_);
if (window_)
window_->RemoveObserver(this);
}
ui::DisplayConfigurator::ContentProtectionClientId
OutputProtectionDelegate::GetClientId() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (client_id_ == ui::DisplayConfigurator::kInvalidClientId) {
content::RenderFrameHost* rfh =
content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
if (!GetCurrentDisplayId(rfh, &display_id_))
return ui::DisplayConfigurator::kInvalidClientId;
window_ = rfh->GetNativeView();
if (!window_)
return ui::DisplayConfigurator::kInvalidClientId;
ui::DisplayConfigurator* configurator =
ash::Shell::GetInstance()->display_configurator();
client_id_ = configurator->RegisterContentProtectionClient();
if (client_id_ != ui::DisplayConfigurator::kInvalidClientId)
window_->AddObserver(this);
}
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.";
callback.Run(false, 0, 0);
return;
}
ui::DisplayConfigurator* configurator =
ash::Shell::GetInstance()->display_configurator();
configurator->QueryContentProtectionStatus(
GetClientId(), display_id_,
base::Bind(&OutputProtectionDelegate::QueryStatusComplete,
weak_ptr_factory_.GetWeakPtr(), callback));
}
void OutputProtectionDelegate::EnableProtection(
uint32_t desired_method_mask,
const EnableProtectionCallback& callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
ui::DisplayConfigurator* configurator =
ash::Shell::GetInstance()->display_configurator();
configurator->EnableContentProtection(
GetClientId(), display_id_, desired_method_mask,
base::Bind(&OutputProtectionDelegate::EnableProtectionComplete,
weak_ptr_factory_.GetWeakPtr(), callback));
desired_method_mask_ = desired_method_mask;
}
void OutputProtectionDelegate::QueryStatusComplete(
const QueryStatusCallback& callback,
const ui::DisplayConfigurator::QueryProtectionResponse& response) {
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.";
callback.Run(false, 0, 0);
return;
}
uint32_t link_mask = response.link_mask;
// If we successfully retrieved the device level status, check for capturers.
if (response.success) {
const bool capture_detected =
// Check for tab capture on the current tab.
content::WebContents::FromRenderFrameHost(rfh)->GetCapturerCount() >
0 ||
// Check for desktop capture.
MediaCaptureDevicesDispatcher::GetInstance()
->IsDesktopCaptureInProgress();
if (capture_detected)
link_mask |= ui::DISPLAY_CONNECTION_TYPE_NETWORK;
}
callback.Run(response.success, link_mask, response.protection_mask);
}
void OutputProtectionDelegate::EnableProtectionComplete(
const EnableProtectionCallback& callback,
bool success) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
callback.Run(success);
}
void OutputProtectionDelegate::OnWindowHierarchyChanged(
const aura::WindowObserver::HierarchyChangeParams& params) {
content::RenderFrameHost* rfh =
content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
if (!rfh) {
LOG(WARNING) << "RenderFrameHost is not alive.";
return;
}
int64 new_display_id = 0;
if (!GetCurrentDisplayId(rfh, &new_display_id))
return;
if (display_id_ == new_display_id)
return;
if (desired_method_mask_ != ui::CONTENT_PROTECTION_METHOD_NONE) {
// Display changed and should enable output protections on new display.
ui::DisplayConfigurator* configurator =
ash::Shell::GetInstance()->display_configurator();
configurator->EnableContentProtection(GetClientId(), new_display_id,
desired_method_mask_,
base::Bind(&DoNothing));
configurator->EnableContentProtection(GetClientId(), display_id_,
ui::CONTENT_PROTECTION_METHOD_NONE,
base::Bind(&DoNothing));
}
display_id_ = new_display_id;
}
void OutputProtectionDelegate::OnWindowDestroying(aura::Window* window) {
DCHECK_EQ(window, window_);
window_->RemoveObserver(this);
window_ = nullptr;
}
} // namespace chromeos
// Copyright 2013 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 CHROME_BROWSER_CHROMEOS_DISPLAY_OUTPUT_PROTECTION_DELEGATE_H_
#define CHROME_BROWSER_CHROMEOS_DISPLAY_OUTPUT_PROTECTION_DELEGATE_H_
#include "base/memory/weak_ptr.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/display/chromeos/display_configurator.h"
namespace chromeos {
// A class to query output protection status and/or enable output protection.
// All methods except constructor should be invoked in UI thread.
class OutputProtectionDelegate : public aura::WindowObserver {
public:
typedef base::Callback<void(bool /* success */,
uint32_t /* link_mask */,
uint32_t /* protection_mask*/)>
QueryStatusCallback;
typedef base::Callback<void(bool /* success */)> EnableProtectionCallback;
OutputProtectionDelegate(int render_process_id, int render_frame_id);
~OutputProtectionDelegate() override;
// aura::WindowObserver overrides.
void OnWindowHierarchyChanged(
const aura::WindowObserver::HierarchyChangeParams& params) override;
void OnWindowDestroying(aura::Window* window) override;
void QueryStatus(const QueryStatusCallback& callback);
void EnableProtection(uint32_t desired_method_mask,
const EnableProtectionCallback& callback);
private:
ui::DisplayConfigurator::ContentProtectionClientId GetClientId();
void QueryStatusComplete(
const QueryStatusCallback& callback,
const ui::DisplayConfigurator::QueryProtectionResponse& response);
void EnableProtectionComplete(const EnableProtectionCallback& callback,
bool success);
// Used to lookup the WebContents associated with the render frame.
int render_process_id_;
int render_frame_id_;
// Native window being observed.
aura::Window* window_;
ui::DisplayConfigurator::ContentProtectionClientId client_id_;
// The display id which the renderer currently uses.
int64 display_id_;
// The last desired method mask. Will enable this mask on new display if
// renderer changes display.
uint32_t desired_method_mask_;
base::WeakPtrFactory<OutputProtectionDelegate> weak_ptr_factory_;
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_DISPLAY_OUTPUT_PROTECTION_DELEGATE_H_
...@@ -19,6 +19,12 @@ struct HostMessageContext; ...@@ -19,6 +19,12 @@ struct HostMessageContext;
} // namespace host } // namespace host
} // namespace ppapi } // namespace ppapi
#if defined(OS_CHROMEOS)
namespace chromeos {
class OutputProtectionDelegate;
}
#endif
namespace chrome { namespace chrome {
class PepperOutputProtectionMessageFilter class PepperOutputProtectionMessageFilter
...@@ -28,10 +34,6 @@ class PepperOutputProtectionMessageFilter ...@@ -28,10 +34,6 @@ class PepperOutputProtectionMessageFilter
PP_Instance instance); PP_Instance instance);
private: private:
#if defined(OS_CHROMEOS)
class Delegate;
#endif
// ppapi::host::ResourceMessageFilter overrides. // ppapi::host::ResourceMessageFilter overrides.
scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage( scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage(
const IPC::Message& msg) override; const IPC::Message& msg) override;
...@@ -46,17 +48,17 @@ class PepperOutputProtectionMessageFilter ...@@ -46,17 +48,17 @@ class PepperOutputProtectionMessageFilter
uint32_t desired_method_mask); uint32_t desired_method_mask);
void OnQueryStatusComplete(ppapi::host::ReplyMessageContext reply_context, void OnQueryStatusComplete(ppapi::host::ReplyMessageContext reply_context,
int32_t result, bool success,
uint32_t link_mask, uint32_t link_mask,
uint32_t protection_mask); uint32_t protection_mask);
void OnEnableProtectionComplete( void OnEnableProtectionComplete(
ppapi::host::ReplyMessageContext reply_context, ppapi::host::ReplyMessageContext reply_context,
int32_t result); bool success);
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Delegator. Should be deleted in UI thread. // Delegate. Should be deleted in UI thread.
Delegate* delegate_; chromeos::OutputProtectionDelegate* delegate_;
#endif #endif
base::WeakPtrFactory<PepperOutputProtectionMessageFilter> weak_ptr_factory_; base::WeakPtrFactory<PepperOutputProtectionMessageFilter> weak_ptr_factory_;
......
...@@ -93,6 +93,8 @@ ...@@ -93,6 +93,8 @@
'browser/chromeos/display/display_configuration_observer.h', 'browser/chromeos/display/display_configuration_observer.h',
'browser/chromeos/display/display_preferences.cc', 'browser/chromeos/display/display_preferences.cc',
'browser/chromeos/display/display_preferences.h', 'browser/chromeos/display/display_preferences.h',
'browser/chromeos/display/output_protection_delegate.cc',
'browser/chromeos/display/output_protection_delegate.h',
'browser/chromeos/display/overscan_calibrator.cc', 'browser/chromeos/display/overscan_calibrator.cc',
'browser/chromeos/display/overscan_calibrator.h', 'browser/chromeos/display/overscan_calibrator.h',
'browser/chromeos/drive/change_list_loader.cc', 'browser/chromeos/drive/change_list_loader.cc',
......
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