/[gcjwebplugin]/gcjwebplugin/src/GCJPluginInstance.cc
ViewVC logotype

Diff of /gcjwebplugin/src/GCJPluginInstance.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.13 by mkoch, Tue Jul 29 04:20:20 2003 UTC revision 1.14 by fitzsim, Mon Sep 15 02:52:00 2003 UTC
# Line 35  exception statement from your version. * Line 35  exception statement from your version. *
35    
36    
37  #include <cassert>  #include <cassert>
38    #include <glib.h>
39    
40  #include <nsplugindefs.h>  #include <nsplugindefs.h>
41  #include <nsIJVMPluginTagInfo.h>  #include <nsIJVMPluginTagInfo.h>
# Line 43  exception statement from your version. * Line 44  exception statement from your version. *
44  #include <plugin/npapi.h>  #include <plugin/npapi.h>
45    
46  #include "GCJPluginInstance.h"  #include "GCJPluginInstance.h"
 #include "jniHelp.h"  
47  #include "pluginDebug.h"  #include "pluginDebug.h"
48    
49  NS_IMPL_ISUPPORTS1 (GCJPluginInstance, nsIJVMPluginInstance)  NS_IMPL_ISUPPORTS1 (GCJPluginInstance, nsIJVMPluginInstance)
# Line 53  static NS_DEFINE_IID (kIPluginTagInfo2II Line 53  static NS_DEFINE_IID (kIPluginTagInfo2II
53    
54  GCJPluginInstance::GCJPluginInstance (GCJPluginFactory* factory, JNIEnv* jniEnv)  GCJPluginInstance::GCJPluginInstance (GCJPluginFactory* factory, JNIEnv* jniEnv)
55    : m_peer (NULL)    : m_peer (NULL)
   , m_jniEnv (jniEnv)  
   , m_applet (NULL)  
   , m_appletLoader (NULL)  
   , m_embeddedWindow (NULL)  
56  {  {
57    PLUGIN_DEBUG ("GCJPluginInstance::GCJPluginInstance\n");    PLUGIN_DEBUG ("GCJPluginInstance::GCJPluginInstance\n");
58  }  }
# Line 74  GCJPluginInstance::Initialize (nsIPlugin Line 70  GCJPluginInstance::Initialize (nsIPlugin
70    m_peer = peer;    m_peer = peer;
71    m_peer->AddRef ();    m_peer->AddRef ();
72    
   jstring code;  
   jstring codeBase;  
   jstring documentBase;  
   jstring archive;  
     
73    nsresult result;    nsresult result;
74    nsIJVMPluginTagInfo* pluginTagInfo;    nsIJVMPluginTagInfo* pluginTagInfo;
75    nsIPluginTagInfo2* pluginTagInfo2;    nsIPluginTagInfo2* pluginTagInfo2;
# Line 89  GCJPluginInstance::Initialize (nsIPlugin Line 80  GCJPluginInstance::Initialize (nsIPlugin
80    
81    if (NS_SUCCEEDED (result))    if (NS_SUCCEEDED (result))
82      {      {
83        const char* tmp_code = NULL;        // Extract tag data from web browser.
84        const char* tmp_codeBase = NULL;        pluginTagInfo->GetCode (&code);
85        const char* tmp_documentBase = NULL;        pluginTagInfo->GetCodeBase (&codebase);
86        const char* tmp_archive = NULL;        pluginTagInfo->GetArchive (&archive);
87                pluginTagInfo2->GetDocumentBase (&documentbase);
88        PRUint16 numParams;        pluginTagInfo2->GetParameters (numParams, paramNames, paramValues);
       const char* const* tmp_paramNames = NULL;  
       const char* const* tmp_paramValues = NULL;  
         
       // Extract plugin data got from web browser  
       //  
       pluginTagInfo->GetCode (&tmp_code);  
       pluginTagInfo->GetCodeBase (&tmp_codeBase);  
       pluginTagInfo->GetArchive (&tmp_archive);  
       pluginTagInfo2->GetDocumentBase (&tmp_documentBase);  
       pluginTagInfo2->GetParameters (numParams, tmp_paramNames, tmp_paramValues);  
         
       if (tmp_code != NULL)  
         code = m_jniEnv->NewStringUTF (tmp_code);  
         
       if (tmp_codeBase != NULL)  
         codeBase = m_jniEnv->NewStringUTF (tmp_codeBase);  
         
       if (tmp_documentBase != NULL)  
         documentBase = m_jniEnv->NewStringUTF (tmp_documentBase);  
   
       if (tmp_archive != NULL)  
         archive = m_jniEnv->NewStringUTF (tmp_archive);  
   
       // Get references to classes and methods via JNI  
       //  
       jclass appletLoader_cl = m_jniEnv->FindClass ("gnu/applet/AppletLoader");  
       assert (appletLoader_cl != NULL);  
   
       jmethodID appletLoader_init = m_jniEnv->GetMethodID (appletLoader_cl, "<init>", "()V");  
       assert (appletLoader_init != NULL);  
   
       jmethodID appletLoader_setCode = m_jniEnv->GetMethodID (appletLoader_cl, "setCode", "(Ljava.lang.String;)V");  
       assert (appletLoader_setCode != NULL);  
   
       jmethodID appletLoader_setCodeBase = m_jniEnv->GetMethodID (appletLoader_cl, "setCodeBase", "(Ljava.lang.String;)V");  
       assert (appletLoader_setCodeBase != NULL);  
         
       jmethodID appletLoader_setDocumentBase = m_jniEnv->GetMethodID (appletLoader_cl, "setDocumentBase", "(Ljava.lang.String;)V");  
       assert (appletLoader_setDocumentBase != NULL);  
         
       jmethodID appletLoader_setArchive = m_jniEnv->GetMethodID (appletLoader_cl, "setArchive", "(Ljava.lang.String;)V");  
       assert (appletLoader_setArchive != NULL);  
   
       jmethodID appletLoader_addParameter = m_jniEnv->GetMethodID (appletLoader_cl, "addParameter", "(Ljava.lang.String;Ljava.lang.String;)V");  
       assert (appletLoader_addParameter != NULL);  
   
       jmethodID appletLoader_loadApplet  = m_jniEnv->GetMethodID (appletLoader_cl, "loadApplet", "()Ljava.applet.Applet;");  
       assert (appletLoader_loadApplet != NULL);  
         
       // Load applet  
       //  
       PLUGIN_DEBUG ("GCJPluginInstance::Initialize: AppletLoader.<init>\n");  
       JNI_NewObject0 (m_jniEnv, appletLoader_cl, appletLoader_init, m_appletLoader);  
   
       if (tmp_code != NULL)  
         {  
           PLUGIN_DEBUG ("GCJPluginInstance::Initialize: AppletLoader.setCode\n");  
           JNI_CallVoidMethod1 (m_jniEnv, m_appletLoader, appletLoader_setCode, code);  
         }  
   
       if (tmp_codeBase != NULL)  
         {  
           PLUGIN_DEBUG ("GCJPluginInstance::Initialize: AppletLoader.setCodeBase\n");  
           JNI_CallVoidMethod1 (m_jniEnv, m_appletLoader, appletLoader_setCodeBase, codeBase);  
         }  
   
       if (tmp_documentBase != NULL)  
         {  
           PLUGIN_DEBUG ("GCJPluginInstance::Initialize: AppletLoader.setDocumentBase\n");  
           JNI_CallVoidMethod1 (m_jniEnv, m_appletLoader, appletLoader_setDocumentBase, documentBase);  
         }  
   
       if (tmp_archive != NULL)  
         {  
           PLUGIN_DEBUG ("GCJPluginInstance::Initialize: AppletLoader.setArchive\n");  
           JNI_CallVoidMethod1 (m_jniEnv, m_appletLoader, appletLoader_setArchive, archive);  
         }  
   
       for (int count = 0; count < numParams; count++)  
         {  
           PLUGIN_DEBUG ("GCJPluginInstance::Initialize: AppletLoader.addParameter\n");  
           JNI_CallVoidMethod2 (m_jniEnv, m_appletLoader, appletLoader_addParameter,  
                                m_jniEnv->NewStringUTF (tmp_paramNames [count]),  
                                m_jniEnv->NewStringUTF (tmp_paramValues [count]));  
         }  
   
       PLUGIN_DEBUG ("GCJPluginInstance::Initialize: AppletLoader.loadApplet\n");  
       JNI_CallObjectMethod0 (m_jniEnv, m_appletLoader, appletLoader_loadApplet, m_applet);  
89      }      }
90    
91    pluginTagInfo->Release();    pluginTagInfo->Release();
92    pluginTagInfo2->Release();    pluginTagInfo2->Release();
93    
   if (m_applet == NULL)  
     {  
       PLUGIN_DEBUG ("GCJPluginInstance::Initialize: Applet couldn't be loaded\n");  
       return  NS_ERROR_FAILURE;  
     }  
   
   jclass applet_cl;  
   jmethodID applet_init;  
   
   JNI_GetObjectClass (m_jniEnv, m_applet, applet_cl);  
   JNI_GetMethodID (m_jniEnv, applet_cl, "init", "()V", applet_init);  
   JNI_CallVoidMethod0 (m_jniEnv, m_applet, applet_init);  
     
94    return NS_OK;    return NS_OK;
95  }  }
96    
# Line 218  GCJPluginInstance::Start () Line 108  GCJPluginInstance::Start ()
108  {  {
109    PLUGIN_DEBUG ("GCJPluginInstance::Start\n");    PLUGIN_DEBUG ("GCJPluginInstance::Start\n");
110    
111    if (m_applet != NULL)    // FIXME: call applet's start method via protocol
112      {  
       jclass applet_cl;  
       jmethodID applet_start;  
         
       JNI_GetObjectClass (m_jniEnv, m_applet, applet_cl);  
       JNI_GetMethodID (m_jniEnv, applet_cl, "start", "()V", applet_start);  
       JNI_CallVoidMethod0 (m_jniEnv, m_applet, applet_start);  
     }  
     
113    return NS_OK;    return NS_OK;
114  }  }
115    
# Line 236  GCJPluginInstance::Stop () Line 118  GCJPluginInstance::Stop ()
118  {  {
119    PLUGIN_DEBUG ("GCJPluginInstance::Stop\n");    PLUGIN_DEBUG ("GCJPluginInstance::Stop\n");
120    
121    if (m_applet != NULL)    // FIXME: call applet's stop method via protocol
122      {  
       jclass applet_cl;  
       jmethodID applet_stop;  
         
       JNI_GetObjectClass (m_jniEnv, m_applet, applet_cl);  
       JNI_GetMethodID (m_jniEnv, applet_cl, "stop", "()V", applet_stop);  
       JNI_CallVoidMethod0 (m_jniEnv, m_applet, applet_stop);  
     }  
     
123    return NS_OK;    return NS_OK;
124  }  }
125    
# Line 253  NS_IMETHODIMP Line 127  NS_IMETHODIMP
127  GCJPluginInstance::Destroy ()  GCJPluginInstance::Destroy ()
128  {  {
129    PLUGIN_DEBUG ("GCJPluginInstance::Destroy\n");    PLUGIN_DEBUG ("GCJPluginInstance::Destroy\n");
130      
131    if (m_applet != NULL)    // FIXME: kill spawned process
     {  
       jclass applet_cl;  
       jmethodID applet_destroy;  
         
       JNI_GetObjectClass (m_jniEnv, m_applet, applet_cl);  
       JNI_GetMethodID (m_jniEnv, applet_cl, "destroy", "()V", applet_destroy);  
       JNI_CallVoidMethod0 (m_jniEnv, m_applet, applet_destroy);  
     }  
132        
133    return NS_OK;    return NS_OK;
134  }  }
# Line 272  GCJPluginInstance::SetWindow (nsPluginWi Line 138  GCJPluginInstance::SetWindow (nsPluginWi
138  {  {
139    PLUGIN_DEBUG ("GCJPluginInstance::SetWindow\n");    PLUGIN_DEBUG ("GCJPluginInstance::SetWindow\n");
140    
141    if (m_applet != NULL)    width = window->width;
142      {    height = window->height;
143        // First, create an embedded window.    xid = (int)(window->window);
144        PLUGIN_DEBUG (" Finding EmbeddedWindow methods...\n");  
145      // FIXME: select only initialized arguments
146        jclass embeddedWindow_cl;    gchar *cmd_line = g_strdup_printf ("/home/fitzsim/build/plugin-bld/src/appletviewer "
147        jmethodID embeddedWindow_init;                                       "--code=%s "
148        jmethodID embeddedWindow_setSize;                                       "--archive=%s "
149                                               "--width=%d "
150        JNI_FindClass (m_jniEnv, "gnu/java/awt/EmbeddedWindow",                                       "--height=%d "
151                       embeddedWindow_cl);                                       "--xid=%d ",
152        JNI_GetMethodID (m_jniEnv, embeddedWindow_cl, "<init>", "(I)V",                                       code,
153                         embeddedWindow_init);                                       archive,
154        JNI_GetMethodID (m_jniEnv, embeddedWindow_cl, "setSize", "(II)V",                                       width,
155                         embeddedWindow_setSize);                                       height,
156                                         xid);
157        PLUGIN_DEBUG2 (" Initializing EmbeddedWindow: %d...\n", (unsigned long) window->window);  
158      printf ("Running: %s\n", cmd_line);
159        JNI_NewObject1 (m_jniEnv, embeddedWindow_cl, embeddedWindow_init,    GError *err;
160                        (jint) window->window, m_embeddedWindow);  
161      // FIXME: open input and output pipes
162        PLUGIN_DEBUG2 (" Setting EmbeddedWindow size: width  %d...\n", (unsigned long) window->width);    if (!g_spawn_command_line_async (cmd_line, &err))
163        PLUGIN_DEBUG2 (" Setting EmbeddedWindow size: height %d...\n", (unsigned long) window->height);      fprintf (stderr, "SetWindow error: %s\n", err->message);
   
       JNI_CallVoidMethod2 (m_jniEnv, m_embeddedWindow, embeddedWindow_setSize,  
                            (jint) (window->width), (jint) (window->height));  
   
       PLUGIN_DEBUG (" Finding AppletLoader...\n");  
   
       /* Now add the applet to this window. */  
       jclass appletLoader_cl;  
       jmethodID appletLoader_setEmbeddedWindow;  
         
       JNI_FindClass (m_jniEnv, "gnu/applet/AppletLoader", appletLoader_cl);  
   
       PLUGIN_DEBUG (" Finding setEmbeddedWindow...\n");  
   
       JNI_GetMethodID (m_jniEnv, appletLoader_cl, "setEmbeddedWindow",  
                        "(Lgnu.java.awt.EmbeddedWindow;)V", appletLoader_setEmbeddedWindow);  
   
       PLUGIN_DEBUG (" Calling setEmbeddedWindow...\n");  
   
       if (!m_appletLoader)  
         PLUGIN_DEBUG (" no m_appletLoader!...\n");  
   
       if (!m_embeddedWindow)  
         PLUGIN_DEBUG (" no m_embeddedWindow!...\n");  
   
       JNI_CallVoidMethod1 (m_jniEnv, m_appletLoader,  
                            appletLoader_setEmbeddedWindow, m_embeddedWindow);  
   
     }  
164    
165    return NS_OK;    return NS_OK;
166  }  }
# Line 393  GCJPluginInstance::GetJavaObject (jobjec Line 230  GCJPluginInstance::GetJavaObject (jobjec
230  {  {
231    PLUGIN_DEBUG ("GCJPluginInstance::GetJavaObject\n");    PLUGIN_DEBUG ("GCJPluginInstance::GetJavaObject\n");
232    
   (*result) = (jobject) m_applet;  
233    return NS_OK;    return NS_OK;
234  }  }
235    

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26