WebViewGuest: Add missing break statement.
[chromium-blink-merge.git] / ppapi / proxy / ppb_instance_proxy.cc
bloba0b4ca31d35ae41e6409413d6cb604c42f2b6d88
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/proxy/ppb_instance_proxy.h"
7 #include "base/memory/ref_counted.h"
8 #include "build/build_config.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/pp_time.h"
11 #include "ppapi/c/pp_var.h"
12 #include "ppapi/c/ppb_audio_config.h"
13 #include "ppapi/c/ppb_instance.h"
14 #include "ppapi/c/ppb_messaging.h"
15 #include "ppapi/c/ppb_mouse_lock.h"
16 #include "ppapi/c/private/pp_content_decryptor.h"
17 #include "ppapi/proxy/broker_resource.h"
18 #include "ppapi/proxy/browser_font_singleton_resource.h"
19 #include "ppapi/proxy/content_decryptor_private_serializer.h"
20 #include "ppapi/proxy/enter_proxy.h"
21 #include "ppapi/proxy/extensions_common_resource.h"
22 #include "ppapi/proxy/file_mapping_resource.h"
23 #include "ppapi/proxy/flash_clipboard_resource.h"
24 #include "ppapi/proxy/flash_file_resource.h"
25 #include "ppapi/proxy/flash_fullscreen_resource.h"
26 #include "ppapi/proxy/flash_resource.h"
27 #include "ppapi/proxy/gamepad_resource.h"
28 #include "ppapi/proxy/host_dispatcher.h"
29 #include "ppapi/proxy/isolated_file_system_private_resource.h"
30 #include "ppapi/proxy/network_proxy_resource.h"
31 #include "ppapi/proxy/pdf_resource.h"
32 #include "ppapi/proxy/plugin_dispatcher.h"
33 #include "ppapi/proxy/ppapi_messages.h"
34 #include "ppapi/proxy/serialized_var.h"
35 #include "ppapi/proxy/truetype_font_singleton_resource.h"
36 #include "ppapi/proxy/uma_private_resource.h"
37 #include "ppapi/shared_impl/ppapi_globals.h"
38 #include "ppapi/shared_impl/ppb_url_util_shared.h"
39 #include "ppapi/shared_impl/ppb_view_shared.h"
40 #include "ppapi/shared_impl/var.h"
41 #include "ppapi/thunk/enter.h"
42 #include "ppapi/thunk/ppb_graphics_2d_api.h"
43 #include "ppapi/thunk/ppb_graphics_3d_api.h"
44 #include "ppapi/thunk/thunk.h"
46 // Windows headers interfere with this file.
47 #ifdef PostMessage
48 #undef PostMessage
49 #endif
51 using ppapi::thunk::EnterInstanceNoLock;
52 using ppapi::thunk::EnterResourceNoLock;
53 using ppapi::thunk::PPB_Graphics2D_API;
54 using ppapi::thunk::PPB_Graphics3D_API;
55 using ppapi::thunk::PPB_Instance_API;
57 namespace ppapi {
58 namespace proxy {
60 namespace {
62 #if !defined(OS_NACL)
63 const char kSerializationError[] = "Failed to convert a PostMessage "
64 "argument from a PP_Var to a Javascript value. It may have cycles or be of "
65 "an unsupported type.";
66 #endif
68 void RequestSurroundingText(PP_Instance instance) {
69 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
70 if (!dispatcher)
71 return; // Instance has gone away while message was pending.
73 InstanceData* data = dispatcher->GetInstanceData(instance);
74 DCHECK(data); // Should have it, since we still have a dispatcher.
75 data->is_request_surrounding_text_pending = false;
76 if (!data->should_do_request_surrounding_text)
77 return;
79 // Just fake out a RequestSurroundingText message to the proxy for the PPP
80 // interface.
81 InterfaceProxy* proxy = dispatcher->GetInterfaceProxy(API_ID_PPP_TEXT_INPUT);
82 if (!proxy)
83 return;
84 proxy->OnMessageReceived(PpapiMsg_PPPTextInput_RequestSurroundingText(
85 API_ID_PPP_TEXT_INPUT, instance,
86 PPB_Instance_Shared::kExtraCharsForTextInput));
89 } // namespace
91 PPB_Instance_Proxy::PPB_Instance_Proxy(Dispatcher* dispatcher)
92 : InterfaceProxy(dispatcher),
93 callback_factory_(this) {
96 PPB_Instance_Proxy::~PPB_Instance_Proxy() {
99 bool PPB_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) {
100 // Prevent the dispatcher from going away during a call to ExecuteScript.
101 // This must happen OUTSIDE of ExecuteScript since the SerializedVars use
102 // the dispatcher upon return of the function (converting the
103 // SerializedVarReturnValue/OutParam to a SerializedVar in the destructor).
104 #if !defined(OS_NACL)
105 ScopedModuleReference death_grip(dispatcher());
106 #endif
108 bool handled = true;
109 IPC_BEGIN_MESSAGE_MAP(PPB_Instance_Proxy, msg)
110 #if !defined(OS_NACL)
111 // Plugin -> Host messages.
112 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetWindowObject,
113 OnHostMsgGetWindowObject)
114 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetOwnerElementObject,
115 OnHostMsgGetOwnerElementObject)
116 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_BindGraphics,
117 OnHostMsgBindGraphics)
118 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_IsFullFrame,
119 OnHostMsgIsFullFrame)
120 IPC_MESSAGE_HANDLER(
121 PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate,
122 OnHostMsgGetAudioHardwareOutputSampleRate)
123 IPC_MESSAGE_HANDLER(
124 PpapiHostMsg_PPBInstance_GetAudioHardwareOutputBufferSize,
125 OnHostMsgGetAudioHardwareOutputBufferSize)
126 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ExecuteScript,
127 OnHostMsgExecuteScript)
128 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDefaultCharSet,
129 OnHostMsgGetDefaultCharSet)
130 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetPluginToHandleFindRequests,
131 OnHostMsgSetPluginToHandleFindRequests);
132 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_NumberOfFindResultsChanged,
133 OnHostMsgNumberOfFindResultsChanged)
134 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SelectFindResultChanged,
135 OnHostMsgSelectFindResultChanged)
136 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetTickmarks,
137 OnHostMsgSetTickmarks)
138 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PostMessage,
139 OnHostMsgPostMessage)
140 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetFullscreen,
141 OnHostMsgSetFullscreen)
142 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetScreenSize,
143 OnHostMsgGetScreenSize)
144 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_RequestInputEvents,
145 OnHostMsgRequestInputEvents)
146 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ClearInputEvents,
147 OnHostMsgClearInputEvents)
148 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_StartTrackingLatency,
149 OnHostMsgStartTrackingLatency)
150 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_LockMouse,
151 OnHostMsgLockMouse)
152 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UnlockMouse,
153 OnHostMsgUnlockMouse)
154 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetCursor,
155 OnHostMsgSetCursor)
156 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetTextInputType,
157 OnHostMsgSetTextInputType)
158 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UpdateCaretPosition,
159 OnHostMsgUpdateCaretPosition)
160 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_CancelCompositionText,
161 OnHostMsgCancelCompositionText)
162 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UpdateSurroundingText,
163 OnHostMsgUpdateSurroundingText)
164 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDocumentURL,
165 OnHostMsgGetDocumentURL)
166 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ResolveRelativeToDocument,
167 OnHostMsgResolveRelativeToDocument)
168 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanRequest,
169 OnHostMsgDocumentCanRequest)
170 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanAccessDocument,
171 OnHostMsgDocumentCanAccessDocument)
172 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginInstanceURL,
173 OnHostMsgGetPluginInstanceURL)
174 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginReferrerURL,
175 OnHostMsgGetPluginReferrerURL)
176 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionCreated,
177 OnHostMsgSessionCreated)
178 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionMessage,
179 OnHostMsgSessionMessage)
180 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionReady,
181 OnHostMsgSessionReady)
182 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionClosed,
183 OnHostMsgSessionClosed)
184 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SessionError,
185 OnHostMsgSessionError)
186 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverBlock,
187 OnHostMsgDeliverBlock)
188 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderInitializeDone,
189 OnHostMsgDecoderInitializeDone)
190 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderDeinitializeDone,
191 OnHostMsgDecoderDeinitializeDone)
192 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DecoderResetDone,
193 OnHostMsgDecoderResetDone)
194 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverFrame,
195 OnHostMsgDeliverFrame)
196 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DeliverSamples,
197 OnHostMsgDeliverSamples)
198 #endif // !defined(OS_NACL)
200 // Host -> Plugin messages.
201 IPC_MESSAGE_HANDLER(PpapiMsg_PPBInstance_MouseLockComplete,
202 OnPluginMsgMouseLockComplete)
204 IPC_MESSAGE_UNHANDLED(handled = false)
205 IPC_END_MESSAGE_MAP()
206 return handled;
209 PP_Bool PPB_Instance_Proxy::BindGraphics(PP_Instance instance,
210 PP_Resource device) {
211 // If device is 0, pass a null HostResource. This signals the host to unbind
212 // all devices.
213 HostResource host_resource;
214 PP_Resource pp_resource = 0;
215 if (device) {
216 Resource* resource =
217 PpapiGlobals::Get()->GetResourceTracker()->GetResource(device);
218 if (!resource || resource->pp_instance() != instance)
219 return PP_FALSE;
220 host_resource = resource->host_resource();
221 pp_resource = resource->pp_resource();
222 } else {
223 // Passing 0 means unbinding all devices.
224 dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
225 API_ID_PPB_INSTANCE, instance, 0));
226 return PP_TRUE;
229 // We need to pass different resource to Graphics 2D and 3D right now. Once
230 // 3D is migrated to the new design, we should be able to unify this.
231 EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false);
232 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false);
233 if (enter_2d.succeeded()) {
234 dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
235 API_ID_PPB_INSTANCE, instance, pp_resource));
236 return PP_TRUE;
237 } else if (enter_3d.succeeded()) {
238 dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
239 API_ID_PPB_INSTANCE, instance, host_resource.host_resource()));
240 return PP_TRUE;
242 return PP_FALSE;
245 PP_Bool PPB_Instance_Proxy::IsFullFrame(PP_Instance instance) {
246 PP_Bool result = PP_FALSE;
247 dispatcher()->Send(new PpapiHostMsg_PPBInstance_IsFullFrame(
248 API_ID_PPB_INSTANCE, instance, &result));
249 return result;
252 const ViewData* PPB_Instance_Proxy::GetViewData(PP_Instance instance) {
253 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
254 GetInstanceData(instance);
255 if (!data)
256 return NULL;
257 return &data->view;
260 PP_Bool PPB_Instance_Proxy::FlashIsFullscreen(PP_Instance instance) {
261 // This function is only used for proxying in the renderer process. It is not
262 // implemented in the plugin process.
263 NOTREACHED();
264 return PP_FALSE;
267 PP_Var PPB_Instance_Proxy::GetWindowObject(PP_Instance instance) {
268 ReceiveSerializedVarReturnValue result;
269 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetWindowObject(
270 API_ID_PPB_INSTANCE, instance, &result));
271 return result.Return(dispatcher());
274 PP_Var PPB_Instance_Proxy::GetOwnerElementObject(PP_Instance instance) {
275 ReceiveSerializedVarReturnValue result;
276 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetOwnerElementObject(
277 API_ID_PPB_INSTANCE, instance, &result));
278 return result.Return(dispatcher());
281 PP_Var PPB_Instance_Proxy::ExecuteScript(PP_Instance instance,
282 PP_Var script,
283 PP_Var* exception) {
284 ReceiveSerializedException se(dispatcher(), exception);
285 if (se.IsThrown())
286 return PP_MakeUndefined();
288 ReceiveSerializedVarReturnValue result;
289 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ExecuteScript(
290 API_ID_PPB_INSTANCE, instance,
291 SerializedVarSendInput(dispatcher(), script), &se, &result));
292 return result.Return(dispatcher());
295 uint32_t PPB_Instance_Proxy::GetAudioHardwareOutputSampleRate(
296 PP_Instance instance) {
297 uint32_t result = PP_AUDIOSAMPLERATE_NONE;
298 dispatcher()->Send(
299 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate(
300 API_ID_PPB_INSTANCE, instance, &result));
301 return result;
304 uint32_t PPB_Instance_Proxy::GetAudioHardwareOutputBufferSize(
305 PP_Instance instance) {
306 uint32_t result = 0;
307 dispatcher()->Send(
308 new PpapiHostMsg_PPBInstance_GetAudioHardwareOutputBufferSize(
309 API_ID_PPB_INSTANCE, instance, &result));
310 return result;
313 PP_Var PPB_Instance_Proxy::GetDefaultCharSet(PP_Instance instance) {
314 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
315 if (!dispatcher)
316 return PP_MakeUndefined();
318 ReceiveSerializedVarReturnValue result;
319 dispatcher->Send(new PpapiHostMsg_PPBInstance_GetDefaultCharSet(
320 API_ID_PPB_INSTANCE, instance, &result));
321 return result.Return(dispatcher);
324 void PPB_Instance_Proxy::SetPluginToHandleFindRequests(PP_Instance instance) {
325 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetPluginToHandleFindRequests(
326 API_ID_PPB_INSTANCE, instance));
329 void PPB_Instance_Proxy::NumberOfFindResultsChanged(PP_Instance instance,
330 int32_t total,
331 PP_Bool final_result) {
332 dispatcher()->Send(new PpapiHostMsg_PPBInstance_NumberOfFindResultsChanged(
333 API_ID_PPB_INSTANCE, instance, total, final_result));
336 void PPB_Instance_Proxy::SelectedFindResultChanged(PP_Instance instance,
337 int32_t index) {
338 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SelectFindResultChanged(
339 API_ID_PPB_INSTANCE, instance, index));
342 void PPB_Instance_Proxy::SetTickmarks(PP_Instance instance,
343 const PP_Rect* tickmarks,
344 uint32_t count) {
345 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTickmarks(
346 API_ID_PPB_INSTANCE, instance,
347 std::vector<PP_Rect>(tickmarks, tickmarks + count)));
350 PP_Bool PPB_Instance_Proxy::IsFullscreen(PP_Instance instance) {
351 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
352 GetInstanceData(instance);
353 if (!data)
354 return PP_FALSE;
355 return PP_FromBool(data->view.is_fullscreen);
358 PP_Bool PPB_Instance_Proxy::SetFullscreen(PP_Instance instance,
359 PP_Bool fullscreen) {
360 PP_Bool result = PP_FALSE;
361 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetFullscreen(
362 API_ID_PPB_INSTANCE, instance, fullscreen, &result));
363 return result;
366 PP_Bool PPB_Instance_Proxy::GetScreenSize(PP_Instance instance,
367 PP_Size* size) {
368 PP_Bool result = PP_FALSE;
369 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetScreenSize(
370 API_ID_PPB_INSTANCE, instance, &result, size));
371 return result;
374 Resource* PPB_Instance_Proxy::GetSingletonResource(PP_Instance instance,
375 SingletonResourceID id) {
376 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
377 GetInstanceData(instance);
379 InstanceData::SingletonResourceMap::iterator it =
380 data->singleton_resources.find(id);
381 if (it != data->singleton_resources.end())
382 return it->second.get();
384 scoped_refptr<Resource> new_singleton;
385 Connection connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher());
387 switch (id) {
388 case BROKER_SINGLETON_ID:
389 new_singleton = new BrokerResource(connection, instance);
390 break;
391 case EXTENSIONS_COMMON_SINGLETON_ID:
392 new_singleton = new ExtensionsCommonResource(connection, instance);
393 break;
394 case FILE_MAPPING_SINGLETON_ID:
395 new_singleton = new FileMappingResource(connection, instance);
396 break;
397 case GAMEPAD_SINGLETON_ID:
398 new_singleton = new GamepadResource(connection, instance);
399 break;
400 case ISOLATED_FILESYSTEM_SINGLETON_ID:
401 new_singleton =
402 new IsolatedFileSystemPrivateResource(connection, instance);
403 break;
404 case NETWORK_PROXY_SINGLETON_ID:
405 new_singleton = new NetworkProxyResource(connection, instance);
406 break;
407 case TRUETYPE_FONT_SINGLETON_ID:
408 new_singleton = new TrueTypeFontSingletonResource(connection, instance);
409 break;
410 case UMA_SINGLETON_ID:
411 new_singleton = new UMAPrivateResource(connection, instance);
412 break;
413 // Flash/trusted resources aren't needed for NaCl.
414 #if !defined(OS_NACL) && !defined(NACL_WIN64)
415 case BROWSER_FONT_SINGLETON_ID:
416 new_singleton = new BrowserFontSingletonResource(connection, instance);
417 break;
418 case FLASH_CLIPBOARD_SINGLETON_ID:
419 new_singleton = new FlashClipboardResource(connection, instance);
420 break;
421 case FLASH_FILE_SINGLETON_ID:
422 new_singleton = new FlashFileResource(connection, instance);
423 break;
424 case FLASH_FULLSCREEN_SINGLETON_ID:
425 new_singleton = new FlashFullscreenResource(connection, instance);
426 break;
427 case FLASH_SINGLETON_ID:
428 new_singleton = new FlashResource(connection, instance,
429 static_cast<PluginDispatcher*>(dispatcher()));
430 break;
431 case PDF_SINGLETON_ID:
432 new_singleton = new PDFResource(connection, instance);
433 break;
434 #else
435 case BROWSER_FONT_SINGLETON_ID:
436 case FLASH_CLIPBOARD_SINGLETON_ID:
437 case FLASH_FILE_SINGLETON_ID:
438 case FLASH_FULLSCREEN_SINGLETON_ID:
439 case FLASH_SINGLETON_ID:
440 case PDF_SINGLETON_ID:
441 NOTREACHED();
442 break;
443 #endif // !defined(OS_NACL) && !defined(NACL_WIN64)
446 if (!new_singleton.get()) {
447 // Getting here implies that a constructor is missing in the above switch.
448 NOTREACHED();
449 return NULL;
452 data->singleton_resources[id] = new_singleton;
453 return new_singleton.get();
456 int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance,
457 uint32_t event_classes) {
458 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
459 API_ID_PPB_INSTANCE, instance, false, event_classes));
461 // We always register for the classes we can handle, this function validates
462 // the flags so we can notify it if anything was invalid, without requiring
463 // a sync reply.
464 return ValidateRequestInputEvents(false, event_classes);
467 int32_t PPB_Instance_Proxy::RequestFilteringInputEvents(
468 PP_Instance instance,
469 uint32_t event_classes) {
470 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
471 API_ID_PPB_INSTANCE, instance, true, event_classes));
473 // We always register for the classes we can handle, this function validates
474 // the flags so we can notify it if anything was invalid, without requiring
475 // a sync reply.
476 return ValidateRequestInputEvents(true, event_classes);
479 void PPB_Instance_Proxy::ClearInputEventRequest(PP_Instance instance,
480 uint32_t event_classes) {
481 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ClearInputEvents(
482 API_ID_PPB_INSTANCE, instance, event_classes));
485 void PPB_Instance_Proxy::StartTrackingLatency(PP_Instance instance) {
486 dispatcher()->Send(new PpapiHostMsg_PPBInstance_StartTrackingLatency(
487 API_ID_PPB_INSTANCE, instance));
490 void PPB_Instance_Proxy::ZoomChanged(PP_Instance instance,
491 double factor) {
492 // Not proxied yet.
493 NOTIMPLEMENTED();
496 void PPB_Instance_Proxy::ZoomLimitsChanged(PP_Instance instance,
497 double minimum_factor,
498 double maximium_factor) {
499 // Not proxied yet.
500 NOTIMPLEMENTED();
503 PP_Var PPB_Instance_Proxy::GetDocumentURL(PP_Instance instance,
504 PP_URLComponents_Dev* components) {
505 ReceiveSerializedVarReturnValue result;
506 PP_URLComponents_Dev url_components;
507 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetDocumentURL(
508 API_ID_PPB_INSTANCE, instance, &url_components, &result));
509 if (components)
510 *components = url_components;
511 return result.Return(dispatcher());
514 #if !defined(OS_NACL)
515 PP_Var PPB_Instance_Proxy::ResolveRelativeToDocument(
516 PP_Instance instance,
517 PP_Var relative,
518 PP_URLComponents_Dev* components) {
519 ReceiveSerializedVarReturnValue result;
520 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ResolveRelativeToDocument(
521 API_ID_PPB_INSTANCE, instance,
522 SerializedVarSendInput(dispatcher(), relative),
523 &result));
524 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
525 result.Return(dispatcher()),
526 components);
529 PP_Bool PPB_Instance_Proxy::DocumentCanRequest(PP_Instance instance,
530 PP_Var url) {
531 PP_Bool result = PP_FALSE;
532 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanRequest(
533 API_ID_PPB_INSTANCE, instance,
534 SerializedVarSendInput(dispatcher(), url),
535 &result));
536 return result;
539 PP_Bool PPB_Instance_Proxy::DocumentCanAccessDocument(PP_Instance instance,
540 PP_Instance target) {
541 PP_Bool result = PP_FALSE;
542 dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanAccessDocument(
543 API_ID_PPB_INSTANCE, instance, target, &result));
544 return result;
547 PP_Var PPB_Instance_Proxy::GetPluginInstanceURL(
548 PP_Instance instance,
549 PP_URLComponents_Dev* components) {
550 ReceiveSerializedVarReturnValue result;
551 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginInstanceURL(
552 API_ID_PPB_INSTANCE, instance, &result));
553 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
554 result.Return(dispatcher()),
555 components);
558 PP_Var PPB_Instance_Proxy::GetPluginReferrerURL(
559 PP_Instance instance,
560 PP_URLComponents_Dev* components) {
561 ReceiveSerializedVarReturnValue result;
562 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginReferrerURL(
563 API_ID_PPB_INSTANCE, instance, &result));
564 return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL(
565 result.Return(dispatcher()),
566 components);
569 void PPB_Instance_Proxy::SessionCreated(PP_Instance instance,
570 uint32_t session_id,
571 PP_Var web_session_id) {
572 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionCreated(
573 API_ID_PPB_INSTANCE,
574 instance,
575 session_id,
576 SerializedVarSendInput(dispatcher(), web_session_id)));
579 void PPB_Instance_Proxy::SessionMessage(PP_Instance instance,
580 uint32_t session_id,
581 PP_Var message,
582 PP_Var destination_url) {
583 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionMessage(
584 API_ID_PPB_INSTANCE,
585 instance,
586 session_id,
587 SerializedVarSendInput(dispatcher(), message),
588 SerializedVarSendInput(dispatcher(), destination_url)));
591 void PPB_Instance_Proxy::SessionReady(PP_Instance instance,
592 uint32_t session_id) {
593 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionReady(
594 API_ID_PPB_INSTANCE, instance, session_id));
597 void PPB_Instance_Proxy::SessionClosed(PP_Instance instance,
598 uint32_t session_id) {
599 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionClosed(
600 API_ID_PPB_INSTANCE, instance, session_id));
603 void PPB_Instance_Proxy::SessionError(PP_Instance instance,
604 uint32_t session_id,
605 int32_t media_error,
606 uint32_t system_code) {
607 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SessionError(
608 API_ID_PPB_INSTANCE, instance, session_id, media_error, system_code));
611 void PPB_Instance_Proxy::DeliverBlock(PP_Instance instance,
612 PP_Resource decrypted_block,
613 const PP_DecryptedBlockInfo* block_info) {
614 PP_Resource decrypted_block_host_resource = 0;
616 if (decrypted_block) {
617 Resource* object =
618 PpapiGlobals::Get()->GetResourceTracker()->GetResource(decrypted_block);
619 if (!object || object->pp_instance() != instance) {
620 NOTREACHED();
621 return;
623 decrypted_block_host_resource = object->host_resource().host_resource();
626 std::string serialized_block_info;
627 if (!SerializeBlockInfo(*block_info, &serialized_block_info)) {
628 NOTREACHED();
629 return;
632 dispatcher()->Send(
633 new PpapiHostMsg_PPBInstance_DeliverBlock(API_ID_PPB_INSTANCE,
634 instance,
635 decrypted_block_host_resource,
636 serialized_block_info));
639 void PPB_Instance_Proxy::DecoderInitializeDone(
640 PP_Instance instance,
641 PP_DecryptorStreamType decoder_type,
642 uint32_t request_id,
643 PP_Bool success) {
644 dispatcher()->Send(
645 new PpapiHostMsg_PPBInstance_DecoderInitializeDone(
646 API_ID_PPB_INSTANCE,
647 instance,
648 decoder_type,
649 request_id,
650 success));
653 void PPB_Instance_Proxy::DecoderDeinitializeDone(
654 PP_Instance instance,
655 PP_DecryptorStreamType decoder_type,
656 uint32_t request_id) {
657 dispatcher()->Send(
658 new PpapiHostMsg_PPBInstance_DecoderDeinitializeDone(
659 API_ID_PPB_INSTANCE,
660 instance,
661 decoder_type,
662 request_id));
665 void PPB_Instance_Proxy::DecoderResetDone(PP_Instance instance,
666 PP_DecryptorStreamType decoder_type,
667 uint32_t request_id) {
668 dispatcher()->Send(
669 new PpapiHostMsg_PPBInstance_DecoderResetDone(
670 API_ID_PPB_INSTANCE,
671 instance,
672 decoder_type,
673 request_id));
676 void PPB_Instance_Proxy::DeliverFrame(PP_Instance instance,
677 PP_Resource decrypted_frame,
678 const PP_DecryptedFrameInfo* frame_info) {
679 PP_Resource host_resource = 0;
680 if (decrypted_frame != 0) {
681 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
682 Resource* object = tracker->GetResource(decrypted_frame);
684 if (!object || object->pp_instance() != instance) {
685 NOTREACHED();
686 return;
689 host_resource = object->host_resource().host_resource();
692 std::string serialized_frame_info;
693 if (!SerializeBlockInfo(*frame_info, &serialized_frame_info)) {
694 NOTREACHED();
695 return;
698 dispatcher()->Send(
699 new PpapiHostMsg_PPBInstance_DeliverFrame(API_ID_PPB_INSTANCE,
700 instance,
701 host_resource,
702 serialized_frame_info));
705 void PPB_Instance_Proxy::DeliverSamples(
706 PP_Instance instance,
707 PP_Resource decrypted_samples,
708 const PP_DecryptedSampleInfo* sample_info) {
709 PP_Resource host_resource = 0;
710 if (decrypted_samples != 0) {
711 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
712 Resource* object = tracker->GetResource(decrypted_samples);
714 if (!object || object->pp_instance() != instance) {
715 NOTREACHED();
716 return;
719 host_resource = object->host_resource().host_resource();
722 std::string serialized_sample_info;
723 if (!SerializeBlockInfo(*sample_info, &serialized_sample_info)) {
724 NOTREACHED();
725 return;
728 dispatcher()->Send(
729 new PpapiHostMsg_PPBInstance_DeliverSamples(API_ID_PPB_INSTANCE,
730 instance,
731 host_resource,
732 serialized_sample_info));
734 #endif // !defined(OS_NACL)
736 void PPB_Instance_Proxy::PostMessage(PP_Instance instance,
737 PP_Var message) {
738 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage(
739 API_ID_PPB_INSTANCE,
740 instance, SerializedVarSendInputShmem(dispatcher(), message,
741 instance)));
743 int32_t PPB_Instance_Proxy::RegisterMessageHandler(
744 PP_Instance instance,
745 void* user_data,
746 const PPP_MessageHandler_0_1* handler,
747 PP_Resource message_loop) {
748 // Not yet implemented. See crbug.com/367896
749 return PP_ERROR_NOTSUPPORTED;
752 void PPB_Instance_Proxy::UnregisterMessageHandler(PP_Instance instance) {
753 // Not yet implemented. See crbug.com/367896
756 PP_Bool PPB_Instance_Proxy::SetCursor(PP_Instance instance,
757 PP_MouseCursor_Type type,
758 PP_Resource image,
759 const PP_Point* hot_spot) {
760 // Some of these parameters are important for security. This check is in the
761 // plugin process just for the convenience of the caller (since we don't
762 // bother returning errors from the other process with a sync message). The
763 // parameters will be validated again in the renderer.
764 if (!ValidateSetCursorParams(type, image, hot_spot))
765 return PP_FALSE;
767 HostResource image_host_resource;
768 if (image) {
769 Resource* cursor_image =
770 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image);
771 if (!cursor_image || cursor_image->pp_instance() != instance)
772 return PP_FALSE;
773 image_host_resource = cursor_image->host_resource();
776 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetCursor(
777 API_ID_PPB_INSTANCE, instance, static_cast<int32_t>(type),
778 image_host_resource, hot_spot ? *hot_spot : PP_MakePoint(0, 0)));
779 return PP_TRUE;
782 int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance,
783 scoped_refptr<TrackedCallback> callback) {
784 // Save the mouse callback on the instance data.
785 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
786 GetInstanceData(instance);
787 if (!data)
788 return PP_ERROR_BADARGUMENT;
789 if (TrackedCallback::IsPending(data->mouse_lock_callback))
790 return PP_ERROR_INPROGRESS; // Already have a pending callback.
791 data->mouse_lock_callback = callback;
793 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LockMouse(
794 API_ID_PPB_INSTANCE, instance));
795 return PP_OK_COMPLETIONPENDING;
798 void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance) {
799 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UnlockMouse(
800 API_ID_PPB_INSTANCE, instance));
803 void PPB_Instance_Proxy::SetTextInputType(PP_Instance instance,
804 PP_TextInput_Type type) {
805 CancelAnyPendingRequestSurroundingText(instance);
806 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetTextInputType(
807 API_ID_PPB_INSTANCE, instance, type));
810 void PPB_Instance_Proxy::UpdateCaretPosition(PP_Instance instance,
811 const PP_Rect& caret,
812 const PP_Rect& bounding_box) {
813 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateCaretPosition(
814 API_ID_PPB_INSTANCE, instance, caret, bounding_box));
817 void PPB_Instance_Proxy::CancelCompositionText(PP_Instance instance) {
818 CancelAnyPendingRequestSurroundingText(instance);
819 dispatcher()->Send(new PpapiHostMsg_PPBInstance_CancelCompositionText(
820 API_ID_PPB_INSTANCE, instance));
823 void PPB_Instance_Proxy::SelectionChanged(PP_Instance instance) {
824 // The "right" way to do this is to send the message to the host. However,
825 // all it will do is call RequestSurroundingText with a hardcoded number of
826 // characters in response, which is an entire IPC round-trip.
828 // We can avoid this round-trip by just implementing the
829 // RequestSurroundingText logic in the plugin process. If the logic in the
830 // host becomes more complex (like a more adaptive number of characters),
831 // we'll need to reevanuate whether we want to do the round trip instead.
833 // Be careful to post a task to avoid reentering the plugin.
835 InstanceData* data =
836 static_cast<PluginDispatcher*>(dispatcher())->GetInstanceData(instance);
837 if (!data)
838 return;
839 data->should_do_request_surrounding_text = true;
841 if (!data->is_request_surrounding_text_pending) {
842 base::MessageLoop::current()->PostTask(
843 FROM_HERE,
844 RunWhileLocked(base::Bind(&RequestSurroundingText, instance)));
845 data->is_request_surrounding_text_pending = true;
849 void PPB_Instance_Proxy::UpdateSurroundingText(PP_Instance instance,
850 const char* text,
851 uint32_t caret,
852 uint32_t anchor) {
853 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UpdateSurroundingText(
854 API_ID_PPB_INSTANCE, instance, text, caret, anchor));
857 #if !defined(OS_NACL)
858 void PPB_Instance_Proxy::OnHostMsgGetWindowObject(
859 PP_Instance instance,
860 SerializedVarReturnValue result) {
861 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
862 return;
863 EnterInstanceNoLock enter(instance);
864 if (enter.succeeded())
865 result.Return(dispatcher(), enter.functions()->GetWindowObject(instance));
868 void PPB_Instance_Proxy::OnHostMsgGetOwnerElementObject(
869 PP_Instance instance,
870 SerializedVarReturnValue result) {
871 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
872 return;
873 EnterInstanceNoLock enter(instance);
874 if (enter.succeeded()) {
875 result.Return(dispatcher(),
876 enter.functions()->GetOwnerElementObject(instance));
880 void PPB_Instance_Proxy::OnHostMsgBindGraphics(PP_Instance instance,
881 PP_Resource device) {
882 // Note that we ignroe the return value here. Otherwise, this would need to
883 // be a slow sync call, and the plugin side of the proxy will have already
884 // validated the resources, so we shouldn't see errors here that weren't
885 // already caught.
886 EnterInstanceNoLock enter(instance);
887 if (enter.succeeded())
888 enter.functions()->BindGraphics(instance, device);
891 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputSampleRate(
892 PP_Instance instance, uint32_t* result) {
893 EnterInstanceNoLock enter(instance);
894 if (enter.succeeded())
895 *result = enter.functions()->GetAudioHardwareOutputSampleRate(instance);
898 void PPB_Instance_Proxy::OnHostMsgGetAudioHardwareOutputBufferSize(
899 PP_Instance instance, uint32_t* result) {
900 EnterInstanceNoLock enter(instance);
901 if (enter.succeeded())
902 *result = enter.functions()->GetAudioHardwareOutputBufferSize(instance);
905 void PPB_Instance_Proxy::OnHostMsgIsFullFrame(PP_Instance instance,
906 PP_Bool* result) {
907 EnterInstanceNoLock enter(instance);
908 if (enter.succeeded())
909 *result = enter.functions()->IsFullFrame(instance);
912 void PPB_Instance_Proxy::OnHostMsgExecuteScript(
913 PP_Instance instance,
914 SerializedVarReceiveInput script,
915 SerializedVarOutParam out_exception,
916 SerializedVarReturnValue result) {
917 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
918 return;
919 EnterInstanceNoLock enter(instance);
920 if (enter.failed())
921 return;
923 if (dispatcher()->IsPlugin())
924 NOTREACHED();
925 else
926 static_cast<HostDispatcher*>(dispatcher())->set_allow_plugin_reentrancy();
928 result.Return(dispatcher(), enter.functions()->ExecuteScript(
929 instance,
930 script.Get(dispatcher()),
931 out_exception.OutParam(dispatcher())));
934 void PPB_Instance_Proxy::OnHostMsgGetDefaultCharSet(
935 PP_Instance instance,
936 SerializedVarReturnValue result) {
937 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
938 return;
939 EnterInstanceNoLock enter(instance);
940 if (enter.succeeded())
941 result.Return(dispatcher(), enter.functions()->GetDefaultCharSet(instance));
944 void PPB_Instance_Proxy::OnHostMsgSetPluginToHandleFindRequests(
945 PP_Instance instance) {
946 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
947 return;
948 EnterInstanceNoLock enter(instance);
949 if (enter.succeeded())
950 enter.functions()->SetPluginToHandleFindRequests(instance);
953 void PPB_Instance_Proxy::OnHostMsgNumberOfFindResultsChanged(
954 PP_Instance instance,
955 int32_t total,
956 PP_Bool final_result) {
957 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
958 return;
959 EnterInstanceNoLock enter(instance);
960 if (enter.succeeded()) {
961 enter.functions()->NumberOfFindResultsChanged(
962 instance, total, final_result);
966 void PPB_Instance_Proxy::OnHostMsgSelectFindResultChanged(
967 PP_Instance instance,
968 int32_t index) {
969 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
970 return;
971 EnterInstanceNoLock enter(instance);
972 if (enter.succeeded())
973 enter.functions()->SelectedFindResultChanged(instance, index);
976 void PPB_Instance_Proxy::OnHostMsgSetTickmarks(
977 PP_Instance instance,
978 const std::vector<PP_Rect>& tickmarks) {
979 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
980 return;
981 const PP_Rect* array = tickmarks.empty() ? NULL : &tickmarks[0];
982 EnterInstanceNoLock enter(instance);
983 if (enter.succeeded()) {
984 enter.functions()->SetTickmarks(instance,
985 array,
986 static_cast<uint32_t>(tickmarks.size()));
990 void PPB_Instance_Proxy::OnHostMsgSetFullscreen(PP_Instance instance,
991 PP_Bool fullscreen,
992 PP_Bool* result) {
993 EnterInstanceNoLock enter(instance);
994 if (enter.succeeded())
995 *result = enter.functions()->SetFullscreen(instance, fullscreen);
999 void PPB_Instance_Proxy::OnHostMsgGetScreenSize(PP_Instance instance,
1000 PP_Bool* result,
1001 PP_Size* size) {
1002 EnterInstanceNoLock enter(instance);
1003 if (enter.succeeded())
1004 *result = enter.functions()->GetScreenSize(instance, size);
1007 void PPB_Instance_Proxy::OnHostMsgRequestInputEvents(PP_Instance instance,
1008 bool is_filtering,
1009 uint32_t event_classes) {
1010 EnterInstanceNoLock enter(instance);
1011 if (enter.succeeded()) {
1012 if (is_filtering)
1013 enter.functions()->RequestFilteringInputEvents(instance, event_classes);
1014 else
1015 enter.functions()->RequestInputEvents(instance, event_classes);
1019 void PPB_Instance_Proxy::OnHostMsgClearInputEvents(PP_Instance instance,
1020 uint32_t event_classes) {
1021 EnterInstanceNoLock enter(instance);
1022 if (enter.succeeded())
1023 enter.functions()->ClearInputEventRequest(instance, event_classes);
1026 void PPB_Instance_Proxy::OnHostMsgStartTrackingLatency(PP_Instance instance) {
1027 EnterInstanceNoLock enter(instance);
1028 if (enter.succeeded())
1029 enter.functions()->StartTrackingLatency(instance);
1032 void PPB_Instance_Proxy::OnHostMsgPostMessage(
1033 PP_Instance instance,
1034 SerializedVarReceiveInput message) {
1035 EnterInstanceNoLock enter(instance);
1036 if (!message.is_valid_var()) {
1037 PpapiGlobals::Get()->LogWithSource(
1038 instance, PP_LOGLEVEL_ERROR, std::string(), kSerializationError);
1039 return;
1042 if (enter.succeeded())
1043 enter.functions()->PostMessage(instance,
1044 message.GetForInstance(dispatcher(),
1045 instance));
1048 void PPB_Instance_Proxy::OnHostMsgLockMouse(PP_Instance instance) {
1049 // Need to be careful to always issue the callback.
1050 pp::CompletionCallback cb = callback_factory_.NewCallback(
1051 &PPB_Instance_Proxy::MouseLockCompleteInHost, instance);
1053 EnterInstanceNoLock enter(instance, cb.pp_completion_callback());
1054 if (enter.succeeded())
1055 enter.SetResult(enter.functions()->LockMouse(instance, enter.callback()));
1058 void PPB_Instance_Proxy::OnHostMsgUnlockMouse(PP_Instance instance) {
1059 EnterInstanceNoLock enter(instance);
1060 if (enter.succeeded())
1061 enter.functions()->UnlockMouse(instance);
1064 void PPB_Instance_Proxy::OnHostMsgGetDocumentURL(
1065 PP_Instance instance,
1066 PP_URLComponents_Dev* components,
1067 SerializedVarReturnValue result) {
1068 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1069 return;
1070 EnterInstanceNoLock enter(instance);
1071 if (enter.succeeded()) {
1072 PP_Var document_url = enter.functions()->GetDocumentURL(instance,
1073 components);
1074 result.Return(dispatcher(), document_url);
1078 void PPB_Instance_Proxy::OnHostMsgResolveRelativeToDocument(
1079 PP_Instance instance,
1080 SerializedVarReceiveInput relative,
1081 SerializedVarReturnValue result) {
1082 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1083 return;
1084 EnterInstanceNoLock enter(instance);
1085 if (enter.succeeded()) {
1086 result.Return(dispatcher(),
1087 enter.functions()->ResolveRelativeToDocument(
1088 instance, relative.Get(dispatcher()), NULL));
1092 void PPB_Instance_Proxy::OnHostMsgDocumentCanRequest(
1093 PP_Instance instance,
1094 SerializedVarReceiveInput url,
1095 PP_Bool* result) {
1096 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1097 return;
1098 EnterInstanceNoLock enter(instance);
1099 if (enter.succeeded()) {
1100 *result = enter.functions()->DocumentCanRequest(instance,
1101 url.Get(dispatcher()));
1105 void PPB_Instance_Proxy::OnHostMsgDocumentCanAccessDocument(PP_Instance active,
1106 PP_Instance target,
1107 PP_Bool* result) {
1108 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1109 return;
1110 EnterInstanceNoLock enter(active);
1111 if (enter.succeeded())
1112 *result = enter.functions()->DocumentCanAccessDocument(active, target);
1115 void PPB_Instance_Proxy::OnHostMsgGetPluginInstanceURL(
1116 PP_Instance instance,
1117 SerializedVarReturnValue result) {
1118 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1119 return;
1120 EnterInstanceNoLock enter(instance);
1121 if (enter.succeeded()) {
1122 result.Return(dispatcher(),
1123 enter.functions()->GetPluginInstanceURL(instance, NULL));
1127 void PPB_Instance_Proxy::OnHostMsgGetPluginReferrerURL(
1128 PP_Instance instance,
1129 SerializedVarReturnValue result) {
1130 if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
1131 return;
1132 EnterInstanceNoLock enter(instance);
1133 if (enter.succeeded()) {
1134 result.Return(dispatcher(),
1135 enter.functions()->GetPluginReferrerURL(instance, NULL));
1139 void PPB_Instance_Proxy::OnHostMsgSessionCreated(
1140 PP_Instance instance,
1141 uint32_t session_id,
1142 SerializedVarReceiveInput web_session_id) {
1143 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1144 return;
1145 EnterInstanceNoLock enter(instance);
1146 if (enter.succeeded()) {
1147 enter.functions()->SessionCreated(
1148 instance, session_id, web_session_id.Get(dispatcher()));
1152 void PPB_Instance_Proxy::OnHostMsgSessionMessage(
1153 PP_Instance instance,
1154 uint32_t session_id,
1155 SerializedVarReceiveInput message,
1156 SerializedVarReceiveInput destination_url) {
1157 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1158 return;
1159 EnterInstanceNoLock enter(instance);
1160 if (enter.succeeded()) {
1161 enter.functions()->SessionMessage(instance,
1162 session_id,
1163 message.Get(dispatcher()),
1164 destination_url.Get(dispatcher()));
1168 void PPB_Instance_Proxy::OnHostMsgSessionReady(PP_Instance instance,
1169 uint32_t session_id) {
1170 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1171 return;
1172 EnterInstanceNoLock enter(instance);
1173 if (enter.succeeded()) {
1174 enter.functions()->SessionReady(instance, session_id);
1178 void PPB_Instance_Proxy::OnHostMsgSessionClosed(PP_Instance instance,
1179 uint32_t session_id) {
1180 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1181 return;
1182 EnterInstanceNoLock enter(instance);
1183 if (enter.succeeded()) {
1184 enter.functions()->SessionClosed(instance, session_id);
1188 void PPB_Instance_Proxy::OnHostMsgSessionError(PP_Instance instance,
1189 uint32_t session_id,
1190 int32_t media_error,
1191 uint32_t system_code) {
1192 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1193 return;
1194 EnterInstanceNoLock enter(instance);
1195 if (enter.succeeded()) {
1196 enter.functions()->SessionError(
1197 instance, session_id, media_error, system_code);
1201 void PPB_Instance_Proxy::OnHostMsgDeliverBlock(
1202 PP_Instance instance,
1203 PP_Resource decrypted_block,
1204 const std::string& serialized_block_info) {
1205 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1206 return;
1207 PP_DecryptedBlockInfo block_info;
1208 if (!DeserializeBlockInfo(serialized_block_info, &block_info))
1209 return;
1211 EnterInstanceNoLock enter(instance);
1212 if (enter.succeeded())
1213 enter.functions()->DeliverBlock(instance, decrypted_block, &block_info);
1216 void PPB_Instance_Proxy::OnHostMsgDecoderInitializeDone(
1217 PP_Instance instance,
1218 PP_DecryptorStreamType decoder_type,
1219 uint32_t request_id,
1220 PP_Bool success) {
1221 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1222 return;
1223 EnterInstanceNoLock enter(instance);
1224 if (enter.succeeded()) {
1225 enter.functions()->DecoderInitializeDone(instance,
1226 decoder_type,
1227 request_id,
1228 success);
1232 void PPB_Instance_Proxy::OnHostMsgDecoderDeinitializeDone(
1233 PP_Instance instance,
1234 PP_DecryptorStreamType decoder_type,
1235 uint32_t request_id) {
1236 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1237 return;
1238 EnterInstanceNoLock enter(instance);
1239 if (enter.succeeded())
1240 enter.functions()->DecoderDeinitializeDone(instance,
1241 decoder_type,
1242 request_id);
1245 void PPB_Instance_Proxy::OnHostMsgDecoderResetDone(
1246 PP_Instance instance,
1247 PP_DecryptorStreamType decoder_type,
1248 uint32_t request_id) {
1249 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1250 return;
1251 EnterInstanceNoLock enter(instance);
1252 if (enter.succeeded())
1253 enter.functions()->DecoderResetDone(instance, decoder_type, request_id);
1256 void PPB_Instance_Proxy::OnHostMsgDeliverFrame(
1257 PP_Instance instance,
1258 PP_Resource decrypted_frame,
1259 const std::string& serialized_frame_info) {
1260 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1261 return;
1262 PP_DecryptedFrameInfo frame_info;
1263 if (!DeserializeBlockInfo(serialized_frame_info, &frame_info))
1264 return;
1266 EnterInstanceNoLock enter(instance);
1267 if (enter.succeeded())
1268 enter.functions()->DeliverFrame(instance, decrypted_frame, &frame_info);
1271 void PPB_Instance_Proxy::OnHostMsgDeliverSamples(
1272 PP_Instance instance,
1273 PP_Resource audio_frames,
1274 const std::string& serialized_sample_info) {
1275 if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE))
1276 return;
1277 PP_DecryptedSampleInfo sample_info;
1278 if (!DeserializeBlockInfo(serialized_sample_info, &sample_info))
1279 return;
1281 EnterInstanceNoLock enter(instance);
1282 if (enter.succeeded())
1283 enter.functions()->DeliverSamples(instance, audio_frames, &sample_info);
1286 void PPB_Instance_Proxy::OnHostMsgSetCursor(
1287 PP_Instance instance,
1288 int32_t type,
1289 const ppapi::HostResource& custom_image,
1290 const PP_Point& hot_spot) {
1291 // This API serves PPB_CursorControl_Dev and PPB_MouseCursor, so is public.
1292 EnterInstanceNoLock enter(instance);
1293 if (enter.succeeded()) {
1294 enter.functions()->SetCursor(
1295 instance, static_cast<PP_MouseCursor_Type>(type),
1296 custom_image.host_resource(), &hot_spot);
1300 void PPB_Instance_Proxy::OnHostMsgSetTextInputType(PP_Instance instance,
1301 PP_TextInput_Type type) {
1302 EnterInstanceNoLock enter(instance);
1303 if (enter.succeeded())
1304 enter.functions()->SetTextInputType(instance, type);
1307 void PPB_Instance_Proxy::OnHostMsgUpdateCaretPosition(
1308 PP_Instance instance,
1309 const PP_Rect& caret,
1310 const PP_Rect& bounding_box) {
1311 EnterInstanceNoLock enter(instance);
1312 if (enter.succeeded())
1313 enter.functions()->UpdateCaretPosition(instance, caret, bounding_box);
1316 void PPB_Instance_Proxy::OnHostMsgCancelCompositionText(PP_Instance instance) {
1317 EnterInstanceNoLock enter(instance);
1318 if (enter.succeeded())
1319 enter.functions()->CancelCompositionText(instance);
1322 void PPB_Instance_Proxy::OnHostMsgUpdateSurroundingText(
1323 PP_Instance instance,
1324 const std::string& text,
1325 uint32_t caret,
1326 uint32_t anchor) {
1327 EnterInstanceNoLock enter(instance);
1328 if (enter.succeeded()) {
1329 enter.functions()->UpdateSurroundingText(instance, text.c_str(), caret,
1330 anchor);
1333 #endif // !defined(OS_NACL)
1335 void PPB_Instance_Proxy::OnPluginMsgMouseLockComplete(PP_Instance instance,
1336 int32_t result) {
1337 if (!dispatcher()->IsPlugin())
1338 return;
1340 // Save the mouse callback on the instance data.
1341 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1342 GetInstanceData(instance);
1343 if (!data)
1344 return; // Instance was probably deleted.
1345 if (!TrackedCallback::IsPending(data->mouse_lock_callback)) {
1346 NOTREACHED();
1347 return;
1349 data->mouse_lock_callback->Run(result);
1352 #if !defined(OS_NACL)
1353 void PPB_Instance_Proxy::MouseLockCompleteInHost(int32_t result,
1354 PP_Instance instance) {
1355 dispatcher()->Send(new PpapiMsg_PPBInstance_MouseLockComplete(
1356 API_ID_PPB_INSTANCE, instance, result));
1358 #endif // !defined(OS_NACL)
1360 void PPB_Instance_Proxy::CancelAnyPendingRequestSurroundingText(
1361 PP_Instance instance) {
1362 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1363 GetInstanceData(instance);
1364 if (!data)
1365 return; // Instance was probably deleted.
1366 data->should_do_request_surrounding_text = false;
1369 } // namespace proxy
1370 } // namespace ppapi