Elim cr-checkbox
[chromium-blink-merge.git] / ppapi / proxy / ppb_instance_proxy.cc
blob8ccee5dac5de1db9a305d8c9924b5c6ac75c3080
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/proxy/ppb_instance_proxy.h"
7 #include "base/memory/ref_counted.h"
8 #include "base/numerics/safe_conversions.h"
9 #include "base/stl_util.h"
10 #include "build/build_config.h"
11 #include "media/base/limits.h"
12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/c/pp_time.h"
14 #include "ppapi/c/pp_var.h"
15 #include "ppapi/c/ppb_audio_config.h"
16 #include "ppapi/c/ppb_instance.h"
17 #include "ppapi/c/ppb_messaging.h"
18 #include "ppapi/c/ppb_mouse_lock.h"
19 #include "ppapi/c/private/pp_content_decryptor.h"
20 #include "ppapi/proxy/broker_resource.h"
21 #include "ppapi/proxy/browser_font_singleton_resource.h"
22 #include "ppapi/proxy/content_decryptor_private_serializer.h"
23 #include "ppapi/proxy/enter_proxy.h"
24 #include "ppapi/proxy/flash_clipboard_resource.h"
25 #include "ppapi/proxy/flash_file_resource.h"
26 #include "ppapi/proxy/flash_fullscreen_resource.h"
27 #include "ppapi/proxy/flash_resource.h"
28 #include "ppapi/proxy/gamepad_resource.h"
29 #include "ppapi/proxy/host_dispatcher.h"
30 #include "ppapi/proxy/isolated_file_system_private_resource.h"
31 #include "ppapi/proxy/message_handler.h"
32 #include "ppapi/proxy/network_proxy_resource.h"
33 #include "ppapi/proxy/pdf_resource.h"
34 #include "ppapi/proxy/plugin_dispatcher.h"
35 #include "ppapi/proxy/ppapi_messages.h"
36 #include "ppapi/proxy/serialized_var.h"
37 #include "ppapi/proxy/truetype_font_singleton_resource.h"
38 #include "ppapi/proxy/uma_private_resource.h"
39 #include "ppapi/shared_impl/array_var.h"
40 #include "ppapi/shared_impl/ppapi_globals.h"
41 #include "ppapi/shared_impl/ppb_url_util_shared.h"
42 #include "ppapi/shared_impl/ppb_view_shared.h"
43 #include "ppapi/shared_impl/scoped_pp_var.h"
44 #include "ppapi/shared_impl/var.h"
45 #include "ppapi/thunk/enter.h"
46 #include "ppapi/thunk/ppb_compositor_api.h"
47 #include "ppapi/thunk/ppb_graphics_2d_api.h"
48 #include "ppapi/thunk/ppb_graphics_3d_api.h"
49 #include "ppapi/thunk/thunk.h"
51 // Windows headers interfere with this file.
52 #ifdef PostMessage
53 #undef PostMessage
54 #endif
56 using ppapi::thunk::EnterInstanceNoLock;
57 using ppapi::thunk::EnterResourceNoLock;
58 using ppapi::thunk::PPB_Compositor_API;
59 using ppapi::thunk::PPB_Graphics2D_API;
60 using ppapi::thunk::PPB_Graphics3D_API;
61 using ppapi::thunk::PPB_Instance_API;
63 namespace ppapi {
64 namespace proxy {
66 namespace {
68 #if !defined(OS_NACL)
69 const char kSerializationError[] = "Failed to convert a PostMessage "
70 "argument from a PP_Var to a Javascript value. It may have cycles or be of "
71 "an unsupported type.";
72 #endif
74 void RequestSurroundingText(PP_Instance instance) {
75 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
76 if (!dispatcher)
77 return; // Instance has gone away while message was pending.
79 InstanceData* data = dispatcher->GetInstanceData(instance);
80 DCHECK(data); // Should have it, since we still have a dispatcher.
81 data->is_request_surrounding_text_pending = false;
82 if (!data->should_do_request_surrounding_text)
83 return;
85 // Just fake out a RequestSurroundingText message to the proxy for the PPP
86 // interface.
87 InterfaceProxy* proxy = dispatcher->GetInterfaceProxy(API_ID_PPP_TEXT_INPUT);
88 if (!proxy)
89 return;
90 proxy->OnMessageReceived(PpapiMsg_PPPTextInput_RequestSurroundingText(
91 API_ID_PPP_TEXT_INPUT, instance,
92 PPB_Instance_Shared::kExtraCharsForTextInput));
95 } // namespace
97 PPB_Instance_Proxy::PPB_Instance_Proxy(Dispatcher* dispatcher)
98 : InterfaceProxy(dispatcher),
99 callback_factory_(this) {
102 PPB_Instance_Proxy::~PPB_Instance_Proxy() {
105 bool PPB_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) {
106 // Prevent the dispatcher from going away during a call to ExecuteScript.
107 // This must happen OUTSIDE of ExecuteScript since the SerializedVars use
108 // the dispatcher upon return of the function (converting the
109 // SerializedVarReturnValue/OutParam to a SerializedVar in the destructor).
110 #if !defined(OS_NACL)
111 ScopedModuleReference death_grip(dispatcher());
112 #endif
114 bool handled = true;
115 IPC_BEGIN_MESSAGE_MAP(PPB_Instance_Proxy, msg)
116 #if !defined(OS_NACL)
117 // Plugin -> Host messages.
118 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetWindowObject,
119 OnHostMsgGetWindowObject)
120 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetOwnerElementObject,
121 OnHostMsgGetOwnerElementObject)
122 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_BindGraphics,
123 OnHostMsgBindGraphics)
124 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_IsFullFrame,
125 OnHostMsgIsFullFrame)
126 IPC_MESSAGE_HANDLER(
127 PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate,
128 OnHostMsgGetAudioHardwareOutputSampleRate)
129 IPC_MESSAGE_HANDLER(
130 PpapiHostMsg_PPBInstance_GetAudioHardwareOutputBufferSize,
131 OnHostMsgGetAudioHardwareOutputBufferSize)
132 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ExecuteScript,
133 OnHostMsgExecuteScript)
134 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDefaultCharSet,
135 OnHostMsgGetDefaultCharSet)
136 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetPluginToHandleFindRequests,
137 OnHostMsgSetPluginToHandleFindRequests);
138 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_NumberOfFindResultsChanged,
139 OnHostMsgNumberOfFindResultsChanged)
140 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SelectFindResultChanged,
141 OnHostMsgSelectFindResultChanged)
142 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetTickmarks,
143 OnHostMsgSetTickmarks)
144 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PostMessage,
145 OnHostMsgPostMessage)
146 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetFullscreen,
147 OnHostMsgSetFullscreen)
148 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetScreenSize,
149 OnHostMsgGetScreenSize)
150 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_RequestInputEvents,
151 OnHostMsgRequestInputEvents)
152 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ClearInputEvents,
153 OnHostMsgClearInputEvents)
154 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_LockMouse,
155 OnHostMsgLockMouse)
156 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UnlockMouse,
157 OnHostMsgUnlockMouse)
158 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetCursor,
159 OnHostMsgSetCursor)
160 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetTextInputType,
161 OnHostMsgSetTextInputType)
162 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UpdateCaretPosition,
163 OnHostMsgUpdateCaretPosition)
164 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_CancelCompositionText,
165 OnHostMsgCancelCompositionText)
166 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UpdateSurroundingText,
167 OnHostMsgUpdateSurroundingText)
168 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDocumentURL,
169 OnHostMsgGetDocumentURL)
170 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ResolveRelativeToDocument,
171 OnHostMsgResolveRelativeToDocument)
172 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanRequest,
173 OnHostMsgDocumentCanRequest)
174 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanAccessDocument,
175 OnHostMsgDocumentCanAccessDocument)
176 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginInstanceURL,
177 OnHostMsgGetPluginInstanceURL)
178 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginReferrerURL,
179 OnHostMsgGetPluginReferrerURL)
180 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PromiseResolved,
181 OnHostMsgPromiseResolved)
182 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PromiseResolvedWithSession,
183 OnHostMsgPromiseResolvedWithSession)
184 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PromiseRejected,
185 OnHostMsgPromiseRejected)
186 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionMessage,
187 OnHostMsgSessionMessage)
188 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionKeysChange,
189 OnHostMsgSessionKeysChange)
190 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionExpirationChange,
191 OnHostMsgSessionExpirationChange)
192 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionClosed,
193 OnHostMsgSessionClosed)
194 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_LegacySessionError,
195 OnHostMsgLegacySessionError)
196 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverBlock,
197 OnHostMsgDeliverBlock)
198 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderInitializeDone,
199 OnHostMsgDecoderInitializeDone)
200 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderDeinitializeDone,
201 OnHostMsgDecoderDeinitializeDone)
202 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderResetDone,
203 OnHostMsgDecoderResetDone)
204 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverFrame,
205 OnHostMsgDeliverFrame)
206 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverSamples,
207 OnHostMsgDeliverSamples)
208 #endif // !defined(OS_NACL)
210 // Host -> Plugin messages.
211 IPC_MESSAGE_HANDLER(PpapiMsg_PPBInstance_MouseLockComplete,
212 OnPluginMsgMouseLockComplete)
214 IPC_MESSAGE_UNHANDLED(handled = false)
215 IPC_END_MESSAGE_MAP()
216 return handled;
219 PP_Bool PPB_Instance_Proxy::BindGraphics(PP_Instance instance,
220 PP_Resource device) {
221 // If device is 0, pass a null HostResource. This signals the host to unbind
222 // all devices.
223 PP_Resource pp_resource = 0;
224 if (device) {
225 Resource* resource =
226 PpapiGlobals::Get()->GetResourceTracker()->GetResource(device);
227 if (!resource || resource->pp_instance() != instance)
228 return PP_FALSE;
229 // We need to pass different resource to Graphics 2D, 3D and Compositor
230 // right now. Once 3D is migrated to the new design, we should be able to
231 // unify this.
232 if (resource->AsPPB_Graphics3D_API()) {
233 pp_resource = resource->host_resource().host_resource();
234 } else if (resource->AsPPB_Graphics2D_API() ||
235 resource->AsPPB_Compositor_API()) {
236 pp_resource = resource->pp_resource();
237 } else {
238 // A bad resource.
239 return PP_FALSE;
242 dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
243 API_ID_PPB_INSTANCE, instance, pp_resource));
244 return PP_TRUE;
247 PP_Bool PPB_Instance_Proxy::IsFullFrame(PP_Instance instance) {
248 PP_Bool result = PP_FALSE;
249 dispatcher()->Send(new PpapiHostMsg_PPBInstance_IsFullFrame(
250 API_ID_PPB_INSTANCE, instance, &result));
251 return result;
254 const ViewData* PPB_Instance_Proxy::GetViewData(PP_Instance instance) {
255 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
256 GetInstanceData(instance);
257 if (!data)
258 return NULL;
259 return &data->view;
262 PP_Bool PPB_Instance_Proxy::FlashIsFullscreen(PP_Instance instance) {
263 // This function is only used for proxying in the renderer process. It is not
264 // implemented in the plugin process.
265 NOTREACHED();
266 return PP_FALSE;
269 PP_Var PPB_Instance_Proxy::GetWindowObject(PP_Instance instance) {
270 ReceiveSerializedVarReturnValue result;
271 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetWindowObject(
272 API_ID_PPB_INSTANCE, instance, &result));
273 return result.Return(dispatcher());
276 PP_Var PPB_Instance_Proxy::GetOwnerElementObject(PP_Instance instance) {
277 ReceiveSerializedVarReturnValue result;
278 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetOwnerElementObject(
279 API_ID_PPB_INSTANCE, instance, &result));
280 return result.Return(dispatcher());
283 PP_Var PPB_Instance_Proxy::ExecuteScript(PP_Instance instance,
284 PP_Var script,
285 PP_Var* exception) {
286 ReceiveSerializedException se(dispatcher(), exception);
287 if (se.IsThrown())
288 return PP_MakeUndefined();
290 ReceiveSerializedVarReturnValue result;
291 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ExecuteScript(
292 API_ID_PPB_INSTANCE, instance,
293 SerializedVarSendInput(dispatcher(), script), &se, &result));
294 return result.Return(dispatcher());
297 uint32_t PPB_Instance_Proxy::GetAudioHardwareOutputSampleRate(
298 PP_Instance instance) {
299 uint32_t result = PP_AUDIOSAMPLERATE_NONE;
300 dispatcher()->Send(
301 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate(
302 API_ID_PPB_INSTANCE, instance, &result));
303 return result;
306 uint32_t PPB_Instance_Proxy::GetAudioHardwareOutputBufferSize(
307 PP_Instance instance) {
308 uint32_t result = 0;
309 dispatcher()->Send(
310 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputBufferSize(
311 API_ID_PPB_INSTANCE, instance, &result));
312 return result;
315 PP_Var PPB_Instance_Proxy::GetDefaultCharSet(PP_Instance instance) {
316 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
317 if (!dispatcher)
318 return PP_MakeUndefined();
320 ReceiveSerializedVarReturnValue result;
321 dispatcher->Send(new PpapiHostMsg_PPBInstance_GetDefaultCharSet(
322 API_ID_PPB_INSTANCE, instance, &result));
323 return result.Return(dispatcher);
326 void PPB_Instance_Proxy::SetPluginToHandleFindRequests(PP_Instance instance) {
327 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetPluginToHandleFindRequests(
328 API_ID_PPB_INSTANCE, instance));
331 void PPB_Instance_Proxy::NumberOfFindResultsChanged(PP_Instance instance,
332 int32_t total,
333 PP_Bool final_result) {
334 dispatcher()->Send(new PpapiHostMsg_PPBInstance_NumberOfFindResultsChanged(
335 API_ID_PPB_INSTANCE, instance, total, final_result));
338 void PPB_Instance_Proxy::SelectedFindResultChanged(PP_Instance instance,
339 int32_t index) {
340 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SelectFindResultChanged(
341 API_ID_PPB_INSTANCE, instance, index));
344 void PPB_Instance_Proxy::SetTickmarks(PP_Instance instance,
345 const PP_Rect* tickmarks,
346 uint32_t count) {
347 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTickmarks(
348 API_ID_PPB_INSTANCE, instance,
349 std::vector<PP_Rect>(tickmarks, tickmarks + count)));
352 PP_Bool PPB_Instance_Proxy::IsFullscreen(PP_Instance instance) {
353 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
354 GetInstanceData(instance);
355 if (!data)
356 return PP_FALSE;
357 return PP_FromBool(data->view.is_fullscreen);
360 PP_Bool PPB_Instance_Proxy::SetFullscreen(PP_Instance instance,
361 PP_Bool fullscreen) {
362 PP_Bool result = PP_FALSE;
363 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetFullscreen(
364 API_ID_PPB_INSTANCE, instance, fullscreen, &result));
365 return result;
368 PP_Bool PPB_Instance_Proxy::GetScreenSize(PP_Instance instance,
369 PP_Size* size) {
370 PP_Bool result = PP_FALSE;
371 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetScreenSize(
372 API_ID_PPB_INSTANCE, instance, &result, size));
373 return result;
376 Resource* PPB_Instance_Proxy::GetSingletonResource(PP_Instance instance,
377 SingletonResourceID id) {
378 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
379 GetInstanceData(instance);
381 InstanceData::SingletonResourceMap::iterator it =
382 data->singleton_resources.find(id);
383 if (it != data->singleton_resources.end())
384 return it->second.get();
386 scoped_refptr<Resource> new_singleton;
387 Connection connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher());
389 switch (id) {
390 case BROKER_SINGLETON_ID:
391 new_singleton = new BrokerResource(connection, instance);
392 break;
393 case GAMEPAD_SINGLETON_ID:
394 new_singleton = new GamepadResource(connection, instance);
395 break;
396 case ISOLATED_FILESYSTEM_SINGLETON_ID:
397 new_singleton =
398 new IsolatedFileSystemPrivateResource(connection, instance);
399 break;
400 case NETWORK_PROXY_SINGLETON_ID:
401 new_singleton = new NetworkProxyResource(connection, instance);
402 break;
403 case TRUETYPE_FONT_SINGLETON_ID:
404 new_singleton = new TrueTypeFontSingletonResource(connection, instance);
405 break;
406 case UMA_SINGLETON_ID:
407 new_singleton = new UMAPrivateResource(connection, instance);
408 break;
409 // Flash/trusted resources aren't needed for NaCl.
410 #if !defined(OS_NACL) && !defined(NACL_WIN64)
411 case BROWSER_FONT_SINGLETON_ID:
412 new_singleton = new BrowserFontSingletonResource(connection, instance);
413 break;
414 case FLASH_CLIPBOARD_SINGLETON_ID:
415 new_singleton = new FlashClipboardResource(connection, instance);
416 break;
417 case FLASH_FILE_SINGLETON_ID:
418 new_singleton = new FlashFileResource(connection, instance);
419 break;
420 case FLASH_FULLSCREEN_SINGLETON_ID:
421 new_singleton = new FlashFullscreenResource(connection, instance);
422 break;
423 case FLASH_SINGLETON_ID:
424 new_singleton = new FlashResource(connection, instance,
425 static_cast<PluginDispatcher*>(dispatcher()));
426 break;
427 case PDF_SINGLETON_ID:
428 new_singleton = new PDFResource(connection, instance);
429 break;
430 #else
431 case BROWSER_FONT_SINGLETON_ID:
432 case FLASH_CLIPBOARD_SINGLETON_ID:
433 case FLASH_FILE_SINGLETON_ID:
434 case FLASH_FULLSCREEN_SINGLETON_ID:
435 case FLASH_SINGLETON_ID:
436 case PDF_SINGLETON_ID:
437 NOTREACHED();
438 break;
439 #endif // !defined(OS_NACL) && !defined(NACL_WIN64)
442 if (!new_singleton.get()) {
443 // Getting here implies that a constructor is missing in the above switch.
444 NOTREACHED();
445 return NULL;
448 data->singleton_resources[id] = new_singleton;
449 return new_singleton.get();
452 int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance,
453 uint32_t event_classes) {
454 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
455 API_ID_PPB_INSTANCE, instance, false, event_classes));
457 // We always register for the classes we can handle, this function validates
458 // the flags so we can notify it if anything was invalid, without requiring
459 // a sync reply.
460 return ValidateRequestInputEvents(false, event_classes);
463 int32_t PPB_Instance_Proxy::RequestFilteringInputEvents(
464 PP_Instance instance,
465 uint32_t event_classes) {
466 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
467 API_ID_PPB_INSTANCE, instance, true, event_classes));
469 // We always register for the classes we can handle, this function validates
470 // the flags so we can notify it if anything was invalid, without requiring
471 // a sync reply.
472 return ValidateRequestInputEvents(true, event_classes);
475 void PPB_Instance_Proxy::ClearInputEventRequest(PP_Instance instance,
476 uint32_t event_classes) {
477 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ClearInputEvents(
478 API_ID_PPB_INSTANCE, instance, event_classes));
481 PP_Var PPB_Instance_Proxy::GetDocumentURL(PP_Instance instance,
482 PP_URLComponents_Dev* components) {
483 ReceiveSerializedVarReturnValue result;
484 PP_URLComponents_Dev url_components = {{0}};
485 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetDocumentURL(
486 API_ID_PPB_INSTANCE, instance, &url_components, &result));
487 if (components)
488 *components = url_components;
489 return result.Return(dispatcher());
492 #if !defined(OS_NACL)
493 PP_Var PPB_Instance_Proxy::ResolveRelativeToDocument(
494 PP_Instance instance,
495 PP_Var relative,
496 PP_URLComponents_Dev* components) {
497 ReceiveSerializedVarReturnValue result;
498 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ResolveRelativeToDocument(
499 API_ID_PPB_INSTANCE, instance,
500 SerializedVarSendInput(dispatcher(), relative),
501 &result));
502 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
503 result.Return(dispatcher()),
504 components);
507 PP_Bool PPB_Instance_Proxy::DocumentCanRequest(PP_Instance instance,
508 PP_Var url) {
509 PP_Bool result = PP_FALSE;
510 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanRequest(
511 API_ID_PPB_INSTANCE, instance,
512 SerializedVarSendInput(dispatcher(), url),
513 &result));
514 return result;
517 PP_Bool PPB_Instance_Proxy::DocumentCanAccessDocument(PP_Instance instance,
518 PP_Instance target) {
519 PP_Bool result = PP_FALSE;
520 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanAccessDocument(
521 API_ID_PPB_INSTANCE, instance, target, &result));
522 return result;
525 PP_Var PPB_Instance_Proxy::GetPluginInstanceURL(
526 PP_Instance instance,
527 PP_URLComponents_Dev* components) {
528 ReceiveSerializedVarReturnValue result;
529 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginInstanceURL(
530 API_ID_PPB_INSTANCE, instance, &result));
531 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
532 result.Return(dispatcher()),
533 components);
536 PP_Var PPB_Instance_Proxy::GetPluginReferrerURL(
537 PP_Instance instance,
538 PP_URLComponents_Dev* components) {
539 ReceiveSerializedVarReturnValue result;
540 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginReferrerURL(
541 API_ID_PPB_INSTANCE, instance, &result));
542 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
543 result.Return(dispatcher()),
544 components);
547 void PPB_Instance_Proxy::PromiseResolved(PP_Instance instance,
548 uint32 promise_id) {
549 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseResolved(
550 API_ID_PPB_INSTANCE, instance, promise_id));
553 void PPB_Instance_Proxy::PromiseResolvedWithSession(PP_Instance instance,
554 uint32 promise_id,
555 PP_Var session_id_var) {
556 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseResolvedWithSession(
557 API_ID_PPB_INSTANCE, instance, promise_id,
558 SerializedVarSendInput(dispatcher(), session_id_var)));
561 void PPB_Instance_Proxy::PromiseRejected(PP_Instance instance,
562 uint32 promise_id,
563 PP_CdmExceptionCode exception_code,
564 uint32 system_code,
565 PP_Var error_description_var) {
566 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseRejected(
567 API_ID_PPB_INSTANCE,
568 instance,
569 promise_id,
570 exception_code,
571 system_code,
572 SerializedVarSendInput(dispatcher(), error_description_var)));
575 void PPB_Instance_Proxy::SessionMessage(PP_Instance instance,
576 PP_Var session_id_var,
577 PP_CdmMessageType message_type,
578 PP_Var message_var,
579 PP_Var legacy_destination_url_var) {
580 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionMessage(
581 API_ID_PPB_INSTANCE, instance,
582 SerializedVarSendInput(dispatcher(), session_id_var), message_type,
583 SerializedVarSendInput(dispatcher(), message_var),
584 SerializedVarSendInput(dispatcher(), legacy_destination_url_var)));
587 void PPB_Instance_Proxy::SessionKeysChange(
588 PP_Instance instance,
589 PP_Var session_id_var,
590 PP_Bool has_additional_usable_key,
591 uint32_t key_count,
592 const struct PP_KeyInformation key_information[]) {
593 StringVar* session_id = StringVar::FromPPVar(session_id_var);
594 if (!session_id ||
595 session_id->value().length() > media::limits::kMaxSessionIdLength) {
596 NOTREACHED();
597 return;
600 if (key_count > media::limits::kMaxKeyIds) {
601 NOTREACHED();
602 return;
605 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionKeysChange(
606 API_ID_PPB_INSTANCE, instance, session_id->value(),
607 has_additional_usable_key,
608 std::vector<PP_KeyInformation>(key_information,
609 key_information + key_count)));
612 void PPB_Instance_Proxy::SessionExpirationChange(PP_Instance instance,
613 PP_Var session_id_var,
614 PP_Time new_expiry_time) {
615 StringVar* session_id = StringVar::FromPPVar(session_id_var);
616 if (!session_id ||
617 session_id->value().length() > media::limits::kMaxSessionIdLength) {
618 NOTREACHED();
619 return;
622 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionExpirationChange(
623 API_ID_PPB_INSTANCE, instance, session_id->value(), new_expiry_time));
626 void PPB_Instance_Proxy::SessionClosed(PP_Instance instance,
627 PP_Var session_id_var) {
628 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionClosed(
629 API_ID_PPB_INSTANCE, instance,
630 SerializedVarSendInput(dispatcher(), session_id_var)));
633 void PPB_Instance_Proxy::LegacySessionError(PP_Instance instance,
634 PP_Var session_id_var,
635 PP_CdmExceptionCode exception_code,
636 uint32 system_code,
637 PP_Var error_description_var) {
638 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LegacySessionError(
639 API_ID_PPB_INSTANCE, instance,
640 SerializedVarSendInput(dispatcher(), session_id_var), exception_code,
641 system_code,
642 SerializedVarSendInput(dispatcher(), error_description_var)));
645 void PPB_Instance_Proxy::DeliverBlock(PP_Instance instance,
646 PP_Resource decrypted_block,
647 const PP_DecryptedBlockInfo* block_info) {
648 PP_Resource decrypted_block_host_resource = 0;
650 if (decrypted_block) {
651 Resource* object =
652 PpapiGlobals::Get()->GetResourceTracker()->GetResource(decrypted_block);
653 if (!object || object->pp_instance() != instance) {
654 NOTREACHED();
655 return;
657 decrypted_block_host_resource = object->host_resource().host_resource();
660 std::string serialized_block_info;
661 if (!SerializeBlockInfo(*block_info, &serialized_block_info)) {
662 NOTREACHED();
663 return;
666 dispatcher()->Send(
667 new PpapiHostMsg_PPBInstance_DeliverBlock(API_ID_PPB_INSTANCE,
668 instance,
669 decrypted_block_host_resource,
670 serialized_block_info));
673 void PPB_Instance_Proxy::DecoderInitializeDone(
674 PP_Instance instance,
675 PP_DecryptorStreamType decoder_type,
676 uint32_t request_id,
677 PP_Bool success) {
678 dispatcher()->Send(
679 new PpapiHostMsg_PPBInstance_DecoderInitializeDone(
680 API_ID_PPB_INSTANCE,
681 instance,
682 decoder_type,
683 request_id,
684 success));
687 void PPB_Instance_Proxy::DecoderDeinitializeDone(
688 PP_Instance instance,
689 PP_DecryptorStreamType decoder_type,
690 uint32_t request_id) {
691 dispatcher()->Send(
692 new PpapiHostMsg_PPBInstance_DecoderDeinitializeDone(
693 API_ID_PPB_INSTANCE,
694 instance,
695 decoder_type,
696 request_id));
699 void PPB_Instance_Proxy::DecoderResetDone(PP_Instance instance,
700 PP_DecryptorStreamType decoder_type,
701 uint32_t request_id) {
702 dispatcher()->Send(
703 new PpapiHostMsg_PPBInstance_DecoderResetDone(
704 API_ID_PPB_INSTANCE,
705 instance,
706 decoder_type,
707 request_id));
710 void PPB_Instance_Proxy::DeliverFrame(PP_Instance instance,
711 PP_Resource decrypted_frame,
712 const PP_DecryptedFrameInfo* frame_info) {
713 PP_Resource host_resource = 0;
714 if (decrypted_frame != 0) {
715 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
716 Resource* object = tracker->GetResource(decrypted_frame);
718 if (!object || object->pp_instance() != instance) {
719 NOTREACHED();
720 return;
723 host_resource = object->host_resource().host_resource();
726 std::string serialized_frame_info;
727 if (!SerializeBlockInfo(*frame_info, &serialized_frame_info)) {
728 NOTREACHED();
729 return;
732 dispatcher()->Send(
733 new PpapiHostMsg_PPBInstance_DeliverFrame(API_ID_PPB_INSTANCE,
734 instance,
735 host_resource,
736 serialized_frame_info));
739 void PPB_Instance_Proxy::DeliverSamples(
740 PP_Instance instance,
741 PP_Resource decrypted_samples,
742 const PP_DecryptedSampleInfo* sample_info) {
743 PP_Resource host_resource = 0;
744 if (decrypted_samples != 0) {
745 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
746 Resource* object = tracker->GetResource(decrypted_samples);
748 if (!object || object->pp_instance() != instance) {
749 NOTREACHED();
750 return;
753 host_resource = object->host_resource().host_resource();
756 std::string serialized_sample_info;
757 if (!SerializeBlockInfo(*sample_info, &serialized_sample_info)) {
758 NOTREACHED();
759 return;
762 dispatcher()->Send(
763 new PpapiHostMsg_PPBInstance_DeliverSamples(API_ID_PPB_INSTANCE,
764 instance,
765 host_resource,
766 serialized_sample_info));
768 #endif // !defined(OS_NACL)
770 void PPB_Instance_Proxy::PostMessage(PP_Instance instance,
771 PP_Var message) {
772 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage(
773 API_ID_PPB_INSTANCE,
774 instance, SerializedVarSendInputShmem(dispatcher(), message,
775 instance)));
778 int32_t PPB_Instance_Proxy::RegisterMessageHandler(
779 PP_Instance instance,
780 void* user_data,
781 const PPP_MessageHandler_0_2* handler,
782 PP_Resource message_loop) {
783 InstanceData* data =
784 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
785 if (!data)
786 return PP_ERROR_BADARGUMENT;
788 int32_t result = PP_ERROR_FAILED;
789 scoped_ptr<MessageHandler> message_handler = MessageHandler::Create(
790 instance, handler, user_data, message_loop, &result);
791 if (message_handler)
792 data->message_handler = message_handler.Pass();
793 return result;
796 void PPB_Instance_Proxy::UnregisterMessageHandler(PP_Instance instance) {
797 InstanceData* data =
798 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
799 if (!data)
800 return;
801 data->message_handler.reset();
804 PP_Bool PPB_Instance_Proxy::SetCursor(PP_Instance instance,
805 PP_MouseCursor_Type type,
806 PP_Resource image,
807 const PP_Point* hot_spot) {
808 // Some of these parameters are important for security. This check is in the
809 // plugin process just for the convenience of the caller (since we don't
810 // bother returning errors from the other process with a sync message). The
811 // parameters will be validated again in the renderer.
812 if (!ValidateSetCursorParams(type, image, hot_spot))
813 return PP_FALSE;
815 HostResource image_host_resource;
816 if (image) {
817 Resource* cursor_image =
818 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image);
819 if (!cursor_image || cursor_image->pp_instance() != instance)
820 return PP_FALSE;
821 image_host_resource = cursor_image->host_resource();
824 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetCursor(
825 API_ID_PPB_INSTANCE, instance, static_cast<int32_t>(type),
826 image_host_resource, hot_spot ? *hot_spot : PP_MakePoint(0, 0)));
827 return PP_TRUE;
830 int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance,
831 scoped_refptr<TrackedCallback> callback) {
832 // Save the mouse callback on the instance data.
833 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
834 GetInstanceData(instance);
835 if (!data)
836 return PP_ERROR_BADARGUMENT;
837 if (TrackedCallback::IsPending(data->mouse_lock_callback))
838 return PP_ERROR_INPROGRESS; // Already have a pending callback.
839 data->mouse_lock_callback = callback;
841 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LockMouse(
842 API_ID_PPB_INSTANCE, instance));
843 return PP_OK_COMPLETIONPENDING;
846 void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance) {
847 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UnlockMouse(
848 API_ID_PPB_INSTANCE, instance));
851 void PPB_Instance_Proxy::SetTextInputType(PP_Instance instance,
852 PP_TextInput_Type type) {
853 CancelAnyPendingRequestSurroundingText(instance);
854 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTextInputType(
855 API_ID_PPB_INSTANCE, instance, type));
858 void PPB_Instance_Proxy::UpdateCaretPosition(PP_Instance instance,
859 const PP_Rect& caret,
860 const PP_Rect& bounding_box) {
861 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateCaretPosition(
862 API_ID_PPB_INSTANCE, instance, caret, bounding_box));
865 void PPB_Instance_Proxy::CancelCompositionText(PP_Instance instance) {
866 CancelAnyPendingRequestSurroundingText(instance);
867 dispatcher()->Send(new PpapiHostMsg_PPBInstance_CancelCompositionText(
868 API_ID_PPB_INSTANCE, instance));
871 void PPB_Instance_Proxy::SelectionChanged(PP_Instance instance) {
872 // The "right" way to do this is to send the message to the host. However,
873 // all it will do is call RequestSurroundingText with a hardcoded number of
874 // characters in response, which is an entire IPC round-trip.
876 // We can avoid this round-trip by just implementing the
877 // RequestSurroundingText logic in the plugin process. If the logic in the
878 // host becomes more complex (like a more adaptive number of characters),
879 // we'll need to reevanuate whether we want to do the round trip instead.
881 // Be careful to post a task to avoid reentering the plugin.
883 InstanceData* data =
884 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
885 if (!data)
886 return;
887 data->should_do_request_surrounding_text = true;
889 if (!data->is_request_surrounding_text_pending) {
890 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
891 FROM_HERE,
892 RunWhileLocked(base::Bind(&RequestSurroundingText, instance)));
893 data->is_request_surrounding_text_pending = true;
897 void PPB_Instance_Proxy::UpdateSurroundingText(PP_Instance instance,
898 const char* text,
899 uint32_t caret,
900 uint32_t anchor) {
901 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateSurroundingText(
902 API_ID_PPB_INSTANCE, instance, text, caret, anchor));
905 #if !defined(OS_NACL)
906 void PPB_Instance_Proxy::OnHostMsgGetWindowObject(
907 PP_Instance instance,
908 SerializedVarReturnValue result) {
909 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
910 return;
911 EnterInstanceNoLock enter(instance);
912 if (enter.succeeded())
913 result.Return(dispatcher(), enter.functions()->GetWindowObject(instance));
916 void PPB_Instance_Proxy::OnHostMsgGetOwnerElementObject(
917 PP_Instance instance,
918 SerializedVarReturnValue result) {
919 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
920 return;
921 EnterInstanceNoLock enter(instance);
922 if (enter.succeeded()) {
923 result.Return(dispatcher(),
924 enter.functions()->GetOwnerElementObject(instance));
928 void PPB_Instance_Proxy::OnHostMsgBindGraphics(PP_Instance instance,
929 PP_Resource device) {
930 // Note that we ignroe the return value here. Otherwise, this would need to
931 // be a slow sync call, and the plugin side of the proxy will have already
932 // validated the resources, so we shouldn't see errors here that weren't
933 // already caught.
934 EnterInstanceNoLock enter(instance);
935 if (enter.succeeded())
936 enter.functions()->BindGraphics(instance, device);
939 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputSampleRate(
940 PP_Instance instance, uint32_t* result) {
941 EnterInstanceNoLock enter(instance);
942 if (enter.succeeded())
943 *result = enter.functions()->GetAudioHardwareOutputSampleRate(instance);
946 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputBufferSize(
947 PP_Instance instance, uint32_t* result) {
948 EnterInstanceNoLock enter(instance);
949 if (enter.succeeded())
950 *result = enter.functions()->GetAudioHardwareOutputBufferSize(instance);
953 void PPB_Instance_Proxy::OnHostMsgIsFullFrame(PP_Instance instance,
954 PP_Bool* result) {
955 EnterInstanceNoLock enter(instance);
956 if (enter.succeeded())
957 *result = enter.functions()->IsFullFrame(instance);
960 void PPB_Instance_Proxy::OnHostMsgExecuteScript(
961 PP_Instance instance,
962 SerializedVarReceiveInput script,
963 SerializedVarOutParam out_exception,
964 SerializedVarReturnValue result) {
965 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
966 return;
967 EnterInstanceNoLock enter(instance);
968 if (enter.failed())
969 return;
971 if (dispatcher()->IsPlugin())
972 NOTREACHED();
973 else
974 static_cast<HostDispatcher*>(dispatcher())->set_allow_plugin_reentrancy();
976 result.Return(dispatcher(), enter.functions()->ExecuteScript(
977 instance,
978 script.Get(dispatcher()),
979 out_exception.OutParam(dispatcher())));
982 void PPB_Instance_Proxy::OnHostMsgGetDefaultCharSet(
983 PP_Instance instance,
984 SerializedVarReturnValue result) {
985 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
986 return;
987 EnterInstanceNoLock enter(instance);
988 if (enter.succeeded())
989 result.Return(dispatcher(), enter.functions()->GetDefaultCharSet(instance));
992 void PPB_Instance_Proxy::OnHostMsgSetPluginToHandleFindRequests(
993 PP_Instance instance) {
994 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
995 return;
996 EnterInstanceNoLock enter(instance);
997 if (enter.succeeded())
998 enter.functions()->SetPluginToHandleFindRequests(instance);
1001 void PPB_Instance_Proxy::OnHostMsgNumberOfFindResultsChanged(
1002 PP_Instance instance,
1003 int32_t total,
1004 PP_Bool final_result) {
1005 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1006 return;
1007 EnterInstanceNoLock enter(instance);
1008 if (enter.succeeded()) {
1009 enter.functions()->NumberOfFindResultsChanged(
1010 instance, total, final_result);
1014 void PPB_Instance_Proxy::OnHostMsgSelectFindResultChanged(
1015 PP_Instance instance,
1016 int32_t index) {
1017 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1018 return;
1019 EnterInstanceNoLock enter(instance);
1020 if (enter.succeeded())
1021 enter.functions()->SelectedFindResultChanged(instance, index);
1024 void PPB_Instance_Proxy::OnHostMsgSetTickmarks(
1025 PP_Instance instance,
1026 const std::vector<PP_Rect>& tickmarks) {
1027 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1028 return;
1029 const PP_Rect* array = tickmarks.empty() ? NULL : &tickmarks[0];
1030 EnterInstanceNoLock enter(instance);
1031 if (enter.succeeded()) {
1032 enter.functions()->SetTickmarks(instance,
1033 array,
1034 static_cast<uint32_t>(tickmarks.size()));
1038 void PPB_Instance_Proxy::OnHostMsgSetFullscreen(PP_Instance instance,
1039 PP_Bool fullscreen,
1040 PP_Bool* result) {
1041 EnterInstanceNoLock enter(instance);
1042 if (enter.succeeded())
1043 *result = enter.functions()->SetFullscreen(instance, fullscreen);
1047 void PPB_Instance_Proxy::OnHostMsgGetScreenSize(PP_Instance instance,
1048 PP_Bool* result,
1049 PP_Size* size) {
1050 EnterInstanceNoLock enter(instance);
1051 if (enter.succeeded())
1052 *result = enter.functions()->GetScreenSize(instance, size);
1055 void PPB_Instance_Proxy::OnHostMsgRequestInputEvents(PP_Instance instance,
1056 bool is_filtering,
1057 uint32_t event_classes) {
1058 EnterInstanceNoLock enter(instance);
1059 if (enter.succeeded()) {
1060 if (is_filtering)
1061 enter.functions()->RequestFilteringInputEvents(instance, event_classes);
1062 else
1063 enter.functions()->RequestInputEvents(instance, event_classes);
1067 void PPB_Instance_Proxy::OnHostMsgClearInputEvents(PP_Instance instance,
1068 uint32_t event_classes) {
1069 EnterInstanceNoLock enter(instance);
1070 if (enter.succeeded())
1071 enter.functions()->ClearInputEventRequest(instance, event_classes);
1074 void PPB_Instance_Proxy::OnHostMsgPostMessage(
1075 PP_Instance instance,
1076 SerializedVarReceiveInput message) {
1077 EnterInstanceNoLock enter(instance);
1078 if (!message.is_valid_var()) {
1079 PpapiGlobals::Get()->LogWithSource(
1080 instance, PP_LOGLEVEL_ERROR, std::string(), kSerializationError);
1081 return;
1084 if (enter.succeeded())
1085 enter.functions()->PostMessage(instance,
1086 message.GetForInstance(dispatcher(),
1087 instance));
1090 void PPB_Instance_Proxy::OnHostMsgLockMouse(PP_Instance instance) {
1091 // Need to be careful to always issue the callback.
1092 pp::CompletionCallback cb = callback_factory_.NewCallback(
1093 &PPB_Instance_Proxy::MouseLockCompleteInHost, instance);
1095 EnterInstanceNoLock enter(instance, cb.pp_completion_callback());
1096 if (enter.succeeded())
1097 enter.SetResult(enter.functions()->LockMouse(instance, enter.callback()));
1100 void PPB_Instance_Proxy::OnHostMsgUnlockMouse(PP_Instance instance) {
1101 EnterInstanceNoLock enter(instance);
1102 if (enter.succeeded())
1103 enter.functions()->UnlockMouse(instance);
1106 void PPB_Instance_Proxy::OnHostMsgGetDocumentURL(
1107 PP_Instance instance,
1108 PP_URLComponents_Dev* components,
1109 SerializedVarReturnValue result) {
1110 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1111 return;
1112 EnterInstanceNoLock enter(instance);
1113 if (enter.succeeded()) {
1114 PP_Var document_url = enter.functions()->GetDocumentURL(instance,
1115 components);
1116 result.Return(dispatcher(), document_url);
1120 void PPB_Instance_Proxy::OnHostMsgResolveRelativeToDocument(
1121 PP_Instance instance,
1122 SerializedVarReceiveInput relative,
1123 SerializedVarReturnValue result) {
1124 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1125 return;
1126 EnterInstanceNoLock enter(instance);
1127 if (enter.succeeded()) {
1128 result.Return(dispatcher(),
1129 enter.functions()->ResolveRelativeToDocument(
1130 instance, relative.Get(dispatcher()), NULL));
1134 void PPB_Instance_Proxy::OnHostMsgDocumentCanRequest(
1135 PP_Instance instance,
1136 SerializedVarReceiveInput url,
1137 PP_Bool* result) {
1138 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1139 return;
1140 EnterInstanceNoLock enter(instance);
1141 if (enter.succeeded()) {
1142 *result = enter.functions()->DocumentCanRequest(instance,
1143 url.Get(dispatcher()));
1147 void PPB_Instance_Proxy::OnHostMsgDocumentCanAccessDocument(PP_Instance active,
1148 PP_Instance target,
1149 PP_Bool* result) {
1150 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1151 return;
1152 EnterInstanceNoLock enter(active);
1153 if (enter.succeeded())
1154 *result = enter.functions()->DocumentCanAccessDocument(active, target);
1157 void PPB_Instance_Proxy::OnHostMsgGetPluginInstanceURL(
1158 PP_Instance instance,
1159 SerializedVarReturnValue result) {
1160 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1161 return;
1162 EnterInstanceNoLock enter(instance);
1163 if (enter.succeeded()) {
1164 result.Return(dispatcher(),
1165 enter.functions()->GetPluginInstanceURL(instance, NULL));
1169 void PPB_Instance_Proxy::OnHostMsgGetPluginReferrerURL(
1170 PP_Instance instance,
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()->GetPluginReferrerURL(instance, NULL));
1181 void PPB_Instance_Proxy::OnHostMsgPromiseResolved(PP_Instance instance,
1182 uint32_t promise_id) {
1183 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1184 return;
1185 EnterInstanceNoLock enter(instance);
1186 if (enter.succeeded()) {
1187 enter.functions()->PromiseResolved(instance, promise_id);
1191 void PPB_Instance_Proxy::OnHostMsgPromiseResolvedWithSession(
1192 PP_Instance instance,
1193 uint32_t promise_id,
1194 SerializedVarReceiveInput session_id) {
1195 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1196 return;
1197 EnterInstanceNoLock enter(instance);
1198 if (enter.succeeded()) {
1199 enter.functions()->PromiseResolvedWithSession(instance, promise_id,
1200 session_id.Get(dispatcher()));
1204 void PPB_Instance_Proxy::OnHostMsgPromiseRejected(
1205 PP_Instance instance,
1206 uint32_t promise_id,
1207 PP_CdmExceptionCode exception_code,
1208 uint32_t system_code,
1209 SerializedVarReceiveInput error_description) {
1210 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1211 return;
1212 EnterInstanceNoLock enter(instance);
1213 if (enter.succeeded()) {
1214 enter.functions()->PromiseRejected(instance,
1215 promise_id,
1216 exception_code,
1217 system_code,
1218 error_description.Get(dispatcher()));
1222 void PPB_Instance_Proxy::OnHostMsgSessionMessage(
1223 PP_Instance instance,
1224 SerializedVarReceiveInput session_id,
1225 PP_CdmMessageType message_type,
1226 SerializedVarReceiveInput message,
1227 SerializedVarReceiveInput legacy_destination_url) {
1228 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1229 return;
1230 EnterInstanceNoLock enter(instance);
1231 if (enter.succeeded()) {
1232 enter.functions()->SessionMessage(instance, session_id.Get(dispatcher()),
1233 message_type, message.Get(dispatcher()),
1234 legacy_destination_url.Get(dispatcher()));
1238 void PPB_Instance_Proxy::OnHostMsgSessionKeysChange(
1239 PP_Instance instance,
1240 const std::string& session_id,
1241 PP_Bool has_additional_usable_key,
1242 const std::vector<PP_KeyInformation>& key_information) {
1243 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1244 return;
1246 if (key_information.size() > media::limits::kMaxKeyIds) {
1247 NOTREACHED();
1248 return;
1251 EnterInstanceNoLock enter(instance);
1252 if (enter.succeeded()) {
1253 ScopedPPVar session_id_var(ScopedPPVar::PassRef(),
1254 StringVar::StringToPPVar(session_id));
1255 enter.functions()->SessionKeysChange(
1256 instance, session_id_var.get(), has_additional_usable_key,
1257 base::checked_cast<uint32_t>(key_information.size()),
1258 vector_as_array(&key_information));
1262 void PPB_Instance_Proxy::OnHostMsgSessionExpirationChange(
1263 PP_Instance instance,
1264 const std::string& session_id,
1265 PP_Time new_expiry_time) {
1266 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1267 return;
1268 EnterInstanceNoLock enter(instance);
1269 if (enter.succeeded()) {
1270 ScopedPPVar session_id_var(ScopedPPVar::PassRef(),
1271 StringVar::StringToPPVar(session_id));
1272 enter.functions()->SessionExpirationChange(instance, session_id_var.get(),
1273 new_expiry_time);
1277 void PPB_Instance_Proxy::OnHostMsgSessionClosed(
1278 PP_Instance instance,
1279 SerializedVarReceiveInput session_id) {
1280 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1281 return;
1282 EnterInstanceNoLock enter(instance);
1283 if (enter.succeeded()) {
1284 enter.functions()->SessionClosed(instance, session_id.Get(dispatcher()));
1288 void PPB_Instance_Proxy::OnHostMsgLegacySessionError(
1289 PP_Instance instance,
1290 SerializedVarReceiveInput session_id,
1291 PP_CdmExceptionCode exception_code,
1292 uint32_t system_code,
1293 SerializedVarReceiveInput error_description) {
1294 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1295 return;
1296 EnterInstanceNoLock enter(instance);
1297 if (enter.succeeded()) {
1298 enter.functions()->LegacySessionError(
1299 instance, session_id.Get(dispatcher()), exception_code, system_code,
1300 error_description.Get(dispatcher()));
1304 void PPB_Instance_Proxy::OnHostMsgDeliverBlock(
1305 PP_Instance instance,
1306 PP_Resource decrypted_block,
1307 const std::string& serialized_block_info) {
1308 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1309 return;
1310 PP_DecryptedBlockInfo block_info;
1311 if (!DeserializeBlockInfo(serialized_block_info, &block_info))
1312 return;
1314 EnterInstanceNoLock enter(instance);
1315 if (enter.succeeded())
1316 enter.functions()->DeliverBlock(instance, decrypted_block, &block_info);
1319 void PPB_Instance_Proxy::OnHostMsgDecoderInitializeDone(
1320 PP_Instance instance,
1321 PP_DecryptorStreamType decoder_type,
1322 uint32_t request_id,
1323 PP_Bool success) {
1324 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1325 return;
1326 EnterInstanceNoLock enter(instance);
1327 if (enter.succeeded()) {
1328 enter.functions()->DecoderInitializeDone(instance,
1329 decoder_type,
1330 request_id,
1331 success);
1335 void PPB_Instance_Proxy::OnHostMsgDecoderDeinitializeDone(
1336 PP_Instance instance,
1337 PP_DecryptorStreamType decoder_type,
1338 uint32_t request_id) {
1339 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1340 return;
1341 EnterInstanceNoLock enter(instance);
1342 if (enter.succeeded())
1343 enter.functions()->DecoderDeinitializeDone(instance,
1344 decoder_type,
1345 request_id);
1348 void PPB_Instance_Proxy::OnHostMsgDecoderResetDone(
1349 PP_Instance instance,
1350 PP_DecryptorStreamType decoder_type,
1351 uint32_t request_id) {
1352 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1353 return;
1354 EnterInstanceNoLock enter(instance);
1355 if (enter.succeeded())
1356 enter.functions()->DecoderResetDone(instance, decoder_type, request_id);
1359 void PPB_Instance_Proxy::OnHostMsgDeliverFrame(
1360 PP_Instance instance,
1361 PP_Resource decrypted_frame,
1362 const std::string& serialized_frame_info) {
1363 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1364 return;
1365 PP_DecryptedFrameInfo frame_info;
1366 if (!DeserializeBlockInfo(serialized_frame_info, &frame_info))
1367 return;
1369 EnterInstanceNoLock enter(instance);
1370 if (enter.succeeded())
1371 enter.functions()->DeliverFrame(instance, decrypted_frame, &frame_info);
1374 void PPB_Instance_Proxy::OnHostMsgDeliverSamples(
1375 PP_Instance instance,
1376 PP_Resource audio_frames,
1377 const std::string& serialized_sample_info) {
1378 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1379 return;
1380 PP_DecryptedSampleInfo sample_info;
1381 if (!DeserializeBlockInfo(serialized_sample_info, &sample_info))
1382 return;
1384 EnterInstanceNoLock enter(instance);
1385 if (enter.succeeded())
1386 enter.functions()->DeliverSamples(instance, audio_frames, &sample_info);
1389 void PPB_Instance_Proxy::OnHostMsgSetCursor(
1390 PP_Instance instance,
1391 int32_t type,
1392 const ppapi::HostResource& custom_image,
1393 const PP_Point& hot_spot) {
1394 // This API serves PPB_CursorControl_Dev and PPB_MouseCursor, so is public.
1395 EnterInstanceNoLock enter(instance);
1396 if (enter.succeeded()) {
1397 enter.functions()->SetCursor(
1398 instance, static_cast<PP_MouseCursor_Type>(type),
1399 custom_image.host_resource(), &hot_spot);
1403 void PPB_Instance_Proxy::OnHostMsgSetTextInputType(PP_Instance instance,
1404 PP_TextInput_Type type) {
1405 EnterInstanceNoLock enter(instance);
1406 if (enter.succeeded())
1407 enter.functions()->SetTextInputType(instance, type);
1410 void PPB_Instance_Proxy::OnHostMsgUpdateCaretPosition(
1411 PP_Instance instance,
1412 const PP_Rect& caret,
1413 const PP_Rect& bounding_box) {
1414 EnterInstanceNoLock enter(instance);
1415 if (enter.succeeded())
1416 enter.functions()->UpdateCaretPosition(instance, caret, bounding_box);
1419 void PPB_Instance_Proxy::OnHostMsgCancelCompositionText(PP_Instance instance) {
1420 EnterInstanceNoLock enter(instance);
1421 if (enter.succeeded())
1422 enter.functions()->CancelCompositionText(instance);
1425 void PPB_Instance_Proxy::OnHostMsgUpdateSurroundingText(
1426 PP_Instance instance,
1427 const std::string& text,
1428 uint32_t caret,
1429 uint32_t anchor) {
1430 EnterInstanceNoLock enter(instance);
1431 if (enter.succeeded()) {
1432 enter.functions()->UpdateSurroundingText(instance, text.c_str(), caret,
1433 anchor);
1436 #endif // !defined(OS_NACL)
1438 void PPB_Instance_Proxy::OnPluginMsgMouseLockComplete(PP_Instance instance,
1439 int32_t result) {
1440 if (!dispatcher()->IsPlugin())
1441 return;
1443 // Save the mouse callback on the instance data.
1444 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1445 GetInstanceData(instance);
1446 if (!data)
1447 return; // Instance was probably deleted.
1448 if (!TrackedCallback::IsPending(data->mouse_lock_callback)) {
1449 NOTREACHED();
1450 return;
1452 data->mouse_lock_callback->Run(result);
1455 #if !defined(OS_NACL)
1456 void PPB_Instance_Proxy::MouseLockCompleteInHost(int32_t result,
1457 PP_Instance instance) {
1458 dispatcher()->Send(new PpapiMsg_PPBInstance_MouseLockComplete(
1459 API_ID_PPB_INSTANCE, instance, result));
1461 #endif // !defined(OS_NACL)
1463 void PPB_Instance_Proxy::CancelAnyPendingRequestSurroundingText(
1464 PP_Instance instance) {
1465 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1466 GetInstanceData(instance);
1467 if (!data)
1468 return; // Instance was probably deleted.
1469 data->should_do_request_surrounding_text = false;
1472 } // namespace proxy
1473 } // namespace ppapi