webengine/osswebengine/WebKit/s60/plugins/PluginHandler.h
changeset 0 dd21522fd290
child 8 7c90e6132015
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     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:  Plugin handling, manages the loading and unloading of the
       
    15 *                plugin. Initializes the CInfoArray that contains the plugin
       
    16 *                MIME-types supported.
       
    17 *
       
    18 */
       
    19 
       
    20 #ifndef PluginHandler_H
       
    21 #define PluginHandler_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <npupp.h>
       
    25 #include <f32file.h>
       
    26 #include <badesca.h>
       
    27 
       
    28 #include <ECom/ImplementationInformation.h>    // ecom
       
    29 #include "EcomBrowserPluginInterface.h"
       
    30 #include "WebCorePluginHandler.h"
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 class PluginInfo;
       
    34 class WebView;
       
    35 
       
    36 
       
    37 // CLASS DECLARATION
       
    38 
       
    39 /**
       
    40 * Primarily deals with the loading and unloading of plugins as well as
       
    41 * other plugin utility functions.
       
    42 *
       
    43 *  @lib Browser Engine
       
    44 *  @since 3.1
       
    45 */
       
    46 class PluginHandler : public CBase
       
    47     {
       
    48     public:  // Constructors and destructor
       
    49 
       
    50         /**
       
    51         * Two-phased constructor.
       
    52         * @param aEnablePlugin flag to check for plugin support enabled by Browser Setting
       
    53         * @param aWebKitView Pointer to the browser view
       
    54         */
       
    55         static PluginHandler* NewL(TBool enablePlugin);
       
    56 
       
    57         /**
       
    58         * Destructor.
       
    59         */
       
    60         virtual ~PluginHandler();
       
    61 
       
    62 
       
    63     public: // New functions
       
    64 
       
    65 
       
    66         /**
       
    67         * Find a plugin by MIME type
       
    68         *
       
    69         * @since 3.1
       
    70         * @param aMIMEType The MIME type of the <object> element.
       
    71         * @return The handle of the plugin supporting the MIME type or KErrNotFound.
       
    72         */
       
    73         TInt findPlugin(const TDesC& mimeType);
       
    74 
       
    75         /**
       
    76         * Find a plugin by file extension
       
    77         *
       
    78         * @since 3.1
       
    79         * @param aFileName The url of the <object> element data.
       
    80         * @return The handle of the plugin supporting the file name or KErrNotFound.
       
    81         */
       
    82         TInt findPluginByExtension(const TDesC8& url);
       
    83 
       
    84         /**
       
    85         * Load a plugin if not yet loaded
       
    86         *
       
    87         * @since 3.1
       
    88         * @param aHandle The handle of the plugin, returned from FindPlugin.
       
    89         * @param aPluginFuncs Upon success it contains the associated
       
    90         *        plugin's function table.
       
    91         * @return void
       
    92         */
       
    93 
       
    94         void loadPluginL(TInt handle, NPPluginFuncs** retFuncs);
       
    95 
       
    96         /**
       
    97         * Unload a plugin. If this is the last instance, the library is unloaded.
       
    98         *
       
    99         * @since 3.1
       
   100         * @param aHandle The handle of the plugin, returned from FindPlugin.
       
   101         * @return void
       
   102         */
       
   103         void unloadPlugin(TInt handle);
       
   104 
       
   105         /**
       
   106         * Get the index of plugin info from its handle.
       
   107         *
       
   108         * @since 3.1
       
   109         * @param aHandle The handle of the plugin, returned from FindPlugin.
       
   110         * @return the index of the plugin info.
       
   111         */
       
   112         TUint getIndexFromHandle(TInt handle);
       
   113 
       
   114     public: //From MWebCorePluginHandler
       
   115 
       
   116         TInt getPluginCount();
       
   117         TBool pluginSupportsMIMEType(const TDesC& mimeType);
       
   118         TBool objectAtIndex(TInt index, TWebCorePluginInfo& aPluginInfo );
       
   119         void refreshPlugins(TBool reload);
       
   120         HBufC8* extensionsForMIMEType(TInt index, TDesC& mimeType);
       
   121         HBufC* descriptionForMIMEType(TInt index, TDesC& mimeType);
       
   122 
       
   123         /**
       
   124         * Determines whether a given content-type of dot-extension has a cooresponding
       
   125         * plugin or external application.  aContentType and aUrl can be NULL, but at least
       
   126         * one must be non-NULL (otherwise it will always return EFalse).  If aHandlerType
       
   127         * is EPlugin then it returns ETrue only if their is a supported plugin.  If aHandlerType
       
   128         * is EExternalApp then it returns ETrue only if their is a supported external
       
   129         * application.  If aHandlerType is EBoth then it returns ETrue only if their is a
       
   130         * supported plugin or external application.
       
   131         *
       
   132         * @since 3.1
       
   133         * @param aContentType the content type to compare against, may be NULL.
       
   134         * @param aUrl the url to extract the dot-extension and to compare against, may be NULL.
       
   135         *
       
   136         * @return ETrue or EFalse.
       
   137         */
       
   138         TBool isSupported(const TDesC& contType, const TDesC8& url);
       
   139 
       
   140     private: // New functions
       
   141 
       
   142         /**
       
   143         * Scans for new plugins.
       
   144         *
       
   145         * @since 3.1
       
   146         * @param aReloadPages if ETrue the current page is reloaded.
       
   147         * @return void.
       
   148         */
       
   149         void reloadPluginsL(TBool reload);
       
   150 
       
   151         /**
       
   152         * C++ default constructor.
       
   153         * @param aEnablePlugin flag to check if plugin support is enabled by Browser Settings
       
   154         * @param aWebKitView pointer to CWebKitView
       
   155         */
       
   156         PluginHandler(TBool enablePlugin);
       
   157 
       
   158         /**
       
   159         * By default Symbian 2nd phase constructor is private.
       
   160         */
       
   161         void ConstructL();
       
   162 
       
   163         /**
       
   164         * Initializes the PluginHandler, possibly asynchronously.
       
   165         *
       
   166         * @since 3.1
       
   167         * @return void.
       
   168         */
       
   169         static TBool initialize(TAny* pluginHandler);
       
   170 
       
   171         /**
       
   172         * Loads all the plugins and query them for details. Used during
       
   173         * initialization.
       
   174         *
       
   175         * @since 3.1
       
   176         * @return void.
       
   177         */
       
   178         TBool loadPluginsL();
       
   179 
       
   180     private:    // Data
       
   181 
       
   182         // Array of information about existing plugins
       
   183         RPointerArray<PluginInfo>   m_pluginInfoArray;
       
   184         TInt                        m_nextHandle;
       
   185         TBool                       m_pluginsLoaded;
       
   186         TBool                       m_enablePlugins;
       
   187         TBool                       m_asyncLoading;      //ETrue for Async scanning of drives
       
   188                                                         //EFalse for sync scanning and loading
       
   189 
       
   190         CIdle*                      m_idle;              //Active Object to initailise
       
   191                                                         //the plugins from drives
       
   192     };
       
   193 
       
   194 
       
   195 /**
       
   196 * A private helper class used by PluginHandler which is used
       
   197 * to interact with individual plugins.
       
   198 *
       
   199 * @lib Browser Engine
       
   200 * @since 3.1
       
   201 */
       
   202 class PluginInfo : public CBase
       
   203     {
       
   204     public:  // Constructors and destructor
       
   205 
       
   206         /**
       
   207         * Two-phased constructor.
       
   208         */
       
   209         static PluginInfo* NewL(const TDesC& mimeDescription, const TDesC& name,
       
   210                 const TDesC& description, const TDesC& fileName, const TDesC& pathName);
       
   211 
       
   212         /**
       
   213         * Destructor.
       
   214         */
       
   215         virtual ~PluginInfo();
       
   216 
       
   217 
       
   218     public:  // New functions
       
   219 
       
   220         /**
       
   221         * Returns ETrue if the plugin should be loaded.
       
   222         *
       
   223         * @since 3.1
       
   224         * @return ETrue or EFalse
       
   225         */
       
   226         TBool shouldLoad();
       
   227 
       
   228         /**
       
   229         * Returns ETrue if the plugin should be unloaded.
       
   230         *
       
   231         * @since 3.1
       
   232         * @return ETrue or EFalse
       
   233         */
       
   234         TBool shouldUnload();
       
   235 
       
   236         /**
       
   237         * Increments the PluginInfo's reference count.
       
   238         *
       
   239         * @since 3.1
       
   240         * @return void
       
   241         */
       
   242         void loadInstance();
       
   243 
       
   244         /**
       
   245         * Decrements the PluginInfo's reference count.
       
   246         *
       
   247         * @since 3.1
       
   248         * @return void
       
   249         */
       
   250         void unloadInstance();
       
   251 
       
   252         /**
       
   253         * Copy the mimetypes and file extention from one PluginInfo to another.
       
   254         * Called after a rescan of the file system.
       
   255         *
       
   256         * @since 3.1
       
   257         * @param aPluginInfo the instance to move mimetypes and file extentions from.
       
   258         * @return void.
       
   259         */
       
   260         void copyMimeDescription(PluginInfo& pluginInfo);
       
   261 
       
   262         /**
       
   263         * Getter function.
       
   264         *
       
   265         * @since 3.1
       
   266         * @return The mime types supported by this plugin
       
   267         */
       
   268 
       
   269         const RPointerArray <HBufC>&  mimeTypes() {return m_mimeTypes;}
       
   270 
       
   271         /**
       
   272         * Getter function.
       
   273         *
       
   274         * @since 3.1
       
   275         * @return The mime extensions supported by this plugin
       
   276         */
       
   277 
       
   278         const RPointerArray <HBufC8>&  mimeFileExtensions() {return m_mimeFileExtensions;}
       
   279 
       
   280         /**
       
   281         * Getter function.
       
   282         *
       
   283         * @since 3.1
       
   284         * @return The mime descriptions supported by this plugin
       
   285         */
       
   286 
       
   287         const RPointerArray <HBufC>&  mimeDescriptions() {return m_mimeDescriptions;}
       
   288 
       
   289         /**
       
   290         * Getter function.
       
   291         *
       
   292         * @since 3.1
       
   293         * @return The list of mimeExtensions given the mimeType supported by this plugin
       
   294         * The list of mimeExtensions is a comma-delimited string. For example, given
       
   295         * the mimeType "text/html", you will receive "html,htm".
       
   296         */
       
   297 
       
   298         HBufC8* getMimeExtensionsL(const TDesC& mimeType);
       
   299 
       
   300         /**
       
   301         * Getter function.
       
   302         *
       
   303         * @since 3.1
       
   304         * @return The name of this plugin
       
   305         */
       
   306         HBufC* name() {return m_name;}
       
   307 
       
   308         /**
       
   309         * Getter function.
       
   310         *
       
   311         * @since 3.1
       
   312         * @return The description of this plugin
       
   313         */
       
   314         HBufC* description() {return m_description;}
       
   315 
       
   316         /**
       
   317         * Getter function.
       
   318         *
       
   319         * @since 3.1
       
   320         * @return The file name of this plugin
       
   321         */
       
   322         HBufC* fileName() {return m_filename;}
       
   323 
       
   324         void parseDefaultDataL(const TDesC8& mimeDescription);
       
   325         void parseDisplayNameL(const TDesC& pluginDescription);
       
   326 
       
   327     private:  // Private Methods
       
   328 
       
   329         /**
       
   330         * C++ default constructor.
       
   331         */
       
   332         PluginInfo();
       
   333 
       
   334         /**
       
   335         * By default Symbian 2nd phase constructor is private.
       
   336         */
       
   337     public:   //Data
       
   338         CImplementationInformation* m_pluginInfo;  // ECom plugin implementation info
       
   339 
       
   340     private:  // Data
       
   341 
       
   342         RPointerArray <HBufC>  m_mimeTypes;
       
   343         RPointerArray <HBufC8> m_mimeFileExtensions;
       
   344         RPointerArray <HBufC>  m_mimeExtensionToTypeMap;
       
   345         RPointerArray <HBufC>  m_mimeDescriptions;
       
   346 
       
   347 
       
   348         HBufC*                 m_name;
       
   349         HBufC*                 m_description;
       
   350         TInt                   m_ref;
       
   351         TInt                   m_handle;
       
   352         NPPluginFuncs*         m_nppFuncs;
       
   353         HBufC*                 m_filename;
       
   354 
       
   355         TUid                   m_uid;
       
   356         CEcomBrowserPluginInterface* m_pluginInterface;
       
   357 
       
   358     private:  // Friend classes
       
   359 
       
   360         friend class PluginHandler;
       
   361     };
       
   362 
       
   363 #endif      // PluginHandler_H
       
   364 
       
   365 // End of File
       
   366