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 "base/numerics/safe_conversions.h"
9 #include "base/stl_util.h"
10 #include "build/build_config.h"
11 #include "media/base/limits.h"
12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/c/pp_time.h"
14 #include "ppapi/c/pp_var.h"
15 #include "ppapi/c/ppb_audio_config.h"
16 #include "ppapi/c/ppb_instance.h"
17 #include "ppapi/c/ppb_messaging.h"
18 #include "ppapi/c/ppb_mouse_lock.h"
19 #include "ppapi/c/private/pp_content_decryptor.h"
20 #include "ppapi/proxy/broker_resource.h"
21 #include "ppapi/proxy/browser_font_singleton_resource.h"
22 #include "ppapi/proxy/content_decryptor_private_serializer.h"
23 #include "ppapi/proxy/enter_proxy.h"
24 #include "ppapi/proxy/flash_clipboard_resource.h"
25 #include "ppapi/proxy/flash_file_resource.h"
26 #include "ppapi/proxy/flash_fullscreen_resource.h"
27 #include "ppapi/proxy/flash_resource.h"
28 #include "ppapi/proxy/gamepad_resource.h"
29 #include "ppapi/proxy/host_dispatcher.h"
30 #include "ppapi/proxy/isolated_file_system_private_resource.h"
31 #include "ppapi/proxy/message_handler.h"
32 #include "ppapi/proxy/network_proxy_resource.h"
33 #include "ppapi/proxy/pdf_resource.h"
34 #include "ppapi/proxy/plugin_dispatcher.h"
35 #include "ppapi/proxy/ppapi_messages.h"
36 #include "ppapi/proxy/serialized_var.h"
37 #include "ppapi/proxy/truetype_font_singleton_resource.h"
38 #include "ppapi/proxy/uma_private_resource.h"
39 #include "ppapi/shared_impl/array_var.h"
40 #include "ppapi/shared_impl/ppapi_globals.h"
41 #include "ppapi/shared_impl/ppb_url_util_shared.h"
42 #include "ppapi/shared_impl/ppb_view_shared.h"
43 #include "ppapi/shared_impl/scoped_pp_var.h"
44 #include "ppapi/shared_impl/var.h"
45 #include "ppapi/thunk/enter.h"
46 #include "ppapi/thunk/ppb_compositor_api.h"
47 #include "ppapi/thunk/ppb_graphics_2d_api.h"
48 #include "ppapi/thunk/ppb_graphics_3d_api.h"
49 #include "ppapi/thunk/thunk.h"
51 // Windows headers interfere with this file.
56 using ppapi::thunk::EnterInstanceNoLock
;
57 using ppapi::thunk::EnterResourceNoLock
;
58 using ppapi::thunk::PPB_Compositor_API
;
59 using ppapi::thunk::PPB_Graphics2D_API
;
60 using ppapi::thunk::PPB_Graphics3D_API
;
61 using ppapi::thunk::PPB_Instance_API
;
69 const char kSerializationError
[] = "Failed to convert a PostMessage "
70 "argument from a PP_Var to a Javascript value. It may have cycles or be of "
71 "an unsupported type.";
74 void RequestSurroundingText(PP_Instance instance
) {
75 PluginDispatcher
* dispatcher
= PluginDispatcher::GetForInstance(instance
);
77 return; // Instance has gone away while message was pending.
79 InstanceData
* data
= dispatcher
->GetInstanceData(instance
);
80 DCHECK(data
); // Should have it, since we still have a dispatcher.
81 data
->is_request_surrounding_text_pending
= false;
82 if (!data
->should_do_request_surrounding_text
)
85 // Just fake out a RequestSurroundingText message to the proxy for the PPP
87 InterfaceProxy
* proxy
= dispatcher
->GetInterfaceProxy(API_ID_PPP_TEXT_INPUT
);
90 proxy
->OnMessageReceived(PpapiMsg_PPPTextInput_RequestSurroundingText(
91 API_ID_PPP_TEXT_INPUT
, instance
,
92 PPB_Instance_Shared::kExtraCharsForTextInput
));
97 PPB_Instance_Proxy::PPB_Instance_Proxy(Dispatcher
* dispatcher
)
98 : InterfaceProxy(dispatcher
),
99 callback_factory_(this) {
102 PPB_Instance_Proxy::~PPB_Instance_Proxy() {
105 bool PPB_Instance_Proxy::OnMessageReceived(const IPC::Message
& msg
) {
106 // Prevent the dispatcher from going away during a call to ExecuteScript.
107 // This must happen OUTSIDE of ExecuteScript since the SerializedVars use
108 // the dispatcher upon return of the function (converting the
109 // SerializedVarReturnValue/OutParam to a SerializedVar in the destructor).
110 #if !defined(OS_NACL)
111 ScopedModuleReference
death_grip(dispatcher());
115 IPC_BEGIN_MESSAGE_MAP(PPB_Instance_Proxy
, msg
)
116 #if !defined(OS_NACL)
117 // Plugin -> Host messages.
118 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetWindowObject
,
119 OnHostMsgGetWindowObject
)
120 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetOwnerElementObject
,
121 OnHostMsgGetOwnerElementObject
)
122 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_BindGraphics
,
123 OnHostMsgBindGraphics
)
124 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_IsFullFrame
,
125 OnHostMsgIsFullFrame
)
127 PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate
,
128 OnHostMsgGetAudioHardwareOutputSampleRate
)
130 PpapiHostMsg_PPBInstance_GetAudioHardwareOutputBufferSize
,
131 OnHostMsgGetAudioHardwareOutputBufferSize
)
132 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ExecuteScript
,
133 OnHostMsgExecuteScript
)
134 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDefaultCharSet
,
135 OnHostMsgGetDefaultCharSet
)
136 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetPluginToHandleFindRequests
,
137 OnHostMsgSetPluginToHandleFindRequests
);
138 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_NumberOfFindResultsChanged
,
139 OnHostMsgNumberOfFindResultsChanged
)
140 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SelectFindResultChanged
,
141 OnHostMsgSelectFindResultChanged
)
142 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetTickmarks
,
143 OnHostMsgSetTickmarks
)
144 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PostMessage
,
145 OnHostMsgPostMessage
)
146 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetFullscreen
,
147 OnHostMsgSetFullscreen
)
148 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetScreenSize
,
149 OnHostMsgGetScreenSize
)
150 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_RequestInputEvents
,
151 OnHostMsgRequestInputEvents
)
152 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ClearInputEvents
,
153 OnHostMsgClearInputEvents
)
154 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_LockMouse
,
156 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UnlockMouse
,
157 OnHostMsgUnlockMouse
)
158 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetCursor
,
160 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetTextInputType
,
161 OnHostMsgSetTextInputType
)
162 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UpdateCaretPosition
,
163 OnHostMsgUpdateCaretPosition
)
164 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_CancelCompositionText
,
165 OnHostMsgCancelCompositionText
)
166 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UpdateSurroundingText
,
167 OnHostMsgUpdateSurroundingText
)
168 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDocumentURL
,
169 OnHostMsgGetDocumentURL
)
170 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ResolveRelativeToDocument
,
171 OnHostMsgResolveRelativeToDocument
)
172 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanRequest
,
173 OnHostMsgDocumentCanRequest
)
174 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanAccessDocument
,
175 OnHostMsgDocumentCanAccessDocument
)
176 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginInstanceURL
,
177 OnHostMsgGetPluginInstanceURL
)
178 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginReferrerURL
,
179 OnHostMsgGetPluginReferrerURL
)
180 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PromiseResolved
,
181 OnHostMsgPromiseResolved
)
182 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PromiseResolvedWithSession
,
183 OnHostMsgPromiseResolvedWithSession
)
184 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PromiseRejected
,
185 OnHostMsgPromiseRejected
)
186 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionMessage
,
187 OnHostMsgSessionMessage
)
188 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionKeysChange
,
189 OnHostMsgSessionKeysChange
)
190 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionExpirationChange
,
191 OnHostMsgSessionExpirationChange
)
192 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionClosed
,
193 OnHostMsgSessionClosed
)
194 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_LegacySessionError
,
195 OnHostMsgLegacySessionError
)
196 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverBlock
,
197 OnHostMsgDeliverBlock
)
198 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderInitializeDone
,
199 OnHostMsgDecoderInitializeDone
)
200 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderDeinitializeDone
,
201 OnHostMsgDecoderDeinitializeDone
)
202 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderResetDone
,
203 OnHostMsgDecoderResetDone
)
204 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverFrame
,
205 OnHostMsgDeliverFrame
)
206 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverSamples
,
207 OnHostMsgDeliverSamples
)
208 #endif // !defined(OS_NACL)
210 // Host -> Plugin messages.
211 IPC_MESSAGE_HANDLER(PpapiMsg_PPBInstance_MouseLockComplete
,
212 OnPluginMsgMouseLockComplete
)
214 IPC_MESSAGE_UNHANDLED(handled
= false)
215 IPC_END_MESSAGE_MAP()
219 PP_Bool
PPB_Instance_Proxy::BindGraphics(PP_Instance instance
,
220 PP_Resource device
) {
221 // If device is 0, pass a null HostResource. This signals the host to unbind
223 PP_Resource pp_resource
= 0;
226 PpapiGlobals::Get()->GetResourceTracker()->GetResource(device
);
227 if (!resource
|| resource
->pp_instance() != instance
)
229 // We need to pass different resource to Graphics 2D, 3D and Compositor
230 // right now. Once 3D is migrated to the new design, we should be able to
232 if (resource
->AsPPB_Graphics3D_API()) {
233 pp_resource
= resource
->host_resource().host_resource();
234 } else if (resource
->AsPPB_Graphics2D_API() ||
235 resource
->AsPPB_Compositor_API()) {
236 pp_resource
= resource
->pp_resource();
242 dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
243 API_ID_PPB_INSTANCE
, instance
, pp_resource
));
247 PP_Bool
PPB_Instance_Proxy::IsFullFrame(PP_Instance instance
) {
248 PP_Bool result
= PP_FALSE
;
249 dispatcher()->Send(new PpapiHostMsg_PPBInstance_IsFullFrame(
250 API_ID_PPB_INSTANCE
, instance
, &result
));
254 const ViewData
* PPB_Instance_Proxy::GetViewData(PP_Instance instance
) {
255 InstanceData
* data
= static_cast<PluginDispatcher
*>(dispatcher())->
256 GetInstanceData(instance
);
262 PP_Bool
PPB_Instance_Proxy::FlashIsFullscreen(PP_Instance instance
) {
263 // This function is only used for proxying in the renderer process. It is not
264 // implemented in the plugin process.
269 PP_Var
PPB_Instance_Proxy::GetWindowObject(PP_Instance instance
) {
270 ReceiveSerializedVarReturnValue result
;
271 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetWindowObject(
272 API_ID_PPB_INSTANCE
, instance
, &result
));
273 return result
.Return(dispatcher());
276 PP_Var
PPB_Instance_Proxy::GetOwnerElementObject(PP_Instance instance
) {
277 ReceiveSerializedVarReturnValue result
;
278 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetOwnerElementObject(
279 API_ID_PPB_INSTANCE
, instance
, &result
));
280 return result
.Return(dispatcher());
283 PP_Var
PPB_Instance_Proxy::ExecuteScript(PP_Instance instance
,
286 ReceiveSerializedException
se(dispatcher(), exception
);
288 return PP_MakeUndefined();
290 ReceiveSerializedVarReturnValue result
;
291 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ExecuteScript(
292 API_ID_PPB_INSTANCE
, instance
,
293 SerializedVarSendInput(dispatcher(), script
), &se
, &result
));
294 return result
.Return(dispatcher());
297 uint32_t PPB_Instance_Proxy::GetAudioHardwareOutputSampleRate(
298 PP_Instance instance
) {
299 uint32_t result
= PP_AUDIOSAMPLERATE_NONE
;
301 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate(
302 API_ID_PPB_INSTANCE
, instance
, &result
));
306 uint32_t PPB_Instance_Proxy::GetAudioHardwareOutputBufferSize(
307 PP_Instance instance
) {
310 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputBufferSize(
311 API_ID_PPB_INSTANCE
, instance
, &result
));
315 PP_Var
PPB_Instance_Proxy::GetDefaultCharSet(PP_Instance instance
) {
316 PluginDispatcher
* dispatcher
= PluginDispatcher::GetForInstance(instance
);
318 return PP_MakeUndefined();
320 ReceiveSerializedVarReturnValue result
;
321 dispatcher
->Send(new PpapiHostMsg_PPBInstance_GetDefaultCharSet(
322 API_ID_PPB_INSTANCE
, instance
, &result
));
323 return result
.Return(dispatcher
);
326 void PPB_Instance_Proxy::SetPluginToHandleFindRequests(PP_Instance instance
) {
327 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetPluginToHandleFindRequests(
328 API_ID_PPB_INSTANCE
, instance
));
331 void PPB_Instance_Proxy::NumberOfFindResultsChanged(PP_Instance instance
,
333 PP_Bool final_result
) {
334 dispatcher()->Send(new PpapiHostMsg_PPBInstance_NumberOfFindResultsChanged(
335 API_ID_PPB_INSTANCE
, instance
, total
, final_result
));
338 void PPB_Instance_Proxy::SelectedFindResultChanged(PP_Instance instance
,
340 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SelectFindResultChanged(
341 API_ID_PPB_INSTANCE
, instance
, index
));
344 void PPB_Instance_Proxy::SetTickmarks(PP_Instance instance
,
345 const PP_Rect
* tickmarks
,
347 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTickmarks(
348 API_ID_PPB_INSTANCE
, instance
,
349 std::vector
<PP_Rect
>(tickmarks
, tickmarks
+ count
)));
352 PP_Bool
PPB_Instance_Proxy::IsFullscreen(PP_Instance instance
) {
353 InstanceData
* data
= static_cast<PluginDispatcher
*>(dispatcher())->
354 GetInstanceData(instance
);
357 return PP_FromBool(data
->view
.is_fullscreen
);
360 PP_Bool
PPB_Instance_Proxy::SetFullscreen(PP_Instance instance
,
361 PP_Bool fullscreen
) {
362 PP_Bool result
= PP_FALSE
;
363 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetFullscreen(
364 API_ID_PPB_INSTANCE
, instance
, fullscreen
, &result
));
368 PP_Bool
PPB_Instance_Proxy::GetScreenSize(PP_Instance instance
,
370 PP_Bool result
= PP_FALSE
;
371 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetScreenSize(
372 API_ID_PPB_INSTANCE
, instance
, &result
, size
));
376 Resource
* PPB_Instance_Proxy::GetSingletonResource(PP_Instance instance
,
377 SingletonResourceID id
) {
378 InstanceData
* data
= static_cast<PluginDispatcher
*>(dispatcher())->
379 GetInstanceData(instance
);
381 InstanceData::SingletonResourceMap::iterator it
=
382 data
->singleton_resources
.find(id
);
383 if (it
!= data
->singleton_resources
.end())
384 return it
->second
.get();
386 scoped_refptr
<Resource
> new_singleton
;
387 Connection
connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher());
390 case BROKER_SINGLETON_ID
:
391 new_singleton
= new BrokerResource(connection
, instance
);
393 case GAMEPAD_SINGLETON_ID
:
394 new_singleton
= new GamepadResource(connection
, instance
);
396 case ISOLATED_FILESYSTEM_SINGLETON_ID
:
398 new IsolatedFileSystemPrivateResource(connection
, instance
);
400 case NETWORK_PROXY_SINGLETON_ID
:
401 new_singleton
= new NetworkProxyResource(connection
, instance
);
403 case TRUETYPE_FONT_SINGLETON_ID
:
404 new_singleton
= new TrueTypeFontSingletonResource(connection
, instance
);
406 case UMA_SINGLETON_ID
:
407 new_singleton
= new UMAPrivateResource(connection
, instance
);
409 // Flash/trusted resources aren't needed for NaCl.
410 #if !defined(OS_NACL) && !defined(NACL_WIN64)
411 case BROWSER_FONT_SINGLETON_ID
:
412 new_singleton
= new BrowserFontSingletonResource(connection
, instance
);
414 case FLASH_CLIPBOARD_SINGLETON_ID
:
415 new_singleton
= new FlashClipboardResource(connection
, instance
);
417 case FLASH_FILE_SINGLETON_ID
:
418 new_singleton
= new FlashFileResource(connection
, instance
);
420 case FLASH_FULLSCREEN_SINGLETON_ID
:
421 new_singleton
= new FlashFullscreenResource(connection
, instance
);
423 case FLASH_SINGLETON_ID
:
424 new_singleton
= new FlashResource(connection
, instance
,
425 static_cast<PluginDispatcher
*>(dispatcher()));
427 case PDF_SINGLETON_ID
:
428 new_singleton
= new PDFResource(connection
, instance
);
431 case BROWSER_FONT_SINGLETON_ID
:
432 case FLASH_CLIPBOARD_SINGLETON_ID
:
433 case FLASH_FILE_SINGLETON_ID
:
434 case FLASH_FULLSCREEN_SINGLETON_ID
:
435 case FLASH_SINGLETON_ID
:
436 case PDF_SINGLETON_ID
:
439 #endif // !defined(OS_NACL) && !defined(NACL_WIN64)
442 if (!new_singleton
.get()) {
443 // Getting here implies that a constructor is missing in the above switch.
448 data
->singleton_resources
[id
] = new_singleton
;
449 return new_singleton
.get();
452 int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance
,
453 uint32_t event_classes
) {
454 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
455 API_ID_PPB_INSTANCE
, instance
, false, event_classes
));
457 // We always register for the classes we can handle, this function validates
458 // the flags so we can notify it if anything was invalid, without requiring
460 return ValidateRequestInputEvents(false, event_classes
);
463 int32_t PPB_Instance_Proxy::RequestFilteringInputEvents(
464 PP_Instance instance
,
465 uint32_t event_classes
) {
466 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
467 API_ID_PPB_INSTANCE
, instance
, true, event_classes
));
469 // We always register for the classes we can handle, this function validates
470 // the flags so we can notify it if anything was invalid, without requiring
472 return ValidateRequestInputEvents(true, event_classes
);
475 void PPB_Instance_Proxy::ClearInputEventRequest(PP_Instance instance
,
476 uint32_t event_classes
) {
477 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ClearInputEvents(
478 API_ID_PPB_INSTANCE
, instance
, event_classes
));
481 PP_Var
PPB_Instance_Proxy::GetDocumentURL(PP_Instance instance
,
482 PP_URLComponents_Dev
* components
) {
483 ReceiveSerializedVarReturnValue result
;
484 PP_URLComponents_Dev url_components
= {{0}};
485 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetDocumentURL(
486 API_ID_PPB_INSTANCE
, instance
, &url_components
, &result
));
488 *components
= url_components
;
489 return result
.Return(dispatcher());
492 #if !defined(OS_NACL)
493 PP_Var
PPB_Instance_Proxy::ResolveRelativeToDocument(
494 PP_Instance instance
,
496 PP_URLComponents_Dev
* components
) {
497 ReceiveSerializedVarReturnValue result
;
498 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ResolveRelativeToDocument(
499 API_ID_PPB_INSTANCE
, instance
,
500 SerializedVarSendInput(dispatcher(), relative
),
502 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
503 result
.Return(dispatcher()),
507 PP_Bool
PPB_Instance_Proxy::DocumentCanRequest(PP_Instance instance
,
509 PP_Bool result
= PP_FALSE
;
510 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanRequest(
511 API_ID_PPB_INSTANCE
, instance
,
512 SerializedVarSendInput(dispatcher(), url
),
517 PP_Bool
PPB_Instance_Proxy::DocumentCanAccessDocument(PP_Instance instance
,
518 PP_Instance target
) {
519 PP_Bool result
= PP_FALSE
;
520 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanAccessDocument(
521 API_ID_PPB_INSTANCE
, instance
, target
, &result
));
525 PP_Var
PPB_Instance_Proxy::GetPluginInstanceURL(
526 PP_Instance instance
,
527 PP_URLComponents_Dev
* components
) {
528 ReceiveSerializedVarReturnValue result
;
529 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginInstanceURL(
530 API_ID_PPB_INSTANCE
, instance
, &result
));
531 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
532 result
.Return(dispatcher()),
536 PP_Var
PPB_Instance_Proxy::GetPluginReferrerURL(
537 PP_Instance instance
,
538 PP_URLComponents_Dev
* components
) {
539 ReceiveSerializedVarReturnValue result
;
540 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginReferrerURL(
541 API_ID_PPB_INSTANCE
, instance
, &result
));
542 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
543 result
.Return(dispatcher()),
547 void PPB_Instance_Proxy::PromiseResolved(PP_Instance instance
,
549 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseResolved(
550 API_ID_PPB_INSTANCE
, instance
, promise_id
));
553 void PPB_Instance_Proxy::PromiseResolvedWithSession(PP_Instance instance
,
555 PP_Var session_id_var
) {
556 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseResolvedWithSession(
557 API_ID_PPB_INSTANCE
, instance
, promise_id
,
558 SerializedVarSendInput(dispatcher(), session_id_var
)));
561 void PPB_Instance_Proxy::PromiseRejected(PP_Instance instance
,
563 PP_CdmExceptionCode exception_code
,
565 PP_Var error_description_var
) {
566 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseRejected(
572 SerializedVarSendInput(dispatcher(), error_description_var
)));
575 void PPB_Instance_Proxy::SessionMessage(PP_Instance instance
,
576 PP_Var session_id_var
,
577 PP_CdmMessageType message_type
,
579 PP_Var legacy_destination_url_var
) {
580 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionMessage(
581 API_ID_PPB_INSTANCE
, instance
,
582 SerializedVarSendInput(dispatcher(), session_id_var
), message_type
,
583 SerializedVarSendInput(dispatcher(), message_var
),
584 SerializedVarSendInput(dispatcher(), legacy_destination_url_var
)));
587 void PPB_Instance_Proxy::SessionKeysChange(
588 PP_Instance instance
,
589 PP_Var session_id_var
,
590 PP_Bool has_additional_usable_key
,
592 const struct PP_KeyInformation key_information
[]) {
593 StringVar
* session_id
= StringVar::FromPPVar(session_id_var
);
595 session_id
->value().length() > media::limits::kMaxSessionIdLength
) {
600 if (key_count
> media::limits::kMaxKeyIds
) {
605 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionKeysChange(
606 API_ID_PPB_INSTANCE
, instance
, session_id
->value(),
607 has_additional_usable_key
,
608 std::vector
<PP_KeyInformation
>(key_information
,
609 key_information
+ key_count
)));
612 void PPB_Instance_Proxy::SessionExpirationChange(PP_Instance instance
,
613 PP_Var session_id_var
,
614 PP_Time new_expiry_time
) {
615 StringVar
* session_id
= StringVar::FromPPVar(session_id_var
);
617 session_id
->value().length() > media::limits::kMaxSessionIdLength
) {
622 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionExpirationChange(
623 API_ID_PPB_INSTANCE
, instance
, session_id
->value(), new_expiry_time
));
626 void PPB_Instance_Proxy::SessionClosed(PP_Instance instance
,
627 PP_Var session_id_var
) {
628 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionClosed(
629 API_ID_PPB_INSTANCE
, instance
,
630 SerializedVarSendInput(dispatcher(), session_id_var
)));
633 void PPB_Instance_Proxy::LegacySessionError(PP_Instance instance
,
634 PP_Var session_id_var
,
635 PP_CdmExceptionCode exception_code
,
637 PP_Var error_description_var
) {
638 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LegacySessionError(
639 API_ID_PPB_INSTANCE
, instance
,
640 SerializedVarSendInput(dispatcher(), session_id_var
), exception_code
,
642 SerializedVarSendInput(dispatcher(), error_description_var
)));
645 void PPB_Instance_Proxy::DeliverBlock(PP_Instance instance
,
646 PP_Resource decrypted_block
,
647 const PP_DecryptedBlockInfo
* block_info
) {
648 PP_Resource decrypted_block_host_resource
= 0;
650 if (decrypted_block
) {
652 PpapiGlobals::Get()->GetResourceTracker()->GetResource(decrypted_block
);
653 if (!object
|| object
->pp_instance() != instance
) {
657 decrypted_block_host_resource
= object
->host_resource().host_resource();
660 std::string serialized_block_info
;
661 if (!SerializeBlockInfo(*block_info
, &serialized_block_info
)) {
667 new PpapiHostMsg_PPBInstance_DeliverBlock(API_ID_PPB_INSTANCE
,
669 decrypted_block_host_resource
,
670 serialized_block_info
));
673 void PPB_Instance_Proxy::DecoderInitializeDone(
674 PP_Instance instance
,
675 PP_DecryptorStreamType decoder_type
,
679 new PpapiHostMsg_PPBInstance_DecoderInitializeDone(
687 void PPB_Instance_Proxy::DecoderDeinitializeDone(
688 PP_Instance instance
,
689 PP_DecryptorStreamType decoder_type
,
690 uint32_t request_id
) {
692 new PpapiHostMsg_PPBInstance_DecoderDeinitializeDone(
699 void PPB_Instance_Proxy::DecoderResetDone(PP_Instance instance
,
700 PP_DecryptorStreamType decoder_type
,
701 uint32_t request_id
) {
703 new PpapiHostMsg_PPBInstance_DecoderResetDone(
710 void PPB_Instance_Proxy::DeliverFrame(PP_Instance instance
,
711 PP_Resource decrypted_frame
,
712 const PP_DecryptedFrameInfo
* frame_info
) {
713 PP_Resource host_resource
= 0;
714 if (decrypted_frame
!= 0) {
715 ResourceTracker
* tracker
= PpapiGlobals::Get()->GetResourceTracker();
716 Resource
* object
= tracker
->GetResource(decrypted_frame
);
718 if (!object
|| object
->pp_instance() != instance
) {
723 host_resource
= object
->host_resource().host_resource();
726 std::string serialized_frame_info
;
727 if (!SerializeBlockInfo(*frame_info
, &serialized_frame_info
)) {
733 new PpapiHostMsg_PPBInstance_DeliverFrame(API_ID_PPB_INSTANCE
,
736 serialized_frame_info
));
739 void PPB_Instance_Proxy::DeliverSamples(
740 PP_Instance instance
,
741 PP_Resource decrypted_samples
,
742 const PP_DecryptedSampleInfo
* sample_info
) {
743 PP_Resource host_resource
= 0;
744 if (decrypted_samples
!= 0) {
745 ResourceTracker
* tracker
= PpapiGlobals::Get()->GetResourceTracker();
746 Resource
* object
= tracker
->GetResource(decrypted_samples
);
748 if (!object
|| object
->pp_instance() != instance
) {
753 host_resource
= object
->host_resource().host_resource();
756 std::string serialized_sample_info
;
757 if (!SerializeBlockInfo(*sample_info
, &serialized_sample_info
)) {
763 new PpapiHostMsg_PPBInstance_DeliverSamples(API_ID_PPB_INSTANCE
,
766 serialized_sample_info
));
768 #endif // !defined(OS_NACL)
770 void PPB_Instance_Proxy::PostMessage(PP_Instance instance
,
772 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage(
774 instance
, SerializedVarSendInputShmem(dispatcher(), message
,
778 int32_t PPB_Instance_Proxy::RegisterMessageHandler(
779 PP_Instance instance
,
781 const PPP_MessageHandler_0_2
* handler
,
782 PP_Resource message_loop
) {
784 static_cast<PluginDispatcher
*>(dispatcher())->GetInstanceData(instance
);
786 return PP_ERROR_BADARGUMENT
;
788 int32_t result
= PP_ERROR_FAILED
;
789 scoped_ptr
<MessageHandler
> message_handler
= MessageHandler::Create(
790 instance
, handler
, user_data
, message_loop
, &result
);
792 data
->message_handler
= message_handler
.Pass();
796 void PPB_Instance_Proxy::UnregisterMessageHandler(PP_Instance instance
) {
798 static_cast<PluginDispatcher
*>(dispatcher())->GetInstanceData(instance
);
801 data
->message_handler
.reset();
804 PP_Bool
PPB_Instance_Proxy::SetCursor(PP_Instance instance
,
805 PP_MouseCursor_Type type
,
807 const PP_Point
* hot_spot
) {
808 // Some of these parameters are important for security. This check is in the
809 // plugin process just for the convenience of the caller (since we don't
810 // bother returning errors from the other process with a sync message). The
811 // parameters will be validated again in the renderer.
812 if (!ValidateSetCursorParams(type
, image
, hot_spot
))
815 HostResource image_host_resource
;
817 Resource
* cursor_image
=
818 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image
);
819 if (!cursor_image
|| cursor_image
->pp_instance() != instance
)
821 image_host_resource
= cursor_image
->host_resource();
824 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetCursor(
825 API_ID_PPB_INSTANCE
, instance
, static_cast<int32_t>(type
),
826 image_host_resource
, hot_spot
? *hot_spot
: PP_MakePoint(0, 0)));
830 int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance
,
831 scoped_refptr
<TrackedCallback
> callback
) {
832 // Save the mouse callback on the instance data.
833 InstanceData
* data
= static_cast<PluginDispatcher
*>(dispatcher())->
834 GetInstanceData(instance
);
836 return PP_ERROR_BADARGUMENT
;
837 if (TrackedCallback::IsPending(data
->mouse_lock_callback
))
838 return PP_ERROR_INPROGRESS
; // Already have a pending callback.
839 data
->mouse_lock_callback
= callback
;
841 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LockMouse(
842 API_ID_PPB_INSTANCE
, instance
));
843 return PP_OK_COMPLETIONPENDING
;
846 void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance
) {
847 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UnlockMouse(
848 API_ID_PPB_INSTANCE
, instance
));
851 void PPB_Instance_Proxy::SetTextInputType(PP_Instance instance
,
852 PP_TextInput_Type type
) {
853 CancelAnyPendingRequestSurroundingText(instance
);
854 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTextInputType(
855 API_ID_PPB_INSTANCE
, instance
, type
));
858 void PPB_Instance_Proxy::UpdateCaretPosition(PP_Instance instance
,
859 const PP_Rect
& caret
,
860 const PP_Rect
& bounding_box
) {
861 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateCaretPosition(
862 API_ID_PPB_INSTANCE
, instance
, caret
, bounding_box
));
865 void PPB_Instance_Proxy::CancelCompositionText(PP_Instance instance
) {
866 CancelAnyPendingRequestSurroundingText(instance
);
867 dispatcher()->Send(new PpapiHostMsg_PPBInstance_CancelCompositionText(
868 API_ID_PPB_INSTANCE
, instance
));
871 void PPB_Instance_Proxy::SelectionChanged(PP_Instance instance
) {
872 // The "right" way to do this is to send the message to the host. However,
873 // all it will do is call RequestSurroundingText with a hardcoded number of
874 // characters in response, which is an entire IPC round-trip.
876 // We can avoid this round-trip by just implementing the
877 // RequestSurroundingText logic in the plugin process. If the logic in the
878 // host becomes more complex (like a more adaptive number of characters),
879 // we'll need to reevanuate whether we want to do the round trip instead.
881 // Be careful to post a task to avoid reentering the plugin.
884 static_cast<PluginDispatcher
*>(dispatcher())->GetInstanceData(instance
);
887 data
->should_do_request_surrounding_text
= true;
889 if (!data
->is_request_surrounding_text_pending
) {
890 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
892 RunWhileLocked(base::Bind(&RequestSurroundingText
, instance
)));
893 data
->is_request_surrounding_text_pending
= true;
897 void PPB_Instance_Proxy::UpdateSurroundingText(PP_Instance instance
,
901 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateSurroundingText(
902 API_ID_PPB_INSTANCE
, instance
, text
, caret
, anchor
));
905 #if !defined(OS_NACL)
906 void PPB_Instance_Proxy::OnHostMsgGetWindowObject(
907 PP_Instance instance
,
908 SerializedVarReturnValue result
) {
909 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
911 EnterInstanceNoLock
enter(instance
);
912 if (enter
.succeeded())
913 result
.Return(dispatcher(), enter
.functions()->GetWindowObject(instance
));
916 void PPB_Instance_Proxy::OnHostMsgGetOwnerElementObject(
917 PP_Instance instance
,
918 SerializedVarReturnValue result
) {
919 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
921 EnterInstanceNoLock
enter(instance
);
922 if (enter
.succeeded()) {
923 result
.Return(dispatcher(),
924 enter
.functions()->GetOwnerElementObject(instance
));
928 void PPB_Instance_Proxy::OnHostMsgBindGraphics(PP_Instance instance
,
929 PP_Resource device
) {
930 // Note that we ignroe the return value here. Otherwise, this would need to
931 // be a slow sync call, and the plugin side of the proxy will have already
932 // validated the resources, so we shouldn't see errors here that weren't
934 EnterInstanceNoLock
enter(instance
);
935 if (enter
.succeeded())
936 enter
.functions()->BindGraphics(instance
, device
);
939 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputSampleRate(
940 PP_Instance instance
, uint32_t* result
) {
941 EnterInstanceNoLock
enter(instance
);
942 if (enter
.succeeded())
943 *result
= enter
.functions()->GetAudioHardwareOutputSampleRate(instance
);
946 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputBufferSize(
947 PP_Instance instance
, uint32_t* result
) {
948 EnterInstanceNoLock
enter(instance
);
949 if (enter
.succeeded())
950 *result
= enter
.functions()->GetAudioHardwareOutputBufferSize(instance
);
953 void PPB_Instance_Proxy::OnHostMsgIsFullFrame(PP_Instance instance
,
955 EnterInstanceNoLock
enter(instance
);
956 if (enter
.succeeded())
957 *result
= enter
.functions()->IsFullFrame(instance
);
960 void PPB_Instance_Proxy::OnHostMsgExecuteScript(
961 PP_Instance instance
,
962 SerializedVarReceiveInput script
,
963 SerializedVarOutParam out_exception
,
964 SerializedVarReturnValue result
) {
965 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
967 EnterInstanceNoLock
enter(instance
);
971 if (dispatcher()->IsPlugin())
974 static_cast<HostDispatcher
*>(dispatcher())->set_allow_plugin_reentrancy();
976 result
.Return(dispatcher(), enter
.functions()->ExecuteScript(
978 script
.Get(dispatcher()),
979 out_exception
.OutParam(dispatcher())));
982 void PPB_Instance_Proxy::OnHostMsgGetDefaultCharSet(
983 PP_Instance instance
,
984 SerializedVarReturnValue result
) {
985 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
987 EnterInstanceNoLock
enter(instance
);
988 if (enter
.succeeded())
989 result
.Return(dispatcher(), enter
.functions()->GetDefaultCharSet(instance
));
992 void PPB_Instance_Proxy::OnHostMsgSetPluginToHandleFindRequests(
993 PP_Instance instance
) {
994 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
996 EnterInstanceNoLock
enter(instance
);
997 if (enter
.succeeded())
998 enter
.functions()->SetPluginToHandleFindRequests(instance
);
1001 void PPB_Instance_Proxy::OnHostMsgNumberOfFindResultsChanged(
1002 PP_Instance instance
,
1004 PP_Bool final_result
) {
1005 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1007 EnterInstanceNoLock
enter(instance
);
1008 if (enter
.succeeded()) {
1009 enter
.functions()->NumberOfFindResultsChanged(
1010 instance
, total
, final_result
);
1014 void PPB_Instance_Proxy::OnHostMsgSelectFindResultChanged(
1015 PP_Instance instance
,
1017 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1019 EnterInstanceNoLock
enter(instance
);
1020 if (enter
.succeeded())
1021 enter
.functions()->SelectedFindResultChanged(instance
, index
);
1024 void PPB_Instance_Proxy::OnHostMsgSetTickmarks(
1025 PP_Instance instance
,
1026 const std::vector
<PP_Rect
>& tickmarks
) {
1027 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1029 const PP_Rect
* array
= tickmarks
.empty() ? NULL
: &tickmarks
[0];
1030 EnterInstanceNoLock
enter(instance
);
1031 if (enter
.succeeded()) {
1032 enter
.functions()->SetTickmarks(instance
,
1034 static_cast<uint32_t>(tickmarks
.size()));
1038 void PPB_Instance_Proxy::OnHostMsgSetFullscreen(PP_Instance instance
,
1041 EnterInstanceNoLock
enter(instance
);
1042 if (enter
.succeeded())
1043 *result
= enter
.functions()->SetFullscreen(instance
, fullscreen
);
1047 void PPB_Instance_Proxy::OnHostMsgGetScreenSize(PP_Instance instance
,
1050 EnterInstanceNoLock
enter(instance
);
1051 if (enter
.succeeded())
1052 *result
= enter
.functions()->GetScreenSize(instance
, size
);
1055 void PPB_Instance_Proxy::OnHostMsgRequestInputEvents(PP_Instance instance
,
1057 uint32_t event_classes
) {
1058 EnterInstanceNoLock
enter(instance
);
1059 if (enter
.succeeded()) {
1061 enter
.functions()->RequestFilteringInputEvents(instance
, event_classes
);
1063 enter
.functions()->RequestInputEvents(instance
, event_classes
);
1067 void PPB_Instance_Proxy::OnHostMsgClearInputEvents(PP_Instance instance
,
1068 uint32_t event_classes
) {
1069 EnterInstanceNoLock
enter(instance
);
1070 if (enter
.succeeded())
1071 enter
.functions()->ClearInputEventRequest(instance
, event_classes
);
1074 void PPB_Instance_Proxy::OnHostMsgPostMessage(
1075 PP_Instance instance
,
1076 SerializedVarReceiveInput message
) {
1077 EnterInstanceNoLock
enter(instance
);
1078 if (!message
.is_valid_var()) {
1079 PpapiGlobals::Get()->LogWithSource(
1080 instance
, PP_LOGLEVEL_ERROR
, std::string(), kSerializationError
);
1084 if (enter
.succeeded())
1085 enter
.functions()->PostMessage(instance
,
1086 message
.GetForInstance(dispatcher(),
1090 void PPB_Instance_Proxy::OnHostMsgLockMouse(PP_Instance instance
) {
1091 // Need to be careful to always issue the callback.
1092 pp::CompletionCallback cb
= callback_factory_
.NewCallback(
1093 &PPB_Instance_Proxy::MouseLockCompleteInHost
, instance
);
1095 EnterInstanceNoLock
enter(instance
, cb
.pp_completion_callback());
1096 if (enter
.succeeded())
1097 enter
.SetResult(enter
.functions()->LockMouse(instance
, enter
.callback()));
1100 void PPB_Instance_Proxy::OnHostMsgUnlockMouse(PP_Instance instance
) {
1101 EnterInstanceNoLock
enter(instance
);
1102 if (enter
.succeeded())
1103 enter
.functions()->UnlockMouse(instance
);
1106 void PPB_Instance_Proxy::OnHostMsgGetDocumentURL(
1107 PP_Instance instance
,
1108 PP_URLComponents_Dev
* components
,
1109 SerializedVarReturnValue result
) {
1110 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1112 EnterInstanceNoLock
enter(instance
);
1113 if (enter
.succeeded()) {
1114 PP_Var document_url
= enter
.functions()->GetDocumentURL(instance
,
1116 result
.Return(dispatcher(), document_url
);
1120 void PPB_Instance_Proxy::OnHostMsgResolveRelativeToDocument(
1121 PP_Instance instance
,
1122 SerializedVarReceiveInput relative
,
1123 SerializedVarReturnValue result
) {
1124 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1126 EnterInstanceNoLock
enter(instance
);
1127 if (enter
.succeeded()) {
1128 result
.Return(dispatcher(),
1129 enter
.functions()->ResolveRelativeToDocument(
1130 instance
, relative
.Get(dispatcher()), NULL
));
1134 void PPB_Instance_Proxy::OnHostMsgDocumentCanRequest(
1135 PP_Instance instance
,
1136 SerializedVarReceiveInput url
,
1138 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1140 EnterInstanceNoLock
enter(instance
);
1141 if (enter
.succeeded()) {
1142 *result
= enter
.functions()->DocumentCanRequest(instance
,
1143 url
.Get(dispatcher()));
1147 void PPB_Instance_Proxy::OnHostMsgDocumentCanAccessDocument(PP_Instance active
,
1150 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1152 EnterInstanceNoLock
enter(active
);
1153 if (enter
.succeeded())
1154 *result
= enter
.functions()->DocumentCanAccessDocument(active
, target
);
1157 void PPB_Instance_Proxy::OnHostMsgGetPluginInstanceURL(
1158 PP_Instance instance
,
1159 SerializedVarReturnValue result
) {
1160 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1162 EnterInstanceNoLock
enter(instance
);
1163 if (enter
.succeeded()) {
1164 result
.Return(dispatcher(),
1165 enter
.functions()->GetPluginInstanceURL(instance
, NULL
));
1169 void PPB_Instance_Proxy::OnHostMsgGetPluginReferrerURL(
1170 PP_Instance instance
,
1171 SerializedVarReturnValue result
) {
1172 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1174 EnterInstanceNoLock
enter(instance
);
1175 if (enter
.succeeded()) {
1176 result
.Return(dispatcher(),
1177 enter
.functions()->GetPluginReferrerURL(instance
, NULL
));
1181 void PPB_Instance_Proxy::OnHostMsgPromiseResolved(PP_Instance instance
,
1182 uint32_t promise_id
) {
1183 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1185 EnterInstanceNoLock
enter(instance
);
1186 if (enter
.succeeded()) {
1187 enter
.functions()->PromiseResolved(instance
, promise_id
);
1191 void PPB_Instance_Proxy::OnHostMsgPromiseResolvedWithSession(
1192 PP_Instance instance
,
1193 uint32_t promise_id
,
1194 SerializedVarReceiveInput session_id
) {
1195 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1197 EnterInstanceNoLock
enter(instance
);
1198 if (enter
.succeeded()) {
1199 enter
.functions()->PromiseResolvedWithSession(instance
, promise_id
,
1200 session_id
.Get(dispatcher()));
1204 void PPB_Instance_Proxy::OnHostMsgPromiseRejected(
1205 PP_Instance instance
,
1206 uint32_t promise_id
,
1207 PP_CdmExceptionCode exception_code
,
1208 uint32_t system_code
,
1209 SerializedVarReceiveInput error_description
) {
1210 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1212 EnterInstanceNoLock
enter(instance
);
1213 if (enter
.succeeded()) {
1214 enter
.functions()->PromiseRejected(instance
,
1218 error_description
.Get(dispatcher()));
1222 void PPB_Instance_Proxy::OnHostMsgSessionMessage(
1223 PP_Instance instance
,
1224 SerializedVarReceiveInput session_id
,
1225 PP_CdmMessageType message_type
,
1226 SerializedVarReceiveInput message
,
1227 SerializedVarReceiveInput legacy_destination_url
) {
1228 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1230 EnterInstanceNoLock
enter(instance
);
1231 if (enter
.succeeded()) {
1232 enter
.functions()->SessionMessage(instance
, session_id
.Get(dispatcher()),
1233 message_type
, message
.Get(dispatcher()),
1234 legacy_destination_url
.Get(dispatcher()));
1238 void PPB_Instance_Proxy::OnHostMsgSessionKeysChange(
1239 PP_Instance instance
,
1240 const std::string
& session_id
,
1241 PP_Bool has_additional_usable_key
,
1242 const std::vector
<PP_KeyInformation
>& key_information
) {
1243 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1246 if (key_information
.size() > media::limits::kMaxKeyIds
) {
1251 EnterInstanceNoLock
enter(instance
);
1252 if (enter
.succeeded()) {
1253 ScopedPPVar
session_id_var(ScopedPPVar::PassRef(),
1254 StringVar::StringToPPVar(session_id
));
1255 enter
.functions()->SessionKeysChange(
1256 instance
, session_id_var
.get(), has_additional_usable_key
,
1257 base::checked_cast
<uint32_t>(key_information
.size()),
1258 vector_as_array(&key_information
));
1262 void PPB_Instance_Proxy::OnHostMsgSessionExpirationChange(
1263 PP_Instance instance
,
1264 const std::string
& session_id
,
1265 PP_Time new_expiry_time
) {
1266 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1268 EnterInstanceNoLock
enter(instance
);
1269 if (enter
.succeeded()) {
1270 ScopedPPVar
session_id_var(ScopedPPVar::PassRef(),
1271 StringVar::StringToPPVar(session_id
));
1272 enter
.functions()->SessionExpirationChange(instance
, session_id_var
.get(),
1277 void PPB_Instance_Proxy::OnHostMsgSessionClosed(
1278 PP_Instance instance
,
1279 SerializedVarReceiveInput session_id
) {
1280 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1282 EnterInstanceNoLock
enter(instance
);
1283 if (enter
.succeeded()) {
1284 enter
.functions()->SessionClosed(instance
, session_id
.Get(dispatcher()));
1288 void PPB_Instance_Proxy::OnHostMsgLegacySessionError(
1289 PP_Instance instance
,
1290 SerializedVarReceiveInput session_id
,
1291 PP_CdmExceptionCode exception_code
,
1292 uint32_t system_code
,
1293 SerializedVarReceiveInput error_description
) {
1294 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1296 EnterInstanceNoLock
enter(instance
);
1297 if (enter
.succeeded()) {
1298 enter
.functions()->LegacySessionError(
1299 instance
, session_id
.Get(dispatcher()), exception_code
, system_code
,
1300 error_description
.Get(dispatcher()));
1304 void PPB_Instance_Proxy::OnHostMsgDeliverBlock(
1305 PP_Instance instance
,
1306 PP_Resource decrypted_block
,
1307 const std::string
& serialized_block_info
) {
1308 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1310 PP_DecryptedBlockInfo block_info
;
1311 if (!DeserializeBlockInfo(serialized_block_info
, &block_info
))
1314 EnterInstanceNoLock
enter(instance
);
1315 if (enter
.succeeded())
1316 enter
.functions()->DeliverBlock(instance
, decrypted_block
, &block_info
);
1319 void PPB_Instance_Proxy::OnHostMsgDecoderInitializeDone(
1320 PP_Instance instance
,
1321 PP_DecryptorStreamType decoder_type
,
1322 uint32_t request_id
,
1324 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1326 EnterInstanceNoLock
enter(instance
);
1327 if (enter
.succeeded()) {
1328 enter
.functions()->DecoderInitializeDone(instance
,
1335 void PPB_Instance_Proxy::OnHostMsgDecoderDeinitializeDone(
1336 PP_Instance instance
,
1337 PP_DecryptorStreamType decoder_type
,
1338 uint32_t request_id
) {
1339 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1341 EnterInstanceNoLock
enter(instance
);
1342 if (enter
.succeeded())
1343 enter
.functions()->DecoderDeinitializeDone(instance
,
1348 void PPB_Instance_Proxy::OnHostMsgDecoderResetDone(
1349 PP_Instance instance
,
1350 PP_DecryptorStreamType decoder_type
,
1351 uint32_t request_id
) {
1352 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1354 EnterInstanceNoLock
enter(instance
);
1355 if (enter
.succeeded())
1356 enter
.functions()->DecoderResetDone(instance
, decoder_type
, request_id
);
1359 void PPB_Instance_Proxy::OnHostMsgDeliverFrame(
1360 PP_Instance instance
,
1361 PP_Resource decrypted_frame
,
1362 const std::string
& serialized_frame_info
) {
1363 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1365 PP_DecryptedFrameInfo frame_info
;
1366 if (!DeserializeBlockInfo(serialized_frame_info
, &frame_info
))
1369 EnterInstanceNoLock
enter(instance
);
1370 if (enter
.succeeded())
1371 enter
.functions()->DeliverFrame(instance
, decrypted_frame
, &frame_info
);
1374 void PPB_Instance_Proxy::OnHostMsgDeliverSamples(
1375 PP_Instance instance
,
1376 PP_Resource audio_frames
,
1377 const std::string
& serialized_sample_info
) {
1378 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1380 PP_DecryptedSampleInfo sample_info
;
1381 if (!DeserializeBlockInfo(serialized_sample_info
, &sample_info
))
1384 EnterInstanceNoLock
enter(instance
);
1385 if (enter
.succeeded())
1386 enter
.functions()->DeliverSamples(instance
, audio_frames
, &sample_info
);
1389 void PPB_Instance_Proxy::OnHostMsgSetCursor(
1390 PP_Instance instance
,
1392 const ppapi::HostResource
& custom_image
,
1393 const PP_Point
& hot_spot
) {
1394 // This API serves PPB_CursorControl_Dev and PPB_MouseCursor, so is public.
1395 EnterInstanceNoLock
enter(instance
);
1396 if (enter
.succeeded()) {
1397 enter
.functions()->SetCursor(
1398 instance
, static_cast<PP_MouseCursor_Type
>(type
),
1399 custom_image
.host_resource(), &hot_spot
);
1403 void PPB_Instance_Proxy::OnHostMsgSetTextInputType(PP_Instance instance
,
1404 PP_TextInput_Type type
) {
1405 EnterInstanceNoLock
enter(instance
);
1406 if (enter
.succeeded())
1407 enter
.functions()->SetTextInputType(instance
, type
);
1410 void PPB_Instance_Proxy::OnHostMsgUpdateCaretPosition(
1411 PP_Instance instance
,
1412 const PP_Rect
& caret
,
1413 const PP_Rect
& bounding_box
) {
1414 EnterInstanceNoLock
enter(instance
);
1415 if (enter
.succeeded())
1416 enter
.functions()->UpdateCaretPosition(instance
, caret
, bounding_box
);
1419 void PPB_Instance_Proxy::OnHostMsgCancelCompositionText(PP_Instance instance
) {
1420 EnterInstanceNoLock
enter(instance
);
1421 if (enter
.succeeded())
1422 enter
.functions()->CancelCompositionText(instance
);
1425 void PPB_Instance_Proxy::OnHostMsgUpdateSurroundingText(
1426 PP_Instance instance
,
1427 const std::string
& text
,
1430 EnterInstanceNoLock
enter(instance
);
1431 if (enter
.succeeded()) {
1432 enter
.functions()->UpdateSurroundingText(instance
, text
.c_str(), caret
,
1436 #endif // !defined(OS_NACL)
1438 void PPB_Instance_Proxy::OnPluginMsgMouseLockComplete(PP_Instance instance
,
1440 if (!dispatcher()->IsPlugin())
1443 // Save the mouse callback on the instance data.
1444 InstanceData
* data
= static_cast<PluginDispatcher
*>(dispatcher())->
1445 GetInstanceData(instance
);
1447 return; // Instance was probably deleted.
1448 if (!TrackedCallback::IsPending(data
->mouse_lock_callback
)) {
1452 data
->mouse_lock_callback
->Run(result
);
1455 #if !defined(OS_NACL)
1456 void PPB_Instance_Proxy::MouseLockCompleteInHost(int32_t result
,
1457 PP_Instance instance
) {
1458 dispatcher()->Send(new PpapiMsg_PPBInstance_MouseLockComplete(
1459 API_ID_PPB_INSTANCE
, instance
, result
));
1461 #endif // !defined(OS_NACL)
1463 void PPB_Instance_Proxy::CancelAnyPendingRequestSurroundingText(
1464 PP_Instance instance
) {
1465 InstanceData
* data
= static_cast<PluginDispatcher
*>(dispatcher())->
1466 GetInstanceData(instance
);
1468 return; // Instance was probably deleted.
1469 data
->should_do_request_surrounding_text
= false;
1472 } // namespace proxy
1473 } // namespace ppapi