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_StartTrackingLatency
,
155 OnHostMsgStartTrackingLatency
)
156 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_LockMouse
,
158 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UnlockMouse
,
159 OnHostMsgUnlockMouse
)
160 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetCursor
,
162 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetTextInputType
,
163 OnHostMsgSetTextInputType
)
164 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UpdateCaretPosition
,
165 OnHostMsgUpdateCaretPosition
)
166 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_CancelCompositionText
,
167 OnHostMsgCancelCompositionText
)
168 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UpdateSurroundingText
,
169 OnHostMsgUpdateSurroundingText
)
170 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDocumentURL
,
171 OnHostMsgGetDocumentURL
)
172 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ResolveRelativeToDocument
,
173 OnHostMsgResolveRelativeToDocument
)
174 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanRequest
,
175 OnHostMsgDocumentCanRequest
)
176 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanAccessDocument
,
177 OnHostMsgDocumentCanAccessDocument
)
178 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginInstanceURL
,
179 OnHostMsgGetPluginInstanceURL
)
180 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginReferrerURL
,
181 OnHostMsgGetPluginReferrerURL
)
182 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PromiseResolved
,
183 OnHostMsgPromiseResolved
)
184 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PromiseResolvedWithSession
,
185 OnHostMsgPromiseResolvedWithSession
)
186 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PromiseRejected
,
187 OnHostMsgPromiseRejected
)
188 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionMessage
,
189 OnHostMsgSessionMessage
)
190 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionKeysChange
,
191 OnHostMsgSessionKeysChange
)
192 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionExpirationChange
,
193 OnHostMsgSessionExpirationChange
)
194 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionClosed
,
195 OnHostMsgSessionClosed
)
196 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_LegacySessionError
,
197 OnHostMsgLegacySessionError
)
198 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverBlock
,
199 OnHostMsgDeliverBlock
)
200 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderInitializeDone
,
201 OnHostMsgDecoderInitializeDone
)
202 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderDeinitializeDone
,
203 OnHostMsgDecoderDeinitializeDone
)
204 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderResetDone
,
205 OnHostMsgDecoderResetDone
)
206 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverFrame
,
207 OnHostMsgDeliverFrame
)
208 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverSamples
,
209 OnHostMsgDeliverSamples
)
210 #endif // !defined(OS_NACL)
212 // Host -> Plugin messages.
213 IPC_MESSAGE_HANDLER(PpapiMsg_PPBInstance_MouseLockComplete
,
214 OnPluginMsgMouseLockComplete
)
216 IPC_MESSAGE_UNHANDLED(handled
= false)
217 IPC_END_MESSAGE_MAP()
221 PP_Bool
PPB_Instance_Proxy::BindGraphics(PP_Instance instance
,
222 PP_Resource device
) {
223 // If device is 0, pass a null HostResource. This signals the host to unbind
225 PP_Resource pp_resource
= 0;
228 PpapiGlobals::Get()->GetResourceTracker()->GetResource(device
);
229 if (!resource
|| resource
->pp_instance() != instance
)
231 // We need to pass different resource to Graphics 2D, 3D and Compositor
232 // right now. Once 3D is migrated to the new design, we should be able to
234 if (resource
->AsPPB_Graphics3D_API()) {
235 pp_resource
= resource
->host_resource().host_resource();
236 } else if (resource
->AsPPB_Graphics2D_API() ||
237 resource
->AsPPB_Compositor_API()) {
238 pp_resource
= resource
->pp_resource();
244 dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
245 API_ID_PPB_INSTANCE
, instance
, pp_resource
));
249 PP_Bool
PPB_Instance_Proxy::IsFullFrame(PP_Instance instance
) {
250 PP_Bool result
= PP_FALSE
;
251 dispatcher()->Send(new PpapiHostMsg_PPBInstance_IsFullFrame(
252 API_ID_PPB_INSTANCE
, instance
, &result
));
256 const ViewData
* PPB_Instance_Proxy::GetViewData(PP_Instance instance
) {
257 InstanceData
* data
= static_cast<PluginDispatcher
*>(dispatcher())->
258 GetInstanceData(instance
);
264 PP_Bool
PPB_Instance_Proxy::FlashIsFullscreen(PP_Instance instance
) {
265 // This function is only used for proxying in the renderer process. It is not
266 // implemented in the plugin process.
271 PP_Var
PPB_Instance_Proxy::GetWindowObject(PP_Instance instance
) {
272 ReceiveSerializedVarReturnValue result
;
273 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetWindowObject(
274 API_ID_PPB_INSTANCE
, instance
, &result
));
275 return result
.Return(dispatcher());
278 PP_Var
PPB_Instance_Proxy::GetOwnerElementObject(PP_Instance instance
) {
279 ReceiveSerializedVarReturnValue result
;
280 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetOwnerElementObject(
281 API_ID_PPB_INSTANCE
, instance
, &result
));
282 return result
.Return(dispatcher());
285 PP_Var
PPB_Instance_Proxy::ExecuteScript(PP_Instance instance
,
288 ReceiveSerializedException
se(dispatcher(), exception
);
290 return PP_MakeUndefined();
292 ReceiveSerializedVarReturnValue result
;
293 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ExecuteScript(
294 API_ID_PPB_INSTANCE
, instance
,
295 SerializedVarSendInput(dispatcher(), script
), &se
, &result
));
296 return result
.Return(dispatcher());
299 uint32_t PPB_Instance_Proxy::GetAudioHardwareOutputSampleRate(
300 PP_Instance instance
) {
301 uint32_t result
= PP_AUDIOSAMPLERATE_NONE
;
303 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate(
304 API_ID_PPB_INSTANCE
, instance
, &result
));
308 uint32_t PPB_Instance_Proxy::GetAudioHardwareOutputBufferSize(
309 PP_Instance instance
) {
312 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputBufferSize(
313 API_ID_PPB_INSTANCE
, instance
, &result
));
317 PP_Var
PPB_Instance_Proxy::GetDefaultCharSet(PP_Instance instance
) {
318 PluginDispatcher
* dispatcher
= PluginDispatcher::GetForInstance(instance
);
320 return PP_MakeUndefined();
322 ReceiveSerializedVarReturnValue result
;
323 dispatcher
->Send(new PpapiHostMsg_PPBInstance_GetDefaultCharSet(
324 API_ID_PPB_INSTANCE
, instance
, &result
));
325 return result
.Return(dispatcher
);
328 void PPB_Instance_Proxy::SetPluginToHandleFindRequests(PP_Instance instance
) {
329 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetPluginToHandleFindRequests(
330 API_ID_PPB_INSTANCE
, instance
));
333 void PPB_Instance_Proxy::NumberOfFindResultsChanged(PP_Instance instance
,
335 PP_Bool final_result
) {
336 dispatcher()->Send(new PpapiHostMsg_PPBInstance_NumberOfFindResultsChanged(
337 API_ID_PPB_INSTANCE
, instance
, total
, final_result
));
340 void PPB_Instance_Proxy::SelectedFindResultChanged(PP_Instance instance
,
342 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SelectFindResultChanged(
343 API_ID_PPB_INSTANCE
, instance
, index
));
346 void PPB_Instance_Proxy::SetTickmarks(PP_Instance instance
,
347 const PP_Rect
* tickmarks
,
349 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTickmarks(
350 API_ID_PPB_INSTANCE
, instance
,
351 std::vector
<PP_Rect
>(tickmarks
, tickmarks
+ count
)));
354 PP_Bool
PPB_Instance_Proxy::IsFullscreen(PP_Instance instance
) {
355 InstanceData
* data
= static_cast<PluginDispatcher
*>(dispatcher())->
356 GetInstanceData(instance
);
359 return PP_FromBool(data
->view
.is_fullscreen
);
362 PP_Bool
PPB_Instance_Proxy::SetFullscreen(PP_Instance instance
,
363 PP_Bool fullscreen
) {
364 PP_Bool result
= PP_FALSE
;
365 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetFullscreen(
366 API_ID_PPB_INSTANCE
, instance
, fullscreen
, &result
));
370 PP_Bool
PPB_Instance_Proxy::GetScreenSize(PP_Instance instance
,
372 PP_Bool result
= PP_FALSE
;
373 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetScreenSize(
374 API_ID_PPB_INSTANCE
, instance
, &result
, size
));
378 Resource
* PPB_Instance_Proxy::GetSingletonResource(PP_Instance instance
,
379 SingletonResourceID id
) {
380 InstanceData
* data
= static_cast<PluginDispatcher
*>(dispatcher())->
381 GetInstanceData(instance
);
383 InstanceData::SingletonResourceMap::iterator it
=
384 data
->singleton_resources
.find(id
);
385 if (it
!= data
->singleton_resources
.end())
386 return it
->second
.get();
388 scoped_refptr
<Resource
> new_singleton
;
389 Connection
connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher());
392 case BROKER_SINGLETON_ID
:
393 new_singleton
= new BrokerResource(connection
, instance
);
395 case GAMEPAD_SINGLETON_ID
:
396 new_singleton
= new GamepadResource(connection
, instance
);
398 case ISOLATED_FILESYSTEM_SINGLETON_ID
:
400 new IsolatedFileSystemPrivateResource(connection
, instance
);
402 case NETWORK_PROXY_SINGLETON_ID
:
403 new_singleton
= new NetworkProxyResource(connection
, instance
);
405 case TRUETYPE_FONT_SINGLETON_ID
:
406 new_singleton
= new TrueTypeFontSingletonResource(connection
, instance
);
408 case UMA_SINGLETON_ID
:
409 new_singleton
= new UMAPrivateResource(connection
, instance
);
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
);
416 case FLASH_CLIPBOARD_SINGLETON_ID
:
417 new_singleton
= new FlashClipboardResource(connection
, instance
);
419 case FLASH_FILE_SINGLETON_ID
:
420 new_singleton
= new FlashFileResource(connection
, instance
);
422 case FLASH_FULLSCREEN_SINGLETON_ID
:
423 new_singleton
= new FlashFullscreenResource(connection
, instance
);
425 case FLASH_SINGLETON_ID
:
426 new_singleton
= new FlashResource(connection
, instance
,
427 static_cast<PluginDispatcher
*>(dispatcher()));
429 case PDF_SINGLETON_ID
:
430 new_singleton
= new PDFResource(connection
, instance
);
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
:
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.
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
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
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::StartTrackingLatency(PP_Instance instance
) {
484 dispatcher()->Send(new PpapiHostMsg_PPBInstance_StartTrackingLatency(
485 API_ID_PPB_INSTANCE
, instance
));
488 PP_Var
PPB_Instance_Proxy::GetDocumentURL(PP_Instance instance
,
489 PP_URLComponents_Dev
* components
) {
490 ReceiveSerializedVarReturnValue result
;
491 PP_URLComponents_Dev url_components
= {{0}};
492 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetDocumentURL(
493 API_ID_PPB_INSTANCE
, instance
, &url_components
, &result
));
495 *components
= url_components
;
496 return result
.Return(dispatcher());
499 #if !defined(OS_NACL)
500 PP_Var
PPB_Instance_Proxy::ResolveRelativeToDocument(
501 PP_Instance instance
,
503 PP_URLComponents_Dev
* components
) {
504 ReceiveSerializedVarReturnValue result
;
505 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ResolveRelativeToDocument(
506 API_ID_PPB_INSTANCE
, instance
,
507 SerializedVarSendInput(dispatcher(), relative
),
509 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
510 result
.Return(dispatcher()),
514 PP_Bool
PPB_Instance_Proxy::DocumentCanRequest(PP_Instance instance
,
516 PP_Bool result
= PP_FALSE
;
517 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanRequest(
518 API_ID_PPB_INSTANCE
, instance
,
519 SerializedVarSendInput(dispatcher(), url
),
524 PP_Bool
PPB_Instance_Proxy::DocumentCanAccessDocument(PP_Instance instance
,
525 PP_Instance target
) {
526 PP_Bool result
= PP_FALSE
;
527 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanAccessDocument(
528 API_ID_PPB_INSTANCE
, instance
, target
, &result
));
532 PP_Var
PPB_Instance_Proxy::GetPluginInstanceURL(
533 PP_Instance instance
,
534 PP_URLComponents_Dev
* components
) {
535 ReceiveSerializedVarReturnValue result
;
536 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginInstanceURL(
537 API_ID_PPB_INSTANCE
, instance
, &result
));
538 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
539 result
.Return(dispatcher()),
543 PP_Var
PPB_Instance_Proxy::GetPluginReferrerURL(
544 PP_Instance instance
,
545 PP_URLComponents_Dev
* components
) {
546 ReceiveSerializedVarReturnValue result
;
547 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginReferrerURL(
548 API_ID_PPB_INSTANCE
, instance
, &result
));
549 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
550 result
.Return(dispatcher()),
554 void PPB_Instance_Proxy::PromiseResolved(PP_Instance instance
,
556 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseResolved(
557 API_ID_PPB_INSTANCE
, instance
, promise_id
));
560 void PPB_Instance_Proxy::PromiseResolvedWithSession(PP_Instance instance
,
562 PP_Var session_id_var
) {
563 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseResolvedWithSession(
564 API_ID_PPB_INSTANCE
, instance
, promise_id
,
565 SerializedVarSendInput(dispatcher(), session_id_var
)));
568 void PPB_Instance_Proxy::PromiseRejected(PP_Instance instance
,
570 PP_CdmExceptionCode exception_code
,
572 PP_Var error_description_var
) {
573 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseRejected(
579 SerializedVarSendInput(dispatcher(), error_description_var
)));
582 void PPB_Instance_Proxy::SessionMessage(PP_Instance instance
,
583 PP_Var session_id_var
,
584 PP_CdmMessageType message_type
,
586 PP_Var legacy_destination_url_var
) {
587 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionMessage(
588 API_ID_PPB_INSTANCE
, instance
,
589 SerializedVarSendInput(dispatcher(), session_id_var
), message_type
,
590 SerializedVarSendInput(dispatcher(), message_var
),
591 SerializedVarSendInput(dispatcher(), legacy_destination_url_var
)));
594 void PPB_Instance_Proxy::SessionKeysChange(
595 PP_Instance instance
,
596 PP_Var session_id_var
,
597 PP_Bool has_additional_usable_key
,
599 const struct PP_KeyInformation key_information
[]) {
600 StringVar
* session_id
= StringVar::FromPPVar(session_id_var
);
602 session_id
->value().length() > media::limits::kMaxSessionIdLength
) {
607 if (key_count
> media::limits::kMaxKeyIds
) {
612 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionKeysChange(
613 API_ID_PPB_INSTANCE
, instance
, session_id
->value(),
614 has_additional_usable_key
,
615 std::vector
<PP_KeyInformation
>(key_information
,
616 key_information
+ key_count
)));
619 void PPB_Instance_Proxy::SessionExpirationChange(PP_Instance instance
,
620 PP_Var session_id_var
,
621 PP_Time new_expiry_time
) {
622 StringVar
* session_id
= StringVar::FromPPVar(session_id_var
);
624 session_id
->value().length() > media::limits::kMaxSessionIdLength
) {
629 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionExpirationChange(
630 API_ID_PPB_INSTANCE
, instance
, session_id
->value(), new_expiry_time
));
633 void PPB_Instance_Proxy::SessionClosed(PP_Instance instance
,
634 PP_Var session_id_var
) {
635 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionClosed(
636 API_ID_PPB_INSTANCE
, instance
,
637 SerializedVarSendInput(dispatcher(), session_id_var
)));
640 void PPB_Instance_Proxy::LegacySessionError(PP_Instance instance
,
641 PP_Var session_id_var
,
642 PP_CdmExceptionCode exception_code
,
644 PP_Var error_description_var
) {
645 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LegacySessionError(
646 API_ID_PPB_INSTANCE
, instance
,
647 SerializedVarSendInput(dispatcher(), session_id_var
), exception_code
,
649 SerializedVarSendInput(dispatcher(), error_description_var
)));
652 void PPB_Instance_Proxy::DeliverBlock(PP_Instance instance
,
653 PP_Resource decrypted_block
,
654 const PP_DecryptedBlockInfo
* block_info
) {
655 PP_Resource decrypted_block_host_resource
= 0;
657 if (decrypted_block
) {
659 PpapiGlobals::Get()->GetResourceTracker()->GetResource(decrypted_block
);
660 if (!object
|| object
->pp_instance() != instance
) {
664 decrypted_block_host_resource
= object
->host_resource().host_resource();
667 std::string serialized_block_info
;
668 if (!SerializeBlockInfo(*block_info
, &serialized_block_info
)) {
674 new PpapiHostMsg_PPBInstance_DeliverBlock(API_ID_PPB_INSTANCE
,
676 decrypted_block_host_resource
,
677 serialized_block_info
));
680 void PPB_Instance_Proxy::DecoderInitializeDone(
681 PP_Instance instance
,
682 PP_DecryptorStreamType decoder_type
,
686 new PpapiHostMsg_PPBInstance_DecoderInitializeDone(
694 void PPB_Instance_Proxy::DecoderDeinitializeDone(
695 PP_Instance instance
,
696 PP_DecryptorStreamType decoder_type
,
697 uint32_t request_id
) {
699 new PpapiHostMsg_PPBInstance_DecoderDeinitializeDone(
706 void PPB_Instance_Proxy::DecoderResetDone(PP_Instance instance
,
707 PP_DecryptorStreamType decoder_type
,
708 uint32_t request_id
) {
710 new PpapiHostMsg_PPBInstance_DecoderResetDone(
717 void PPB_Instance_Proxy::DeliverFrame(PP_Instance instance
,
718 PP_Resource decrypted_frame
,
719 const PP_DecryptedFrameInfo
* frame_info
) {
720 PP_Resource host_resource
= 0;
721 if (decrypted_frame
!= 0) {
722 ResourceTracker
* tracker
= PpapiGlobals::Get()->GetResourceTracker();
723 Resource
* object
= tracker
->GetResource(decrypted_frame
);
725 if (!object
|| object
->pp_instance() != instance
) {
730 host_resource
= object
->host_resource().host_resource();
733 std::string serialized_frame_info
;
734 if (!SerializeBlockInfo(*frame_info
, &serialized_frame_info
)) {
740 new PpapiHostMsg_PPBInstance_DeliverFrame(API_ID_PPB_INSTANCE
,
743 serialized_frame_info
));
746 void PPB_Instance_Proxy::DeliverSamples(
747 PP_Instance instance
,
748 PP_Resource decrypted_samples
,
749 const PP_DecryptedSampleInfo
* sample_info
) {
750 PP_Resource host_resource
= 0;
751 if (decrypted_samples
!= 0) {
752 ResourceTracker
* tracker
= PpapiGlobals::Get()->GetResourceTracker();
753 Resource
* object
= tracker
->GetResource(decrypted_samples
);
755 if (!object
|| object
->pp_instance() != instance
) {
760 host_resource
= object
->host_resource().host_resource();
763 std::string serialized_sample_info
;
764 if (!SerializeBlockInfo(*sample_info
, &serialized_sample_info
)) {
770 new PpapiHostMsg_PPBInstance_DeliverSamples(API_ID_PPB_INSTANCE
,
773 serialized_sample_info
));
775 #endif // !defined(OS_NACL)
777 void PPB_Instance_Proxy::PostMessage(PP_Instance instance
,
779 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage(
781 instance
, SerializedVarSendInputShmem(dispatcher(), message
,
785 int32_t PPB_Instance_Proxy::RegisterMessageHandler(
786 PP_Instance instance
,
788 const PPP_MessageHandler_0_2
* handler
,
789 PP_Resource message_loop
) {
791 static_cast<PluginDispatcher
*>(dispatcher())->GetInstanceData(instance
);
793 return PP_ERROR_BADARGUMENT
;
795 int32_t result
= PP_ERROR_FAILED
;
796 scoped_ptr
<MessageHandler
> message_handler
= MessageHandler::Create(
797 instance
, handler
, user_data
, message_loop
, &result
);
799 data
->message_handler
= message_handler
.Pass();
803 void PPB_Instance_Proxy::UnregisterMessageHandler(PP_Instance instance
) {
805 static_cast<PluginDispatcher
*>(dispatcher())->GetInstanceData(instance
);
808 data
->message_handler
.reset();
811 PP_Bool
PPB_Instance_Proxy::SetCursor(PP_Instance instance
,
812 PP_MouseCursor_Type type
,
814 const PP_Point
* hot_spot
) {
815 // Some of these parameters are important for security. This check is in the
816 // plugin process just for the convenience of the caller (since we don't
817 // bother returning errors from the other process with a sync message). The
818 // parameters will be validated again in the renderer.
819 if (!ValidateSetCursorParams(type
, image
, hot_spot
))
822 HostResource image_host_resource
;
824 Resource
* cursor_image
=
825 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image
);
826 if (!cursor_image
|| cursor_image
->pp_instance() != instance
)
828 image_host_resource
= cursor_image
->host_resource();
831 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetCursor(
832 API_ID_PPB_INSTANCE
, instance
, static_cast<int32_t>(type
),
833 image_host_resource
, hot_spot
? *hot_spot
: PP_MakePoint(0, 0)));
837 int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance
,
838 scoped_refptr
<TrackedCallback
> callback
) {
839 // Save the mouse callback on the instance data.
840 InstanceData
* data
= static_cast<PluginDispatcher
*>(dispatcher())->
841 GetInstanceData(instance
);
843 return PP_ERROR_BADARGUMENT
;
844 if (TrackedCallback::IsPending(data
->mouse_lock_callback
))
845 return PP_ERROR_INPROGRESS
; // Already have a pending callback.
846 data
->mouse_lock_callback
= callback
;
848 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LockMouse(
849 API_ID_PPB_INSTANCE
, instance
));
850 return PP_OK_COMPLETIONPENDING
;
853 void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance
) {
854 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UnlockMouse(
855 API_ID_PPB_INSTANCE
, instance
));
858 void PPB_Instance_Proxy::SetTextInputType(PP_Instance instance
,
859 PP_TextInput_Type type
) {
860 CancelAnyPendingRequestSurroundingText(instance
);
861 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTextInputType(
862 API_ID_PPB_INSTANCE
, instance
, type
));
865 void PPB_Instance_Proxy::UpdateCaretPosition(PP_Instance instance
,
866 const PP_Rect
& caret
,
867 const PP_Rect
& bounding_box
) {
868 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateCaretPosition(
869 API_ID_PPB_INSTANCE
, instance
, caret
, bounding_box
));
872 void PPB_Instance_Proxy::CancelCompositionText(PP_Instance instance
) {
873 CancelAnyPendingRequestSurroundingText(instance
);
874 dispatcher()->Send(new PpapiHostMsg_PPBInstance_CancelCompositionText(
875 API_ID_PPB_INSTANCE
, instance
));
878 void PPB_Instance_Proxy::SelectionChanged(PP_Instance instance
) {
879 // The "right" way to do this is to send the message to the host. However,
880 // all it will do is call RequestSurroundingText with a hardcoded number of
881 // characters in response, which is an entire IPC round-trip.
883 // We can avoid this round-trip by just implementing the
884 // RequestSurroundingText logic in the plugin process. If the logic in the
885 // host becomes more complex (like a more adaptive number of characters),
886 // we'll need to reevanuate whether we want to do the round trip instead.
888 // Be careful to post a task to avoid reentering the plugin.
891 static_cast<PluginDispatcher
*>(dispatcher())->GetInstanceData(instance
);
894 data
->should_do_request_surrounding_text
= true;
896 if (!data
->is_request_surrounding_text_pending
) {
897 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
899 RunWhileLocked(base::Bind(&RequestSurroundingText
, instance
)));
900 data
->is_request_surrounding_text_pending
= true;
904 void PPB_Instance_Proxy::UpdateSurroundingText(PP_Instance instance
,
908 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateSurroundingText(
909 API_ID_PPB_INSTANCE
, instance
, text
, caret
, anchor
));
912 #if !defined(OS_NACL)
913 void PPB_Instance_Proxy::OnHostMsgGetWindowObject(
914 PP_Instance instance
,
915 SerializedVarReturnValue result
) {
916 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
918 EnterInstanceNoLock
enter(instance
);
919 if (enter
.succeeded())
920 result
.Return(dispatcher(), enter
.functions()->GetWindowObject(instance
));
923 void PPB_Instance_Proxy::OnHostMsgGetOwnerElementObject(
924 PP_Instance instance
,
925 SerializedVarReturnValue result
) {
926 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
928 EnterInstanceNoLock
enter(instance
);
929 if (enter
.succeeded()) {
930 result
.Return(dispatcher(),
931 enter
.functions()->GetOwnerElementObject(instance
));
935 void PPB_Instance_Proxy::OnHostMsgBindGraphics(PP_Instance instance
,
936 PP_Resource device
) {
937 // Note that we ignroe the return value here. Otherwise, this would need to
938 // be a slow sync call, and the plugin side of the proxy will have already
939 // validated the resources, so we shouldn't see errors here that weren't
941 EnterInstanceNoLock
enter(instance
);
942 if (enter
.succeeded())
943 enter
.functions()->BindGraphics(instance
, device
);
946 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputSampleRate(
947 PP_Instance instance
, uint32_t* result
) {
948 EnterInstanceNoLock
enter(instance
);
949 if (enter
.succeeded())
950 *result
= enter
.functions()->GetAudioHardwareOutputSampleRate(instance
);
953 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputBufferSize(
954 PP_Instance instance
, uint32_t* result
) {
955 EnterInstanceNoLock
enter(instance
);
956 if (enter
.succeeded())
957 *result
= enter
.functions()->GetAudioHardwareOutputBufferSize(instance
);
960 void PPB_Instance_Proxy::OnHostMsgIsFullFrame(PP_Instance instance
,
962 EnterInstanceNoLock
enter(instance
);
963 if (enter
.succeeded())
964 *result
= enter
.functions()->IsFullFrame(instance
);
967 void PPB_Instance_Proxy::OnHostMsgExecuteScript(
968 PP_Instance instance
,
969 SerializedVarReceiveInput script
,
970 SerializedVarOutParam out_exception
,
971 SerializedVarReturnValue result
) {
972 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
974 EnterInstanceNoLock
enter(instance
);
978 if (dispatcher()->IsPlugin())
981 static_cast<HostDispatcher
*>(dispatcher())->set_allow_plugin_reentrancy();
983 result
.Return(dispatcher(), enter
.functions()->ExecuteScript(
985 script
.Get(dispatcher()),
986 out_exception
.OutParam(dispatcher())));
989 void PPB_Instance_Proxy::OnHostMsgGetDefaultCharSet(
990 PP_Instance instance
,
991 SerializedVarReturnValue result
) {
992 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
994 EnterInstanceNoLock
enter(instance
);
995 if (enter
.succeeded())
996 result
.Return(dispatcher(), enter
.functions()->GetDefaultCharSet(instance
));
999 void PPB_Instance_Proxy::OnHostMsgSetPluginToHandleFindRequests(
1000 PP_Instance instance
) {
1001 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1003 EnterInstanceNoLock
enter(instance
);
1004 if (enter
.succeeded())
1005 enter
.functions()->SetPluginToHandleFindRequests(instance
);
1008 void PPB_Instance_Proxy::OnHostMsgNumberOfFindResultsChanged(
1009 PP_Instance instance
,
1011 PP_Bool final_result
) {
1012 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1014 EnterInstanceNoLock
enter(instance
);
1015 if (enter
.succeeded()) {
1016 enter
.functions()->NumberOfFindResultsChanged(
1017 instance
, total
, final_result
);
1021 void PPB_Instance_Proxy::OnHostMsgSelectFindResultChanged(
1022 PP_Instance instance
,
1024 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1026 EnterInstanceNoLock
enter(instance
);
1027 if (enter
.succeeded())
1028 enter
.functions()->SelectedFindResultChanged(instance
, index
);
1031 void PPB_Instance_Proxy::OnHostMsgSetTickmarks(
1032 PP_Instance instance
,
1033 const std::vector
<PP_Rect
>& tickmarks
) {
1034 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1036 const PP_Rect
* array
= tickmarks
.empty() ? NULL
: &tickmarks
[0];
1037 EnterInstanceNoLock
enter(instance
);
1038 if (enter
.succeeded()) {
1039 enter
.functions()->SetTickmarks(instance
,
1041 static_cast<uint32_t>(tickmarks
.size()));
1045 void PPB_Instance_Proxy::OnHostMsgSetFullscreen(PP_Instance instance
,
1048 EnterInstanceNoLock
enter(instance
);
1049 if (enter
.succeeded())
1050 *result
= enter
.functions()->SetFullscreen(instance
, fullscreen
);
1054 void PPB_Instance_Proxy::OnHostMsgGetScreenSize(PP_Instance instance
,
1057 EnterInstanceNoLock
enter(instance
);
1058 if (enter
.succeeded())
1059 *result
= enter
.functions()->GetScreenSize(instance
, size
);
1062 void PPB_Instance_Proxy::OnHostMsgRequestInputEvents(PP_Instance instance
,
1064 uint32_t event_classes
) {
1065 EnterInstanceNoLock
enter(instance
);
1066 if (enter
.succeeded()) {
1068 enter
.functions()->RequestFilteringInputEvents(instance
, event_classes
);
1070 enter
.functions()->RequestInputEvents(instance
, event_classes
);
1074 void PPB_Instance_Proxy::OnHostMsgClearInputEvents(PP_Instance instance
,
1075 uint32_t event_classes
) {
1076 EnterInstanceNoLock
enter(instance
);
1077 if (enter
.succeeded())
1078 enter
.functions()->ClearInputEventRequest(instance
, event_classes
);
1081 void PPB_Instance_Proxy::OnHostMsgStartTrackingLatency(PP_Instance instance
) {
1082 EnterInstanceNoLock
enter(instance
);
1083 if (enter
.succeeded())
1084 enter
.functions()->StartTrackingLatency(instance
);
1087 void PPB_Instance_Proxy::OnHostMsgPostMessage(
1088 PP_Instance instance
,
1089 SerializedVarReceiveInput message
) {
1090 EnterInstanceNoLock
enter(instance
);
1091 if (!message
.is_valid_var()) {
1092 PpapiGlobals::Get()->LogWithSource(
1093 instance
, PP_LOGLEVEL_ERROR
, std::string(), kSerializationError
);
1097 if (enter
.succeeded())
1098 enter
.functions()->PostMessage(instance
,
1099 message
.GetForInstance(dispatcher(),
1103 void PPB_Instance_Proxy::OnHostMsgLockMouse(PP_Instance instance
) {
1104 // Need to be careful to always issue the callback.
1105 pp::CompletionCallback cb
= callback_factory_
.NewCallback(
1106 &PPB_Instance_Proxy::MouseLockCompleteInHost
, instance
);
1108 EnterInstanceNoLock
enter(instance
, cb
.pp_completion_callback());
1109 if (enter
.succeeded())
1110 enter
.SetResult(enter
.functions()->LockMouse(instance
, enter
.callback()));
1113 void PPB_Instance_Proxy::OnHostMsgUnlockMouse(PP_Instance instance
) {
1114 EnterInstanceNoLock
enter(instance
);
1115 if (enter
.succeeded())
1116 enter
.functions()->UnlockMouse(instance
);
1119 void PPB_Instance_Proxy::OnHostMsgGetDocumentURL(
1120 PP_Instance instance
,
1121 PP_URLComponents_Dev
* components
,
1122 SerializedVarReturnValue result
) {
1123 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1125 EnterInstanceNoLock
enter(instance
);
1126 if (enter
.succeeded()) {
1127 PP_Var document_url
= enter
.functions()->GetDocumentURL(instance
,
1129 result
.Return(dispatcher(), document_url
);
1133 void PPB_Instance_Proxy::OnHostMsgResolveRelativeToDocument(
1134 PP_Instance instance
,
1135 SerializedVarReceiveInput relative
,
1136 SerializedVarReturnValue result
) {
1137 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1139 EnterInstanceNoLock
enter(instance
);
1140 if (enter
.succeeded()) {
1141 result
.Return(dispatcher(),
1142 enter
.functions()->ResolveRelativeToDocument(
1143 instance
, relative
.Get(dispatcher()), NULL
));
1147 void PPB_Instance_Proxy::OnHostMsgDocumentCanRequest(
1148 PP_Instance instance
,
1149 SerializedVarReceiveInput url
,
1151 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1153 EnterInstanceNoLock
enter(instance
);
1154 if (enter
.succeeded()) {
1155 *result
= enter
.functions()->DocumentCanRequest(instance
,
1156 url
.Get(dispatcher()));
1160 void PPB_Instance_Proxy::OnHostMsgDocumentCanAccessDocument(PP_Instance active
,
1163 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1165 EnterInstanceNoLock
enter(active
);
1166 if (enter
.succeeded())
1167 *result
= enter
.functions()->DocumentCanAccessDocument(active
, target
);
1170 void PPB_Instance_Proxy::OnHostMsgGetPluginInstanceURL(
1171 PP_Instance instance
,
1172 SerializedVarReturnValue result
) {
1173 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1175 EnterInstanceNoLock
enter(instance
);
1176 if (enter
.succeeded()) {
1177 result
.Return(dispatcher(),
1178 enter
.functions()->GetPluginInstanceURL(instance
, NULL
));
1182 void PPB_Instance_Proxy::OnHostMsgGetPluginReferrerURL(
1183 PP_Instance instance
,
1184 SerializedVarReturnValue result
) {
1185 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1187 EnterInstanceNoLock
enter(instance
);
1188 if (enter
.succeeded()) {
1189 result
.Return(dispatcher(),
1190 enter
.functions()->GetPluginReferrerURL(instance
, NULL
));
1194 void PPB_Instance_Proxy::OnHostMsgPromiseResolved(PP_Instance instance
,
1195 uint32_t promise_id
) {
1196 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1198 EnterInstanceNoLock
enter(instance
);
1199 if (enter
.succeeded()) {
1200 enter
.functions()->PromiseResolved(instance
, promise_id
);
1204 void PPB_Instance_Proxy::OnHostMsgPromiseResolvedWithSession(
1205 PP_Instance instance
,
1206 uint32_t promise_id
,
1207 SerializedVarReceiveInput session_id
) {
1208 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1210 EnterInstanceNoLock
enter(instance
);
1211 if (enter
.succeeded()) {
1212 enter
.functions()->PromiseResolvedWithSession(instance
, promise_id
,
1213 session_id
.Get(dispatcher()));
1217 void PPB_Instance_Proxy::OnHostMsgPromiseRejected(
1218 PP_Instance instance
,
1219 uint32_t promise_id
,
1220 PP_CdmExceptionCode exception_code
,
1221 uint32_t system_code
,
1222 SerializedVarReceiveInput error_description
) {
1223 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1225 EnterInstanceNoLock
enter(instance
);
1226 if (enter
.succeeded()) {
1227 enter
.functions()->PromiseRejected(instance
,
1231 error_description
.Get(dispatcher()));
1235 void PPB_Instance_Proxy::OnHostMsgSessionMessage(
1236 PP_Instance instance
,
1237 SerializedVarReceiveInput session_id
,
1238 PP_CdmMessageType message_type
,
1239 SerializedVarReceiveInput message
,
1240 SerializedVarReceiveInput legacy_destination_url
) {
1241 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1243 EnterInstanceNoLock
enter(instance
);
1244 if (enter
.succeeded()) {
1245 enter
.functions()->SessionMessage(instance
, session_id
.Get(dispatcher()),
1246 message_type
, message
.Get(dispatcher()),
1247 legacy_destination_url
.Get(dispatcher()));
1251 void PPB_Instance_Proxy::OnHostMsgSessionKeysChange(
1252 PP_Instance instance
,
1253 const std::string
& session_id
,
1254 PP_Bool has_additional_usable_key
,
1255 const std::vector
<PP_KeyInformation
>& key_information
) {
1256 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1259 if (key_information
.size() > media::limits::kMaxKeyIds
) {
1264 EnterInstanceNoLock
enter(instance
);
1265 if (enter
.succeeded()) {
1266 ScopedPPVar
session_id_var(ScopedPPVar::PassRef(),
1267 StringVar::StringToPPVar(session_id
));
1268 enter
.functions()->SessionKeysChange(
1269 instance
, session_id_var
.get(), has_additional_usable_key
,
1270 base::checked_cast
<uint32_t>(key_information
.size()),
1271 vector_as_array(&key_information
));
1275 void PPB_Instance_Proxy::OnHostMsgSessionExpirationChange(
1276 PP_Instance instance
,
1277 const std::string
& session_id
,
1278 PP_Time new_expiry_time
) {
1279 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1281 EnterInstanceNoLock
enter(instance
);
1282 if (enter
.succeeded()) {
1283 ScopedPPVar
session_id_var(ScopedPPVar::PassRef(),
1284 StringVar::StringToPPVar(session_id
));
1285 enter
.functions()->SessionExpirationChange(instance
, session_id_var
.get(),
1290 void PPB_Instance_Proxy::OnHostMsgSessionClosed(
1291 PP_Instance instance
,
1292 SerializedVarReceiveInput session_id
) {
1293 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1295 EnterInstanceNoLock
enter(instance
);
1296 if (enter
.succeeded()) {
1297 enter
.functions()->SessionClosed(instance
, session_id
.Get(dispatcher()));
1301 void PPB_Instance_Proxy::OnHostMsgLegacySessionError(
1302 PP_Instance instance
,
1303 SerializedVarReceiveInput session_id
,
1304 PP_CdmExceptionCode exception_code
,
1305 uint32_t system_code
,
1306 SerializedVarReceiveInput error_description
) {
1307 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1309 EnterInstanceNoLock
enter(instance
);
1310 if (enter
.succeeded()) {
1311 enter
.functions()->LegacySessionError(
1312 instance
, session_id
.Get(dispatcher()), exception_code
, system_code
,
1313 error_description
.Get(dispatcher()));
1317 void PPB_Instance_Proxy::OnHostMsgDeliverBlock(
1318 PP_Instance instance
,
1319 PP_Resource decrypted_block
,
1320 const std::string
& serialized_block_info
) {
1321 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1323 PP_DecryptedBlockInfo block_info
;
1324 if (!DeserializeBlockInfo(serialized_block_info
, &block_info
))
1327 EnterInstanceNoLock
enter(instance
);
1328 if (enter
.succeeded())
1329 enter
.functions()->DeliverBlock(instance
, decrypted_block
, &block_info
);
1332 void PPB_Instance_Proxy::OnHostMsgDecoderInitializeDone(
1333 PP_Instance instance
,
1334 PP_DecryptorStreamType decoder_type
,
1335 uint32_t request_id
,
1337 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1339 EnterInstanceNoLock
enter(instance
);
1340 if (enter
.succeeded()) {
1341 enter
.functions()->DecoderInitializeDone(instance
,
1348 void PPB_Instance_Proxy::OnHostMsgDecoderDeinitializeDone(
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()->DecoderDeinitializeDone(instance
,
1361 void PPB_Instance_Proxy::OnHostMsgDecoderResetDone(
1362 PP_Instance instance
,
1363 PP_DecryptorStreamType decoder_type
,
1364 uint32_t request_id
) {
1365 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1367 EnterInstanceNoLock
enter(instance
);
1368 if (enter
.succeeded())
1369 enter
.functions()->DecoderResetDone(instance
, decoder_type
, request_id
);
1372 void PPB_Instance_Proxy::OnHostMsgDeliverFrame(
1373 PP_Instance instance
,
1374 PP_Resource decrypted_frame
,
1375 const std::string
& serialized_frame_info
) {
1376 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1378 PP_DecryptedFrameInfo frame_info
;
1379 if (!DeserializeBlockInfo(serialized_frame_info
, &frame_info
))
1382 EnterInstanceNoLock
enter(instance
);
1383 if (enter
.succeeded())
1384 enter
.functions()->DeliverFrame(instance
, decrypted_frame
, &frame_info
);
1387 void PPB_Instance_Proxy::OnHostMsgDeliverSamples(
1388 PP_Instance instance
,
1389 PP_Resource audio_frames
,
1390 const std::string
& serialized_sample_info
) {
1391 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1393 PP_DecryptedSampleInfo sample_info
;
1394 if (!DeserializeBlockInfo(serialized_sample_info
, &sample_info
))
1397 EnterInstanceNoLock
enter(instance
);
1398 if (enter
.succeeded())
1399 enter
.functions()->DeliverSamples(instance
, audio_frames
, &sample_info
);
1402 void PPB_Instance_Proxy::OnHostMsgSetCursor(
1403 PP_Instance instance
,
1405 const ppapi::HostResource
& custom_image
,
1406 const PP_Point
& hot_spot
) {
1407 // This API serves PPB_CursorControl_Dev and PPB_MouseCursor, so is public.
1408 EnterInstanceNoLock
enter(instance
);
1409 if (enter
.succeeded()) {
1410 enter
.functions()->SetCursor(
1411 instance
, static_cast<PP_MouseCursor_Type
>(type
),
1412 custom_image
.host_resource(), &hot_spot
);
1416 void PPB_Instance_Proxy::OnHostMsgSetTextInputType(PP_Instance instance
,
1417 PP_TextInput_Type type
) {
1418 EnterInstanceNoLock
enter(instance
);
1419 if (enter
.succeeded())
1420 enter
.functions()->SetTextInputType(instance
, type
);
1423 void PPB_Instance_Proxy::OnHostMsgUpdateCaretPosition(
1424 PP_Instance instance
,
1425 const PP_Rect
& caret
,
1426 const PP_Rect
& bounding_box
) {
1427 EnterInstanceNoLock
enter(instance
);
1428 if (enter
.succeeded())
1429 enter
.functions()->UpdateCaretPosition(instance
, caret
, bounding_box
);
1432 void PPB_Instance_Proxy::OnHostMsgCancelCompositionText(PP_Instance instance
) {
1433 EnterInstanceNoLock
enter(instance
);
1434 if (enter
.succeeded())
1435 enter
.functions()->CancelCompositionText(instance
);
1438 void PPB_Instance_Proxy::OnHostMsgUpdateSurroundingText(
1439 PP_Instance instance
,
1440 const std::string
& text
,
1443 EnterInstanceNoLock
enter(instance
);
1444 if (enter
.succeeded()) {
1445 enter
.functions()->UpdateSurroundingText(instance
, text
.c_str(), caret
,
1449 #endif // !defined(OS_NACL)
1451 void PPB_Instance_Proxy::OnPluginMsgMouseLockComplete(PP_Instance instance
,
1453 if (!dispatcher()->IsPlugin())
1456 // Save the mouse callback on the instance data.
1457 InstanceData
* data
= static_cast<PluginDispatcher
*>(dispatcher())->
1458 GetInstanceData(instance
);
1460 return; // Instance was probably deleted.
1461 if (!TrackedCallback::IsPending(data
->mouse_lock_callback
)) {
1465 data
->mouse_lock_callback
->Run(result
);
1468 #if !defined(OS_NACL)
1469 void PPB_Instance_Proxy::MouseLockCompleteInHost(int32_t result
,
1470 PP_Instance instance
) {
1471 dispatcher()->Send(new PpapiMsg_PPBInstance_MouseLockComplete(
1472 API_ID_PPB_INSTANCE
, instance
, result
));
1474 #endif // !defined(OS_NACL)
1476 void PPB_Instance_Proxy::CancelAnyPendingRequestSurroundingText(
1477 PP_Instance instance
) {
1478 InstanceData
* data
= static_cast<PluginDispatcher
*>(dispatcher())->
1479 GetInstanceData(instance
);
1481 return; // Instance was probably deleted.
1482 data
->should_do_request_surrounding_text
= false;
1485 } // namespace proxy
1486 } // namespace ppapi