Port Android relocation packer to chromium build
[chromium-blink-merge.git] / ppapi / proxy / ppb_instance_proxy.cc
blob08daacb2864ac6e6ec397fbe7520cee7fff4c46c
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.
52 #ifdef PostMessage
53 #undef PostMessage
54 #endif
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;
63 namespace ppapi {
64 namespace proxy {
66 namespace {
68 #if !defined(OS_NACL)
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.";
72 #endif
74 void RequestSurroundingText(PP_Instance instance) {
75 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
76 if (!dispatcher)
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)
83 return;
85 // Just fake out a RequestSurroundingText message to the proxy for the PPP
86 // interface.
87 InterfaceProxy* proxy = dispatcher->GetInterfaceProxy(API_ID_PPP_TEXT_INPUT);
88 if (!proxy)
89 return;
90 proxy->OnMessageReceived(PpapiMsg_PPPTextInput_RequestSurroundingText(
91 API_ID_PPP_TEXT_INPUT, instance,
92 PPB_Instance_Shared::kExtraCharsForTextInput));
95 } // namespace
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());
112 #endif
114 bool handled = true;
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)
126 IPC_MESSAGE_HANDLER(
127 PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate,
128 OnHostMsgGetAudioHardwareOutputSampleRate)
129 IPC_MESSAGE_HANDLER(
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,
157 OnHostMsgLockMouse)
158 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UnlockMouse,
159 OnHostMsgUnlockMouse)
160 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetCursor,
161 OnHostMsgSetCursor)
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_SessionError,
197 OnHostMsgSessionError)
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()
218 return handled;
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
224 // all devices.
225 PP_Resource pp_resource = 0;
226 if (device) {
227 Resource* resource =
228 PpapiGlobals::Get()->GetResourceTracker()->GetResource(device);
229 if (!resource || resource->pp_instance() != instance)
230 return PP_FALSE;
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
233 // unify this.
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();
239 } else {
240 // A bad resource.
241 return PP_FALSE;
244 dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
245 API_ID_PPB_INSTANCE, instance, pp_resource));
246 return PP_TRUE;
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));
253 return result;
256 const ViewData* PPB_Instance_Proxy::GetViewData(PP_Instance instance) {
257 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
258 GetInstanceData(instance);
259 if (!data)
260 return NULL;
261 return &data->view;
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.
267 NOTREACHED();
268 return PP_FALSE;
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,
286 PP_Var script,
287 PP_Var* exception) {
288 ReceiveSerializedException se(dispatcher(), exception);
289 if (se.IsThrown())
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;
302 dispatcher()->Send(
303 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate(
304 API_ID_PPB_INSTANCE, instance, &result));
305 return result;
308 uint32_t PPB_Instance_Proxy::GetAudioHardwareOutputBufferSize(
309 PP_Instance instance) {
310 uint32_t result = 0;
311 dispatcher()->Send(
312 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputBufferSize(
313 API_ID_PPB_INSTANCE, instance, &result));
314 return result;
317 PP_Var PPB_Instance_Proxy::GetDefaultCharSet(PP_Instance instance) {
318 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
319 if (!dispatcher)
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,
334 int32_t total,
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,
341 int32_t index) {
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,
348 uint32_t count) {
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);
357 if (!data)
358 return PP_FALSE;
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));
367 return result;
370 PP_Bool PPB_Instance_Proxy::GetScreenSize(PP_Instance instance,
371 PP_Size* size) {
372 PP_Bool result = PP_FALSE;
373 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetScreenSize(
374 API_ID_PPB_INSTANCE, instance, &result, size));
375 return result;
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());
391 switch (id) {
392 case BROKER_SINGLETON_ID:
393 new_singleton = new BrokerResource(connection, instance);
394 break;
395 case GAMEPAD_SINGLETON_ID:
396 new_singleton = new GamepadResource(connection, instance);
397 break;
398 case ISOLATED_FILESYSTEM_SINGLETON_ID:
399 new_singleton =
400 new IsolatedFileSystemPrivateResource(connection, instance);
401 break;
402 case NETWORK_PROXY_SINGLETON_ID:
403 new_singleton = new NetworkProxyResource(connection, instance);
404 break;
405 case TRUETYPE_FONT_SINGLETON_ID:
406 new_singleton = new TrueTypeFontSingletonResource(connection, instance);
407 break;
408 case UMA_SINGLETON_ID:
409 new_singleton = new UMAPrivateResource(connection, instance);
410 break;
411 // Flash/trusted resources aren't needed for NaCl.
412 #if !defined(OS_NACL) && !defined(NACL_WIN64)
413 case BROWSER_FONT_SINGLETON_ID:
414 new_singleton = new BrowserFontSingletonResource(connection, instance);
415 break;
416 case FLASH_CLIPBOARD_SINGLETON_ID:
417 new_singleton = new FlashClipboardResource(connection, instance);
418 break;
419 case FLASH_FILE_SINGLETON_ID:
420 new_singleton = new FlashFileResource(connection, instance);
421 break;
422 case FLASH_FULLSCREEN_SINGLETON_ID:
423 new_singleton = new FlashFullscreenResource(connection, instance);
424 break;
425 case FLASH_SINGLETON_ID:
426 new_singleton = new FlashResource(connection, instance,
427 static_cast<PluginDispatcher*>(dispatcher()));
428 break;
429 case PDF_SINGLETON_ID:
430 new_singleton = new PDFResource(connection, instance);
431 break;
432 #else
433 case BROWSER_FONT_SINGLETON_ID:
434 case FLASH_CLIPBOARD_SINGLETON_ID:
435 case FLASH_FILE_SINGLETON_ID:
436 case FLASH_FULLSCREEN_SINGLETON_ID:
437 case FLASH_SINGLETON_ID:
438 case PDF_SINGLETON_ID:
439 NOTREACHED();
440 break;
441 #endif // !defined(OS_NACL) && !defined(NACL_WIN64)
444 if (!new_singleton.get()) {
445 // Getting here implies that a constructor is missing in the above switch.
446 NOTREACHED();
447 return NULL;
450 data->singleton_resources[id] = new_singleton;
451 return new_singleton.get();
454 int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance,
455 uint32_t event_classes) {
456 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
457 API_ID_PPB_INSTANCE, instance, false, event_classes));
459 // We always register for the classes we can handle, this function validates
460 // the flags so we can notify it if anything was invalid, without requiring
461 // a sync reply.
462 return ValidateRequestInputEvents(false, event_classes);
465 int32_t PPB_Instance_Proxy::RequestFilteringInputEvents(
466 PP_Instance instance,
467 uint32_t event_classes) {
468 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
469 API_ID_PPB_INSTANCE, instance, true, event_classes));
471 // We always register for the classes we can handle, this function validates
472 // the flags so we can notify it if anything was invalid, without requiring
473 // a sync reply.
474 return ValidateRequestInputEvents(true, event_classes);
477 void PPB_Instance_Proxy::ClearInputEventRequest(PP_Instance instance,
478 uint32_t event_classes) {
479 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ClearInputEvents(
480 API_ID_PPB_INSTANCE, instance, event_classes));
483 void PPB_Instance_Proxy::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,
489 double factor) {
490 // Not proxied yet.
491 NOTIMPLEMENTED();
494 void PPB_Instance_Proxy::ZoomLimitsChanged(PP_Instance instance,
495 double minimum_factor,
496 double maximium_factor) {
497 // Not proxied yet.
498 NOTIMPLEMENTED();
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));
507 if (components)
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,
515 PP_Var relative,
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),
521 &result));
522 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
523 result.Return(dispatcher()),
524 components);
527 PP_Bool PPB_Instance_Proxy::DocumentCanRequest(PP_Instance instance,
528 PP_Var url) {
529 PP_Bool result = PP_FALSE;
530 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanRequest(
531 API_ID_PPB_INSTANCE, instance,
532 SerializedVarSendInput(dispatcher(), url),
533 &result));
534 return result;
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));
542 return 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()),
553 components);
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()),
564 components);
567 void PPB_Instance_Proxy::PromiseResolved(PP_Instance instance,
568 uint32 promise_id) {
569 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseResolved(
570 API_ID_PPB_INSTANCE, instance, promise_id));
573 void PPB_Instance_Proxy::PromiseResolvedWithSession(PP_Instance instance,
574 uint32 promise_id,
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,
582 uint32 promise_id,
583 PP_CdmExceptionCode exception_code,
584 uint32 system_code,
585 PP_Var error_description_var) {
586 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseRejected(
587 API_ID_PPB_INSTANCE,
588 instance,
589 promise_id,
590 exception_code,
591 system_code,
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,
598 PP_Var message_var,
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,
611 uint32_t key_count,
612 const struct PP_KeyInformation key_information[]) {
613 StringVar* session_id = StringVar::FromPPVar(session_id_var);
614 if (!session_id ||
615 session_id->value().length() > media::limits::kMaxSessionIdLength) {
616 NOTREACHED();
617 return;
620 if (key_count > media::limits::kMaxKeyIds) {
621 NOTREACHED();
622 return;
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);
636 if (!session_id ||
637 session_id->value().length() > media::limits::kMaxSessionIdLength) {
638 NOTREACHED();
639 return;
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::SessionError(PP_Instance instance,
654 PP_Var session_id_var,
655 PP_CdmExceptionCode exception_code,
656 uint32 system_code,
657 PP_Var error_description_var) {
658 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionError(
659 API_ID_PPB_INSTANCE, instance,
660 SerializedVarSendInput(dispatcher(), session_id_var), exception_code,
661 system_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) {
671 Resource* object =
672 PpapiGlobals::Get()->GetResourceTracker()->GetResource(decrypted_block);
673 if (!object || object->pp_instance() != instance) {
674 NOTREACHED();
675 return;
677 decrypted_block_host_resource = object->host_resource().host_resource();
680 std::string serialized_block_info;
681 if (!SerializeBlockInfo(*block_info, &serialized_block_info)) {
682 NOTREACHED();
683 return;
686 dispatcher()->Send(
687 new PpapiHostMsg_PPBInstance_DeliverBlock(API_ID_PPB_INSTANCE,
688 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,
696 uint32_t request_id,
697 PP_Bool success) {
698 dispatcher()->Send(
699 new PpapiHostMsg_PPBInstance_DecoderInitializeDone(
700 API_ID_PPB_INSTANCE,
701 instance,
702 decoder_type,
703 request_id,
704 success));
707 void PPB_Instance_Proxy::DecoderDeinitializeDone(
708 PP_Instance instance,
709 PP_DecryptorStreamType decoder_type,
710 uint32_t request_id) {
711 dispatcher()->Send(
712 new PpapiHostMsg_PPBInstance_DecoderDeinitializeDone(
713 API_ID_PPB_INSTANCE,
714 instance,
715 decoder_type,
716 request_id));
719 void PPB_Instance_Proxy::DecoderResetDone(PP_Instance instance,
720 PP_DecryptorStreamType decoder_type,
721 uint32_t request_id) {
722 dispatcher()->Send(
723 new PpapiHostMsg_PPBInstance_DecoderResetDone(
724 API_ID_PPB_INSTANCE,
725 instance,
726 decoder_type,
727 request_id));
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) {
739 NOTREACHED();
740 return;
743 host_resource = object->host_resource().host_resource();
746 std::string serialized_frame_info;
747 if (!SerializeBlockInfo(*frame_info, &serialized_frame_info)) {
748 NOTREACHED();
749 return;
752 dispatcher()->Send(
753 new PpapiHostMsg_PPBInstance_DeliverFrame(API_ID_PPB_INSTANCE,
754 instance,
755 host_resource,
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) {
769 NOTREACHED();
770 return;
773 host_resource = object->host_resource().host_resource();
776 std::string serialized_sample_info;
777 if (!SerializeBlockInfo(*sample_info, &serialized_sample_info)) {
778 NOTREACHED();
779 return;
782 dispatcher()->Send(
783 new PpapiHostMsg_PPBInstance_DeliverSamples(API_ID_PPB_INSTANCE,
784 instance,
785 host_resource,
786 serialized_sample_info));
788 #endif // !defined(OS_NACL)
790 void PPB_Instance_Proxy::PostMessage(PP_Instance instance,
791 PP_Var message) {
792 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage(
793 API_ID_PPB_INSTANCE,
794 instance, SerializedVarSendInputShmem(dispatcher(), message,
795 instance)));
798 int32_t PPB_Instance_Proxy::RegisterMessageHandler(
799 PP_Instance instance,
800 void* user_data,
801 const PPP_MessageHandler_0_2* handler,
802 PP_Resource message_loop) {
803 InstanceData* data =
804 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
805 if (!data)
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);
811 if (message_handler)
812 data->message_handler = message_handler.Pass();
813 return result;
816 // TODO(dmichael): Remove this. crbug.com/414398
817 int32_t PPB_Instance_Proxy::RegisterMessageHandler_1_1_Deprecated(
818 PP_Instance instance,
819 void* user_data,
820 const PPP_MessageHandler_0_1_Deprecated* handler,
821 PP_Resource message_loop) {
822 InstanceData* data =
823 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
824 if (!data)
825 return PP_ERROR_BADARGUMENT;
827 int32_t result = PP_ERROR_FAILED;
828 scoped_ptr<MessageHandler> message_handler = MessageHandler::CreateDeprecated(
829 instance, handler, user_data, message_loop, &result);
830 if (message_handler)
831 data->message_handler = message_handler.Pass();
832 return result;
835 void PPB_Instance_Proxy::UnregisterMessageHandler(PP_Instance instance) {
836 InstanceData* data =
837 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
838 if (!data)
839 return;
840 data->message_handler.reset();
843 PP_Bool PPB_Instance_Proxy::SetCursor(PP_Instance instance,
844 PP_MouseCursor_Type type,
845 PP_Resource image,
846 const PP_Point* hot_spot) {
847 // Some of these parameters are important for security. This check is in the
848 // plugin process just for the convenience of the caller (since we don't
849 // bother returning errors from the other process with a sync message). The
850 // parameters will be validated again in the renderer.
851 if (!ValidateSetCursorParams(type, image, hot_spot))
852 return PP_FALSE;
854 HostResource image_host_resource;
855 if (image) {
856 Resource* cursor_image =
857 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image);
858 if (!cursor_image || cursor_image->pp_instance() != instance)
859 return PP_FALSE;
860 image_host_resource = cursor_image->host_resource();
863 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetCursor(
864 API_ID_PPB_INSTANCE, instance, static_cast<int32_t>(type),
865 image_host_resource, hot_spot ? *hot_spot : PP_MakePoint(0, 0)));
866 return PP_TRUE;
869 int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance,
870 scoped_refptr<TrackedCallback> callback) {
871 // Save the mouse callback on the instance data.
872 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
873 GetInstanceData(instance);
874 if (!data)
875 return PP_ERROR_BADARGUMENT;
876 if (TrackedCallback::IsPending(data->mouse_lock_callback))
877 return PP_ERROR_INPROGRESS; // Already have a pending callback.
878 data->mouse_lock_callback = callback;
880 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LockMouse(
881 API_ID_PPB_INSTANCE, instance));
882 return PP_OK_COMPLETIONPENDING;
885 void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance) {
886 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UnlockMouse(
887 API_ID_PPB_INSTANCE, instance));
890 void PPB_Instance_Proxy::SetTextInputType(PP_Instance instance,
891 PP_TextInput_Type type) {
892 CancelAnyPendingRequestSurroundingText(instance);
893 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTextInputType(
894 API_ID_PPB_INSTANCE, instance, type));
897 void PPB_Instance_Proxy::UpdateCaretPosition(PP_Instance instance,
898 const PP_Rect& caret,
899 const PP_Rect& bounding_box) {
900 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateCaretPosition(
901 API_ID_PPB_INSTANCE, instance, caret, bounding_box));
904 void PPB_Instance_Proxy::CancelCompositionText(PP_Instance instance) {
905 CancelAnyPendingRequestSurroundingText(instance);
906 dispatcher()->Send(new PpapiHostMsg_PPBInstance_CancelCompositionText(
907 API_ID_PPB_INSTANCE, instance));
910 void PPB_Instance_Proxy::SelectionChanged(PP_Instance instance) {
911 // The "right" way to do this is to send the message to the host. However,
912 // all it will do is call RequestSurroundingText with a hardcoded number of
913 // characters in response, which is an entire IPC round-trip.
915 // We can avoid this round-trip by just implementing the
916 // RequestSurroundingText logic in the plugin process. If the logic in the
917 // host becomes more complex (like a more adaptive number of characters),
918 // we'll need to reevanuate whether we want to do the round trip instead.
920 // Be careful to post a task to avoid reentering the plugin.
922 InstanceData* data =
923 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
924 if (!data)
925 return;
926 data->should_do_request_surrounding_text = true;
928 if (!data->is_request_surrounding_text_pending) {
929 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
930 FROM_HERE,
931 RunWhileLocked(base::Bind(&RequestSurroundingText, instance)));
932 data->is_request_surrounding_text_pending = true;
936 void PPB_Instance_Proxy::UpdateSurroundingText(PP_Instance instance,
937 const char* text,
938 uint32_t caret,
939 uint32_t anchor) {
940 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateSurroundingText(
941 API_ID_PPB_INSTANCE, instance, text, caret, anchor));
944 #if !defined(OS_NACL)
945 void PPB_Instance_Proxy::OnHostMsgGetWindowObject(
946 PP_Instance instance,
947 SerializedVarReturnValue result) {
948 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
949 return;
950 EnterInstanceNoLock enter(instance);
951 if (enter.succeeded())
952 result.Return(dispatcher(), enter.functions()->GetWindowObject(instance));
955 void PPB_Instance_Proxy::OnHostMsgGetOwnerElementObject(
956 PP_Instance instance,
957 SerializedVarReturnValue result) {
958 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
959 return;
960 EnterInstanceNoLock enter(instance);
961 if (enter.succeeded()) {
962 result.Return(dispatcher(),
963 enter.functions()->GetOwnerElementObject(instance));
967 void PPB_Instance_Proxy::OnHostMsgBindGraphics(PP_Instance instance,
968 PP_Resource device) {
969 // Note that we ignroe the return value here. Otherwise, this would need to
970 // be a slow sync call, and the plugin side of the proxy will have already
971 // validated the resources, so we shouldn't see errors here that weren't
972 // already caught.
973 EnterInstanceNoLock enter(instance);
974 if (enter.succeeded())
975 enter.functions()->BindGraphics(instance, device);
978 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputSampleRate(
979 PP_Instance instance, uint32_t* result) {
980 EnterInstanceNoLock enter(instance);
981 if (enter.succeeded())
982 *result = enter.functions()->GetAudioHardwareOutputSampleRate(instance);
985 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputBufferSize(
986 PP_Instance instance, uint32_t* result) {
987 EnterInstanceNoLock enter(instance);
988 if (enter.succeeded())
989 *result = enter.functions()->GetAudioHardwareOutputBufferSize(instance);
992 void PPB_Instance_Proxy::OnHostMsgIsFullFrame(PP_Instance instance,
993 PP_Bool* result) {
994 EnterInstanceNoLock enter(instance);
995 if (enter.succeeded())
996 *result = enter.functions()->IsFullFrame(instance);
999 void PPB_Instance_Proxy::OnHostMsgExecuteScript(
1000 PP_Instance instance,
1001 SerializedVarReceiveInput script,
1002 SerializedVarOutParam out_exception,
1003 SerializedVarReturnValue result) {
1004 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1005 return;
1006 EnterInstanceNoLock enter(instance);
1007 if (enter.failed())
1008 return;
1010 if (dispatcher()->IsPlugin())
1011 NOTREACHED();
1012 else
1013 static_cast<HostDispatcher*>(dispatcher())->set_allow_plugin_reentrancy();
1015 result.Return(dispatcher(), enter.functions()->ExecuteScript(
1016 instance,
1017 script.Get(dispatcher()),
1018 out_exception.OutParam(dispatcher())));
1021 void PPB_Instance_Proxy::OnHostMsgGetDefaultCharSet(
1022 PP_Instance instance,
1023 SerializedVarReturnValue result) {
1024 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1025 return;
1026 EnterInstanceNoLock enter(instance);
1027 if (enter.succeeded())
1028 result.Return(dispatcher(), enter.functions()->GetDefaultCharSet(instance));
1031 void PPB_Instance_Proxy::OnHostMsgSetPluginToHandleFindRequests(
1032 PP_Instance instance) {
1033 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1034 return;
1035 EnterInstanceNoLock enter(instance);
1036 if (enter.succeeded())
1037 enter.functions()->SetPluginToHandleFindRequests(instance);
1040 void PPB_Instance_Proxy::OnHostMsgNumberOfFindResultsChanged(
1041 PP_Instance instance,
1042 int32_t total,
1043 PP_Bool final_result) {
1044 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1045 return;
1046 EnterInstanceNoLock enter(instance);
1047 if (enter.succeeded()) {
1048 enter.functions()->NumberOfFindResultsChanged(
1049 instance, total, final_result);
1053 void PPB_Instance_Proxy::OnHostMsgSelectFindResultChanged(
1054 PP_Instance instance,
1055 int32_t index) {
1056 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1057 return;
1058 EnterInstanceNoLock enter(instance);
1059 if (enter.succeeded())
1060 enter.functions()->SelectedFindResultChanged(instance, index);
1063 void PPB_Instance_Proxy::OnHostMsgSetTickmarks(
1064 PP_Instance instance,
1065 const std::vector<PP_Rect>& tickmarks) {
1066 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1067 return;
1068 const PP_Rect* array = tickmarks.empty() ? NULL : &tickmarks[0];
1069 EnterInstanceNoLock enter(instance);
1070 if (enter.succeeded()) {
1071 enter.functions()->SetTickmarks(instance,
1072 array,
1073 static_cast<uint32_t>(tickmarks.size()));
1077 void PPB_Instance_Proxy::OnHostMsgSetFullscreen(PP_Instance instance,
1078 PP_Bool fullscreen,
1079 PP_Bool* result) {
1080 EnterInstanceNoLock enter(instance);
1081 if (enter.succeeded())
1082 *result = enter.functions()->SetFullscreen(instance, fullscreen);
1086 void PPB_Instance_Proxy::OnHostMsgGetScreenSize(PP_Instance instance,
1087 PP_Bool* result,
1088 PP_Size* size) {
1089 EnterInstanceNoLock enter(instance);
1090 if (enter.succeeded())
1091 *result = enter.functions()->GetScreenSize(instance, size);
1094 void PPB_Instance_Proxy::OnHostMsgRequestInputEvents(PP_Instance instance,
1095 bool is_filtering,
1096 uint32_t event_classes) {
1097 EnterInstanceNoLock enter(instance);
1098 if (enter.succeeded()) {
1099 if (is_filtering)
1100 enter.functions()->RequestFilteringInputEvents(instance, event_classes);
1101 else
1102 enter.functions()->RequestInputEvents(instance, event_classes);
1106 void PPB_Instance_Proxy::OnHostMsgClearInputEvents(PP_Instance instance,
1107 uint32_t event_classes) {
1108 EnterInstanceNoLock enter(instance);
1109 if (enter.succeeded())
1110 enter.functions()->ClearInputEventRequest(instance, event_classes);
1113 void PPB_Instance_Proxy::OnHostMsgStartTrackingLatency(PP_Instance instance) {
1114 EnterInstanceNoLock enter(instance);
1115 if (enter.succeeded())
1116 enter.functions()->StartTrackingLatency(instance);
1119 void PPB_Instance_Proxy::OnHostMsgPostMessage(
1120 PP_Instance instance,
1121 SerializedVarReceiveInput message) {
1122 EnterInstanceNoLock enter(instance);
1123 if (!message.is_valid_var()) {
1124 PpapiGlobals::Get()->LogWithSource(
1125 instance, PP_LOGLEVEL_ERROR, std::string(), kSerializationError);
1126 return;
1129 if (enter.succeeded())
1130 enter.functions()->PostMessage(instance,
1131 message.GetForInstance(dispatcher(),
1132 instance));
1135 void PPB_Instance_Proxy::OnHostMsgLockMouse(PP_Instance instance) {
1136 // Need to be careful to always issue the callback.
1137 pp::CompletionCallback cb = callback_factory_.NewCallback(
1138 &PPB_Instance_Proxy::MouseLockCompleteInHost, instance);
1140 EnterInstanceNoLock enter(instance, cb.pp_completion_callback());
1141 if (enter.succeeded())
1142 enter.SetResult(enter.functions()->LockMouse(instance, enter.callback()));
1145 void PPB_Instance_Proxy::OnHostMsgUnlockMouse(PP_Instance instance) {
1146 EnterInstanceNoLock enter(instance);
1147 if (enter.succeeded())
1148 enter.functions()->UnlockMouse(instance);
1151 void PPB_Instance_Proxy::OnHostMsgGetDocumentURL(
1152 PP_Instance instance,
1153 PP_URLComponents_Dev* components,
1154 SerializedVarReturnValue result) {
1155 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1156 return;
1157 EnterInstanceNoLock enter(instance);
1158 if (enter.succeeded()) {
1159 PP_Var document_url = enter.functions()->GetDocumentURL(instance,
1160 components);
1161 result.Return(dispatcher(), document_url);
1165 void PPB_Instance_Proxy::OnHostMsgResolveRelativeToDocument(
1166 PP_Instance instance,
1167 SerializedVarReceiveInput relative,
1168 SerializedVarReturnValue result) {
1169 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1170 return;
1171 EnterInstanceNoLock enter(instance);
1172 if (enter.succeeded()) {
1173 result.Return(dispatcher(),
1174 enter.functions()->ResolveRelativeToDocument(
1175 instance, relative.Get(dispatcher()), NULL));
1179 void PPB_Instance_Proxy::OnHostMsgDocumentCanRequest(
1180 PP_Instance instance,
1181 SerializedVarReceiveInput url,
1182 PP_Bool* result) {
1183 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1184 return;
1185 EnterInstanceNoLock enter(instance);
1186 if (enter.succeeded()) {
1187 *result = enter.functions()->DocumentCanRequest(instance,
1188 url.Get(dispatcher()));
1192 void PPB_Instance_Proxy::OnHostMsgDocumentCanAccessDocument(PP_Instance active,
1193 PP_Instance target,
1194 PP_Bool* result) {
1195 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1196 return;
1197 EnterInstanceNoLock enter(active);
1198 if (enter.succeeded())
1199 *result = enter.functions()->DocumentCanAccessDocument(active, target);
1202 void PPB_Instance_Proxy::OnHostMsgGetPluginInstanceURL(
1203 PP_Instance instance,
1204 SerializedVarReturnValue result) {
1205 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1206 return;
1207 EnterInstanceNoLock enter(instance);
1208 if (enter.succeeded()) {
1209 result.Return(dispatcher(),
1210 enter.functions()->GetPluginInstanceURL(instance, NULL));
1214 void PPB_Instance_Proxy::OnHostMsgGetPluginReferrerURL(
1215 PP_Instance instance,
1216 SerializedVarReturnValue result) {
1217 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1218 return;
1219 EnterInstanceNoLock enter(instance);
1220 if (enter.succeeded()) {
1221 result.Return(dispatcher(),
1222 enter.functions()->GetPluginReferrerURL(instance, NULL));
1226 void PPB_Instance_Proxy::OnHostMsgPromiseResolved(PP_Instance instance,
1227 uint32_t promise_id) {
1228 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1229 return;
1230 EnterInstanceNoLock enter(instance);
1231 if (enter.succeeded()) {
1232 enter.functions()->PromiseResolved(instance, promise_id);
1236 void PPB_Instance_Proxy::OnHostMsgPromiseResolvedWithSession(
1237 PP_Instance instance,
1238 uint32_t promise_id,
1239 SerializedVarReceiveInput session_id) {
1240 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1241 return;
1242 EnterInstanceNoLock enter(instance);
1243 if (enter.succeeded()) {
1244 enter.functions()->PromiseResolvedWithSession(instance, promise_id,
1245 session_id.Get(dispatcher()));
1249 void PPB_Instance_Proxy::OnHostMsgPromiseRejected(
1250 PP_Instance instance,
1251 uint32_t promise_id,
1252 PP_CdmExceptionCode exception_code,
1253 uint32_t system_code,
1254 SerializedVarReceiveInput error_description) {
1255 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1256 return;
1257 EnterInstanceNoLock enter(instance);
1258 if (enter.succeeded()) {
1259 enter.functions()->PromiseRejected(instance,
1260 promise_id,
1261 exception_code,
1262 system_code,
1263 error_description.Get(dispatcher()));
1267 void PPB_Instance_Proxy::OnHostMsgSessionMessage(
1268 PP_Instance instance,
1269 SerializedVarReceiveInput session_id,
1270 PP_CdmMessageType message_type,
1271 SerializedVarReceiveInput message,
1272 SerializedVarReceiveInput legacy_destination_url) {
1273 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1274 return;
1275 EnterInstanceNoLock enter(instance);
1276 if (enter.succeeded()) {
1277 enter.functions()->SessionMessage(instance, session_id.Get(dispatcher()),
1278 message_type, message.Get(dispatcher()),
1279 legacy_destination_url.Get(dispatcher()));
1283 void PPB_Instance_Proxy::OnHostMsgSessionKeysChange(
1284 PP_Instance instance,
1285 const std::string& session_id,
1286 PP_Bool has_additional_usable_key,
1287 const std::vector<PP_KeyInformation>& key_information) {
1288 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1289 return;
1291 if (key_information.size() > media::limits::kMaxKeyIds) {
1292 NOTREACHED();
1293 return;
1296 EnterInstanceNoLock enter(instance);
1297 if (enter.succeeded()) {
1298 ScopedPPVar session_id_var(ScopedPPVar::PassRef(),
1299 StringVar::StringToPPVar(session_id));
1300 enter.functions()->SessionKeysChange(
1301 instance, session_id_var.get(), has_additional_usable_key,
1302 base::checked_cast<uint32_t>(key_information.size()),
1303 vector_as_array(&key_information));
1307 void PPB_Instance_Proxy::OnHostMsgSessionExpirationChange(
1308 PP_Instance instance,
1309 const std::string& session_id,
1310 PP_Time new_expiry_time) {
1311 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1312 return;
1313 EnterInstanceNoLock enter(instance);
1314 if (enter.succeeded()) {
1315 ScopedPPVar session_id_var(ScopedPPVar::PassRef(),
1316 StringVar::StringToPPVar(session_id));
1317 enter.functions()->SessionExpirationChange(instance, session_id_var.get(),
1318 new_expiry_time);
1322 void PPB_Instance_Proxy::OnHostMsgSessionClosed(
1323 PP_Instance instance,
1324 SerializedVarReceiveInput session_id) {
1325 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1326 return;
1327 EnterInstanceNoLock enter(instance);
1328 if (enter.succeeded()) {
1329 enter.functions()->SessionClosed(instance, session_id.Get(dispatcher()));
1333 void PPB_Instance_Proxy::OnHostMsgSessionError(
1334 PP_Instance instance,
1335 SerializedVarReceiveInput session_id,
1336 PP_CdmExceptionCode exception_code,
1337 uint32_t system_code,
1338 SerializedVarReceiveInput error_description) {
1339 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1340 return;
1341 EnterInstanceNoLock enter(instance);
1342 if (enter.succeeded()) {
1343 enter.functions()->SessionError(instance, session_id.Get(dispatcher()),
1344 exception_code, system_code,
1345 error_description.Get(dispatcher()));
1349 void PPB_Instance_Proxy::OnHostMsgDeliverBlock(
1350 PP_Instance instance,
1351 PP_Resource decrypted_block,
1352 const std::string& serialized_block_info) {
1353 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1354 return;
1355 PP_DecryptedBlockInfo block_info;
1356 if (!DeserializeBlockInfo(serialized_block_info, &block_info))
1357 return;
1359 EnterInstanceNoLock enter(instance);
1360 if (enter.succeeded())
1361 enter.functions()->DeliverBlock(instance, decrypted_block, &block_info);
1364 void PPB_Instance_Proxy::OnHostMsgDecoderInitializeDone(
1365 PP_Instance instance,
1366 PP_DecryptorStreamType decoder_type,
1367 uint32_t request_id,
1368 PP_Bool success) {
1369 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1370 return;
1371 EnterInstanceNoLock enter(instance);
1372 if (enter.succeeded()) {
1373 enter.functions()->DecoderInitializeDone(instance,
1374 decoder_type,
1375 request_id,
1376 success);
1380 void PPB_Instance_Proxy::OnHostMsgDecoderDeinitializeDone(
1381 PP_Instance instance,
1382 PP_DecryptorStreamType decoder_type,
1383 uint32_t request_id) {
1384 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1385 return;
1386 EnterInstanceNoLock enter(instance);
1387 if (enter.succeeded())
1388 enter.functions()->DecoderDeinitializeDone(instance,
1389 decoder_type,
1390 request_id);
1393 void PPB_Instance_Proxy::OnHostMsgDecoderResetDone(
1394 PP_Instance instance,
1395 PP_DecryptorStreamType decoder_type,
1396 uint32_t request_id) {
1397 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1398 return;
1399 EnterInstanceNoLock enter(instance);
1400 if (enter.succeeded())
1401 enter.functions()->DecoderResetDone(instance, decoder_type, request_id);
1404 void PPB_Instance_Proxy::OnHostMsgDeliverFrame(
1405 PP_Instance instance,
1406 PP_Resource decrypted_frame,
1407 const std::string& serialized_frame_info) {
1408 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1409 return;
1410 PP_DecryptedFrameInfo frame_info;
1411 if (!DeserializeBlockInfo(serialized_frame_info, &frame_info))
1412 return;
1414 EnterInstanceNoLock enter(instance);
1415 if (enter.succeeded())
1416 enter.functions()->DeliverFrame(instance, decrypted_frame, &frame_info);
1419 void PPB_Instance_Proxy::OnHostMsgDeliverSamples(
1420 PP_Instance instance,
1421 PP_Resource audio_frames,
1422 const std::string& serialized_sample_info) {
1423 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1424 return;
1425 PP_DecryptedSampleInfo sample_info;
1426 if (!DeserializeBlockInfo(serialized_sample_info, &sample_info))
1427 return;
1429 EnterInstanceNoLock enter(instance);
1430 if (enter.succeeded())
1431 enter.functions()->DeliverSamples(instance, audio_frames, &sample_info);
1434 void PPB_Instance_Proxy::OnHostMsgSetCursor(
1435 PP_Instance instance,
1436 int32_t type,
1437 const ppapi::HostResource& custom_image,
1438 const PP_Point& hot_spot) {
1439 // This API serves PPB_CursorControl_Dev and PPB_MouseCursor, so is public.
1440 EnterInstanceNoLock enter(instance);
1441 if (enter.succeeded()) {
1442 enter.functions()->SetCursor(
1443 instance, static_cast<PP_MouseCursor_Type>(type),
1444 custom_image.host_resource(), &hot_spot);
1448 void PPB_Instance_Proxy::OnHostMsgSetTextInputType(PP_Instance instance,
1449 PP_TextInput_Type type) {
1450 EnterInstanceNoLock enter(instance);
1451 if (enter.succeeded())
1452 enter.functions()->SetTextInputType(instance, type);
1455 void PPB_Instance_Proxy::OnHostMsgUpdateCaretPosition(
1456 PP_Instance instance,
1457 const PP_Rect& caret,
1458 const PP_Rect& bounding_box) {
1459 EnterInstanceNoLock enter(instance);
1460 if (enter.succeeded())
1461 enter.functions()->UpdateCaretPosition(instance, caret, bounding_box);
1464 void PPB_Instance_Proxy::OnHostMsgCancelCompositionText(PP_Instance instance) {
1465 EnterInstanceNoLock enter(instance);
1466 if (enter.succeeded())
1467 enter.functions()->CancelCompositionText(instance);
1470 void PPB_Instance_Proxy::OnHostMsgUpdateSurroundingText(
1471 PP_Instance instance,
1472 const std::string& text,
1473 uint32_t caret,
1474 uint32_t anchor) {
1475 EnterInstanceNoLock enter(instance);
1476 if (enter.succeeded()) {
1477 enter.functions()->UpdateSurroundingText(instance, text.c_str(), caret,
1478 anchor);
1481 #endif // !defined(OS_NACL)
1483 void PPB_Instance_Proxy::OnPluginMsgMouseLockComplete(PP_Instance instance,
1484 int32_t result) {
1485 if (!dispatcher()->IsPlugin())
1486 return;
1488 // Save the mouse callback on the instance data.
1489 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1490 GetInstanceData(instance);
1491 if (!data)
1492 return; // Instance was probably deleted.
1493 if (!TrackedCallback::IsPending(data->mouse_lock_callback)) {
1494 NOTREACHED();
1495 return;
1497 data->mouse_lock_callback->Run(result);
1500 #if !defined(OS_NACL)
1501 void PPB_Instance_Proxy::MouseLockCompleteInHost(int32_t result,
1502 PP_Instance instance) {
1503 dispatcher()->Send(new PpapiMsg_PPBInstance_MouseLockComplete(
1504 API_ID_PPB_INSTANCE, instance, result));
1506 #endif // !defined(OS_NACL)
1508 void PPB_Instance_Proxy::CancelAnyPendingRequestSurroundingText(
1509 PP_Instance instance) {
1510 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1511 GetInstanceData(instance);
1512 if (!data)
1513 return; // Instance was probably deleted.
1514 data->should_do_request_surrounding_text = false;
1517 } // namespace proxy
1518 } // namespace ppapi