Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / mojo / examples / pepper_container_app / plugin_instance.cc
1 // Copyright 2014 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.
4
5 #include "mojo/examples/pepper_container_app/plugin_instance.h"
6
7 #include "base/logging.h"
8 #include "mojo/examples/pepper_container_app/graphics_3d_resource.h"
9 #include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h"
10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/c/pp_var.h"
12 #include "ppapi/c/ppp_graphics_3d.h"
13 #include "ppapi/c/ppp_instance.h"
14 #include "ppapi/shared_impl/ppb_view_shared.h"
15 #include "ppapi/shared_impl/proxy_lock.h"
16 #include "ppapi/shared_impl/tracked_callback.h"
17 #include "ppapi/thunk/enter.h"
18 #include "ppapi/thunk/ppb_graphics_3d_api.h"
19
20 namespace mojo {
21 namespace examples {
22
23 PluginInstance::PluginInstance(scoped_refptr<PluginModule> plugin_module)
24     : pp_instance_(0),
25       plugin_module_(plugin_module) {
26   pp_instance_ = MojoPpapiGlobals::Get()->AddInstance(this);
27 }
28
29 PluginInstance::~PluginInstance() {
30   MojoPpapiGlobals::Get()->InstanceDeleted(pp_instance_);
31 }
32
33 bool PluginInstance::DidCreate() {
34   ppapi::ProxyAutoUnlock unlock;
35   const PPP_Instance_1_1* instance_interface =
36       static_cast<const PPP_Instance_1_1*>(plugin_module_->GetPluginInterface(
37           PPP_INSTANCE_INTERFACE_1_1));
38   return !!instance_interface->DidCreate(pp_instance(), 0, NULL, NULL);
39 }
40
41 void PluginInstance::DidDestroy() {
42   ppapi::ProxyAutoUnlock unlock;
43   const PPP_Instance_1_1* instance_interface =
44       static_cast<const PPP_Instance_1_1*>(plugin_module_->GetPluginInterface(
45           PPP_INSTANCE_INTERFACE_1_1));
46   instance_interface->DidDestroy(pp_instance());
47 }
48
49 void PluginInstance::DidChangeView(const PP_Rect& bounds) {
50   ppapi::ViewData view_data;
51   view_data.rect = bounds;
52   view_data.is_fullscreen = false;
53   view_data.is_page_visible = true;
54   view_data.clip_rect = bounds;
55   view_data.device_scale = 1.0f;
56   view_data.css_scale = 1.0f;
57
58   ppapi::ScopedPPResource resource(ppapi::ScopedPPResource::PassRef(),
59       (new ppapi::PPB_View_Shared(
60           ppapi::OBJECT_IS_IMPL, pp_instance(), view_data))->GetReference());
61   {
62     ppapi::ProxyAutoUnlock unlock;
63     const PPP_Instance_1_1* instance_interface =
64         static_cast<const PPP_Instance_1_1*>(plugin_module_->GetPluginInterface(
65             PPP_INSTANCE_INTERFACE_1_1));
66     instance_interface->DidChangeView(pp_instance(), resource);
67   }
68 }
69
70 void PluginInstance::Graphics3DContextLost() {
71   ppapi::ProxyAutoUnlock unlock;
72   const PPP_Graphics3D_1_0* graphic_3d_interface =
73       static_cast<const PPP_Graphics3D_1_0*>(plugin_module_->GetPluginInterface(
74           PPP_GRAPHICS_3D_INTERFACE_1_0));
75   // TODO(yzshen): Maybe we only need to notify for the bound graphics context?
76   graphic_3d_interface->Graphics3DContextLost(pp_instance());
77 }
78
79 bool PluginInstance::IsBoundGraphics(PP_Resource device) const {
80   return device != 0 && device == bound_graphics_.get();
81 }
82
83 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, PP_Resource device) {
84   if (bound_graphics_.get() == device)
85     return PP_TRUE;
86
87   ppapi::thunk::EnterResourceNoLock<ppapi::thunk::PPB_Graphics3D_API>
88       enter(device, false);
89   if (enter.failed())
90     return PP_FALSE;
91
92   bound_graphics_ = device;
93   static_cast<Graphics3DResource*>(enter.object())->BindGraphics();
94
95   return PP_TRUE;
96 }
97
98 PP_Bool PluginInstance::IsFullFrame(PP_Instance instance) {
99   NOTIMPLEMENTED();
100   return PP_FALSE;
101 }
102
103 const ppapi::ViewData* PluginInstance::GetViewData(PP_Instance instance) {
104   NOTIMPLEMENTED();
105   return NULL;
106 }
107
108 PP_Bool PluginInstance::FlashIsFullscreen(PP_Instance instance) {
109   NOTIMPLEMENTED();
110   return PP_FALSE;
111 }
112
113 PP_Var PluginInstance::GetWindowObject(PP_Instance instance) {
114   NOTIMPLEMENTED();
115   return PP_MakeUndefined();
116 }
117
118 PP_Var PluginInstance::GetOwnerElementObject(PP_Instance instance) {
119   NOTIMPLEMENTED();
120   return PP_MakeUndefined();
121 }
122
123 PP_Var PluginInstance::ExecuteScript(PP_Instance instance,
124                                      PP_Var script,
125                                      PP_Var* exception) {
126   NOTIMPLEMENTED();
127   return PP_MakeUndefined();
128 }
129
130 uint32_t PluginInstance::GetAudioHardwareOutputSampleRate(
131     PP_Instance instance) {
132   NOTIMPLEMENTED();
133   return 0;
134 }
135
136 uint32_t PluginInstance::GetAudioHardwareOutputBufferSize(
137     PP_Instance instance) {
138   NOTIMPLEMENTED();
139   return 0;
140 }
141
142 PP_Var PluginInstance::GetDefaultCharSet(PP_Instance instance) {
143   NOTIMPLEMENTED();
144   return PP_MakeUndefined();
145 }
146
147 void PluginInstance::Log(PP_Instance instance,
148                          PP_LogLevel log_level,
149                          PP_Var value) {
150   NOTIMPLEMENTED();
151 }
152
153 void PluginInstance::LogWithSource(PP_Instance instance,
154                                    PP_LogLevel log_level,
155                                    PP_Var source,
156                                    PP_Var value) {
157   NOTIMPLEMENTED();
158 }
159
160 void PluginInstance::SetPluginToHandleFindRequests(PP_Instance instance) {
161   NOTIMPLEMENTED();
162 }
163
164 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance,
165                                                 int32_t total,
166                                                 PP_Bool final_result) {
167   NOTIMPLEMENTED();
168 }
169
170 void PluginInstance::SelectedFindResultChanged(PP_Instance instance,
171                                                int32_t index) {
172   NOTIMPLEMENTED();
173 }
174
175 void PluginInstance::SetTickmarks(PP_Instance instance,
176                                   const PP_Rect* tickmarks,
177                                   uint32_t count) {
178   NOTIMPLEMENTED();
179 }
180
181 PP_Bool PluginInstance::IsFullscreen(PP_Instance instance) {
182   NOTIMPLEMENTED();
183   return PP_FALSE;
184 }
185
186 PP_Bool PluginInstance::SetFullscreen(PP_Instance instance,
187                                       PP_Bool fullscreen) {
188   NOTIMPLEMENTED();
189   return PP_FALSE;
190 }
191
192 PP_Bool PluginInstance::GetScreenSize(PP_Instance instance, PP_Size* size) {
193   NOTIMPLEMENTED();
194   return PP_FALSE;
195 }
196
197 ppapi::Resource* PluginInstance::GetSingletonResource(
198     PP_Instance instance,
199     ppapi::SingletonResourceID id) {
200   NOTIMPLEMENTED();
201   return NULL;
202 }
203
204 int32_t PluginInstance::RequestInputEvents(PP_Instance instance,
205                                            uint32_t event_classes) {
206   NOTIMPLEMENTED();
207   return PP_ERROR_FAILED;
208 }
209
210 int32_t PluginInstance::RequestFilteringInputEvents(PP_Instance instance,
211                                                     uint32_t event_classes) {
212   NOTIMPLEMENTED();
213   return PP_ERROR_FAILED;
214 }
215
216 void PluginInstance::ClearInputEventRequest(PP_Instance instance,
217                                             uint32_t event_classes) {
218   NOTIMPLEMENTED();
219 }
220
221 void PluginInstance::StartTrackingLatency(PP_Instance instance) {
222   NOTIMPLEMENTED();
223 }
224
225 void PluginInstance::PostMessage(PP_Instance instance, PP_Var message) {
226   NOTIMPLEMENTED();
227 }
228
229 int32_t PluginInstance::RegisterMessageHandler(
230     PP_Instance instance,
231     void* user_data,
232     const PPP_MessageHandler_0_2* handler,
233     PP_Resource message_loop) {
234   NOTIMPLEMENTED();
235   return PP_ERROR_FAILED;
236 }
237
238 // TODO(dmichael): Remove this. crbug.com/414398
239 int32_t PluginInstance::RegisterMessageHandler_1_1_Deprecated(
240     PP_Instance instance,
241     void* user_data,
242     const PPP_MessageHandler_0_1_Deprecated* handler,
243     PP_Resource message_loop) {
244   NOTIMPLEMENTED();
245   return PP_ERROR_FAILED;
246 }
247
248 void PluginInstance::UnregisterMessageHandler(PP_Instance instance) {
249   NOTIMPLEMENTED();
250 }
251
252 PP_Bool PluginInstance::SetCursor(PP_Instance instance,
253                                   PP_MouseCursor_Type type,
254                                   PP_Resource image,
255                                   const PP_Point* hot_spot) {
256   NOTIMPLEMENTED();
257   return PP_FALSE;
258 }
259
260 int32_t PluginInstance::LockMouse(
261     PP_Instance instance,
262     scoped_refptr<ppapi::TrackedCallback> callback) {
263   NOTIMPLEMENTED();
264   return PP_ERROR_FAILED;
265 }
266
267 void PluginInstance::UnlockMouse(PP_Instance instance) {
268   NOTIMPLEMENTED();
269 }
270
271 void PluginInstance::SetTextInputType(PP_Instance instance,
272                                       PP_TextInput_Type type) {
273   NOTIMPLEMENTED();
274 }
275
276 void PluginInstance::UpdateCaretPosition(PP_Instance instance,
277                                          const PP_Rect& caret,
278                                          const PP_Rect& bounding_box) {
279   NOTIMPLEMENTED();
280 }
281
282 void PluginInstance::CancelCompositionText(PP_Instance instance) {
283   NOTIMPLEMENTED();
284 }
285
286 void PluginInstance::SelectionChanged(PP_Instance instance) {
287   NOTIMPLEMENTED();
288 }
289
290 void PluginInstance::UpdateSurroundingText(PP_Instance instance,
291                                            const char* text,
292                                            uint32_t caret,
293                                            uint32_t anchor) {
294   NOTIMPLEMENTED();
295 }
296
297 void PluginInstance::ZoomChanged(PP_Instance instance, double factor) {
298   NOTIMPLEMENTED();
299 }
300
301 void PluginInstance::ZoomLimitsChanged(PP_Instance instance,
302                                        double minimum_factor,
303                                        double maximum_factor) {
304   NOTIMPLEMENTED();
305 }
306
307 PP_Var PluginInstance::GetDocumentURL(PP_Instance instance,
308                                       PP_URLComponents_Dev* components) {
309   NOTIMPLEMENTED();
310   return PP_MakeUndefined();
311 }
312
313 void PluginInstance::PromiseResolved(PP_Instance instance, uint32 promise_id) {
314   NOTIMPLEMENTED();
315 }
316
317 void PluginInstance::PromiseResolvedWithSession(PP_Instance instance,
318                                                 uint32 promise_id,
319                                                 PP_Var web_session_id_var) {
320   NOTIMPLEMENTED();
321 }
322
323 void PluginInstance::PromiseResolvedWithKeyIds(PP_Instance instance,
324                                                uint32 promise_id,
325                                                PP_Var key_ids_var) {
326   NOTIMPLEMENTED();
327 }
328
329 void PluginInstance::PromiseRejected(PP_Instance instance,
330                                      uint32 promise_id,
331                                      PP_CdmExceptionCode exception_code,
332                                      uint32 system_code,
333                                      PP_Var error_description_var) {
334   NOTIMPLEMENTED();
335 }
336
337 void PluginInstance::SessionMessage(PP_Instance instance,
338                                     PP_Var web_session_id_var,
339                                     PP_Var message_var,
340                                     PP_Var destination_url_var) {
341   NOTIMPLEMENTED();
342 }
343
344 void PluginInstance::SessionKeysChange(PP_Instance instance,
345                                        PP_Var web_session_id_var,
346                                        PP_Bool has_additional_usable_key) {
347   NOTIMPLEMENTED();
348 }
349
350 void PluginInstance::SessionExpirationChange(PP_Instance instance,
351                                              PP_Var web_session_id_var,
352                                              PP_Time new_expiry_time) {
353   NOTIMPLEMENTED();
354 }
355
356 void PluginInstance::SessionReady(PP_Instance instance,
357                                   PP_Var web_session_id_var) {
358   NOTIMPLEMENTED();
359 }
360
361 void PluginInstance::SessionClosed(PP_Instance instance,
362                                    PP_Var web_session_id_var) {
363   NOTIMPLEMENTED();
364 }
365
366 void PluginInstance::SessionError(PP_Instance instance,
367                                   PP_Var web_session_id_var,
368                                   PP_CdmExceptionCode exception_code,
369                                   uint32 system_code,
370                                   PP_Var error_description_var) {
371   NOTIMPLEMENTED();
372 }
373
374 void PluginInstance::DeliverBlock(PP_Instance instance,
375                                   PP_Resource decrypted_block,
376                                   const PP_DecryptedBlockInfo* block_info) {
377   NOTIMPLEMENTED();
378 }
379
380 void PluginInstance::DecoderInitializeDone(PP_Instance instance,
381                                            PP_DecryptorStreamType decoder_type,
382                                            uint32_t request_id,
383                                            PP_Bool success) {
384   NOTIMPLEMENTED();
385 }
386
387 void PluginInstance::DecoderDeinitializeDone(
388     PP_Instance instance,
389     PP_DecryptorStreamType decoder_type,
390     uint32_t request_id) {
391   NOTIMPLEMENTED();
392 }
393
394 void PluginInstance::DecoderResetDone(PP_Instance instance,
395                                       PP_DecryptorStreamType decoder_type,
396                                       uint32_t request_id) {
397   NOTIMPLEMENTED();
398 }
399
400 void PluginInstance::DeliverFrame(PP_Instance instance,
401                                   PP_Resource decrypted_frame,
402                                   const PP_DecryptedFrameInfo* frame_info) {
403   NOTIMPLEMENTED();
404 }
405
406 void PluginInstance::DeliverSamples(PP_Instance instance,
407                                     PP_Resource audio_frames,
408                                     const PP_DecryptedSampleInfo* sample_info) {
409   NOTIMPLEMENTED();
410 }
411
412 PP_Var PluginInstance::ResolveRelativeToDocument(
413     PP_Instance instance,
414     PP_Var relative,
415     PP_URLComponents_Dev* components) {
416   NOTIMPLEMENTED();
417   return PP_MakeUndefined();
418 }
419
420 PP_Bool PluginInstance::DocumentCanRequest(PP_Instance instance, PP_Var url) {
421   NOTIMPLEMENTED();
422   return PP_FALSE;
423 }
424
425 PP_Bool PluginInstance::DocumentCanAccessDocument(PP_Instance instance,
426                                                   PP_Instance target) {
427   NOTIMPLEMENTED();
428   return PP_FALSE;
429 }
430
431 PP_Var PluginInstance::GetPluginInstanceURL(PP_Instance instance,
432                                             PP_URLComponents_Dev* components) {
433   NOTIMPLEMENTED();
434   return PP_MakeUndefined();
435 }
436
437 PP_Var PluginInstance::GetPluginReferrerURL(PP_Instance instance,
438                                             PP_URLComponents_Dev* components) {
439   NOTIMPLEMENTED();
440   return PP_MakeUndefined();
441 }
442
443 }  // namespace examples
444 }  // namespace mojo