Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / ppapi / proxy / ppb_instance_proxy.cc
blob85f1f1621005bf140711c570c2e8fd7b466cf345
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
3 // found in the LICENSE file.
5 #include "ppapi/proxy/ppb_instance_proxy.h"
7 #include "base/memory/ref_counted.h"
8 #include "build/build_config.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/pp_time.h"
11 #include "ppapi/c/pp_var.h"
12 #include "ppapi/c/ppb_audio_config.h"
13 #include "ppapi/c/ppb_instance.h"
14 #include "ppapi/c/ppb_messaging.h"
15 #include "ppapi/c/ppb_mouse_lock.h"
16 #include "ppapi/c/private/pp_content_decryptor.h"
17 #include "ppapi/proxy/broker_resource.h"
18 #include "ppapi/proxy/browser_font_singleton_resource.h"
19 #include "ppapi/proxy/content_decryptor_private_serializer.h"
20 #include "ppapi/proxy/enter_proxy.h"
21 #include "ppapi/proxy/extensions_common_resource.h"
22 #include "ppapi/proxy/file_mapping_resource.h"
23 #include "ppapi/proxy/flash_clipboard_resource.h"
24 #include "ppapi/proxy/flash_file_resource.h"
25 #include "ppapi/proxy/flash_fullscreen_resource.h"
26 #include "ppapi/proxy/flash_resource.h"
27 #include "ppapi/proxy/gamepad_resource.h"
28 #include "ppapi/proxy/host_dispatcher.h"
29 #include "ppapi/proxy/isolated_file_system_private_resource.h"
30 #include "ppapi/proxy/network_proxy_resource.h"
31 #include "ppapi/proxy/pdf_resource.h"
32 #include "ppapi/proxy/plugin_dispatcher.h"
33 #include "ppapi/proxy/ppapi_messages.h"
34 #include "ppapi/proxy/serialized_var.h"
35 #include "ppapi/proxy/truetype_font_singleton_resource.h"
36 #include "ppapi/proxy/uma_private_resource.h"
37 #include "ppapi/shared_impl/ppapi_globals.h"
38 #include "ppapi/shared_impl/ppb_url_util_shared.h"
39 #include "ppapi/shared_impl/ppb_view_shared.h"
40 #include "ppapi/shared_impl/var.h"
41 #include "ppapi/thunk/enter.h"
42 #include "ppapi/thunk/ppb_graphics_2d_api.h"
43 #include "ppapi/thunk/ppb_graphics_3d_api.h"
44 #include "ppapi/thunk/thunk.h"
46 // Windows headers interfere with this file.
47 #ifdef PostMessage
48 #undef PostMessage
49 #endif
51 using ppapi::thunk::EnterInstanceNoLock;
52 using ppapi::thunk::EnterResourceNoLock;
53 using ppapi::thunk::PPB_Graphics2D_API;
54 using ppapi::thunk::PPB_Graphics3D_API;
55 using ppapi::thunk::PPB_Instance_API;
57 namespace ppapi {
58 namespace proxy {
60 namespace {
62 #if !defined(OS_NACL)
63 const char kSerializationError[] = "Failed to convert a PostMessage "
64 "argument from a PP_Var to a Javascript value. It may have cycles or be of "
65 "an unsupported type.";
66 #endif
68 void RequestSurroundingText(PP_Instance instance) {
69 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
70 if (!dispatcher)
71 return; // Instance has gone away while message was pending.
73 InstanceData* data = dispatcher->GetInstanceData(instance);
74 DCHECK(data); // Should have it, since we still have a dispatcher.
75 data->is_request_surrounding_text_pending = false;
76 if (!data->should_do_request_surrounding_text)
77 return;
79 // Just fake out a RequestSurroundingText message to the proxy for the PPP
80 // interface.
81 InterfaceProxy* proxy = dispatcher->GetInterfaceProxy(API_ID_PPP_TEXT_INPUT);
82 if (!proxy)
83 return;
84 proxy->OnMessageReceived(PpapiMsg_PPPTextInput_RequestSurroundingText(
85 API_ID_PPP_TEXT_INPUT, instance,
86 PPB_Instance_Shared::kExtraCharsForTextInput));
89 } // namespace
91 PPB_Instance_Proxy::PPB_Instance_Proxy(Dispatcher* dispatcher)
92 : InterfaceProxy(dispatcher),
93 callback_factory_(this) {
96 PPB_Instance_Proxy::~PPB_Instance_Proxy() {
99 bool PPB_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) {
100 // Prevent the dispatcher from going away during a call to ExecuteScript.
101 // This must happen OUTSIDE of ExecuteScript since the SerializedVars use
102 // the dispatcher upon return of the function (converting the
103 // SerializedVarReturnValue/OutParam to a SerializedVar in the destructor).
104 #if !defined(OS_NACL)
105 ScopedModuleReference death_grip(dispatcher());
106 #endif
108 bool handled = true;
109 IPC_BEGIN_MESSAGE_MAP(PPB_Instance_Proxy, msg)
110 #if !defined(OS_NACL)
111 // Plugin -> Host messages.
112 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetWindowObject,
113 OnHostMsgGetWindowObject)
114 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetOwnerElementObject,
115 OnHostMsgGetOwnerElementObject)
116 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_BindGraphics,
117 OnHostMsgBindGraphics)
118 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_IsFullFrame,
119 OnHostMsgIsFullFrame)
120 IPC_MESSAGE_HANDLER(
121 PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate,
122 OnHostMsgGetAudioHardwareOutputSampleRate)
123 IPC_MESSAGE_HANDLER(
124 PpapiHostMsg_PPBInstance_GetAudioHardwareOutputBufferSize,
125 OnHostMsgGetAudioHardwareOutputBufferSize)
126 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ExecuteScript,
127 OnHostMsgExecuteScript)
128 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDefaultCharSet,
129 OnHostMsgGetDefaultCharSet)
130 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetPluginToHandleFindRequests,
131 OnHostMsgSetPluginToHandleFindRequests);
132 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_NumberOfFindResultsChanged,
133 OnHostMsgNumberOfFindResultsChanged)
134 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SelectFindResultChanged,
135 OnHostMsgSelectFindResultChanged)
136 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetTickmarks,
137 OnHostMsgSetTickmarks)
138 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PostMessage,
139 OnHostMsgPostMessage)
140 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetFullscreen,
141 OnHostMsgSetFullscreen)
142 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetScreenSize,
143 OnHostMsgGetScreenSize)
144 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_RequestInputEvents,
145 OnHostMsgRequestInputEvents)
146 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ClearInputEvents,
147 OnHostMsgClearInputEvents)
148 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_LockMouse,
149 OnHostMsgLockMouse)
150 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UnlockMouse,
151 OnHostMsgUnlockMouse)
152 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetCursor,
153 OnHostMsgSetCursor)
154 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetTextInputType,
155 OnHostMsgSetTextInputType)
156 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UpdateCaretPosition,
157 OnHostMsgUpdateCaretPosition)
158 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_CancelCompositionText,
159 OnHostMsgCancelCompositionText)
160 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UpdateSurroundingText,
161 OnHostMsgUpdateSurroundingText)
162 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDocumentURL,
163 OnHostMsgGetDocumentURL)
164 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ResolveRelativeToDocument,
165 OnHostMsgResolveRelativeToDocument)
166 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanRequest,
167 OnHostMsgDocumentCanRequest)
168 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanAccessDocument,
169 OnHostMsgDocumentCanAccessDocument)
170 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginInstanceURL,
171 OnHostMsgGetPluginInstanceURL)
172 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginReferrerURL,
173 OnHostMsgGetPluginReferrerURL)
174 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionCreated,
175 OnHostMsgSessionCreated)
176 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionMessage,
177 OnHostMsgSessionMessage)
178 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionReady,
179 OnHostMsgSessionReady)
180 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionClosed,
181 OnHostMsgSessionClosed)
182 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionError,
183 OnHostMsgSessionError)
184 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverBlock,
185 OnHostMsgDeliverBlock)
186 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderInitializeDone,
187 OnHostMsgDecoderInitializeDone)
188 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderDeinitializeDone,
189 OnHostMsgDecoderDeinitializeDone)
190 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderResetDone,
191 OnHostMsgDecoderResetDone)
192 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverFrame,
193 OnHostMsgDeliverFrame)
194 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverSamples,
195 OnHostMsgDeliverSamples)
196 #endif // !defined(OS_NACL)
198 // Host -> Plugin messages.
199 IPC_MESSAGE_HANDLER(PpapiMsg_PPBInstance_MouseLockComplete,
200 OnPluginMsgMouseLockComplete)
202 IPC_MESSAGE_UNHANDLED(handled = false)
203 IPC_END_MESSAGE_MAP()
204 return handled;
207 PP_Bool PPB_Instance_Proxy::BindGraphics(PP_Instance instance,
208 PP_Resource device) {
209 // If device is 0, pass a null HostResource. This signals the host to unbind
210 // all devices.
211 HostResource host_resource;
212 PP_Resource pp_resource = 0;
213 if (device) {
214 Resource* resource =
215 PpapiGlobals::Get()->GetResourceTracker()->GetResource(device);
216 if (!resource || resource->pp_instance() != instance)
217 return PP_FALSE;
218 host_resource = resource->host_resource();
219 pp_resource = resource->pp_resource();
220 } else {
221 // Passing 0 means unbinding all devices.
222 dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
223 API_ID_PPB_INSTANCE, instance, 0));
224 return PP_TRUE;
227 // We need to pass different resource to Graphics 2D and 3D right now. Once
228 // 3D is migrated to the new design, we should be able to unify this.
229 EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false);
230 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false);
231 if (enter_2d.succeeded()) {
232 dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
233 API_ID_PPB_INSTANCE, instance, pp_resource));
234 return PP_TRUE;
235 } else if (enter_3d.succeeded()) {
236 dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
237 API_ID_PPB_INSTANCE, instance, host_resource.host_resource()));
238 return PP_TRUE;
240 return PP_FALSE;
243 PP_Bool PPB_Instance_Proxy::IsFullFrame(PP_Instance instance) {
244 PP_Bool result = PP_FALSE;
245 dispatcher()->Send(new PpapiHostMsg_PPBInstance_IsFullFrame(
246 API_ID_PPB_INSTANCE, instance, &result));
247 return result;
250 const ViewData* PPB_Instance_Proxy::GetViewData(PP_Instance instance) {
251 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
252 GetInstanceData(instance);
253 if (!data)
254 return NULL;
255 return &data->view;
258 PP_Bool PPB_Instance_Proxy::FlashIsFullscreen(PP_Instance instance) {
259 // This function is only used for proxying in the renderer process. It is not
260 // implemented in the plugin process.
261 NOTREACHED();
262 return PP_FALSE;
265 PP_Var PPB_Instance_Proxy::GetWindowObject(PP_Instance instance) {
266 ReceiveSerializedVarReturnValue result;
267 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetWindowObject(
268 API_ID_PPB_INSTANCE, instance, &result));
269 return result.Return(dispatcher());
272 PP_Var PPB_Instance_Proxy::GetOwnerElementObject(PP_Instance instance) {
273 ReceiveSerializedVarReturnValue result;
274 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetOwnerElementObject(
275 API_ID_PPB_INSTANCE, instance, &result));
276 return result.Return(dispatcher());
279 PP_Var PPB_Instance_Proxy::ExecuteScript(PP_Instance instance,
280 PP_Var script,
281 PP_Var* exception) {
282 ReceiveSerializedException se(dispatcher(), exception);
283 if (se.IsThrown())
284 return PP_MakeUndefined();
286 ReceiveSerializedVarReturnValue result;
287 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ExecuteScript(
288 API_ID_PPB_INSTANCE, instance,
289 SerializedVarSendInput(dispatcher(), script), &se, &result));
290 return result.Return(dispatcher());
293 uint32_t PPB_Instance_Proxy::GetAudioHardwareOutputSampleRate(
294 PP_Instance instance) {
295 uint32_t result = PP_AUDIOSAMPLERATE_NONE;
296 dispatcher()->Send(
297 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate(
298 API_ID_PPB_INSTANCE, instance, &result));
299 return result;
302 uint32_t PPB_Instance_Proxy::GetAudioHardwareOutputBufferSize(
303 PP_Instance instance) {
304 uint32_t result = 0;
305 dispatcher()->Send(
306 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputBufferSize(
307 API_ID_PPB_INSTANCE, instance, &result));
308 return result;
311 PP_Var PPB_Instance_Proxy::GetDefaultCharSet(PP_Instance instance) {
312 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
313 if (!dispatcher)
314 return PP_MakeUndefined();
316 ReceiveSerializedVarReturnValue result;
317 dispatcher->Send(new PpapiHostMsg_PPBInstance_GetDefaultCharSet(
318 API_ID_PPB_INSTANCE, instance, &result));
319 return result.Return(dispatcher);
322 void PPB_Instance_Proxy::SetPluginToHandleFindRequests(PP_Instance instance) {
323 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetPluginToHandleFindRequests(
324 API_ID_PPB_INSTANCE, instance));
327 void PPB_Instance_Proxy::NumberOfFindResultsChanged(PP_Instance instance,
328 int32_t total,
329 PP_Bool final_result) {
330 dispatcher()->Send(new PpapiHostMsg_PPBInstance_NumberOfFindResultsChanged(
331 API_ID_PPB_INSTANCE, instance, total, final_result));
334 void PPB_Instance_Proxy::SelectedFindResultChanged(PP_Instance instance,
335 int32_t index) {
336 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SelectFindResultChanged(
337 API_ID_PPB_INSTANCE, instance, index));
340 void PPB_Instance_Proxy::SetTickmarks(PP_Instance instance,
341 const PP_Rect* tickmarks,
342 uint32_t count) {
343 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTickmarks(
344 API_ID_PPB_INSTANCE, instance,
345 std::vector<PP_Rect>(tickmarks, tickmarks + count)));
348 PP_Bool PPB_Instance_Proxy::IsFullscreen(PP_Instance instance) {
349 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
350 GetInstanceData(instance);
351 if (!data)
352 return PP_FALSE;
353 return PP_FromBool(data->view.is_fullscreen);
356 PP_Bool PPB_Instance_Proxy::SetFullscreen(PP_Instance instance,
357 PP_Bool fullscreen) {
358 PP_Bool result = PP_FALSE;
359 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetFullscreen(
360 API_ID_PPB_INSTANCE, instance, fullscreen, &result));
361 return result;
364 PP_Bool PPB_Instance_Proxy::GetScreenSize(PP_Instance instance,
365 PP_Size* size) {
366 PP_Bool result = PP_FALSE;
367 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetScreenSize(
368 API_ID_PPB_INSTANCE, instance, &result, size));
369 return result;
372 Resource* PPB_Instance_Proxy::GetSingletonResource(PP_Instance instance,
373 SingletonResourceID id) {
374 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
375 GetInstanceData(instance);
377 InstanceData::SingletonResourceMap::iterator it =
378 data->singleton_resources.find(id);
379 if (it != data->singleton_resources.end())
380 return it->second.get();
382 scoped_refptr<Resource> new_singleton;
383 Connection connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher());
385 switch (id) {
386 case BROKER_SINGLETON_ID:
387 new_singleton = new BrokerResource(connection, instance);
388 break;
389 case EXTENSIONS_COMMON_SINGLETON_ID:
390 new_singleton = new ExtensionsCommonResource(connection, instance);
391 break;
392 case FILE_MAPPING_SINGLETON_ID:
393 new_singleton = new FileMappingResource(connection, instance);
394 break;
395 case GAMEPAD_SINGLETON_ID:
396 new_singleton = new GamepadResource(connection, instance);
397 break;
398 case ISOLATED_FILESYSTEM_SINGLETON_ID:
399 new_singleton =
400 new IsolatedFileSystemPrivateResource(connection, instance);
401 break;
402 case NETWORK_PROXY_SINGLETON_ID:
403 new_singleton = new NetworkProxyResource(connection, instance);
404 break;
405 case TRUETYPE_FONT_SINGLETON_ID:
406 new_singleton = new TrueTypeFontSingletonResource(connection, instance);
407 break;
408 case UMA_SINGLETON_ID:
409 new_singleton = new UMAPrivateResource(connection, instance);
410 break;
411 // Flash/trusted resources aren't needed for NaCl.
412 #if !defined(OS_NACL) && !defined(NACL_WIN64)
413 case BROWSER_FONT_SINGLETON_ID:
414 new_singleton = new BrowserFontSingletonResource(connection, instance);
415 break;
416 case FLASH_CLIPBOARD_SINGLETON_ID:
417 new_singleton = new FlashClipboardResource(connection, instance);
418 break;
419 case FLASH_FILE_SINGLETON_ID:
420 new_singleton = new FlashFileResource(connection, instance);
421 break;
422 case FLASH_FULLSCREEN_SINGLETON_ID:
423 new_singleton = new FlashFullscreenResource(connection, instance);
424 break;
425 case FLASH_SINGLETON_ID:
426 new_singleton = new FlashResource(connection, instance,
427 static_cast<PluginDispatcher*>(dispatcher()));
428 break;
429 case PDF_SINGLETON_ID:
430 new_singleton = new PDFResource(connection, instance);
431 break;
432 #else
433 case BROWSER_FONT_SINGLETON_ID:
434 case FLASH_CLIPBOARD_SINGLETON_ID:
435 case FLASH_FILE_SINGLETON_ID:
436 case FLASH_FULLSCREEN_SINGLETON_ID:
437 case FLASH_SINGLETON_ID:
438 case PDF_SINGLETON_ID:
439 NOTREACHED();
440 break;
441 #endif // !defined(OS_NACL) && !defined(NACL_WIN64)
444 if (!new_singleton.get()) {
445 // Getting here implies that a constructor is missing in the above switch.
446 NOTREACHED();
447 return NULL;
450 data->singleton_resources[id] = new_singleton;
451 return new_singleton.get();
454 int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance,
455 uint32_t event_classes) {
456 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
457 API_ID_PPB_INSTANCE, instance, false, event_classes));
459 // We always register for the classes we can handle, this function validates
460 // the flags so we can notify it if anything was invalid, without requiring
461 // a sync reply.
462 return ValidateRequestInputEvents(false, event_classes);
465 int32_t PPB_Instance_Proxy::RequestFilteringInputEvents(
466 PP_Instance instance,
467 uint32_t event_classes) {
468 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
469 API_ID_PPB_INSTANCE, instance, true, event_classes));
471 // We always register for the classes we can handle, this function validates
472 // the flags so we can notify it if anything was invalid, without requiring
473 // a sync reply.
474 return ValidateRequestInputEvents(true, event_classes);
477 void PPB_Instance_Proxy::ClearInputEventRequest(PP_Instance instance,
478 uint32_t event_classes) {
479 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ClearInputEvents(
480 API_ID_PPB_INSTANCE, instance, event_classes));
483 void PPB_Instance_Proxy::ZoomChanged(PP_Instance instance,
484 double factor) {
485 // Not proxied yet.
486 NOTIMPLEMENTED();
489 void PPB_Instance_Proxy::ZoomLimitsChanged(PP_Instance instance,
490 double minimum_factor,
491 double maximium_factor) {
492 // Not proxied yet.
493 NOTIMPLEMENTED();
496 PP_Var PPB_Instance_Proxy::GetDocumentURL(PP_Instance instance,
497 PP_URLComponents_Dev* components) {
498 ReceiveSerializedVarReturnValue result;
499 PP_URLComponents_Dev url_components;
500 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetDocumentURL(
501 API_ID_PPB_INSTANCE, instance, &url_components, &result));
502 if (components)
503 *components = url_components;
504 return result.Return(dispatcher());
507 #if !defined(OS_NACL)
508 PP_Var PPB_Instance_Proxy::ResolveRelativeToDocument(
509 PP_Instance instance,
510 PP_Var relative,
511 PP_URLComponents_Dev* components) {
512 ReceiveSerializedVarReturnValue result;
513 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ResolveRelativeToDocument(
514 API_ID_PPB_INSTANCE, instance,
515 SerializedVarSendInput(dispatcher(), relative),
516 &result));
517 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
518 result.Return(dispatcher()),
519 components);
522 PP_Bool PPB_Instance_Proxy::DocumentCanRequest(PP_Instance instance,
523 PP_Var url) {
524 PP_Bool result = PP_FALSE;
525 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanRequest(
526 API_ID_PPB_INSTANCE, instance,
527 SerializedVarSendInput(dispatcher(), url),
528 &result));
529 return result;
532 PP_Bool PPB_Instance_Proxy::DocumentCanAccessDocument(PP_Instance instance,
533 PP_Instance target) {
534 PP_Bool result = PP_FALSE;
535 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanAccessDocument(
536 API_ID_PPB_INSTANCE, instance, target, &result));
537 return result;
540 PP_Var PPB_Instance_Proxy::GetPluginInstanceURL(
541 PP_Instance instance,
542 PP_URLComponents_Dev* components) {
543 ReceiveSerializedVarReturnValue result;
544 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginInstanceURL(
545 API_ID_PPB_INSTANCE, instance, &result));
546 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
547 result.Return(dispatcher()),
548 components);
551 PP_Var PPB_Instance_Proxy::GetPluginReferrerURL(
552 PP_Instance instance,
553 PP_URLComponents_Dev* components) {
554 ReceiveSerializedVarReturnValue result;
555 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginReferrerURL(
556 API_ID_PPB_INSTANCE, instance, &result));
557 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
558 result.Return(dispatcher()),
559 components);
562 void PPB_Instance_Proxy::SessionCreated(PP_Instance instance,
563 uint32_t session_id,
564 PP_Var web_session_id) {
565 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionCreated(
566 API_ID_PPB_INSTANCE,
567 instance,
568 session_id,
569 SerializedVarSendInput(dispatcher(), web_session_id)));
572 void PPB_Instance_Proxy::SessionMessage(PP_Instance instance,
573 uint32_t session_id,
574 PP_Var message,
575 PP_Var destination_url) {
576 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionMessage(
577 API_ID_PPB_INSTANCE,
578 instance,
579 session_id,
580 SerializedVarSendInput(dispatcher(), message),
581 SerializedVarSendInput(dispatcher(), destination_url)));
584 void PPB_Instance_Proxy::SessionReady(PP_Instance instance,
585 uint32_t session_id) {
586 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionReady(
587 API_ID_PPB_INSTANCE, instance, session_id));
590 void PPB_Instance_Proxy::SessionClosed(PP_Instance instance,
591 uint32_t session_id) {
592 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionClosed(
593 API_ID_PPB_INSTANCE, instance, session_id));
596 void PPB_Instance_Proxy::SessionError(PP_Instance instance,
597 uint32_t session_id,
598 int32_t media_error,
599 uint32_t system_code) {
600 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionError(
601 API_ID_PPB_INSTANCE, instance, session_id, media_error, system_code));
604 void PPB_Instance_Proxy::DeliverBlock(PP_Instance instance,
605 PP_Resource decrypted_block,
606 const PP_DecryptedBlockInfo* block_info) {
607 PP_Resource decrypted_block_host_resource = 0;
609 if (decrypted_block) {
610 Resource* object =
611 PpapiGlobals::Get()->GetResourceTracker()->GetResource(decrypted_block);
612 if (!object || object->pp_instance() != instance) {
613 NOTREACHED();
614 return;
616 decrypted_block_host_resource = object->host_resource().host_resource();
619 std::string serialized_block_info;
620 if (!SerializeBlockInfo(*block_info, &serialized_block_info)) {
621 NOTREACHED();
622 return;
625 dispatcher()->Send(
626 new PpapiHostMsg_PPBInstance_DeliverBlock(API_ID_PPB_INSTANCE,
627 instance,
628 decrypted_block_host_resource,
629 serialized_block_info));
632 void PPB_Instance_Proxy::DecoderInitializeDone(
633 PP_Instance instance,
634 PP_DecryptorStreamType decoder_type,
635 uint32_t request_id,
636 PP_Bool success) {
637 dispatcher()->Send(
638 new PpapiHostMsg_PPBInstance_DecoderInitializeDone(
639 API_ID_PPB_INSTANCE,
640 instance,
641 decoder_type,
642 request_id,
643 success));
646 void PPB_Instance_Proxy::DecoderDeinitializeDone(
647 PP_Instance instance,
648 PP_DecryptorStreamType decoder_type,
649 uint32_t request_id) {
650 dispatcher()->Send(
651 new PpapiHostMsg_PPBInstance_DecoderDeinitializeDone(
652 API_ID_PPB_INSTANCE,
653 instance,
654 decoder_type,
655 request_id));
658 void PPB_Instance_Proxy::DecoderResetDone(PP_Instance instance,
659 PP_DecryptorStreamType decoder_type,
660 uint32_t request_id) {
661 dispatcher()->Send(
662 new PpapiHostMsg_PPBInstance_DecoderResetDone(
663 API_ID_PPB_INSTANCE,
664 instance,
665 decoder_type,
666 request_id));
669 void PPB_Instance_Proxy::DeliverFrame(PP_Instance instance,
670 PP_Resource decrypted_frame,
671 const PP_DecryptedFrameInfo* frame_info) {
672 PP_Resource host_resource = 0;
673 if (decrypted_frame != 0) {
674 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
675 Resource* object = tracker->GetResource(decrypted_frame);
677 if (!object || object->pp_instance() != instance) {
678 NOTREACHED();
679 return;
682 host_resource = object->host_resource().host_resource();
685 std::string serialized_frame_info;
686 if (!SerializeBlockInfo(*frame_info, &serialized_frame_info)) {
687 NOTREACHED();
688 return;
691 dispatcher()->Send(
692 new PpapiHostMsg_PPBInstance_DeliverFrame(API_ID_PPB_INSTANCE,
693 instance,
694 host_resource,
695 serialized_frame_info));
698 void PPB_Instance_Proxy::DeliverSamples(
699 PP_Instance instance,
700 PP_Resource decrypted_samples,
701 const PP_DecryptedSampleInfo* sample_info) {
702 PP_Resource host_resource = 0;
703 if (decrypted_samples != 0) {
704 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
705 Resource* object = tracker->GetResource(decrypted_samples);
707 if (!object || object->pp_instance() != instance) {
708 NOTREACHED();
709 return;
712 host_resource = object->host_resource().host_resource();
715 std::string serialized_sample_info;
716 if (!SerializeBlockInfo(*sample_info, &serialized_sample_info)) {
717 NOTREACHED();
718 return;
721 dispatcher()->Send(
722 new PpapiHostMsg_PPBInstance_DeliverSamples(API_ID_PPB_INSTANCE,
723 instance,
724 host_resource,
725 serialized_sample_info));
727 #endif // !defined(OS_NACL)
729 void PPB_Instance_Proxy::PostMessage(PP_Instance instance,
730 PP_Var message) {
731 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage(
732 API_ID_PPB_INSTANCE,
733 instance, SerializedVarSendInputShmem(dispatcher(), message,
734 instance)));
737 PP_Bool PPB_Instance_Proxy::SetCursor(PP_Instance instance,
738 PP_MouseCursor_Type type,
739 PP_Resource image,
740 const PP_Point* hot_spot) {
741 // Some of these parameters are important for security. This check is in the
742 // plugin process just for the convenience of the caller (since we don't
743 // bother returning errors from the other process with a sync message). The
744 // parameters will be validated again in the renderer.
745 if (!ValidateSetCursorParams(type, image, hot_spot))
746 return PP_FALSE;
748 HostResource image_host_resource;
749 if (image) {
750 Resource* cursor_image =
751 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image);
752 if (!cursor_image || cursor_image->pp_instance() != instance)
753 return PP_FALSE;
754 image_host_resource = cursor_image->host_resource();
757 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetCursor(
758 API_ID_PPB_INSTANCE, instance, static_cast<int32_t>(type),
759 image_host_resource, hot_spot ? *hot_spot : PP_MakePoint(0, 0)));
760 return PP_TRUE;
763 int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance,
764 scoped_refptr<TrackedCallback> callback) {
765 // Save the mouse callback on the instance data.
766 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
767 GetInstanceData(instance);
768 if (!data)
769 return PP_ERROR_BADARGUMENT;
770 if (TrackedCallback::IsPending(data->mouse_lock_callback))
771 return PP_ERROR_INPROGRESS; // Already have a pending callback.
772 data->mouse_lock_callback = callback;
774 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LockMouse(
775 API_ID_PPB_INSTANCE, instance));
776 return PP_OK_COMPLETIONPENDING;
779 void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance) {
780 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UnlockMouse(
781 API_ID_PPB_INSTANCE, instance));
784 void PPB_Instance_Proxy::SetTextInputType(PP_Instance instance,
785 PP_TextInput_Type type) {
786 CancelAnyPendingRequestSurroundingText(instance);
787 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTextInputType(
788 API_ID_PPB_INSTANCE, instance, type));
791 void PPB_Instance_Proxy::UpdateCaretPosition(PP_Instance instance,
792 const PP_Rect& caret,
793 const PP_Rect& bounding_box) {
794 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateCaretPosition(
795 API_ID_PPB_INSTANCE, instance, caret, bounding_box));
798 void PPB_Instance_Proxy::CancelCompositionText(PP_Instance instance) {
799 CancelAnyPendingRequestSurroundingText(instance);
800 dispatcher()->Send(new PpapiHostMsg_PPBInstance_CancelCompositionText(
801 API_ID_PPB_INSTANCE, instance));
804 void PPB_Instance_Proxy::SelectionChanged(PP_Instance instance) {
805 // The "right" way to do this is to send the message to the host. However,
806 // all it will do is call RequestSurroundingText with a hardcoded number of
807 // characters in response, which is an entire IPC round-trip.
809 // We can avoid this round-trip by just implementing the
810 // RequestSurroundingText logic in the plugin process. If the logic in the
811 // host becomes more complex (like a more adaptive number of characters),
812 // we'll need to reevanuate whether we want to do the round trip instead.
814 // Be careful to post a task to avoid reentering the plugin.
816 InstanceData* data =
817 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
818 if (!data)
819 return;
820 data->should_do_request_surrounding_text = true;
822 if (!data->is_request_surrounding_text_pending) {
823 base::MessageLoop::current()->PostTask(
824 FROM_HERE,
825 RunWhileLocked(base::Bind(&RequestSurroundingText, instance)));
826 data->is_request_surrounding_text_pending = true;
830 void PPB_Instance_Proxy::UpdateSurroundingText(PP_Instance instance,
831 const char* text,
832 uint32_t caret,
833 uint32_t anchor) {
834 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateSurroundingText(
835 API_ID_PPB_INSTANCE, instance, text, caret, anchor));
838 #if !defined(OS_NACL)
839 void PPB_Instance_Proxy::OnHostMsgGetWindowObject(
840 PP_Instance instance,
841 SerializedVarReturnValue result) {
842 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
843 return;
844 EnterInstanceNoLock enter(instance);
845 if (enter.succeeded())
846 result.Return(dispatcher(), enter.functions()->GetWindowObject(instance));
849 void PPB_Instance_Proxy::OnHostMsgGetOwnerElementObject(
850 PP_Instance instance,
851 SerializedVarReturnValue result) {
852 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
853 return;
854 EnterInstanceNoLock enter(instance);
855 if (enter.succeeded()) {
856 result.Return(dispatcher(),
857 enter.functions()->GetOwnerElementObject(instance));
861 void PPB_Instance_Proxy::OnHostMsgBindGraphics(PP_Instance instance,
862 PP_Resource device) {
863 // Note that we ignroe the return value here. Otherwise, this would need to
864 // be a slow sync call, and the plugin side of the proxy will have already
865 // validated the resources, so we shouldn't see errors here that weren't
866 // already caught.
867 EnterInstanceNoLock enter(instance);
868 if (enter.succeeded())
869 enter.functions()->BindGraphics(instance, device);
872 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputSampleRate(
873 PP_Instance instance, uint32_t* result) {
874 EnterInstanceNoLock enter(instance);
875 if (enter.succeeded())
876 *result = enter.functions()->GetAudioHardwareOutputSampleRate(instance);
879 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputBufferSize(
880 PP_Instance instance, uint32_t* result) {
881 EnterInstanceNoLock enter(instance);
882 if (enter.succeeded())
883 *result = enter.functions()->GetAudioHardwareOutputBufferSize(instance);
886 void PPB_Instance_Proxy::OnHostMsgIsFullFrame(PP_Instance instance,
887 PP_Bool* result) {
888 EnterInstanceNoLock enter(instance);
889 if (enter.succeeded())
890 *result = enter.functions()->IsFullFrame(instance);
893 void PPB_Instance_Proxy::OnHostMsgExecuteScript(
894 PP_Instance instance,
895 SerializedVarReceiveInput script,
896 SerializedVarOutParam out_exception,
897 SerializedVarReturnValue result) {
898 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
899 return;
900 EnterInstanceNoLock enter(instance);
901 if (enter.failed())
902 return;
904 if (dispatcher()->IsPlugin())
905 NOTREACHED();
906 else
907 static_cast<HostDispatcher*>(dispatcher())->set_allow_plugin_reentrancy();
909 result.Return(dispatcher(), enter.functions()->ExecuteScript(
910 instance,
911 script.Get(dispatcher()),
912 out_exception.OutParam(dispatcher())));
915 void PPB_Instance_Proxy::OnHostMsgGetDefaultCharSet(
916 PP_Instance instance,
917 SerializedVarReturnValue result) {
918 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
919 return;
920 EnterInstanceNoLock enter(instance);
921 if (enter.succeeded())
922 result.Return(dispatcher(), enter.functions()->GetDefaultCharSet(instance));
925 void PPB_Instance_Proxy::OnHostMsgSetPluginToHandleFindRequests(
926 PP_Instance instance) {
927 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
928 return;
929 EnterInstanceNoLock enter(instance);
930 if (enter.succeeded())
931 enter.functions()->SetPluginToHandleFindRequests(instance);
934 void PPB_Instance_Proxy::OnHostMsgNumberOfFindResultsChanged(
935 PP_Instance instance,
936 int32_t total,
937 PP_Bool final_result) {
938 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
939 return;
940 EnterInstanceNoLock enter(instance);
941 if (enter.succeeded()) {
942 enter.functions()->NumberOfFindResultsChanged(
943 instance, total, final_result);
947 void PPB_Instance_Proxy::OnHostMsgSelectFindResultChanged(
948 PP_Instance instance,
949 int32_t index) {
950 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
951 return;
952 EnterInstanceNoLock enter(instance);
953 if (enter.succeeded())
954 enter.functions()->SelectedFindResultChanged(instance, index);
957 void PPB_Instance_Proxy::OnHostMsgSetTickmarks(
958 PP_Instance instance,
959 const std::vector<PP_Rect>& tickmarks) {
960 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
961 return;
962 const PP_Rect* array = tickmarks.empty() ? NULL : &tickmarks[0];
963 EnterInstanceNoLock enter(instance);
964 if (enter.succeeded()) {
965 enter.functions()->SetTickmarks(instance,
966 array,
967 static_cast<uint32_t>(tickmarks.size()));
971 void PPB_Instance_Proxy::OnHostMsgSetFullscreen(PP_Instance instance,
972 PP_Bool fullscreen,
973 PP_Bool* result) {
974 EnterInstanceNoLock enter(instance);
975 if (enter.succeeded())
976 *result = enter.functions()->SetFullscreen(instance, fullscreen);
980 void PPB_Instance_Proxy::OnHostMsgGetScreenSize(PP_Instance instance,
981 PP_Bool* result,
982 PP_Size* size) {
983 EnterInstanceNoLock enter(instance);
984 if (enter.succeeded())
985 *result = enter.functions()->GetScreenSize(instance, size);
988 void PPB_Instance_Proxy::OnHostMsgRequestInputEvents(PP_Instance instance,
989 bool is_filtering,
990 uint32_t event_classes) {
991 EnterInstanceNoLock enter(instance);
992 if (enter.succeeded()) {
993 if (is_filtering)
994 enter.functions()->RequestFilteringInputEvents(instance, event_classes);
995 else
996 enter.functions()->RequestInputEvents(instance, event_classes);
1000 void PPB_Instance_Proxy::OnHostMsgClearInputEvents(PP_Instance instance,
1001 uint32_t event_classes) {
1002 EnterInstanceNoLock enter(instance);
1003 if (enter.succeeded())
1004 enter.functions()->ClearInputEventRequest(instance, event_classes);
1007 void PPB_Instance_Proxy::OnHostMsgPostMessage(
1008 PP_Instance instance,
1009 SerializedVarReceiveInput message) {
1010 EnterInstanceNoLock enter(instance);
1011 if (!message.is_valid_var()) {
1012 PpapiGlobals::Get()->LogWithSource(
1013 instance, PP_LOGLEVEL_ERROR, std::string(), kSerializationError);
1014 return;
1017 if (enter.succeeded())
1018 enter.functions()->PostMessage(instance,
1019 message.GetForInstance(dispatcher(),
1020 instance));
1023 void PPB_Instance_Proxy::OnHostMsgLockMouse(PP_Instance instance) {
1024 // Need to be careful to always issue the callback.
1025 pp::CompletionCallback cb = callback_factory_.NewCallback(
1026 &PPB_Instance_Proxy::MouseLockCompleteInHost, instance);
1028 EnterInstanceNoLock enter(instance, cb.pp_completion_callback());
1029 if (enter.succeeded())
1030 enter.SetResult(enter.functions()->LockMouse(instance, enter.callback()));
1033 void PPB_Instance_Proxy::OnHostMsgUnlockMouse(PP_Instance instance) {
1034 EnterInstanceNoLock enter(instance);
1035 if (enter.succeeded())
1036 enter.functions()->UnlockMouse(instance);
1039 void PPB_Instance_Proxy::OnHostMsgGetDocumentURL(
1040 PP_Instance instance,
1041 PP_URLComponents_Dev* components,
1042 SerializedVarReturnValue result) {
1043 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1044 return;
1045 EnterInstanceNoLock enter(instance);
1046 if (enter.succeeded()) {
1047 PP_Var document_url = enter.functions()->GetDocumentURL(instance,
1048 components);
1049 result.Return(dispatcher(), document_url);
1053 void PPB_Instance_Proxy::OnHostMsgResolveRelativeToDocument(
1054 PP_Instance instance,
1055 SerializedVarReceiveInput relative,
1056 SerializedVarReturnValue result) {
1057 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1058 return;
1059 EnterInstanceNoLock enter(instance);
1060 if (enter.succeeded()) {
1061 result.Return(dispatcher(),
1062 enter.functions()->ResolveRelativeToDocument(
1063 instance, relative.Get(dispatcher()), NULL));
1067 void PPB_Instance_Proxy::OnHostMsgDocumentCanRequest(
1068 PP_Instance instance,
1069 SerializedVarReceiveInput url,
1070 PP_Bool* result) {
1071 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1072 return;
1073 EnterInstanceNoLock enter(instance);
1074 if (enter.succeeded()) {
1075 *result = enter.functions()->DocumentCanRequest(instance,
1076 url.Get(dispatcher()));
1080 void PPB_Instance_Proxy::OnHostMsgDocumentCanAccessDocument(PP_Instance active,
1081 PP_Instance target,
1082 PP_Bool* result) {
1083 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1084 return;
1085 EnterInstanceNoLock enter(active);
1086 if (enter.succeeded())
1087 *result = enter.functions()->DocumentCanAccessDocument(active, target);
1090 void PPB_Instance_Proxy::OnHostMsgGetPluginInstanceURL(
1091 PP_Instance instance,
1092 SerializedVarReturnValue result) {
1093 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1094 return;
1095 EnterInstanceNoLock enter(instance);
1096 if (enter.succeeded()) {
1097 result.Return(dispatcher(),
1098 enter.functions()->GetPluginInstanceURL(instance, NULL));
1102 void PPB_Instance_Proxy::OnHostMsgGetPluginReferrerURL(
1103 PP_Instance instance,
1104 SerializedVarReturnValue result) {
1105 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1106 return;
1107 EnterInstanceNoLock enter(instance);
1108 if (enter.succeeded()) {
1109 result.Return(dispatcher(),
1110 enter.functions()->GetPluginReferrerURL(instance, NULL));
1114 void PPB_Instance_Proxy::OnHostMsgSessionCreated(
1115 PP_Instance instance,
1116 uint32_t session_id,
1117 SerializedVarReceiveInput web_session_id) {
1118 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1119 return;
1120 EnterInstanceNoLock enter(instance);
1121 if (enter.succeeded()) {
1122 enter.functions()->SessionCreated(
1123 instance, session_id, web_session_id.Get(dispatcher()));
1127 void PPB_Instance_Proxy::OnHostMsgSessionMessage(
1128 PP_Instance instance,
1129 uint32_t session_id,
1130 SerializedVarReceiveInput message,
1131 SerializedVarReceiveInput destination_url) {
1132 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1133 return;
1134 EnterInstanceNoLock enter(instance);
1135 if (enter.succeeded()) {
1136 enter.functions()->SessionMessage(instance,
1137 session_id,
1138 message.Get(dispatcher()),
1139 destination_url.Get(dispatcher()));
1143 void PPB_Instance_Proxy::OnHostMsgSessionReady(PP_Instance instance,
1144 uint32_t session_id) {
1145 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1146 return;
1147 EnterInstanceNoLock enter(instance);
1148 if (enter.succeeded()) {
1149 enter.functions()->SessionReady(instance, session_id);
1153 void PPB_Instance_Proxy::OnHostMsgSessionClosed(PP_Instance instance,
1154 uint32_t session_id) {
1155 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1156 return;
1157 EnterInstanceNoLock enter(instance);
1158 if (enter.succeeded()) {
1159 enter.functions()->SessionClosed(instance, session_id);
1163 void PPB_Instance_Proxy::OnHostMsgSessionError(PP_Instance instance,
1164 uint32_t session_id,
1165 int32_t media_error,
1166 uint32_t system_code) {
1167 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1168 return;
1169 EnterInstanceNoLock enter(instance);
1170 if (enter.succeeded()) {
1171 enter.functions()->SessionError(
1172 instance, session_id, media_error, system_code);
1176 void PPB_Instance_Proxy::OnHostMsgDeliverBlock(
1177 PP_Instance instance,
1178 PP_Resource decrypted_block,
1179 const std::string& serialized_block_info) {
1180 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1181 return;
1182 PP_DecryptedBlockInfo block_info;
1183 if (!DeserializeBlockInfo(serialized_block_info, &block_info))
1184 return;
1186 EnterInstanceNoLock enter(instance);
1187 if (enter.succeeded())
1188 enter.functions()->DeliverBlock(instance, decrypted_block, &block_info);
1191 void PPB_Instance_Proxy::OnHostMsgDecoderInitializeDone(
1192 PP_Instance instance,
1193 PP_DecryptorStreamType decoder_type,
1194 uint32_t request_id,
1195 PP_Bool success) {
1196 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1197 return;
1198 EnterInstanceNoLock enter(instance);
1199 if (enter.succeeded()) {
1200 enter.functions()->DecoderInitializeDone(instance,
1201 decoder_type,
1202 request_id,
1203 success);
1207 void PPB_Instance_Proxy::OnHostMsgDecoderDeinitializeDone(
1208 PP_Instance instance,
1209 PP_DecryptorStreamType decoder_type,
1210 uint32_t request_id) {
1211 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1212 return;
1213 EnterInstanceNoLock enter(instance);
1214 if (enter.succeeded())
1215 enter.functions()->DecoderDeinitializeDone(instance,
1216 decoder_type,
1217 request_id);
1220 void PPB_Instance_Proxy::OnHostMsgDecoderResetDone(
1221 PP_Instance instance,
1222 PP_DecryptorStreamType decoder_type,
1223 uint32_t request_id) {
1224 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1225 return;
1226 EnterInstanceNoLock enter(instance);
1227 if (enter.succeeded())
1228 enter.functions()->DecoderResetDone(instance, decoder_type, request_id);
1231 void PPB_Instance_Proxy::OnHostMsgDeliverFrame(
1232 PP_Instance instance,
1233 PP_Resource decrypted_frame,
1234 const std::string& serialized_frame_info) {
1235 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1236 return;
1237 PP_DecryptedFrameInfo frame_info;
1238 if (!DeserializeBlockInfo(serialized_frame_info, &frame_info))
1239 return;
1241 EnterInstanceNoLock enter(instance);
1242 if (enter.succeeded())
1243 enter.functions()->DeliverFrame(instance, decrypted_frame, &frame_info);
1246 void PPB_Instance_Proxy::OnHostMsgDeliverSamples(
1247 PP_Instance instance,
1248 PP_Resource audio_frames,
1249 const std::string& serialized_sample_info) {
1250 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1251 return;
1252 PP_DecryptedSampleInfo sample_info;
1253 if (!DeserializeBlockInfo(serialized_sample_info, &sample_info))
1254 return;
1256 EnterInstanceNoLock enter(instance);
1257 if (enter.succeeded())
1258 enter.functions()->DeliverSamples(instance, audio_frames, &sample_info);
1261 void PPB_Instance_Proxy::OnHostMsgSetCursor(
1262 PP_Instance instance,
1263 int32_t type,
1264 const ppapi::HostResource& custom_image,
1265 const PP_Point& hot_spot) {
1266 // This API serves PPB_CursorControl_Dev and PPB_MouseCursor, so is public.
1267 EnterInstanceNoLock enter(instance);
1268 if (enter.succeeded()) {
1269 enter.functions()->SetCursor(
1270 instance, static_cast<PP_MouseCursor_Type>(type),
1271 custom_image.host_resource(), &hot_spot);
1275 void PPB_Instance_Proxy::OnHostMsgSetTextInputType(PP_Instance instance,
1276 PP_TextInput_Type type) {
1277 EnterInstanceNoLock enter(instance);
1278 if (enter.succeeded())
1279 enter.functions()->SetTextInputType(instance, type);
1282 void PPB_Instance_Proxy::OnHostMsgUpdateCaretPosition(
1283 PP_Instance instance,
1284 const PP_Rect& caret,
1285 const PP_Rect& bounding_box) {
1286 EnterInstanceNoLock enter(instance);
1287 if (enter.succeeded())
1288 enter.functions()->UpdateCaretPosition(instance, caret, bounding_box);
1291 void PPB_Instance_Proxy::OnHostMsgCancelCompositionText(PP_Instance instance) {
1292 EnterInstanceNoLock enter(instance);
1293 if (enter.succeeded())
1294 enter.functions()->CancelCompositionText(instance);
1297 void PPB_Instance_Proxy::OnHostMsgUpdateSurroundingText(
1298 PP_Instance instance,
1299 const std::string& text,
1300 uint32_t caret,
1301 uint32_t anchor) {
1302 EnterInstanceNoLock enter(instance);
1303 if (enter.succeeded()) {
1304 enter.functions()->UpdateSurroundingText(instance, text.c_str(), caret,
1305 anchor);
1308 #endif // !defined(OS_NACL)
1310 void PPB_Instance_Proxy::OnPluginMsgMouseLockComplete(PP_Instance instance,
1311 int32_t result) {
1312 if (!dispatcher()->IsPlugin())
1313 return;
1315 // Save the mouse callback on the instance data.
1316 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1317 GetInstanceData(instance);
1318 if (!data)
1319 return; // Instance was probably deleted.
1320 if (!TrackedCallback::IsPending(data->mouse_lock_callback)) {
1321 NOTREACHED();
1322 return;
1324 data->mouse_lock_callback->Run(result);
1327 #if !defined(OS_NACL)
1328 void PPB_Instance_Proxy::MouseLockCompleteInHost(int32_t result,
1329 PP_Instance instance) {
1330 dispatcher()->Send(new PpapiMsg_PPBInstance_MouseLockComplete(
1331 API_ID_PPB_INSTANCE, instance, result));
1333 #endif // !defined(OS_NACL)
1335 void PPB_Instance_Proxy::CancelAnyPendingRequestSurroundingText(
1336 PP_Instance instance) {
1337 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1338 GetInstanceData(instance);
1339 if (!data)
1340 return; // Instance was probably deleted.
1341 data->should_do_request_surrounding_text = false;
1344 } // namespace proxy
1345 } // namespace ppapi