Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ppapi / proxy / ppb_instance_proxy.cc
blobbcbbe6fb55e2ad3f86cab94ad4ed94fdafaf8bdb
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/proxy/ppb_instance_proxy.h"
7 #include "base/memory/ref_counted.h"
8 #include "base/numerics/safe_conversions.h"
9 #include "base/stl_util.h"
10 #include "build/build_config.h"
11 #include "media/base/limits.h"
12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/c/pp_time.h"
14 #include "ppapi/c/pp_var.h"
15 #include "ppapi/c/ppb_audio_config.h"
16 #include "ppapi/c/ppb_instance.h"
17 #include "ppapi/c/ppb_messaging.h"
18 #include "ppapi/c/ppb_mouse_lock.h"
19 #include "ppapi/c/private/pp_content_decryptor.h"
20 #include "ppapi/proxy/broker_resource.h"
21 #include "ppapi/proxy/browser_font_singleton_resource.h"
22 #include "ppapi/proxy/content_decryptor_private_serializer.h"
23 #include "ppapi/proxy/enter_proxy.h"
24 #include "ppapi/proxy/flash_clipboard_resource.h"
25 #include "ppapi/proxy/flash_file_resource.h"
26 #include "ppapi/proxy/flash_fullscreen_resource.h"
27 #include "ppapi/proxy/flash_resource.h"
28 #include "ppapi/proxy/gamepad_resource.h"
29 #include "ppapi/proxy/host_dispatcher.h"
30 #include "ppapi/proxy/isolated_file_system_private_resource.h"
31 #include "ppapi/proxy/message_handler.h"
32 #include "ppapi/proxy/network_proxy_resource.h"
33 #include "ppapi/proxy/pdf_resource.h"
34 #include "ppapi/proxy/plugin_dispatcher.h"
35 #include "ppapi/proxy/ppapi_messages.h"
36 #include "ppapi/proxy/serialized_var.h"
37 #include "ppapi/proxy/truetype_font_singleton_resource.h"
38 #include "ppapi/proxy/uma_private_resource.h"
39 #include "ppapi/shared_impl/array_var.h"
40 #include "ppapi/shared_impl/ppapi_globals.h"
41 #include "ppapi/shared_impl/ppb_url_util_shared.h"
42 #include "ppapi/shared_impl/ppb_view_shared.h"
43 #include "ppapi/shared_impl/scoped_pp_var.h"
44 #include "ppapi/shared_impl/var.h"
45 #include "ppapi/thunk/enter.h"
46 #include "ppapi/thunk/ppb_compositor_api.h"
47 #include "ppapi/thunk/ppb_graphics_2d_api.h"
48 #include "ppapi/thunk/ppb_graphics_3d_api.h"
49 #include "ppapi/thunk/thunk.h"
51 // Windows headers interfere with this file.
52 #ifdef PostMessage
53 #undef PostMessage
54 #endif
56 using ppapi::thunk::EnterInstanceNoLock;
57 using ppapi::thunk::EnterResourceNoLock;
58 using ppapi::thunk::PPB_Compositor_API;
59 using ppapi::thunk::PPB_Graphics2D_API;
60 using ppapi::thunk::PPB_Graphics3D_API;
61 using ppapi::thunk::PPB_Instance_API;
63 namespace ppapi {
64 namespace proxy {
66 namespace {
68 #if !defined(OS_NACL)
69 const char kSerializationError[] = "Failed to convert a PostMessage "
70 "argument from a PP_Var to a Javascript value. It may have cycles or be of "
71 "an unsupported type.";
72 #endif
74 void RequestSurroundingText(PP_Instance instance) {
75 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
76 if (!dispatcher)
77 return; // Instance has gone away while message was pending.
79 InstanceData* data = dispatcher->GetInstanceData(instance);
80 DCHECK(data); // Should have it, since we still have a dispatcher.
81 data->is_request_surrounding_text_pending = false;
82 if (!data->should_do_request_surrounding_text)
83 return;
85 // Just fake out a RequestSurroundingText message to the proxy for the PPP
86 // interface.
87 InterfaceProxy* proxy = dispatcher->GetInterfaceProxy(API_ID_PPP_TEXT_INPUT);
88 if (!proxy)
89 return;
90 proxy->OnMessageReceived(PpapiMsg_PPPTextInput_RequestSurroundingText(
91 API_ID_PPP_TEXT_INPUT, instance,
92 PPB_Instance_Shared::kExtraCharsForTextInput));
95 } // namespace
97 PPB_Instance_Proxy::PPB_Instance_Proxy(Dispatcher* dispatcher)
98 : InterfaceProxy(dispatcher),
99 callback_factory_(this) {
102 PPB_Instance_Proxy::~PPB_Instance_Proxy() {
105 bool PPB_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) {
106 // Prevent the dispatcher from going away during a call to ExecuteScript.
107 // This must happen OUTSIDE of ExecuteScript since the SerializedVars use
108 // the dispatcher upon return of the function (converting the
109 // SerializedVarReturnValue/OutParam to a SerializedVar in the destructor).
110 #if !defined(OS_NACL)
111 ScopedModuleReference death_grip(dispatcher());
112 #endif
114 bool handled = true;
115 IPC_BEGIN_MESSAGE_MAP(PPB_Instance_Proxy, msg)
116 #if !defined(OS_NACL)
117 // Plugin -> Host messages.
118 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetWindowObject,
119 OnHostMsgGetWindowObject)
120 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetOwnerElementObject,
121 OnHostMsgGetOwnerElementObject)
122 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_BindGraphics,
123 OnHostMsgBindGraphics)
124 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_IsFullFrame,
125 OnHostMsgIsFullFrame)
126 IPC_MESSAGE_HANDLER(
127 PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate,
128 OnHostMsgGetAudioHardwareOutputSampleRate)
129 IPC_MESSAGE_HANDLER(
130 PpapiHostMsg_PPBInstance_GetAudioHardwareOutputBufferSize,
131 OnHostMsgGetAudioHardwareOutputBufferSize)
132 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ExecuteScript,
133 OnHostMsgExecuteScript)
134 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDefaultCharSet,
135 OnHostMsgGetDefaultCharSet)
136 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetPluginToHandleFindRequests,
137 OnHostMsgSetPluginToHandleFindRequests);
138 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_NumberOfFindResultsChanged,
139 OnHostMsgNumberOfFindResultsChanged)
140 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SelectFindResultChanged,
141 OnHostMsgSelectFindResultChanged)
142 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetTickmarks,
143 OnHostMsgSetTickmarks)
144 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PostMessage,
145 OnHostMsgPostMessage)
146 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetFullscreen,
147 OnHostMsgSetFullscreen)
148 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetScreenSize,
149 OnHostMsgGetScreenSize)
150 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_RequestInputEvents,
151 OnHostMsgRequestInputEvents)
152 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ClearInputEvents,
153 OnHostMsgClearInputEvents)
154 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_StartTrackingLatency,
155 OnHostMsgStartTrackingLatency)
156 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_LockMouse,
157 OnHostMsgLockMouse)
158 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UnlockMouse,
159 OnHostMsgUnlockMouse)
160 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetCursor,
161 OnHostMsgSetCursor)
162 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetTextInputType,
163 OnHostMsgSetTextInputType)
164 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UpdateCaretPosition,
165 OnHostMsgUpdateCaretPosition)
166 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_CancelCompositionText,
167 OnHostMsgCancelCompositionText)
168 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UpdateSurroundingText,
169 OnHostMsgUpdateSurroundingText)
170 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDocumentURL,
171 OnHostMsgGetDocumentURL)
172 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ResolveRelativeToDocument,
173 OnHostMsgResolveRelativeToDocument)
174 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanRequest,
175 OnHostMsgDocumentCanRequest)
176 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanAccessDocument,
177 OnHostMsgDocumentCanAccessDocument)
178 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginInstanceURL,
179 OnHostMsgGetPluginInstanceURL)
180 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginReferrerURL,
181 OnHostMsgGetPluginReferrerURL)
182 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PromiseResolved,
183 OnHostMsgPromiseResolved)
184 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PromiseResolvedWithSession,
185 OnHostMsgPromiseResolvedWithSession)
186 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PromiseRejected,
187 OnHostMsgPromiseRejected)
188 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionMessage,
189 OnHostMsgSessionMessage)
190 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionKeysChange,
191 OnHostMsgSessionKeysChange)
192 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionExpirationChange,
193 OnHostMsgSessionExpirationChange)
194 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionClosed,
195 OnHostMsgSessionClosed)
196 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_LegacySessionError,
197 OnHostMsgLegacySessionError)
198 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverBlock,
199 OnHostMsgDeliverBlock)
200 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderInitializeDone,
201 OnHostMsgDecoderInitializeDone)
202 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderDeinitializeDone,
203 OnHostMsgDecoderDeinitializeDone)
204 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderResetDone,
205 OnHostMsgDecoderResetDone)
206 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverFrame,
207 OnHostMsgDeliverFrame)
208 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverSamples,
209 OnHostMsgDeliverSamples)
210 #endif // !defined(OS_NACL)
212 // Host -> Plugin messages.
213 IPC_MESSAGE_HANDLER(PpapiMsg_PPBInstance_MouseLockComplete,
214 OnPluginMsgMouseLockComplete)
216 IPC_MESSAGE_UNHANDLED(handled = false)
217 IPC_END_MESSAGE_MAP()
218 return handled;
221 PP_Bool PPB_Instance_Proxy::BindGraphics(PP_Instance instance,
222 PP_Resource device) {
223 // If device is 0, pass a null HostResource. This signals the host to unbind
224 // all devices.
225 PP_Resource pp_resource = 0;
226 if (device) {
227 Resource* resource =
228 PpapiGlobals::Get()->GetResourceTracker()->GetResource(device);
229 if (!resource || resource->pp_instance() != instance)
230 return PP_FALSE;
231 // We need to pass different resource to Graphics 2D, 3D and Compositor
232 // right now. Once 3D is migrated to the new design, we should be able to
233 // unify this.
234 if (resource->AsPPB_Graphics3D_API()) {
235 pp_resource = resource->host_resource().host_resource();
236 } else if (resource->AsPPB_Graphics2D_API() ||
237 resource->AsPPB_Compositor_API()) {
238 pp_resource = resource->pp_resource();
239 } else {
240 // A bad resource.
241 return PP_FALSE;
244 dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
245 API_ID_PPB_INSTANCE, instance, pp_resource));
246 return PP_TRUE;
249 PP_Bool PPB_Instance_Proxy::IsFullFrame(PP_Instance instance) {
250 PP_Bool result = PP_FALSE;
251 dispatcher()->Send(new PpapiHostMsg_PPBInstance_IsFullFrame(
252 API_ID_PPB_INSTANCE, instance, &result));
253 return result;
256 const ViewData* PPB_Instance_Proxy::GetViewData(PP_Instance instance) {
257 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
258 GetInstanceData(instance);
259 if (!data)
260 return NULL;
261 return &data->view;
264 PP_Bool PPB_Instance_Proxy::FlashIsFullscreen(PP_Instance instance) {
265 // This function is only used for proxying in the renderer process. It is not
266 // implemented in the plugin process.
267 NOTREACHED();
268 return PP_FALSE;
271 PP_Var PPB_Instance_Proxy::GetWindowObject(PP_Instance instance) {
272 ReceiveSerializedVarReturnValue result;
273 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetWindowObject(
274 API_ID_PPB_INSTANCE, instance, &result));
275 return result.Return(dispatcher());
278 PP_Var PPB_Instance_Proxy::GetOwnerElementObject(PP_Instance instance) {
279 ReceiveSerializedVarReturnValue result;
280 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetOwnerElementObject(
281 API_ID_PPB_INSTANCE, instance, &result));
282 return result.Return(dispatcher());
285 PP_Var PPB_Instance_Proxy::ExecuteScript(PP_Instance instance,
286 PP_Var script,
287 PP_Var* exception) {
288 ReceiveSerializedException se(dispatcher(), exception);
289 if (se.IsThrown())
290 return PP_MakeUndefined();
292 ReceiveSerializedVarReturnValue result;
293 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ExecuteScript(
294 API_ID_PPB_INSTANCE, instance,
295 SerializedVarSendInput(dispatcher(), script), &se, &result));
296 return result.Return(dispatcher());
299 uint32_t PPB_Instance_Proxy::GetAudioHardwareOutputSampleRate(
300 PP_Instance instance) {
301 uint32_t result = PP_AUDIOSAMPLERATE_NONE;
302 dispatcher()->Send(
303 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate(
304 API_ID_PPB_INSTANCE, instance, &result));
305 return result;
308 uint32_t PPB_Instance_Proxy::GetAudioHardwareOutputBufferSize(
309 PP_Instance instance) {
310 uint32_t result = 0;
311 dispatcher()->Send(
312 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputBufferSize(
313 API_ID_PPB_INSTANCE, instance, &result));
314 return result;
317 PP_Var PPB_Instance_Proxy::GetDefaultCharSet(PP_Instance instance) {
318 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
319 if (!dispatcher)
320 return PP_MakeUndefined();
322 ReceiveSerializedVarReturnValue result;
323 dispatcher->Send(new PpapiHostMsg_PPBInstance_GetDefaultCharSet(
324 API_ID_PPB_INSTANCE, instance, &result));
325 return result.Return(dispatcher);
328 void PPB_Instance_Proxy::SetPluginToHandleFindRequests(PP_Instance instance) {
329 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetPluginToHandleFindRequests(
330 API_ID_PPB_INSTANCE, instance));
333 void PPB_Instance_Proxy::NumberOfFindResultsChanged(PP_Instance instance,
334 int32_t total,
335 PP_Bool final_result) {
336 dispatcher()->Send(new PpapiHostMsg_PPBInstance_NumberOfFindResultsChanged(
337 API_ID_PPB_INSTANCE, instance, total, final_result));
340 void PPB_Instance_Proxy::SelectedFindResultChanged(PP_Instance instance,
341 int32_t index) {
342 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SelectFindResultChanged(
343 API_ID_PPB_INSTANCE, instance, index));
346 void PPB_Instance_Proxy::SetTickmarks(PP_Instance instance,
347 const PP_Rect* tickmarks,
348 uint32_t count) {
349 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTickmarks(
350 API_ID_PPB_INSTANCE, instance,
351 std::vector<PP_Rect>(tickmarks, tickmarks + count)));
354 PP_Bool PPB_Instance_Proxy::IsFullscreen(PP_Instance instance) {
355 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
356 GetInstanceData(instance);
357 if (!data)
358 return PP_FALSE;
359 return PP_FromBool(data->view.is_fullscreen);
362 PP_Bool PPB_Instance_Proxy::SetFullscreen(PP_Instance instance,
363 PP_Bool fullscreen) {
364 PP_Bool result = PP_FALSE;
365 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetFullscreen(
366 API_ID_PPB_INSTANCE, instance, fullscreen, &result));
367 return result;
370 PP_Bool PPB_Instance_Proxy::GetScreenSize(PP_Instance instance,
371 PP_Size* size) {
372 PP_Bool result = PP_FALSE;
373 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetScreenSize(
374 API_ID_PPB_INSTANCE, instance, &result, size));
375 return result;
378 Resource* PPB_Instance_Proxy::GetSingletonResource(PP_Instance instance,
379 SingletonResourceID id) {
380 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
381 GetInstanceData(instance);
383 InstanceData::SingletonResourceMap::iterator it =
384 data->singleton_resources.find(id);
385 if (it != data->singleton_resources.end())
386 return it->second.get();
388 scoped_refptr<Resource> new_singleton;
389 Connection connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher());
391 switch (id) {
392 case BROKER_SINGLETON_ID:
393 new_singleton = new BrokerResource(connection, instance);
394 break;
395 case GAMEPAD_SINGLETON_ID:
396 new_singleton = new GamepadResource(connection, instance);
397 break;
398 case ISOLATED_FILESYSTEM_SINGLETON_ID:
399 new_singleton =
400 new IsolatedFileSystemPrivateResource(connection, instance);
401 break;
402 case NETWORK_PROXY_SINGLETON_ID:
403 new_singleton = new NetworkProxyResource(connection, instance);
404 break;
405 case TRUETYPE_FONT_SINGLETON_ID:
406 new_singleton = new TrueTypeFontSingletonResource(connection, instance);
407 break;
408 case UMA_SINGLETON_ID:
409 new_singleton = new UMAPrivateResource(connection, instance);
410 break;
411 // Flash/trusted resources aren't needed for NaCl.
412 #if !defined(OS_NACL) && !defined(NACL_WIN64)
413 case BROWSER_FONT_SINGLETON_ID:
414 new_singleton = new BrowserFontSingletonResource(connection, instance);
415 break;
416 case FLASH_CLIPBOARD_SINGLETON_ID:
417 new_singleton = new FlashClipboardResource(connection, instance);
418 break;
419 case FLASH_FILE_SINGLETON_ID:
420 new_singleton = new FlashFileResource(connection, instance);
421 break;
422 case FLASH_FULLSCREEN_SINGLETON_ID:
423 new_singleton = new FlashFullscreenResource(connection, instance);
424 break;
425 case FLASH_SINGLETON_ID:
426 new_singleton = new FlashResource(connection, instance,
427 static_cast<PluginDispatcher*>(dispatcher()));
428 break;
429 case PDF_SINGLETON_ID:
430 new_singleton = new PDFResource(connection, instance);
431 break;
432 #else
433 case BROWSER_FONT_SINGLETON_ID:
434 case FLASH_CLIPBOARD_SINGLETON_ID:
435 case FLASH_FILE_SINGLETON_ID:
436 case FLASH_FULLSCREEN_SINGLETON_ID:
437 case FLASH_SINGLETON_ID:
438 case PDF_SINGLETON_ID:
439 NOTREACHED();
440 break;
441 #endif // !defined(OS_NACL) && !defined(NACL_WIN64)
444 if (!new_singleton.get()) {
445 // Getting here implies that a constructor is missing in the above switch.
446 NOTREACHED();
447 return NULL;
450 data->singleton_resources[id] = new_singleton;
451 return new_singleton.get();
454 int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance,
455 uint32_t event_classes) {
456 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
457 API_ID_PPB_INSTANCE, instance, false, event_classes));
459 // We always register for the classes we can handle, this function validates
460 // the flags so we can notify it if anything was invalid, without requiring
461 // a sync reply.
462 return ValidateRequestInputEvents(false, event_classes);
465 int32_t PPB_Instance_Proxy::RequestFilteringInputEvents(
466 PP_Instance instance,
467 uint32_t event_classes) {
468 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
469 API_ID_PPB_INSTANCE, instance, true, event_classes));
471 // We always register for the classes we can handle, this function validates
472 // the flags so we can notify it if anything was invalid, without requiring
473 // a sync reply.
474 return ValidateRequestInputEvents(true, event_classes);
477 void PPB_Instance_Proxy::ClearInputEventRequest(PP_Instance instance,
478 uint32_t event_classes) {
479 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ClearInputEvents(
480 API_ID_PPB_INSTANCE, instance, event_classes));
483 void PPB_Instance_Proxy::StartTrackingLatency(PP_Instance instance) {
484 dispatcher()->Send(new PpapiHostMsg_PPBInstance_StartTrackingLatency(
485 API_ID_PPB_INSTANCE, instance));
488 PP_Var PPB_Instance_Proxy::GetDocumentURL(PP_Instance instance,
489 PP_URLComponents_Dev* components) {
490 ReceiveSerializedVarReturnValue result;
491 PP_URLComponents_Dev url_components = {{0}};
492 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetDocumentURL(
493 API_ID_PPB_INSTANCE, instance, &url_components, &result));
494 if (components)
495 *components = url_components;
496 return result.Return(dispatcher());
499 #if !defined(OS_NACL)
500 PP_Var PPB_Instance_Proxy::ResolveRelativeToDocument(
501 PP_Instance instance,
502 PP_Var relative,
503 PP_URLComponents_Dev* components) {
504 ReceiveSerializedVarReturnValue result;
505 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ResolveRelativeToDocument(
506 API_ID_PPB_INSTANCE, instance,
507 SerializedVarSendInput(dispatcher(), relative),
508 &result));
509 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
510 result.Return(dispatcher()),
511 components);
514 PP_Bool PPB_Instance_Proxy::DocumentCanRequest(PP_Instance instance,
515 PP_Var url) {
516 PP_Bool result = PP_FALSE;
517 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanRequest(
518 API_ID_PPB_INSTANCE, instance,
519 SerializedVarSendInput(dispatcher(), url),
520 &result));
521 return result;
524 PP_Bool PPB_Instance_Proxy::DocumentCanAccessDocument(PP_Instance instance,
525 PP_Instance target) {
526 PP_Bool result = PP_FALSE;
527 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanAccessDocument(
528 API_ID_PPB_INSTANCE, instance, target, &result));
529 return result;
532 PP_Var PPB_Instance_Proxy::GetPluginInstanceURL(
533 PP_Instance instance,
534 PP_URLComponents_Dev* components) {
535 ReceiveSerializedVarReturnValue result;
536 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginInstanceURL(
537 API_ID_PPB_INSTANCE, instance, &result));
538 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
539 result.Return(dispatcher()),
540 components);
543 PP_Var PPB_Instance_Proxy::GetPluginReferrerURL(
544 PP_Instance instance,
545 PP_URLComponents_Dev* components) {
546 ReceiveSerializedVarReturnValue result;
547 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginReferrerURL(
548 API_ID_PPB_INSTANCE, instance, &result));
549 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
550 result.Return(dispatcher()),
551 components);
554 void PPB_Instance_Proxy::PromiseResolved(PP_Instance instance,
555 uint32 promise_id) {
556 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseResolved(
557 API_ID_PPB_INSTANCE, instance, promise_id));
560 void PPB_Instance_Proxy::PromiseResolvedWithSession(PP_Instance instance,
561 uint32 promise_id,
562 PP_Var session_id_var) {
563 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseResolvedWithSession(
564 API_ID_PPB_INSTANCE, instance, promise_id,
565 SerializedVarSendInput(dispatcher(), session_id_var)));
568 void PPB_Instance_Proxy::PromiseRejected(PP_Instance instance,
569 uint32 promise_id,
570 PP_CdmExceptionCode exception_code,
571 uint32 system_code,
572 PP_Var error_description_var) {
573 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PromiseRejected(
574 API_ID_PPB_INSTANCE,
575 instance,
576 promise_id,
577 exception_code,
578 system_code,
579 SerializedVarSendInput(dispatcher(), error_description_var)));
582 void PPB_Instance_Proxy::SessionMessage(PP_Instance instance,
583 PP_Var session_id_var,
584 PP_CdmMessageType message_type,
585 PP_Var message_var,
586 PP_Var legacy_destination_url_var) {
587 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionMessage(
588 API_ID_PPB_INSTANCE, instance,
589 SerializedVarSendInput(dispatcher(), session_id_var), message_type,
590 SerializedVarSendInput(dispatcher(), message_var),
591 SerializedVarSendInput(dispatcher(), legacy_destination_url_var)));
594 void PPB_Instance_Proxy::SessionKeysChange(
595 PP_Instance instance,
596 PP_Var session_id_var,
597 PP_Bool has_additional_usable_key,
598 uint32_t key_count,
599 const struct PP_KeyInformation key_information[]) {
600 StringVar* session_id = StringVar::FromPPVar(session_id_var);
601 if (!session_id ||
602 session_id->value().length() > media::limits::kMaxSessionIdLength) {
603 NOTREACHED();
604 return;
607 if (key_count > media::limits::kMaxKeyIds) {
608 NOTREACHED();
609 return;
612 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionKeysChange(
613 API_ID_PPB_INSTANCE, instance, session_id->value(),
614 has_additional_usable_key,
615 std::vector<PP_KeyInformation>(key_information,
616 key_information + key_count)));
619 void PPB_Instance_Proxy::SessionExpirationChange(PP_Instance instance,
620 PP_Var session_id_var,
621 PP_Time new_expiry_time) {
622 StringVar* session_id = StringVar::FromPPVar(session_id_var);
623 if (!session_id ||
624 session_id->value().length() > media::limits::kMaxSessionIdLength) {
625 NOTREACHED();
626 return;
629 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionExpirationChange(
630 API_ID_PPB_INSTANCE, instance, session_id->value(), new_expiry_time));
633 void PPB_Instance_Proxy::SessionClosed(PP_Instance instance,
634 PP_Var session_id_var) {
635 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionClosed(
636 API_ID_PPB_INSTANCE, instance,
637 SerializedVarSendInput(dispatcher(), session_id_var)));
640 void PPB_Instance_Proxy::LegacySessionError(PP_Instance instance,
641 PP_Var session_id_var,
642 PP_CdmExceptionCode exception_code,
643 uint32 system_code,
644 PP_Var error_description_var) {
645 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LegacySessionError(
646 API_ID_PPB_INSTANCE, instance,
647 SerializedVarSendInput(dispatcher(), session_id_var), exception_code,
648 system_code,
649 SerializedVarSendInput(dispatcher(), error_description_var)));
652 void PPB_Instance_Proxy::DeliverBlock(PP_Instance instance,
653 PP_Resource decrypted_block,
654 const PP_DecryptedBlockInfo* block_info) {
655 PP_Resource decrypted_block_host_resource = 0;
657 if (decrypted_block) {
658 Resource* object =
659 PpapiGlobals::Get()->GetResourceTracker()->GetResource(decrypted_block);
660 if (!object || object->pp_instance() != instance) {
661 NOTREACHED();
662 return;
664 decrypted_block_host_resource = object->host_resource().host_resource();
667 std::string serialized_block_info;
668 if (!SerializeBlockInfo(*block_info, &serialized_block_info)) {
669 NOTREACHED();
670 return;
673 dispatcher()->Send(
674 new PpapiHostMsg_PPBInstance_DeliverBlock(API_ID_PPB_INSTANCE,
675 instance,
676 decrypted_block_host_resource,
677 serialized_block_info));
680 void PPB_Instance_Proxy::DecoderInitializeDone(
681 PP_Instance instance,
682 PP_DecryptorStreamType decoder_type,
683 uint32_t request_id,
684 PP_Bool success) {
685 dispatcher()->Send(
686 new PpapiHostMsg_PPBInstance_DecoderInitializeDone(
687 API_ID_PPB_INSTANCE,
688 instance,
689 decoder_type,
690 request_id,
691 success));
694 void PPB_Instance_Proxy::DecoderDeinitializeDone(
695 PP_Instance instance,
696 PP_DecryptorStreamType decoder_type,
697 uint32_t request_id) {
698 dispatcher()->Send(
699 new PpapiHostMsg_PPBInstance_DecoderDeinitializeDone(
700 API_ID_PPB_INSTANCE,
701 instance,
702 decoder_type,
703 request_id));
706 void PPB_Instance_Proxy::DecoderResetDone(PP_Instance instance,
707 PP_DecryptorStreamType decoder_type,
708 uint32_t request_id) {
709 dispatcher()->Send(
710 new PpapiHostMsg_PPBInstance_DecoderResetDone(
711 API_ID_PPB_INSTANCE,
712 instance,
713 decoder_type,
714 request_id));
717 void PPB_Instance_Proxy::DeliverFrame(PP_Instance instance,
718 PP_Resource decrypted_frame,
719 const PP_DecryptedFrameInfo* frame_info) {
720 PP_Resource host_resource = 0;
721 if (decrypted_frame != 0) {
722 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
723 Resource* object = tracker->GetResource(decrypted_frame);
725 if (!object || object->pp_instance() != instance) {
726 NOTREACHED();
727 return;
730 host_resource = object->host_resource().host_resource();
733 std::string serialized_frame_info;
734 if (!SerializeBlockInfo(*frame_info, &serialized_frame_info)) {
735 NOTREACHED();
736 return;
739 dispatcher()->Send(
740 new PpapiHostMsg_PPBInstance_DeliverFrame(API_ID_PPB_INSTANCE,
741 instance,
742 host_resource,
743 serialized_frame_info));
746 void PPB_Instance_Proxy::DeliverSamples(
747 PP_Instance instance,
748 PP_Resource decrypted_samples,
749 const PP_DecryptedSampleInfo* sample_info) {
750 PP_Resource host_resource = 0;
751 if (decrypted_samples != 0) {
752 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
753 Resource* object = tracker->GetResource(decrypted_samples);
755 if (!object || object->pp_instance() != instance) {
756 NOTREACHED();
757 return;
760 host_resource = object->host_resource().host_resource();
763 std::string serialized_sample_info;
764 if (!SerializeBlockInfo(*sample_info, &serialized_sample_info)) {
765 NOTREACHED();
766 return;
769 dispatcher()->Send(
770 new PpapiHostMsg_PPBInstance_DeliverSamples(API_ID_PPB_INSTANCE,
771 instance,
772 host_resource,
773 serialized_sample_info));
775 #endif // !defined(OS_NACL)
777 void PPB_Instance_Proxy::PostMessage(PP_Instance instance,
778 PP_Var message) {
779 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage(
780 API_ID_PPB_INSTANCE,
781 instance, SerializedVarSendInputShmem(dispatcher(), message,
782 instance)));
785 int32_t PPB_Instance_Proxy::RegisterMessageHandler(
786 PP_Instance instance,
787 void* user_data,
788 const PPP_MessageHandler_0_2* handler,
789 PP_Resource message_loop) {
790 InstanceData* data =
791 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
792 if (!data)
793 return PP_ERROR_BADARGUMENT;
795 int32_t result = PP_ERROR_FAILED;
796 scoped_ptr<MessageHandler> message_handler = MessageHandler::Create(
797 instance, handler, user_data, message_loop, &result);
798 if (message_handler)
799 data->message_handler = message_handler.Pass();
800 return result;
803 void PPB_Instance_Proxy::UnregisterMessageHandler(PP_Instance instance) {
804 InstanceData* data =
805 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
806 if (!data)
807 return;
808 data->message_handler.reset();
811 PP_Bool PPB_Instance_Proxy::SetCursor(PP_Instance instance,
812 PP_MouseCursor_Type type,
813 PP_Resource image,
814 const PP_Point* hot_spot) {
815 // Some of these parameters are important for security. This check is in the
816 // plugin process just for the convenience of the caller (since we don't
817 // bother returning errors from the other process with a sync message). The
818 // parameters will be validated again in the renderer.
819 if (!ValidateSetCursorParams(type, image, hot_spot))
820 return PP_FALSE;
822 HostResource image_host_resource;
823 if (image) {
824 Resource* cursor_image =
825 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image);
826 if (!cursor_image || cursor_image->pp_instance() != instance)
827 return PP_FALSE;
828 image_host_resource = cursor_image->host_resource();
831 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetCursor(
832 API_ID_PPB_INSTANCE, instance, static_cast<int32_t>(type),
833 image_host_resource, hot_spot ? *hot_spot : PP_MakePoint(0, 0)));
834 return PP_TRUE;
837 int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance,
838 scoped_refptr<TrackedCallback> callback) {
839 // Save the mouse callback on the instance data.
840 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
841 GetInstanceData(instance);
842 if (!data)
843 return PP_ERROR_BADARGUMENT;
844 if (TrackedCallback::IsPending(data->mouse_lock_callback))
845 return PP_ERROR_INPROGRESS; // Already have a pending callback.
846 data->mouse_lock_callback = callback;
848 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LockMouse(
849 API_ID_PPB_INSTANCE, instance));
850 return PP_OK_COMPLETIONPENDING;
853 void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance) {
854 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UnlockMouse(
855 API_ID_PPB_INSTANCE, instance));
858 void PPB_Instance_Proxy::SetTextInputType(PP_Instance instance,
859 PP_TextInput_Type type) {
860 CancelAnyPendingRequestSurroundingText(instance);
861 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTextInputType(
862 API_ID_PPB_INSTANCE, instance, type));
865 void PPB_Instance_Proxy::UpdateCaretPosition(PP_Instance instance,
866 const PP_Rect& caret,
867 const PP_Rect& bounding_box) {
868 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateCaretPosition(
869 API_ID_PPB_INSTANCE, instance, caret, bounding_box));
872 void PPB_Instance_Proxy::CancelCompositionText(PP_Instance instance) {
873 CancelAnyPendingRequestSurroundingText(instance);
874 dispatcher()->Send(new PpapiHostMsg_PPBInstance_CancelCompositionText(
875 API_ID_PPB_INSTANCE, instance));
878 void PPB_Instance_Proxy::SelectionChanged(PP_Instance instance) {
879 // The "right" way to do this is to send the message to the host. However,
880 // all it will do is call RequestSurroundingText with a hardcoded number of
881 // characters in response, which is an entire IPC round-trip.
883 // We can avoid this round-trip by just implementing the
884 // RequestSurroundingText logic in the plugin process. If the logic in the
885 // host becomes more complex (like a more adaptive number of characters),
886 // we'll need to reevanuate whether we want to do the round trip instead.
888 // Be careful to post a task to avoid reentering the plugin.
890 InstanceData* data =
891 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
892 if (!data)
893 return;
894 data->should_do_request_surrounding_text = true;
896 if (!data->is_request_surrounding_text_pending) {
897 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
898 FROM_HERE,
899 RunWhileLocked(base::Bind(&RequestSurroundingText, instance)));
900 data->is_request_surrounding_text_pending = true;
904 void PPB_Instance_Proxy::UpdateSurroundingText(PP_Instance instance,
905 const char* text,
906 uint32_t caret,
907 uint32_t anchor) {
908 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateSurroundingText(
909 API_ID_PPB_INSTANCE, instance, text, caret, anchor));
912 #if !defined(OS_NACL)
913 void PPB_Instance_Proxy::OnHostMsgGetWindowObject(
914 PP_Instance instance,
915 SerializedVarReturnValue result) {
916 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
917 return;
918 EnterInstanceNoLock enter(instance);
919 if (enter.succeeded())
920 result.Return(dispatcher(), enter.functions()->GetWindowObject(instance));
923 void PPB_Instance_Proxy::OnHostMsgGetOwnerElementObject(
924 PP_Instance instance,
925 SerializedVarReturnValue result) {
926 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
927 return;
928 EnterInstanceNoLock enter(instance);
929 if (enter.succeeded()) {
930 result.Return(dispatcher(),
931 enter.functions()->GetOwnerElementObject(instance));
935 void PPB_Instance_Proxy::OnHostMsgBindGraphics(PP_Instance instance,
936 PP_Resource device) {
937 // Note that we ignroe the return value here. Otherwise, this would need to
938 // be a slow sync call, and the plugin side of the proxy will have already
939 // validated the resources, so we shouldn't see errors here that weren't
940 // already caught.
941 EnterInstanceNoLock enter(instance);
942 if (enter.succeeded())
943 enter.functions()->BindGraphics(instance, device);
946 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputSampleRate(
947 PP_Instance instance, uint32_t* result) {
948 EnterInstanceNoLock enter(instance);
949 if (enter.succeeded())
950 *result = enter.functions()->GetAudioHardwareOutputSampleRate(instance);
953 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputBufferSize(
954 PP_Instance instance, uint32_t* result) {
955 EnterInstanceNoLock enter(instance);
956 if (enter.succeeded())
957 *result = enter.functions()->GetAudioHardwareOutputBufferSize(instance);
960 void PPB_Instance_Proxy::OnHostMsgIsFullFrame(PP_Instance instance,
961 PP_Bool* result) {
962 EnterInstanceNoLock enter(instance);
963 if (enter.succeeded())
964 *result = enter.functions()->IsFullFrame(instance);
967 void PPB_Instance_Proxy::OnHostMsgExecuteScript(
968 PP_Instance instance,
969 SerializedVarReceiveInput script,
970 SerializedVarOutParam out_exception,
971 SerializedVarReturnValue result) {
972 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
973 return;
974 EnterInstanceNoLock enter(instance);
975 if (enter.failed())
976 return;
978 if (dispatcher()->IsPlugin())
979 NOTREACHED();
980 else
981 static_cast<HostDispatcher*>(dispatcher())->set_allow_plugin_reentrancy();
983 result.Return(dispatcher(), enter.functions()->ExecuteScript(
984 instance,
985 script.Get(dispatcher()),
986 out_exception.OutParam(dispatcher())));
989 void PPB_Instance_Proxy::OnHostMsgGetDefaultCharSet(
990 PP_Instance instance,
991 SerializedVarReturnValue result) {
992 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
993 return;
994 EnterInstanceNoLock enter(instance);
995 if (enter.succeeded())
996 result.Return(dispatcher(), enter.functions()->GetDefaultCharSet(instance));
999 void PPB_Instance_Proxy::OnHostMsgSetPluginToHandleFindRequests(
1000 PP_Instance instance) {
1001 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1002 return;
1003 EnterInstanceNoLock enter(instance);
1004 if (enter.succeeded())
1005 enter.functions()->SetPluginToHandleFindRequests(instance);
1008 void PPB_Instance_Proxy::OnHostMsgNumberOfFindResultsChanged(
1009 PP_Instance instance,
1010 int32_t total,
1011 PP_Bool final_result) {
1012 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1013 return;
1014 EnterInstanceNoLock enter(instance);
1015 if (enter.succeeded()) {
1016 enter.functions()->NumberOfFindResultsChanged(
1017 instance, total, final_result);
1021 void PPB_Instance_Proxy::OnHostMsgSelectFindResultChanged(
1022 PP_Instance instance,
1023 int32_t index) {
1024 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1025 return;
1026 EnterInstanceNoLock enter(instance);
1027 if (enter.succeeded())
1028 enter.functions()->SelectedFindResultChanged(instance, index);
1031 void PPB_Instance_Proxy::OnHostMsgSetTickmarks(
1032 PP_Instance instance,
1033 const std::vector<PP_Rect>& tickmarks) {
1034 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1035 return;
1036 const PP_Rect* array = tickmarks.empty() ? NULL : &tickmarks[0];
1037 EnterInstanceNoLock enter(instance);
1038 if (enter.succeeded()) {
1039 enter.functions()->SetTickmarks(instance,
1040 array,
1041 static_cast<uint32_t>(tickmarks.size()));
1045 void PPB_Instance_Proxy::OnHostMsgSetFullscreen(PP_Instance instance,
1046 PP_Bool fullscreen,
1047 PP_Bool* result) {
1048 EnterInstanceNoLock enter(instance);
1049 if (enter.succeeded())
1050 *result = enter.functions()->SetFullscreen(instance, fullscreen);
1054 void PPB_Instance_Proxy::OnHostMsgGetScreenSize(PP_Instance instance,
1055 PP_Bool* result,
1056 PP_Size* size) {
1057 EnterInstanceNoLock enter(instance);
1058 if (enter.succeeded())
1059 *result = enter.functions()->GetScreenSize(instance, size);
1062 void PPB_Instance_Proxy::OnHostMsgRequestInputEvents(PP_Instance instance,
1063 bool is_filtering,
1064 uint32_t event_classes) {
1065 EnterInstanceNoLock enter(instance);
1066 if (enter.succeeded()) {
1067 if (is_filtering)
1068 enter.functions()->RequestFilteringInputEvents(instance, event_classes);
1069 else
1070 enter.functions()->RequestInputEvents(instance, event_classes);
1074 void PPB_Instance_Proxy::OnHostMsgClearInputEvents(PP_Instance instance,
1075 uint32_t event_classes) {
1076 EnterInstanceNoLock enter(instance);
1077 if (enter.succeeded())
1078 enter.functions()->ClearInputEventRequest(instance, event_classes);
1081 void PPB_Instance_Proxy::OnHostMsgStartTrackingLatency(PP_Instance instance) {
1082 EnterInstanceNoLock enter(instance);
1083 if (enter.succeeded())
1084 enter.functions()->StartTrackingLatency(instance);
1087 void PPB_Instance_Proxy::OnHostMsgPostMessage(
1088 PP_Instance instance,
1089 SerializedVarReceiveInput message) {
1090 EnterInstanceNoLock enter(instance);
1091 if (!message.is_valid_var()) {
1092 PpapiGlobals::Get()->LogWithSource(
1093 instance, PP_LOGLEVEL_ERROR, std::string(), kSerializationError);
1094 return;
1097 if (enter.succeeded())
1098 enter.functions()->PostMessage(instance,
1099 message.GetForInstance(dispatcher(),
1100 instance));
1103 void PPB_Instance_Proxy::OnHostMsgLockMouse(PP_Instance instance) {
1104 // Need to be careful to always issue the callback.
1105 pp::CompletionCallback cb = callback_factory_.NewCallback(
1106 &PPB_Instance_Proxy::MouseLockCompleteInHost, instance);
1108 EnterInstanceNoLock enter(instance, cb.pp_completion_callback());
1109 if (enter.succeeded())
1110 enter.SetResult(enter.functions()->LockMouse(instance, enter.callback()));
1113 void PPB_Instance_Proxy::OnHostMsgUnlockMouse(PP_Instance instance) {
1114 EnterInstanceNoLock enter(instance);
1115 if (enter.succeeded())
1116 enter.functions()->UnlockMouse(instance);
1119 void PPB_Instance_Proxy::OnHostMsgGetDocumentURL(
1120 PP_Instance instance,
1121 PP_URLComponents_Dev* components,
1122 SerializedVarReturnValue result) {
1123 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1124 return;
1125 EnterInstanceNoLock enter(instance);
1126 if (enter.succeeded()) {
1127 PP_Var document_url = enter.functions()->GetDocumentURL(instance,
1128 components);
1129 result.Return(dispatcher(), document_url);
1133 void PPB_Instance_Proxy::OnHostMsgResolveRelativeToDocument(
1134 PP_Instance instance,
1135 SerializedVarReceiveInput relative,
1136 SerializedVarReturnValue result) {
1137 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1138 return;
1139 EnterInstanceNoLock enter(instance);
1140 if (enter.succeeded()) {
1141 result.Return(dispatcher(),
1142 enter.functions()->ResolveRelativeToDocument(
1143 instance, relative.Get(dispatcher()), NULL));
1147 void PPB_Instance_Proxy::OnHostMsgDocumentCanRequest(
1148 PP_Instance instance,
1149 SerializedVarReceiveInput url,
1150 PP_Bool* result) {
1151 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1152 return;
1153 EnterInstanceNoLock enter(instance);
1154 if (enter.succeeded()) {
1155 *result = enter.functions()->DocumentCanRequest(instance,
1156 url.Get(dispatcher()));
1160 void PPB_Instance_Proxy::OnHostMsgDocumentCanAccessDocument(PP_Instance active,
1161 PP_Instance target,
1162 PP_Bool* result) {
1163 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1164 return;
1165 EnterInstanceNoLock enter(active);
1166 if (enter.succeeded())
1167 *result = enter.functions()->DocumentCanAccessDocument(active, target);
1170 void PPB_Instance_Proxy::OnHostMsgGetPluginInstanceURL(
1171 PP_Instance instance,
1172 SerializedVarReturnValue result) {
1173 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1174 return;
1175 EnterInstanceNoLock enter(instance);
1176 if (enter.succeeded()) {
1177 result.Return(dispatcher(),
1178 enter.functions()->GetPluginInstanceURL(instance, NULL));
1182 void PPB_Instance_Proxy::OnHostMsgGetPluginReferrerURL(
1183 PP_Instance instance,
1184 SerializedVarReturnValue result) {
1185 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1186 return;
1187 EnterInstanceNoLock enter(instance);
1188 if (enter.succeeded()) {
1189 result.Return(dispatcher(),
1190 enter.functions()->GetPluginReferrerURL(instance, NULL));
1194 void PPB_Instance_Proxy::OnHostMsgPromiseResolved(PP_Instance instance,
1195 uint32_t promise_id) {
1196 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1197 return;
1198 EnterInstanceNoLock enter(instance);
1199 if (enter.succeeded()) {
1200 enter.functions()->PromiseResolved(instance, promise_id);
1204 void PPB_Instance_Proxy::OnHostMsgPromiseResolvedWithSession(
1205 PP_Instance instance,
1206 uint32_t promise_id,
1207 SerializedVarReceiveInput session_id) {
1208 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1209 return;
1210 EnterInstanceNoLock enter(instance);
1211 if (enter.succeeded()) {
1212 enter.functions()->PromiseResolvedWithSession(instance, promise_id,
1213 session_id.Get(dispatcher()));
1217 void PPB_Instance_Proxy::OnHostMsgPromiseRejected(
1218 PP_Instance instance,
1219 uint32_t promise_id,
1220 PP_CdmExceptionCode exception_code,
1221 uint32_t system_code,
1222 SerializedVarReceiveInput error_description) {
1223 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1224 return;
1225 EnterInstanceNoLock enter(instance);
1226 if (enter.succeeded()) {
1227 enter.functions()->PromiseRejected(instance,
1228 promise_id,
1229 exception_code,
1230 system_code,
1231 error_description.Get(dispatcher()));
1235 void PPB_Instance_Proxy::OnHostMsgSessionMessage(
1236 PP_Instance instance,
1237 SerializedVarReceiveInput session_id,
1238 PP_CdmMessageType message_type,
1239 SerializedVarReceiveInput message,
1240 SerializedVarReceiveInput legacy_destination_url) {
1241 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1242 return;
1243 EnterInstanceNoLock enter(instance);
1244 if (enter.succeeded()) {
1245 enter.functions()->SessionMessage(instance, session_id.Get(dispatcher()),
1246 message_type, message.Get(dispatcher()),
1247 legacy_destination_url.Get(dispatcher()));
1251 void PPB_Instance_Proxy::OnHostMsgSessionKeysChange(
1252 PP_Instance instance,
1253 const std::string& session_id,
1254 PP_Bool has_additional_usable_key,
1255 const std::vector<PP_KeyInformation>& key_information) {
1256 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1257 return;
1259 if (key_information.size() > media::limits::kMaxKeyIds) {
1260 NOTREACHED();
1261 return;
1264 EnterInstanceNoLock enter(instance);
1265 if (enter.succeeded()) {
1266 ScopedPPVar session_id_var(ScopedPPVar::PassRef(),
1267 StringVar::StringToPPVar(session_id));
1268 enter.functions()->SessionKeysChange(
1269 instance, session_id_var.get(), has_additional_usable_key,
1270 base::checked_cast<uint32_t>(key_information.size()),
1271 vector_as_array(&key_information));
1275 void PPB_Instance_Proxy::OnHostMsgSessionExpirationChange(
1276 PP_Instance instance,
1277 const std::string& session_id,
1278 PP_Time new_expiry_time) {
1279 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1280 return;
1281 EnterInstanceNoLock enter(instance);
1282 if (enter.succeeded()) {
1283 ScopedPPVar session_id_var(ScopedPPVar::PassRef(),
1284 StringVar::StringToPPVar(session_id));
1285 enter.functions()->SessionExpirationChange(instance, session_id_var.get(),
1286 new_expiry_time);
1290 void PPB_Instance_Proxy::OnHostMsgSessionClosed(
1291 PP_Instance instance,
1292 SerializedVarReceiveInput session_id) {
1293 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1294 return;
1295 EnterInstanceNoLock enter(instance);
1296 if (enter.succeeded()) {
1297 enter.functions()->SessionClosed(instance, session_id.Get(dispatcher()));
1301 void PPB_Instance_Proxy::OnHostMsgLegacySessionError(
1302 PP_Instance instance,
1303 SerializedVarReceiveInput session_id,
1304 PP_CdmExceptionCode exception_code,
1305 uint32_t system_code,
1306 SerializedVarReceiveInput error_description) {
1307 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1308 return;
1309 EnterInstanceNoLock enter(instance);
1310 if (enter.succeeded()) {
1311 enter.functions()->LegacySessionError(
1312 instance, session_id.Get(dispatcher()), exception_code, system_code,
1313 error_description.Get(dispatcher()));
1317 void PPB_Instance_Proxy::OnHostMsgDeliverBlock(
1318 PP_Instance instance,
1319 PP_Resource decrypted_block,
1320 const std::string& serialized_block_info) {
1321 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1322 return;
1323 PP_DecryptedBlockInfo block_info;
1324 if (!DeserializeBlockInfo(serialized_block_info, &block_info))
1325 return;
1327 EnterInstanceNoLock enter(instance);
1328 if (enter.succeeded())
1329 enter.functions()->DeliverBlock(instance, decrypted_block, &block_info);
1332 void PPB_Instance_Proxy::OnHostMsgDecoderInitializeDone(
1333 PP_Instance instance,
1334 PP_DecryptorStreamType decoder_type,
1335 uint32_t request_id,
1336 PP_Bool success) {
1337 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1338 return;
1339 EnterInstanceNoLock enter(instance);
1340 if (enter.succeeded()) {
1341 enter.functions()->DecoderInitializeDone(instance,
1342 decoder_type,
1343 request_id,
1344 success);
1348 void PPB_Instance_Proxy::OnHostMsgDecoderDeinitializeDone(
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()->DecoderDeinitializeDone(instance,
1357 decoder_type,
1358 request_id);
1361 void PPB_Instance_Proxy::OnHostMsgDecoderResetDone(
1362 PP_Instance instance,
1363 PP_DecryptorStreamType decoder_type,
1364 uint32_t request_id) {
1365 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1366 return;
1367 EnterInstanceNoLock enter(instance);
1368 if (enter.succeeded())
1369 enter.functions()->DecoderResetDone(instance, decoder_type, request_id);
1372 void PPB_Instance_Proxy::OnHostMsgDeliverFrame(
1373 PP_Instance instance,
1374 PP_Resource decrypted_frame,
1375 const std::string& serialized_frame_info) {
1376 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1377 return;
1378 PP_DecryptedFrameInfo frame_info;
1379 if (!DeserializeBlockInfo(serialized_frame_info, &frame_info))
1380 return;
1382 EnterInstanceNoLock enter(instance);
1383 if (enter.succeeded())
1384 enter.functions()->DeliverFrame(instance, decrypted_frame, &frame_info);
1387 void PPB_Instance_Proxy::OnHostMsgDeliverSamples(
1388 PP_Instance instance,
1389 PP_Resource audio_frames,
1390 const std::string& serialized_sample_info) {
1391 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1392 return;
1393 PP_DecryptedSampleInfo sample_info;
1394 if (!DeserializeBlockInfo(serialized_sample_info, &sample_info))
1395 return;
1397 EnterInstanceNoLock enter(instance);
1398 if (enter.succeeded())
1399 enter.functions()->DeliverSamples(instance, audio_frames, &sample_info);
1402 void PPB_Instance_Proxy::OnHostMsgSetCursor(
1403 PP_Instance instance,
1404 int32_t type,
1405 const ppapi::HostResource& custom_image,
1406 const PP_Point& hot_spot) {
1407 // This API serves PPB_CursorControl_Dev and PPB_MouseCursor, so is public.
1408 EnterInstanceNoLock enter(instance);
1409 if (enter.succeeded()) {
1410 enter.functions()->SetCursor(
1411 instance, static_cast<PP_MouseCursor_Type>(type),
1412 custom_image.host_resource(), &hot_spot);
1416 void PPB_Instance_Proxy::OnHostMsgSetTextInputType(PP_Instance instance,
1417 PP_TextInput_Type type) {
1418 EnterInstanceNoLock enter(instance);
1419 if (enter.succeeded())
1420 enter.functions()->SetTextInputType(instance, type);
1423 void PPB_Instance_Proxy::OnHostMsgUpdateCaretPosition(
1424 PP_Instance instance,
1425 const PP_Rect& caret,
1426 const PP_Rect& bounding_box) {
1427 EnterInstanceNoLock enter(instance);
1428 if (enter.succeeded())
1429 enter.functions()->UpdateCaretPosition(instance, caret, bounding_box);
1432 void PPB_Instance_Proxy::OnHostMsgCancelCompositionText(PP_Instance instance) {
1433 EnterInstanceNoLock enter(instance);
1434 if (enter.succeeded())
1435 enter.functions()->CancelCompositionText(instance);
1438 void PPB_Instance_Proxy::OnHostMsgUpdateSurroundingText(
1439 PP_Instance instance,
1440 const std::string& text,
1441 uint32_t caret,
1442 uint32_t anchor) {
1443 EnterInstanceNoLock enter(instance);
1444 if (enter.succeeded()) {
1445 enter.functions()->UpdateSurroundingText(instance, text.c_str(), caret,
1446 anchor);
1449 #endif // !defined(OS_NACL)
1451 void PPB_Instance_Proxy::OnPluginMsgMouseLockComplete(PP_Instance instance,
1452 int32_t result) {
1453 if (!dispatcher()->IsPlugin())
1454 return;
1456 // Save the mouse callback on the instance data.
1457 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1458 GetInstanceData(instance);
1459 if (!data)
1460 return; // Instance was probably deleted.
1461 if (!TrackedCallback::IsPending(data->mouse_lock_callback)) {
1462 NOTREACHED();
1463 return;
1465 data->mouse_lock_callback->Run(result);
1468 #if !defined(OS_NACL)
1469 void PPB_Instance_Proxy::MouseLockCompleteInHost(int32_t result,
1470 PP_Instance instance) {
1471 dispatcher()->Send(new PpapiMsg_PPBInstance_MouseLockComplete(
1472 API_ID_PPB_INSTANCE, instance, result));
1474 #endif // !defined(OS_NACL)
1476 void PPB_Instance_Proxy::CancelAnyPendingRequestSurroundingText(
1477 PP_Instance instance) {
1478 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1479 GetInstanceData(instance);
1480 if (!data)
1481 return; // Instance was probably deleted.
1482 data->should_do_request_surrounding_text = false;
1485 } // namespace proxy
1486 } // namespace ppapi