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 | |
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 reply.params.set_result(0); | |
97 | |
98 content::RenderViewHost* render_view_host = | |
99 content::RenderViewHost::FromID(render_process_id, render_view_id); | |
100 if (!render_view_host) | |
101 return reply; // RVH destroyed while task was pending. | |
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 #else | |
111 NOTIMPLEMENTED(); | |
112 #endif | |
113 return reply; | |
114 } | |
115 | |
116 void StopRemotingOnUIThread() { | |
117 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
118 #if defined(USE_ASH) | |
119 ash::Shell::GetInstance()->system_tray_notifier()->NotifyScreenShareStop(); | |
120 #else | |
121 NOTIMPLEMENTED(); | |
122 #endif | |
123 } | |
124 | |
125 ppapi::host::ReplyMessageContext StopRemotingOnUIThreadWithResult( | |
126 ppapi::host::ReplyMessageContext reply) { | |
127 reply.params.set_result(0); | |
128 StopRemotingOnUIThread(); | |
129 return reply; | |
130 } | |
131 | |
63 } // namespace | 132 } // namespace |
64 | 133 |
65 PepperTalkHost::PepperTalkHost(content::BrowserPpapiHost* host, | 134 PepperTalkHost::PepperTalkHost(content::BrowserPpapiHost* host, |
66 PP_Instance instance, | 135 PP_Instance instance, |
67 PP_Resource resource) | 136 PP_Resource resource) |
68 : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource), | 137 : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource), |
69 weak_factory_(this), | 138 weak_factory_(this), |
70 browser_ppapi_host_(host) { | 139 browser_ppapi_host_(host), |
140 remoting_started_(false) { | |
71 } | 141 } |
72 | 142 |
73 PepperTalkHost::~PepperTalkHost() { | 143 PepperTalkHost::~PepperTalkHost() { |
144 if (remoting_started_) { | |
145 content::BrowserThread::PostTask( | |
146 content::BrowserThread::UI, FROM_HERE, | |
147 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
| |
148 } | |
74 } | 149 } |
75 | 150 |
76 int32_t PepperTalkHost::OnResourceMessageReceived( | 151 int32_t PepperTalkHost::OnResourceMessageReceived( |
77 const IPC::Message& msg, | 152 const IPC::Message& msg, |
78 ppapi::host::HostMessageContext* context) { | 153 ppapi::host::HostMessageContext* context) { |
79 IPC_BEGIN_MESSAGE_MAP(PepperTalkHost, msg) | 154 IPC_BEGIN_MESSAGE_MAP(PepperTalkHost, msg) |
80 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Talk_RequestPermission, | 155 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Talk_RequestPermission, |
81 OnRequestPermission) | 156 OnRequestPermission) |
82 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Talk_StartRemoting, | 157 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Talk_StartRemoting, |
83 OnStartRemoting) | 158 OnStartRemoting) |
84 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Talk_StopRemoting, | 159 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Talk_StopRemoting, |
85 OnStopRemoting) | 160 OnStopRemoting) |
86 IPC_END_MESSAGE_MAP() | 161 IPC_END_MESSAGE_MAP() |
87 return PP_ERROR_FAILED; | 162 return PP_ERROR_FAILED; |
88 } | 163 } |
89 | 164 |
90 int32_t PepperTalkHost::OnRequestPermission( | 165 int32_t PepperTalkHost::OnRequestPermission( |
91 ppapi::host::HostMessageContext* context, | 166 ppapi::host::HostMessageContext* context, |
92 PP_TalkPermission permission) { | 167 PP_TalkPermission permission) { |
93 // TODO(dcaiafa): Implement support for other permission types. | 168 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.
| |
94 if (permission != PP_TALKPERMISSION_SCREENCAST) | |
95 return PP_ERROR_BADARGUMENT; | 169 return PP_ERROR_BADARGUMENT; |
96 | 170 |
97 int render_process_id = 0; | 171 int render_process_id = 0; |
98 int render_view_id = 0; | 172 int render_view_id = 0; |
99 browser_ppapi_host_->GetRenderViewIDsForInstance( | 173 browser_ppapi_host_->GetRenderViewIDsForInstance( |
100 pp_instance(), &render_process_id, &render_view_id); | 174 pp_instance(), &render_process_id, &render_view_id); |
101 | 175 |
102 content::BrowserThread::PostTaskAndReplyWithResult( | 176 content::BrowserThread::PostTaskAndReplyWithResult( |
103 content::BrowserThread::UI, FROM_HERE, | 177 content::BrowserThread::UI, FROM_HERE, |
104 base::Bind(&GetPermissionOnUIThread, render_process_id, render_view_id, | 178 base::Bind(&GetPermissionOnUIThread, permission, render_process_id, |
105 context->MakeReplyMessageContext()), | 179 render_view_id, context->MakeReplyMessageContext()), |
106 base::Bind(&PepperTalkHost::GotTalkPermission, | 180 base::Bind(&PepperTalkHost::OnRequestPermissionCompleted, |
107 weak_factory_.GetWeakPtr())); | 181 weak_factory_.GetWeakPtr())); |
108 return PP_OK_COMPLETIONPENDING; | 182 return PP_OK_COMPLETIONPENDING; |
109 } | 183 } |
110 | 184 |
111 void PepperTalkHost::GotTalkPermission( | 185 void PepperTalkHost::OnRequestPermissionCompleted( |
112 ppapi::host::ReplyMessageContext reply) { | 186 ppapi::host::ReplyMessageContext reply) { |
113 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 187 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
114 host()->SendReply(reply, PpapiPluginMsg_Talk_RequestPermissionReply()); | 188 host()->SendReply(reply, PpapiPluginMsg_Talk_RequestPermissionReply()); |
115 } | 189 } |
116 | 190 |
117 int32_t PepperTalkHost::OnStartRemoting( | 191 int32_t PepperTalkHost::OnStartRemoting( |
118 ppapi::host::HostMessageContext* context) { | 192 ppapi::host::HostMessageContext* context) { |
119 // TODO(dcaiafa): Request IPC audit when this is implemented | 193 int render_process_id = 0; |
120 NOTIMPLEMENTED(); | 194 int render_view_id = 0; |
121 return PP_ERROR_FAILED; | 195 browser_ppapi_host_->GetRenderViewIDsForInstance( |
196 pp_instance(), &render_process_id, &render_view_id); | |
197 | |
198 base::Closure remoting_stop_callback = base::Bind( | |
199 &PepperTalkHost::OnRemotingStopEvent, | |
200 weak_factory_.GetWeakPtr()); | |
201 | |
202 content::BrowserThread::PostTaskAndReplyWithResult( | |
203 content::BrowserThread::UI, FROM_HERE, | |
204 base::Bind(&StartRemotingOnUIThread, remoting_stop_callback, | |
205 render_process_id, render_view_id, | |
206 context->MakeReplyMessageContext()), | |
207 base::Bind(&PepperTalkHost::OnStartRemotingCompleted, | |
208 weak_factory_.GetWeakPtr())); | |
209 return PP_OK_COMPLETIONPENDING; | |
210 } | |
211 | |
212 void PepperTalkHost::OnStartRemotingCompleted( | |
213 ppapi::host::ReplyMessageContext reply) { | |
214 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
215 if (reply.params.result() == PP_OK) { | |
216 // Remember to hide remoting UI when resource is deleted. | |
217 remoting_started_ = true; | |
218 } | |
219 host()->SendReply(reply, PpapiPluginMsg_Talk_StartRemotingReply()); | |
122 } | 220 } |
123 | 221 |
124 int32_t PepperTalkHost::OnStopRemoting( | 222 int32_t PepperTalkHost::OnStopRemoting( |
125 ppapi::host::HostMessageContext* context) { | 223 ppapi::host::HostMessageContext* context) { |
126 // TODO(dcaiafa): Request IPC audit when this is implemented | 224 content::BrowserThread::PostTaskAndReplyWithResult( |
127 NOTIMPLEMENTED(); | 225 content::BrowserThread::UI, FROM_HERE, |
128 return PP_ERROR_FAILED; | 226 base::Bind(&StopRemotingOnUIThreadWithResult, |
227 context->MakeReplyMessageContext()), | |
228 base::Bind(&PepperTalkHost::OnStopRemotingCompleted, | |
229 weak_factory_.GetWeakPtr())); | |
230 return PP_OK_COMPLETIONPENDING; | |
231 } | |
232 | |
233 void PepperTalkHost::OnStopRemotingCompleted( | |
234 ppapi::host::ReplyMessageContext reply) { | |
235 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
236 remoting_started_ = false; | |
237 host()->SendReply(reply, PpapiPluginMsg_Talk_StopRemotingReply()); | |
238 } | |
239 | |
240 void PepperTalkHost::OnRemotingStopEvent() { | |
241 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
242 remoting_started_ = false; | |
243 host()->SendUnsolicitedReply( | |
244 pp_resource(), PpapiPluginMsg_Talk_NotifyEvent(PP_TALKEVENT_TERMINATE)); | |
129 } | 245 } |
130 | 246 |
131 } // namespace chrome | 247 } // namespace chrome |
OLD | NEW |