2 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
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.
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.
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.
20 #include "PluginPackage.h"
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>
32 #if ENABLE(NETSCAPE_PLUGIN_API)
33 bool PluginPackage::fetchInfo()
39 NPError err = m_pluginFuncs.getvalue(0, NPPVpluginNameString, (void *)&buf);
41 err = m_pluginFuncs.getvalue(0, NPPVpluginDescriptionString, (void *)&buf);
44 determineModuleVersionFromDescription();
46 String s = m_npInterface->NP_GetMIMEDescription();
48 s.split(UChar('|'), false, types); // <MIME1>;<ext1,ext2,ext3,...>;<Description>|<MIME2>|<MIME3>|...
50 for (int i = 0; i < types.size(); ++i) {
52 types[i].split(UChar(';'), true, mime); // <MIME1>;<ext1,ext2,ext3,...>;<Description>
53 if (mime.size() > 0) {
56 mime[1].split(UChar(','), false, exts); // <ext1,ext2,ext3,...>
58 m_mimeToExtensions.add(mime[0], exts); // <MIME>,<ext1,ext2,ext3>
59 determineQuirks(mime[0]);
61 m_mimeToDescriptions.add(mime[0], mime[2]); // <MIME>,<Description>
68 void PluginPackage::determineQuirks(const String& mimeType)
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);
79 bool PluginPackage::load()
86 m_pluginLoader = new QPluginLoader(m_path);
87 if (!m_pluginLoader->load()) {
88 delete m_pluginLoader;
93 QObject* plugin = m_pluginLoader->instance();
95 m_pluginLoader->unload();
96 delete m_pluginLoader;
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;
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;
162 npErr = m_npInterface->NP_Initialize(&m_browserFuncs, &m_pluginFuncs);
163 if (npErr != NPERR_NO_ERROR) {
164 m_pluginLoader->unload();
165 delete m_pluginLoader;
175 void PluginPackage::unload()
180 if (--m_loadCount > 0)
184 m_npInterface->NP_Shutdown();
186 m_pluginLoader->unload();
187 delete m_pluginLoader;
191 #if ENABLE(NETSCAPE_PLUGIN_API)
192 uint16_t PluginPackage::NPVersion() const
194 return NP_VERSION_MINOR;