idlehomescreen/xmluirendering/renderingplugins/xnnppluginfactory/src/xnnppluginadapter.cpp
changeset 0 f72a12da539e
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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 "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:  Implementation for wrapper for a Netscape Plugin API.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "xnnppluginadapter.h"
       
    21 #include "xnnpplugincontroladapter.h"
       
    22 #include "xnnppluginhandler.h"
       
    23 #include "xnproperty.h"
       
    24 #include "xndomproperty.h"
       
    25 #include "xndompropertyvalue.h"
       
    26 #include "xndomlist.h"
       
    27 #include "xnnodepluginif.h"
       
    28 #include "xnuienginepluginif.h"
       
    29 #include "xnresource.h"
       
    30 #include "c_xnutils.h"
       
    31 
       
    32 // MACROS
       
    33 _LIT8( KContentFile, "contentfile" );
       
    34 _LIT8( KMediaType, "mediatype" );
       
    35 
       
    36 // LOCAL FUNCTION PROTOTYPES
       
    37 const TDesC8& GetStringPropertyL( CXnNodePluginIf& aNode, const TDesC8& aProperty );
       
    38 CXnResource* FindResource(TXnUiEnginePluginIf& aEngine, const TDesC& aResourceFileName );
       
    39 
       
    40 // ============================= LOCAL FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // GetStringProperty Retrieves the string property for the node.
       
    44 // Returns: CXnNodePluginIf& aNode A node.
       
    45 //          TDesC8& aProperty A name of the property.
       
    46 //          const TDesC8 The value of property.
       
    47 // -----------------------------------------------------------------------------
       
    48 // 
       
    49 const TDesC8& GetStringPropertyL(
       
    50     CXnNodePluginIf& aNode,
       
    51     const TDesC8& aProperty )
       
    52     {
       
    53     CXnProperty* prop = aNode.GetPropertyL( aProperty );
       
    54     if( prop )
       
    55         {
       
    56         CXnDomPropertyValue* value = 
       
    57         static_cast<CXnDomPropertyValue*>(prop->Property()->PropertyValueList().Item(0));
       
    58         if( CXnDomPropertyValue::EIdent == value->PrimitiveValueType() ||
       
    59             CXnDomPropertyValue::EString == value->PrimitiveValueType() )
       
    60             {
       
    61             return prop->StringValue();
       
    62             }
       
    63         }
       
    64     return KNullDesC8;
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // FindResource Locates a resource from the resource list.
       
    69 // Returns: TXnUiEnginePluginIf& Pointer to UIEngine.
       
    70 //          const TDesC& The name of the resource file.
       
    71 //          CCnResource The actual resource.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CXnResource* FindResource(
       
    75     TXnUiEnginePluginIf& aEngine,
       
    76     const TDesC& aResourceFileName )    
       
    77     {
       
    78     if (aResourceFileName == KNullDesC)
       
    79         {
       
    80         return NULL;
       
    81         }
       
    82     CArrayPtrSeg<CXnResource>& resources = aEngine.Resources();
       
    83     for (TInt i = resources.Count() - 1; i >= 0; --i)
       
    84         {
       
    85         CXnResource* res = resources.At(i);
       
    86         if (res->ResourceId().Compare(aResourceFileName) == 0 )
       
    87             {
       
    88             return res;
       
    89             }
       
    90         }
       
    91     return NULL;
       
    92     }
       
    93 
       
    94 // ============================ MEMBER FUNCTIONS ===============================
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CXnNPPluginAdapter::NewL
       
    98 // Symbian static 1st phase constructor
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 CXnNPPluginAdapter* CXnNPPluginAdapter::NewL(
       
   102     CXnControlAdapter* aParent,
       
   103     CXnNodePluginIf& aNode )
       
   104     {
       
   105     CXnNPPluginAdapter* self = new( ELeave ) CXnNPPluginAdapter;
       
   106 
       
   107     CleanupStack::PushL( self );
       
   108     self->ConstructL( aParent, aNode );
       
   109     CleanupStack::Pop();
       
   110 
       
   111     return self;    
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CXnNPPluginAdapter::CXnNPPluginAdapter
       
   116 // C++ default constructor
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 CXnNPPluginAdapter::CXnNPPluginAdapter()
       
   120     {
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CXnNPPluginAdapter::~CXnNPPluginAdapter
       
   125 // C++ destructor
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 CXnNPPluginAdapter::~CXnNPPluginAdapter()
       
   129     {
       
   130     //Clean up the content file from private folder.
       
   131     iFs.Close(); 
       
   132     delete iContentFile;    
       
   133     
       
   134     if( iPluginFuncs )
       
   135         {        
       
   136         iPluginFuncs->destroy(iInstance,NULL);
       
   137         }
       
   138     delete iPluginFuncs;
       
   139     delete iPluginController;
       
   140     delete iPluginHandler;
       
   141     delete iInstance;
       
   142     }
       
   143     
       
   144 // -----------------------------------------------------------------------------
       
   145 // CXnNPPluginAdapter::ConstructL
       
   146 // Symbian 2nd phase constructor can leave.
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CXnNPPluginAdapter::ConstructL( 
       
   150     CXnControlAdapter* aParent,
       
   151     CXnNodePluginIf& aNode )
       
   152     {    
       
   153     iNode = &aNode;
       
   154     
       
   155     CXnControlAdapter::ConstructL( aNode );
       
   156     
       
   157     iPluginHandler = CXnNPPluginHandler::NewL();
       
   158 
       
   159     iPluginController = new (ELeave)CXnNPPluginControlAdapter;
       
   160     ConstructPluginL( aParent );   
       
   161     }
       
   162     
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CXnNPPluginAdapter::ConstructPluginL
       
   166 // Function returns if something goes wrong in plugin loading.
       
   167 // -----------------------------------------------------------------------------
       
   168 //    
       
   169 TInt CXnNPPluginAdapter::ConstructPluginL( CXnControlAdapter* aParent )
       
   170     {
       
   171     const TDesC8& mimeType = GetStringPropertyL( *iNode, KMediaType );
       
   172     const TDesC8& contentFile = GetStringPropertyL( *iNode, KContentFile );
       
   173     
       
   174     iContentFile = HBufC::NewL( contentFile.Length() );
       
   175     TPtr cFilePtr = iContentFile->Des();
       
   176     cFilePtr.Copy( contentFile );
       
   177     
       
   178     //Connect to file server
       
   179     User::LeaveIfError( iFs.Connect() );
       
   180     iFs.CreatePrivatePath( EDriveC );    
       
   181     
       
   182     // Return if plugin could not be loaded.
       
   183     if( KErrNone != iPluginHandler->LoadSpecificPluginL( mimeType, &iPluginFuncs ))
       
   184         {
       
   185         return KErrGeneral;
       
   186         }    
       
   187 
       
   188     // Call parent
       
   189     iPluginController->iParentControlAdapter = aParent;
       
   190     
       
   191     iInstance = ( NPP ) User::AllocL( sizeof( NPP_t ));
       
   192     iInstance->ndata = ( void* ) iPluginController;
       
   193     iInstance->pdata = NULL;
       
   194     
       
   195     CDesCArray* argn = new( ELeave ) CDesCArrayFlat(1);
       
   196     CDesCArray* argv = new( ELeave ) CDesCArrayFlat(1);
       
   197 
       
   198     argn->AppendL( KNullDesC );
       
   199     argv->AppendL( KNullDesC );
       
   200 
       
   201     if (( iPluginFuncs ) && ( iPluginFuncs->newp ))
       
   202         {
       
   203         TDesC8* string( NULL );
       
   204         iPluginFuncs->newp(*string, iInstance, NP_EMBED, CONST_CAST( CDesCArray*, argn ),
       
   205                            CONST_CAST( CDesCArray*, argv ), NULL);
       
   206         }
       
   207     else
       
   208         {
       
   209         delete argn;
       
   210         delete argv;
       
   211         return KErrGeneral;
       
   212         }
       
   213     
       
   214     TRect rect = iNode->Rect();
       
   215     // Coordinates for the plugin always start from (0,0) and are relative 
       
   216     // to the parent CCoeControl
       
   217     NPWindow window;
       
   218     window.x = 0;
       
   219     window.y = 0;
       
   220     window.width = rect.Width();
       
   221     window.height = rect.Height();
       
   222     window.type = NPWindowTypeDrawable;
       
   223     window.window = ( void* ) iPluginController;
       
   224     window.clipRect.top = window.x;
       
   225     window.clipRect.bottom = window.x + window.height;
       
   226     window.clipRect.left = window.y;
       
   227     window.clipRect.right = window.y + window.width;
       
   228     // Finally set the window.       
       
   229     iPluginFuncs->setwindow(iInstance,&window);
       
   230     
       
   231     NPStream* npstream = ( NPStream* )User::AllocL( sizeof( NPStream ));
       
   232     npstream->url = NULL;
       
   233     npstream->notifyData = NULL;
       
   234     
       
   235     TPtr resFileName = iContentFile->Des();
       
   236     /*TInt bitmapIndex;
       
   237     CXnResource* resource = CXnUtils::FindResource( iNode->UiEngineL()->Resources(),
       
   238                                                    resFileName, bitmapIndex );
       
   239     if( !resource )
       
   240         {
       
   241         User::Leave( KErrNotFound );
       
   242         }
       
   243     TParsePtrC pathParser( resource->FileName() );
       
   244     TPtrC driveAndPath = pathParser.DriveAndPath();*/
       
   245     
       
   246     npstream->url = resFileName.AllocL();
       
   247     
       
   248     iPluginFuncs->asfile( iInstance, npstream, resFileName );
       
   249     
       
   250     // Tell the plugin to destroy its stream
       
   251     iPluginFuncs->destroystream( iInstance, npstream, 0 );
       
   252     // Delete the NPStream object    
       
   253     delete npstream->url;
       
   254     delete npstream;
       
   255     delete argn;
       
   256     delete argv;
       
   257     return KErrNone;
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CXnNPPluginAdapter::SizeChanged
       
   262 // (Other items were commented in header.)
       
   263 // -----------------------------------------------------------------------------
       
   264 //      
       
   265 void CXnNPPluginAdapter::SizeChanged()
       
   266     {
       
   267     if( iPluginFuncs )
       
   268         {        
       
   269         TRect rect = iNode->Rect();
       
   270         // Coordinates for the plugin always start from (0,0) and are relative 
       
   271         // to the parent CCoeControl
       
   272         NPWindow window;
       
   273         window.x = 0;
       
   274         window.y = 0;
       
   275         window.width = rect.Width();
       
   276         window.height = rect.Height();
       
   277         window.type = NPWindowTypeDrawable;
       
   278         window.window = ( void* ) iPluginController;
       
   279         window.clipRect.top = window.x;
       
   280         window.clipRect.bottom = window.x + window.height;
       
   281         window.clipRect.left = window.y;
       
   282         window.clipRect.right = window.y + window.width;
       
   283         // Finally set the window.
       
   284         iPluginFuncs->setwindow(iInstance,&window);
       
   285         // Set the correct position to the parent CCoeControl.
       
   286         iPluginController->iNPPControlAdapter->SetPosition( TPoint( rect.iTl.iX, rect.iTl.iY ));
       
   287         }
       
   288     }
       
   289 // -----------------------------------------------------------------------------
       
   290 // CXnNPPluginAdapter::DoEnterPowerSaveModeL
       
   291 // Enter power save mode
       
   292 // -----------------------------------------------------------------------------
       
   293 void CXnNPPluginAdapter::DoEnterPowerSaveModeL(TModeEvent /*aEvent*/)
       
   294     {
       
   295     if ( iPluginController->iPluginNotifier )
       
   296         {
       
   297          iPluginController->iPluginNotifier->NotifyL
       
   298         (MPluginNotifier::EApplicationFocusChanged, NULL);      
       
   299         }
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CXnNPPluginAdapter::DoExitPowerSaveModeL
       
   304 // Exit power save mode
       
   305 // -----------------------------------------------------------------------------
       
   306 void CXnNPPluginAdapter::DoExitPowerSaveModeL(TModeEvent /*aEvent*/)
       
   307     {
       
   308     if ( iPluginController->iPluginNotifier )
       
   309         {
       
   310         TBool param(ETrue);
       
   311         iPluginController->iPluginNotifier->NotifyL 
       
   312             (MPluginNotifier::EApplicationFocusChanged, &param );  
       
   313        
       
   314         }
       
   315     }   
       
   316 // End of file