idlehomescreen/xmluirendering/renderingplugins/xnnppluginfactory/src/xnnppluginhandler.cpp
changeset 0 f72a12da539e
child 1 5315654608de
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2002-2008 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:  Loads the browser plugin via ECOM.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "xnnppluginhandler.h"
       
    22 #include    <ecom/implementationinformation.h>
       
    23 #include    <CEcomBrowserPluginInterface.h>
       
    24 
       
    25 // ============================= LOCAL FUNCTIONS ===============================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // ParseAndMatchMimeTypeL Parses the matching mime types from the.given string.
       
    29 // Returns: TDesC8&: String that holds the mime types.
       
    30 //          TDesC8&: Mime type to match with.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 TBool ParseAndMatchMimeTypeL(
       
    34     const TDesC8& aMIMEDescription,
       
    35     const TDesC8& aMatch )
       
    36     {
       
    37     _LIT(KPatternPtr, ";|");
       
    38 
       
    39     TUint    end = aMIMEDescription.Length();
       
    40     TUint    i = 0;
       
    41     TUint    marker = 0;
       
    42     TUint    mimeSeparator = '|';
       
    43 
       
    44     // Parse the aMIMEDescription string.
       
    45     for (; i < end;)
       
    46         {
       
    47         // Search until end of buffer or match one of the delimiters ';' or '|'.
       
    48         // We are looking for the mimeType, ie "text/html", "application/pdf", etc.
       
    49         for (; (i < end) && (KPatternPtr().Locate((aMIMEDescription)[i]) == 
       
    50                              KErrNotFound); i++)
       
    51             {
       
    52             // Walking the aMIMEDescription string
       
    53             }
       
    54 
       
    55         if (i > marker)
       
    56             {
       
    57             // Try matching the found mime type with the given type.
       
    58             TPtrC8 newString( aMIMEDescription.Mid(marker, i - marker ).Ptr(), i - marker );
       
    59             if( newString == aMatch )
       
    60                 {
       
    61                 return ETrue;
       
    62                 }
       
    63             }
       
    64 
       
    65         // Are we at the end of the supported mime string
       
    66         if (i == end)
       
    67             {
       
    68             // This break with i=end means we leave outer for loop
       
    69             break;
       
    70             }
       
    71 
       
    72         marker = ++i;
       
    73         if ((aMIMEDescription)[i - 1] == mimeSeparator)
       
    74             {
       
    75             // Found a mime separator '|', get next supported mime
       
    76             continue;
       
    77             }        
       
    78         }   // end of for
       
    79         return EFalse;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // PluginWrapperGetUrl
       
    84 // Unsupported.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 static NPError PluginWrapperGetUrl(NPP /*aInstance*/, const TDesC& /*aUrl*/, 
       
    88         const TDesC* /*aWindowType*/ )
       
    89     {
       
    90     return NPERR_GENERIC_ERROR;
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // PluginWrapperPostUrl
       
    95 // Unsupported.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 static NPError PluginWrapperPostUrl(NPP /*aInstance*/, const TDesC& /*aUrl*/, 
       
    99         const TDesC* /*aWindowType*/, const TDesC& /*aBuf*/, NPBool /*aFile*/)
       
   100     {
       
   101     return NPERR_GENERIC_ERROR;
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // PluginWrapperRequestRead
       
   106 // Unsupported.
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 static NPError PluginWrapperRequestRead(NPStream* /*aStream*/, 
       
   110         NPByteRange* /*aRangeList*/)
       
   111     {
       
   112     return NPERR_GENERIC_ERROR;
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // PluginWrapperNewStream
       
   117 // Unsupported.
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 static NPError PluginWrapperNewStream(NPP /*aInstance*/, NPMIMEType /*aType*/, 
       
   121         const TDesC* /*aWindowType*/, NPStream** /*aStream*/)
       
   122     {
       
   123     return NPERR_GENERIC_ERROR;
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // PluginWrapperWrite
       
   128 // Unsupported.
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 static TInt32 PluginWrapperWrite(NPP /*aInstance*/, NPStream* /*aStream*/, 
       
   132         TInt32 /*aLen*/, void* /*aBuffer*/)
       
   133     {
       
   134     return NPERR_GENERIC_ERROR;
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // PluginWrapperDestroyStream
       
   139 // Unsupported.
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 static NPError PluginWrapperDestroyStream(NPP /*aInstance*/, 
       
   143         NPStream* /*aStream*/, NPReason /*aReason*/)
       
   144     {
       
   145     return NPERR_GENERIC_ERROR;
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // PluginWrapperStatus
       
   150 // Unsupported.
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 static void PluginWrapperStatus(NPP /*aInstance*/, const TDesC& /*aMessage*/)
       
   154     {
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // PluginWrapperUAgent
       
   159 // Unsupported.
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 static const TDesC* PluginWrapperUAgent(NPP /*aInstance*/)
       
   163     {
       
   164     return NULL;
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // PluginWrapperMemAlloc
       
   169 // Unsupported.
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 static void* PluginWrapperMemAlloc( uint32 /*aSize*/ )
       
   173     {
       
   174     return NULL;
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // PluginWrapperMemFree
       
   179 // Unsupported.
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 static void PluginWrapperMemFree( void* aPtr )
       
   183     {
       
   184     delete aPtr;
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // PluginWrapperMemFlush
       
   189 // Unsupported.
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 static uint32 PluginWrapperMemFlush(uint32 /*aSize*/)
       
   193     {
       
   194     return NPERR_GENERIC_ERROR;
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // PluginWrapperReloadPlugins
       
   199 // Unsupported.
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 static void PluginWrapperReloadPlugins(NPBool /*aReloadPages*/)
       
   203     {
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // PluginWrapperGetJavaEnv
       
   208 // Unsupported.
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 static JRIEnv* PluginWrapperGetJavaEnv()
       
   212     {
       
   213     return NULL;
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // PluginWrapperGetJavaPeer
       
   218 // Unsupported.
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 static jref PluginWrapperGetJavaPeer(NPP /*aInstance*/)
       
   222     {
       
   223     return NULL;
       
   224     }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // PluginWrapperGetUrlNotify
       
   228 // Unsupported.
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 static NPError PluginWrapperGetUrlNotify(NPP /*aInstance*/, const TDesC& /*aUrl*/, 
       
   232         const TDesC* /*aWindowType*/, void* /*aNotifyData*/)
       
   233     {
       
   234     return NPERR_GENERIC_ERROR;
       
   235     }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // PluginWrapperPostUrlNotify
       
   239 // Unsupported.
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 static NPError PluginWrapperPostUrlNotify(NPP /*aInstance*/, const TDesC& /*aUr*l*/, 
       
   243         const TDesC* /*aWindowType*/, const TDesC& /*aBuf*/, NPBool /*aFile*/, void* /*aNotifyData*/)
       
   244     {
       
   245     return NPERR_GENERIC_ERROR;
       
   246     }
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // PluginWrapperGetValue
       
   250 // Unsupported.
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 static NPError PluginWrapperGetValue(NPP /*aInstance*/, NPNVariable /*aVariable*/, 
       
   254         void* /*aRetValue*/)
       
   255     {
       
   256     return NPERR_NO_ERROR;
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // PluginWrapperSetValue
       
   261 // Unsupported.
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 static NPError PluginWrapperSetValue(NPP /*aInstance*/, NPPVariable /*aVariable*/, 
       
   265         void * /*aRetValue*/)
       
   266     {
       
   267     return NPERR_GENERIC_ERROR;
       
   268     }
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // PluginWrapperInvalidateRect
       
   272 // Unsupported.
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 static void PluginWrapperInvalidateRect(NPP /*aInstance*/, NPRect * /*aRect*/)
       
   276     {
       
   277     }
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // PluginWrapperInvalidateRegion
       
   281 // Unsupported.
       
   282 // -----------------------------------------------------------------------------
       
   283 //
       
   284 static void PluginWrapperInvalidateRegion(NPP /*aInstance*/, NPRegion /*aRegion*/)
       
   285     {
       
   286     }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // PluginWrapperForceRedraw
       
   290 // Unsupported.
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 static void PluginWrapperForceRedraw(NPP /*aInstance*/)
       
   294     {
       
   295     }
       
   296     
       
   297 const NPNetscapeFuncs PluginWrapperFuncs =
       
   298     {
       
   299     sizeof(NPNetscapeFuncs),
       
   300     1,
       
   301     PluginWrapperGetUrl,
       
   302     PluginWrapperPostUrl,
       
   303     PluginWrapperRequestRead,
       
   304     PluginWrapperNewStream,
       
   305     PluginWrapperWrite,
       
   306     PluginWrapperDestroyStream,
       
   307     PluginWrapperStatus,
       
   308     PluginWrapperUAgent,
       
   309     PluginWrapperMemAlloc,
       
   310     PluginWrapperMemFree,
       
   311     PluginWrapperMemFlush,
       
   312     PluginWrapperReloadPlugins,
       
   313     PluginWrapperGetJavaEnv,
       
   314     PluginWrapperGetJavaPeer,
       
   315     PluginWrapperGetUrlNotify,
       
   316     PluginWrapperPostUrlNotify,
       
   317     PluginWrapperGetValue,
       
   318     PluginWrapperSetValue,
       
   319     PluginWrapperInvalidateRect,
       
   320     PluginWrapperInvalidateRegion,
       
   321     PluginWrapperForceRedraw
       
   322     };
       
   323 
       
   324 // ============================ MEMBER FUNCTIONS ===============================
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CXnNPPluginHandler::CXnNPPluginHandler
       
   328 // C++ default constructor can NOT contain any code, that
       
   329 // might leave.
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 CXnNPPluginHandler::CXnNPPluginHandler()
       
   333     {
       
   334     }
       
   335 
       
   336 // -----------------------------------------------------------------------------
       
   337 // CXnNPPluginHandler::ConstructL
       
   338 // Symbian 2nd phase constructor can leave.
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341 void CXnNPPluginHandler::ConstructL()
       
   342     {
       
   343     }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // CXnNPPluginHandler::NewL
       
   347 // Two-phased constructor.
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 CXnNPPluginHandler* CXnNPPluginHandler::NewL()
       
   351     {
       
   352     CXnNPPluginHandler* self = new( ELeave ) CXnNPPluginHandler;
       
   353     
       
   354     CleanupStack::PushL( self );
       
   355     self->ConstructL();
       
   356     CleanupStack::Pop();
       
   357 
       
   358     return self;
       
   359     }
       
   360 
       
   361     
       
   362 // Destructor
       
   363 CXnNPPluginHandler::~CXnNPPluginHandler()
       
   364     {
       
   365     delete iPluginInterface;
       
   366     }
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 // CXnNPPluginHandler::LoadSpecificPluginL
       
   370 // (other items were commented in a header).
       
   371 // -----------------------------------------------------------------------------
       
   372 // 
       
   373 TInt CXnNPPluginHandler::LoadSpecificPluginL(
       
   374     const TDesC8& aResolveparam,
       
   375     NPPluginFuncs** aPluginFuncs )
       
   376     {
       
   377     RImplInfoPtrArray implInfoArray;
       
   378     CImplementationInformation* impl = NULL;
       
   379     REComSession::ListImplementationsL( KBrowserPluginInterfaceUid, implInfoArray );     
       
   380     TBool implFound( EFalse );
       
   381     TInt count = implInfoArray.Count();
       
   382     for(TInt index = 0; index < count; ++index )
       
   383         {
       
   384         impl = implInfoArray[index];
       
   385         if( ParseAndMatchMimeTypeL( impl->DataType(), aResolveparam ) )
       
   386             {
       
   387             implFound = ETrue;
       
   388             break;
       
   389             }
       
   390         }
       
   391 
       
   392     if( !implFound )
       
   393         {
       
   394         implInfoArray.ResetAndDestroy();
       
   395         implInfoArray.Close();
       
   396         return KErrNotFound;
       
   397         }
       
   398         
       
   399     NPPluginFuncs* pluginFuncs = (NPPluginFuncs*) User::AllocLC(sizeof (NPPluginFuncs));
       
   400     Mem::FillZ((void*) pluginFuncs, sizeof (NPPluginFuncs));
       
   401 
       
   402     iPluginInterface = CEcomBrowserPluginInterface::CreatePluginL( 
       
   403          impl->ImplementationUid(),(NPNetscapeFuncs *) (&PluginWrapperFuncs), pluginFuncs );
       
   404 
       
   405     CleanupStack::Pop(pluginFuncs);
       
   406 
       
   407     *aPluginFuncs = pluginFuncs;
       
   408     pluginFuncs = NULL;
       
   409     
       
   410     implInfoArray.ResetAndDestroy();
       
   411     implInfoArray.Close();
       
   412     return KErrNone;
       
   413     }
       
   414 
       
   415 //  End of File