| 1 | /* IcedTeaNPPlugin.h
|
|---|
| 2 |
|
|---|
| 3 | Copyright (C) 2009, 2010 Red Hat
|
|---|
| 4 |
|
|---|
| 5 | This file is part of IcedTea.
|
|---|
| 6 |
|
|---|
| 7 | IcedTea is free software; you can redistribute it and/or modify
|
|---|
| 8 | it under the terms of the GNU General Public License as published by
|
|---|
| 9 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 10 | any later version.
|
|---|
| 11 |
|
|---|
| 12 | IcedTea is distributed in the hope that it will be useful, but
|
|---|
| 13 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 15 | General Public License for more details.
|
|---|
| 16 |
|
|---|
| 17 | You should have received a copy of the GNU General Public License
|
|---|
| 18 | along with IcedTea; see the file COPYING. If not, write to the
|
|---|
| 19 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|---|
| 20 | 02110-1301 USA.
|
|---|
| 21 |
|
|---|
| 22 | Linking this library statically or dynamically with other modules is
|
|---|
| 23 | making a combined work based on this library. Thus, the terms and
|
|---|
| 24 | conditions of the GNU General Public License cover the whole
|
|---|
| 25 | combination.
|
|---|
| 26 |
|
|---|
| 27 | As a special exception, the copyright holders of this library give you
|
|---|
| 28 | permission to link this library with independent modules to produce an
|
|---|
| 29 | executable, regardless of the license terms of these independent
|
|---|
| 30 | modules, and to copy and distribute the resulting executable under
|
|---|
| 31 | terms of your choice, provided that you also meet, for each linked
|
|---|
| 32 | independent module, the terms and conditions of the license of that
|
|---|
| 33 | module. An independent module is a module which is not derived from
|
|---|
| 34 | or based on this library. If you modify this library, you may extend
|
|---|
| 35 | this exception to your version of the library, but you are not
|
|---|
| 36 | obligated to do so. If you do not wish to do so, delete this
|
|---|
| 37 | exception statement from your version. */
|
|---|
| 38 |
|
|---|
| 39 | #ifndef __ICEDTEANPPLUGIN_H__
|
|---|
| 40 | #define __ICEDTEANPPLUGIN_H__
|
|---|
| 41 |
|
|---|
| 42 | #include <npapi.h>
|
|---|
| 43 | #include <npruntime.h>
|
|---|
| 44 | #include <npfunctions.h>
|
|---|
| 45 |
|
|---|
| 46 | // GLib includes.
|
|---|
| 47 | #include <glib.h>
|
|---|
| 48 | #include <glib/gstdio.h>
|
|---|
| 49 |
|
|---|
| 50 | #include "IcedTeaPluginUtils.h"
|
|---|
| 51 | #include "IcedTeaPluginRequestProcessor.h"
|
|---|
| 52 |
|
|---|
| 53 | // ITNPPluginData stores all the data associated with a single plugin
|
|---|
| 54 | // instance. A separate plugin instance is created for each <APPLET>
|
|---|
| 55 | // tag. For now, each plugin instance spawns its own applet viewer
|
|---|
| 56 | // process but this may need to change if we find pages containing
|
|---|
| 57 | // multiple applets that expect to be running in the same VM.
|
|---|
| 58 | struct ITNPPluginData
|
|---|
| 59 | {
|
|---|
| 60 | // A unique identifier for this plugin window.
|
|---|
| 61 | gchar* instance_id;
|
|---|
| 62 | // The parameter list string sent to Java side
|
|---|
| 63 | gchar* parameters_string;
|
|---|
| 64 | // Mutex to protect appletviewer_alive.
|
|---|
| 65 | GMutex* appletviewer_mutex;
|
|---|
| 66 | // Back-pointer to the plugin instance to which this data belongs.
|
|---|
| 67 | // This should not be freed but instead simply set to NULL.
|
|---|
| 68 | NPP owner;
|
|---|
| 69 | // The address of the plugin window. This should not be freed but
|
|---|
| 70 | // instead simply set to NULL.
|
|---|
| 71 | gpointer window_handle;
|
|---|
| 72 | // The last plugin window width sent to us by the browser.
|
|---|
| 73 | guint32 window_width;
|
|---|
| 74 | // The last plugin window height sent to us by the browser.
|
|---|
| 75 | guint32 window_height;
|
|---|
| 76 | // The source location for this instance
|
|---|
| 77 | std::string source;
|
|---|
| 78 | // If this is an actual applet instance, or a dummy instance for static calls
|
|---|
| 79 | bool is_applet_instance;
|
|---|
| 80 |
|
|---|
| 81 | ITNPPluginData() {
|
|---|
| 82 | instance_id = NULL;
|
|---|
| 83 | parameters_string = NULL;
|
|---|
| 84 | appletviewer_mutex = NULL;
|
|---|
| 85 | owner = (NPP)NULL;
|
|---|
| 86 | window_handle = NULL;
|
|---|
| 87 | window_width = 0;
|
|---|
| 88 | window_height = 0;
|
|---|
| 89 | is_applet_instance = false;
|
|---|
| 90 | }
|
|---|
| 91 | ~ITNPPluginData() {
|
|---|
| 92 | if (appletviewer_mutex) {
|
|---|
| 93 | g_mutex_free (appletviewer_mutex);
|
|---|
| 94 | }
|
|---|
| 95 | // cleanup_instance_string:
|
|---|
| 96 | g_free (instance_id);
|
|---|
| 97 | // cleanup applet tag
|
|---|
| 98 | g_free (parameters_string);
|
|---|
| 99 | }
|
|---|
| 100 | };
|
|---|
| 101 |
|
|---|
| 102 | // Have the browser allocate a new ITNPPluginData structure.
|
|---|
| 103 | ITNPPluginData* plugin_data_new ();
|
|---|
| 104 | void plugin_data_destroy (NPP instance);
|
|---|
| 105 |
|
|---|
| 106 | NPError initialize_data_directory();
|
|---|
| 107 | NPError start_jvm_if_needed();
|
|---|
| 108 |
|
|---|
| 109 | #ifdef __OS2__
|
|---|
| 110 | struct QueueProcessorData
|
|---|
| 111 | {
|
|---|
| 112 | PluginRequestProcessor *processor;
|
|---|
| 113 | bool stopRequested;
|
|---|
| 114 | };
|
|---|
| 115 | #endif
|
|---|
| 116 |
|
|---|
| 117 | // ID of plug-in thread
|
|---|
| 118 | extern pthread_t itnp_plugin_thread_id;
|
|---|
| 119 |
|
|---|
| 120 | /* Mutex around plugin async call queue ops */
|
|---|
| 121 | extern pthread_mutex_t pluginAsyncCallMutex;
|
|---|
| 122 |
|
|---|
| 123 | /*to sync pipe to apletviewer console*/
|
|---|
| 124 | extern pthread_mutex_t debug_pipe_lock;
|
|---|
| 125 |
|
|---|
| 126 | // debug switches
|
|---|
| 127 | extern bool debug_initiated;
|
|---|
| 128 | extern int plugin_debug;
|
|---|
| 129 | extern bool plugin_debug_headers;
|
|---|
| 130 | extern bool plugin_debug_to_file;
|
|---|
| 131 | extern bool plugin_debug_to_streams;
|
|---|
| 132 | extern bool plugin_debug_to_system;
|
|---|
| 133 | extern bool plugin_debug_to_console;
|
|---|
| 134 | extern FILE * plugin_file_log;
|
|---|
| 135 | extern std::string plugin_file_log_name;
|
|---|
| 136 | #ifdef __OS2__
|
|---|
| 137 | extern int debug_pipe[2];
|
|---|
| 138 | #else
|
|---|
| 139 | extern gchar* debug_pipe_name;
|
|---|
| 140 | #endif
|
|---|
| 141 |
|
|---|
| 142 | extern gboolean jvm_up;
|
|---|
| 143 |
|
|---|
| 144 | // Browser function table.
|
|---|
| 145 | extern NPNetscapeFuncs browser_functions;
|
|---|
| 146 |
|
|---|
| 147 | // messages to the java side
|
|---|
| 148 | extern MessageBus* plugin_to_java_bus;
|
|---|
| 149 |
|
|---|
| 150 | // messages from the java side
|
|---|
| 151 | extern MessageBus* java_to_plugin_bus;
|
|---|
| 152 |
|
|---|
| 153 | // internal messages (e.g ones that need processing in main thread)
|
|---|
| 154 | //extern MessageBus* internal_bus;
|
|---|
| 155 |
|
|---|
| 156 | // subscribes to plugin_to_java_bus and sends messages over the link
|
|---|
| 157 | extern JavaMessageSender java_request_processor;
|
|---|
| 158 |
|
|---|
| 159 | // processes requests made to the plugin
|
|---|
| 160 | extern PluginRequestProcessor plugin_request_processor;
|
|---|
| 161 |
|
|---|
| 162 | /* Given an instance pointer, return its id */
|
|---|
| 163 | void get_instance_from_id(int id, NPP& instance);
|
|---|
| 164 |
|
|---|
| 165 | /* Given an instance id, return its pointer */
|
|---|
| 166 | int get_id_from_instance(NPP instance);
|
|---|
| 167 |
|
|---|
| 168 | /* Sends a message to the appletviewer */
|
|---|
| 169 | void plugin_send_message_to_appletviewer(gchar const* message);
|
|---|
| 170 | /*this method is not logging, do not add \n and is using different pipe*/
|
|---|
| 171 | void plugin_send_message_to_appletviewer_console(gchar const* message);
|
|---|
| 172 | void flush_plugin_send_message_to_appletviewer_console();
|
|---|
| 173 |
|
|---|
| 174 | /* Returns an appropriate (package/object) scriptable npobject */
|
|---|
| 175 | NPObject* get_scriptable_object(NPP instance);
|
|---|
| 176 |
|
|---|
| 177 | /* Creates a new scriptable plugin object and returns it */
|
|---|
| 178 | NPObject* allocate_scriptable_object(NPP npp, NPClass *aClass);
|
|---|
| 179 |
|
|---|
| 180 | NPError plugin_start_appletviewer (ITNPPluginData* data);
|
|---|
| 181 |
|
|---|
| 182 | #endif /* __ICEDTEANPPLUGIN_H__ */
|
|---|