Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ppapi / proxy / ppb_instance_proxy.cc
blob2780022d605b2e13f7efa82dbb956e71ff575379
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 "build/build_config.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/pp_time.h"
11 #include "ppapi/c/pp_var.h"
12 #include "ppapi/c/ppb_audio_config.h"
13 #include "ppapi/c/ppb_instance.h"
14 #include "ppapi/c/ppb_messaging.h"
15 #include "ppapi/c/ppb_mouse_lock.h"
16 #include "ppapi/c/private/pp_content_decryptor.h"
17 #include "ppapi/proxy/broker_resource.h"
18 #include "ppapi/proxy/browser_font_singleton_resource.h"
19 #include "ppapi/proxy/content_decryptor_private_serializer.h"
20 #include "ppapi/proxy/enter_proxy.h"
21 #include "ppapi/proxy/file_mapping_resource.h"
22 #include "ppapi/proxy/flash_clipboard_resource.h"
23 #include "ppapi/proxy/flash_file_resource.h"
24 #include "ppapi/proxy/flash_fullscreen_resource.h"
25 #include "ppapi/proxy/flash_resource.h"
26 #include "ppapi/proxy/gamepad_resource.h"
27 #include "ppapi/proxy/host_dispatcher.h"
28 #include "ppapi/proxy/isolated_file_system_private_resource.h"
29 #include "ppapi/proxy/message_handler.h"
30 #include "ppapi/proxy/network_proxy_resource.h"
31 #include "ppapi/proxy/pdf_resource.h"
32 #include "ppapi/proxy/plugin_dispatcher.h"
33 #include "ppapi/proxy/ppapi_messages.h"
34 #include "ppapi/proxy/serialized_var.h"
35 #include "ppapi/proxy/truetype_font_singleton_resource.h"
36 #include "ppapi/proxy/uma_private_resource.h"
37 #include "ppapi/shared_impl/ppapi_globals.h"
38 #include "ppapi/shared_impl/ppb_url_util_shared.h"
39 #include "ppapi/shared_impl/ppb_view_shared.h"
40 #include "ppapi/shared_impl/var.h"
41 #include "ppapi/thunk/enter.h"
42 #include "ppapi/thunk/ppb_compositor_api.h"
43 #include "ppapi/thunk/ppb_graphics_2d_api.h"
44 #include "ppapi/thunk/ppb_graphics_3d_api.h"
45 #include "ppapi/thunk/thunk.h"
47 // Windows headers interfere with this file.
48 #ifdef PostMessage
49 #undef PostMessage
50 #endif
52 using ppapi::thunk::EnterInstanceNoLock;
53 using ppapi::thunk::EnterResourceNoLock;
54 using ppapi::thunk::PPB_Compositor_API;
55 using ppapi::thunk::PPB_Graphics2D_API;
56 using ppapi::thunk::PPB_Graphics3D_API;
57 using ppapi::thunk::PPB_Instance_API;
59 namespace ppapi {
60 namespace proxy {
62 namespace {
64 #if !defined(OS_NACL)
65 const char kSerializationError[] = "Failed to convert a PostMessage "
66 "argument from a PP_Var to a Javascript value. It may have cycles or be of "
67 "an unsupported type.";
68 #endif
70 void RequestSurroundingText(PP_Instance instance) {
71 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
72 if (!dispatcher)
73 return; // Instance has gone away while message was pending.
75 InstanceData* data = dispatcher->GetInstanceData(instance);
76 DCHECK(data); // Should have it, since we still have a dispatcher.
77 data->is_request_surrounding_text_pending = false;
78 if (!data->should_do_request_surrounding_text)
79 return;
81 // Just fake out a RequestSurroundingText message to the proxy for the PPP
82 // interface.
83 InterfaceProxy* proxy = dispatcher->GetInterfaceProxy(API_ID_PPP_TEXT_INPUT);
84 if (!proxy)
85 return;
86 proxy->OnMessageReceived(PpapiMsg_PPPTextInput_RequestSurroundingText(
87 API_ID_PPP_TEXT_INPUT, instance,
88 PPB_Instance_Shared::kExtraCharsForTextInput));
91 } // namespace
93 PPB_Instance_Proxy::PPB_Instance_Proxy(Dispatcher* dispatcher)
94 : InterfaceProxy(dispatcher),
95 callback_factory_(this) {
98 PPB_Instance_Proxy::~PPB_Instance_Proxy() {
101 bool PPB_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) {
102 // Prevent the dispatcher from going away during a call to ExecuteScript.
103 // This must happen OUTSIDE of ExecuteScript since the SerializedVars use
104 // the dispatcher upon return of the function (converting the
105 // SerializedVarReturnValue/OutParam to a SerializedVar in the destructor).
106 #if !defined(OS_NACL)
107 ScopedModuleReference death_grip(dispatcher());
108 #endif
110 bool handled = true;
111 IPC_BEGIN_MESSAGE_MAP(PPB_Instance_Proxy, msg)
112 #if !defined(OS_NACL)
113 // Plugin -> Host messages.
114 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetWindowObject,
115 OnHostMsgGetWindowObject)
116 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetOwnerElementObject,
117 OnHostMsgGetOwnerElementObject)
118 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_BindGraphics,
119 OnHostMsgBindGraphics)
120 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_IsFullFrame,
121 OnHostMsgIsFullFrame)
122 IPC_MESSAGE_HANDLER(
123 PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate,
124 OnHostMsgGetAudioHardwareOutputSampleRate)
125 IPC_MESSAGE_HANDLER(
126 PpapiHostMsg_PPBInstance_GetAudioHardwareOutputBufferSize,
127 OnHostMsgGetAudioHardwareOutputBufferSize)
128 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ExecuteScript,
129 OnHostMsgExecuteScript)
130 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDefaultCharSet,
131 OnHostMsgGetDefaultCharSet)
132 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetPluginToHandleFindRequests,
133 OnHostMsgSetPluginToHandleFindRequests);
134 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_NumberOfFindResultsChanged,
135 OnHostMsgNumberOfFindResultsChanged)
136 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SelectFindResultChanged,
137 OnHostMsgSelectFindResultChanged)
138 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetTickmarks,
139 OnHostMsgSetTickmarks)
140 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PostMessage,
141 OnHostMsgPostMessage)
142 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetFullscreen,
143 OnHostMsgSetFullscreen)
144 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetScreenSize,
145 OnHostMsgGetScreenSize)
146 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_RequestInputEvents,
147 OnHostMsgRequestInputEvents)
148 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ClearInputEvents,
149 OnHostMsgClearInputEvents)
150 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_StartTrackingLatency,
151 OnHostMsgStartTrackingLatency)
152 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_LockMouse,
153 OnHostMsgLockMouse)
154 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UnlockMouse,
155 OnHostMsgUnlockMouse)
156 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetCursor,
157 OnHostMsgSetCursor)
158 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetTextInputType,
159 OnHostMsgSetTextInputType)
160 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UpdateCaretPosition,
161 OnHostMsgUpdateCaretPosition)
162 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_CancelCompositionText,
163 OnHostMsgCancelCompositionText)
164 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UpdateSurroundingText,
165 OnHostMsgUpdateSurroundingText)
166 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDocumentURL,
167 OnHostMsgGetDocumentURL)
168 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ResolveRelativeToDocument,
169 OnHostMsgResolveRelativeToDocument)
170 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanRequest,
171 OnHostMsgDocumentCanRequest)
172 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanAccessDocument,
173 OnHostMsgDocumentCanAccessDocument)
174 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginInstanceURL,
175 OnHostMsgGetPluginInstanceURL)
176 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginReferrerURL,
177 OnHostMsgGetPluginReferrerURL)
178 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PromiseResolved,
179 OnHostMsgPromiseResolved)
180 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PromiseResolvedWithSession,
181 OnHostMsgPromiseResolvedWithSession)
182 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PromiseRejected,
183 OnHostMsgPromiseRejected)
184 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionMessage,
185 OnHostMsgSessionMessage)
186 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionReady,
187 OnHostMsgSessionReady)
188 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionClosed,
189 OnHostMsgSessionClosed)
190 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionError,
191 OnHostMsgSessionError)
192 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverBlock,
193 OnHostMsgDeliverBlock)
194 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderInitializeDone,
195 OnHostMsgDecoderInitializeDone)
196 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderDeinitializeDone,
197 OnHostMsgDecoderDeinitializeDone)
198 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderResetDone,
199 OnHostMsgDecoderResetDone)
200 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverFrame,
201 OnHostMsgDeliverFrame)
202 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverSamples,
203 OnHostMsgDeliverSamples)
204 #endif // !defined(OS_NACL)
206 // Host -> Plugin messages.
207 IPC_MESSAGE_HANDLER(PpapiMsg_PPBInstance_MouseLockComplete,
208 OnPluginMsgMouseLockComplete)
210 IPC_MESSAGE_UNHANDLED(handled = false)
211 IPC_END_MESSAGE_MAP()
212 return handled;
215 PP_Bool PPB_Instance_Proxy::BindGraphics(PP_Instance instance,
216 PP_Resource device) {
217 // If device is 0, pass a null HostResource. This signals the host to unbind
218 // all devices.
219 PP_Resource pp_resource = 0;
220 if (device) {
221 Resource* resource =
222 PpapiGlobals::Get()->GetResourceTracker()->GetResource(device);
223 if (!resource || resource->pp_instance() != instance)
224 return PP_FALSE;
225 // We need to pass different resource to Graphics 2D, 3D and Compositor
226 // right now. Once 3D is migrated to the new design, we should be able to
227 // unify this.
228 if (resource->AsPPB_Graphics3D_API()) {
229 pp_resource = resource->host_resource().host_resource();
230 } else if (resource->AsPPB_Graphics2D_API() ||
231 resource->AsPPB_Compositor_API()) {
232 pp_resource = resource->pp_resource();
233 } else {
234 // A bad resource.
235 return PP_FALSE;
238 dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
239 API_ID_PPB_INSTANCE, instance, pp_resource));
240 return PP_TRUE;
243 PP_Bool PPB_Instance_Proxy::IsFullFrame(PP_Instance instance) {
244 PP_Bool result = PP_FALSE;
245 dispatcher()->Send(new PpapiHostMsg_PPBInstance_IsFullFrame(
246 API_ID_PPB_INSTANCE, instance, &result));
247 return result;
250 const ViewData* PPB_Instance_Proxy::GetViewData(PP_Instance instance) {
251 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
252 GetInstanceData(instance);
253 if (!data)
254 return NULL;
255 return &data->view;
258 PP_Bool PPB_Instance_Proxy::FlashIsFullscreen(PP_Instance instance) {
259 // This function is only used for proxying in the renderer process. It is not
260 // implemented in the plugin process.
261 NOTREACHED();
262 return PP_FALSE;
265 PP_Var PPB_Instance_Proxy::GetWindowObject(PP_Instance instance) {
266 ReceiveSerializedVarReturnValue result;
267 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetWindowObject(
268 API_ID_PPB_INSTANCE, instance, &result));
269 return result.Return(dispatcher());
272 PP_Var PPB_Instance_Proxy::GetOwnerElementObject(PP_Instance instance) {
273 ReceiveSerializedVarReturnValue result;
274 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetOwnerElementObject(
275 API_ID_PPB_INSTANCE, instance, &result));
276 return result.Return(dispatcher());
279 PP_Var PPB_Instance_Proxy::ExecuteScript(PP_Instance instance,
280 PP_Var script,
281 PP_Var* exception) {
282 ReceiveSerializedException se(dispatcher(), exception);
283 if (se.IsThrown())
284 return PP_MakeUndefined();
286 ReceiveSerializedVarReturnValue result;
287 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ExecuteScript(
288 API_ID_PPB_INSTANCE, instance,
289 SerializedVarSendInput(dispatcher(), script), &se, &result));
290 return result.Return(dispatcher());
293 uint32_t PPB_Instance_Proxy::GetAudioHardwareOutputSampleRate(
294 PP_Instance instance) {
295 uint32_t result = PP_AUDIOSAMPLERATE_NONE;
296 dispatcher()->Send(
297 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate(
298 API_ID_PPB_INSTANCE, instance, &result));
299 return result;
302 uint32_t PPB_Instance_Proxy::GetAudioHardwareOutputBufferSize(
303 PP_Instance instance) {
304 uint32_t result = 0;
305 dispatcher()->Send(
306 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputBufferSize(
307 API_ID_PPB_INSTANCE, instance, &result));
308 return result;
311 PP_Var PPB_Instance_Proxy::GetDefaultCharSet(PP_Instance instance) {
312 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
313 if (!dispatcher)
314 return PP_MakeUndefined();
316 ReceiveSerializedVarReturnValue result;
317 dispatcher->Send(new PpapiHostMsg_PPBInstance_GetDefaultCharSet(
318 API_ID_PPB_INSTANCE, instance, &result));
319 return result.Return(dispatcher);
322 void PPB_Instance_Proxy::SetPluginToHandleFindRequests(PP_Instance instance) {
323 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetPluginToHandleFindRequests(
324 API_ID_PPB_INSTANCE, instance));
327 void PPB_Instance_Proxy::NumberOfFindResultsChanged(PP_Instance instance,
328 int32_t total,
329 PP_Bool final_result) {
330 dispatcher()->Send(new PpapiHostMsg_PPBInstance_NumberOfFindResultsChanged(
331 API_ID_PPB_INSTANCE, instance, total, final_result));
334 void PPB_Instance_Proxy::SelectedFindResultChanged(PP_Instance instance,
335 int32_t index) {
336 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SelectFindResultChanged(
337 API_ID_PPB_INSTANCE, instance, index));
340 void PPB_Instance_Proxy::SetTickmarks(PP_Instance instance,
341 const PP_Rect* tickmarks,
342 uint32_t count) {
343 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTickmarks(
344 API_ID_PPB_INSTANCE, instance,
345 std::vector<PP_Rect>(tickmarks, tickmarks + count)));
348 PP_Bool PPB_Instance_Proxy::IsFullscreen(PP_Instance instance) {
349 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
350 GetInstanceData(instance);
351 if (!data)
352 return PP_FALSE;
353 return PP_FromBool(data->view.is_fullscreen);
356 PP_Bool PPB_Instance_Proxy::SetFullscreen(PP_Instance instance,
357 PP_Bool fullscreen) {
358 PP_Bool result = PP_FALSE;
359 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetFullscreen(
360 API_ID_PPB_INSTANCE, instance, fullscreen, &result));
361 return result;
364 PP_Bool PPB_Instance_Proxy::GetScreenSize(PP_Instance instance,
365 PP_Size* size) {
366 PP_Bool result = PP_FALSE;
367 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetScreenSize(
368 API_ID_PPB_INSTANCE, instance, &result, size));
369 return result;
372 Resource* PPB_Instance_Proxy::GetSingletonResource(PP_Instance instance,
373 SingletonResourceID id) {
374 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
375 GetInstanceData(instance);
377 InstanceData::SingletonResourceMap::iterator it =
378 data->singleton_resources.find(id);
379 if (it != data->singleton_resources.end())
380 return it->second.get();
382 scoped_refptr<Resource> new_singleton;
383 Connection connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher());
385 switch (id) {
386 case BROKER_SINGLETON_ID:
387 new_singleton = new BrokerResource(connection, instance);
388 break;
389 case FILE_MAPPING_SINGLETON_ID:
390 new_singleton = new FileMappingResource(connection, instance);
391 break;
392 case GAMEPAD_SINGLETON_ID:
393 new_singleton = new GamepadResource(connection, instance);
394 break;
395 case ISOLATED_FILESYSTEM_SINGLETON_ID:
396 new_singleton =
397 new IsolatedFileSystemPrivateResource(connection, instance);
398 break;
399 case NETWORK_PROXY_SINGLETON_ID:
400 new_singleton = new NetworkProxyResource(connection, instance);
401 break;
402 case TRUETYPE_FONT_SINGLETON_ID:
403 new_singleton = new TrueTypeFontSingletonResource(connection, instance);
404 break;
405 case UMA_SINGLETON_ID:
406 new_singleton = new UMAPrivateResource(connection, instance);
407 break;
408 // Flash/trusted resources aren't needed for NaCl.
409 #if !defined(OS_NACL) && !defined(NACL_WIN64)
410 case BROWSER_FONT_SINGLETON_ID:
411 new_singleton = new BrowserFontSingletonResource(connection, instance);
412 break;
413 case FLASH_CLIPBOARD_SINGLETON_ID:
414 new_singleton = new FlashClipboardResource(connection, instance);
415 break;
416 case FLASH_FILE_SINGLETON_ID:
417 new_singleton = new FlashFileResource(connection, instance);
418 break;
419 case FLASH_FULLSCREEN_SINGLETON_ID:
420 new_singleton = new FlashFullscreenResource(connection, instance);
421 break;
422 case FLASH_SINGLETON_ID:
423 new_singleton = new FlashResource(connection, instance,
424 static_cast<PluginDispatcher*>(dispatcher()));
425 break;
426 case PDF_SINGLETON_ID:
427 new_singleton = new PDFResource(connection, instance);
428 break;
429 #else
430 case BROWSER_FONT_SINGLETON_ID:
431 case FLASH_CLIPBOARD_SINGLETON_ID:
432 case FLASH_FILE_SINGLETON_ID:
433 case FLASH_FULLSCREEN_SINGLETON_ID:
434 case FLASH_SINGLETON_ID:
435 case PDF_SINGLETON_ID:
436 NOTREACHED();
437 break;
438 #endif // !defined(OS_NACL) && !defined(NACL_WIN64)
441 if (!new_singleton.get()) {
442 // Getting here implies that a constructor is missing in the above switch.
443 NOTREACHED();
444 return NULL;
447 data->singleton_resources[id] = new_singleton;
448 return new_singleton.get();
451 int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance,
452 uint32_t event_classes) {
453 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
454 API_ID_PPB_INSTANCE, instance, false, event_classes));
456 // We always register for the classes we can handle, this function validates
457 // the flags so we can notify it if anything was invalid, without requiring
458 // a sync reply.
459 return ValidateRequestInputEvents(false, event_classes);
462 int32_t PPB_Instance_Proxy::RequestFilteringInputEvents(
463 PP_Instance instance,
464 uint32_t event_classes) {
465 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
466 API_ID_PPB_INSTANCE, instance, true, event_classes));
468 // We always register for the classes we can handle, this function validates
469 // the flags so we can notify it if anything was invalid, without requiring
470 // a sync reply.
471 return ValidateRequestInputEvents(true, event_classes);
474 void PPB_Instance_Proxy::ClearInputEventRequest(PP_Instance instance,
475 uint32_t event_classes) {
476 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ClearInputEvents(
477 API_ID_PPB_INSTANCE, instance, event_classes));
480 void PPB_Instance_Proxy::StartTrackingLatency(PP_Instance instance) {
481 dispatcher()->Send(new PpapiHostMsg_PPBInstance_StartTrackingLatency(
482 API_ID_PPB_INSTANCE, instance));
485 void PPB_Instance_Proxy::ZoomChanged(PP_Instance instance,
486 double factor) {
487 // Not proxied yet.
488 NOTIMPLEMENTED();
491 void PPB_Instance_Proxy::ZoomLimitsChanged(PP_Instance instance,
492 double minimum_factor,
493 double maximium_factor) {
494 // Not proxied yet.
495 NOTIMPLEMENTED();
498 PP_Var PPB_Instance_Proxy::GetDocumentURL(PP_Instance instance,
499 PP_URLComponents_Dev* components) {
500 ReceiveSerializedVarReturnValue result;
501 PP_URLComponents_Dev url_components = {{0}};
502 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetDocumentURL(
503 API_ID_PPB_INSTANCE, instance, &url_components, &result));
504 if (components)
505 *components = url_components;
506 return result.Return(dispatcher());
509 #if !defined(OS_NACL)
510 PP_Var PPB_Instance_Proxy::ResolveRelativeToDocument(
511 PP_Instance instance,
512 PP_Var relative,
513 PP_URLComponents_Dev* components) {
514 ReceiveSerializedVarReturnValue result;
515 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ResolveRelativeToDocument(
516 API_ID_PPB_INSTANCE, instance,
517 SerializedVarSendInput(dispatcher(), relative),
518 &result));
519 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
520 result.Return(dispatcher()),
521 components);
524 PP_Bool PPB_Instance_Proxy::DocumentCanRequest(PP_Instance instance,
525 PP_Var url) {
526 PP_Bool result = PP_FALSE;
527 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanRequest(
528 API_ID_PPB_INSTANCE, instance,
529 SerializedVarSendInput(dispatcher(), url),
530 &result));
531 return result;
534 PP_Bool PPB_Instance_Proxy::DocumentCanAccessDocument(PP_Instance instance,
535 PP_Instance target) {
536 PP_Bool result = PP_FALSE;
537 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanAccessDocument(
538 API_ID_PPB_INSTANCE, instance, target, &result));
539 return result;
542 PP_Var PPB_Instance_Proxy::GetPluginInstanceURL(
543 PP_Instance instance,
544 PP_URLComponents_Dev* components) {
545 ReceiveSerializedVarReturnValue result;
546 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginInstanceURL(
547 API_ID_PPB_INSTANCE, instance, &result));
548 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
549 result.Return(dispatcher()),
550 components);
553 PP_Var PPB_Instance_Proxy::GetPluginReferrerURL(
554 PP_Instance instance,
555 PP_URLComponents_Dev* components) {
556 ReceiveSerializedVarReturnValue result;
557 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginReferrerURL(
558 API_ID_PPB_INSTANCE, instance, &result));
559 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
560 result.Return(dispatcher()),
561 components);
564 void PPB_Instance_Proxy::PromiseResolved(PP_Instance instance,
565 uint32 promise_id) {
566 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseResolved(
567 API_ID_PPB_INSTANCE, instance, promise_id));
570 void PPB_Instance_Proxy::PromiseResolvedWithSession(PP_Instance instance,
571 uint32 promise_id,
572 PP_Var web_session_id_var) {
573 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseResolvedWithSession(
574 API_ID_PPB_INSTANCE,
575 instance,
576 promise_id,
577 SerializedVarSendInput(dispatcher(), web_session_id_var)));
580 void PPB_Instance_Proxy::PromiseRejected(PP_Instance instance,
581 uint32 promise_id,
582 PP_CdmExceptionCode exception_code,
583 uint32 system_code,
584 PP_Var error_description_var) {
585 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseRejected(
586 API_ID_PPB_INSTANCE,
587 instance,
588 promise_id,
589 exception_code,
590 system_code,
591 SerializedVarSendInput(dispatcher(), error_description_var)));
594 void PPB_Instance_Proxy::SessionMessage(PP_Instance instance,
595 PP_Var web_session_id_var,
596 PP_Var message_var,
597 PP_Var destination_url_var) {
598 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionMessage(
599 API_ID_PPB_INSTANCE,
600 instance,
601 SerializedVarSendInput(dispatcher(), web_session_id_var),
602 SerializedVarSendInput(dispatcher(), message_var),
603 SerializedVarSendInput(dispatcher(), destination_url_var)));
606 void PPB_Instance_Proxy::SessionReady(PP_Instance instance,
607 PP_Var web_session_id_var) {
608 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionReady(
609 API_ID_PPB_INSTANCE,
610 instance,
611 SerializedVarSendInput(dispatcher(), web_session_id_var)));
614 void PPB_Instance_Proxy::SessionClosed(PP_Instance instance,
615 PP_Var web_session_id_var) {
616 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionClosed(
617 API_ID_PPB_INSTANCE,
618 instance,
619 SerializedVarSendInput(dispatcher(), web_session_id_var)));
622 void PPB_Instance_Proxy::SessionError(PP_Instance instance,
623 PP_Var web_session_id_var,
624 PP_CdmExceptionCode exception_code,
625 uint32 system_code,
626 PP_Var error_description_var) {
627 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionError(
628 API_ID_PPB_INSTANCE,
629 instance,
630 SerializedVarSendInput(dispatcher(), web_session_id_var),
631 exception_code,
632 system_code,
633 SerializedVarSendInput(dispatcher(), error_description_var)));
636 void PPB_Instance_Proxy::DeliverBlock(PP_Instance instance,
637 PP_Resource decrypted_block,
638 const PP_DecryptedBlockInfo* block_info) {
639 PP_Resource decrypted_block_host_resource = 0;
641 if (decrypted_block) {
642 Resource* object =
643 PpapiGlobals::Get()->GetResourceTracker()->GetResource(decrypted_block);
644 if (!object || object->pp_instance() != instance) {
645 NOTREACHED();
646 return;
648 decrypted_block_host_resource = object->host_resource().host_resource();
651 std::string serialized_block_info;
652 if (!SerializeBlockInfo(*block_info, &serialized_block_info)) {
653 NOTREACHED();
654 return;
657 dispatcher()->Send(
658 new PpapiHostMsg_PPBInstance_DeliverBlock(API_ID_PPB_INSTANCE,
659 instance,
660 decrypted_block_host_resource,
661 serialized_block_info));
664 void PPB_Instance_Proxy::DecoderInitializeDone(
665 PP_Instance instance,
666 PP_DecryptorStreamType decoder_type,
667 uint32_t request_id,
668 PP_Bool success) {
669 dispatcher()->Send(
670 new PpapiHostMsg_PPBInstance_DecoderInitializeDone(
671 API_ID_PPB_INSTANCE,
672 instance,
673 decoder_type,
674 request_id,
675 success));
678 void PPB_Instance_Proxy::DecoderDeinitializeDone(
679 PP_Instance instance,
680 PP_DecryptorStreamType decoder_type,
681 uint32_t request_id) {
682 dispatcher()->Send(
683 new PpapiHostMsg_PPBInstance_DecoderDeinitializeDone(
684 API_ID_PPB_INSTANCE,
685 instance,
686 decoder_type,
687 request_id));
690 void PPB_Instance_Proxy::DecoderResetDone(PP_Instance instance,
691 PP_DecryptorStreamType decoder_type,
692 uint32_t request_id) {
693 dispatcher()->Send(
694 new PpapiHostMsg_PPBInstance_DecoderResetDone(
695 API_ID_PPB_INSTANCE,
696 instance,
697 decoder_type,
698 request_id));
701 void PPB_Instance_Proxy::DeliverFrame(PP_Instance instance,
702 PP_Resource decrypted_frame,
703 const PP_DecryptedFrameInfo* frame_info) {
704 PP_Resource host_resource = 0;
705 if (decrypted_frame != 0) {
706 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
707 Resource* object = tracker->GetResource(decrypted_frame);
709 if (!object || object->pp_instance() != instance) {
710 NOTREACHED();
711 return;
714 host_resource = object->host_resource().host_resource();
717 std::string serialized_frame_info;
718 if (!SerializeBlockInfo(*frame_info, &serialized_frame_info)) {
719 NOTREACHED();
720 return;
723 dispatcher()->Send(
724 new PpapiHostMsg_PPBInstance_DeliverFrame(API_ID_PPB_INSTANCE,
725 instance,
726 host_resource,
727 serialized_frame_info));
730 void PPB_Instance_Proxy::DeliverSamples(
731 PP_Instance instance,
732 PP_Resource decrypted_samples,
733 const PP_DecryptedSampleInfo* sample_info) {
734 PP_Resource host_resource = 0;
735 if (decrypted_samples != 0) {
736 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
737 Resource* object = tracker->GetResource(decrypted_samples);
739 if (!object || object->pp_instance() != instance) {
740 NOTREACHED();
741 return;
744 host_resource = object->host_resource().host_resource();
747 std::string serialized_sample_info;
748 if (!SerializeBlockInfo(*sample_info, &serialized_sample_info)) {
749 NOTREACHED();
750 return;
753 dispatcher()->Send(
754 new PpapiHostMsg_PPBInstance_DeliverSamples(API_ID_PPB_INSTANCE,
755 instance,
756 host_resource,
757 serialized_sample_info));
759 #endif // !defined(OS_NACL)
761 void PPB_Instance_Proxy::PostMessage(PP_Instance instance,
762 PP_Var message) {
763 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage(
764 API_ID_PPB_INSTANCE,
765 instance, SerializedVarSendInputShmem(dispatcher(), message,
766 instance)));
769 int32_t PPB_Instance_Proxy::RegisterMessageHandler(
770 PP_Instance instance,
771 void* user_data,
772 const PPP_MessageHandler_0_1* handler,
773 PP_Resource message_loop) {
774 InstanceData* data =
775 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
776 if (!data)
777 return PP_ERROR_BADARGUMENT;
779 int32_t result = PP_ERROR_FAILED;
780 scoped_ptr<MessageHandler> message_handler = MessageHandler::Create(
781 instance, handler, user_data, message_loop, &result);
782 if (message_handler)
783 data->message_handler = message_handler.Pass();
784 return result;
787 void PPB_Instance_Proxy::UnregisterMessageHandler(PP_Instance instance) {
788 InstanceData* data =
789 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
790 if (!data)
791 return;
792 data->message_handler.reset();
795 PP_Bool PPB_Instance_Proxy::SetCursor(PP_Instance instance,
796 PP_MouseCursor_Type type,
797 PP_Resource image,
798 const PP_Point* hot_spot) {
799 // Some of these parameters are important for security. This check is in the
800 // plugin process just for the convenience of the caller (since we don't
801 // bother returning errors from the other process with a sync message). The
802 // parameters will be validated again in the renderer.
803 if (!ValidateSetCursorParams(type, image, hot_spot))
804 return PP_FALSE;
806 HostResource image_host_resource;
807 if (image) {
808 Resource* cursor_image =
809 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image);
810 if (!cursor_image || cursor_image->pp_instance() != instance)
811 return PP_FALSE;
812 image_host_resource = cursor_image->host_resource();
815 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetCursor(
816 API_ID_PPB_INSTANCE, instance, static_cast<int32_t>(type),
817 image_host_resource, hot_spot ? *hot_spot : PP_MakePoint(0, 0)));
818 return PP_TRUE;
821 int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance,
822 scoped_refptr<TrackedCallback> callback) {
823 // Save the mouse callback on the instance data.
824 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
825 GetInstanceData(instance);
826 if (!data)
827 return PP_ERROR_BADARGUMENT;
828 if (TrackedCallback::IsPending(data->mouse_lock_callback))
829 return PP_ERROR_INPROGRESS; // Already have a pending callback.
830 data->mouse_lock_callback = callback;
832 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LockMouse(
833 API_ID_PPB_INSTANCE, instance));
834 return PP_OK_COMPLETIONPENDING;
837 void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance) {
838 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UnlockMouse(
839 API_ID_PPB_INSTANCE, instance));
842 void PPB_Instance_Proxy::SetTextInputType(PP_Instance instance,
843 PP_TextInput_Type type) {
844 CancelAnyPendingRequestSurroundingText(instance);
845 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTextInputType(
846 API_ID_PPB_INSTANCE, instance, type));
849 void PPB_Instance_Proxy::UpdateCaretPosition(PP_Instance instance,
850 const PP_Rect& caret,
851 const PP_Rect& bounding_box) {
852 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateCaretPosition(
853 API_ID_PPB_INSTANCE, instance, caret, bounding_box));
856 void PPB_Instance_Proxy::CancelCompositionText(PP_Instance instance) {
857 CancelAnyPendingRequestSurroundingText(instance);
858 dispatcher()->Send(new PpapiHostMsg_PPBInstance_CancelCompositionText(
859 API_ID_PPB_INSTANCE, instance));
862 void PPB_Instance_Proxy::SelectionChanged(PP_Instance instance) {
863 // The "right" way to do this is to send the message to the host. However,
864 // all it will do is call RequestSurroundingText with a hardcoded number of
865 // characters in response, which is an entire IPC round-trip.
867 // We can avoid this round-trip by just implementing the
868 // RequestSurroundingText logic in the plugin process. If the logic in the
869 // host becomes more complex (like a more adaptive number of characters),
870 // we'll need to reevanuate whether we want to do the round trip instead.
872 // Be careful to post a task to avoid reentering the plugin.
874 InstanceData* data =
875 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
876 if (!data)
877 return;
878 data->should_do_request_surrounding_text = true;
880 if (!data->is_request_surrounding_text_pending) {
881 base::MessageLoop::current()->PostTask(
882 FROM_HERE,
883 RunWhileLocked(base::Bind(&RequestSurroundingText, instance)));
884 data->is_request_surrounding_text_pending = true;
888 void PPB_Instance_Proxy::UpdateSurroundingText(PP_Instance instance,
889 const char* text,
890 uint32_t caret,
891 uint32_t anchor) {
892 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateSurroundingText(
893 API_ID_PPB_INSTANCE, instance, text, caret, anchor));
896 #if !defined(OS_NACL)
897 void PPB_Instance_Proxy::OnHostMsgGetWindowObject(
898 PP_Instance instance,
899 SerializedVarReturnValue result) {
900 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
901 return;
902 EnterInstanceNoLock enter(instance);
903 if (enter.succeeded())
904 result.Return(dispatcher(), enter.functions()->GetWindowObject(instance));
907 void PPB_Instance_Proxy::OnHostMsgGetOwnerElementObject(
908 PP_Instance instance,
909 SerializedVarReturnValue result) {
910 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
911 return;
912 EnterInstanceNoLock enter(instance);
913 if (enter.succeeded()) {
914 result.Return(dispatcher(),
915 enter.functions()->GetOwnerElementObject(instance));
919 void PPB_Instance_Proxy::OnHostMsgBindGraphics(PP_Instance instance,
920 PP_Resource device) {
921 // Note that we ignroe the return value here. Otherwise, this would need to
922 // be a slow sync call, and the plugin side of the proxy will have already
923 // validated the resources, so we shouldn't see errors here that weren't
924 // already caught.
925 EnterInstanceNoLock enter(instance);
926 if (enter.succeeded())
927 enter.functions()->BindGraphics(instance, device);
930 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputSampleRate(
931 PP_Instance instance, uint32_t* result) {
932 EnterInstanceNoLock enter(instance);
933 if (enter.succeeded())
934 *result = enter.functions()->GetAudioHardwareOutputSampleRate(instance);
937 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputBufferSize(
938 PP_Instance instance, uint32_t* result) {
939 EnterInstanceNoLock enter(instance);
940 if (enter.succeeded())
941 *result = enter.functions()->GetAudioHardwareOutputBufferSize(instance);
944 void PPB_Instance_Proxy::OnHostMsgIsFullFrame(PP_Instance instance,
945 PP_Bool* result) {
946 EnterInstanceNoLock enter(instance);
947 if (enter.succeeded())
948 *result = enter.functions()->IsFullFrame(instance);
951 void PPB_Instance_Proxy::OnHostMsgExecuteScript(
952 PP_Instance instance,
953 SerializedVarReceiveInput script,
954 SerializedVarOutParam out_exception,
955 SerializedVarReturnValue result) {
956 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
957 return;
958 EnterInstanceNoLock enter(instance);
959 if (enter.failed())
960 return;
962 if (dispatcher()->IsPlugin())
963 NOTREACHED();
964 else
965 static_cast<HostDispatcher*>(dispatcher())->set_allow_plugin_reentrancy();
967 result.Return(dispatcher(), enter.functions()->ExecuteScript(
968 instance,
969 script.Get(dispatcher()),
970 out_exception.OutParam(dispatcher())));
973 void PPB_Instance_Proxy::OnHostMsgGetDefaultCharSet(
974 PP_Instance instance,
975 SerializedVarReturnValue result) {
976 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
977 return;
978 EnterInstanceNoLock enter(instance);
979 if (enter.succeeded())
980 result.Return(dispatcher(), enter.functions()->GetDefaultCharSet(instance));
983 void PPB_Instance_Proxy::OnHostMsgSetPluginToHandleFindRequests(
984 PP_Instance instance) {
985 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
986 return;
987 EnterInstanceNoLock enter(instance);
988 if (enter.succeeded())
989 enter.functions()->SetPluginToHandleFindRequests(instance);
992 void PPB_Instance_Proxy::OnHostMsgNumberOfFindResultsChanged(
993 PP_Instance instance,
994 int32_t total,
995 PP_Bool final_result) {
996 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
997 return;
998 EnterInstanceNoLock enter(instance);
999 if (enter.succeeded()) {
1000 enter.functions()->NumberOfFindResultsChanged(
1001 instance, total, final_result);
1005 void PPB_Instance_Proxy::OnHostMsgSelectFindResultChanged(
1006 PP_Instance instance,
1007 int32_t index) {
1008 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1009 return;
1010 EnterInstanceNoLock enter(instance);
1011 if (enter.succeeded())
1012 enter.functions()->SelectedFindResultChanged(instance, index);
1015 void PPB_Instance_Proxy::OnHostMsgSetTickmarks(
1016 PP_Instance instance,
1017 const std::vector<PP_Rect>& tickmarks) {
1018 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1019 return;
1020 const PP_Rect* array = tickmarks.empty() ? NULL : &tickmarks[0];
1021 EnterInstanceNoLock enter(instance);
1022 if (enter.succeeded()) {
1023 enter.functions()->SetTickmarks(instance,
1024 array,
1025 static_cast<uint32_t>(tickmarks.size()));
1029 void PPB_Instance_Proxy::OnHostMsgSetFullscreen(PP_Instance instance,
1030 PP_Bool fullscreen,
1031 PP_Bool* result) {
1032 EnterInstanceNoLock enter(instance);
1033 if (enter.succeeded())
1034 *result = enter.functions()->SetFullscreen(instance, fullscreen);
1038 void PPB_Instance_Proxy::OnHostMsgGetScreenSize(PP_Instance instance,
1039 PP_Bool* result,
1040 PP_Size* size) {
1041 EnterInstanceNoLock enter(instance);
1042 if (enter.succeeded())
1043 *result = enter.functions()->GetScreenSize(instance, size);
1046 void PPB_Instance_Proxy::OnHostMsgRequestInputEvents(PP_Instance instance,
1047 bool is_filtering,
1048 uint32_t event_classes) {
1049 EnterInstanceNoLock enter(instance);
1050 if (enter.succeeded()) {
1051 if (is_filtering)
1052 enter.functions()->RequestFilteringInputEvents(instance, event_classes);
1053 else
1054 enter.functions()->RequestInputEvents(instance, event_classes);
1058 void PPB_Instance_Proxy::OnHostMsgClearInputEvents(PP_Instance instance,
1059 uint32_t event_classes) {
1060 EnterInstanceNoLock enter(instance);
1061 if (enter.succeeded())
1062 enter.functions()->ClearInputEventRequest(instance, event_classes);
1065 void PPB_Instance_Proxy::OnHostMsgStartTrackingLatency(PP_Instance instance) {
1066 EnterInstanceNoLock enter(instance);
1067 if (enter.succeeded())
1068 enter.functions()->StartTrackingLatency(instance);
1071 void PPB_Instance_Proxy::OnHostMsgPostMessage(
1072 PP_Instance instance,
1073 SerializedVarReceiveInput message) {
1074 EnterInstanceNoLock enter(instance);
1075 if (!message.is_valid_var()) {
1076 PpapiGlobals::Get()->LogWithSource(
1077 instance, PP_LOGLEVEL_ERROR, std::string(), kSerializationError);
1078 return;
1081 if (enter.succeeded())
1082 enter.functions()->PostMessage(instance,
1083 message.GetForInstance(dispatcher(),
1084 instance));
1087 void PPB_Instance_Proxy::OnHostMsgLockMouse(PP_Instance instance) {
1088 // Need to be careful to always issue the callback.
1089 pp::CompletionCallback cb = callback_factory_.NewCallback(
1090 &PPB_Instance_Proxy::MouseLockCompleteInHost, instance);
1092 EnterInstanceNoLock enter(instance, cb.pp_completion_callback());
1093 if (enter.succeeded())
1094 enter.SetResult(enter.functions()->LockMouse(instance, enter.callback()));
1097 void PPB_Instance_Proxy::OnHostMsgUnlockMouse(PP_Instance instance) {
1098 EnterInstanceNoLock enter(instance);
1099 if (enter.succeeded())
1100 enter.functions()->UnlockMouse(instance);
1103 void PPB_Instance_Proxy::OnHostMsgGetDocumentURL(
1104 PP_Instance instance,
1105 PP_URLComponents_Dev* components,
1106 SerializedVarReturnValue result) {
1107 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1108 return;
1109 EnterInstanceNoLock enter(instance);
1110 if (enter.succeeded()) {
1111 PP_Var document_url = enter.functions()->GetDocumentURL(instance,
1112 components);
1113 result.Return(dispatcher(), document_url);
1117 void PPB_Instance_Proxy::OnHostMsgResolveRelativeToDocument(
1118 PP_Instance instance,
1119 SerializedVarReceiveInput relative,
1120 SerializedVarReturnValue result) {
1121 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1122 return;
1123 EnterInstanceNoLock enter(instance);
1124 if (enter.succeeded()) {
1125 result.Return(dispatcher(),
1126 enter.functions()->ResolveRelativeToDocument(
1127 instance, relative.Get(dispatcher()), NULL));
1131 void PPB_Instance_Proxy::OnHostMsgDocumentCanRequest(
1132 PP_Instance instance,
1133 SerializedVarReceiveInput url,
1134 PP_Bool* result) {
1135 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1136 return;
1137 EnterInstanceNoLock enter(instance);
1138 if (enter.succeeded()) {
1139 *result = enter.functions()->DocumentCanRequest(instance,
1140 url.Get(dispatcher()));
1144 void PPB_Instance_Proxy::OnHostMsgDocumentCanAccessDocument(PP_Instance active,
1145 PP_Instance target,
1146 PP_Bool* result) {
1147 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1148 return;
1149 EnterInstanceNoLock enter(active);
1150 if (enter.succeeded())
1151 *result = enter.functions()->DocumentCanAccessDocument(active, target);
1154 void PPB_Instance_Proxy::OnHostMsgGetPluginInstanceURL(
1155 PP_Instance instance,
1156 SerializedVarReturnValue result) {
1157 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1158 return;
1159 EnterInstanceNoLock enter(instance);
1160 if (enter.succeeded()) {
1161 result.Return(dispatcher(),
1162 enter.functions()->GetPluginInstanceURL(instance, NULL));
1166 void PPB_Instance_Proxy::OnHostMsgGetPluginReferrerURL(
1167 PP_Instance instance,
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()->GetPluginReferrerURL(instance, NULL));
1178 void PPB_Instance_Proxy::OnHostMsgPromiseResolved(PP_Instance instance,
1179 uint32_t promise_id) {
1180 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1181 return;
1182 EnterInstanceNoLock enter(instance);
1183 if (enter.succeeded()) {
1184 enter.functions()->PromiseResolved(instance, promise_id);
1188 void PPB_Instance_Proxy::OnHostMsgPromiseResolvedWithSession(
1189 PP_Instance instance,
1190 uint32_t promise_id,
1191 SerializedVarReceiveInput web_session_id) {
1192 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1193 return;
1194 EnterInstanceNoLock enter(instance);
1195 if (enter.succeeded()) {
1196 enter.functions()->PromiseResolvedWithSession(
1197 instance, promise_id, web_session_id.Get(dispatcher()));
1201 void PPB_Instance_Proxy::OnHostMsgPromiseRejected(
1202 PP_Instance instance,
1203 uint32_t promise_id,
1204 PP_CdmExceptionCode exception_code,
1205 uint32_t system_code,
1206 SerializedVarReceiveInput error_description) {
1207 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1208 return;
1209 EnterInstanceNoLock enter(instance);
1210 if (enter.succeeded()) {
1211 enter.functions()->PromiseRejected(instance,
1212 promise_id,
1213 exception_code,
1214 system_code,
1215 error_description.Get(dispatcher()));
1219 void PPB_Instance_Proxy::OnHostMsgSessionMessage(
1220 PP_Instance instance,
1221 SerializedVarReceiveInput web_session_id,
1222 SerializedVarReceiveInput message,
1223 SerializedVarReceiveInput destination_url) {
1224 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1225 return;
1226 EnterInstanceNoLock enter(instance);
1227 if (enter.succeeded()) {
1228 enter.functions()->SessionMessage(instance,
1229 web_session_id.Get(dispatcher()),
1230 message.Get(dispatcher()),
1231 destination_url.Get(dispatcher()));
1235 void PPB_Instance_Proxy::OnHostMsgSessionReady(
1236 PP_Instance instance,
1237 SerializedVarReceiveInput web_session_id) {
1238 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1239 return;
1240 EnterInstanceNoLock enter(instance);
1241 if (enter.succeeded()) {
1242 enter.functions()->SessionReady(instance, web_session_id.Get(dispatcher()));
1246 void PPB_Instance_Proxy::OnHostMsgSessionClosed(
1247 PP_Instance instance,
1248 SerializedVarReceiveInput web_session_id) {
1249 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1250 return;
1251 EnterInstanceNoLock enter(instance);
1252 if (enter.succeeded()) {
1253 enter.functions()->SessionClosed(instance,
1254 web_session_id.Get(dispatcher()));
1258 void PPB_Instance_Proxy::OnHostMsgSessionError(
1259 PP_Instance instance,
1260 SerializedVarReceiveInput web_session_id,
1261 PP_CdmExceptionCode exception_code,
1262 uint32_t system_code,
1263 SerializedVarReceiveInput error_description) {
1264 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1265 return;
1266 EnterInstanceNoLock enter(instance);
1267 if (enter.succeeded()) {
1268 enter.functions()->SessionError(instance,
1269 web_session_id.Get(dispatcher()),
1270 exception_code,
1271 system_code,
1272 error_description.Get(dispatcher()));
1276 void PPB_Instance_Proxy::OnHostMsgDeliverBlock(
1277 PP_Instance instance,
1278 PP_Resource decrypted_block,
1279 const std::string& serialized_block_info) {
1280 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1281 return;
1282 PP_DecryptedBlockInfo block_info;
1283 if (!DeserializeBlockInfo(serialized_block_info, &block_info))
1284 return;
1286 EnterInstanceNoLock enter(instance);
1287 if (enter.succeeded())
1288 enter.functions()->DeliverBlock(instance, decrypted_block, &block_info);
1291 void PPB_Instance_Proxy::OnHostMsgDecoderInitializeDone(
1292 PP_Instance instance,
1293 PP_DecryptorStreamType decoder_type,
1294 uint32_t request_id,
1295 PP_Bool success) {
1296 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1297 return;
1298 EnterInstanceNoLock enter(instance);
1299 if (enter.succeeded()) {
1300 enter.functions()->DecoderInitializeDone(instance,
1301 decoder_type,
1302 request_id,
1303 success);
1307 void PPB_Instance_Proxy::OnHostMsgDecoderDeinitializeDone(
1308 PP_Instance instance,
1309 PP_DecryptorStreamType decoder_type,
1310 uint32_t request_id) {
1311 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1312 return;
1313 EnterInstanceNoLock enter(instance);
1314 if (enter.succeeded())
1315 enter.functions()->DecoderDeinitializeDone(instance,
1316 decoder_type,
1317 request_id);
1320 void PPB_Instance_Proxy::OnHostMsgDecoderResetDone(
1321 PP_Instance instance,
1322 PP_DecryptorStreamType decoder_type,
1323 uint32_t request_id) {
1324 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1325 return;
1326 EnterInstanceNoLock enter(instance);
1327 if (enter.succeeded())
1328 enter.functions()->DecoderResetDone(instance, decoder_type, request_id);
1331 void PPB_Instance_Proxy::OnHostMsgDeliverFrame(
1332 PP_Instance instance,
1333 PP_Resource decrypted_frame,
1334 const std::string& serialized_frame_info) {
1335 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1336 return;
1337 PP_DecryptedFrameInfo frame_info;
1338 if (!DeserializeBlockInfo(serialized_frame_info, &frame_info))
1339 return;
1341 EnterInstanceNoLock enter(instance);
1342 if (enter.succeeded())
1343 enter.functions()->DeliverFrame(instance, decrypted_frame, &frame_info);
1346 void PPB_Instance_Proxy::OnHostMsgDeliverSamples(
1347 PP_Instance instance,
1348 PP_Resource audio_frames,
1349 const std::string& serialized_sample_info) {
1350 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1351 return;
1352 PP_DecryptedSampleInfo sample_info;
1353 if (!DeserializeBlockInfo(serialized_sample_info, &sample_info))
1354 return;
1356 EnterInstanceNoLock enter(instance);
1357 if (enter.succeeded())
1358 enter.functions()->DeliverSamples(instance, audio_frames, &sample_info);
1361 void PPB_Instance_Proxy::OnHostMsgSetCursor(
1362 PP_Instance instance,
1363 int32_t type,
1364 const ppapi::HostResource& custom_image,
1365 const PP_Point& hot_spot) {
1366 // This API serves PPB_CursorControl_Dev and PPB_MouseCursor, so is public.
1367 EnterInstanceNoLock enter(instance);
1368 if (enter.succeeded()) {
1369 enter.functions()->SetCursor(
1370 instance, static_cast<PP_MouseCursor_Type>(type),
1371 custom_image.host_resource(), &hot_spot);
1375 void PPB_Instance_Proxy::OnHostMsgSetTextInputType(PP_Instance instance,
1376 PP_TextInput_Type type) {
1377 EnterInstanceNoLock enter(instance);
1378 if (enter.succeeded())
1379 enter.functions()->SetTextInputType(instance, type);
1382 void PPB_Instance_Proxy::OnHostMsgUpdateCaretPosition(
1383 PP_Instance instance,
1384 const PP_Rect& caret,
1385 const PP_Rect& bounding_box) {
1386 EnterInstanceNoLock enter(instance);
1387 if (enter.succeeded())
1388 enter.functions()->UpdateCaretPosition(instance, caret, bounding_box);
1391 void PPB_Instance_Proxy::OnHostMsgCancelCompositionText(PP_Instance instance) {
1392 EnterInstanceNoLock enter(instance);
1393 if (enter.succeeded())
1394 enter.functions()->CancelCompositionText(instance);
1397 void PPB_Instance_Proxy::OnHostMsgUpdateSurroundingText(
1398 PP_Instance instance,
1399 const std::string& text,
1400 uint32_t caret,
1401 uint32_t anchor) {
1402 EnterInstanceNoLock enter(instance);
1403 if (enter.succeeded()) {
1404 enter.functions()->UpdateSurroundingText(instance, text.c_str(), caret,
1405 anchor);
1408 #endif // !defined(OS_NACL)
1410 void PPB_Instance_Proxy::OnPluginMsgMouseLockComplete(PP_Instance instance,
1411 int32_t result) {
1412 if (!dispatcher()->IsPlugin())
1413 return;
1415 // Save the mouse callback on the instance data.
1416 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1417 GetInstanceData(instance);
1418 if (!data)
1419 return; // Instance was probably deleted.
1420 if (!TrackedCallback::IsPending(data->mouse_lock_callback)) {
1421 NOTREACHED();
1422 return;
1424 data->mouse_lock_callback->Run(result);
1427 #if !defined(OS_NACL)
1428 void PPB_Instance_Proxy::MouseLockCompleteInHost(int32_t result,
1429 PP_Instance instance) {
1430 dispatcher()->Send(new PpapiMsg_PPBInstance_MouseLockComplete(
1431 API_ID_PPB_INSTANCE, instance, result));
1433 #endif // !defined(OS_NACL)
1435 void PPB_Instance_Proxy::CancelAnyPendingRequestSurroundingText(
1436 PP_Instance instance) {
1437 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1438 GetInstanceData(instance);
1439 if (!data)
1440 return; // Instance was probably deleted.
1441 data->should_do_request_surrounding_text = false;
1444 } // namespace proxy
1445 } // namespace ppapi