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_frame_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 "ash/system/tray/system_tray_notifier.h" |
23 #include "chrome/browser/ui/simple_message_box.h" | 23 #include "chrome/browser/ui/simple_message_box.h" |
24 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
25 #endif | 25 #endif |
26 | 26 |
27 namespace chrome { | 27 namespace chrome { |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 ppapi::host::ReplyMessageContext GetPermissionOnUIThread( | 31 ppapi::host::ReplyMessageContext GetPermissionOnUIThread( |
32 PP_TalkPermission permission, | 32 PP_TalkPermission permission, |
33 int render_process_id, | 33 int render_process_id, |
34 int render_view_id, | 34 int render_frame_id, |
35 ppapi::host::ReplyMessageContext reply) { | 35 ppapi::host::ReplyMessageContext reply) { |
36 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 36 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
37 reply.params.set_result(0); | 37 reply.params.set_result(0); |
38 | 38 |
39 content::RenderViewHost* render_view_host = | 39 content::RenderFrameHost* render_frame_host = |
40 content::RenderViewHost::FromID(render_process_id, render_view_id); | 40 content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
41 if (!render_view_host) | 41 if (!render_frame_host) |
42 return reply; // RVH destroyed while task was pending. | 42 return reply; // RFH destroyed while task was pending. |
43 | 43 |
44 #if defined(USE_ASH) | 44 #if defined(USE_ASH) |
45 base::string16 title; | 45 base::string16 title; |
46 base::string16 message; | 46 base::string16 message; |
47 | 47 |
48 switch (permission) { | 48 switch (permission) { |
49 case PP_TALKPERMISSION_SCREENCAST: | 49 case PP_TALKPERMISSION_SCREENCAST: |
50 title = l10n_util::GetStringUTF16(IDS_GTALK_SCREEN_SHARE_DIALOG_TITLE); | 50 title = l10n_util::GetStringUTF16(IDS_GTALK_SCREEN_SHARE_DIALOG_TITLE); |
51 message = l10n_util::GetStringUTF16( | 51 message = l10n_util::GetStringUTF16( |
52 IDS_GTALK_SCREEN_SHARE_DIALOG_MESSAGE); | 52 IDS_GTALK_SCREEN_SHARE_DIALOG_MESSAGE); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 #if defined(USE_ASH) && defined(OS_CHROMEOS) | 84 #if defined(USE_ASH) && defined(OS_CHROMEOS) |
85 void OnTerminateRemotingEventOnUIThread(const base::Closure& stop_callback) { | 85 void OnTerminateRemotingEventOnUIThread(const base::Closure& stop_callback) { |
86 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | 86 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
87 stop_callback); | 87 stop_callback); |
88 } | 88 } |
89 #endif // defined(USE_ASH) && defined(OS_CHROMEOS) | 89 #endif // defined(USE_ASH) && defined(OS_CHROMEOS) |
90 | 90 |
91 ppapi::host::ReplyMessageContext StartRemotingOnUIThread( | 91 ppapi::host::ReplyMessageContext StartRemotingOnUIThread( |
92 const base::Closure& stop_callback, | 92 const base::Closure& stop_callback, |
93 int render_process_id, | 93 int render_process_id, |
94 int render_view_id, | 94 int render_frame_id, |
95 ppapi::host::ReplyMessageContext reply) { | 95 ppapi::host::ReplyMessageContext reply) { |
96 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 96 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
97 content::RenderViewHost* render_view_host = | 97 content::RenderFrameHost* render_frame_host = |
98 content::RenderViewHost::FromID(render_process_id, render_view_id); | 98 content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
99 if (!render_view_host) { | 99 if (!render_frame_host) { |
100 reply.params.set_result(PP_ERROR_FAILED); | 100 reply.params.set_result(PP_ERROR_FAILED); |
101 return reply; // RVH destroyed while task was pending. | 101 return reply; // RFH destroyed while task was pending. |
102 } | 102 } |
103 | 103 |
104 #if defined(USE_ASH) && defined(OS_CHROMEOS) | 104 #if defined(USE_ASH) && defined(OS_CHROMEOS) |
105 base::Closure stop_callback_ui_thread = base::Bind( | 105 base::Closure stop_callback_ui_thread = base::Bind( |
106 &OnTerminateRemotingEventOnUIThread, | 106 &OnTerminateRemotingEventOnUIThread, |
107 stop_callback); | 107 stop_callback); |
108 | 108 |
109 ash::Shell::GetInstance()->system_tray_notifier()->NotifyScreenShareStart( | 109 ash::Shell::GetInstance()->system_tray_notifier()->NotifyScreenShareStart( |
110 stop_callback_ui_thread, base::string16()); | 110 stop_callback_ui_thread, base::string16()); |
111 reply.params.set_result(PP_OK); | 111 reply.params.set_result(PP_OK); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 168 } |
169 | 169 |
170 int32_t PepperTalkHost::OnRequestPermission( | 170 int32_t PepperTalkHost::OnRequestPermission( |
171 ppapi::host::HostMessageContext* context, | 171 ppapi::host::HostMessageContext* context, |
172 PP_TalkPermission permission) { | 172 PP_TalkPermission permission) { |
173 if (permission < PP_TALKPERMISSION_SCREENCAST || | 173 if (permission < PP_TALKPERMISSION_SCREENCAST || |
174 permission >= PP_TALKPERMISSION_NUM_PERMISSIONS) | 174 permission >= PP_TALKPERMISSION_NUM_PERMISSIONS) |
175 return PP_ERROR_BADARGUMENT; | 175 return PP_ERROR_BADARGUMENT; |
176 | 176 |
177 int render_process_id = 0; | 177 int render_process_id = 0; |
178 int render_view_id = 0; | 178 int render_frame_id = 0; |
179 browser_ppapi_host_->GetRenderViewIDsForInstance( | 179 browser_ppapi_host_->GetRenderFrameIDsForInstance( |
180 pp_instance(), &render_process_id, &render_view_id); | 180 pp_instance(), &render_process_id, &render_frame_id); |
181 | 181 |
182 content::BrowserThread::PostTaskAndReplyWithResult( | 182 content::BrowserThread::PostTaskAndReplyWithResult( |
183 content::BrowserThread::UI, FROM_HERE, | 183 content::BrowserThread::UI, FROM_HERE, |
184 base::Bind(&GetPermissionOnUIThread, permission, render_process_id, | 184 base::Bind(&GetPermissionOnUIThread, permission, render_process_id, |
185 render_view_id, context->MakeReplyMessageContext()), | 185 render_frame_id, context->MakeReplyMessageContext()), |
186 base::Bind(&PepperTalkHost::OnRequestPermissionCompleted, | 186 base::Bind(&PepperTalkHost::OnRequestPermissionCompleted, |
187 weak_factory_.GetWeakPtr())); | 187 weak_factory_.GetWeakPtr())); |
188 return PP_OK_COMPLETIONPENDING; | 188 return PP_OK_COMPLETIONPENDING; |
189 } | 189 } |
190 | 190 |
191 int32_t PepperTalkHost::OnStartRemoting( | 191 int32_t PepperTalkHost::OnStartRemoting( |
192 ppapi::host::HostMessageContext* context) { | 192 ppapi::host::HostMessageContext* context) { |
193 int render_process_id = 0; | 193 int render_process_id = 0; |
194 int render_view_id = 0; | 194 int render_frame_id = 0; |
195 browser_ppapi_host_->GetRenderViewIDsForInstance( | 195 browser_ppapi_host_->GetRenderFrameIDsForInstance( |
196 pp_instance(), &render_process_id, &render_view_id); | 196 pp_instance(), &render_process_id, &render_frame_id); |
197 | 197 |
198 base::Closure remoting_stop_callback = base::Bind( | 198 base::Closure remoting_stop_callback = base::Bind( |
199 &PepperTalkHost::OnRemotingStopEvent, | 199 &PepperTalkHost::OnRemotingStopEvent, |
200 weak_factory_.GetWeakPtr()); | 200 weak_factory_.GetWeakPtr()); |
201 | 201 |
202 content::BrowserThread::PostTaskAndReplyWithResult( | 202 content::BrowserThread::PostTaskAndReplyWithResult( |
203 content::BrowserThread::UI, FROM_HERE, | 203 content::BrowserThread::UI, FROM_HERE, |
204 base::Bind(&StartRemotingOnUIThread, remoting_stop_callback, | 204 base::Bind(&StartRemotingOnUIThread, remoting_stop_callback, |
205 render_process_id, render_view_id, | 205 render_process_id, render_frame_id, |
206 context->MakeReplyMessageContext()), | 206 context->MakeReplyMessageContext()), |
207 base::Bind(&PepperTalkHost::OnStartRemotingCompleted, | 207 base::Bind(&PepperTalkHost::OnStartRemotingCompleted, |
208 weak_factory_.GetWeakPtr())); | 208 weak_factory_.GetWeakPtr())); |
209 return PP_OK_COMPLETIONPENDING; | 209 return PP_OK_COMPLETIONPENDING; |
210 } | 210 } |
211 | 211 |
212 int32_t PepperTalkHost::OnStopRemoting( | 212 int32_t PepperTalkHost::OnStopRemoting( |
213 ppapi::host::HostMessageContext* context) { | 213 ppapi::host::HostMessageContext* context) { |
214 content::BrowserThread::PostTaskAndReplyWithResult( | 214 content::BrowserThread::PostTaskAndReplyWithResult( |
215 content::BrowserThread::UI, FROM_HERE, | 215 content::BrowserThread::UI, FROM_HERE, |
(...skipping 28 matching lines...) Expand all Loading... |
244 } | 244 } |
245 | 245 |
246 void PepperTalkHost::OnStopRemotingCompleted( | 246 void PepperTalkHost::OnStopRemotingCompleted( |
247 ppapi::host::ReplyMessageContext reply) { | 247 ppapi::host::ReplyMessageContext reply) { |
248 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 248 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
249 remoting_started_ = false; | 249 remoting_started_ = false; |
250 host()->SendReply(reply, PpapiPluginMsg_Talk_StopRemotingReply()); | 250 host()->SendReply(reply, PpapiPluginMsg_Talk_StopRemotingReply()); |
251 } | 251 } |
252 | 252 |
253 } // namespace chrome | 253 } // namespace chrome |
OLD | NEW |