Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/renderer_host/pepper/pepper_talk_host.h" | 5 #include "chrome/browser/renderer_host/pepper/pepper_talk_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "content/public/browser/browser_ppapi_host.h" | 8 #include "content/public/browser/browser_ppapi_host.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| 11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
| 12 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
| 13 #include "ppapi/host/dispatch_host_message.h" | 13 #include "ppapi/host/dispatch_host_message.h" |
| 14 #include "ppapi/host/host_message_context.h" | 14 #include "ppapi/host/host_message_context.h" |
| 15 #include "ppapi/host/ppapi_host.h" | 15 #include "ppapi/host/ppapi_host.h" |
| 16 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 | 18 |
| 19 #if defined(USE_ASH) | 19 #if defined(USE_ASH) |
| 20 #include "ash/shell.h" | 20 #include "ash/shell.h" |
| 21 #include "ash/shell_window_ids.h" | 21 #include "ash/shell_window_ids.h" |
| 22 #include "ash/system/tray/system_tray_notifier.h" | |
| 22 #include "chrome/browser/ui/simple_message_box.h" | 23 #include "chrome/browser/ui/simple_message_box.h" |
| 23 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 namespace chrome { | 27 namespace chrome { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 ppapi::host::ReplyMessageContext GetPermissionOnUIThread( | 31 ppapi::host::ReplyMessageContext GetPermissionOnUIThread( |
| 32 PP_TalkPermission permission, | |
| 31 int render_process_id, | 33 int render_process_id, |
| 32 int render_view_id, | 34 int render_view_id, |
| 33 ppapi::host::ReplyMessageContext reply) { | 35 ppapi::host::ReplyMessageContext reply) { |
| 34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 36 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 35 reply.params.set_result(0); | 37 reply.params.set_result(0); |
| 36 | 38 |
| 37 content::RenderViewHost* render_view_host = | 39 content::RenderViewHost* render_view_host = |
| 38 content::RenderViewHost::FromID(render_process_id, render_view_id); | 40 content::RenderViewHost::FromID(render_process_id, render_view_id); |
| 39 if (!render_view_host) | 41 if (!render_view_host) |
| 40 return reply; // RVH destroyed while task was pending. | 42 return reply; // RVH destroyed while task was pending. |
| 41 | 43 |
| 42 #if defined(USE_ASH) | 44 #if defined(USE_ASH) |
| 45 | |
|
raymes
2013/06/18 00:30:51
nit: blank line
dcaiafa
2013/06/18 16:36:40
Done.
| |
| 46 string16 title; | |
| 47 string16 message; | |
| 48 | |
| 49 switch (permission) { | |
| 50 case PP_TALKPERMISSION_SCREENCAST: | |
| 51 title = l10n_util::GetStringUTF16(IDS_GTALK_SCREEN_SHARE_DIALOG_TITLE); | |
| 52 message = l10n_util::GetStringUTF16( | |
| 53 IDS_GTALK_SCREEN_SHARE_DIALOG_MESSAGE); | |
| 54 break; | |
| 55 case PP_TALKPERMISSION_REMOTING: | |
| 56 title = l10n_util::GetStringUTF16(IDS_GTALK_REMOTING_DIALOG_TITLE); | |
| 57 message = l10n_util::GetStringUTF16( | |
| 58 IDS_GTALK_REMOTING_DIALOG_MESSAGE); | |
| 59 break; | |
| 60 case PP_TALKPERMISSION_REMOTING_CONTINUE: | |
| 61 title = l10n_util::GetStringUTF16(IDS_GTALK_REMOTING_DIALOG_TITLE); | |
| 62 message = l10n_util::GetStringUTF16( | |
| 63 IDS_GTALK_REMOTING_CONTINUE_DIALOG_MESSAGE); | |
| 64 break; | |
| 65 default: | |
| 66 NOTREACHED(); | |
| 67 return reply; | |
| 68 } | |
| 69 | |
| 43 // TODO(brettw). We should not be grabbing the active toplevel window, we | 70 // TODO(brettw). We should not be grabbing the active toplevel window, we |
| 44 // should use the toplevel window associated with the render view. | 71 // should use the toplevel window associated with the render view. |
| 45 const string16 title = l10n_util::GetStringUTF16( | |
| 46 IDS_GTALK_SCREEN_SHARE_DIALOG_TITLE); | |
| 47 const string16 message = l10n_util::GetStringUTF16( | |
| 48 IDS_GTALK_SCREEN_SHARE_DIALOG_MESSAGE); | |
| 49 | |
| 50 aura::Window* parent = ash::Shell::GetContainer( | 72 aura::Window* parent = ash::Shell::GetContainer( |
| 51 ash::Shell::GetActiveRootWindow(), | 73 ash::Shell::GetActiveRootWindow(), |
| 52 ash::internal::kShellWindowId_SystemModalContainer); | 74 ash::internal::kShellWindowId_SystemModalContainer); |
| 53 reply.params.set_result(static_cast<int32_t>( | 75 reply.params.set_result(static_cast<int32_t>( |
| 54 chrome::ShowMessageBox(parent, title, message, | 76 chrome::ShowMessageBox(parent, title, message, |
| 55 chrome::MESSAGE_BOX_TYPE_QUESTION) == | 77 chrome::MESSAGE_BOX_TYPE_QUESTION) == |
| 56 chrome::MESSAGE_BOX_RESULT_YES)); | 78 chrome::MESSAGE_BOX_RESULT_YES)); |
| 57 #else | 79 #else |
| 58 NOTIMPLEMENTED(); | 80 NOTIMPLEMENTED(); |
| 59 #endif | 81 #endif |
| 60 return reply; | 82 return reply; |
| 61 } | 83 } |
| 62 | 84 |
| 85 void OnTerminateRemotingEventOnUIThread(const base::Closure& stop_callback) { | |
| 86 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | |
| 87 stop_callback); | |
| 88 } | |
| 89 | |
| 90 ppapi::host::ReplyMessageContext StartRemotingOnUIThread( | |
| 91 const base::Closure& stop_callback, | |
| 92 int render_process_id, | |
| 93 int render_view_id, | |
| 94 ppapi::host::ReplyMessageContext reply) { | |
| 95 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 96 content::RenderViewHost* render_view_host = | |
| 97 content::RenderViewHost::FromID(render_process_id, render_view_id); | |
| 98 if (!render_view_host) { | |
| 99 reply.params.set_result(PP_ERROR_FAILED); | |
| 100 return reply; // RVH destroyed while task was pending. | |
| 101 } | |
| 102 | |
| 103 #if defined(USE_ASH) | |
| 104 base::Closure stop_callback_ui_thread = base::Bind( | |
| 105 &OnTerminateRemotingEventOnUIThread, | |
| 106 stop_callback); | |
| 107 | |
| 108 ash::Shell::GetInstance()->system_tray_notifier()->NotifyScreenShareStart( | |
| 109 stop_callback_ui_thread, base::string16()); | |
| 110 reply.params.set_result(PP_OK); | |
| 111 #else | |
| 112 NOTIMPLEMENTED(); | |
| 113 reply.params.set_result(PP_ERROR_NOTSUPPORTED); | |
| 114 #endif | |
| 115 return reply; | |
| 116 } | |
| 117 | |
| 118 void StopRemotingOnUIThread() { | |
| 119 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 120 #if defined(USE_ASH) | |
| 121 ash::Shell::GetInstance()->system_tray_notifier()->NotifyScreenShareStop(); | |
|
raymes
2013/06/18 00:30:51
Should you be checking any of these things are sti
dcaiafa
2013/06/18 16:36:40
Good point. RequestPermission and StartRemoting ar
| |
| 122 #else | |
| 123 NOTIMPLEMENTED(); | |
| 124 #endif | |
| 125 } | |
| 126 | |
| 127 ppapi::host::ReplyMessageContext StopRemotingOnUIThreadWithResult( | |
| 128 ppapi::host::ReplyMessageContext reply) { | |
| 129 reply.params.set_result(PP_OK); | |
| 130 StopRemotingOnUIThread(); | |
| 131 return reply; | |
| 132 } | |
| 133 | |
| 63 } // namespace | 134 } // namespace |
| 64 | 135 |
| 65 PepperTalkHost::PepperTalkHost(content::BrowserPpapiHost* host, | 136 PepperTalkHost::PepperTalkHost(content::BrowserPpapiHost* host, |
| 66 PP_Instance instance, | 137 PP_Instance instance, |
| 67 PP_Resource resource) | 138 PP_Resource resource) |
| 68 : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource), | 139 : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource), |
| 69 weak_factory_(this), | 140 weak_factory_(this), |
| 70 browser_ppapi_host_(host) { | 141 browser_ppapi_host_(host), |
| 142 remoting_started_(false) { | |
| 71 } | 143 } |
| 72 | 144 |
| 73 PepperTalkHost::~PepperTalkHost() { | 145 PepperTalkHost::~PepperTalkHost() { |
| 146 if (remoting_started_) { | |
| 147 content::BrowserThread::PostTask( | |
| 148 content::BrowserThread::UI, FROM_HERE, | |
| 149 base::Bind(&StopRemotingOnUIThread)); | |
| 150 } | |
| 74 } | 151 } |
| 75 | 152 |
| 76 int32_t PepperTalkHost::OnResourceMessageReceived( | 153 int32_t PepperTalkHost::OnResourceMessageReceived( |
| 77 const IPC::Message& msg, | 154 const IPC::Message& msg, |
| 78 ppapi::host::HostMessageContext* context) { | 155 ppapi::host::HostMessageContext* context) { |
| 79 IPC_BEGIN_MESSAGE_MAP(PepperTalkHost, msg) | 156 IPC_BEGIN_MESSAGE_MAP(PepperTalkHost, msg) |
| 80 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Talk_RequestPermission, | 157 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Talk_RequestPermission, |
| 81 OnRequestPermission) | 158 OnRequestPermission) |
| 82 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Talk_StartRemoting, | 159 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Talk_StartRemoting, |
| 83 OnStartRemoting) | 160 OnStartRemoting) |
| 84 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Talk_StopRemoting, | 161 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Talk_StopRemoting, |
| 85 OnStopRemoting) | 162 OnStopRemoting) |
| 86 IPC_END_MESSAGE_MAP() | 163 IPC_END_MESSAGE_MAP() |
| 87 return PP_ERROR_FAILED; | 164 return PP_ERROR_FAILED; |
| 88 } | 165 } |
| 89 | 166 |
| 90 int32_t PepperTalkHost::OnRequestPermission( | 167 int32_t PepperTalkHost::OnRequestPermission( |
| 91 ppapi::host::HostMessageContext* context, | 168 ppapi::host::HostMessageContext* context, |
| 92 PP_TalkPermission permission) { | 169 PP_TalkPermission permission) { |
| 93 // TODO(dcaiafa): Implement support for other permission types. | 170 if (permission < PP_TALKPERMISSION_SCREENCAST || |
| 94 if (permission != PP_TALKPERMISSION_SCREENCAST) | 171 permission >= PP_TALKPERMISSION_NUM_PERMISSIONS) |
| 95 return PP_ERROR_BADARGUMENT; | 172 return PP_ERROR_BADARGUMENT; |
| 96 | 173 |
| 97 int render_process_id = 0; | 174 int render_process_id = 0; |
| 98 int render_view_id = 0; | 175 int render_view_id = 0; |
| 99 browser_ppapi_host_->GetRenderViewIDsForInstance( | 176 browser_ppapi_host_->GetRenderViewIDsForInstance( |
| 100 pp_instance(), &render_process_id, &render_view_id); | 177 pp_instance(), &render_process_id, &render_view_id); |
| 101 | 178 |
| 102 content::BrowserThread::PostTaskAndReplyWithResult( | 179 content::BrowserThread::PostTaskAndReplyWithResult( |
| 103 content::BrowserThread::UI, FROM_HERE, | 180 content::BrowserThread::UI, FROM_HERE, |
| 104 base::Bind(&GetPermissionOnUIThread, render_process_id, render_view_id, | 181 base::Bind(&GetPermissionOnUIThread, permission, render_process_id, |
| 105 context->MakeReplyMessageContext()), | 182 render_view_id, context->MakeReplyMessageContext()), |
| 106 base::Bind(&PepperTalkHost::GotTalkPermission, | 183 base::Bind(&PepperTalkHost::OnRequestPermissionCompleted, |
| 107 weak_factory_.GetWeakPtr())); | 184 weak_factory_.GetWeakPtr())); |
| 108 return PP_OK_COMPLETIONPENDING; | 185 return PP_OK_COMPLETIONPENDING; |
| 109 } | 186 } |
| 110 | 187 |
| 111 void PepperTalkHost::GotTalkPermission( | 188 void PepperTalkHost::OnRequestPermissionCompleted( |
| 112 ppapi::host::ReplyMessageContext reply) { | 189 ppapi::host::ReplyMessageContext reply) { |
| 113 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 190 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 114 host()->SendReply(reply, PpapiPluginMsg_Talk_RequestPermissionReply()); | 191 host()->SendReply(reply, PpapiPluginMsg_Talk_RequestPermissionReply()); |
| 115 } | 192 } |
| 116 | 193 |
| 117 int32_t PepperTalkHost::OnStartRemoting( | 194 int32_t PepperTalkHost::OnStartRemoting( |
| 118 ppapi::host::HostMessageContext* context) { | 195 ppapi::host::HostMessageContext* context) { |
| 119 // TODO(dcaiafa): Request IPC audit when this is implemented | 196 int render_process_id = 0; |
| 120 NOTIMPLEMENTED(); | 197 int render_view_id = 0; |
| 121 return PP_ERROR_FAILED; | 198 browser_ppapi_host_->GetRenderViewIDsForInstance( |
| 199 pp_instance(), &render_process_id, &render_view_id); | |
| 200 | |
| 201 base::Closure remoting_stop_callback = base::Bind( | |
| 202 &PepperTalkHost::OnRemotingStopEvent, | |
| 203 weak_factory_.GetWeakPtr()); | |
| 204 | |
| 205 content::BrowserThread::PostTaskAndReplyWithResult( | |
| 206 content::BrowserThread::UI, FROM_HERE, | |
| 207 base::Bind(&StartRemotingOnUIThread, remoting_stop_callback, | |
| 208 render_process_id, render_view_id, | |
| 209 context->MakeReplyMessageContext()), | |
| 210 base::Bind(&PepperTalkHost::OnStartRemotingCompleted, | |
| 211 weak_factory_.GetWeakPtr())); | |
| 212 return PP_OK_COMPLETIONPENDING; | |
| 213 } | |
| 214 | |
| 215 void PepperTalkHost::OnStartRemotingCompleted( | |
| 216 ppapi::host::ReplyMessageContext reply) { | |
| 217 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
| 218 if (reply.params.result() == PP_OK) { | |
| 219 // Remember to hide remoting UI when resource is deleted. | |
| 220 remoting_started_ = true; | |
| 221 } | |
| 222 host()->SendReply(reply, PpapiPluginMsg_Talk_StartRemotingReply()); | |
| 122 } | 223 } |
| 123 | 224 |
| 124 int32_t PepperTalkHost::OnStopRemoting( | 225 int32_t PepperTalkHost::OnStopRemoting( |
| 125 ppapi::host::HostMessageContext* context) { | 226 ppapi::host::HostMessageContext* context) { |
| 126 // TODO(dcaiafa): Request IPC audit when this is implemented | 227 content::BrowserThread::PostTaskAndReplyWithResult( |
| 127 NOTIMPLEMENTED(); | 228 content::BrowserThread::UI, FROM_HERE, |
| 128 return PP_ERROR_FAILED; | 229 base::Bind(&StopRemotingOnUIThreadWithResult, |
| 230 context->MakeReplyMessageContext()), | |
| 231 base::Bind(&PepperTalkHost::OnStopRemotingCompleted, | |
| 232 weak_factory_.GetWeakPtr())); | |
| 233 return PP_OK_COMPLETIONPENDING; | |
| 234 } | |
| 235 | |
| 236 void PepperTalkHost::OnStopRemotingCompleted( | |
| 237 ppapi::host::ReplyMessageContext reply) { | |
| 238 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
| 239 remoting_started_ = false; | |
| 240 host()->SendReply(reply, PpapiPluginMsg_Talk_StopRemotingReply()); | |
| 241 } | |
| 242 | |
| 243 void PepperTalkHost::OnRemotingStopEvent() { | |
| 244 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
| 245 remoting_started_ = false; | |
|
raymes
2013/06/18 00:30:51
Is it possible for this to be called before OnStar
dcaiafa
2013/06/18 16:36:40
Done.
On 2013/06/18 00:30:51, raymes wrote:
| |
| 246 host()->SendUnsolicitedReply( | |
| 247 pp_resource(), PpapiPluginMsg_Talk_NotifyEvent(PP_TALKEVENT_TERMINATE)); | |
| 129 } | 248 } |
| 130 | 249 |
| 131 } // namespace chrome | 250 } // namespace chrome |
| OLD | NEW |