blob: 08da58c9c8cba5d4cad0e118ba398547514f8283 [file] [log] [blame]
[email protected]f24448db2011-01-27 20:40:391// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]4c2e9352010-11-05 22:13:022// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ppapi/proxy/ppb_instance_proxy.h"
6
[email protected]ceadc392011-06-15 23:04:247#include "ppapi/c/dev/ppb_fullscreen_dev.h"
[email protected]4c2e9352010-11-05 22:13:028#include "ppapi/c/pp_var.h"
9#include "ppapi/c/ppb_instance.h"
[email protected]7f801d82011-07-08 23:30:1110#include "ppapi/c/ppb_messaging.h"
[email protected]037f63f2011-03-13 19:44:4611#include "ppapi/proxy/host_dispatcher.h"
[email protected]4c2e9352010-11-05 22:13:0212#include "ppapi/proxy/plugin_dispatcher.h"
[email protected]f24448db2011-01-27 20:40:3913#include "ppapi/proxy/plugin_resource.h"
14#include "ppapi/proxy/plugin_resource_tracker.h"
[email protected]4c2e9352010-11-05 22:13:0215#include "ppapi/proxy/ppapi_messages.h"
16#include "ppapi/proxy/serialized_var.h"
[email protected]ceadc392011-06-15 23:04:2417#include "ppapi/thunk/enter.h"
18#include "ppapi/thunk/thunk.h"
19
[email protected]55a5a522011-07-06 22:52:4020// Windows headers interfere with this file.
21#ifdef PostMessage
22#undef PostMessage
23#endif
24
[email protected]be0a84b2011-08-13 04:18:4425using ppapi::HostResource;
[email protected]ceadc392011-06-15 23:04:2426using ppapi::thunk::EnterFunctionNoLock;
27using ppapi::thunk::EnterResourceNoLock;
28using ppapi::thunk::PPB_Instance_FunctionAPI;
[email protected]4c2e9352010-11-05 22:13:0229
30namespace pp {
31namespace proxy {
32
33namespace {
34
[email protected]465faa22011-02-08 16:31:4635InterfaceProxy* CreateInstanceProxy(Dispatcher* dispatcher,
36 const void* target_interface) {
37 return new PPB_Instance_Proxy(dispatcher, target_interface);
38}
39
[email protected]4c2e9352010-11-05 22:13:0240} // namespace
41
42PPB_Instance_Proxy::PPB_Instance_Proxy(Dispatcher* dispatcher,
43 const void* target_interface)
44 : InterfaceProxy(dispatcher, target_interface) {
45}
46
47PPB_Instance_Proxy::~PPB_Instance_Proxy() {
48}
49
[email protected]465faa22011-02-08 16:31:4650// static
[email protected]ceadc392011-06-15 23:04:2451const InterfaceProxy::Info* PPB_Instance_Proxy::GetInfo0_5() {
52 static const Info info = {
[email protected]7d0284e02011-07-13 03:48:2453 ppapi::thunk::GetPPB_Instance_1_0_Thunk(),
[email protected]ceadc392011-06-15 23:04:2454 PPB_INSTANCE_INTERFACE_0_5,
[email protected]7d0284e02011-07-13 03:48:2455 INTERFACE_ID_NONE, // 1_0 is the canonical one.
56 false,
57 &CreateInstanceProxy,
58 };
59 return &info;
60}
61
62// static
63const InterfaceProxy::Info* PPB_Instance_Proxy::GetInfo1_0() {
64 static const Info info = {
65 ppapi::thunk::GetPPB_Instance_1_0_Thunk(),
66 PPB_INSTANCE_INTERFACE_1_0,
[email protected]465faa22011-02-08 16:31:4667 INTERFACE_ID_PPB_INSTANCE,
68 false,
69 &CreateInstanceProxy,
70 };
71 return &info;
[email protected]4c2e9352010-11-05 22:13:0272}
73
[email protected]ceadc392011-06-15 23:04:2474// static
[email protected]7f801d82011-07-08 23:30:1175const InterfaceProxy::Info* PPB_Instance_Proxy::GetInfoMessaging() {
76 static const Info info = {
77 ppapi::thunk::GetPPB_Messaging_Thunk(),
78 PPB_MESSAGING_INTERFACE,
[email protected]657f4ef2011-07-14 16:39:2379 INTERFACE_ID_NONE, // 1_0 is the canonical one.
[email protected]7f801d82011-07-08 23:30:1180 false,
81 &CreateInstanceProxy,
82 };
83 return &info;
84}
85
86// static
[email protected]ceadc392011-06-15 23:04:2487const InterfaceProxy::Info* PPB_Instance_Proxy::GetInfoPrivate() {
88 static const Info info = {
89 ppapi::thunk::GetPPB_Instance_Private_Thunk(),
90 PPB_INSTANCE_PRIVATE_INTERFACE,
[email protected]657f4ef2011-07-14 16:39:2391 INTERFACE_ID_NONE, // 1_0 is the canonical one.
[email protected]ceadc392011-06-15 23:04:2492 false,
93 &CreateInstanceProxy,
94 };
95 return &info;
96}
97
98// static
99const InterfaceProxy::Info* PPB_Instance_Proxy::GetInfoFullscreen() {
100 static const Info info = {
101 ppapi::thunk::GetPPB_Fullscreen_Thunk(),
102 PPB_FULLSCREEN_DEV_INTERFACE,
[email protected]657f4ef2011-07-14 16:39:23103 INTERFACE_ID_NONE, // 1_0 is the canonical one.
[email protected]ceadc392011-06-15 23:04:24104 false,
105 &CreateInstanceProxy,
106 };
107 return &info;
108}
109
[email protected]a95986a82010-12-24 06:19:28110bool PPB_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) {
[email protected]3502a99692011-04-18 20:51:18111 // Prevent the dispatcher from going away during a call to ExecuteScript.
112 // This must happen OUTSIDE of ExecuteScript since the SerializedVars use
113 // the dispatcher upon return of the function (converting the
114 // SerializedVarReturnValue/OutParam to a SerializedVar in the destructor).
115 ScopedModuleReference death_grip(dispatcher());
116
[email protected]a95986a82010-12-24 06:19:28117 bool handled = true;
[email protected]4c2e9352010-11-05 22:13:02118 IPC_BEGIN_MESSAGE_MAP(PPB_Instance_Proxy, msg)
119 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetWindowObject,
120 OnMsgGetWindowObject)
121 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetOwnerElementObject,
122 OnMsgGetOwnerElementObject)
123 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_BindGraphics,
124 OnMsgBindGraphics)
125 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_IsFullFrame,
126 OnMsgIsFullFrame)
127 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ExecuteScript,
128 OnMsgExecuteScript)
[email protected]7f801d82011-07-08 23:30:11129 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PostMessage,
130 OnMsgPostMessage)
[email protected]ceadc392011-06-15 23:04:24131 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetFullscreen,
132 OnMsgSetFullscreen)
133 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetScreenSize,
134 OnMsgGetScreenSize)
[email protected]493d14212011-07-07 15:38:48135 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_RequestInputEvents,
136 OnMsgRequestInputEvents)
137 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ClearInputEvents,
138 OnMsgClearInputEvents)
[email protected]a95986a82010-12-24 06:19:28139 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]4c2e9352010-11-05 22:13:02140 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28141 return handled;
[email protected]4c2e9352010-11-05 22:13:02142}
143
[email protected]ceadc392011-06-15 23:04:24144PPB_Instance_FunctionAPI* PPB_Instance_Proxy::AsPPB_Instance_FunctionAPI() {
145 return this;
146}
147
148PP_Bool PPB_Instance_Proxy::BindGraphics(PP_Instance instance,
149 PP_Resource device) {
150 PluginResource* object =
151 PluginResourceTracker::GetInstance()->GetResourceObject(device);
152 if (!object || object->instance() != instance)
153 return PP_FALSE;
154
155 PP_Bool result = PP_FALSE;
156 dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
157 INTERFACE_ID_PPB_INSTANCE, instance, object->host_resource(),
158 &result));
159 return result;
160}
161
162PP_Bool PPB_Instance_Proxy::IsFullFrame(PP_Instance instance) {
163 PP_Bool result = PP_FALSE;
164 dispatcher()->Send(new PpapiHostMsg_PPBInstance_IsFullFrame(
165 INTERFACE_ID_PPB_INSTANCE, instance, &result));
166 return result;
167}
168
169PP_Var PPB_Instance_Proxy::GetWindowObject(PP_Instance instance) {
170 ReceiveSerializedVarReturnValue result;
171 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetWindowObject(
172 INTERFACE_ID_PPB_INSTANCE, instance, &result));
173 return result.Return(dispatcher());
174}
175
176PP_Var PPB_Instance_Proxy::GetOwnerElementObject(PP_Instance instance) {
177 ReceiveSerializedVarReturnValue result;
178 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetOwnerElementObject(
179 INTERFACE_ID_PPB_INSTANCE, instance, &result));
180 return result.Return(dispatcher());
181}
182
183PP_Var PPB_Instance_Proxy::ExecuteScript(PP_Instance instance,
184 PP_Var script,
185 PP_Var* exception) {
186 ReceiveSerializedException se(dispatcher(), exception);
187 if (se.IsThrown())
188 return PP_MakeUndefined();
189
190 ReceiveSerializedVarReturnValue result;
191 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ExecuteScript(
192 INTERFACE_ID_PPB_INSTANCE, instance,
193 SerializedVarSendInput(dispatcher(), script), &se, &result));
194 return result.Return(dispatcher());
195}
196
197PP_Bool PPB_Instance_Proxy::IsFullscreen(PP_Instance instance) {
198 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
199 GetInstanceData(instance);
200 if (!data)
201 return PP_FALSE;
202 return data->fullscreen;
203}
204
205PP_Bool PPB_Instance_Proxy::SetFullscreen(PP_Instance instance,
206 PP_Bool fullscreen) {
207 PP_Bool result = PP_FALSE;
208 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetFullscreen(
209 INTERFACE_ID_PPB_INSTANCE, instance, fullscreen, &result));
210 return result;
211}
212
213PP_Bool PPB_Instance_Proxy::GetScreenSize(PP_Instance instance,
214 PP_Size* size) {
215 PP_Bool result = PP_FALSE;
216 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetScreenSize(
217 INTERFACE_ID_PPB_INSTANCE, instance, &result, size));
218 return result;
219}
220
[email protected]493d14212011-07-07 15:38:48221int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance,
222 uint32_t event_classes) {
223 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
224 INTERFACE_ID_PPB_INSTANCE, instance, false, event_classes));
225
226 // We always register for the classes we can handle, this function validates
227 // the flags so we can notify it if anything was invalid, without requiring
228 // a sync reply.
229 return ValidateRequestInputEvents(false, event_classes);
230}
231
232int32_t PPB_Instance_Proxy::RequestFilteringInputEvents(
233 PP_Instance instance,
234 uint32_t event_classes) {
235 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
236 INTERFACE_ID_PPB_INSTANCE, instance, true, event_classes));
237
238 // We always register for the classes we can handle, this function validates
239 // the flags so we can notify it if anything was invalid, without requiring
240 // a sync reply.
241 return ValidateRequestInputEvents(true, event_classes);
242}
243
244void PPB_Instance_Proxy::ClearInputEventRequest(PP_Instance instance,
245 uint32_t event_classes) {
246 dispatcher()->Send(new PpapiHostMsg_PPBInstance_ClearInputEvents(
247 INTERFACE_ID_PPB_INSTANCE, instance, event_classes));
248}
249
[email protected]55a5a522011-07-06 22:52:40250void PPB_Instance_Proxy::ZoomChanged(PP_Instance instance,
251 double factor) {
252 // Not proxied yet.
253 NOTIMPLEMENTED();
254}
255
256void PPB_Instance_Proxy::ZoomLimitsChanged(PP_Instance instance,
257 double minimum_factor,
258 double maximium_factor) {
259 // Not proxied yet.
260 NOTIMPLEMENTED();
261}
262
[email protected]15237942011-07-30 04:24:19263void PPB_Instance_Proxy::SubscribeToPolicyUpdates(PP_Instance instance) {
264 // Not proxied yet.
265 NOTIMPLEMENTED();
266}
267
[email protected]55a5a522011-07-06 22:52:40268void PPB_Instance_Proxy::PostMessage(PP_Instance instance,
269 PP_Var message) {
270 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage(
271 INTERFACE_ID_PPB_INSTANCE,
272 instance, SerializedVarSendInput(dispatcher(), message)));
273}
274
[email protected]4c2e9352010-11-05 22:13:02275void PPB_Instance_Proxy::OnMsgGetWindowObject(
276 PP_Instance instance,
277 SerializedVarReturnValue result) {
[email protected]ceadc392011-06-15 23:04:24278 EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false);
279 if (enter.succeeded())
280 result.Return(dispatcher(), enter.functions()->GetWindowObject(instance));
[email protected]4c2e9352010-11-05 22:13:02281}
282
283void PPB_Instance_Proxy::OnMsgGetOwnerElementObject(
284 PP_Instance instance,
285 SerializedVarReturnValue result) {
[email protected]ceadc392011-06-15 23:04:24286 EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false);
287 if (enter.succeeded()) {
288 result.Return(dispatcher(),
289 enter.functions()->GetOwnerElementObject(instance));
290 }
[email protected]4c2e9352010-11-05 22:13:02291}
292
293void PPB_Instance_Proxy::OnMsgBindGraphics(PP_Instance instance,
[email protected]be0a84b2011-08-13 04:18:44294 const HostResource& device,
[email protected]19d2b012010-11-08 16:32:18295 PP_Bool* result) {
[email protected]ceadc392011-06-15 23:04:24296 EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false);
297 if (enter.succeeded()) {
298 *result = enter.functions()->BindGraphics(instance,
299 device.host_resource());
300 }
[email protected]4c2e9352010-11-05 22:13:02301}
302
[email protected]19d2b012010-11-08 16:32:18303void PPB_Instance_Proxy::OnMsgIsFullFrame(PP_Instance instance,
304 PP_Bool* result) {
[email protected]ceadc392011-06-15 23:04:24305 EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false);
306 if (enter.succeeded())
307 *result = enter.functions()->IsFullFrame(instance);
[email protected]4c2e9352010-11-05 22:13:02308}
309
310void PPB_Instance_Proxy::OnMsgExecuteScript(
311 PP_Instance instance,
312 SerializedVarReceiveInput script,
313 SerializedVarOutParam out_exception,
314 SerializedVarReturnValue result) {
[email protected]ceadc392011-06-15 23:04:24315 EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false);
316 if (enter.failed())
317 return;
318
[email protected]037f63f2011-03-13 19:44:46319 if (dispatcher()->IsPlugin())
320 NOTREACHED();
321 else
322 static_cast<HostDispatcher*>(dispatcher())->set_allow_plugin_reentrancy();
323
[email protected]ceadc392011-06-15 23:04:24324 result.Return(dispatcher(), enter.functions()->ExecuteScript(
[email protected]4c2e9352010-11-05 22:13:02325 instance,
326 script.Get(dispatcher()),
327 out_exception.OutParam(dispatcher())));
328}
329
[email protected]ceadc392011-06-15 23:04:24330void PPB_Instance_Proxy::OnMsgSetFullscreen(PP_Instance instance,
331 PP_Bool fullscreen,
332 PP_Bool* result) {
333 EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false);
334 if (enter.succeeded())
335 *result = enter.functions()->SetFullscreen(instance, fullscreen);
336}
337
338void PPB_Instance_Proxy::OnMsgGetScreenSize(PP_Instance instance,
339 PP_Bool* result,
340 PP_Size* size) {
341 EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false);
342 if (enter.succeeded())
343 *result = enter.functions()->GetScreenSize(instance, size);
344}
345
[email protected]493d14212011-07-07 15:38:48346void PPB_Instance_Proxy::OnMsgRequestInputEvents(PP_Instance instance,
347 bool is_filtering,
348 uint32_t event_classes) {
349 EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false);
350 if (enter.succeeded()) {
351 if (is_filtering)
352 enter.functions()->RequestFilteringInputEvents(instance, event_classes);
353 else
354 enter.functions()->RequestInputEvents(instance, event_classes);
355 }
356}
357
358void PPB_Instance_Proxy::OnMsgClearInputEvents(PP_Instance instance,
359 uint32_t event_classes) {
360 EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false);
361 if (enter.succeeded())
362 enter.functions()->ClearInputEventRequest(instance, event_classes);
363}
364
[email protected]55a5a522011-07-06 22:52:40365void PPB_Instance_Proxy::OnMsgPostMessage(PP_Instance instance,
366 SerializedVarReceiveInput message) {
367 EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false);
368 if (enter.succeeded())
369 enter.functions()->PostMessage(instance, message.Get(dispatcher()));
370}
371
[email protected]4c2e9352010-11-05 22:13:02372} // namespace proxy
373} // namespace pp