browserplugins/browseraudiovideoplugin/src/BavpPlugin.cpp
changeset 0 84ad3b177aa3
child 5 e45c3f40ea5f
equal deleted inserted replaced
-1:000000000000 0:84ad3b177aa3
       
     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:  Interface to Browser for handling embedded video requests.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <BrowserAudioVideoPlugin.rsg>
       
    21 #include <StringLoader.h>
       
    22 #include <data_caging_path_literals.hrh>
       
    23 #include <bautils.h>
       
    24 
       
    25 #include "BavpLogger.h"
       
    26 #include "BavpPlugin.h"
       
    27 #include "BavpView.h"
       
    28 #include "BavpControllerAudio.h"
       
    29 #include "BavpControllerVideo.h"
       
    30 
       
    31 #include <npscript.h>
       
    32 
       
    33 // CONSTANTS
       
    34 _LIT( KBrowserAVPluginRscFileZ, "z:BrowserAudioVideoPlugin.rsc" );
       
    35 _LIT( KBrowserAVPluginRscFile, "\\resource\\BrowserAudioVideoPlugin.rsc");
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CBavpPlugin::CBavpPlugin
       
    41 // C++ default constructor can NOT contain any code, that
       
    42 // might leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 CBavpPlugin::CBavpPlugin()
       
    45     : iError( EFalse ),
       
    46     iMimeType( NULL )
       
    47     {
       
    48     
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CBavpPlugin::ConstructL
       
    53 // Symbian 2nd phase constructor can leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 void CBavpPlugin::ConstructL()
       
    56     {
       
    57     TFileName fileName;
       
    58     TParse parse;
       
    59                
       
    60     Dll::FileName (fileName);
       
    61     parse.Set(KBrowserAVPluginRscFile, &fileName, NULL);
       
    62     fileName = parse.FullName();        
       
    63     BaflUtils::NearestLanguageFile(CCoeEnv::Static()->FsSession(), fileName);
       
    64     if ( !BaflUtils::FileExists( CCoeEnv::Static()->FsSession(), fileName ) )        
       
    65         {
       
    66         // Use the Z drive one
       
    67         parse.Set( KBrowserAVPluginRscFileZ, &KDC_RESOURCE_FILES_DIR, NULL );
       
    68         fileName = parse.FullName(); 
       
    69         BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(),fileName );
       
    70         }
       
    71     iResourceOffset = CCoeEnv::Static()->AddResourceFileL( fileName );
       
    72     iDrmHelper = CDRMHelper::NewL( *CCoeEnv::Static() );             
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CBavpPlugin::NewL
       
    77 // Two-phased constructor.
       
    78 // -----------------------------------------------------------------------------
       
    79 CBavpPlugin* CBavpPlugin::NewL()
       
    80     {
       
    81     Log( EFalse, _L("CBavpPlugin::NewL") );
       
    82     
       
    83     CBavpPlugin* self = new (ELeave) CBavpPlugin;
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL();
       
    86     CleanupStack::Pop( self );
       
    87     
       
    88     return self;
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CBavpPlugin::Destructor
       
    93 // -----------------------------------------------------------------------------
       
    94 CBavpPlugin::~CBavpPlugin()
       
    95     {
       
    96     Log( EFalse, _L("CBavpPlugin::~CBavpPlugin") );
       
    97 
       
    98     delete iBavpController;
       
    99 
       
   100     delete iFileName;
       
   101 
       
   102     delete iBavpView;
       
   103         
       
   104     delete iDrmHelper;
       
   105     
       
   106     if ( iMimeType )
       
   107     {
       
   108         delete iMimeType;
       
   109     }
       
   110     
       
   111     
       
   112     if ( iResourceOffset )
       
   113         {
       
   114         CCoeEnv::Static()->DeleteResourceFile( iResourceOffset );
       
   115         }
       
   116     if ( iNPObject )
       
   117         {
       
   118         if (iNPObject->plugin == this)
       
   119             iNPObject->plugin = 0;
       
   120         NPN_ReleaseObject((struct NPObject*)(iNPObject));
       
   121         }
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CBavpPlugin::SetWindowL
       
   126 // Handles the creation of the window for the video file.
       
   127 // Called by Browser for window creation.
       
   128 // aPluginAdapter allows callback to Browser. aRect is window size.
       
   129 // -----------------------------------------------------------------------------
       
   130 void CBavpPlugin::SetWindowL( MPluginAdapter *aPluginAdapter,
       
   131                               NPWindow* aWindow, NPP aInstance )
       
   132     {
       
   133     Log( EFalse, _L("CBavpPlugin::SetWindowL") );
       
   134 
       
   135     // Set our PluginAdapter
       
   136     iPluginAdapter = aPluginAdapter;
       
   137     iNPP = aInstance;
       
   138 
       
   139     // Check if error occurs last time for setWindowL
       
   140     if ( iError )
       
   141         {
       
   142         // Stop browser calling NotifyL
       
   143         iPluginAdapter->SetPluginNotifier( NULL );
       
   144         
       
   145         // Error detected on OpenAndPlayFile
       
   146         return;
       
   147         }
       
   148 
       
   149     if ( !iBavpView )
       
   150         {
       
   151         iBavpView = CBavpView::NewL( (CCoeControl*)iPluginAdapter->GetParentControl(), TRect(0, 0, 0, 0), this);
       
   152 
       
   153         // Note: The pluginAdapter returns NULL
       
   154         iBavpView->SetObserver( aPluginAdapter->GetParentControlObserver() );
       
   155 
       
   156         // Register for Browser Notifications
       
   157         iPluginAdapter->SetPluginNotifier( (MPluginNotifier *)this );
       
   158         
       
   159         // Add option menu handler
       
   160         iPluginAdapter->SetOptionMenuHandler( (MOptionMenuHandler *)iBavpView );
       
   161     
       
   162         // Notify Browser that plugin has been constructed
       
   163         iPluginAdapter->PluginConstructedL( iBavpView );
       
   164         }
       
   165     else
       
   166         {
       
   167         // Only setRect() is enough, since it calls SizeChanged() and
       
   168         // inside it refreshes the rect's coordinate
       
   169         iBavpView->SetRect( aWindow );
       
   170         
       
   171         // If we have a Rtsp scheme, we need to play it (aka start the
       
   172         // BavpControllerVideo). We only do this once
       
   173         if ( iRtspUrl )
       
   174             {
       
   175             OpenAndPlayUrlL( *iRtspUrl );
       
   176             delete iRtspUrl;
       
   177             iRtspUrl = NULL;
       
   178             }
       
   179         }
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CBavpPlugin::OpenAndPlayFileL
       
   184 // Called by Browser when ready for file to be played
       
   185 // -----------------------------------------------------------------------------
       
   186 void CBavpPlugin::OpenAndPlayFileL( const TDesC& aFilename, const HBufC* originalFileName )
       
   187     {
       
   188     Log( EFalse, _L("CBavpPlugin::OpenAndPlayFileL"), (TInt)this );
       
   189 
       
   190     if ( !iBavpView )
       
   191         {
       
   192         // The view is not set yet.
       
   193         // Re-invoke the OpenAndPlayFile after the window has been initialized
       
   194         delete iFileName;
       
   195         iFileName = NULL;
       
   196         iFileName = aFilename.AllocL();
       
   197         }
       
   198     else
       
   199         {
       
   200         if ( iBavpController )
       
   201             {
       
   202             // Will stop current audio or video player
       
   203             delete iBavpController;
       
   204             iBavpController = NULL;
       
   205             
       
   206             // Set to null, otherwise, plugin will crash when it switches file
       
   207             iBavpView->SetBavpController( NULL );
       
   208             }
       
   209 
       
   210         // Determine if file is audio or video, so we can start up an audio
       
   211         // or video controller
       
   212         CBavpMediaRecognizer* mediaRecognizer = CBavpMediaRecognizer::NewL();
       
   213         CleanupStack::PushL( mediaRecognizer );
       
   214         TBavpMediaType mediaType = mediaRecognizer->IdentifyMediaTypeL( aFilename );
       
   215         CleanupStack::PopAndDestroy();  // mediaRecognizer
       
   216         
       
   217         // Do we have audio content, let the audio controller handle it
       
   218         if ( mediaType == ELocalAudioFile || mediaType == ELocalAudioPlaylist )
       
   219             {
       
   220             iBavpController = CBavpControllerAudio::NewL( iBavpView,
       
   221                                                           iAccessPtId,
       
   222                                                           mediaType,
       
   223                                                           aFilename );
       
   224             }
       
   225         else
       
   226             {
       
   227             // We got other content, let the video controller handle it.
       
   228             iBavpController = CBavpControllerVideo::NewL( iBavpView,
       
   229                                                           iAccessPtId,
       
   230                                                           mediaType,
       
   231                                                           aFilename );
       
   232             }
       
   233 
       
   234         // Set the volume and loop from the attribute values
       
   235         iBavpController->SetVolumeFromAttribute( iVolume );
       
   236         iBavpController->SetLoopFromAttribute( iLoop, iInfiniteFlag );
       
   237         
       
   238         // Set the original file name & mime type
       
   239         iBavpController->SetOriginalFileName(originalFileName);
       
   240         iBavpController->SetMimeType(iMimeType);
       
   241         
       
   242         iBavpView->SetBavpController( iBavpController );
       
   243 
       
   244         TRAPD( err, iBavpController->PlayAudioVideoL() );
       
   245         if ( err )
       
   246             {
       
   247             Log( EFalse, _L("CBavpPlugin::OpenAndPlayFileL ERROR from PlayAudioVideoL") );
       
   248             iBavpController->iCurrentState = EBavpBadContent;
       
   249             iBavpView->UpdateView();
       
   250             User::Leave( err );
       
   251             }
       
   252         }
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CBavpPlugin::OpenAndPlayUrlL
       
   257 // Called by Browser when ready for url to be played
       
   258 // -----------------------------------------------------------------------------
       
   259 void CBavpPlugin::OpenAndPlayUrlL( const TDesC& aUrl )
       
   260     {
       
   261     Log( EFalse, _L("CBavpPlugin::OpenAndPlayUrlL"), (TInt)this );
       
   262 
       
   263     if ( iBavpController )
       
   264         {
       
   265         // Will stop current audio or video player
       
   266         delete iBavpController;
       
   267         iBavpController = NULL;
       
   268         
       
   269         // Set to null, otherwise, plugin will crash when it switches file
       
   270         iBavpView->SetBavpController( NULL );
       
   271         }
       
   272 
       
   273     iBavpController = CBavpControllerVideo::NewL( iBavpView,
       
   274                                                   iAccessPtId,
       
   275                                                   EUrl,
       
   276                                                   aUrl );
       
   277 
       
   278     // iRtspUrl is used as a flag in SetWindow, which is re-entrant, so delete
       
   279     // once we got a controller for it
       
   280     delete iRtspUrl;
       
   281     iRtspUrl = NULL;
       
   282 
       
   283     // Set the volume and loop from the attribute values
       
   284     iBavpController->SetVolumeFromAttribute( iVolume );
       
   285     iBavpController->SetLoopFromAttribute( iLoop, iInfiniteFlag );
       
   286     
       
   287     iBavpView->SetBavpController( iBavpController );
       
   288 
       
   289     iBavpController->PlayAudioVideoL();
       
   290     }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // CBavpPlugin::SetAccessPtId
       
   294 // Sets access pt id to be used
       
   295 // -----------------------------------------------------------------------------
       
   296 void CBavpPlugin::SetAccessPtId( TUint aAccessPtId )
       
   297     {
       
   298     iAccessPtId = aAccessPtId;
       
   299     }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // CBavpPlugin::SetVolumeAndLoop
       
   303 // Called to set the volume and loop value that we get from the webpage source
       
   304 // to be able to use it later 
       
   305 // -----------------------------------------------------------------------------
       
   306 void CBavpPlugin::SetVolumeAndLoop( TInt aVolume, TInt aLoop, TInt aInfiniteFlag )
       
   307     {
       
   308     // Save volume attribute value, pass to controller after it initializes
       
   309     iVolume = aVolume;
       
   310 
       
   311     // Save loop attribute values, pass to controller after it initializes
       
   312     iLoop = aLoop;
       
   313     iInfiniteFlag = aInfiniteFlag;
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CBavpPlugin::SetVolumeAndLoop
       
   318 // Called to set the volume and loop value that we get from the webpage source
       
   319 // to be able to use it later 
       
   320 // -----------------------------------------------------------------------------
       
   321 void CBavpPlugin::SetRtspUriL( const TDesC& aRtspUri )
       
   322     {
       
   323     iRtspUrl = aRtspUri.AllocL();
       
   324     }
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CBavpPlugin::NotifyL
       
   328 // MPluginNotifier callback, Browser calls this to inform Plugin of some event.
       
   329 // The biggest use is when the Browser goes in-focus or out-focus. Out-foucus
       
   330 // can happen when other component takes top of CCoeControl stack, such as the 
       
   331 // Option Menu, another application, Screen saver, ... 
       
   332 // -----------------------------------------------------------------------------
       
   333 TInt CBavpPlugin::NotifyL( TNotificationType aCallType, void* aParam )
       
   334     {
       
   335     switch ( aCallType )
       
   336         {
       
   337         case EApplicationFocusChanged:
       
   338             // The browser has gone in-focus (foreground), or out-focus
       
   339             // (background), i.e. the browser is not on top of CCoeControl stack,
       
   340             // so inform this plugin if it is in-focus or out-focus
       
   341             if ( iBavpController )
       
   342                 {
       
   343                 // If Browser out-focus, we send this plugin aParam=EFalse.
       
   344                 // If Browser in-focus, we send this plugin aParam=ETrue, if
       
   345                 // the plugin is (was) in-focus or activated.
       
   346                 iBavpController->HandleBrowserNotification( TBool(aParam) );
       
   347                 }
       
   348             break;
       
   349 
       
   350         default:
       
   351             // Not implemented
       
   352             break;
       
   353 
       
   354         };  // end of switch
       
   355         
       
   356     return NPERR_NO_ERROR;
       
   357     }
       
   358     
       
   359 // -----------------------------------------------------------------------------
       
   360 // CBavpPlugin::SetMimeType
       
   361 // Sets the mime name. Used for scripting functionality
       
   362 // -----------------------------------------------------------------------------
       
   363 void CBavpPlugin::SetMimeType( NPMIMEType type )
       
   364     {
       
   365     iMimeType = type.Alloc();
       
   366     }
       
   367     
       
   368 
       
   369 //  End of File