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 void PPB_Instance_Proxy::ZoomChanged(PP_Instance instance
,
494 void PPB_Instance_Proxy::ZoomLimitsChanged(PP_Instance instance
,
495 double minimum_factor
,
496 double maximium_factor
) {
501 PP_Var
PPB_Instance_Proxy::GetDocumentURL(PP_Instance instance
,
502 PP_URLComponents_Dev
* components
) {
503 ReceiveSerializedVarReturnValue result
;
504 PP_URLComponents_Dev url_components
= {{0}};
505 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetDocumentURL(
506 API_ID_PPB_INSTANCE
, instance
, &url_components
, &result
));
508 *components
= url_components
;
509 return result
.Return(dispatcher());
512 #if !defined(OS_NACL)
513 PP_Var
PPB_Instance_Proxy::ResolveRelativeToDocument(
514 PP_Instance instance
,
516 PP_URLComponents_Dev
* components
) {
517 ReceiveSerializedVarReturnValue result
;
518 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ResolveRelativeToDocument(
519 API_ID_PPB_INSTANCE
, instance
,
520 SerializedVarSendInput(dispatcher(), relative
),
522 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
523 result
.Return(dispatcher()),
527 PP_Bool
PPB_Instance_Proxy::DocumentCanRequest(PP_Instance instance
,
529 PP_Bool result
= PP_FALSE
;
530 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanRequest(
531 API_ID_PPB_INSTANCE
, instance
,
532 SerializedVarSendInput(dispatcher(), url
),
537 PP_Bool
PPB_Instance_Proxy::DocumentCanAccessDocument(PP_Instance instance
,
538 PP_Instance target
) {
539 PP_Bool result
= PP_FALSE
;
540 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanAccessDocument(
541 API_ID_PPB_INSTANCE
, instance
, target
, &result
));
545 PP_Var
PPB_Instance_Proxy::GetPluginInstanceURL(
546 PP_Instance instance
,
547 PP_URLComponents_Dev
* components
) {
548 ReceiveSerializedVarReturnValue result
;
549 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginInstanceURL(
550 API_ID_PPB_INSTANCE
, instance
, &result
));
551 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
552 result
.Return(dispatcher()),
556 PP_Var
PPB_Instance_Proxy::GetPluginReferrerURL(
557 PP_Instance instance
,
558 PP_URLComponents_Dev
* components
) {
559 ReceiveSerializedVarReturnValue result
;
560 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginReferrerURL(
561 API_ID_PPB_INSTANCE
, instance
, &result
));
562 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
563 result
.Return(dispatcher()),
567 void PPB_Instance_Proxy::PromiseResolved(PP_Instance instance
,
569 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseResolved(
570 API_ID_PPB_INSTANCE
, instance
, promise_id
));
573 void PPB_Instance_Proxy::PromiseResolvedWithSession(PP_Instance instance
,
575 PP_Var session_id_var
) {
576 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseResolvedWithSession(
577 API_ID_PPB_INSTANCE
, instance
, promise_id
,
578 SerializedVarSendInput(dispatcher(), session_id_var
)));
581 void PPB_Instance_Proxy::PromiseRejected(PP_Instance instance
,
583 PP_CdmExceptionCode exception_code
,
585 PP_Var error_description_var
) {
586 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseRejected(
592 SerializedVarSendInput(dispatcher(), error_description_var
)));
595 void PPB_Instance_Proxy::SessionMessage(PP_Instance instance
,
596 PP_Var session_id_var
,
597 PP_CdmMessageType message_type
,
599 PP_Var legacy_destination_url_var
) {
600 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionMessage(
601 API_ID_PPB_INSTANCE
, instance
,
602 SerializedVarSendInput(dispatcher(), session_id_var
), message_type
,
603 SerializedVarSendInput(dispatcher(), message_var
),
604 SerializedVarSendInput(dispatcher(), legacy_destination_url_var
)));
607 void PPB_Instance_Proxy::SessionKeysChange(
608 PP_Instance instance
,
609 PP_Var session_id_var
,
610 PP_Bool has_additional_usable_key
,
612 const struct PP_KeyInformation key_information
[]) {
613 StringVar
* session_id
= StringVar::FromPPVar(session_id_var
);
615 session_id
->value().length() > media::limits::kMaxSessionIdLength
) {
620 if (key_count
> media::limits::kMaxKeyIds
) {
625 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionKeysChange(
626 API_ID_PPB_INSTANCE
, instance
, session_id
->value(),
627 has_additional_usable_key
,
628 std::vector
<PP_KeyInformation
>(key_information
,
629 key_information
+ key_count
)));
632 void PPB_Instance_Proxy::SessionExpirationChange(PP_Instance instance
,
633 PP_Var session_id_var
,
634 PP_Time new_expiry_time
) {
635 StringVar
* session_id
= StringVar::FromPPVar(session_id_var
);
637 session_id
->value().length() > media::limits::kMaxSessionIdLength
) {
642 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionExpirationChange(
643 API_ID_PPB_INSTANCE
, instance
, session_id
->value(), new_expiry_time
));
646 void PPB_Instance_Proxy::SessionClosed(PP_Instance instance
,
647 PP_Var session_id_var
) {
648 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionClosed(
649 API_ID_PPB_INSTANCE
, instance
,
650 SerializedVarSendInput(dispatcher(), session_id_var
)));
653 void PPB_Instance_Proxy::LegacySessionError(PP_Instance instance
,
654 PP_Var session_id_var
,
655 PP_CdmExceptionCode exception_code
,
657 PP_Var error_description_var
) {
658 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LegacySessionError(
659 API_ID_PPB_INSTANCE
, instance
,
660 SerializedVarSendInput(dispatcher(), session_id_var
), exception_code
,
662 SerializedVarSendInput(dispatcher(), error_description_var
)));
665 void PPB_Instance_Proxy::DeliverBlock(PP_Instance instance
,
666 PP_Resource decrypted_block
,
667 const PP_DecryptedBlockInfo
* block_info
) {
668 PP_Resource decrypted_block_host_resource
= 0;
670 if (decrypted_block
) {
672 PpapiGlobals::Get()->GetResourceTracker()->GetResource(decrypted_block
);
673 if (!object
|| object
->pp_instance() != instance
) {
677 decrypted_block_host_resource
= object
->host_resource().host_resource();
680 std::string serialized_block_info
;
681 if (!SerializeBlockInfo(*block_info
, &serialized_block_info
)) {
687 new PpapiHostMsg_PPBInstance_DeliverBlock(API_ID_PPB_INSTANCE
,
689 decrypted_block_host_resource
,
690 serialized_block_info
));
693 void PPB_Instance_Proxy::DecoderInitializeDone(
694 PP_Instance instance
,
695 PP_DecryptorStreamType decoder_type
,
699 new PpapiHostMsg_PPBInstance_DecoderInitializeDone(
707 void PPB_Instance_Proxy::DecoderDeinitializeDone(
708 PP_Instance instance
,
709 PP_DecryptorStreamType decoder_type
,
710 uint32_t request_id
) {
712 new PpapiHostMsg_PPBInstance_DecoderDeinitializeDone(
719 void PPB_Instance_Proxy::DecoderResetDone(PP_Instance instance
,
720 PP_DecryptorStreamType decoder_type
,
721 uint32_t request_id
) {
723 new PpapiHostMsg_PPBInstance_DecoderResetDone(
730 void PPB_Instance_Proxy::DeliverFrame(PP_Instance instance
,
731 PP_Resource decrypted_frame
,
732 const PP_DecryptedFrameInfo
* frame_info
) {
733 PP_Resource host_resource
= 0;
734 if (decrypted_frame
!= 0) {
735 ResourceTracker
* tracker
= PpapiGlobals::Get()->GetResourceTracker();
736 Resource
* object
= tracker
->GetResource(decrypted_frame
);
738 if (!object
|| object
->pp_instance() != instance
) {
743 host_resource
= object
->host_resource().host_resource();
746 std::string serialized_frame_info
;
747 if (!SerializeBlockInfo(*frame_info
, &serialized_frame_info
)) {
753 new PpapiHostMsg_PPBInstance_DeliverFrame(API_ID_PPB_INSTANCE
,
756 serialized_frame_info
));
759 void PPB_Instance_Proxy::DeliverSamples(
760 PP_Instance instance
,
761 PP_Resource decrypted_samples
,
762 const PP_DecryptedSampleInfo
* sample_info
) {
763 PP_Resource host_resource
= 0;
764 if (decrypted_samples
!= 0) {
765 ResourceTracker
* tracker
= PpapiGlobals::Get()->GetResourceTracker();
766 Resource
* object
= tracker
->GetResource(decrypted_samples
);
768 if (!object
|| object
->pp_instance() != instance
) {
773 host_resource
= object
->host_resource().host_resource();
776 std::string serialized_sample_info
;
777 if (!SerializeBlockInfo(*sample_info
, &serialized_sample_info
)) {
783 new PpapiHostMsg_PPBInstance_DeliverSamples(API_ID_PPB_INSTANCE
,
786 serialized_sample_info
));
788 #endif // !defined(OS_NACL)
790 void PPB_Instance_Proxy::PostMessage(PP_Instance instance
,
792 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage(
794 instance
, SerializedVarSendInputShmem(dispatcher(), message
,
798 int32_t PPB_Instance_Proxy::RegisterMessageHandler(
799 PP_Instance instance
,
801 const PPP_MessageHandler_0_2
* handler
,
802 PP_Resource message_loop
) {
804 static_cast<PluginDispatcher
*>(dispatcher())->GetInstanceData(instance
);
806 return PP_ERROR_BADARGUMENT
;
808 int32_t result
= PP_ERROR_FAILED
;
809 scoped_ptr
<MessageHandler
> message_handler
= MessageHandler::Create(
810 instance
, handler
, user_data
, message_loop
, &result
);
812 data
->message_handler
= message_handler
.Pass();
816 void PPB_Instance_Proxy::UnregisterMessageHandler(PP_Instance instance
) {
818 static_cast<PluginDispatcher
*>(dispatcher())->GetInstanceData(instance
);
821 data
->message_handler
.reset();
824 PP_Bool
PPB_Instance_Proxy::SetCursor(PP_Instance instance
,
825 PP_MouseCursor_Type type
,
827 const PP_Point
* hot_spot
) {
828 // Some of these parameters are important for security. This check is in the
829 // plugin process just for the convenience of the caller (since we don't
830 // bother returning errors from the other process with a sync message). The
831 // parameters will be validated again in the renderer.
832 if (!ValidateSetCursorParams(type
, image
, hot_spot
))
835 HostResource image_host_resource
;
837 Resource
* cursor_image
=
838 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image
);
839 if (!cursor_image
|| cursor_image
->pp_instance() != instance
)
841 image_host_resource
= cursor_image
->host_resource();
844 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetCursor(
845 API_ID_PPB_INSTANCE
, instance
, static_cast<int32_t>(type
),
846 image_host_resource
, hot_spot
? *hot_spot
: PP_MakePoint(0, 0)));
850 int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance
,
851 scoped_refptr
<TrackedCallback
> callback
) {
852 // Save the mouse callback on the instance data.
853 InstanceData
* data
= static_cast<PluginDispatcher
*>(dispatcher())->
854 GetInstanceData(instance
);
856 return PP_ERROR_BADARGUMENT
;
857 if (TrackedCallback::IsPending(data
->mouse_lock_callback
))
858 return PP_ERROR_INPROGRESS
; // Already have a pending callback.
859 data
->mouse_lock_callback
= callback
;
861 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LockMouse(
862 API_ID_PPB_INSTANCE
, instance
));
863 return PP_OK_COMPLETIONPENDING
;
866 void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance
) {
867 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UnlockMouse(
868 API_ID_PPB_INSTANCE
, instance
));
871 void PPB_Instance_Proxy::SetTextInputType(PP_Instance instance
,
872 PP_TextInput_Type type
) {
873 CancelAnyPendingRequestSurroundingText(instance
);
874 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTextInputType(
875 API_ID_PPB_INSTANCE
, instance
, type
));
878 void PPB_Instance_Proxy::UpdateCaretPosition(PP_Instance instance
,
879 const PP_Rect
& caret
,
880 const PP_Rect
& bounding_box
) {
881 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateCaretPosition(
882 API_ID_PPB_INSTANCE
, instance
, caret
, bounding_box
));
885 void PPB_Instance_Proxy::CancelCompositionText(PP_Instance instance
) {
886 CancelAnyPendingRequestSurroundingText(instance
);
887 dispatcher()->Send(new PpapiHostMsg_PPBInstance_CancelCompositionText(
888 API_ID_PPB_INSTANCE
, instance
));
891 void PPB_Instance_Proxy::SelectionChanged(PP_Instance instance
) {
892 // The "right" way to do this is to send the message to the host. However,
893 // all it will do is call RequestSurroundingText with a hardcoded number of
894 // characters in response, which is an entire IPC round-trip.
896 // We can avoid this round-trip by just implementing the
897 // RequestSurroundingText logic in the plugin process. If the logic in the
898 // host becomes more complex (like a more adaptive number of characters),
899 // we'll need to reevanuate whether we want to do the round trip instead.
901 // Be careful to post a task to avoid reentering the plugin.
904 static_cast<PluginDispatcher
*>(dispatcher())->GetInstanceData(instance
);
907 data
->should_do_request_surrounding_text
= true;
909 if (!data
->is_request_surrounding_text_pending
) {
910 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
912 RunWhileLocked(base::Bind(&RequestSurroundingText
, instance
)));
913 data
->is_request_surrounding_text_pending
= true;
917 void PPB_Instance_Proxy::UpdateSurroundingText(PP_Instance instance
,
921 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateSurroundingText(
922 API_ID_PPB_INSTANCE
, instance
, text
, caret
, anchor
));
925 #if !defined(OS_NACL)
926 void PPB_Instance_Proxy::OnHostMsgGetWindowObject(
927 PP_Instance instance
,
928 SerializedVarReturnValue result
) {
929 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
931 EnterInstanceNoLock
enter(instance
);
932 if (enter
.succeeded())
933 result
.Return(dispatcher(), enter
.functions()->GetWindowObject(instance
));
936 void PPB_Instance_Proxy::OnHostMsgGetOwnerElementObject(
937 PP_Instance instance
,
938 SerializedVarReturnValue result
) {
939 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
941 EnterInstanceNoLock
enter(instance
);
942 if (enter
.succeeded()) {
943 result
.Return(dispatcher(),
944 enter
.functions()->GetOwnerElementObject(instance
));
948 void PPB_Instance_Proxy::OnHostMsgBindGraphics(PP_Instance instance
,
949 PP_Resource device
) {
950 // Note that we ignroe the return value here. Otherwise, this would need to
951 // be a slow sync call, and the plugin side of the proxy will have already
952 // validated the resources, so we shouldn't see errors here that weren't
954 EnterInstanceNoLock
enter(instance
);
955 if (enter
.succeeded())
956 enter
.functions()->BindGraphics(instance
, device
);
959 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputSampleRate(
960 PP_Instance instance
, uint32_t* result
) {
961 EnterInstanceNoLock
enter(instance
);
962 if (enter
.succeeded())
963 *result
= enter
.functions()->GetAudioHardwareOutputSampleRate(instance
);
966 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputBufferSize(
967 PP_Instance instance
, uint32_t* result
) {
968 EnterInstanceNoLock
enter(instance
);
969 if (enter
.succeeded())
970 *result
= enter
.functions()->GetAudioHardwareOutputBufferSize(instance
);
973 void PPB_Instance_Proxy::OnHostMsgIsFullFrame(PP_Instance instance
,
975 EnterInstanceNoLock
enter(instance
);
976 if (enter
.succeeded())
977 *result
= enter
.functions()->IsFullFrame(instance
);
980 void PPB_Instance_Proxy::OnHostMsgExecuteScript(
981 PP_Instance instance
,
982 SerializedVarReceiveInput script
,
983 SerializedVarOutParam out_exception
,
984 SerializedVarReturnValue result
) {
985 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
987 EnterInstanceNoLock
enter(instance
);
991 if (dispatcher()->IsPlugin())
994 static_cast<HostDispatcher
*>(dispatcher())->set_allow_plugin_reentrancy();
996 result
.Return(dispatcher(), enter
.functions()->ExecuteScript(
998 script
.Get(dispatcher()),
999 out_exception
.OutParam(dispatcher())));
1002 void PPB_Instance_Proxy::OnHostMsgGetDefaultCharSet(
1003 PP_Instance instance
,
1004 SerializedVarReturnValue result
) {
1005 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1007 EnterInstanceNoLock
enter(instance
);
1008 if (enter
.succeeded())
1009 result
.Return(dispatcher(), enter
.functions()->GetDefaultCharSet(instance
));
1012 void PPB_Instance_Proxy::OnHostMsgSetPluginToHandleFindRequests(
1013 PP_Instance instance
) {
1014 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1016 EnterInstanceNoLock
enter(instance
);
1017 if (enter
.succeeded())
1018 enter
.functions()->SetPluginToHandleFindRequests(instance
);
1021 void PPB_Instance_Proxy::OnHostMsgNumberOfFindResultsChanged(
1022 PP_Instance instance
,
1024 PP_Bool final_result
) {
1025 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1027 EnterInstanceNoLock
enter(instance
);
1028 if (enter
.succeeded()) {
1029 enter
.functions()->NumberOfFindResultsChanged(
1030 instance
, total
, final_result
);
1034 void PPB_Instance_Proxy::OnHostMsgSelectFindResultChanged(
1035 PP_Instance instance
,
1037 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1039 EnterInstanceNoLock
enter(instance
);
1040 if (enter
.succeeded())
1041 enter
.functions()->SelectedFindResultChanged(instance
, index
);
1044 void PPB_Instance_Proxy::OnHostMsgSetTickmarks(
1045 PP_Instance instance
,
1046 const std::vector
<PP_Rect
>& tickmarks
) {
1047 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1049 const PP_Rect
* array
= tickmarks
.empty() ? NULL
: &tickmarks
[0];
1050 EnterInstanceNoLock
enter(instance
);
1051 if (enter
.succeeded()) {
1052 enter
.functions()->SetTickmarks(instance
,
1054 static_cast<uint32_t>(tickmarks
.size()));
1058 void PPB_Instance_Proxy::OnHostMsgSetFullscreen(PP_Instance instance
,
1061 EnterInstanceNoLock
enter(instance
);
1062 if (enter
.succeeded())
1063 *result
= enter
.functions()->SetFullscreen(instance
, fullscreen
);
1067 void PPB_Instance_Proxy::OnHostMsgGetScreenSize(PP_Instance instance
,
1070 EnterInstanceNoLock
enter(instance
);
1071 if (enter
.succeeded())
1072 *result
= enter
.functions()->GetScreenSize(instance
, size
);
1075 void PPB_Instance_Proxy::OnHostMsgRequestInputEvents(PP_Instance instance
,
1077 uint32_t event_classes
) {
1078 EnterInstanceNoLock
enter(instance
);
1079 if (enter
.succeeded()) {
1081 enter
.functions()->RequestFilteringInputEvents(instance
, event_classes
);
1083 enter
.functions()->RequestInputEvents(instance
, event_classes
);
1087 void PPB_Instance_Proxy::OnHostMsgClearInputEvents(PP_Instance instance
,
1088 uint32_t event_classes
) {
1089 EnterInstanceNoLock
enter(instance
);
1090 if (enter
.succeeded())
1091 enter
.functions()->ClearInputEventRequest(instance
, event_classes
);
1094 void PPB_Instance_Proxy::OnHostMsgStartTrackingLatency(PP_Instance instance
) {
1095 EnterInstanceNoLock
enter(instance
);
1096 if (enter
.succeeded())
1097 enter
.functions()->StartTrackingLatency(instance
);
1100 void PPB_Instance_Proxy::OnHostMsgPostMessage(
1101 PP_Instance instance
,
1102 SerializedVarReceiveInput message
) {
1103 EnterInstanceNoLock
enter(instance
);
1104 if (!message
.is_valid_var()) {
1105 PpapiGlobals::Get()->LogWithSource(
1106 instance
, PP_LOGLEVEL_ERROR
, std::string(), kSerializationError
);
1110 if (enter
.succeeded())
1111 enter
.functions()->PostMessage(instance
,
1112 message
.GetForInstance(dispatcher(),
1116 void PPB_Instance_Proxy::OnHostMsgLockMouse(PP_Instance instance
) {
1117 // Need to be careful to always issue the callback.
1118 pp::CompletionCallback cb
= callback_factory_
.NewCallback(
1119 &PPB_Instance_Proxy::MouseLockCompleteInHost
, instance
);
1121 EnterInstanceNoLock
enter(instance
, cb
.pp_completion_callback());
1122 if (enter
.succeeded())
1123 enter
.SetResult(enter
.functions()->LockMouse(instance
, enter
.callback()));
1126 void PPB_Instance_Proxy::OnHostMsgUnlockMouse(PP_Instance instance
) {
1127 EnterInstanceNoLock
enter(instance
);
1128 if (enter
.succeeded())
1129 enter
.functions()->UnlockMouse(instance
);
1132 void PPB_Instance_Proxy::OnHostMsgGetDocumentURL(
1133 PP_Instance instance
,
1134 PP_URLComponents_Dev
* components
,
1135 SerializedVarReturnValue result
) {
1136 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1138 EnterInstanceNoLock
enter(instance
);
1139 if (enter
.succeeded()) {
1140 PP_Var document_url
= enter
.functions()->GetDocumentURL(instance
,
1142 result
.Return(dispatcher(), document_url
);
1146 void PPB_Instance_Proxy::OnHostMsgResolveRelativeToDocument(
1147 PP_Instance instance
,
1148 SerializedVarReceiveInput relative
,
1149 SerializedVarReturnValue result
) {
1150 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1152 EnterInstanceNoLock
enter(instance
);
1153 if (enter
.succeeded()) {
1154 result
.Return(dispatcher(),
1155 enter
.functions()->ResolveRelativeToDocument(
1156 instance
, relative
.Get(dispatcher()), NULL
));
1160 void PPB_Instance_Proxy::OnHostMsgDocumentCanRequest(
1161 PP_Instance instance
,
1162 SerializedVarReceiveInput url
,
1164 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1166 EnterInstanceNoLock
enter(instance
);
1167 if (enter
.succeeded()) {
1168 *result
= enter
.functions()->DocumentCanRequest(instance
,
1169 url
.Get(dispatcher()));
1173 void PPB_Instance_Proxy::OnHostMsgDocumentCanAccessDocument(PP_Instance active
,
1176 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1178 EnterInstanceNoLock
enter(active
);
1179 if (enter
.succeeded())
1180 *result
= enter
.functions()->DocumentCanAccessDocument(active
, target
);
1183 void PPB_Instance_Proxy::OnHostMsgGetPluginInstanceURL(
1184 PP_Instance instance
,
1185 SerializedVarReturnValue result
) {
1186 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1188 EnterInstanceNoLock
enter(instance
);
1189 if (enter
.succeeded()) {
1190 result
.Return(dispatcher(),
1191 enter
.functions()->GetPluginInstanceURL(instance
, NULL
));
1195 void PPB_Instance_Proxy::OnHostMsgGetPluginReferrerURL(
1196 PP_Instance instance
,
1197 SerializedVarReturnValue result
) {
1198 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV
))
1200 EnterInstanceNoLock
enter(instance
);
1201 if (enter
.succeeded()) {
1202 result
.Return(dispatcher(),
1203 enter
.functions()->GetPluginReferrerURL(instance
, NULL
));
1207 void PPB_Instance_Proxy::OnHostMsgPromiseResolved(PP_Instance instance
,
1208 uint32_t promise_id
) {
1209 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1211 EnterInstanceNoLock
enter(instance
);
1212 if (enter
.succeeded()) {
1213 enter
.functions()->PromiseResolved(instance
, promise_id
);
1217 void PPB_Instance_Proxy::OnHostMsgPromiseResolvedWithSession(
1218 PP_Instance instance
,
1219 uint32_t promise_id
,
1220 SerializedVarReceiveInput session_id
) {
1221 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1223 EnterInstanceNoLock
enter(instance
);
1224 if (enter
.succeeded()) {
1225 enter
.functions()->PromiseResolvedWithSession(instance
, promise_id
,
1226 session_id
.Get(dispatcher()));
1230 void PPB_Instance_Proxy::OnHostMsgPromiseRejected(
1231 PP_Instance instance
,
1232 uint32_t promise_id
,
1233 PP_CdmExceptionCode exception_code
,
1234 uint32_t system_code
,
1235 SerializedVarReceiveInput error_description
) {
1236 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1238 EnterInstanceNoLock
enter(instance
);
1239 if (enter
.succeeded()) {
1240 enter
.functions()->PromiseRejected(instance
,
1244 error_description
.Get(dispatcher()));
1248 void PPB_Instance_Proxy::OnHostMsgSessionMessage(
1249 PP_Instance instance
,
1250 SerializedVarReceiveInput session_id
,
1251 PP_CdmMessageType message_type
,
1252 SerializedVarReceiveInput message
,
1253 SerializedVarReceiveInput legacy_destination_url
) {
1254 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1256 EnterInstanceNoLock
enter(instance
);
1257 if (enter
.succeeded()) {
1258 enter
.functions()->SessionMessage(instance
, session_id
.Get(dispatcher()),
1259 message_type
, message
.Get(dispatcher()),
1260 legacy_destination_url
.Get(dispatcher()));
1264 void PPB_Instance_Proxy::OnHostMsgSessionKeysChange(
1265 PP_Instance instance
,
1266 const std::string
& session_id
,
1267 PP_Bool has_additional_usable_key
,
1268 const std::vector
<PP_KeyInformation
>& key_information
) {
1269 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1272 if (key_information
.size() > media::limits::kMaxKeyIds
) {
1277 EnterInstanceNoLock
enter(instance
);
1278 if (enter
.succeeded()) {
1279 ScopedPPVar
session_id_var(ScopedPPVar::PassRef(),
1280 StringVar::StringToPPVar(session_id
));
1281 enter
.functions()->SessionKeysChange(
1282 instance
, session_id_var
.get(), has_additional_usable_key
,
1283 base::checked_cast
<uint32_t>(key_information
.size()),
1284 vector_as_array(&key_information
));
1288 void PPB_Instance_Proxy::OnHostMsgSessionExpirationChange(
1289 PP_Instance instance
,
1290 const std::string
& session_id
,
1291 PP_Time new_expiry_time
) {
1292 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1294 EnterInstanceNoLock
enter(instance
);
1295 if (enter
.succeeded()) {
1296 ScopedPPVar
session_id_var(ScopedPPVar::PassRef(),
1297 StringVar::StringToPPVar(session_id
));
1298 enter
.functions()->SessionExpirationChange(instance
, session_id_var
.get(),
1303 void PPB_Instance_Proxy::OnHostMsgSessionClosed(
1304 PP_Instance instance
,
1305 SerializedVarReceiveInput session_id
) {
1306 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1308 EnterInstanceNoLock
enter(instance
);
1309 if (enter
.succeeded()) {
1310 enter
.functions()->SessionClosed(instance
, session_id
.Get(dispatcher()));
1314 void PPB_Instance_Proxy::OnHostMsgLegacySessionError(
1315 PP_Instance instance
,
1316 SerializedVarReceiveInput session_id
,
1317 PP_CdmExceptionCode exception_code
,
1318 uint32_t system_code
,
1319 SerializedVarReceiveInput error_description
) {
1320 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1322 EnterInstanceNoLock
enter(instance
);
1323 if (enter
.succeeded()) {
1324 enter
.functions()->LegacySessionError(
1325 instance
, session_id
.Get(dispatcher()), exception_code
, system_code
,
1326 error_description
.Get(dispatcher()));
1330 void PPB_Instance_Proxy::OnHostMsgDeliverBlock(
1331 PP_Instance instance
,
1332 PP_Resource decrypted_block
,
1333 const std::string
& serialized_block_info
) {
1334 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1336 PP_DecryptedBlockInfo block_info
;
1337 if (!DeserializeBlockInfo(serialized_block_info
, &block_info
))
1340 EnterInstanceNoLock
enter(instance
);
1341 if (enter
.succeeded())
1342 enter
.functions()->DeliverBlock(instance
, decrypted_block
, &block_info
);
1345 void PPB_Instance_Proxy::OnHostMsgDecoderInitializeDone(
1346 PP_Instance instance
,
1347 PP_DecryptorStreamType decoder_type
,
1348 uint32_t request_id
,
1350 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1352 EnterInstanceNoLock
enter(instance
);
1353 if (enter
.succeeded()) {
1354 enter
.functions()->DecoderInitializeDone(instance
,
1361 void PPB_Instance_Proxy::OnHostMsgDecoderDeinitializeDone(
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()->DecoderDeinitializeDone(instance
,
1374 void PPB_Instance_Proxy::OnHostMsgDecoderResetDone(
1375 PP_Instance instance
,
1376 PP_DecryptorStreamType decoder_type
,
1377 uint32_t request_id
) {
1378 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1380 EnterInstanceNoLock
enter(instance
);
1381 if (enter
.succeeded())
1382 enter
.functions()->DecoderResetDone(instance
, decoder_type
, request_id
);
1385 void PPB_Instance_Proxy::OnHostMsgDeliverFrame(
1386 PP_Instance instance
,
1387 PP_Resource decrypted_frame
,
1388 const std::string
& serialized_frame_info
) {
1389 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1391 PP_DecryptedFrameInfo frame_info
;
1392 if (!DeserializeBlockInfo(serialized_frame_info
, &frame_info
))
1395 EnterInstanceNoLock
enter(instance
);
1396 if (enter
.succeeded())
1397 enter
.functions()->DeliverFrame(instance
, decrypted_frame
, &frame_info
);
1400 void PPB_Instance_Proxy::OnHostMsgDeliverSamples(
1401 PP_Instance instance
,
1402 PP_Resource audio_frames
,
1403 const std::string
& serialized_sample_info
) {
1404 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE
))
1406 PP_DecryptedSampleInfo sample_info
;
1407 if (!DeserializeBlockInfo(serialized_sample_info
, &sample_info
))
1410 EnterInstanceNoLock
enter(instance
);
1411 if (enter
.succeeded())
1412 enter
.functions()->DeliverSamples(instance
, audio_frames
, &sample_info
);
1415 void PPB_Instance_Proxy::OnHostMsgSetCursor(
1416 PP_Instance instance
,
1418 const ppapi::HostResource
& custom_image
,
1419 const PP_Point
& hot_spot
) {
1420 // This API serves PPB_CursorControl_Dev and PPB_MouseCursor, so is public.
1421 EnterInstanceNoLock
enter(instance
);
1422 if (enter
.succeeded()) {
1423 enter
.functions()->SetCursor(
1424 instance
, static_cast<PP_MouseCursor_Type
>(type
),
1425 custom_image
.host_resource(), &hot_spot
);
1429 void PPB_Instance_Proxy::OnHostMsgSetTextInputType(PP_Instance instance
,
1430 PP_TextInput_Type type
) {
1431 EnterInstanceNoLock
enter(instance
);
1432 if (enter
.succeeded())
1433 enter
.functions()->SetTextInputType(instance
, type
);
1436 void PPB_Instance_Proxy::OnHostMsgUpdateCaretPosition(
1437 PP_Instance instance
,
1438 const PP_Rect
& caret
,
1439 const PP_Rect
& bounding_box
) {
1440 EnterInstanceNoLock
enter(instance
);
1441 if (enter
.succeeded())
1442 enter
.functions()->UpdateCaretPosition(instance
, caret
, bounding_box
);
1445 void PPB_Instance_Proxy::OnHostMsgCancelCompositionText(PP_Instance instance
) {
1446 EnterInstanceNoLock
enter(instance
);
1447 if (enter
.succeeded())
1448 enter
.functions()->CancelCompositionText(instance
);
1451 void PPB_Instance_Proxy::OnHostMsgUpdateSurroundingText(
1452 PP_Instance instance
,
1453 const std::string
& text
,
1456 EnterInstanceNoLock
enter(instance
);
1457 if (enter
.succeeded()) {
1458 enter
.functions()->UpdateSurroundingText(instance
, text
.c_str(), caret
,
1462 #endif // !defined(OS_NACL)
1464 void PPB_Instance_Proxy::OnPluginMsgMouseLockComplete(PP_Instance instance
,
1466 if (!dispatcher()->IsPlugin())
1469 // Save the mouse callback on the instance data.
1470 InstanceData
* data
= static_cast<PluginDispatcher
*>(dispatcher())->
1471 GetInstanceData(instance
);
1473 return; // Instance was probably deleted.
1474 if (!TrackedCallback::IsPending(data
->mouse_lock_callback
)) {
1478 data
->mouse_lock_callback
->Run(result
);
1481 #if !defined(OS_NACL)
1482 void PPB_Instance_Proxy::MouseLockCompleteInHost(int32_t result
,
1483 PP_Instance instance
) {
1484 dispatcher()->Send(new PpapiMsg_PPBInstance_MouseLockComplete(
1485 API_ID_PPB_INSTANCE
, instance
, result
));
1487 #endif // !defined(OS_NACL)
1489 void PPB_Instance_Proxy::CancelAnyPendingRequestSurroundingText(
1490 PP_Instance instance
) {
1491 InstanceData
* data
= static_cast<PluginDispatcher
*>(dispatcher())->
1492 GetInstanceData(instance
);
1494 return; // Instance was probably deleted.
1495 data
->should_do_request_surrounding_text
= false;
1498 } // namespace proxy
1499 } // namespace ppapi