Home | History | Annotate | Download | only in pepper_container_app
      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_1* handler,
    233     PP_Resource message_loop) {
    234   NOTIMPLEMENTED();
    235   return PP_ERROR_FAILED;
    236 }
    237 
    238 void PluginInstance::UnregisterMessageHandler(PP_Instance instance) {
    239   NOTIMPLEMENTED();
    240 }
    241 
    242 PP_Bool PluginInstance::SetCursor(PP_Instance instance,
    243                                   PP_MouseCursor_Type type,
    244                                   PP_Resource image,
    245                                   const PP_Point* hot_spot) {
    246   NOTIMPLEMENTED();
    247   return PP_FALSE;
    248 }
    249 
    250 int32_t PluginInstance::LockMouse(
    251     PP_Instance instance,
    252     scoped_refptr<ppapi::TrackedCallback> callback) {
    253   NOTIMPLEMENTED();
    254   return PP_ERROR_FAILED;
    255 }
    256 
    257 void PluginInstance::UnlockMouse(PP_Instance instance) {
    258   NOTIMPLEMENTED();
    259 }
    260 
    261 void PluginInstance::SetTextInputType(PP_Instance instance,
    262                                       PP_TextInput_Type type) {
    263   NOTIMPLEMENTED();
    264 }
    265 
    266 void PluginInstance::UpdateCaretPosition(PP_Instance instance,
    267                                          const PP_Rect& caret,
    268                                          const PP_Rect& bounding_box) {
    269   NOTIMPLEMENTED();
    270 }
    271 
    272 void PluginInstance::CancelCompositionText(PP_Instance instance) {
    273   NOTIMPLEMENTED();
    274 }
    275 
    276 void PluginInstance::SelectionChanged(PP_Instance instance) {
    277   NOTIMPLEMENTED();
    278 }
    279 
    280 void PluginInstance::UpdateSurroundingText(PP_Instance instance,
    281                                            const char* text,
    282                                            uint32_t caret,
    283                                            uint32_t anchor) {
    284   NOTIMPLEMENTED();
    285 }
    286 
    287 void PluginInstance::ZoomChanged(PP_Instance instance, double factor) {
    288   NOTIMPLEMENTED();
    289 }
    290 
    291 void PluginInstance::ZoomLimitsChanged(PP_Instance instance,
    292                                        double minimum_factor,
    293                                        double maximum_factor) {
    294   NOTIMPLEMENTED();
    295 }
    296 
    297 PP_Var PluginInstance::GetDocumentURL(PP_Instance instance,
    298                                       PP_URLComponents_Dev* components) {
    299   NOTIMPLEMENTED();
    300   return PP_MakeUndefined();
    301 }
    302 
    303 void PluginInstance::PromiseResolved(PP_Instance instance, uint32 promise_id) {
    304   NOTIMPLEMENTED();
    305 }
    306 
    307 void PluginInstance::PromiseResolvedWithSession(PP_Instance instance,
    308                                                 uint32 promise_id,
    309                                                 PP_Var web_session_id_var) {
    310   NOTIMPLEMENTED();
    311 }
    312 
    313 void PluginInstance::PromiseRejected(PP_Instance instance,
    314                                      uint32 promise_id,
    315                                      PP_CdmExceptionCode exception_code,
    316                                      uint32 system_code,
    317                                      PP_Var error_description_var) {
    318   NOTIMPLEMENTED();
    319 }
    320 
    321 void PluginInstance::SessionMessage(PP_Instance instance,
    322                                     PP_Var web_session_id_var,
    323                                     PP_Var message_var,
    324                                     PP_Var destination_url_var) {
    325   NOTIMPLEMENTED();
    326 }
    327 
    328 void PluginInstance::SessionReady(PP_Instance instance,
    329                                   PP_Var web_session_id_var) {
    330   NOTIMPLEMENTED();
    331 }
    332 
    333 void PluginInstance::SessionClosed(PP_Instance instance,
    334                                    PP_Var web_session_id_var) {
    335   NOTIMPLEMENTED();
    336 }
    337 
    338 void PluginInstance::SessionError(PP_Instance instance,
    339                                   PP_Var web_session_id_var,
    340                                   PP_CdmExceptionCode exception_code,
    341                                   uint32 system_code,
    342                                   PP_Var error_description_var) {
    343   NOTIMPLEMENTED();
    344 }
    345 
    346 void PluginInstance::DeliverBlock(PP_Instance instance,
    347                                   PP_Resource decrypted_block,
    348                                   const PP_DecryptedBlockInfo* block_info) {
    349   NOTIMPLEMENTED();
    350 }
    351 
    352 void PluginInstance::DecoderInitializeDone(PP_Instance instance,
    353                                            PP_DecryptorStreamType decoder_type,
    354                                            uint32_t request_id,
    355                                            PP_Bool success) {
    356   NOTIMPLEMENTED();
    357 }
    358 
    359 void PluginInstance::DecoderDeinitializeDone(
    360     PP_Instance instance,
    361     PP_DecryptorStreamType decoder_type,
    362     uint32_t request_id) {
    363   NOTIMPLEMENTED();
    364 }
    365 
    366 void PluginInstance::DecoderResetDone(PP_Instance instance,
    367                                       PP_DecryptorStreamType decoder_type,
    368                                       uint32_t request_id) {
    369   NOTIMPLEMENTED();
    370 }
    371 
    372 void PluginInstance::DeliverFrame(PP_Instance instance,
    373                                   PP_Resource decrypted_frame,
    374                                   const PP_DecryptedFrameInfo* frame_info) {
    375   NOTIMPLEMENTED();
    376 }
    377 
    378 void PluginInstance::DeliverSamples(PP_Instance instance,
    379                                     PP_Resource audio_frames,
    380                                     const PP_DecryptedSampleInfo* sample_info) {
    381   NOTIMPLEMENTED();
    382 }
    383 
    384 PP_Var PluginInstance::ResolveRelativeToDocument(
    385     PP_Instance instance,
    386     PP_Var relative,
    387     PP_URLComponents_Dev* components) {
    388   NOTIMPLEMENTED();
    389   return PP_MakeUndefined();
    390 }
    391 
    392 PP_Bool PluginInstance::DocumentCanRequest(PP_Instance instance, PP_Var url) {
    393   NOTIMPLEMENTED();
    394   return PP_FALSE;
    395 }
    396 
    397 PP_Bool PluginInstance::DocumentCanAccessDocument(PP_Instance instance,
    398                                                   PP_Instance target) {
    399   NOTIMPLEMENTED();
    400   return PP_FALSE;
    401 }
    402 
    403 PP_Var PluginInstance::GetPluginInstanceURL(PP_Instance instance,
    404                                             PP_URLComponents_Dev* components) {
    405   NOTIMPLEMENTED();
    406   return PP_MakeUndefined();
    407 }
    408 
    409 PP_Var PluginInstance::GetPluginReferrerURL(PP_Instance instance,
    410                                             PP_URLComponents_Dev* components) {
    411   NOTIMPLEMENTED();
    412   return PP_MakeUndefined();
    413 }
    414 
    415 }  // namespace examples
    416 }  // namespace mojo
    417