Chromium Code Reviews| Index: chrome/browser/renderer_host/pepper/pepper_talk_host.cc |
| diff --git a/chrome/browser/renderer_host/pepper/pepper_talk_host.cc b/chrome/browser/renderer_host/pepper/pepper_talk_host.cc |
| index 5251578ca0a67723920c7df591c78265d29202d9..a1ab2113c6ce3b7f9bebcca9a83270563d4f3f07 100644 |
| --- a/chrome/browser/renderer_host/pepper/pepper_talk_host.cc |
| +++ b/chrome/browser/renderer_host/pepper/pepper_talk_host.cc |
| @@ -19,6 +19,7 @@ |
| #if defined(USE_ASH) |
| #include "ash/shell.h" |
| #include "ash/shell_window_ids.h" |
| +#include "ash/system/tray/system_tray_notifier.h" |
| #include "chrome/browser/ui/simple_message_box.h" |
| #include "ui/aura/window.h" |
| #endif |
| @@ -28,6 +29,7 @@ namespace chrome { |
| namespace { |
| ppapi::host::ReplyMessageContext GetPermissionOnUIThread( |
| + PP_TalkPermission permission, |
| int render_process_id, |
| int render_view_id, |
| ppapi::host::ReplyMessageContext reply) { |
| @@ -40,13 +42,33 @@ ppapi::host::ReplyMessageContext GetPermissionOnUIThread( |
| return reply; // RVH destroyed while task was pending. |
| #if defined(USE_ASH) |
| + |
| + string16 title; |
| + string16 message; |
| + |
| + switch (permission) { |
| + case PP_TALKPERMISSION_SCREENCAST: |
| + title = l10n_util::GetStringUTF16(IDS_GTALK_SCREEN_SHARE_DIALOG_TITLE); |
| + message = l10n_util::GetStringUTF16( |
| + IDS_GTALK_SCREEN_SHARE_DIALOG_MESSAGE); |
| + break; |
| + case PP_TALKPERMISSION_REMOTING: |
| + title = l10n_util::GetStringUTF16(IDS_GTALK_REMOTING_DIALOG_TITLE); |
| + message = l10n_util::GetStringUTF16( |
| + IDS_GTALK_REMOTING_DIALOG_MESSAGE); |
| + break; |
| + case PP_TALKPERMISSION_REMOTING_CONTINUE: |
| + title = l10n_util::GetStringUTF16(IDS_GTALK_REMOTING_DIALOG_TITLE); |
| + message = l10n_util::GetStringUTF16( |
| + IDS_GTALK_REMOTING_CONTINUE_DIALOG_MESSAGE); |
| + break; |
| + default: |
| + NOTREACHED(); |
| + return reply; |
| + } |
| + |
| // TODO(brettw). We should not be grabbing the active toplevel window, we |
| // should use the toplevel window associated with the render view. |
| - const string16 title = l10n_util::GetStringUTF16( |
| - IDS_GTALK_SCREEN_SHARE_DIALOG_TITLE); |
| - const string16 message = l10n_util::GetStringUTF16( |
| - IDS_GTALK_SCREEN_SHARE_DIALOG_MESSAGE); |
| - |
| aura::Window* parent = ash::Shell::GetContainer( |
| ash::Shell::GetActiveRootWindow(), |
| ash::internal::kShellWindowId_SystemModalContainer); |
| @@ -60,6 +82,53 @@ ppapi::host::ReplyMessageContext GetPermissionOnUIThread( |
| return reply; |
| } |
| +void OnTerminateRemotingEventOnUIThread(const base::Closure& stop_callback) { |
| + content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
| + stop_callback); |
| +} |
| + |
| +ppapi::host::ReplyMessageContext StartRemotingOnUIThread( |
| + const base::Closure& stop_callback, |
| + int render_process_id, |
| + int render_view_id, |
| + ppapi::host::ReplyMessageContext reply) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + reply.params.set_result(0); |
| + |
| + content::RenderViewHost* render_view_host = |
| + content::RenderViewHost::FromID(render_process_id, render_view_id); |
| + if (!render_view_host) |
| + return reply; // RVH destroyed while task was pending. |
| + |
| +#if defined(USE_ASH) |
| + base::Closure stop_callback_ui_thread = base::Bind( |
| + &OnTerminateRemotingEventOnUIThread, |
| + stop_callback); |
| + |
| + ash::Shell::GetInstance()->system_tray_notifier()->NotifyScreenShareStart( |
| + stop_callback_ui_thread, base::string16()); |
| +#else |
| + NOTIMPLEMENTED(); |
| +#endif |
| + return reply; |
| +} |
| + |
| +void StopRemotingOnUIThread() { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| +#if defined(USE_ASH) |
| + ash::Shell::GetInstance()->system_tray_notifier()->NotifyScreenShareStop(); |
| +#else |
| + NOTIMPLEMENTED(); |
| +#endif |
| +} |
| + |
| +ppapi::host::ReplyMessageContext StopRemotingOnUIThreadWithResult( |
| + ppapi::host::ReplyMessageContext reply) { |
| + reply.params.set_result(0); |
| + StopRemotingOnUIThread(); |
| + return reply; |
| +} |
| + |
| } // namespace |
| PepperTalkHost::PepperTalkHost(content::BrowserPpapiHost* host, |
| @@ -67,10 +136,16 @@ PepperTalkHost::PepperTalkHost(content::BrowserPpapiHost* host, |
| PP_Resource resource) |
| : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource), |
| weak_factory_(this), |
| - browser_ppapi_host_(host) { |
| + browser_ppapi_host_(host), |
| + remoting_started_(false) { |
| } |
| PepperTalkHost::~PepperTalkHost() { |
| + if (remoting_started_) { |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::UI, FROM_HERE, |
| + base::Bind(&StopRemotingOnUIThread)); |
|
Josh Horwich
2013/06/17 19:36:05
Doesn't the fact that we're posting a task to a di
dcaiafa
2013/06/17 20:34:25
StopRemotingOnUIThread is a function, not a method
Josh Horwich
2013/06/17 20:56:43
Ah, sorry, my mistake. That certainly addresses my
|
| + } |
| } |
| int32_t PepperTalkHost::OnResourceMessageReceived( |
| @@ -90,8 +165,7 @@ int32_t PepperTalkHost::OnResourceMessageReceived( |
| int32_t PepperTalkHost::OnRequestPermission( |
| ppapi::host::HostMessageContext* context, |
| PP_TalkPermission permission) { |
| - // TODO(dcaiafa): Implement support for other permission types. |
| - if (permission != PP_TALKPERMISSION_SCREENCAST) |
| + if (permission < 0 || permission >= PP_TALKPERMISSION_NUM_PERMISSIONS) |
|
Josh Horwich
2013/06/17 19:36:05
Should this be 'if (permission < PP_TALKPERMISSION
dcaiafa
2013/06/17 20:34:25
Done.
|
| return PP_ERROR_BADARGUMENT; |
| int render_process_id = 0; |
| @@ -101,14 +175,14 @@ int32_t PepperTalkHost::OnRequestPermission( |
| content::BrowserThread::PostTaskAndReplyWithResult( |
| content::BrowserThread::UI, FROM_HERE, |
| - base::Bind(&GetPermissionOnUIThread, render_process_id, render_view_id, |
| - context->MakeReplyMessageContext()), |
| - base::Bind(&PepperTalkHost::GotTalkPermission, |
| + base::Bind(&GetPermissionOnUIThread, permission, render_process_id, |
| + render_view_id, context->MakeReplyMessageContext()), |
| + base::Bind(&PepperTalkHost::OnRequestPermissionCompleted, |
| weak_factory_.GetWeakPtr())); |
| return PP_OK_COMPLETIONPENDING; |
| } |
| -void PepperTalkHost::GotTalkPermission( |
| +void PepperTalkHost::OnRequestPermissionCompleted( |
| ppapi::host::ReplyMessageContext reply) { |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| host()->SendReply(reply, PpapiPluginMsg_Talk_RequestPermissionReply()); |
| @@ -116,16 +190,58 @@ void PepperTalkHost::GotTalkPermission( |
| int32_t PepperTalkHost::OnStartRemoting( |
| ppapi::host::HostMessageContext* context) { |
| - // TODO(dcaiafa): Request IPC audit when this is implemented |
| - NOTIMPLEMENTED(); |
| - return PP_ERROR_FAILED; |
| + int render_process_id = 0; |
| + int render_view_id = 0; |
| + browser_ppapi_host_->GetRenderViewIDsForInstance( |
| + pp_instance(), &render_process_id, &render_view_id); |
| + |
| + base::Closure remoting_stop_callback = base::Bind( |
| + &PepperTalkHost::OnRemotingStopEvent, |
| + weak_factory_.GetWeakPtr()); |
| + |
| + content::BrowserThread::PostTaskAndReplyWithResult( |
| + content::BrowserThread::UI, FROM_HERE, |
| + base::Bind(&StartRemotingOnUIThread, remoting_stop_callback, |
| + render_process_id, render_view_id, |
| + context->MakeReplyMessageContext()), |
| + base::Bind(&PepperTalkHost::OnStartRemotingCompleted, |
| + weak_factory_.GetWeakPtr())); |
| + return PP_OK_COMPLETIONPENDING; |
| +} |
| + |
| +void PepperTalkHost::OnStartRemotingCompleted( |
| + ppapi::host::ReplyMessageContext reply) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| + if (reply.params.result() == PP_OK) { |
| + // Remember to hide remoting UI when resource is deleted. |
| + remoting_started_ = true; |
| + } |
| + host()->SendReply(reply, PpapiPluginMsg_Talk_StartRemotingReply()); |
| } |
| int32_t PepperTalkHost::OnStopRemoting( |
| ppapi::host::HostMessageContext* context) { |
| - // TODO(dcaiafa): Request IPC audit when this is implemented |
| - NOTIMPLEMENTED(); |
| - return PP_ERROR_FAILED; |
| + content::BrowserThread::PostTaskAndReplyWithResult( |
| + content::BrowserThread::UI, FROM_HERE, |
| + base::Bind(&StopRemotingOnUIThreadWithResult, |
| + context->MakeReplyMessageContext()), |
| + base::Bind(&PepperTalkHost::OnStopRemotingCompleted, |
| + weak_factory_.GetWeakPtr())); |
| + return PP_OK_COMPLETIONPENDING; |
| +} |
| + |
| +void PepperTalkHost::OnStopRemotingCompleted( |
| + ppapi::host::ReplyMessageContext reply) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| + remoting_started_ = false; |
| + host()->SendReply(reply, PpapiPluginMsg_Talk_StopRemotingReply()); |
| +} |
| + |
| +void PepperTalkHost::OnRemotingStopEvent() { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| + remoting_started_ = false; |
| + host()->SendUnsolicitedReply( |
| + pp_resource(), PpapiPluginMsg_Talk_NotifyEvent(PP_TALKEVENT_TERMINATE)); |
| } |
| } // namespace chrome |