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.
5 #include "mojo/examples/pepper_container_app/plugin_instance.h"
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"
23 PluginInstance::PluginInstance(scoped_refptr
<PluginModule
> plugin_module
)
25 plugin_module_(plugin_module
) {
26 pp_instance_
= MojoPpapiGlobals::Get()->AddInstance(this);
29 PluginInstance::~PluginInstance() {
30 MojoPpapiGlobals::Get()->InstanceDeleted(pp_instance_
);
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
);
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());
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
;
58 ppapi::ScopedPPResource
resource(ppapi::ScopedPPResource::PassRef(),
59 (new ppapi::PPB_View_Shared(
60 ppapi::OBJECT_IS_IMPL
, pp_instance(), view_data
))->GetReference());
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
);
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());
79 bool PluginInstance::IsBoundGraphics(PP_Resource device
) const {
80 return device
!= 0 && device
== bound_graphics_
.get();
83 PP_Bool
PluginInstance::BindGraphics(PP_Instance instance
, PP_Resource device
) {
84 if (bound_graphics_
.get() == device
)
87 ppapi::thunk::EnterResourceNoLock
<ppapi::thunk::PPB_Graphics3D_API
>
92 bound_graphics_
= device
;
93 static_cast<Graphics3DResource
*>(enter
.object())->BindGraphics();
98 PP_Bool
PluginInstance::IsFullFrame(PP_Instance instance
) {
103 const ppapi::ViewData
* PluginInstance::GetViewData(PP_Instance instance
) {
108 PP_Bool
PluginInstance::FlashIsFullscreen(PP_Instance instance
) {
113 PP_Var
PluginInstance::GetWindowObject(PP_Instance instance
) {
115 return PP_MakeUndefined();
118 PP_Var
PluginInstance::GetOwnerElementObject(PP_Instance instance
) {
120 return PP_MakeUndefined();
123 PP_Var
PluginInstance::ExecuteScript(PP_Instance instance
,
127 return PP_MakeUndefined();
130 uint32_t PluginInstance::GetAudioHardwareOutputSampleRate(
131 PP_Instance instance
) {
136 uint32_t PluginInstance::GetAudioHardwareOutputBufferSize(
137 PP_Instance instance
) {
142 PP_Var
PluginInstance::GetDefaultCharSet(PP_Instance instance
) {
144 return PP_MakeUndefined();
147 void PluginInstance::Log(PP_Instance instance
,
148 PP_LogLevel log_level
,
153 void PluginInstance::LogWithSource(PP_Instance instance
,
154 PP_LogLevel log_level
,
160 void PluginInstance::SetPluginToHandleFindRequests(PP_Instance instance
) {
164 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance
,
166 PP_Bool final_result
) {
170 void PluginInstance::SelectedFindResultChanged(PP_Instance instance
,
175 void PluginInstance::SetTickmarks(PP_Instance instance
,
176 const PP_Rect
* tickmarks
,
181 PP_Bool
PluginInstance::IsFullscreen(PP_Instance instance
) {
186 PP_Bool
PluginInstance::SetFullscreen(PP_Instance instance
,
187 PP_Bool fullscreen
) {
192 PP_Bool
PluginInstance::GetScreenSize(PP_Instance instance
, PP_Size
* size
) {
197 ppapi::Resource
* PluginInstance::GetSingletonResource(
198 PP_Instance instance
,
199 ppapi::SingletonResourceID id
) {
204 int32_t PluginInstance::RequestInputEvents(PP_Instance instance
,
205 uint32_t event_classes
) {
207 return PP_ERROR_FAILED
;
210 int32_t PluginInstance::RequestFilteringInputEvents(PP_Instance instance
,
211 uint32_t event_classes
) {
213 return PP_ERROR_FAILED
;
216 void PluginInstance::ClearInputEventRequest(PP_Instance instance
,
217 uint32_t event_classes
) {
221 void PluginInstance::StartTrackingLatency(PP_Instance instance
) {
225 void PluginInstance::PostMessage(PP_Instance instance
, PP_Var message
) {
229 int32_t PluginInstance::RegisterMessageHandler(
230 PP_Instance instance
,
232 const PPP_MessageHandler_0_1
* handler
,
233 PP_Resource message_loop
) {
235 return PP_ERROR_FAILED
;
238 void PluginInstance::UnregisterMessageHandler(PP_Instance instance
) {
242 PP_Bool
PluginInstance::SetCursor(PP_Instance instance
,
243 PP_MouseCursor_Type type
,
245 const PP_Point
* hot_spot
) {
250 int32_t PluginInstance::LockMouse(
251 PP_Instance instance
,
252 scoped_refptr
<ppapi::TrackedCallback
> callback
) {
254 return PP_ERROR_FAILED
;
257 void PluginInstance::UnlockMouse(PP_Instance instance
) {
261 void PluginInstance::SetTextInputType(PP_Instance instance
,
262 PP_TextInput_Type type
) {
266 void PluginInstance::UpdateCaretPosition(PP_Instance instance
,
267 const PP_Rect
& caret
,
268 const PP_Rect
& bounding_box
) {
272 void PluginInstance::CancelCompositionText(PP_Instance instance
) {
276 void PluginInstance::SelectionChanged(PP_Instance instance
) {
280 void PluginInstance::UpdateSurroundingText(PP_Instance instance
,
287 void PluginInstance::ZoomChanged(PP_Instance instance
, double factor
) {
291 void PluginInstance::ZoomLimitsChanged(PP_Instance instance
,
292 double minimum_factor
,
293 double maximum_factor
) {
297 PP_Var
PluginInstance::GetDocumentURL(PP_Instance instance
,
298 PP_URLComponents_Dev
* components
) {
300 return PP_MakeUndefined();
303 void PluginInstance::PromiseResolved(PP_Instance instance
, uint32 promise_id
) {
307 void PluginInstance::PromiseResolvedWithSession(PP_Instance instance
,
309 PP_Var web_session_id_var
) {
313 void PluginInstance::PromiseRejected(PP_Instance instance
,
315 PP_CdmExceptionCode exception_code
,
317 PP_Var error_description_var
) {
321 void PluginInstance::SessionMessage(PP_Instance instance
,
322 PP_Var web_session_id_var
,
324 PP_Var destination_url_var
) {
328 void PluginInstance::SessionReady(PP_Instance instance
,
329 PP_Var web_session_id_var
) {
333 void PluginInstance::SessionClosed(PP_Instance instance
,
334 PP_Var web_session_id_var
) {
338 void PluginInstance::SessionError(PP_Instance instance
,
339 PP_Var web_session_id_var
,
340 PP_CdmExceptionCode exception_code
,
342 PP_Var error_description_var
) {
346 void PluginInstance::DeliverBlock(PP_Instance instance
,
347 PP_Resource decrypted_block
,
348 const PP_DecryptedBlockInfo
* block_info
) {
352 void PluginInstance::DecoderInitializeDone(PP_Instance instance
,
353 PP_DecryptorStreamType decoder_type
,
359 void PluginInstance::DecoderDeinitializeDone(
360 PP_Instance instance
,
361 PP_DecryptorStreamType decoder_type
,
362 uint32_t request_id
) {
366 void PluginInstance::DecoderResetDone(PP_Instance instance
,
367 PP_DecryptorStreamType decoder_type
,
368 uint32_t request_id
) {
372 void PluginInstance::DeliverFrame(PP_Instance instance
,
373 PP_Resource decrypted_frame
,
374 const PP_DecryptedFrameInfo
* frame_info
) {
378 void PluginInstance::DeliverSamples(PP_Instance instance
,
379 PP_Resource audio_frames
,
380 const PP_DecryptedSampleInfo
* sample_info
) {
384 PP_Var
PluginInstance::ResolveRelativeToDocument(
385 PP_Instance instance
,
387 PP_URLComponents_Dev
* components
) {
389 return PP_MakeUndefined();
392 PP_Bool
PluginInstance::DocumentCanRequest(PP_Instance instance
, PP_Var url
) {
397 PP_Bool
PluginInstance::DocumentCanAccessDocument(PP_Instance instance
,
398 PP_Instance target
) {
403 PP_Var
PluginInstance::GetPluginInstanceURL(PP_Instance instance
,
404 PP_URLComponents_Dev
* components
) {
406 return PP_MakeUndefined();
409 PP_Var
PluginInstance::GetPluginReferrerURL(PP_Instance instance
,
410 PP_URLComponents_Dev
* components
) {
412 return PP_MakeUndefined();
415 } // namespace examples