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

Unified Diff: chrome/browser/renderer_host/pepper/pepper_output_protection_message_filter.cc

Issue 1009943006: [1/8] Prepare Pepper for async output protection configuration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renames Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/renderer_host/pepper/pepper_output_protection_message_filter.cc
diff --git a/chrome/browser/renderer_host/pepper/pepper_output_protection_message_filter.cc b/chrome/browser/renderer_host/pepper/pepper_output_protection_message_filter.cc
index ef8480b4e31b0eb4570093f7128b97b239a765ad..9af20a8c816a980ee87c0d4253b8d27d77f74480 100644
--- a/chrome/browser/renderer_host/pepper/pepper_output_protection_message_filter.cc
+++ b/chrome/browser/renderer_host/pepper/pepper_output_protection_message_filter.cc
@@ -75,6 +75,10 @@ bool GetCurrentDisplayId(content::RenderFrameHost* rfh, int64* display_id) {
*display_id = display.id();
return true;
}
+
+void DoNothing(bool status) {
+}
+
#endif
} // namespace
@@ -85,6 +89,12 @@ bool GetCurrentDisplayId(content::RenderFrameHost* rfh, int64* display_id) {
class PepperOutputProtectionMessageFilter::Delegate
: public aura::WindowObserver {
public:
+ typedef base::Callback<void(int32_t /* result */,
+ uint32_t /* link_mask */,
+ uint32_t /* protection_mask*/)>
+ QueryStatusCallback;
+ typedef base::Callback<void(int32_t /* result */)> EnableProtectionCallback;
+
Delegate(int render_process_id, int render_frame_id);
~Delegate() override;
@@ -93,12 +103,19 @@ class PepperOutputProtectionMessageFilter::Delegate
const aura::WindowObserver::HierarchyChangeParams& params) override;
void OnWindowDestroying(aura::Window* window) override;
- int32_t OnQueryStatus(uint32_t* link_mask, uint32_t* protection_mask);
- int32_t OnEnableProtection(uint32_t desired_method_mask);
+ 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 this PP_Instance.
int render_process_id_;
int render_frame_id_;
@@ -114,6 +131,9 @@ class PepperOutputProtectionMessageFilter::Delegate
// The last desired method mask. Will enable this mask on new display if
// renderer changes display.
uint32_t desired_method_mask_;
+
+ base::WeakPtrFactory<PepperOutputProtectionMessageFilter::Delegate>
+ weak_ptr_factory_;
};
PepperOutputProtectionMessageFilter::Delegate::Delegate(int render_process_id,
@@ -122,7 +142,8 @@ PepperOutputProtectionMessageFilter::Delegate::Delegate(int render_process_id,
render_frame_id_(render_frame_id),
window_(NULL),
client_id_(ui::DisplayConfigurator::kInvalidClientId),
- display_id_(0) {
+ display_id_(0),
+ weak_ptr_factory_(this) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
}
@@ -158,25 +179,56 @@ PepperOutputProtectionMessageFilter::Delegate::GetClientId() {
return client_id_;
}
-int32_t PepperOutputProtectionMessageFilter::Delegate::OnQueryStatus(
- uint32_t* link_mask,
- uint32_t* protection_mask) {
+void PepperOutputProtectionMessageFilter::Delegate::QueryStatus(
+ const QueryStatusCallback& callback) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
content::RenderFrameHost* rfh =
content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
if (!rfh) {
LOG(WARNING) << "RenderFrameHost is not alive.";
- return PP_ERROR_FAILED;
+ callback.Run(PP_ERROR_FAILED, 0, 0);
+ return;
}
ui::DisplayConfigurator* configurator =
ash::Shell::GetInstance()->display_configurator();
- bool result = configurator->QueryContentProtectionStatus(
- GetClientId(), display_id_, link_mask, protection_mask);
+ configurator->QueryContentProtectionStatus(
+ GetClientId(), display_id_,
+ base::Bind(
+ &PepperOutputProtectionMessageFilter::Delegate::QueryStatusComplete,
+ weak_ptr_factory_.GetWeakPtr(), callback));
+}
+
+void PepperOutputProtectionMessageFilter::Delegate::EnableProtection(
+ uint32_t desired_method_mask,
+ const EnableProtectionCallback& callback) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ ui::DisplayConfigurator* configurator =
+ ash::Shell::GetInstance()->display_configurator();
+ configurator->EnableContentProtection(
+ GetClientId(), display_id_, desired_method_mask,
+ base::Bind(&PepperOutputProtectionMessageFilter::Delegate::
+ EnableProtectionComplete,
+ weak_ptr_factory_.GetWeakPtr(), callback));
+ desired_method_mask_ = desired_method_mask;
+}
+
+void PepperOutputProtectionMessageFilter::Delegate::QueryStatusComplete(
+ const QueryStatusCallback& callback,
+ const ui::DisplayConfigurator::QueryProtectionResponse& response) {
+ content::RenderFrameHost* rfh =
+ content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
+ if (!rfh) {
+ LOG(WARNING) << "RenderFrameHost is not alive.";
+ callback.Run(PP_ERROR_FAILED, 0, 0);
+ return;
+ }
+ uint32_t link_mask = response.link_mask;
// If we successfully retrieved the device level status, check for capturers.
- if (result) {
+ if (response.success) {
const bool capture_detected =
// Check for tab capture on the current tab.
content::WebContents::FromRenderFrameHost(rfh)->GetCapturerCount() >
@@ -185,22 +237,17 @@ int32_t PepperOutputProtectionMessageFilter::Delegate::OnQueryStatus(
MediaCaptureDevicesDispatcher::GetInstance()
->IsDesktopCaptureInProgress();
if (capture_detected)
- *link_mask |= ui::DISPLAY_CONNECTION_TYPE_NETWORK;
+ link_mask |= ui::DISPLAY_CONNECTION_TYPE_NETWORK;
}
- return result ? PP_OK : PP_ERROR_FAILED;
+ callback.Run(response.success ? PP_OK : PP_ERROR_FAILED, link_mask,
+ response.protection_mask);
}
-int32_t PepperOutputProtectionMessageFilter::Delegate::OnEnableProtection(
- uint32_t desired_method_mask) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
-
- ui::DisplayConfigurator* configurator =
- ash::Shell::GetInstance()->display_configurator();
- bool result = configurator->EnableContentProtection(
- GetClientId(), display_id_, desired_method_mask);
- desired_method_mask_ = desired_method_mask;
- return result ? PP_OK : PP_ERROR_FAILED;
+void PepperOutputProtectionMessageFilter::Delegate::EnableProtectionComplete(
+ const EnableProtectionCallback& callback,
+ bool result) {
+ callback.Run(result ? PP_OK : PP_ERROR_FAILED);
}
void PepperOutputProtectionMessageFilter::Delegate::OnWindowHierarchyChanged(
@@ -222,10 +269,12 @@ void PepperOutputProtectionMessageFilter::Delegate::OnWindowHierarchyChanged(
// 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_);
- configurator->EnableContentProtection(
- GetClientId(), display_id_, ui::CONTENT_PROTECTION_METHOD_NONE);
+ 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;
}
@@ -240,7 +289,8 @@ void PepperOutputProtectionMessageFilter::Delegate::OnWindowDestroying(
PepperOutputProtectionMessageFilter::PepperOutputProtectionMessageFilter(
content::BrowserPpapiHost* host,
- PP_Instance instance) {
+ PP_Instance instance)
+ : weak_ptr_factory_(this) {
#if defined(OS_CHROMEOS)
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
int render_process_id = 0;
@@ -283,15 +333,11 @@ int32_t PepperOutputProtectionMessageFilter::OnResourceMessageReceived(
int32_t PepperOutputProtectionMessageFilter::OnQueryStatus(
ppapi::host::HostMessageContext* context) {
#if defined(OS_CHROMEOS)
- uint32_t link_mask = 0, protection_mask = 0;
- int32_t result = delegate_->OnQueryStatus(&link_mask, &protection_mask);
-
ppapi::host::ReplyMessageContext reply_context =
context->MakeReplyMessageContext();
- reply_context.params.set_result(result);
- SendReply(reply_context,
- PpapiPluginMsg_OutputProtection_QueryStatusReply(link_mask,
- protection_mask));
+ delegate_->QueryStatus(
+ base::Bind(&PepperOutputProtectionMessageFilter::OnQueryStatusComplete,
+ weak_ptr_factory_.GetWeakPtr(), reply_context));
return PP_OK_COMPLETIONPENDING;
#else
NOTIMPLEMENTED();
@@ -305,10 +351,11 @@ int32_t PepperOutputProtectionMessageFilter::OnEnableProtection(
#if defined(OS_CHROMEOS)
ppapi::host::ReplyMessageContext reply_context =
context->MakeReplyMessageContext();
- int32_t result = delegate_->OnEnableProtection(desired_method_mask);
- reply_context.params.set_result(result);
- SendReply(reply_context,
- PpapiPluginMsg_OutputProtection_EnableProtectionReply());
+ delegate_->EnableProtection(
+ desired_method_mask,
+ base::Bind(
+ &PepperOutputProtectionMessageFilter::OnEnableProtectionComplete,
+ weak_ptr_factory_.GetWeakPtr(), reply_context));
return PP_OK_COMPLETIONPENDING;
#else
NOTIMPLEMENTED();
@@ -316,4 +363,22 @@ int32_t PepperOutputProtectionMessageFilter::OnEnableProtection(
#endif
}
+void PepperOutputProtectionMessageFilter::OnQueryStatusComplete(
+ ppapi::host::ReplyMessageContext reply_context,
+ int32_t result,
+ uint32_t link_mask,
+ uint32_t protection_mask) {
+ reply_context.params.set_result(result);
+ SendReply(reply_context, PpapiPluginMsg_OutputProtection_QueryStatusReply(
+ link_mask, protection_mask));
+}
+
+void PepperOutputProtectionMessageFilter::OnEnableProtectionComplete(
+ ppapi::host::ReplyMessageContext reply_context,
+ int32_t result) {
+ reply_context.params.set_result(result);
+ SendReply(reply_context,
+ PpapiPluginMsg_OutputProtection_EnableProtectionReply());
+}
+
} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698