Extract code handling PrinterProviderAPI from PrintPreviewHandler
[chromium-blink-merge.git] / ppapi / proxy / ppb_instance_proxy.cc
blobf8b8ac9c22ac45b4fe261e3502b1a0ff81b22c08
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/stl_util.h"
9 #include "build/build_config.h"
10 #include "media/base/limits.h"
11 #include "ppapi/c/pp_errors.h"
12 #include "ppapi/c/pp_time.h"
13 #include "ppapi/c/pp_var.h"
14 #include "ppapi/c/ppb_audio_config.h"
15 #include "ppapi/c/ppb_instance.h"
16 #include "ppapi/c/ppb_messaging.h"
17 #include "ppapi/c/ppb_mouse_lock.h"
18 #include "ppapi/c/private/pp_content_decryptor.h"
19 #include "ppapi/proxy/broker_resource.h"
20 #include "ppapi/proxy/browser_font_singleton_resource.h"
21 #include "ppapi/proxy/content_decryptor_private_serializer.h"
22 #include "ppapi/proxy/enter_proxy.h"
23 #include "ppapi/proxy/file_mapping_resource.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 FILE_MAPPING_SINGLETON_ID:
396 new_singleton = new FileMappingResource(connection, instance);
397 break;
398 case GAMEPAD_SINGLETON_ID:
399 new_singleton = new GamepadResource(connection, instance);
400 break;
401 case ISOLATED_FILESYSTEM_SINGLETON_ID:
402 new_singleton =
403 new IsolatedFileSystemPrivateResource(connection, instance);
404 break;
405 case NETWORK_PROXY_SINGLETON_ID:
406 new_singleton = new NetworkProxyResource(connection, instance);
407 break;
408 case TRUETYPE_FONT_SINGLETON_ID:
409 new_singleton = new TrueTypeFontSingletonResource(connection, instance);
410 break;
411 case UMA_SINGLETON_ID:
412 new_singleton = new UMAPrivateResource(connection, instance);
413 break;
414 // Flash/trusted resources aren't needed for NaCl.
415 #if !defined(OS_NACL) && !defined(NACL_WIN64)
416 case BROWSER_FONT_SINGLETON_ID:
417 new_singleton = new BrowserFontSingletonResource(connection, instance);
418 break;
419 case FLASH_CLIPBOARD_SINGLETON_ID:
420 new_singleton = new FlashClipboardResource(connection, instance);
421 break;
422 case FLASH_FILE_SINGLETON_ID:
423 new_singleton = new FlashFileResource(connection, instance);
424 break;
425 case FLASH_FULLSCREEN_SINGLETON_ID:
426 new_singleton = new FlashFullscreenResource(connection, instance);
427 break;
428 case FLASH_SINGLETON_ID:
429 new_singleton = new FlashResource(connection, instance,
430 static_cast<PluginDispatcher*>(dispatcher()));
431 break;
432 case PDF_SINGLETON_ID:
433 new_singleton = new PDFResource(connection, instance);
434 break;
435 #else
436 case BROWSER_FONT_SINGLETON_ID:
437 case FLASH_CLIPBOARD_SINGLETON_ID:
438 case FLASH_FILE_SINGLETON_ID:
439 case FLASH_FULLSCREEN_SINGLETON_ID:
440 case FLASH_SINGLETON_ID:
441 case PDF_SINGLETON_ID:
442 NOTREACHED();
443 break;
444 #endif // !defined(OS_NACL) && !defined(NACL_WIN64)
447 if (!new_singleton.get()) {
448 // Getting here implies that a constructor is missing in the above switch.
449 NOTREACHED();
450 return NULL;
453 data->singleton_resources[id] = new_singleton;
454 return new_singleton.get();
457 int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance,
458 uint32_t event_classes) {
459 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
460 API_ID_PPB_INSTANCE, instance, false, event_classes));
462 // We always register for the classes we can handle, this function validates
463 // the flags so we can notify it if anything was invalid, without requiring
464 // a sync reply.
465 return ValidateRequestInputEvents(false, event_classes);
468 int32_t PPB_Instance_Proxy::RequestFilteringInputEvents(
469 PP_Instance instance,
470 uint32_t event_classes) {
471 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
472 API_ID_PPB_INSTANCE, instance, true, event_classes));
474 // We always register for the classes we can handle, this function validates
475 // the flags so we can notify it if anything was invalid, without requiring
476 // a sync reply.
477 return ValidateRequestInputEvents(true, event_classes);
480 void PPB_Instance_Proxy::ClearInputEventRequest(PP_Instance instance,
481 uint32_t event_classes) {
482 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ClearInputEvents(
483 API_ID_PPB_INSTANCE, instance, event_classes));
486 void PPB_Instance_Proxy::StartTrackingLatency(PP_Instance instance) {
487 dispatcher()->Send(new PpapiHostMsg_PPBInstance_StartTrackingLatency(
488 API_ID_PPB_INSTANCE, instance));
491 void PPB_Instance_Proxy::ZoomChanged(PP_Instance instance,
492 double factor) {
493 // Not proxied yet.
494 NOTIMPLEMENTED();
497 void PPB_Instance_Proxy::ZoomLimitsChanged(PP_Instance instance,
498 double minimum_factor,
499 double maximium_factor) {
500 // Not proxied yet.
501 NOTIMPLEMENTED();
504 PP_Var PPB_Instance_Proxy::GetDocumentURL(PP_Instance instance,
505 PP_URLComponents_Dev* components) {
506 ReceiveSerializedVarReturnValue result;
507 PP_URLComponents_Dev url_components = {{0}};
508 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetDocumentURL(
509 API_ID_PPB_INSTANCE, instance, &url_components, &result));
510 if (components)
511 *components = url_components;
512 return result.Return(dispatcher());
515 #if !defined(OS_NACL)
516 PP_Var PPB_Instance_Proxy::ResolveRelativeToDocument(
517 PP_Instance instance,
518 PP_Var relative,
519 PP_URLComponents_Dev* components) {
520 ReceiveSerializedVarReturnValue result;
521 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ResolveRelativeToDocument(
522 API_ID_PPB_INSTANCE, instance,
523 SerializedVarSendInput(dispatcher(), relative),
524 &result));
525 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
526 result.Return(dispatcher()),
527 components);
530 PP_Bool PPB_Instance_Proxy::DocumentCanRequest(PP_Instance instance,
531 PP_Var url) {
532 PP_Bool result = PP_FALSE;
533 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanRequest(
534 API_ID_PPB_INSTANCE, instance,
535 SerializedVarSendInput(dispatcher(), url),
536 &result));
537 return result;
540 PP_Bool PPB_Instance_Proxy::DocumentCanAccessDocument(PP_Instance instance,
541 PP_Instance target) {
542 PP_Bool result = PP_FALSE;
543 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanAccessDocument(
544 API_ID_PPB_INSTANCE, instance, target, &result));
545 return result;
548 PP_Var PPB_Instance_Proxy::GetPluginInstanceURL(
549 PP_Instance instance,
550 PP_URLComponents_Dev* components) {
551 ReceiveSerializedVarReturnValue result;
552 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginInstanceURL(
553 API_ID_PPB_INSTANCE, instance, &result));
554 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
555 result.Return(dispatcher()),
556 components);
559 PP_Var PPB_Instance_Proxy::GetPluginReferrerURL(
560 PP_Instance instance,
561 PP_URLComponents_Dev* components) {
562 ReceiveSerializedVarReturnValue result;
563 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginReferrerURL(
564 API_ID_PPB_INSTANCE, instance, &result));
565 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
566 result.Return(dispatcher()),
567 components);
570 void PPB_Instance_Proxy::PromiseResolved(PP_Instance instance,
571 uint32 promise_id) {
572 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseResolved(
573 API_ID_PPB_INSTANCE, instance, promise_id));
576 void PPB_Instance_Proxy::PromiseResolvedWithSession(PP_Instance instance,
577 uint32 promise_id,
578 PP_Var session_id_var) {
579 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseResolvedWithSession(
580 API_ID_PPB_INSTANCE, instance, promise_id,
581 SerializedVarSendInput(dispatcher(), session_id_var)));
584 void PPB_Instance_Proxy::PromiseRejected(PP_Instance instance,
585 uint32 promise_id,
586 PP_CdmExceptionCode exception_code,
587 uint32 system_code,
588 PP_Var error_description_var) {
589 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseRejected(
590 API_ID_PPB_INSTANCE,
591 instance,
592 promise_id,
593 exception_code,
594 system_code,
595 SerializedVarSendInput(dispatcher(), error_description_var)));
598 void PPB_Instance_Proxy::SessionMessage(PP_Instance instance,
599 PP_Var session_id_var,
600 PP_CdmMessageType message_type,
601 PP_Var message_var,
602 PP_Var legacy_destination_url_var) {
603 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionMessage(
604 API_ID_PPB_INSTANCE, instance,
605 SerializedVarSendInput(dispatcher(), session_id_var), message_type,
606 SerializedVarSendInput(dispatcher(), message_var),
607 SerializedVarSendInput(dispatcher(), legacy_destination_url_var)));
610 void PPB_Instance_Proxy::SessionKeysChange(
611 PP_Instance instance,
612 PP_Var session_id_var,
613 PP_Bool has_additional_usable_key,
614 uint32_t key_count,
615 const struct PP_KeyInformation key_information[]) {
616 StringVar* session_id = StringVar::FromPPVar(session_id_var);
617 if (!session_id ||
618 session_id->value().length() > media::limits::kMaxSessionIdLength) {
619 NOTREACHED();
620 return;
623 if (key_count > media::limits::kMaxKeyIds) {
624 NOTREACHED();
625 return;
628 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionKeysChange(
629 API_ID_PPB_INSTANCE, instance, session_id->value(),
630 has_additional_usable_key,
631 std::vector<PP_KeyInformation>(key_information,
632 key_information + key_count)));
635 void PPB_Instance_Proxy::SessionExpirationChange(PP_Instance instance,
636 PP_Var session_id_var,
637 PP_Time new_expiry_time) {
638 StringVar* session_id = StringVar::FromPPVar(session_id_var);
639 if (!session_id ||
640 session_id->value().length() > media::limits::kMaxSessionIdLength) {
641 NOTREACHED();
642 return;
645 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionExpirationChange(
646 API_ID_PPB_INSTANCE, instance, session_id->value(), new_expiry_time));
649 void PPB_Instance_Proxy::SessionClosed(PP_Instance instance,
650 PP_Var session_id_var) {
651 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionClosed(
652 API_ID_PPB_INSTANCE, instance,
653 SerializedVarSendInput(dispatcher(), session_id_var)));
656 void PPB_Instance_Proxy::SessionError(PP_Instance instance,
657 PP_Var session_id_var,
658 PP_CdmExceptionCode exception_code,
659 uint32 system_code,
660 PP_Var error_description_var) {
661 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionError(
662 API_ID_PPB_INSTANCE, instance,
663 SerializedVarSendInput(dispatcher(), session_id_var), exception_code,
664 system_code,
665 SerializedVarSendInput(dispatcher(), error_description_var)));
668 void PPB_Instance_Proxy::DeliverBlock(PP_Instance instance,
669 PP_Resource decrypted_block,
670 const PP_DecryptedBlockInfo* block_info) {
671 PP_Resource decrypted_block_host_resource = 0;
673 if (decrypted_block) {
674 Resource* object =
675 PpapiGlobals::Get()->GetResourceTracker()->GetResource(decrypted_block);
676 if (!object || object->pp_instance() != instance) {
677 NOTREACHED();
678 return;
680 decrypted_block_host_resource = object->host_resource().host_resource();
683 std::string serialized_block_info;
684 if (!SerializeBlockInfo(*block_info, &serialized_block_info)) {
685 NOTREACHED();
686 return;
689 dispatcher()->Send(
690 new PpapiHostMsg_PPBInstance_DeliverBlock(API_ID_PPB_INSTANCE,
691 instance,
692 decrypted_block_host_resource,
693 serialized_block_info));
696 void PPB_Instance_Proxy::DecoderInitializeDone(
697 PP_Instance instance,
698 PP_DecryptorStreamType decoder_type,
699 uint32_t request_id,
700 PP_Bool success) {
701 dispatcher()->Send(
702 new PpapiHostMsg_PPBInstance_DecoderInitializeDone(
703 API_ID_PPB_INSTANCE,
704 instance,
705 decoder_type,
706 request_id,
707 success));
710 void PPB_Instance_Proxy::DecoderDeinitializeDone(
711 PP_Instance instance,
712 PP_DecryptorStreamType decoder_type,
713 uint32_t request_id) {
714 dispatcher()->Send(
715 new PpapiHostMsg_PPBInstance_DecoderDeinitializeDone(
716 API_ID_PPB_INSTANCE,
717 instance,
718 decoder_type,
719 request_id));
722 void PPB_Instance_Proxy::DecoderResetDone(PP_Instance instance,
723 PP_DecryptorStreamType decoder_type,
724 uint32_t request_id) {
725 dispatcher()->Send(
726 new PpapiHostMsg_PPBInstance_DecoderResetDone(
727 API_ID_PPB_INSTANCE,
728 instance,
729 decoder_type,
730 request_id));
733 void PPB_Instance_Proxy::DeliverFrame(PP_Instance instance,
734 PP_Resource decrypted_frame,
735 const PP_DecryptedFrameInfo* frame_info) {
736 PP_Resource host_resource = 0;
737 if (decrypted_frame != 0) {
738 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
739 Resource* object = tracker->GetResource(decrypted_frame);
741 if (!object || object->pp_instance() != instance) {
742 NOTREACHED();
743 return;
746 host_resource = object->host_resource().host_resource();
749 std::string serialized_frame_info;
750 if (!SerializeBlockInfo(*frame_info, &serialized_frame_info)) {
751 NOTREACHED();
752 return;
755 dispatcher()->Send(
756 new PpapiHostMsg_PPBInstance_DeliverFrame(API_ID_PPB_INSTANCE,
757 instance,
758 host_resource,
759 serialized_frame_info));
762 void PPB_Instance_Proxy::DeliverSamples(
763 PP_Instance instance,
764 PP_Resource decrypted_samples,
765 const PP_DecryptedSampleInfo* sample_info) {
766 PP_Resource host_resource = 0;
767 if (decrypted_samples != 0) {
768 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
769 Resource* object = tracker->GetResource(decrypted_samples);
771 if (!object || object->pp_instance() != instance) {
772 NOTREACHED();
773 return;
776 host_resource = object->host_resource().host_resource();
779 std::string serialized_sample_info;
780 if (!SerializeBlockInfo(*sample_info, &serialized_sample_info)) {
781 NOTREACHED();
782 return;
785 dispatcher()->Send(
786 new PpapiHostMsg_PPBInstance_DeliverSamples(API_ID_PPB_INSTANCE,
787 instance,
788 host_resource,
789 serialized_sample_info));
791 #endif // !defined(OS_NACL)
793 void PPB_Instance_Proxy::PostMessage(PP_Instance instance,
794 PP_Var message) {
795 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage(
796 API_ID_PPB_INSTANCE,
797 instance, SerializedVarSendInputShmem(dispatcher(), message,
798 instance)));
801 int32_t PPB_Instance_Proxy::RegisterMessageHandler(
802 PP_Instance instance,
803 void* user_data,
804 const PPP_MessageHandler_0_2* handler,
805 PP_Resource message_loop) {
806 InstanceData* data =
807 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
808 if (!data)
809 return PP_ERROR_BADARGUMENT;
811 int32_t result = PP_ERROR_FAILED;
812 scoped_ptr<MessageHandler> message_handler = MessageHandler::Create(
813 instance, handler, user_data, message_loop, &result);
814 if (message_handler)
815 data->message_handler = message_handler.Pass();
816 return result;
819 // TODO(dmichael): Remove this. crbug.com/414398
820 int32_t PPB_Instance_Proxy::RegisterMessageHandler_1_1_Deprecated(
821 PP_Instance instance,
822 void* user_data,
823 const PPP_MessageHandler_0_1_Deprecated* handler,
824 PP_Resource message_loop) {
825 InstanceData* data =
826 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
827 if (!data)
828 return PP_ERROR_BADARGUMENT;
830 int32_t result = PP_ERROR_FAILED;
831 scoped_ptr<MessageHandler> message_handler = MessageHandler::CreateDeprecated(
832 instance, handler, user_data, message_loop, &result);
833 if (message_handler)
834 data->message_handler = message_handler.Pass();
835 return result;
838 void PPB_Instance_Proxy::UnregisterMessageHandler(PP_Instance instance) {
839 InstanceData* data =
840 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
841 if (!data)
842 return;
843 data->message_handler.reset();
846 PP_Bool PPB_Instance_Proxy::SetCursor(PP_Instance instance,
847 PP_MouseCursor_Type type,
848 PP_Resource image,
849 const PP_Point* hot_spot) {
850 // Some of these parameters are important for security. This check is in the
851 // plugin process just for the convenience of the caller (since we don't
852 // bother returning errors from the other process with a sync message). The
853 // parameters will be validated again in the renderer.
854 if (!ValidateSetCursorParams(type, image, hot_spot))
855 return PP_FALSE;
857 HostResource image_host_resource;
858 if (image) {
859 Resource* cursor_image =
860 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image);
861 if (!cursor_image || cursor_image->pp_instance() != instance)
862 return PP_FALSE;
863 image_host_resource = cursor_image->host_resource();
866 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetCursor(
867 API_ID_PPB_INSTANCE, instance, static_cast<int32_t>(type),
868 image_host_resource, hot_spot ? *hot_spot : PP_MakePoint(0, 0)));
869 return PP_TRUE;
872 int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance,
873 scoped_refptr<TrackedCallback> callback) {
874 // Save the mouse callback on the instance data.
875 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
876 GetInstanceData(instance);
877 if (!data)
878 return PP_ERROR_BADARGUMENT;
879 if (TrackedCallback::IsPending(data->mouse_lock_callback))
880 return PP_ERROR_INPROGRESS; // Already have a pending callback.
881 data->mouse_lock_callback = callback;
883 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LockMouse(
884 API_ID_PPB_INSTANCE, instance));
885 return PP_OK_COMPLETIONPENDING;
888 void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance) {
889 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UnlockMouse(
890 API_ID_PPB_INSTANCE, instance));
893 void PPB_Instance_Proxy::SetTextInputType(PP_Instance instance,
894 PP_TextInput_Type type) {
895 CancelAnyPendingRequestSurroundingText(instance);
896 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTextInputType(
897 API_ID_PPB_INSTANCE, instance, type));
900 void PPB_Instance_Proxy::UpdateCaretPosition(PP_Instance instance,
901 const PP_Rect& caret,
902 const PP_Rect& bounding_box) {
903 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateCaretPosition(
904 API_ID_PPB_INSTANCE, instance, caret, bounding_box));
907 void PPB_Instance_Proxy::CancelCompositionText(PP_Instance instance) {
908 CancelAnyPendingRequestSurroundingText(instance);
909 dispatcher()->Send(new PpapiHostMsg_PPBInstance_CancelCompositionText(
910 API_ID_PPB_INSTANCE, instance));
913 void PPB_Instance_Proxy::SelectionChanged(PP_Instance instance) {
914 // The "right" way to do this is to send the message to the host. However,
915 // all it will do is call RequestSurroundingText with a hardcoded number of
916 // characters in response, which is an entire IPC round-trip.
918 // We can avoid this round-trip by just implementing the
919 // RequestSurroundingText logic in the plugin process. If the logic in the
920 // host becomes more complex (like a more adaptive number of characters),
921 // we'll need to reevanuate whether we want to do the round trip instead.
923 // Be careful to post a task to avoid reentering the plugin.
925 InstanceData* data =
926 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
927 if (!data)
928 return;
929 data->should_do_request_surrounding_text = true;
931 if (!data->is_request_surrounding_text_pending) {
932 base::MessageLoop::current()->PostTask(
933 FROM_HERE,
934 RunWhileLocked(base::Bind(&RequestSurroundingText, instance)));
935 data->is_request_surrounding_text_pending = true;
939 void PPB_Instance_Proxy::UpdateSurroundingText(PP_Instance instance,
940 const char* text,
941 uint32_t caret,
942 uint32_t anchor) {
943 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateSurroundingText(
944 API_ID_PPB_INSTANCE, instance, text, caret, anchor));
947 #if !defined(OS_NACL)
948 void PPB_Instance_Proxy::OnHostMsgGetWindowObject(
949 PP_Instance instance,
950 SerializedVarReturnValue result) {
951 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
952 return;
953 EnterInstanceNoLock enter(instance);
954 if (enter.succeeded())
955 result.Return(dispatcher(), enter.functions()->GetWindowObject(instance));
958 void PPB_Instance_Proxy::OnHostMsgGetOwnerElementObject(
959 PP_Instance instance,
960 SerializedVarReturnValue result) {
961 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
962 return;
963 EnterInstanceNoLock enter(instance);
964 if (enter.succeeded()) {
965 result.Return(dispatcher(),
966 enter.functions()->GetOwnerElementObject(instance));
970 void PPB_Instance_Proxy::OnHostMsgBindGraphics(PP_Instance instance,
971 PP_Resource device) {
972 // Note that we ignroe the return value here. Otherwise, this would need to
973 // be a slow sync call, and the plugin side of the proxy will have already
974 // validated the resources, so we shouldn't see errors here that weren't
975 // already caught.
976 EnterInstanceNoLock enter(instance);
977 if (enter.succeeded())
978 enter.functions()->BindGraphics(instance, device);
981 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputSampleRate(
982 PP_Instance instance, uint32_t* result) {
983 EnterInstanceNoLock enter(instance);
984 if (enter.succeeded())
985 *result = enter.functions()->GetAudioHardwareOutputSampleRate(instance);
988 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputBufferSize(
989 PP_Instance instance, uint32_t* result) {
990 EnterInstanceNoLock enter(instance);
991 if (enter.succeeded())
992 *result = enter.functions()->GetAudioHardwareOutputBufferSize(instance);
995 void PPB_Instance_Proxy::OnHostMsgIsFullFrame(PP_Instance instance,
996 PP_Bool* result) {
997 EnterInstanceNoLock enter(instance);
998 if (enter.succeeded())
999 *result = enter.functions()->IsFullFrame(instance);
1002 void PPB_Instance_Proxy::OnHostMsgExecuteScript(
1003 PP_Instance instance,
1004 SerializedVarReceiveInput script,
1005 SerializedVarOutParam out_exception,
1006 SerializedVarReturnValue result) {
1007 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1008 return;
1009 EnterInstanceNoLock enter(instance);
1010 if (enter.failed())
1011 return;
1013 if (dispatcher()->IsPlugin())
1014 NOTREACHED();
1015 else
1016 static_cast<HostDispatcher*>(dispatcher())->set_allow_plugin_reentrancy();
1018 result.Return(dispatcher(), enter.functions()->ExecuteScript(
1019 instance,
1020 script.Get(dispatcher()),
1021 out_exception.OutParam(dispatcher())));
1024 void PPB_Instance_Proxy::OnHostMsgGetDefaultCharSet(
1025 PP_Instance instance,
1026 SerializedVarReturnValue result) {
1027 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1028 return;
1029 EnterInstanceNoLock enter(instance);
1030 if (enter.succeeded())
1031 result.Return(dispatcher(), enter.functions()->GetDefaultCharSet(instance));
1034 void PPB_Instance_Proxy::OnHostMsgSetPluginToHandleFindRequests(
1035 PP_Instance instance) {
1036 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1037 return;
1038 EnterInstanceNoLock enter(instance);
1039 if (enter.succeeded())
1040 enter.functions()->SetPluginToHandleFindRequests(instance);
1043 void PPB_Instance_Proxy::OnHostMsgNumberOfFindResultsChanged(
1044 PP_Instance instance,
1045 int32_t total,
1046 PP_Bool final_result) {
1047 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1048 return;
1049 EnterInstanceNoLock enter(instance);
1050 if (enter.succeeded()) {
1051 enter.functions()->NumberOfFindResultsChanged(
1052 instance, total, final_result);
1056 void PPB_Instance_Proxy::OnHostMsgSelectFindResultChanged(
1057 PP_Instance instance,
1058 int32_t index) {
1059 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1060 return;
1061 EnterInstanceNoLock enter(instance);
1062 if (enter.succeeded())
1063 enter.functions()->SelectedFindResultChanged(instance, index);
1066 void PPB_Instance_Proxy::OnHostMsgSetTickmarks(
1067 PP_Instance instance,
1068 const std::vector<PP_Rect>& tickmarks) {
1069 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1070 return;
1071 const PP_Rect* array = tickmarks.empty() ? NULL : &tickmarks[0];
1072 EnterInstanceNoLock enter(instance);
1073 if (enter.succeeded()) {
1074 enter.functions()->SetTickmarks(instance,
1075 array,
1076 static_cast<uint32_t>(tickmarks.size()));
1080 void PPB_Instance_Proxy::OnHostMsgSetFullscreen(PP_Instance instance,
1081 PP_Bool fullscreen,
1082 PP_Bool* result) {
1083 EnterInstanceNoLock enter(instance);
1084 if (enter.succeeded())
1085 *result = enter.functions()->SetFullscreen(instance, fullscreen);
1089 void PPB_Instance_Proxy::OnHostMsgGetScreenSize(PP_Instance instance,
1090 PP_Bool* result,
1091 PP_Size* size) {
1092 EnterInstanceNoLock enter(instance);
1093 if (enter.succeeded())
1094 *result = enter.functions()->GetScreenSize(instance, size);
1097 void PPB_Instance_Proxy::OnHostMsgRequestInputEvents(PP_Instance instance,
1098 bool is_filtering,
1099 uint32_t event_classes) {
1100 EnterInstanceNoLock enter(instance);
1101 if (enter.succeeded()) {
1102 if (is_filtering)
1103 enter.functions()->RequestFilteringInputEvents(instance, event_classes);
1104 else
1105 enter.functions()->RequestInputEvents(instance, event_classes);
1109 void PPB_Instance_Proxy::OnHostMsgClearInputEvents(PP_Instance instance,
1110 uint32_t event_classes) {
1111 EnterInstanceNoLock enter(instance);
1112 if (enter.succeeded())
1113 enter.functions()->ClearInputEventRequest(instance, event_classes);
1116 void PPB_Instance_Proxy::OnHostMsgStartTrackingLatency(PP_Instance instance) {
1117 EnterInstanceNoLock enter(instance);
1118 if (enter.succeeded())
1119 enter.functions()->StartTrackingLatency(instance);
1122 void PPB_Instance_Proxy::OnHostMsgPostMessage(
1123 PP_Instance instance,
1124 SerializedVarReceiveInput message) {
1125 EnterInstanceNoLock enter(instance);
1126 if (!message.is_valid_var()) {
1127 PpapiGlobals::Get()->LogWithSource(
1128 instance, PP_LOGLEVEL_ERROR, std::string(), kSerializationError);
1129 return;
1132 if (enter.succeeded())
1133 enter.functions()->PostMessage(instance,
1134 message.GetForInstance(dispatcher(),
1135 instance));
1138 void PPB_Instance_Proxy::OnHostMsgLockMouse(PP_Instance instance) {
1139 // Need to be careful to always issue the callback.
1140 pp::CompletionCallback cb = callback_factory_.NewCallback(
1141 &PPB_Instance_Proxy::MouseLockCompleteInHost, instance);
1143 EnterInstanceNoLock enter(instance, cb.pp_completion_callback());
1144 if (enter.succeeded())
1145 enter.SetResult(enter.functions()->LockMouse(instance, enter.callback()));
1148 void PPB_Instance_Proxy::OnHostMsgUnlockMouse(PP_Instance instance) {
1149 EnterInstanceNoLock enter(instance);
1150 if (enter.succeeded())
1151 enter.functions()->UnlockMouse(instance);
1154 void PPB_Instance_Proxy::OnHostMsgGetDocumentURL(
1155 PP_Instance instance,
1156 PP_URLComponents_Dev* components,
1157 SerializedVarReturnValue result) {
1158 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1159 return;
1160 EnterInstanceNoLock enter(instance);
1161 if (enter.succeeded()) {
1162 PP_Var document_url = enter.functions()->GetDocumentURL(instance,
1163 components);
1164 result.Return(dispatcher(), document_url);
1168 void PPB_Instance_Proxy::OnHostMsgResolveRelativeToDocument(
1169 PP_Instance instance,
1170 SerializedVarReceiveInput relative,
1171 SerializedVarReturnValue result) {
1172 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1173 return;
1174 EnterInstanceNoLock enter(instance);
1175 if (enter.succeeded()) {
1176 result.Return(dispatcher(),
1177 enter.functions()->ResolveRelativeToDocument(
1178 instance, relative.Get(dispatcher()), NULL));
1182 void PPB_Instance_Proxy::OnHostMsgDocumentCanRequest(
1183 PP_Instance instance,
1184 SerializedVarReceiveInput url,
1185 PP_Bool* result) {
1186 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1187 return;
1188 EnterInstanceNoLock enter(instance);
1189 if (enter.succeeded()) {
1190 *result = enter.functions()->DocumentCanRequest(instance,
1191 url.Get(dispatcher()));
1195 void PPB_Instance_Proxy::OnHostMsgDocumentCanAccessDocument(PP_Instance active,
1196 PP_Instance target,
1197 PP_Bool* result) {
1198 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1199 return;
1200 EnterInstanceNoLock enter(active);
1201 if (enter.succeeded())
1202 *result = enter.functions()->DocumentCanAccessDocument(active, target);
1205 void PPB_Instance_Proxy::OnHostMsgGetPluginInstanceURL(
1206 PP_Instance instance,
1207 SerializedVarReturnValue result) {
1208 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1209 return;
1210 EnterInstanceNoLock enter(instance);
1211 if (enter.succeeded()) {
1212 result.Return(dispatcher(),
1213 enter.functions()->GetPluginInstanceURL(instance, NULL));
1217 void PPB_Instance_Proxy::OnHostMsgGetPluginReferrerURL(
1218 PP_Instance instance,
1219 SerializedVarReturnValue result) {
1220 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1221 return;
1222 EnterInstanceNoLock enter(instance);
1223 if (enter.succeeded()) {
1224 result.Return(dispatcher(),
1225 enter.functions()->GetPluginReferrerURL(instance, NULL));
1229 void PPB_Instance_Proxy::OnHostMsgPromiseResolved(PP_Instance instance,
1230 uint32_t promise_id) {
1231 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1232 return;
1233 EnterInstanceNoLock enter(instance);
1234 if (enter.succeeded()) {
1235 enter.functions()->PromiseResolved(instance, promise_id);
1239 void PPB_Instance_Proxy::OnHostMsgPromiseResolvedWithSession(
1240 PP_Instance instance,
1241 uint32_t promise_id,
1242 SerializedVarReceiveInput session_id) {
1243 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1244 return;
1245 EnterInstanceNoLock enter(instance);
1246 if (enter.succeeded()) {
1247 enter.functions()->PromiseResolvedWithSession(instance, promise_id,
1248 session_id.Get(dispatcher()));
1252 void PPB_Instance_Proxy::OnHostMsgPromiseRejected(
1253 PP_Instance instance,
1254 uint32_t promise_id,
1255 PP_CdmExceptionCode exception_code,
1256 uint32_t system_code,
1257 SerializedVarReceiveInput error_description) {
1258 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1259 return;
1260 EnterInstanceNoLock enter(instance);
1261 if (enter.succeeded()) {
1262 enter.functions()->PromiseRejected(instance,
1263 promise_id,
1264 exception_code,
1265 system_code,
1266 error_description.Get(dispatcher()));
1270 void PPB_Instance_Proxy::OnHostMsgSessionMessage(
1271 PP_Instance instance,
1272 SerializedVarReceiveInput session_id,
1273 PP_CdmMessageType message_type,
1274 SerializedVarReceiveInput message,
1275 SerializedVarReceiveInput legacy_destination_url) {
1276 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1277 return;
1278 EnterInstanceNoLock enter(instance);
1279 if (enter.succeeded()) {
1280 enter.functions()->SessionMessage(instance, session_id.Get(dispatcher()),
1281 message_type, message.Get(dispatcher()),
1282 legacy_destination_url.Get(dispatcher()));
1286 void PPB_Instance_Proxy::OnHostMsgSessionKeysChange(
1287 PP_Instance instance,
1288 const std::string& session_id,
1289 PP_Bool has_additional_usable_key,
1290 const std::vector<PP_KeyInformation>& key_information) {
1291 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1292 return;
1294 if (key_information.size() > media::limits::kMaxKeyIds) {
1295 NOTREACHED();
1296 return;
1299 EnterInstanceNoLock enter(instance);
1300 if (enter.succeeded()) {
1301 ScopedPPVar session_id_var(ScopedPPVar::PassRef(),
1302 StringVar::StringToPPVar(session_id));
1303 enter.functions()->SessionKeysChange(
1304 instance, session_id_var.get(), has_additional_usable_key,
1305 key_information.size(), vector_as_array(&key_information));
1309 void PPB_Instance_Proxy::OnHostMsgSessionExpirationChange(
1310 PP_Instance instance,
1311 const std::string& session_id,
1312 PP_Time new_expiry_time) {
1313 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1314 return;
1315 EnterInstanceNoLock enter(instance);
1316 if (enter.succeeded()) {
1317 ScopedPPVar session_id_var(ScopedPPVar::PassRef(),
1318 StringVar::StringToPPVar(session_id));
1319 enter.functions()->SessionExpirationChange(instance, session_id_var.get(),
1320 new_expiry_time);
1324 void PPB_Instance_Proxy::OnHostMsgSessionClosed(
1325 PP_Instance instance,
1326 SerializedVarReceiveInput session_id) {
1327 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1328 return;
1329 EnterInstanceNoLock enter(instance);
1330 if (enter.succeeded()) {
1331 enter.functions()->SessionClosed(instance, session_id.Get(dispatcher()));
1335 void PPB_Instance_Proxy::OnHostMsgSessionError(
1336 PP_Instance instance,
1337 SerializedVarReceiveInput session_id,
1338 PP_CdmExceptionCode exception_code,
1339 uint32_t system_code,
1340 SerializedVarReceiveInput error_description) {
1341 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1342 return;
1343 EnterInstanceNoLock enter(instance);
1344 if (enter.succeeded()) {
1345 enter.functions()->SessionError(instance, session_id.Get(dispatcher()),
1346 exception_code, system_code,
1347 error_description.Get(dispatcher()));
1351 void PPB_Instance_Proxy::OnHostMsgDeliverBlock(
1352 PP_Instance instance,
1353 PP_Resource decrypted_block,
1354 const std::string& serialized_block_info) {
1355 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1356 return;
1357 PP_DecryptedBlockInfo block_info;
1358 if (!DeserializeBlockInfo(serialized_block_info, &block_info))
1359 return;
1361 EnterInstanceNoLock enter(instance);
1362 if (enter.succeeded())
1363 enter.functions()->DeliverBlock(instance, decrypted_block, &block_info);
1366 void PPB_Instance_Proxy::OnHostMsgDecoderInitializeDone(
1367 PP_Instance instance,
1368 PP_DecryptorStreamType decoder_type,
1369 uint32_t request_id,
1370 PP_Bool success) {
1371 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1372 return;
1373 EnterInstanceNoLock enter(instance);
1374 if (enter.succeeded()) {
1375 enter.functions()->DecoderInitializeDone(instance,
1376 decoder_type,
1377 request_id,
1378 success);
1382 void PPB_Instance_Proxy::OnHostMsgDecoderDeinitializeDone(
1383 PP_Instance instance,
1384 PP_DecryptorStreamType decoder_type,
1385 uint32_t request_id) {
1386 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1387 return;
1388 EnterInstanceNoLock enter(instance);
1389 if (enter.succeeded())
1390 enter.functions()->DecoderDeinitializeDone(instance,
1391 decoder_type,
1392 request_id);
1395 void PPB_Instance_Proxy::OnHostMsgDecoderResetDone(
1396 PP_Instance instance,
1397 PP_DecryptorStreamType decoder_type,
1398 uint32_t request_id) {
1399 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1400 return;
1401 EnterInstanceNoLock enter(instance);
1402 if (enter.succeeded())
1403 enter.functions()->DecoderResetDone(instance, decoder_type, request_id);
1406 void PPB_Instance_Proxy::OnHostMsgDeliverFrame(
1407 PP_Instance instance,
1408 PP_Resource decrypted_frame,
1409 const std::string& serialized_frame_info) {
1410 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1411 return;
1412 PP_DecryptedFrameInfo frame_info;
1413 if (!DeserializeBlockInfo(serialized_frame_info, &frame_info))
1414 return;
1416 EnterInstanceNoLock enter(instance);
1417 if (enter.succeeded())
1418 enter.functions()->DeliverFrame(instance, decrypted_frame, &frame_info);
1421 void PPB_Instance_Proxy::OnHostMsgDeliverSamples(
1422 PP_Instance instance,
1423 PP_Resource audio_frames,
1424 const std::string& serialized_sample_info) {
1425 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1426 return;
1427 PP_DecryptedSampleInfo sample_info;
1428 if (!DeserializeBlockInfo(serialized_sample_info, &sample_info))
1429 return;
1431 EnterInstanceNoLock enter(instance);
1432 if (enter.succeeded())
1433 enter.functions()->DeliverSamples(instance, audio_frames, &sample_info);
1436 void PPB_Instance_Proxy::OnHostMsgSetCursor(
1437 PP_Instance instance,
1438 int32_t type,
1439 const ppapi::HostResource& custom_image,
1440 const PP_Point& hot_spot) {
1441 // This API serves PPB_CursorControl_Dev and PPB_MouseCursor, so is public.
1442 EnterInstanceNoLock enter(instance);
1443 if (enter.succeeded()) {
1444 enter.functions()->SetCursor(
1445 instance, static_cast<PP_MouseCursor_Type>(type),
1446 custom_image.host_resource(), &hot_spot);
1450 void PPB_Instance_Proxy::OnHostMsgSetTextInputType(PP_Instance instance,
1451 PP_TextInput_Type type) {
1452 EnterInstanceNoLock enter(instance);
1453 if (enter.succeeded())
1454 enter.functions()->SetTextInputType(instance, type);
1457 void PPB_Instance_Proxy::OnHostMsgUpdateCaretPosition(
1458 PP_Instance instance,
1459 const PP_Rect& caret,
1460 const PP_Rect& bounding_box) {
1461 EnterInstanceNoLock enter(instance);
1462 if (enter.succeeded())
1463 enter.functions()->UpdateCaretPosition(instance, caret, bounding_box);
1466 void PPB_Instance_Proxy::OnHostMsgCancelCompositionText(PP_Instance instance) {
1467 EnterInstanceNoLock enter(instance);
1468 if (enter.succeeded())
1469 enter.functions()->CancelCompositionText(instance);
1472 void PPB_Instance_Proxy::OnHostMsgUpdateSurroundingText(
1473 PP_Instance instance,
1474 const std::string& text,
1475 uint32_t caret,
1476 uint32_t anchor) {
1477 EnterInstanceNoLock enter(instance);
1478 if (enter.succeeded()) {
1479 enter.functions()->UpdateSurroundingText(instance, text.c_str(), caret,
1480 anchor);
1483 #endif // !defined(OS_NACL)
1485 void PPB_Instance_Proxy::OnPluginMsgMouseLockComplete(PP_Instance instance,
1486 int32_t result) {
1487 if (!dispatcher()->IsPlugin())
1488 return;
1490 // Save the mouse callback on the instance data.
1491 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1492 GetInstanceData(instance);
1493 if (!data)
1494 return; // Instance was probably deleted.
1495 if (!TrackedCallback::IsPending(data->mouse_lock_callback)) {
1496 NOTREACHED();
1497 return;
1499 data->mouse_lock_callback->Run(result);
1502 #if !defined(OS_NACL)
1503 void PPB_Instance_Proxy::MouseLockCompleteInHost(int32_t result,
1504 PP_Instance instance) {
1505 dispatcher()->Send(new PpapiMsg_PPBInstance_MouseLockComplete(
1506 API_ID_PPB_INSTANCE, instance, result));
1508 #endif // !defined(OS_NACL)
1510 void PPB_Instance_Proxy::CancelAnyPendingRequestSurroundingText(
1511 PP_Instance instance) {
1512 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1513 GetInstanceData(instance);
1514 if (!data)
1515 return; // Instance was probably deleted.
1516 data->should_do_request_surrounding_text = false;
1519 } // namespace proxy
1520 } // namespace ppapi