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

Diff of /gcjwebplugin/src/gcjwebplugin.cc

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

revision 1.12 by fitzsim, Thu Nov 13 06:11:56 2003 UTC revision 1.13 by fitzsim, Fri Nov 14 04:52:58 2003 UTC
# Line 54  static NS_DEFINE_IID (kIPluginTagInfo2II Line 54  static NS_DEFINE_IID (kIPluginTagInfo2II
54    
55  static NPNetscapeFuncs browserFunctions;  static NPNetscapeFuncs browserFunctions;
56    
57  static gint send_message_to_appletviewer (gchar const* name, gchar *value);  static gint send_message_to_appletviewer (gchar const* value);
58  static gint receive_message_from_appletviewer (gchar* string);  static gint receive_message_from_appletviewer (gchar* string);
59    
60  struct GCJPluginData  struct GCJPluginData
# Line 62  struct GCJPluginData Line 62  struct GCJPluginData
62    char *code;    char *code;
63    char *codebase;    char *codebase;
64    char *archive;    char *archive;
65    char const* documentbase;    char *documentbase;
66    char *parameters;    char *parameters;
67    char *width;    char *width;
68    char *height;    char *height;
69    // The xid of the plugin window, encoded in hexadecimal.    // The xid of the plugin window, encoded in hexadecimal.
70    char *xid;    char *xid;
71    GIOChannel *output_to_appletviewer;    char *instance_id;
   GIOChannel *input_from_appletviewer;  
72  };  };
73    
74  static GIOChannel *output_to_appletviewer = NULL;  static GIOChannel *output_to_appletviewer = NULL;
75  static GIOChannel *input_from_appletviewer = NULL;  static GIOChannel *input_from_appletviewer = NULL;
76    
77    static int instance_counter = 0;
78    
79    static void gcjplugindata_new (GCJPluginData ** data);
80    static void gcjplugindata_destroy (GCJPluginData ** data);
81    
82  NPError  NPError
83  GCJ_GetValue (NPP instance, NPPVariable variable, void* value)  GCJ_GetValue (NPP instance, NPPVariable variable, void* value)
84  {  {
# Line 106  GCJ_New (NPMIMEType pluginType, NPP inst Line 110  GCJ_New (NPMIMEType pluginType, NPP inst
110    if (!instance)    if (!instance)
111      return NPERR_INVALID_INSTANCE_ERROR;      return NPERR_INVALID_INSTANCE_ERROR;
112    
113    GCJPluginData* data =    GCJPluginData* data = NULL;
114      (GCJPluginData*) (* browserFunctions.memalloc) (sizeof (struct GCJPluginData));  
115      gcjplugindata_new (&data);
116    
117    if (!data)    if (!data)
118      return NPERR_OUT_OF_MEMORY_ERROR;      return NPERR_OUT_OF_MEMORY_ERROR;
# Line 123  GCJ_New (NPMIMEType pluginType, NPP inst Line 128  GCJ_New (NPMIMEType pluginType, NPP inst
128    nsIPluginTagInfo2* pluginTagInfo2;    nsIPluginTagInfo2* pluginTagInfo2;
129    result = peer->QueryInterface (kIPluginTagInfo2IID, (void**) &pluginTagInfo2);    result = peer->QueryInterface (kIPluginTagInfo2IID, (void**) &pluginTagInfo2);
130    
131    pluginTagInfo2->GetDocumentBase (&data->documentbase);    char const* documentbase;
132      pluginTagInfo2->GetDocumentBase (&documentbase);
133    
134      data->documentbase = g_strdup (documentbase);
135    
136    gchar *applet_tag = g_strdup ("<EMBED ");    gchar *applet_tag = g_strdup ("<EMBED ");
137    
# Line 168  GCJ_New (NPMIMEType pluginType, NPP inst Line 176  GCJ_New (NPMIMEType pluginType, NPP inst
176    applet_tag = g_strconcat (applet_tag,    applet_tag = g_strconcat (applet_tag,
177                              g_strdup_printf ("></EMBED>"), NULL);                              g_strdup_printf ("></EMBED>"), NULL);
178    
179      data->instance_id = g_strdup_printf ("applet%d", instance_counter++);
180    
181    instance->pdata = data;    instance->pdata = data;
182    
183    // FIXME: this multi-instance messaging scheme won't work.  we need    send_message_to_appletviewer ("instance");
184    // a one that includes the instance name in each message, eg:    send_message_to_appletviewer (data->instance_id);
185    //      Applet0: tag    send_message_to_appletviewer ("tag");
186    //      Applet0: <EMBED ...></EMBED>    send_message_to_appletviewer (data->documentbase);
187    // Also, we need a global counter so we can name each instance    send_message_to_appletviewer (applet_tag);
   // uniquely.  
   
   send_message_to_appletviewer ("instance", NULL);  
   send_message_to_appletviewer ("Applet 0", NULL);  
   send_message_to_appletviewer ("tag", NULL);  
   send_message_to_appletviewer (data->documentbase, NULL);  
   send_message_to_appletviewer (applet_tag, NULL);  
188    
189    return NPERR_NO_ERROR;    return NPERR_NO_ERROR;
190  }  }
191    
192    static void
193    gcjplugindata_new (GCJPluginData ** data)
194    {
195      *data = (GCJPluginData*)
196        (* browserFunctions.memalloc) (sizeof (struct GCJPluginData));
197    
198      memset (*data, 0, sizeof (struct GCJPluginData));
199    }
200    
201  NPError  NPError
202  GCJ_Destroy (NPP instance, NPSavedData** save)  GCJ_Destroy (NPP instance, NPSavedData** save)
203  {  {
204    PLUGIN_DEBUG ("GCJ_Destroy\n");    PLUGIN_DEBUG ("GCJ_Destroy\n");
205    
206    // FIXME: Free NPP->pdata structures.    GCJPluginData* data = (GCJPluginData*) instance->pdata;
207    return send_message_to_appletviewer ("shutdown", NULL);  
208      gcjplugindata_destroy (&data);
209    
210      return NPERR_NO_ERROR;
211    }
212    
213    static void
214    gcjplugindata_destroy (GCJPluginData ** data)
215    {
216      GCJPluginData *tofree = *data;
217    
218      g_free (tofree->code);
219      g_free (tofree->codebase);
220      g_free (tofree->archive);
221      g_free (tofree->documentbase);
222      g_free (tofree->parameters);
223      g_free (tofree->width);
224      g_free (tofree->height);
225      g_free (tofree->xid);
226      g_free (tofree->instance_id);
227    
228      (* browserFunctions.memfree) (tofree);
229      tofree = NULL;
230  }  }
231    
232  NPError  NPError
# Line 204  GCJ_SetWindow (NPP instance, NPWindow* w Line 238  GCJ_SetWindow (NPP instance, NPWindow* w
238    
239    if (data->width)    if (data->width)
240      g_free (data->width);      g_free (data->width);
241      if (data->height)
242        g_free (data->height);
243      if (data->xid)
244        g_free (data->xid);
245    
246    data->width = g_strdup_printf ("%d", window->width);    data->width = g_strdup_printf ("%d", window->width);
247    data->height = g_strdup_printf ("%d", window->height);    data->height = g_strdup_printf ("%d", window->height);
248    data->xid = g_strdup_printf ("%d", (int)(window->window));    data->xid = g_strdup_printf ("%d", (int)(window->window));
249    
250    // FIXME: check the return values here.    send_message_to_appletviewer ("instance");
251    send_message_to_appletviewer ("xid", NULL);    send_message_to_appletviewer (data->instance_id);
252    send_message_to_appletviewer (data->xid, NULL);    send_message_to_appletviewer ("xid");
253      send_message_to_appletviewer (data->xid);
254    
255    return NPERR_NO_ERROR;    return NPERR_NO_ERROR;
256  }  }
# Line 283  GCJ_GetJavaClass (void) Line 322  GCJ_GetJavaClass (void)
322  }  }
323    
324  static gint  static gint
325  send_message_to_appletviewer (gchar const* name, gchar *value)  send_message_to_appletviewer (gchar const* name)
326  {  {
327    GError *err = NULL;    GError *err = NULL;
328    gsize bytes_written;    gsize bytes_written;
# Line 299  send_message_to_appletviewer (gchar cons Line 338  send_message_to_appletviewer (gchar cons
338        g_printerr ("send_message_to_appletviewer: Error: %s\n", err->message);        g_printerr ("send_message_to_appletviewer: Error: %s\n", err->message);
339        return NPERR_GENERIC_ERROR;        return NPERR_GENERIC_ERROR;
340      }      }
341    if (err)  
342      g_error_free (err);    if (g_io_channel_flush (output_to_appletviewer, &err)
343    err = NULL;        != G_IO_STATUS_NORMAL)
344        {
345    g_io_channel_flush (output_to_appletviewer, &err);        g_printerr ("send_message_to_appletviewer: Error: %s\n", err->message);
346    if (err)        return NPERR_GENERIC_ERROR;
347      g_error_free (err);      }
348    err = NULL;  
349    PIPE_OUTPUT_DEBUG (name);    PIPE_OUTPUT_DEBUG (name);
350    
351    gchar *recv_name = g_strdup (name);    gchar *recv_name = g_strdup (name);
# Line 314  send_message_to_appletviewer (gchar cons Line 353  send_message_to_appletviewer (gchar cons
353    if ((np_error = receive_message_from_appletviewer (recv_name)) != NPERR_NO_ERROR)    if ((np_error = receive_message_from_appletviewer (recv_name)) != NPERR_NO_ERROR)
354      return np_error;      return np_error;
355    
356    if (value)    g_printerr ("send_message_to_appletviewer: Success: %s\n", recv_name);
     {  
       // Send value of attribute to gcjappletviewer.  
       gchar *value_buf = g_strdup_printf ("%s\n", value);  
       if (g_io_channel_write_chars (output_to_appletviewer,  
                                     value_buf, -1, &bytes_written, &err)  
           != G_IO_STATUS_NORMAL)  
         {  
           g_printerr ("send_message_to_appletviewer: Error: %s\n", err->message);  
           return NPERR_GENERIC_ERROR;  
         }  
       if (err)  
         g_error_free (err);  
       err = NULL;  
       PIPE_OUTPUT_DEBUG (value);  
         
       g_io_channel_flush (output_to_appletviewer, &err);  
       if (err)  
         g_error_free (err);  
       err = NULL;  
   
       if ((np_error = receive_message_from_appletviewer (value)) != NPERR_NO_ERROR)  
         return np_error;  
     }  
   
   g_printerr ("send_message_to_appletviewer: Success: %s, %s\n", recv_name, value);  
357    
358    return NPERR_NO_ERROR;    return NPERR_NO_ERROR;
359  }  }
# Line 441  NP_Initialize(NPNetscapeFuncs* browserTa Line 455  NP_Initialize(NPNetscapeFuncs* browserTa
455    pluginTable->getvalue = NewNPP_GetValueProc(GCJ_GetValue);    pluginTable->getvalue = NewNPP_GetValueProc(GCJ_GetValue);
456    
457    GError *err = NULL;    GError *err = NULL;
458    gint output_to_gcjappletviewer;    gint output_to_gcjappletviewer_fd;
459    gint input_from_gcjappletviewer;    gint input_from_gcjappletviewer_fd;
460    gchar *command_line [3] = { "gcjappletviewer", "--plugin", NULL };    gchar *command_line [3] = { "gcjappletviewer", "--plugin", NULL };
461    
462    if (!g_spawn_async_with_pipes (NULL,    if (!g_spawn_async_with_pipes (NULL,
# Line 452  NP_Initialize(NPNetscapeFuncs* browserTa Line 466  NP_Initialize(NPNetscapeFuncs* browserTa
466                                   NULL,                                   NULL,
467                                   NULL,                                   NULL,
468                                   NULL,                                   NULL,
469                                   &output_to_gcjappletviewer,                                   &output_to_gcjappletviewer_fd,
470                                   &input_from_gcjappletviewer,                                   &input_from_gcjappletviewer_fd,
471                                   NULL,                                   NULL,
472                                   &err))                                   &err))
473      {      {
# Line 461  NP_Initialize(NPNetscapeFuncs* browserTa Line 475  NP_Initialize(NPNetscapeFuncs* browserTa
475        return NPERR_GENERIC_ERROR;        return NPERR_GENERIC_ERROR;
476      }      }
477    
478    output_to_appletviewer = g_io_channel_unix_new (output_to_gcjappletviewer);    output_to_appletviewer = g_io_channel_unix_new (output_to_gcjappletviewer_fd);
479    input_from_appletviewer = g_io_channel_unix_new (input_from_gcjappletviewer);    input_from_appletviewer = g_io_channel_unix_new (input_from_gcjappletviewer_fd);
480    
481    g_printerr ("Spawned gcjappletviewer successfully.\n");    g_printerr ("Spawned gcjappletviewer successfully.\n");
482    
# Line 521  NP_Shutdown(void) Line 535  NP_Shutdown(void)
535  {  {
536    PLUGIN_DEBUG ("NP_Shutdown\n");    PLUGIN_DEBUG ("NP_Shutdown\n");
537    
538      GError *err = NULL;
539      gsize bytes_written;
540    
541      if (g_io_channel_write_chars (output_to_appletviewer,
542                                    "shutdown", -1, &bytes_written, &err)
543          != G_IO_STATUS_NORMAL)
544        {
545          g_printerr ("send_message_to_appletviewer: Error: %s\n", err->message);
546          return NPERR_GENERIC_ERROR;
547        }
548    
549      if (g_io_channel_flush (output_to_appletviewer, &err)
550          != G_IO_STATUS_NORMAL)
551        {
552          g_printerr ("send_message_to_appletviewer: Error: %s\n", err->message);
553          return NPERR_GENERIC_ERROR;
554        }
555    
556      if (g_io_channel_shutdown (output_to_appletviewer,
557                                 TRUE, &err) != G_IO_STATUS_NORMAL)
558        {
559          g_printerr ("NP_Shutdown: Error: %s\n", err->message);
560          return NPERR_GENERIC_ERROR;
561        }
562    
563      if (g_io_channel_shutdown (input_from_appletviewer,
564                                 TRUE, &err) != G_IO_STATUS_NORMAL)
565        {
566          g_printerr ("NP_Shutdown: Error: %s\n", err->message);
567          return NPERR_GENERIC_ERROR;
568        }
569      g_printerr ("Done shutting down.\n");
570    
571    return NPERR_NO_ERROR;    return NPERR_NO_ERROR;
572  }  }

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

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