Home | History | Annotate | Download | only in symbian
      1 /*
      2     Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
      3 
      4     This library is free software; you can redistribute it and/or
      5     modify it under the terms of the GNU Library General Public
      6     License as published by the Free Software Foundation; either
      7     version 2 of the License, or (at your option) any later version.
      8 
      9     This library is distributed in the hope that it will be useful,
     10     but WITHOUT ANY WARRANTY; without even the implied warranty of
     11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12     Library General Public License for more details.
     13 
     14     You should have received a copy of the GNU Library General Public License
     15     along with this library; see the file COPYING.LIB.  If not, write to
     16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17     Boston, MA 02110-1301, USA.
     18 */
     19 #include "config.h"
     20 #include "PluginPackage.h"
     21 
     22 #include "MIMETypeRegistry.h"
     23 #include "npinterface.h"
     24 #include "npruntime_impl.h"
     25 #include "PluginDatabase.h"
     26 #include "PluginDebug.h"
     27 #include <QPluginLoader>
     28 #include <wtf/text/CString.h>
     29 
     30 namespace WebCore {
     31 
     32 #if ENABLE(NETSCAPE_PLUGIN_API)
     33 bool PluginPackage::fetchInfo()
     34 {
     35     if (!load())
     36         return false;
     37 
     38     char* buf = 0;
     39     NPError err = m_pluginFuncs.getvalue(0, NPPVpluginNameString, (void *)&buf);
     40     m_name = buf;
     41     err = m_pluginFuncs.getvalue(0, NPPVpluginDescriptionString, (void *)&buf);
     42     m_description = buf;
     43 
     44     determineModuleVersionFromDescription();
     45 
     46     String s = m_npInterface->NP_GetMIMEDescription();
     47     Vector<String> types;
     48     s.split(UChar('|'), false, types);  // <MIME1>;<ext1,ext2,ext3,...>;<Description>|<MIME2>|<MIME3>|...
     49 
     50     for (int i = 0; i < types.size(); ++i) {
     51         Vector<String> mime;
     52         types[i].split(UChar(';'), true, mime);  // <MIME1>;<ext1,ext2,ext3,...>;<Description>
     53         if (mime.size() > 0) {
     54             Vector<String> exts;
     55             if (mime.size() > 1)
     56                 mime[1].split(UChar(','), false, exts); // <ext1,ext2,ext3,...>
     57 
     58             m_mimeToExtensions.add(mime[0], exts); // <MIME>,<ext1,ext2,ext3>
     59             determineQuirks(mime[0]);
     60             if (mime.size() > 2)
     61                 m_mimeToDescriptions.add(mime[0], mime[2]); // <MIME>,<Description>
     62         }
     63     }
     64     unload();
     65     return true;
     66 }
     67 
     68 void PluginPackage::determineQuirks(const String& mimeType)
     69 {
     70     if (mimeType == "application/x-shockwave-flash") {
     71         PlatformModuleVersion flashTenVersion(0x000a0000);
     72         if (compareFileVersion(flashTenVersion) >= 0) {
     73             // Flash 10 doesn't like having a 0 window handle.
     74             m_quirks.add(PluginQuirkDontSetNullWindowHandleOnDestroy);
     75         }
     76     }
     77 }
     78 
     79 bool PluginPackage::load()
     80 {
     81     if (m_isLoaded) {
     82         m_loadCount++;
     83         return true;
     84     }
     85 
     86     m_pluginLoader = new QPluginLoader(m_path);
     87     if (!m_pluginLoader->load()) {
     88         delete m_pluginLoader;
     89         m_pluginLoader = 0;
     90         return false;
     91     }
     92 
     93     QObject* plugin = m_pluginLoader->instance();
     94     if (!plugin) {
     95         m_pluginLoader->unload();
     96         delete m_pluginLoader;
     97         m_pluginLoader = 0;
     98         return false;
     99     }
    100 
    101     // Plugin instance created
    102     // Cast plugin to NPInterface,
    103     m_npInterface = qobject_cast<NPInterface*>(plugin);
    104     if (!m_npInterface) {
    105         m_pluginLoader->unload();
    106         delete m_pluginLoader;
    107         m_pluginLoader = 0;
    108         return false;
    109     }
    110 
    111     m_isLoaded = true;
    112 
    113     NPError npErr;
    114     memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs));
    115     m_pluginFuncs.size = sizeof(m_pluginFuncs);
    116     m_browserFuncs.size = sizeof(m_browserFuncs);
    117     m_browserFuncs.version = NP_VERSION_MINOR;
    118     m_browserFuncs.geturl = NPN_GetURL;
    119     m_browserFuncs.posturl = NPN_PostURL;
    120     m_browserFuncs.requestread = NPN_RequestRead;
    121     m_browserFuncs.newstream = NPN_NewStream;
    122     m_browserFuncs.write = NPN_Write;
    123     m_browserFuncs.destroystream = NPN_DestroyStream;
    124     m_browserFuncs.status = NPN_Status;
    125     m_browserFuncs.uagent = NPN_UserAgent;
    126     m_browserFuncs.memalloc = NPN_MemAlloc;
    127     m_browserFuncs.memfree = NPN_MemFree;
    128     m_browserFuncs.memflush = NPN_MemFlush;
    129     m_browserFuncs.reloadplugins = NPN_ReloadPlugins;
    130     m_browserFuncs.geturlnotify = NPN_GetURLNotify;
    131     m_browserFuncs.posturlnotify = NPN_PostURLNotify;
    132     m_browserFuncs.getvalue = NPN_GetValue;
    133     m_browserFuncs.setvalue = NPN_SetValue;
    134     m_browserFuncs.invalidaterect = NPN_InvalidateRect;
    135     m_browserFuncs.invalidateregion = NPN_InvalidateRegion;
    136     m_browserFuncs.forceredraw = NPN_ForceRedraw;
    137     m_browserFuncs.getJavaEnv = NPN_GetJavaEnv;
    138     m_browserFuncs.getJavaPeer = NPN_GetJavaPeer;
    139     m_browserFuncs.pushpopupsenabledstate = NPN_PushPopupsEnabledState;
    140     m_browserFuncs.poppopupsenabledstate = NPN_PopPopupsEnabledState;
    141     m_browserFuncs.releasevariantvalue = _NPN_ReleaseVariantValue;
    142     m_browserFuncs.getstringidentifier = _NPN_GetStringIdentifier;
    143     m_browserFuncs.getstringidentifiers = _NPN_GetStringIdentifiers;
    144     m_browserFuncs.getintidentifier = _NPN_GetIntIdentifier;
    145     m_browserFuncs.identifierisstring = _NPN_IdentifierIsString;
    146     m_browserFuncs.utf8fromidentifier = _NPN_UTF8FromIdentifier;
    147     m_browserFuncs.createobject = _NPN_CreateObject;
    148     m_browserFuncs.retainobject = _NPN_RetainObject;
    149     m_browserFuncs.releaseobject = _NPN_ReleaseObject;
    150     m_browserFuncs.invoke = _NPN_Invoke;
    151     m_browserFuncs.invokeDefault = _NPN_InvokeDefault;
    152     m_browserFuncs.evaluate = _NPN_Evaluate;
    153     m_browserFuncs.getproperty = _NPN_GetProperty;
    154     m_browserFuncs.setproperty = _NPN_SetProperty;
    155     m_browserFuncs.removeproperty = _NPN_RemoveProperty;
    156     m_browserFuncs.hasproperty = _NPN_HasMethod;
    157     m_browserFuncs.hasmethod = _NPN_HasProperty;
    158     m_browserFuncs.setexception = _NPN_SetException;
    159     m_browserFuncs.enumerate = _NPN_Enumerate;
    160     m_browserFuncs.construct = _NPN_Construct;
    161 
    162     npErr = m_npInterface->NP_Initialize(&m_browserFuncs, &m_pluginFuncs);
    163     if (npErr != NPERR_NO_ERROR) {
    164         m_pluginLoader->unload();
    165         delete m_pluginLoader;
    166         m_pluginLoader = 0;
    167         return false;
    168     }
    169 
    170     m_loadCount++;
    171     return true;
    172 }
    173 #endif
    174 
    175 void PluginPackage::unload()
    176 {
    177     if (!m_isLoaded)
    178         return;
    179 
    180     if (--m_loadCount > 0)
    181         return;
    182 
    183     m_isLoaded = false;
    184     m_npInterface->NP_Shutdown();
    185 
    186     m_pluginLoader->unload();
    187     delete m_pluginLoader;
    188     m_pluginLoader = 0;
    189 }
    190 
    191 #if ENABLE(NETSCAPE_PLUGIN_API)
    192 uint16_t PluginPackage::NPVersion() const
    193 {
    194     return NP_VERSION_MINOR;
    195 }
    196 #endif
    197 }
    198 
    199