37 |
#include <cassert> |
#include <cassert> |
38 |
|
|
39 |
#include <nsplugindefs.h> |
#include <nsplugindefs.h> |
40 |
|
#include <nsIJVMPluginTagInfo.h> |
41 |
#include <nsIPluginInstancePeer.h> |
#include <nsIPluginInstancePeer.h> |
42 |
|
#include <nsIPluginTagInfo2.h> |
43 |
|
|
44 |
#include "GCJPluginInstance.h" |
#include "GCJPluginInstance.h" |
45 |
|
|
46 |
#define DEBUG(output) printf (output); |
#define DEBUG(output) printf (output); |
47 |
#define DEBUG2(output, arg) printf (output, arg); |
#define DEBUG2(output, arg) printf (output, arg); |
48 |
|
|
|
#define ENV m_jniEnv |
|
|
|
|
49 |
#define CHECK_EXCEPTIONS \ |
#define CHECK_EXCEPTIONS \ |
50 |
if (m_jniEnv->ExceptionOccurred ()) \ |
if (m_jniEnv->ExceptionOccurred ()) \ |
51 |
{ \ |
{ \ |
55 |
|
|
56 |
NS_IMPL_ISUPPORTS1 (GCJPluginInstance, nsIJVMPluginInstance) |
NS_IMPL_ISUPPORTS1 (GCJPluginInstance, nsIJVMPluginInstance) |
57 |
|
|
58 |
|
static NS_DEFINE_IID (kIJVMPluginTagInfoIID, NS_IJVMPLUGINTAGINFO_IID); |
59 |
|
static NS_DEFINE_IID (kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID); |
60 |
|
|
61 |
GCJPluginInstance::GCJPluginInstance (GCJPluginFactory* factory, JNIEnv* jniEnv) |
GCJPluginInstance::GCJPluginInstance (GCJPluginFactory* factory, JNIEnv* jniEnv) |
62 |
: m_peer (NULL) |
: m_peer (NULL) |
63 |
, m_jniEnv (jniEnv) |
, m_jniEnv (jniEnv) |
79 |
|
|
80 |
m_peer = peer; |
m_peer = peer; |
81 |
m_peer->AddRef (); |
m_peer->AddRef (); |
82 |
|
|
83 |
|
jstring code; |
84 |
|
jstring codeBase; |
85 |
|
jstring documentBase; |
86 |
|
jstring archive; |
87 |
|
|
88 |
|
jobject appletLoader; |
89 |
|
|
90 |
|
nsresult result; |
91 |
|
nsIJVMPluginTagInfo* pluginTagInfo; |
92 |
|
nsIPluginTagInfo2* pluginTagInfo2; |
93 |
|
|
94 |
|
result = peer->QueryInterface (kIJVMPluginTagInfoIID, |
95 |
|
(void**) &pluginTagInfo); |
96 |
|
result = peer->QueryInterface (kIPluginTagInfo2IID, (void**) &pluginTagInfo2); |
97 |
|
|
98 |
|
if (NS_SUCCEEDED (result)) |
99 |
|
{ |
100 |
|
const char* tmp_code = NULL; |
101 |
|
const char* tmp_codeBase = NULL; |
102 |
|
const char* tmp_documentBase = NULL; |
103 |
|
const char* tmp_archive = NULL; |
104 |
|
|
105 |
|
PRUint16 numParams; |
106 |
|
const char* const* tmp_paramNames = NULL; |
107 |
|
const char* const* tmp_paramValues = NULL; |
108 |
|
|
109 |
|
// Extract plugin data got from web browser |
110 |
|
// |
111 |
|
pluginTagInfo->GetCode (&tmp_code); |
112 |
|
pluginTagInfo->GetCodeBase (&tmp_codeBase); |
113 |
|
pluginTagInfo->GetArchive (&tmp_archive); |
114 |
|
pluginTagInfo2->GetDocumentBase (&tmp_documentBase); |
115 |
|
pluginTagInfo2->GetParameters (numParams, tmp_paramNames, tmp_paramValues); |
116 |
|
|
117 |
|
if (tmp_code != NULL) |
118 |
|
code = m_jniEnv->NewStringUTF (tmp_code); |
119 |
|
|
120 |
|
if (tmp_codeBase != NULL) |
121 |
|
codeBase = m_jniEnv->NewStringUTF (tmp_codeBase); |
122 |
|
|
123 |
|
if (tmp_documentBase != NULL) |
124 |
|
documentBase = m_jniEnv->NewStringUTF (tmp_documentBase); |
125 |
|
|
126 |
|
if (tmp_archive != NULL) |
127 |
|
archive = m_jniEnv->NewStringUTF (tmp_archive); |
128 |
|
|
129 |
|
// Get references to classes and methods via JNI |
130 |
|
// |
131 |
|
jclass appletLoader_cl = m_jniEnv->FindClass ("gnu/applet/AppletLoader"); |
132 |
|
assert (appletLoader_cl != NULL); |
133 |
|
|
134 |
|
jmethodID appletLoader_init = m_jniEnv->GetMethodID (appletLoader_cl, "<init>", "()V"); |
135 |
|
assert (appletLoader_init != NULL); |
136 |
|
|
137 |
|
jmethodID appletLoader_setCode = m_jniEnv->GetMethodID (appletLoader_cl, "setCode", "(Ljava.lang.String;)V"); |
138 |
|
assert (appletLoader_setCode != NULL); |
139 |
|
|
140 |
|
jmethodID appletLoader_setCodeBase = m_jniEnv->GetMethodID (appletLoader_cl, "setCodeBase", "(Ljava.lang.String;)V"); |
141 |
|
assert (appletLoader_setCodeBase != NULL); |
142 |
|
|
143 |
|
jmethodID appletLoader_setDocumentBase = m_jniEnv->GetMethodID (appletLoader_cl, "setDocumentBase", "(Ljava.lang.String;)V"); |
144 |
|
assert (appletLoader_setDocumentBase != NULL); |
145 |
|
|
146 |
|
jmethodID appletLoader_setArchive = m_jniEnv->GetMethodID (appletLoader_cl, "setArchive", "(Ljava.lang.String;)V"); |
147 |
|
assert (appletLoader_setArchive != NULL); |
148 |
|
|
149 |
|
jmethodID appletLoader_addParameter = m_jniEnv->GetMethodID (appletLoader_cl, "addParameter", "(Ljava.lang.String;Ljava.lang.String;)V"); |
150 |
|
assert (appletLoader_addParameter != NULL); |
151 |
|
|
152 |
|
jmethodID appletLoader_loadApplet = m_jniEnv->GetMethodID (appletLoader_cl, "loadApplet", "()Ljava.applet.Applet;"); |
153 |
|
assert (appletLoader_loadApplet != NULL); |
154 |
|
|
155 |
|
// Load applet |
156 |
|
// |
157 |
|
jobject appletLoader = m_jniEnv->NewObject (appletLoader_cl, appletLoader_init); |
158 |
|
assert (appletLoader != NULL); |
159 |
|
|
160 |
|
if (tmp_code != NULL) |
161 |
|
m_jniEnv->CallVoidMethod (appletLoader_cl, appletLoader_setCode, code); |
162 |
|
|
163 |
|
if (tmp_codeBase != NULL) |
164 |
|
m_jniEnv->CallVoidMethod (appletLoader_cl, appletLoader_setCodeBase, codeBase); |
165 |
|
|
166 |
|
if (tmp_documentBase != NULL) |
167 |
|
m_jniEnv->CallVoidMethod (appletLoader_cl, appletLoader_setDocumentBase, documentBase); |
168 |
|
|
169 |
|
if (tmp_archive != NULL) |
170 |
|
m_jniEnv->CallVoidMethod (appletLoader_cl, appletLoader_setArchive, archive); |
171 |
|
|
172 |
|
for (int count = 0; count < numParams; count++) |
173 |
|
{ |
174 |
|
m_jniEnv->CallVoidMethod (appletLoader_cl, appletLoader_addParameter, |
175 |
|
m_jniEnv->NewStringUTF (tmp_paramNames [count]), |
176 |
|
m_jniEnv->NewStringUTF (tmp_paramValues [count])); |
177 |
|
} |
178 |
|
|
179 |
|
jobject m_applet = m_jniEnv->CallObjectMethod (appletLoader_cl, appletLoader_loadApplet); |
180 |
|
assert (m_applet != NULL); |
181 |
|
} |
182 |
|
|
183 |
|
pluginTagInfo->Release(); |
184 |
|
pluginTagInfo2->Release(); |
185 |
|
|
186 |
return NS_OK; |
return NS_OK; |
187 |
} |
} |