browserplugins/browseraudiovideoplugin/src/BavpApi.cpp
branchRCL_3
changeset 65 8e6fa1719340
equal deleted inserted replaced
64:6385c4c93049 65:8e6fa1719340
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  API functions that were loaded into TLS for the Browser to use.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <Uri16.h>
       
    20 #include <mmf/common/MmfControllerFrameworkBase.h>
       
    21 #include <stdlib.h>
       
    22 
       
    23 #include "BavpLogger.h"
       
    24 #include "BavpPlugin.h"
       
    25 #include "BavpVolumeHandler.h"
       
    26 
       
    27 #include <npscript.h>
       
    28 #include "BavpNPObject.h"
       
    29 // CONSTANTS
       
    30 _LIT(KAccessPtId, "accesspointid");
       
    31 _LIT(KLoop,"loop");
       
    32 _LIT(KSrc,"src");
       
    33 _LIT(KData,"data");
       
    34 _LIT(KRtsp,"rtsp");
       
    35 _LIT(KInfinite,"infinite");
       
    36 _LIT(KVolume, "volume");
       
    37 _LIT(KHigh, "high");
       
    38 _LIT(KMiddle, "middle");
       
    39 _LIT(KLow, "low");
       
    40 
       
    41 const TInt KOneLoopValue = 1;
       
    42 const TInt KMaxLoopValue = 50; 
       
    43 
       
    44 // ============================= LOCAL FUNCTIONS ===============================
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // BavpNewp
       
    48 // Create a new instance of a plugin. This is non-leaving method.
       
    49 // Returns: NPError: Error codes recognized by Browser
       
    50 // -----------------------------------------------------------------------------
       
    51 NPError BavpNewp( NPMIMEType /* pluginType*/,   // Not used locally
       
    52                   NPP aInstance,                // Stores pointer to Bavp 
       
    53                   uint16 /* mode */,            // 
       
    54                   CDesCArray* argn,             // The number of arguments passed
       
    55                   CDesCArray* argv,             // The values of arguments in the array
       
    56                   NPSavedData* /*saved*/ )      // 
       
    57     {
       
    58         
       
    59     // Fix for TSW error ID:  SLON-74588K, as ControlPanel is unsupported so for the time being
       
    60     // controlPanel plugin window shown as emplty non supported window.
       
    61 
       
    62     _LIT(KControls, "controls");     
       
    63     _LIT(KControlPanel, "controlpanel");
       
    64    
       
    65     for ( TInt i=0; i < argn->Count(); i++ )
       
    66     {
       
    67     if(((*argn)[i].Compare( KControls) == 0)&&((*argv)[i].Compare(KControlPanel ) == 0))
       
    68         {
       
    69             return NPERR_INVALID_PLUGIN_ERROR;
       
    70         }
       
    71     }
       
    72     // Create BrowserAudioVideoPlugin, call this leaving method to wrap leaving methods
       
    73     TRAPD( err, BavpConstructL( aInstance, argn, argv ) );
       
    74     if ( err == KErrNoMemory )
       
    75         {       
       
    76         Log( EFalse, _L("FUNCTION BavpNewp ERROR! Out of Memory Error") );
       
    77 
       
    78         return NPERR_OUT_OF_MEMORY_ERROR;
       
    79         }
       
    80         
       
    81     if ( err != KErrNone )
       
    82         {
       
    83         Log( EFalse, _L("FUNCTION BavpNewp ERROR! Module Load Failure") );
       
    84         return NPERR_MODULE_LOAD_FAILED_ERROR;
       
    85         }
       
    86         
       
    87     return NPERR_NO_ERROR;
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // BavpConstructL
       
    92 // This is the leaving method to create the plugin.  We have leaving setters
       
    93 // that need to be wrapped.
       
    94 // Returns: void
       
    95 // -----------------------------------------------------------------------------
       
    96 void BavpConstructL( NPP aInstance,     // Stores pointer to Bavp 
       
    97                      CDesCArray* argn,  // The number of arguments passed
       
    98                      CDesCArray* argv ) // The values of arguments in the array
       
    99     {
       
   100     Log( EFalse, _L("Calling FUNCTION BavpConstructL") );
       
   101     
       
   102     CBavpPlugin *pluginInstance( NULL );
       
   103 
       
   104     // Create BrowserVideoPlugin        
       
   105     pluginInstance = CBavpPlugin::NewL();   
       
   106 
       
   107     // Bavp functions can now be called
       
   108     aInstance->pdata = pluginInstance;
       
   109     
       
   110     // Retrieve the various attributes from the HTTP file and the
       
   111     // object/embed/bgsound/soundstart tags on that page
       
   112     //
       
   113     // Retrieve the access point attribute
       
   114     TInt accessPtIndex;
       
   115     TInt accessPtId( KUseDefaultIap );
       
   116     if  ( !argn->Find( KAccessPtId, accessPtIndex, ECmpFolded ) )
       
   117         {
       
   118         // If the string is found get the access pt id and convert to TInt
       
   119         TPtrC16 accessPtValue( (*argv)[accessPtIndex] );
       
   120         TLex lex( accessPtValue );
       
   121         TInt intVal( 0 );
       
   122         if ( lex.Val( intVal ) == KErrNone)
       
   123           {
       
   124           accessPtId = intVal;
       
   125           }
       
   126         }
       
   127     pluginInstance->SetAccessPtId( accessPtId );
       
   128     
       
   129     // Retrieve the "loop" attribute value, default value is "1",
       
   130     // with infiniteFlag off. This handles the loop attribute missing
       
   131     // and loop="0" cases.
       
   132     TInt loopIndex( 0 );
       
   133     TPtrC16 loopValue;
       
   134     TBool infiniteFlag( EFalse );   // Always false, use loop="50" instead "infinite" 
       
   135     TInt loop( KOneLoopValue );     // Our default loop value is "1"
       
   136     
       
   137     TInt positionLoop = argn->Find( KLoop, loopIndex, ECmpFolded );
       
   138     if ( positionLoop == 0 )
       
   139         {
       
   140         // Found a loop attribute value
       
   141         TPtrC16 pointerLoopCount( (*argv)[loopIndex] );
       
   142         loopValue.Set( pointerLoopCount );
       
   143 
       
   144         // Is the loop value equal to string "infinite"
       
   145         if  ( loopValue.Compare( KInfinite ) == 0 )
       
   146             {
       
   147             // We never play true infinite, we loop max 50 times
       
   148             loop = KMaxLoopValue;
       
   149             }
       
   150         else
       
   151             {
       
   152             // Ensure that only a valid loop value is used (1 to 50)
       
   153             HBufC8* convertPointerLoopCount = HBufC8::New( pointerLoopCount.Length() );
       
   154             TPtr8 convertToByteLoop = convertPointerLoopCount->Des();
       
   155             convertToByteLoop.Copy( pointerLoopCount );
       
   156                 
       
   157             loop = atoi( (char*)(convertToByteLoop.Ptr()) );
       
   158             if ( loop < KOneLoopValue )
       
   159                 {
       
   160                 loop = KOneLoopValue;
       
   161                 }
       
   162             else if ( loop > KMaxLoopValue )
       
   163                 {
       
   164                 loop = KMaxLoopValue;
       
   165                 }
       
   166             }
       
   167         }
       
   168 
       
   169     // Retrieve the "volume" attribute value, default is max, so that if the
       
   170     // "volume" attribute isn't present, the user preferences will not get
       
   171     // overwritten.  There is a check in controller->SetVolumeByAttribute that
       
   172     // checks current and attribute volume and choses lower volume.
       
   173     TInt positionVolumeValue( 0 ); 
       
   174     TInt CRVolume( KCRVolumeMax );
       
   175     TPtrC16 volumeValue;
       
   176     TInt positionVol = argn->Find( KVolume, positionVolumeValue, ECmpFolded );
       
   177     if ( positionVol == 0 )
       
   178     {
       
   179         TPtrC16 pointerVolumeValue( (*argv)[positionVolumeValue] );
       
   180         volumeValue.Set( pointerVolumeValue );
       
   181         if (  !(volumeValue.Compare( KHigh )) )
       
   182             {
       
   183             CRVolume = KCRVolume10;
       
   184             }
       
   185         else if ( !(volumeValue.Compare( KMiddle )) )
       
   186             {
       
   187             CRVolume = KCRVolume5;
       
   188             }
       
   189         else if ( !(volumeValue.Compare( KLow )) )
       
   190             {
       
   191             CRVolume = KCRVolume2;
       
   192             }
       
   193         else
       
   194             {
       
   195             // Convert volume numeric string (i.e. volume="6") to CR volume
       
   196             HBufC8* convertPointerVolumeValue = HBufC8::New( pointerVolumeValue.Length() );
       
   197             TPtr8 convertToByteVolume = convertPointerVolumeValue->Des();
       
   198             convertToByteVolume.Append( pointerVolumeValue );
       
   199             CRVolume = atoi( (char*)(convertToByteVolume.Ptr()) );
       
   200             if ( CRVolume < KCRVolumeMute )
       
   201                 {
       
   202                 CRVolume = KCRVolumeMute;
       
   203                 }
       
   204             else if ( CRVolume > KCRVolumeMax )
       
   205                 {
       
   206                 CRVolume = KCRVolumeMax;
       
   207                 }
       
   208             }    
       
   209     }
       
   210     
       
   211     // Set the Volume and Loop for plugin
       
   212     pluginInstance->SetVolumeAndLoop( CRVolume, loop, infiniteFlag );
       
   213 
       
   214     // Retrieve the "src" or "data" attribute value, if it is rtsp scheme lets
       
   215     // save it, so we can start a controller, since rtsp content is not passed
       
   216     // by WebKit.  It is our (Bavp) responsibilty to load rtsp content.
       
   217     TInt srcIndex( 0 ); 
       
   218     TInt ret = argn->Find( KSrc, srcIndex, ECmpFolded );
       
   219     if  ( ret != 0 )
       
   220         {
       
   221         // If the src attribute NOT found, try to find data attribute
       
   222         ret = argn->Find( KData, srcIndex, ECmpFolded );
       
   223         }
       
   224 
       
   225     if ( ret == 0 )
       
   226         {
       
   227         // We found either data or src attribute
       
   228         TPtrC16 srcValue( (*argv)[ srcIndex ] );
       
   229         TUriParser uriParser;
       
   230         uriParser.Parse( srcValue );
       
   231         if ( !uriParser.Extract( EUriScheme ).Compare( KRtsp ) )
       
   232             {
       
   233             // We found a RTSP scheme. Lets save it up, so when the BavpView
       
   234             // is create we can start the BavpController and load rtsp. This
       
   235             // is because rtsp will not be started by a call to BavpAsFile().
       
   236             // NOTE: Files (http) are downloaded first and then BavpAsFile()
       
   237             // is called, which starts the BavpController.
       
   238             pluginInstance->SetRtspUriL( uriParser.UriDes() );
       
   239             
       
   240             // We may have to move this to a different place if eg: the url of
       
   241             // the object is changed later (say from javascript)
       
   242             CBavpPluginEcomMain* lBavpPluginEcomMain = (CBavpPluginEcomMain*) Dll::Tls();
       
   243             NPNetscapeFuncs* funcPtr = lBavpPluginEcomMain->Funcs();
       
   244             if ( funcPtr && funcPtr->getvalue ) 
       
   245                {
       
   246                funcPtr->getvalue( aInstance, NPNNetworkAccess, (void *)&accessPtId);
       
   247                pluginInstance->SetAccessPtId( accessPtId );
       
   248                }
       
   249             
       
   250             }
       
   251         }
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // BavpDestroy(NPP aInstance, NPSavedData**)
       
   256 // Called by Browser to destroy the plugin
       
   257 // Returns: NPError: Error Code
       
   258 // -----------------------------------------------------------------------------
       
   259 NPError BavpDestroy( NPP    aInstance,          // Link to Browser
       
   260                      NPSavedData** /*save*/ )   // Not used locally
       
   261     {
       
   262     Log( EFalse, _L("Calling FUNCTION BavpDestroy") );
       
   263 
       
   264     CBavpPlugin *pluginInstance = STATIC_CAST( CBavpPlugin*, aInstance->pdata );
       
   265     delete pluginInstance;
       
   266 
       
   267     return NPERR_NO_ERROR;
       
   268     }
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // BavpSetwindow
       
   272 // This is the parent window of plugin
       
   273 // Returns: NPError: Error Code
       
   274 // -----------------------------------------------------------------------------
       
   275 NPError BavpSetwindow( NPP aInstance,       // Link to Browser
       
   276                        NPWindow* aWindow )  // Browser's window passed to Bavp
       
   277     {
       
   278     Log( EFalse, _L("Calling FUNCTION BavpSetwindow") );
       
   279 
       
   280     CBavpPlugin *pluginInstance = STATIC_CAST( CBavpPlugin*, aInstance->pdata );
       
   281     MPluginAdapter *pluginAdapter = STATIC_CAST( MPluginAdapter*, aWindow->window);
       
   282     
       
   283     TRAPD( err, pluginInstance->SetWindowL(pluginAdapter, aWindow, aInstance) );
       
   284     if ( err == KErrNoMemory )
       
   285         {
       
   286         Log( EFalse, _L("FUNCTION BavpSetWindow ERROR! Out of Memory Error") );
       
   287 
       
   288         // Set the error to plugin if err occurs, it's for the next create plugin check
       
   289         pluginInstance->iError = ETrue;
       
   290         return NPERR_OUT_OF_MEMORY_ERROR;
       
   291         }
       
   292         
       
   293     if ( err != KErrNone )
       
   294         {
       
   295         Log( EFalse, _L("FUNCTION BavpSetWindow ERROR: %d"), err );
       
   296 
       
   297         // Set the error to plugin if err occurs, it's for the next create plugin check
       
   298         pluginInstance->iError = ETrue;
       
   299         return NPERR_GENERIC_ERROR;
       
   300         }
       
   301         
       
   302     return NPERR_NO_ERROR;
       
   303     }
       
   304 
       
   305 // -----------------------------------------------------------------------------
       
   306 // BavpNewstream
       
   307 // Indicates start of downloading of an video file from the internet
       
   308 // Returns: NPError: Error Code
       
   309 // -----------------------------------------------------------------------------
       
   310 NPError BavpNewstream( NPP instance,         
       
   311                        NPMIMEType type,      
       
   312                        NPStream* /*stream*/,    // 
       
   313                        NPBool /*seekable*/,     // 
       
   314                        uint16* stype )          // Will set to NP_ASFILEONLY to notify Browser how to send data 
       
   315     {
       
   316     Log( EFalse, _L("Calling FUNCTION BavpNewstream") );
       
   317 
       
   318     // Bavp needs to set stype to alert Browser to send data via Bavp_asfile
       
   319     *stype = NP_ASFILEONLY; 
       
   320     
       
   321     CBavpPlugin *pluginInstance = STATIC_CAST( CBavpPlugin*, instance->pdata );
       
   322     
       
   323     pluginInstance->SetMimeType( type );
       
   324     
       
   325     return NPERR_NO_ERROR;
       
   326     }
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // BavpDestroystream    NOT USED
       
   330 // Indicates completion of downloading an video file from the internet
       
   331 // Returns: NPError: Error Code
       
   332 // -----------------------------------------------------------------------------
       
   333 NPError BavpDestroystream( NPP  /*instance*/,       // Not used locally
       
   334                            NPStream* /*stream*/,    //
       
   335                            NPReason /*aReason*/ )   //
       
   336     {
       
   337     Log( EFalse, _L("Calling FUNCTION BavpDestroyStream") );
       
   338 
       
   339     return NPERR_NO_ERROR; 
       
   340     }
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 // BavpAsfile
       
   344 // Called by Browser when data is copied to a file.
       
   345 // Returns: void
       
   346 // -----------------------------------------------------------------------------
       
   347 void BavpAsfile( NPP aInstance,             // Link to Browser
       
   348                  NPStream* stream,      
       
   349                  const TDesC& aFileName )   // file name and path
       
   350     {
       
   351     Log( EFalse, _L("Calling FUNCTION BavpAsfile") );
       
   352     Log( EFalse, _L("Filename:") );
       
   353     Log( EFalse, aFileName );
       
   354 
       
   355     CBavpPlugin *pluginInstance = STATIC_CAST( CBavpPlugin*, aInstance->pdata );
       
   356     
       
   357     // Get the error, and set this error to iError in plugin
       
   358     TRAPD( err, pluginInstance->OpenAndPlayFileL( aFileName, stream->url ) );
       
   359     if ( err != KErrNone )
       
   360         {
       
   361         Log( EFalse, _L("FUNCTION BavpAsfile ERROR!") );
       
   362 
       
   363         // If error, set for plugin, it's for the next create plugin check
       
   364         pluginInstance->iError = ETrue;
       
   365         }
       
   366     }
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 // BavpWriteready       NOT SUPPORTED
       
   370 // -----------------------------------------------------------------------------
       
   371 int32 BavpWriteready( NPP /*instance*/,     
       
   372                       NPStream* /*stream*/ )    
       
   373     {
       
   374     // Not implemented
       
   375     return NPERR_NO_ERROR;
       
   376     }
       
   377 
       
   378 // -----------------------------------------------------------------------------
       
   379 // BavpWrite     NOT SUPPORTED
       
   380 // -----------------------------------------------------------------------------
       
   381 int32 BavpWrite( NPP /*instance*/,  
       
   382                  NPStream* /*stream*/,   
       
   383                  int32 /*offset*/,      
       
   384                  int32 /*len*/,     
       
   385                  void* /*buffer*/ )
       
   386         {
       
   387         // Not implemented
       
   388         return NPERR_NO_ERROR; 
       
   389         }
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // BavpPrint        NOT SUPPORTED
       
   393 // -----------------------------------------------------------------------------
       
   394 void BavpPrint( NPP /*instance*/,           
       
   395                 NPPrint* /*platformPrint*/ )    
       
   396     {
       
   397     // Not implemented
       
   398     }
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // BavpEvent        NOT SUPPORTED
       
   402 // -----------------------------------------------------------------------------
       
   403 int16 BavpEvent( NPP instance,
       
   404                  void* event )      
       
   405     {
       
   406     TInt ret = EFalse;
       
   407     if (instance)
       
   408         {
       
   409         CBavpPlugin *plugin = static_cast<CBavpPlugin*>(instance->pdata);
       
   410         NPEvent *ev = static_cast<NPEvent*>(event);
       
   411     
       
   412         if (plugin)
       
   413             {
       
   414             if (ev->event == ENppEventPointer)
       
   415                 {
       
   416                 NPEventPointer *evp =static_cast<NPEventPointer*> (ev->param);
       
   417                 ret = plugin->HandleGesture(evp->reserved);
       
   418                 }
       
   419             }
       
   420         }
       
   421     return ret;
       
   422     }
       
   423 
       
   424 // -----------------------------------------------------------------------------
       
   425 // BavpUrlnotify        NOT SUPPORTED
       
   426 // -----------------------------------------------------------------------------
       
   427 void BavpUrlnotify( NPP /*instance*/,       
       
   428                     const TDesC8& /*url*/,  
       
   429                     NPReason /*reason*/,    
       
   430                     void* /*notifyData*/ )
       
   431     {
       
   432     // Not implemented
       
   433     }
       
   434 
       
   435 // -----------------------------------------------------------------------------
       
   436 // BavpSetvalue     NOT SUPPORTED
       
   437 // -----------------------------------------------------------------------------
       
   438 NPError BavpSetvalue( NPP /*instance*/,     
       
   439                       NPNVariable /*variable*/,
       
   440                       void* /*ret_value*/ )
       
   441     {
       
   442     // Not implemented
       
   443     return NPERR_NO_ERROR;
       
   444     }
       
   445 
       
   446 // -----------------------------------------------------------------------------
       
   447 // BavpGetvalue     NOT SUPPORTED
       
   448 // -----------------------------------------------------------------------------
       
   449 NPError BavpGetvalue( NPP aInstance,        
       
   450                       NPPVariable aVariable,  
       
   451                       void* ret_value ) 
       
   452     {
       
   453     NPError err( NPERR_NO_ERROR );
       
   454 
       
   455         switch( aVariable )
       
   456         {
       
   457         case NPPVpluginInteractiveBool:
       
   458             // Interactive=0, Not Interactive=1
       
   459              *(TBool *)ret_value = EFalse;
       
   460              break;
       
   461         case NPPVpluginScriptableNPObject:
       
   462             {        
       
   463             // return instance of scripting object to the browser
       
   464             BavpNPObject *pluginNPObject = BavpNPObject_new( aInstance );        
       
   465         
       
   466             CBavpPlugin *bavpplugin = (CBavpPlugin*)aInstance->pdata;
       
   467             bavpplugin->SetNPObject(pluginNPObject);
       
   468             
       
   469             pluginNPObject->plugin = bavpplugin; 
       
   470             pluginNPObject->nppInstance = aInstance;
       
   471             void** ret = (void**)ret_value;
       
   472             *ret = (void*)pluginNPObject;        
       
   473             }
       
   474             break;
       
   475         default:
       
   476             break;
       
   477         }   //end switch
       
   478 
       
   479     return err;
       
   480     }
       
   481 
       
   482 //  End of File