author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 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 "CString.h" |
|
23 |
#include "MIMETypeRegistry.h" |
|
24 |
#include "npinterface.h" |
|
25 |
#include "npruntime_impl.h" |
|
26 |
#include "PluginDatabase.h" |
|
27 |
#include "PluginDebug.h" |
|
28 |
#include <QPluginLoader> |
|
29 |
||
30 |
namespace WebCore { |
|
31 |
||
32 |
bool PluginPackage::fetchInfo() |
|
33 |
{ |
|
34 |
if (!load()) |
|
35 |
return false; |
|
36 |
||
37 |
char* buf = 0; |
|
38 |
NPError err = m_pluginFuncs.getvalue(0, NPPVpluginNameString, (void *)&buf); |
|
39 |
m_name = buf; |
|
40 |
err = m_pluginFuncs.getvalue(0, NPPVpluginDescriptionString, (void *)&buf); |
|
41 |
m_description = buf; |
|
42 |
||
43 |
determineModuleVersionFromDescription(); |
|
44 |
||
45 |
String s = m_npInterface->NP_GetMIMEDescription(); |
|
46 |
Vector<String> types; |
|
47 |
s.split(UChar('|'), false, types); // <MIME1>;<ext1,ext2,ext3,...>;<Description>|<MIME2>|<MIME3>|... |
|
48 |
||
49 |
for (int i = 0; i < types.size(); ++i) { |
|
50 |
Vector<String> mime; |
|
51 |
types[i].split(UChar(';'), true, mime); // <MIME1>;<ext1,ext2,ext3,...>;<Description> |
|
52 |
if (mime.size() > 0) { |
|
53 |
Vector<String> exts; |
|
54 |
if (mime.size() > 1) |
|
55 |
mime[1].split(UChar(','), false, exts); // <ext1,ext2,ext3,...> |
|
56 |
||
57 |
m_mimeToExtensions.add(mime[0], exts); // <MIME>,<ext1,ext2,ext3> |
|
58 |
if (mime.size() > 2) |
|
59 |
m_mimeToDescriptions.add(mime[0], mime[2]); // <MIME>,<Description> |
|
60 |
} |
|
61 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
62 |
unload(); |
0 | 63 |
return true; |
64 |
} |
|
65 |
||
66 |
bool PluginPackage::load() |
|
67 |
{ |
|
68 |
if (m_isLoaded) { |
|
69 |
m_loadCount++; |
|
70 |
return true; |
|
71 |
} |
|
72 |
||
73 |
m_pluginLoader = new QPluginLoader(m_path); |
|
74 |
if (!m_pluginLoader->load()) { |
|
75 |
delete m_pluginLoader; |
|
76 |
m_pluginLoader = 0; |
|
77 |
return false; |
|
78 |
} |
|
79 |
||
80 |
QObject* plugin = m_pluginLoader->instance(); |
|
81 |
if (!plugin) { |
|
82 |
m_pluginLoader->unload(); |
|
83 |
delete m_pluginLoader; |
|
84 |
m_pluginLoader = 0; |
|
85 |
return false; |
|
86 |
} |
|
87 |
||
88 |
// Plugin instance created |
|
89 |
// Cast plugin to NPInterface, |
|
90 |
m_npInterface = qobject_cast<NPInterface*>(plugin); |
|
91 |
if (!m_npInterface) { |
|
92 |
m_pluginLoader->unload(); |
|
93 |
delete m_pluginLoader; |
|
94 |
m_pluginLoader = 0; |
|
95 |
return false; |
|
96 |
} |
|
97 |
||
98 |
m_isLoaded = true; |
|
99 |
||
100 |
NPError npErr; |
|
101 |
memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs)); |
|
102 |
m_pluginFuncs.size = sizeof(m_pluginFuncs); |
|
103 |
m_browserFuncs.size = sizeof(m_browserFuncs); |
|
104 |
m_browserFuncs.version = NP_VERSION_MINOR; |
|
105 |
m_browserFuncs.geturl = NPN_GetURL; |
|
106 |
m_browserFuncs.posturl = NPN_PostURL; |
|
107 |
m_browserFuncs.requestread = NPN_RequestRead; |
|
108 |
m_browserFuncs.newstream = NPN_NewStream; |
|
109 |
m_browserFuncs.write = NPN_Write; |
|
110 |
m_browserFuncs.destroystream = NPN_DestroyStream; |
|
111 |
m_browserFuncs.status = NPN_Status; |
|
112 |
m_browserFuncs.uagent = NPN_UserAgent; |
|
113 |
m_browserFuncs.memalloc = NPN_MemAlloc; |
|
114 |
m_browserFuncs.memfree = NPN_MemFree; |
|
115 |
m_browserFuncs.memflush = NPN_MemFlush; |
|
116 |
m_browserFuncs.reloadplugins = NPN_ReloadPlugins; |
|
117 |
m_browserFuncs.geturlnotify = NPN_GetURLNotify; |
|
118 |
m_browserFuncs.posturlnotify = NPN_PostURLNotify; |
|
119 |
m_browserFuncs.getvalue = NPN_GetValue; |
|
120 |
m_browserFuncs.setvalue = NPN_SetValue; |
|
121 |
m_browserFuncs.invalidaterect = NPN_InvalidateRect; |
|
122 |
m_browserFuncs.invalidateregion = NPN_InvalidateRegion; |
|
123 |
m_browserFuncs.forceredraw = NPN_ForceRedraw; |
|
124 |
m_browserFuncs.getJavaEnv = NPN_GetJavaEnv; |
|
125 |
m_browserFuncs.getJavaPeer = NPN_GetJavaPeer; |
|
126 |
m_browserFuncs.pushpopupsenabledstate = NPN_PushPopupsEnabledState; |
|
127 |
m_browserFuncs.poppopupsenabledstate = NPN_PopPopupsEnabledState; |
|
128 |
m_browserFuncs.releasevariantvalue = _NPN_ReleaseVariantValue; |
|
129 |
m_browserFuncs.getstringidentifier = _NPN_GetStringIdentifier; |
|
130 |
m_browserFuncs.getstringidentifiers = _NPN_GetStringIdentifiers; |
|
131 |
m_browserFuncs.getintidentifier = _NPN_GetIntIdentifier; |
|
132 |
m_browserFuncs.identifierisstring = _NPN_IdentifierIsString; |
|
133 |
m_browserFuncs.utf8fromidentifier = _NPN_UTF8FromIdentifier; |
|
134 |
m_browserFuncs.createobject = _NPN_CreateObject; |
|
135 |
m_browserFuncs.retainobject = _NPN_RetainObject; |
|
136 |
m_browserFuncs.releaseobject = _NPN_ReleaseObject; |
|
137 |
m_browserFuncs.invoke = _NPN_Invoke; |
|
138 |
m_browserFuncs.invokeDefault = _NPN_InvokeDefault; |
|
139 |
m_browserFuncs.evaluate = _NPN_Evaluate; |
|
140 |
m_browserFuncs.getproperty = _NPN_GetProperty; |
|
141 |
m_browserFuncs.setproperty = _NPN_SetProperty; |
|
142 |
m_browserFuncs.removeproperty = _NPN_RemoveProperty; |
|
143 |
m_browserFuncs.hasproperty = _NPN_HasMethod; |
|
144 |
m_browserFuncs.hasmethod = _NPN_HasProperty; |
|
145 |
m_browserFuncs.setexception = _NPN_SetException; |
|
146 |
m_browserFuncs.enumerate = _NPN_Enumerate; |
|
147 |
m_browserFuncs.construct = _NPN_Construct; |
|
148 |
||
149 |
npErr = m_npInterface->NP_Initialize(&m_browserFuncs, &m_pluginFuncs); |
|
150 |
if (npErr != NPERR_NO_ERROR) { |
|
151 |
m_pluginLoader->unload(); |
|
152 |
delete m_pluginLoader; |
|
153 |
m_pluginLoader = 0; |
|
154 |
return false; |
|
155 |
} |
|
156 |
||
157 |
m_loadCount++; |
|
158 |
return true; |
|
159 |
} |
|
160 |
||
161 |
void PluginPackage::unload() |
|
162 |
{ |
|
163 |
if (!m_isLoaded) |
|
164 |
return; |
|
165 |
||
166 |
if (--m_loadCount > 0) |
|
167 |
return; |
|
168 |
||
169 |
m_isLoaded = false; |
|
170 |
m_npInterface->NP_Shutdown(); |
|
171 |
||
172 |
m_pluginLoader->unload(); |
|
173 |
delete m_pluginLoader; |
|
174 |
m_pluginLoader = 0; |
|
175 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
176 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
177 |
uint16 PluginPackage::NPVersion() const |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
178 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
179 |
return NP_VERSION_MINOR; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
180 |
} |
0 | 181 |
} |
182 |